From 76f6d74b8312f97a36c75ce3fb6f5330c60c654b Mon Sep 17 00:00:00 2001 From: Potuz Date: Fri, 20 May 2022 15:17:53 -0300 Subject: [PATCH] Add new slot tests (#10728) Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- beacon-chain/blockchain/BUILD.bazel | 1 + beacon-chain/blockchain/new_slot_test.go | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index 0452008a4..e1e12df81 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -110,6 +110,7 @@ go_test( "log_test.go", "metrics_test.go", "mock_test.go", + "new_slot_test.go", "pow_block_test.go", "process_attestation_test.go", "process_block_test.go", diff --git a/beacon-chain/blockchain/new_slot_test.go b/beacon-chain/blockchain/new_slot_test.go index eee1e7eae..7d71b1f0d 100644 --- a/beacon-chain/blockchain/new_slot_test.go +++ b/beacon-chain/blockchain/new_slot_test.go @@ -5,19 +5,22 @@ import ( "testing" "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/store" + "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/config/params" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" + "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/testing/assert" "github.com/prysmaticlabs/prysm/testing/require" ) func TestService_newSlot(t *testing.T) { beaconDB := testDB.SetupDB(t) - fcs := protoarray.New(0, 0, [32]byte{}) + fcs := protoarray.New(0, 0, [32]byte{'a'}) opts := []Option{ WithDatabase(beaconDB), WithStateGen(stategen.New(beaconDB)), @@ -25,10 +28,18 @@ func TestService_newSlot(t *testing.T) { } ctx := context.Background() + genesisStateRoot := [32]byte{} + genesis := blocks.NewGenesisBlock(genesisStateRoot[:]) + wsb, err := wrapper.WrappedSignedBeaconBlock(genesis) + require.NoError(t, err) + assert.NoError(t, beaconDB.SaveBlock(ctx, wsb)) + bj, err := genesis.Block.HashTreeRoot() + require.NoError(t, err) + require.NoError(t, fcs.InsertOptimisticBlock(ctx, 0, [32]byte{}, [32]byte{}, [32]byte{}, 0, 0)) // genesis require.NoError(t, fcs.InsertOptimisticBlock(ctx, 32, [32]byte{'a'}, [32]byte{}, [32]byte{}, 0, 0)) // finalized require.NoError(t, fcs.InsertOptimisticBlock(ctx, 64, [32]byte{'b'}, [32]byte{'a'}, [32]byte{}, 0, 0)) // justified - require.NoError(t, fcs.InsertOptimisticBlock(ctx, 96, [32]byte{'c'}, [32]byte{'a'}, [32]byte{}, 0, 0)) // best justified + require.NoError(t, fcs.InsertOptimisticBlock(ctx, 96, bj, [32]byte{'a'}, [32]byte{}, 0, 0)) // best justified require.NoError(t, fcs.InsertOptimisticBlock(ctx, 97, [32]byte{'d'}, [32]byte{}, [32]byte{}, 0, 0)) // bad type args struct { @@ -48,7 +59,7 @@ func TestService_newSlot(t *testing.T) { slot: params.BeaconConfig().SlotsPerEpoch + 1, finalized: ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'a'}, 32)}, justified: ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'b'}, 32)}, - bestJustified: ðpb.Checkpoint{Epoch: 3, Root: bytesutil.PadTo([]byte{'c'}, 32)}, + bestJustified: ðpb.Checkpoint{Epoch: 3, Root: bj[:]}, shouldEqual: false, }, }, @@ -58,7 +69,7 @@ func TestService_newSlot(t *testing.T) { slot: params.BeaconConfig().SlotsPerEpoch, finalized: ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'a'}, 32)}, justified: ðpb.Checkpoint{Epoch: 3, Root: bytesutil.PadTo([]byte{'b'}, 32)}, - bestJustified: ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'c'}, 32)}, + bestJustified: ðpb.Checkpoint{Epoch: 2, Root: bj[:]}, shouldEqual: false, }, }, @@ -78,7 +89,7 @@ func TestService_newSlot(t *testing.T) { slot: params.BeaconConfig().SlotsPerEpoch, finalized: ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'a'}, 32)}, justified: ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'b'}, 32)}, - bestJustified: ðpb.Checkpoint{Epoch: 3, Root: bytesutil.PadTo([]byte{'c'}, 32)}, + bestJustified: ðpb.Checkpoint{Epoch: 3, Root: bj[:]}, shouldEqual: true, }, },