From 3d6652ef502a44ad71921b1cda89fd77b9e347bf Mon Sep 17 00:00:00 2001 From: acud <12988138+acud@users.noreply.github.com> Date: Wed, 17 Jul 2024 23:10:13 +0000 Subject: [PATCH] chore(tx): remove unnecessary indirection (#6153) ## Motivation Removes unnecessary one-liner indirection in test setup. --- txs/conservative_state_test.go | 39 +++++++++++++++------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/txs/conservative_state_test.go b/txs/conservative_state_test.go index 46bad3a5a2..90ae5e7e0f 100644 --- a/txs/conservative_state_test.go +++ b/txs/conservative_state_test.go @@ -16,7 +16,6 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" "go.uber.org/zap" - "go.uber.org/zap/zaptest" "github.com/spacemeshos/go-spacemesh/common/types" "github.com/spacemeshos/go-spacemesh/genvm/sdk" @@ -91,7 +90,7 @@ func createTestState(t *testing.T, gasLimit uint64) *testConState { BlockGasLimit: gasLimit, NumTXsPerProposal: numTXsInProposal, } - logger := zaptest.NewLogger(t) + logger := zap.NewNop() _, pub, err := crypto.GenerateEd25519Key(nil) require.NoError(t, err) id, err := peer.IDFromPublicKey(pub) @@ -109,10 +108,6 @@ func createTestState(t *testing.T, gasLimit uint64) *testConState { } } -func createConservativeState(t *testing.T) *testConState { - return createTestState(t, math.MaxUint64) -} - func addBatch(tb testing.TB, tcs *testConState, numTXs int) ([]types.TransactionID, []*types.Transaction) { tb.Helper() ids := make([]types.TransactionID, 0, numTXs) @@ -132,7 +127,7 @@ func addBatch(tb testing.TB, tcs *testConState, numTXs int) ([]types.Transaction } func TestSelectProposalTXs(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) numTXs := 2 * numTXsInProposal lid := types.LayerID(97) bid := types.BlockID{100} @@ -198,7 +193,7 @@ func TestSelectProposalTXs_ExhaustGas(t *testing.T) { } func TestSelectProposalTXs_ExhaustMemPool(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) numTXs := numTXsInProposal - 1 lid := types.LayerID(97) bid := types.BlockID{100} @@ -249,7 +244,7 @@ func TestSelectProposalTXs_ExhaustMemPool(t *testing.T) { } func TestSelectProposalTXs_SamePrincipal(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) signer, err := signing.NewEdSigner() require.NoError(t, err) addr := types.GenerateAddress(signer.PublicKey().Bytes()) @@ -282,7 +277,7 @@ func TestSelectProposalTXs_TwoPrincipals(t *testing.T) { numTXs = numInProposal * 2 numInDBs = numInProposal ) - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) signer1, err := signing.NewEdSigner() require.NoError(t, err) addr1 := types.GenerateAddress(signer1.PublicKey().Bytes()) @@ -334,7 +329,7 @@ func TestSelectProposalTXs_TwoPrincipals(t *testing.T) { } func TestGetProjection(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) signer, err := signing.NewEdSigner() require.NoError(t, err) addr := types.GenerateAddress(signer.PublicKey().Bytes()) @@ -352,7 +347,7 @@ func TestGetProjection(t *testing.T) { } func TestAddToCache(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) signer, err := signing.NewEdSigner() require.NoError(t, err) addr := types.GenerateAddress(signer.PublicKey().Bytes()) @@ -368,7 +363,7 @@ func TestAddToCache(t *testing.T) { } func TestAddToCache_BadNonceNotPersisted(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) tx := &types.Transaction{ RawTx: types.NewRawTx([]byte{1, 1, 1}), TxHeader: &types.TxHeader{ @@ -383,7 +378,7 @@ func TestAddToCache_BadNonceNotPersisted(t *testing.T) { } func TestAddToCache_NonceGap(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) tx := &types.Transaction{ RawTx: types.NewRawTx([]byte{1, 1, 1}), TxHeader: &types.TxHeader{ @@ -400,7 +395,7 @@ func TestAddToCache_NonceGap(t *testing.T) { } func TestAddToCache_InsufficientBalance(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) signer, err := signing.NewEdSigner() require.NoError(t, err) addr := types.GenerateAddress(signer.PublicKey().Bytes()) @@ -414,7 +409,7 @@ func TestAddToCache_InsufficientBalance(t *testing.T) { } func TestAddToCache_TooManyForOneAccount(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) signer, err := signing.NewEdSigner() require.NoError(t, err) addr := types.GenerateAddress(signer.PublicKey().Bytes()) @@ -431,7 +426,7 @@ func TestAddToCache_TooManyForOneAccount(t *testing.T) { } func TestGetMeshTransaction(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) signer, err := signing.NewEdSigner() require.NoError(t, err) addr := types.GenerateAddress(signer.PublicKey().Bytes()) @@ -458,7 +453,7 @@ func TestGetMeshTransaction(t *testing.T) { } func TestUpdateCache_UpdateHeader(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) lid := types.LayerID(1) signer, err := signing.NewEdSigner() @@ -500,7 +495,7 @@ func TestUpdateCache_UpdateHeader(t *testing.T) { } func TestUpdateCache(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) lid := types.LayerID(1) ids, txs := addBatch(t, tcs, numTXs) block := types.NewExistingBlock(types.BlockID{1}, @@ -532,7 +527,7 @@ func TestUpdateCache(t *testing.T) { } func TestUpdateCache_EmptyLayer(t *testing.T) { - tcs := createConservativeState(t) + tcs := createTestState(t, math.MaxUint64) lid := types.LayerID(1) ids, _ := addBatch(t, tcs, numTXs) require.NoError(t, tcs.LinkTXsWithBlock(lid, types.BlockID{1, 2, 3}, ids)) @@ -552,8 +547,8 @@ func TestConsistentHandling(t *testing.T) { // conservative cache state instances := []*testConState{ - createConservativeState(t), - createConservativeState(t), + createTestState(t, math.MaxUint64), + createTestState(t, math.MaxUint64), } rng := mrand.New(mrand.NewSource(101))