# Week 9 Hi everyone, this week I got started to writing unit tests for my PR which implements a function to calculate field roots for a block body in any fork. ## Setting up the tests ```go blockBodyXXX := hydrateBeaconBlockBodyXXX() i, err := NewBeaconBlockBody(blockBodyXXX) require.NoError(t, err) b := i.(*BeaconBlockBody) ``` This block of code is common to all the forks, we just need to replace the `XXX` with the required fork name. The first line just sets up a block body of the relevant fork with empty fields but correct sizes. The second line returns an interface which is then then typecasted into a `BeaconBlockBody` for further work. ## Phase 0 test ```go fieldRoots, err := ComputeBlockBodyFieldRoots(context.Background(), b) require.NoError(t, err) trie, err := trie.GenerateTrieFromItems(fieldRoots, 3) require.NoError(t, err) layers := trie.ToProto().GetLayers() hash := layers[len(layers)-1].Layer[0] require.NoError(t, err) correctHash, err := b.HashTreeRoot() require.NoError(t, err) require.DeepEqual(t, correctHash[:], hash) ``` The `HashTreeRoot` function is called on the typecasted block body which returns the correct hash. The test hash is computed by the `ComputeBlockBodyFieldRoots` function(the function we are testing mainly) and is then compared with the correct hash to check for the correctness of the former. ## What's Next Right now I am yet to write the tests upto Electra, which I should be finishing soon unless I get some blockers.