Skip to content

Commit

Permalink
Decrease duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
MakisChristou committed Jan 3, 2024
1 parent 06a5e73 commit 1b2c195
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
17 changes: 8 additions & 9 deletions txpool/tx_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 9 additions & 18 deletions txpool/tx_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand All @@ -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) {
Expand Down

0 comments on commit 1b2c195

Please sign in to comment.