diff --git a/beacon-chain/db/kv/state_test.go b/beacon-chain/db/kv/state_test.go index e4a6d4f7b215..f7c1872013da 100644 --- a/beacon-chain/db/kv/state_test.go +++ b/beacon-chain/db/kv/state_test.go @@ -5,7 +5,6 @@ import ( "reflect" "testing" - "github.com/gogo/protobuf/proto" types "github.com/prysmaticlabs/eth2-types" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/prysmaticlabs/prysm/beacon-chain/state" @@ -57,7 +56,7 @@ func TestGenesisState_CanSaveRetrieve(t *testing.T) { savedGenesisS, err := db.GenesisState(context.Background()) require.NoError(t, err) - assert.DeepEqual(t, st.InnerStateUnsafe(), savedGenesisS.InnerStateUnsafe(), "Did not retrieve saved state") + assert.DeepSSZEqual(t, st.InnerStateUnsafe(), savedGenesisS.InnerStateUnsafe(), "Did not retrieve saved state") require.NoError(t, db.SaveGenesisBlockRoot(context.Background(), [32]byte{'C'})) } @@ -197,15 +196,15 @@ func TestStore_SaveDeleteState_CanGetHighestBelow(t *testing.T) { highest, err := db.HighestSlotStatesBelow(context.Background(), 2) require.NoError(t, err) - assert.Equal(t, true, proto.Equal(highest[0].InnerStateUnsafe(), s0), "Did not retrieve saved state: %v != %v", highest, s0) + assert.DeepSSZEqual(t, highest[0].InnerStateUnsafe(), s0) highest, err = db.HighestSlotStatesBelow(context.Background(), 101) require.NoError(t, err) - assert.Equal(t, true, proto.Equal(highest[0].InnerStateUnsafe(), s1), "Did not retrieve saved state: %v != %v", highest, s1) + assert.DeepSSZEqual(t, highest[0].InnerStateUnsafe(), s1) highest, err = db.HighestSlotStatesBelow(context.Background(), 1001) require.NoError(t, err) - assert.Equal(t, true, proto.Equal(highest[0].InnerStateUnsafe(), s2), "Did not retrieve saved state: %v != %v", highest, s2) + assert.DeepSSZEqual(t, highest[0].InnerStateUnsafe(), s2) } func TestStore_GenesisState_CanGetHighestBelow(t *testing.T) { @@ -230,14 +229,14 @@ func TestStore_GenesisState_CanGetHighestBelow(t *testing.T) { highest, err := db.HighestSlotStatesBelow(context.Background(), 2) require.NoError(t, err) - assert.Equal(t, true, proto.Equal(highest[0].InnerStateUnsafe(), st.InnerStateUnsafe())) + assert.DeepSSZEqual(t, highest[0].InnerStateUnsafe(), st.InnerStateUnsafe()) highest, err = db.HighestSlotStatesBelow(context.Background(), 1) require.NoError(t, err) - assert.Equal(t, true, proto.Equal(highest[0].InnerStateUnsafe(), genesisState.InnerStateUnsafe())) + assert.DeepSSZEqual(t, highest[0].InnerStateUnsafe(), genesisState.InnerStateUnsafe()) highest, err = db.HighestSlotStatesBelow(context.Background(), 0) require.NoError(t, err) - assert.Equal(t, true, proto.Equal(highest[0].InnerStateUnsafe(), genesisState.InnerStateUnsafe())) + assert.DeepSSZEqual(t, highest[0].InnerStateUnsafe(), genesisState.InnerStateUnsafe()) } func TestStore_CleanUpDirtyStates_AboveThreshold(t *testing.T) { diff --git a/beacon-chain/db/restore_test.go b/beacon-chain/db/restore_test.go index b4a9a03b8afb..879df02d56b6 100644 --- a/beacon-chain/db/restore_test.go +++ b/beacon-chain/db/restore_test.go @@ -8,6 +8,7 @@ import ( "path" "testing" + types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/db/kv" "github.com/prysmaticlabs/prysm/shared/cmd" "github.com/prysmaticlabs/prysm/shared/testutil" @@ -65,7 +66,7 @@ func TestRestore(t *testing.T) { require.NoError(t, err) headBlock, err := restoredDb.HeadBlock(ctx) require.NoError(t, err) - assert.Equal(t, uint64(5000), headBlock.Block.Slot, "Restored database has incorrect data") + assert.Equal(t, types.Slot(5000), headBlock.Block.Slot, "Restored database has incorrect data") assert.LogsContain(t, logHook, "Restore completed successfully") } diff --git a/beacon-chain/operations/attestations/kv/aggregated_test.go b/beacon-chain/operations/attestations/kv/aggregated_test.go index f8f480423b5d..efba144a8e18 100644 --- a/beacon-chain/operations/attestations/kv/aggregated_test.go +++ b/beacon-chain/operations/attestations/kv/aggregated_test.go @@ -512,6 +512,6 @@ func TestKV_Aggregated_DuplicateAggregatedAttestations(t *testing.T) { returned := cache.AggregatedAttestations() // It should have only returned att2. - assert.DeepEqual(t, att2, returned[0], "Did not receive correct aggregated atts") + assert.DeepSSZEqual(t, att2, returned[0], "Did not receive correct aggregated atts") assert.Equal(t, 1, len(returned), "Did not receive correct aggregated atts") } diff --git a/beacon-chain/rpc/beacon/blocks_test.go b/beacon-chain/rpc/beacon/blocks_test.go index c9bad7197134..71d7c4494873 100644 --- a/beacon-chain/rpc/beacon/blocks_test.go +++ b/beacon-chain/rpc/beacon/blocks_test.go @@ -152,6 +152,9 @@ func TestServer_ListBlocks_Genesis_MultiBlocks(t *testing.T) { } func TestServer_ListBlocks_Pagination(t *testing.T) { + params.UseMinimalConfig() + defer params.UseMainnetConfig() + db := dbTest.SetupDB(t) chain := &chainMock.ChainService{ CanonicalRoots: map[[32]byte]bool{}, @@ -357,8 +360,10 @@ func TestServer_GetChainHead_NoHeadBlock(t *testing.T) { } func TestServer_GetChainHead(t *testing.T) { - db := dbTest.SetupDB(t) + params.UseMinimalConfig() + defer params.UseMainnetConfig() + db := dbTest.SetupDB(t) genBlock := testutil.NewBeaconBlock() genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32) require.NoError(t, db.SaveBlock(context.Background(), genBlock)) diff --git a/beacon-chain/rpc/beacon/validators_test.go b/beacon-chain/rpc/beacon/validators_test.go index 92b1cf3c236e..751629a54599 100644 --- a/beacon-chain/rpc/beacon/validators_test.go +++ b/beacon-chain/rpc/beacon/validators_test.go @@ -1556,8 +1556,10 @@ func TestServer_GetValidatorParticipation_CurrentAndPrevEpoch(t *testing.T) { } func TestServer_GetValidatorParticipation_OrphanedUntilGenesis(t *testing.T) { - beaconDB := dbTest.SetupDB(t) + helpers.ClearCache() + params.UseMainnetConfig() + beaconDB := dbTest.SetupDB(t) ctx := context.Background() validatorCount := uint64(100) @@ -1644,6 +1646,10 @@ func TestGetValidatorPerformance_Syncing(t *testing.T) { } func TestGetValidatorPerformance_OK(t *testing.T) { + helpers.ClearCache() + params.UseMinimalConfig() + defer params.UseMainnetConfig() + ctx := context.Background() epoch := types.Epoch(1) headState, err := testutil.NewBeaconState() @@ -1916,9 +1922,9 @@ func TestServer_GetIndividualVotes_RequestFutureSlot(t *testing.T) { } func TestServer_GetIndividualVotes_ValidatorsDontExist(t *testing.T) { - params.UseMinimalConfig() defer params.UseMainnetConfig() + beaconDB := dbTest.SetupDB(t) ctx := context.Background() diff --git a/beacon-chain/rpc/validator/aggregator_test.go b/beacon-chain/rpc/validator/aggregator_test.go index a476632d802e..e4e9d3ef2676 100644 --- a/beacon-chain/rpc/validator/aggregator_test.go +++ b/beacon-chain/rpc/validator/aggregator_test.go @@ -350,7 +350,7 @@ func TestSubmitAggregateAndProof_PreferOwnAttestation(t *testing.T) { res, err := aggregatorServer.SubmitAggregateSelectionProof(ctx, req) require.NoError(t, err) - assert.DeepEqual(t, att1, res.AggregateAndProof.Aggregate, "Did not receive wanted attestation") + assert.DeepSSZEqual(t, att1, res.AggregateAndProof.Aggregate, "Did not receive wanted attestation") } func TestSubmitAggregateAndProof_SelectsMostBitsWhenOwnAttestationNotPresent(t *testing.T) { @@ -401,7 +401,7 @@ func TestSubmitAggregateAndProof_SelectsMostBitsWhenOwnAttestationNotPresent(t * res, err := aggregatorServer.SubmitAggregateSelectionProof(ctx, req) require.NoError(t, err) - assert.DeepEqual(t, att1, res.AggregateAndProof.Aggregate, "Did not receive wanted attestation") + assert.DeepSSZEqual(t, att1, res.AggregateAndProof.Aggregate, "Did not receive wanted attestation") } func TestSubmitSignedAggregateSelectionProof_ZeroHashesSignatures(t *testing.T) { diff --git a/beacon-chain/state/stategen/epoch_boundary_state_cache_test.go b/beacon-chain/state/stategen/epoch_boundary_state_cache_test.go index 822d2b8a7fc3..a88d3f1d30b2 100644 --- a/beacon-chain/state/stategen/epoch_boundary_state_cache_test.go +++ b/beacon-chain/state/stategen/epoch_boundary_state_cache_test.go @@ -35,7 +35,7 @@ func TestEpochBoundaryStateCache_CanSave(t *testing.T) { got, exists, err = e.getByRoot([32]byte{'a'}) require.NoError(t, err) assert.Equal(t, true, exists, "Should exist") - assert.DeepEqual(t, s.InnerStateUnsafe(), got.state.InnerStateUnsafe(), "Should have the same state") + assert.DeepSSZEqual(t, s.InnerStateUnsafe(), got.state.InnerStateUnsafe(), "Should have the same state") got, exists, err = e.getBySlot(2) require.NoError(t, err) @@ -45,7 +45,7 @@ func TestEpochBoundaryStateCache_CanSave(t *testing.T) { got, exists, err = e.getBySlot(1) require.NoError(t, err) assert.Equal(t, true, exists, "Should exist") - assert.DeepEqual(t, s.InnerStateUnsafe(), got.state.InnerStateUnsafe(), "Should have the same state") + assert.DeepSSZEqual(t, s.InnerStateUnsafe(), got.state.InnerStateUnsafe(), "Should have the same state") } func TestEpochBoundaryStateCache_CanTrim(t *testing.T) { diff --git a/beacon-chain/state/stategen/getter_test.go b/beacon-chain/state/stategen/getter_test.go index b58b2f434304..b6e4a50931f6 100644 --- a/beacon-chain/state/stategen/getter_test.go +++ b/beacon-chain/state/stategen/getter_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "github.com/gogo/protobuf/proto" types "github.com/prysmaticlabs/eth2-types" + "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" @@ -36,9 +36,7 @@ func TestStateByRoot_ColdState(t *testing.T) { require.NoError(t, service.beaconDB.SaveGenesisBlockRoot(ctx, bRoot)) loadedState, err := service.StateByRoot(ctx, bRoot) require.NoError(t, err) - if !proto.Equal(loadedState.InnerStateUnsafe(), beaconState.InnerStateUnsafe()) { - t.Error("Did not correctly save state") - } + require.DeepSSZEqual(t, loadedState.InnerStateUnsafe(), beaconState.InnerStateUnsafe()) } func TestStateByRoot_HotStateUsingEpochBoundaryCacheNoReplay(t *testing.T) { @@ -97,9 +95,7 @@ func TestStateByRoot_HotStateCached(t *testing.T) { loadedState, err := service.StateByRoot(ctx, r) require.NoError(t, err) - if !proto.Equal(loadedState.InnerStateUnsafe(), beaconState.InnerStateUnsafe()) { - t.Error("Did not correctly cache state") - } + require.DeepSSZEqual(t, loadedState.InnerStateUnsafe(), beaconState.InnerStateUnsafe()) } func TestStateByRootInitialSync_UseEpochStateCache(t *testing.T) { @@ -133,9 +129,7 @@ func TestStateByRootInitialSync_UseCache(t *testing.T) { loadedState, err := service.StateByRootInitialSync(ctx, r) require.NoError(t, err) - if !proto.Equal(loadedState.InnerStateUnsafe(), beaconState.InnerStateUnsafe()) { - t.Error("Did not correctly cache state") - } + require.DeepSSZEqual(t, loadedState.InnerStateUnsafe(), beaconState.InnerStateUnsafe()) if service.hotStateCache.has(r) { t.Error("Hot state cache was not invalidated") } @@ -234,10 +228,7 @@ func TestLoadeStateByRoot_Cached(t *testing.T) { // This tests where hot state was already cached. loadedState, err := service.loadStateByRoot(ctx, r) require.NoError(t, err) - - if !proto.Equal(loadedState.InnerStateUnsafe(), beaconState.InnerStateUnsafe()) { - t.Error("Did not correctly cache state") - } + require.DeepSSZEqual(t, loadedState.InnerStateUnsafe(), beaconState.InnerStateUnsafe()) } func TestLoadeStateByRoot_FinalizedState(t *testing.T) { @@ -261,10 +252,7 @@ func TestLoadeStateByRoot_FinalizedState(t *testing.T) { // This tests where hot state was already cached. loadedState, err := service.loadStateByRoot(ctx, gRoot) require.NoError(t, err) - - if !proto.Equal(loadedState.InnerStateUnsafe(), beaconState.InnerStateUnsafe()) { - t.Error("Did not correctly retrieve finalized state") - } + require.DeepSSZEqual(t, loadedState.InnerStateUnsafe(), beaconState.InnerStateUnsafe()) } func TestLoadeStateByRoot_EpochBoundaryStateCanProcess(t *testing.T) { diff --git a/beacon-chain/state/stategen/migrate_test.go b/beacon-chain/state/stategen/migrate_test.go index 079d58c78e40..808f9ec84155 100644 --- a/beacon-chain/state/stategen/migrate_test.go +++ b/beacon-chain/state/stategen/migrate_test.go @@ -51,7 +51,7 @@ func TestMigrateToCold_HappyPath(t *testing.T) { gotState, err := service.beaconDB.State(ctx, fRoot) require.NoError(t, err) - assert.DeepEqual(t, beaconState.InnerStateUnsafe(), gotState.InnerStateUnsafe(), "Did not save state") + assert.DeepSSZEqual(t, beaconState.InnerStateUnsafe(), gotState.InnerStateUnsafe(), "Did not save state") gotRoot := service.beaconDB.ArchivedPointRoot(ctx, stateSlot/service.slotsPerArchivedPoint) assert.Equal(t, fRoot, gotRoot, "Did not save archived root") lastIndex, err := service.beaconDB.LastArchivedSlot(ctx) diff --git a/beacon-chain/state/stategen/replay_test.go b/beacon-chain/state/stategen/replay_test.go index b9cee22bc0c4..befbb0ae6ef3 100644 --- a/beacon-chain/state/stategen/replay_test.go +++ b/beacon-chain/state/stategen/replay_test.go @@ -364,7 +364,7 @@ func TestLastSavedState_Genesis(t *testing.T) { savedState, err := s.lastSavedState(ctx, 0) require.NoError(t, err) - require.DeepEqual(t, gState.InnerStateUnsafe(), savedState.InnerStateUnsafe()) + require.DeepSSZEqual(t, gState.InnerStateUnsafe(), savedState.InnerStateUnsafe()) } func TestLastSavedState_CanGet(t *testing.T) { @@ -394,9 +394,7 @@ func TestLastSavedState_CanGet(t *testing.T) { savedState, err := s.lastSavedState(ctx, s.finalizedInfo.slot+100) require.NoError(t, err) - if !proto.Equal(st.InnerStateUnsafe(), savedState.InnerStateUnsafe()) { - t.Error("Did not save correct root") - } + require.DeepSSZEqual(t, st.InnerStateUnsafe(), savedState.InnerStateUnsafe()) } func TestLastSavedState_NoSavedBlockState(t *testing.T) { diff --git a/beacon-chain/state/stategen/service_test.go b/beacon-chain/state/stategen/service_test.go index 1a09d008d265..755b765d5118 100644 --- a/beacon-chain/state/stategen/service_test.go +++ b/beacon-chain/state/stategen/service_test.go @@ -4,7 +4,6 @@ import ( "context" "testing" - "github.com/gogo/protobuf/proto" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/shared/params" @@ -30,10 +29,7 @@ func TestResume(t *testing.T) { resumeState, err := service.Resume(ctx) require.NoError(t, err) - - if !proto.Equal(beaconState.InnerStateUnsafe(), resumeState.InnerStateUnsafe()) { - t.Error("Diff saved state") - } + require.DeepSSZEqual(t, beaconState.InnerStateUnsafe(), resumeState.InnerStateUnsafe()) assert.Equal(t, params.BeaconConfig().SlotsPerEpoch, service.finalizedInfo.slot, "Did not get watned slot") assert.Equal(t, service.finalizedInfo.root, root, "Did not get wanted root") assert.NotNil(t, service.finalizedState(), "Wanted a non nil finalized state") diff --git a/beacon-chain/state/types_test.go b/beacon-chain/state/types_test.go index 05dfffdb7b16..02d92349d548 100644 --- a/beacon-chain/state/types_test.go +++ b/beacon-chain/state/types_test.go @@ -27,9 +27,7 @@ func TestBeaconState_ProtoBeaconStateCompatibility(t *testing.T) { cloned, ok := proto.Clone(genesis).(*pb.BeaconState) assert.Equal(t, true, ok, "Object is not of type *pb.BeaconState") custom := customState.CloneInnerState() - if !proto.Equal(cloned, custom) { - t.Fatal("Cloned states did not match") - } + assert.DeepSSZEqual(t, cloned, custom) r1, err := customState.HashTreeRoot(ctx) require.NoError(t, err)