From 4007f61fd5e05fa840f199c4dd39e644e4c71f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 12 Feb 2024 20:46:20 +0100 Subject: [PATCH] More fixes --- consensus/polybft/state_store_exit_test.go | 1 + consensus/polybft/validator/validator_set_delta_test.go | 9 +++++++++ consensus/polybft/validators_snapshot_test.go | 1 + e2e/discovery_test.go | 5 +++++ e2e/txpool_test.go | 1 + 5 files changed, 17 insertions(+) diff --git a/consensus/polybft/state_store_exit_test.go b/consensus/polybft/state_store_exit_test.go index 92a6f935ae..4594b4af1f 100644 --- a/consensus/polybft/state_store_exit_test.go +++ b/consensus/polybft/state_store_exit_test.go @@ -194,6 +194,7 @@ func insertTestExitEvents(t *testing.T, state *State, } index++ } + block++ } } diff --git a/consensus/polybft/validator/validator_set_delta_test.go b/consensus/polybft/validator/validator_set_delta_test.go index 2d4a8e6834..44891483b4 100644 --- a/consensus/polybft/validator/validator_set_delta_test.go +++ b/consensus/polybft/validator/validator_set_delta_test.go @@ -71,6 +71,7 @@ func TestValidatorSetDelta_UnmarshalRLPWith_NegativeCases(t *testing.T) { t.Parallel() ar := &fastrlp.Arena{} + delta := &ValidatorSetDelta{} require.NoError(t, delta.UnmarshalRLPWith(ar.NewArray())) }) @@ -84,6 +85,7 @@ func TestValidatorSetDelta_UnmarshalRLPWith_NegativeCases(t *testing.T) { deltaMarshalled.Set(ar.NewBytes([]byte{0x33})) deltaMarshalled.Set(ar.NewBytes([]byte{0x26})) deltaMarshalled.Set(ar.NewBytes([]byte{0x74})) + delta := &ValidatorSetDelta{} require.ErrorContains(t, delta.UnmarshalRLPWith(deltaMarshalled), "incorrect elements count to decode validator set delta, expected 3 but found 4") }) @@ -93,9 +95,11 @@ func TestValidatorSetDelta_UnmarshalRLPWith_NegativeCases(t *testing.T) { ar := &fastrlp.Arena{} deltaMarshalled := ar.NewArray() + deltaMarshalled.Set(ar.NewBytes([]byte{0x59})) deltaMarshalled.Set(ar.NewBytes([]byte{0x33})) deltaMarshalled.Set(ar.NewBytes([]byte{0x27})) + delta := &ValidatorSetDelta{} require.ErrorContains(t, delta.UnmarshalRLPWith(deltaMarshalled), "array expected for added validators") }) @@ -110,6 +114,7 @@ func TestValidatorSetDelta_UnmarshalRLPWith_NegativeCases(t *testing.T) { deltaMarshalled.Set(addedArray) deltaMarshalled.Set(ar.NewNullArray()) deltaMarshalled.Set(ar.NewNull()) + delta := &ValidatorSetDelta{} require.ErrorContains(t, delta.UnmarshalRLPWith(deltaMarshalled), "value is not of type array") }) @@ -136,6 +141,7 @@ func TestValidatorSetDelta_UnmarshalRLPWith_NegativeCases(t *testing.T) { deltaMarshalled.Set(addedArray) deltaMarshalled.Set(updatedArray) deltaMarshalled.Set(ar.NewNull()) + delta := &ValidatorSetDelta{} require.ErrorContains(t, delta.UnmarshalRLPWith(deltaMarshalled), "value is not of type bytes") }) @@ -158,7 +164,9 @@ func TestValidatorSetDelta_UnmarshalRLPWith_NegativeCases(t *testing.T) { ar := &fastrlp.Arena{} deltaMarshalled := ar.NewArray() + updatedArray := ar.NewArray() + updatedArray.Set(ar.NewNull()) deltaMarshalled.Set(ar.NewArray()) deltaMarshalled.Set(updatedArray) @@ -216,6 +224,7 @@ func TestExtra_CreateValidatorSetDelta_Cases(t *testing.T) { // make sure generated voting power is different than the original one v.VotingPower += vp.Uint64() + 1 } + newValidatorSet := vals.GetPublicIdentities(c.newSet...) delta, err := CreateValidatorSetDelta(oldValidatorSet, newValidatorSet) diff --git a/consensus/polybft/validators_snapshot_test.go b/consensus/polybft/validators_snapshot_test.go index e053014ebd..aa2e4ced1b 100644 --- a/consensus/polybft/validators_snapshot_test.go +++ b/consensus/polybft/validators_snapshot_test.go @@ -149,6 +149,7 @@ func TestValidatorsSnapshotCache_Cleanup(t *testing.T) { for i := uint64(0); i < validatorSnapshotLimit; i++ { require.NoError(cache.storeSnapshot(&validatorSnapshot{i, i * 10, snapshot}, nil)) + maxEpoch++ } diff --git a/e2e/discovery_test.go b/e2e/discovery_test.go index b25463d82f..412c79e35c 100644 --- a/e2e/discovery_test.go +++ b/e2e/discovery_test.go @@ -40,18 +40,22 @@ func TestDiscovery(t *testing.T) { srvs := framework.NewTestServers(t, tt.numNodes, conf) p2pAddrs := make([]string, tt.numNodes) + for i, s := range srvs { status, err := s.Operator().GetStatus(context.Background(), &empty.Empty{}) if err != nil { t.Fatal(err) } + p2pAddrs[i] = strings.Split(status.P2PAddr, ",")[0] } for i := 0; i < tt.numInitConnectNodes-1; i++ { srv, dest := srvs[i], p2pAddrs[i+1] + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() + _, err := srv.Operator().PeersAdd(ctx, &proto.PeersAddRequest{ Id: dest, }) @@ -63,6 +67,7 @@ func TestDiscovery(t *testing.T) { for i, srv := range srvs { shouldKnowPeers := true subTestName := fmt.Sprintf("node %d should know other peers", i) + if i >= tt.numInitConnectNodes { shouldKnowPeers = false subTestName = fmt.Sprintf("node %d shouldn't know other peers", i) diff --git a/e2e/txpool_test.go b/e2e/txpool_test.go index 53e5332177..240e13645f 100644 --- a/e2e/txpool_test.go +++ b/e2e/txpool_test.go @@ -186,6 +186,7 @@ func TestTxPool_ErrorCodes(t *testing.T) { convertedHash := types.StringToHash(addResponse.TxHash) _, receiptErr := tests.WaitForReceipt(receiptCtx, srv.JSONRPC().Eth(), ethgo.Hash(convertedHash)) + if receiptErr != nil { t.Fatalf("Unable to get receipt, %v", receiptErr) }