Skip to content

Commit

Permalink
chore(tx): remove unnecessary indirection (#6153)
Browse files Browse the repository at this point in the history
## Motivation

Removes unnecessary one-liner indirection in test setup.
  • Loading branch information
acud committed Jul 17, 2024
1 parent 845d2ff commit 3d6652e
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions txs/conservative_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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()
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down

0 comments on commit 3d6652e

Please sign in to comment.