diff --git a/txpool/tx_object_test.go b/txpool/tx_object_test.go index 3e4ad5b07..468e1a365 100644 --- a/txpool/tx_object_test.go +++ b/txpool/tx_object_test.go @@ -73,7 +73,7 @@ func newDelegatedTx(chainTag byte, clauses []*tx.Clause, gas uint64, blockRef tx return tx.WithSignature(sig) } -func TestExecutableWithError(t *testing.T) { +func SetupTest() (genesis.DevAccount, *chain.Repository, *block.Block, *state.State) { acc := genesis.DevAccounts()[0] db := muxdb.NewMem() @@ -83,6 +83,12 @@ func TestExecutableWithError(t *testing.T) { repo.AddBlock(b1, nil, 0) st := state.New(db, repo.GenesisBlock().Header().StateRoot(), 0, 0, 0) + return acc, repo, b1, st +} + +func TestExecutableWithError(t *testing.T) { + acc, repo, b1, st := SetupTest() + tests := []struct { tx *tx.Transaction expected bool @@ -134,14 +140,7 @@ func TestResolve(t *testing.T) { } func TestExecutable(t *testing.T) { - acc := genesis.DevAccounts()[0] - - db := muxdb.NewMem() - repo := newChainRepo(db) - b0 := repo.GenesisBlock() - b1 := new(block.Builder).ParentID(b0.Header().ID()).GasLimit(10000000).TotalScore(100).Build() - repo.AddBlock(b1, nil, 0) - st := state.New(db, repo.GenesisBlock().Header().StateRoot(), 0, 0, 0) + acc, repo, b1, st := SetupTest() tests := []struct { tx *tx.Transaction diff --git a/txpool/tx_pool_test.go b/txpool/tx_pool_test.go index a30aabbd4..8913c06d8 100644 --- a/txpool/tx_pool_test.go +++ b/txpool/tx_pool_test.go @@ -106,10 +106,7 @@ func TestNewCloseWithServer(t *testing.T) { time.Sleep(2 * time.Second) } -func TestAddWithFullErrorUnsyncedChain(t *testing.T) { - pool := newPool(LIMIT, LIMIT_PER_ACCOUNT) - defer pool.Close() - +func FillPoolWithTxs(pool *TxPool, t *testing.T) { // Create a slice of transactions to be added to the pool. txs := make(Tx.Transactions, 0, 15) for i := 0; i < 12; i++ { @@ -127,25 +124,19 @@ func TestAddWithFullErrorUnsyncedChain(t *testing.T) { time.Sleep(2 * time.Second) } -func TestAddWithFullErrorSyncedChain(t *testing.T) { - pool := newPoolWithParams(LIMIT, LIMIT_PER_ACCOUNT, "./", "", uint64(time.Now().Unix())) +func TestAddWithFullErrorUnsyncedChain(t *testing.T) { + pool := newPool(LIMIT, LIMIT_PER_ACCOUNT) defer pool.Close() - // Create a slice of transactions to be added to the pool. - txs := make(Tx.Transactions, 0, 15) - for i := 0; i < 12; i++ { - tx := newTx(pool.repo.ChainTag(), nil, 21000, tx.BlockRef{}, 100, nil, tx.Features(0), genesis.DevAccounts()[0]) - txs = append(txs, tx) - } + FillPoolWithTxs(pool, t) - // Call the Fill method - pool.Fill(txs) +} - err := pool.Add(newTx(pool.repo.ChainTag(), nil, 21000, tx.NewBlockRef(10), 100, nil, Tx.Features(0), genesis.DevAccounts()[0])) - assert.Equal(t, err.Error(), "tx rejected: pool is full") +func TestAddWithFullErrorSyncedChain(t *testing.T) { + pool := newPoolWithParams(LIMIT, LIMIT_PER_ACCOUNT, "./", "", uint64(time.Now().Unix())) + defer pool.Close() - // Add a delay of 2 seconds - time.Sleep(2 * time.Second) + FillPoolWithTxs(pool, t) } func TestNewCloseWithError(t *testing.T) {