github.com/igggame/nebulas-go@v2.1.0+incompatible/core/transaction_pool_test.go (about)

     1  // Copyright (C) 2017 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // the go-nebulas library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU General Public License
    16  // along with the go-nebulas library.  If not, see <http://www.gnu.org/licenses/>.
    17  //
    18  
    19  package core
    20  
    21  import (
    22  	"testing"
    23  
    24  	"time"
    25  
    26  	"github.com/nebulasio/go-nebulas/crypto"
    27  	"github.com/nebulasio/go-nebulas/crypto/keystore"
    28  	"github.com/nebulasio/go-nebulas/crypto/keystore/secp256k1"
    29  	"github.com/nebulasio/go-nebulas/util"
    30  	"github.com/stretchr/testify/assert"
    31  )
    32  
    33  func TestTransactionPool_1(t *testing.T) {
    34  	ks := keystore.DefaultKS
    35  	priv1 := secp256k1.GeneratePrivateKey()
    36  	pubdata1, _ := priv1.PublicKey().Encoded()
    37  	from, _ := NewAddressFromPublicKey(pubdata1)
    38  	ks.SetKey(from.String(), priv1, []byte("passphrase"))
    39  	ks.Unlock(from.String(), []byte("passphrase"), time.Second*60*60*24*365)
    40  	key1, _ := ks.GetUnlocked(from.String())
    41  	signature1, _ := crypto.NewSignature(keystore.SECP256K1)
    42  	signature1.InitSign(key1.(keystore.PrivateKey))
    43  
    44  	priv2 := secp256k1.GeneratePrivateKey()
    45  	pubdata2, _ := priv2.PublicKey().Encoded()
    46  	other, _ := NewAddressFromPublicKey(pubdata2)
    47  	ks.SetKey(other.String(), priv2, []byte("passphrase"))
    48  	ks.Unlock(other.String(), []byte("passphrase"), time.Second*60*60*24*365)
    49  	key2, _ := ks.GetUnlocked(other.String())
    50  	signature2, _ := crypto.NewSignature(keystore.SECP256K1)
    51  	signature2.InitSign(key2.(keystore.PrivateKey))
    52  
    53  	priv3 := secp256k1.GeneratePrivateKey()
    54  	pubdata3, _ := priv3.PublicKey().Encoded()
    55  	other2, _ := NewAddressFromPublicKey(pubdata3)
    56  	ks.SetKey(other2.String(), priv3, []byte("passphrase"))
    57  	ks.Unlock(other2.String(), []byte("passphrase"), time.Second*60*60*24*365)
    58  	key3, _ := ks.GetUnlocked(other2.String())
    59  	signature3, _ := crypto.NewSignature(keystore.SECP256K1)
    60  	signature3.InitSign(key3.(keystore.PrivateKey))
    61  
    62  	priv4 := secp256k1.GeneratePrivateKey()
    63  	pubdata4, _ := priv4.PublicKey().Encoded()
    64  	other3, _ := NewAddressFromPublicKey(pubdata4)
    65  	ks.SetKey(other3.String(), priv4, []byte("passphrase"))
    66  	ks.Unlock(other3.String(), []byte("passphrase"), time.Second*60*60*24*365)
    67  	key4, _ := ks.GetUnlocked(other3.String())
    68  	signature4, _ := crypto.NewSignature(keystore.SECP256K1)
    69  	signature4.InitSign(key4.(keystore.PrivateKey))
    70  
    71  	gasCount, _ := util.NewUint128FromInt(2)
    72  	heighPrice, err := TransactionGasPrice.Mul(gasCount)
    73  	assert.Nil(t, err)
    74  
    75  	bc := testNeb(t).chain
    76  	txPool, _ := NewTransactionPool(3)
    77  	txPool.setBlockChain(bc)
    78  	txPool.setEventEmitter(bc.eventEmitter)
    79  	txPool.setAccess(new(Access))
    80  
    81  	gasLimit, _ := util.NewUint128FromInt(200000)
    82  	tx1, _ := NewTransaction(bc.ChainID(), from, &Address{address: []byte("to")}, util.NewUint128(), 10, TxPayloadBinaryType, []byte("1"), TransactionGasPrice, gasLimit)
    83  	tx2, _ := NewTransaction(bc.ChainID(), other, &Address{address: []byte("to")}, util.NewUint128(), 1, TxPayloadBinaryType, []byte("2"), heighPrice, gasLimit)
    84  	tx3, _ := NewTransaction(bc.ChainID(), from, &Address{address: []byte("to")}, util.NewUint128(), 1, TxPayloadBinaryType, []byte("3"), TransactionGasPrice, gasLimit)
    85  
    86  	tx4, _ := NewTransaction(bc.ChainID(), from, &Address{address: []byte("to")}, util.NewUint128(), 2, TxPayloadBinaryType, []byte("4"), TransactionGasPrice, gasLimit)
    87  	tx5, _ := NewTransaction(bc.ChainID()+1, from, &Address{address: []byte("to")}, util.NewUint128(), 0, TxPayloadBinaryType, []byte("5"), TransactionGasPrice, gasLimit)
    88  
    89  	tx6, _ := NewTransaction(bc.ChainID(), other2, &Address{[]byte("to")}, util.NewUint128(), 1, TxPayloadBinaryType, []byte("6"), TransactionGasPrice, gasLimit)
    90  	tx7, _ := NewTransaction(bc.ChainID(), other, &Address{[]byte("to")}, util.NewUint128(), 1, TxPayloadBinaryType, []byte("7"), heighPrice, gasLimit)
    91  
    92  	tx8, _ := NewTransaction(bc.ChainID(), other3, &Address{[]byte("to")}, util.NewUint128(), 1, TxPayloadBinaryType, []byte("8"), heighPrice, gasLimit)
    93  
    94  	txs := []*Transaction{tx1, tx2, tx3, tx4, tx5, tx6, tx7, tx8}
    95  
    96  	assert.Nil(t, txs[0].Sign(signature1))
    97  	assert.Nil(t, txPool.Push(txs[0]))
    98  	// put dup tx, should fail
    99  	assert.NotNil(t, txPool.Push(txs[0]))
   100  	assert.Nil(t, txs[1].Sign(signature2))
   101  	assert.Nil(t, txPool.Push(txs[1]))
   102  	assert.Nil(t, txs[2].Sign(signature1))
   103  	assert.Nil(t, txPool.Push(txs[2]))
   104  	// put not signed tx, should fail
   105  	assert.NotNil(t, txPool.Push(txs[3]))
   106  	// push 3, full, drop 0
   107  	assert.Equal(t, len(txPool.all), 3)
   108  	assert.NotNil(t, txPool.all[txs[0].hash.Hex()])
   109  	assert.Nil(t, txs[3].Sign(signature1))
   110  	assert.Nil(t, txPool.Push(txs[3]))
   111  	assert.Nil(t, txPool.all[txs[0].hash.Hex()])
   112  	assert.Equal(t, len(txPool.all), 3)
   113  	// pop 1
   114  	tx := txPool.Pop()
   115  	assert.Equal(t, txs[1].data, tx.data)
   116  	// put tx with different chainID, should fail
   117  	assert.Nil(t, txs[4].Sign(signature1))
   118  	assert.NotNil(t, txPool.Push(txs[4]))
   119  	// put one new
   120  	assert.Equal(t, len(txPool.all), 2)
   121  	assert.Nil(t, txs[5].Sign(signature3))
   122  	assert.Nil(t, txPool.Push(txs[5]))
   123  	assert.Equal(t, len(txPool.all), 3)
   124  	// put one new, full, pop 3
   125  	assert.Equal(t, len(txPool.all), 3)
   126  	assert.NotNil(t, txPool.all[txs[3].hash.Hex()])
   127  	assert.Nil(t, txs[6].Sign(signature2))
   128  	assert.Nil(t, txPool.Push(txs[6]))
   129  	assert.Nil(t, txPool.all[txs[3].hash.Hex()])
   130  	assert.Equal(t, len(txPool.all), 3)
   131  
   132  	assert.Equal(t, len(txPool.all), 3)
   133  	assert.Nil(t, txs[7].Sign(signature4))
   134  	assert.Nil(t, txPool.Push(txs[7]))
   135  	assert.Equal(t, len(txPool.all), 3)
   136  
   137  	assert.NotNil(t, txPool.Pop())
   138  	assert.Equal(t, len(txPool.all), 2)
   139  	assert.NotNil(t, txPool.Pop())
   140  	assert.Equal(t, len(txPool.all), 1)
   141  	assert.NotNil(t, txPool.Pop())
   142  	assert.Equal(t, len(txPool.all), 0)
   143  	assert.Equal(t, txPool.Empty(), true)
   144  	assert.Nil(t, txPool.Pop())
   145  }
   146  
   147  func TestTransactionPool(t *testing.T) {
   148  	ks := keystore.DefaultKS
   149  	priv1 := secp256k1.GeneratePrivateKey()
   150  	pubdata1, _ := priv1.PublicKey().Encoded()
   151  	from, _ := NewAddressFromPublicKey(pubdata1)
   152  	ks.SetKey(from.String(), priv1, []byte("passphrase"))
   153  	ks.Unlock(from.String(), []byte("passphrase"), time.Second*60*60*24*365)
   154  	key1, _ := ks.GetUnlocked(from.String())
   155  	signature1, _ := crypto.NewSignature(keystore.SECP256K1)
   156  	signature1.InitSign(key1.(keystore.PrivateKey))
   157  
   158  	priv2 := secp256k1.GeneratePrivateKey()
   159  	pubdata2, _ := priv2.PublicKey().Encoded()
   160  	other, _ := NewAddressFromPublicKey(pubdata2)
   161  	ks.SetKey(other.String(), priv2, []byte("passphrase"))
   162  	ks.Unlock(other.String(), []byte("passphrase"), time.Second*60*60*24*365)
   163  	key2, _ := ks.GetUnlocked(other.String())
   164  	signature2, _ := crypto.NewSignature(keystore.SECP256K1)
   165  	signature2.InitSign(key2.(keystore.PrivateKey))
   166  	gasCount, _ := util.NewUint128FromInt(2)
   167  	heighPrice, err := TransactionGasPrice.Mul(gasCount)
   168  	assert.Nil(t, err)
   169  	neb := testNeb(t)
   170  	bc := neb.chain
   171  	txPool := bc.txPool
   172  
   173  	gasLimit, _ := util.NewUint128FromInt(200000)
   174  
   175  	tx1, _ := NewTransaction(bc.ChainID(), from, &Address{[]byte("to")}, util.NewUint128(), 10, TxPayloadBinaryType, []byte("1"), TransactionGasPrice, gasLimit)
   176  	tx2, _ := NewTransaction(bc.ChainID(), other, &Address{[]byte("to")}, util.NewUint128(), 2, TxPayloadBinaryType, []byte("2"), TransactionGasPrice, gasLimit)
   177  	tx3, _ := NewTransaction(bc.ChainID(), from, &Address{[]byte("to")}, util.NewUint128(), 1, TxPayloadBinaryType, []byte("3"), TransactionGasPrice, gasLimit)
   178  	tx4, _ := NewTransaction(bc.ChainID(), from, &Address{[]byte("to")}, util.NewUint128(), 2, TxPayloadBinaryType, []byte("4"), TransactionGasPrice, gasLimit)
   179  	tx5, _ := NewTransaction(bc.ChainID()+1, from, &Address{[]byte("to")}, util.NewUint128(), 0, TxPayloadBinaryType, []byte("5"), TransactionGasPrice, gasLimit)
   180  	tx6, _ := NewTransaction(bc.ChainID(), other, &Address{[]byte("to")}, util.NewUint128(), 1, TxPayloadBinaryType, []byte("6"), heighPrice, gasLimit)
   181  	tx7, _ := NewTransaction(bc.ChainID(), from, &Address{[]byte("to")}, util.NewUint128(), 1, TxPayloadBinaryType, []byte("7"), heighPrice, gasLimit)
   182  
   183  	txs := []*Transaction{tx1, tx2, tx3, tx4, tx5, tx6, tx7}
   184  
   185  	assert.Nil(t, txs[0].Sign(signature1))
   186  	assert.Nil(t, txPool.Push(txs[0]))
   187  	//put dup tx, should fail
   188  	assert.NotNil(t, txPool.Push(txs[0]))
   189  	assert.Nil(t, txs[1].Sign(signature2))
   190  	assert.Nil(t, txPool.Push(txs[1]))
   191  	assert.Nil(t, txs[2].Sign(signature1))
   192  	assert.Nil(t, txPool.Push(txs[2]))
   193  	// put not signed tx, should fail
   194  	assert.NotNil(t, txPool.Push(txs[3]))
   195  	// put tx with different chainID, should fail
   196  	assert.Nil(t, txs[4].Sign(signature1))
   197  	assert.NotNil(t, txPool.Push(txs[4]))
   198  	// put one new, replace txs[1]
   199  	assert.Equal(t, len(txPool.all), 3)
   200  	assert.Nil(t, txs[6].Sign(signature1))
   201  	assert.Nil(t, txPool.Push(txs[6]))
   202  	assert.Equal(t, len(txPool.all), 4)
   203  	// get from: other, nonce: 1, data: "da"
   204  	tx := txPool.Pop()
   205  	assert.Equal(t, txs[6].data.Payload, tx.data.Payload)
   206  	// put one new
   207  	assert.Equal(t, len(txPool.all), 3)
   208  	assert.Nil(t, txs[5].Sign(signature2))
   209  	assert.Nil(t, txPool.Push(txs[5]))
   210  	assert.Equal(t, len(txPool.all), 4)
   211  	// get 2 txs, txs[5], txs[0]
   212  	tx = txPool.Pop()
   213  	assert.Equal(t, txs[5].from.address, tx.from.address)
   214  	assert.Equal(t, txs[5].Nonce(), tx.Nonce())
   215  	assert.Equal(t, txs[5].data, tx.data)
   216  	assert.Equal(t, txPool.Empty(), false)
   217  	txPool.Pop()
   218  	txPool.Pop()
   219  	txPool.Pop()
   220  	assert.Equal(t, txPool.Empty(), true)
   221  	assert.Nil(t, txPool.Pop())
   222  }
   223  
   224  func TestGasConfig(t *testing.T) {
   225  	txPool, _ := NewTransactionPool(3)
   226  	txPool.SetGasConfig(nil, nil)
   227  	assert.Equal(t, txPool.minGasPrice, TransactionGasPrice)
   228  	assert.Equal(t, txPool.maxGasLimit, TransactionMaxGas)
   229  	gasPrice, _ := util.NewUint128FromInt(1)
   230  	gasLimit, _ := util.NewUint128FromInt(1)
   231  	txPool.SetGasConfig(gasPrice, gasLimit)
   232  	assert.Equal(t, txPool.minGasPrice, gasPrice)
   233  	assert.Equal(t, txPool.maxGasLimit, gasLimit)
   234  }
   235  
   236  func TestPushTxs(t *testing.T) {
   237  	ks := keystore.DefaultKS
   238  	priv1 := secp256k1.GeneratePrivateKey()
   239  	pubdata1, _ := priv1.PublicKey().Encoded()
   240  	from, _ := NewAddressFromPublicKey(pubdata1)
   241  	ks.SetKey(from.String(), priv1, []byte("passphrase"))
   242  	ks.Unlock(from.String(), []byte("passphrase"), time.Second*60*60*24*365)
   243  	key1, _ := ks.GetUnlocked(from.String())
   244  	signature1, _ := crypto.NewSignature(keystore.SECP256K1)
   245  	signature1.InitSign(key1.(keystore.PrivateKey))
   246  
   247  	priv2 := secp256k1.GeneratePrivateKey()
   248  	pubdata2, _ := priv2.PublicKey().Encoded()
   249  	to, _ := NewAddressFromPublicKey(pubdata2)
   250  	ks.SetKey(to.String(), priv2, []byte("passphrase"))
   251  	ks.Unlock(to.String(), []byte("passphrase"), time.Second*60*60*24*365)
   252  	key2, _ := ks.GetUnlocked(to.String())
   253  	signature2, _ := crypto.NewSignature(keystore.SECP256K1)
   254  	signature2.InitSign(key2.(keystore.PrivateKey))
   255  
   256  	neb := testNeb(t)
   257  	bc := neb.chain
   258  	txPool := bc.txPool
   259  	txPool.setBlockChain(bc)
   260  	txPool.setEventEmitter(bc.eventEmitter)
   261  	uint128Number1, _ := util.NewUint128FromInt(1)
   262  	MaxGasPlus1, _ := TransactionMaxGas.Add(uint128Number1)
   263  	gasPrice, _ := util.NewUint128FromInt(1000000 - 1)
   264  	tx1, err := NewTransaction(bc.ChainID(), from, to, util.NewUint128(), 10, TxPayloadBinaryType, []byte("datadata"), gasPrice, TransactionMaxGas)
   265  	assert.Nil(t, err)
   266  	_, err = NewTransaction(bc.ChainID(), from, to, util.NewUint128(), 10, TxPayloadBinaryType, []byte("datadata"), TransactionGasPrice, MaxGasPlus1)
   267  	assert.Equal(t, err, ErrInvalidGasLimit)
   268  	txs := []*Transaction{tx1}
   269  	assert.Equal(t, txPool.Push(txs[0]), ErrBelowGasPrice)
   270  }
   271  
   272  func TestTransactionPool_Pop(t *testing.T) {
   273  	ks := keystore.DefaultKS
   274  	priv1 := secp256k1.GeneratePrivateKey()
   275  	pubdata1, _ := priv1.PublicKey().Encoded()
   276  	from, _ := NewAddressFromPublicKey(pubdata1)
   277  	ks.SetKey(from.String(), priv1, []byte("passphrase"))
   278  	ks.Unlock(from.String(), []byte("passphrase"), time.Second*60*60*24*365)
   279  	key1, _ := ks.GetUnlocked(from.String())
   280  	signature1, _ := crypto.NewSignature(keystore.SECP256K1)
   281  	signature1.InitSign(key1.(keystore.PrivateKey))
   282  
   283  	priv2 := secp256k1.GeneratePrivateKey()
   284  	pubdata2, _ := priv2.PublicKey().Encoded()
   285  	other, _ := NewAddressFromPublicKey(pubdata2)
   286  	ks.SetKey(other.String(), priv2, []byte("passphrase"))
   287  	ks.Unlock(other.String(), []byte("passphrase"), time.Second*60*60*24*365)
   288  	key2, _ := ks.GetUnlocked(other.String())
   289  	signature2, _ := crypto.NewSignature(keystore.SECP256K1)
   290  	signature2.InitSign(key2.(keystore.PrivateKey))
   291  
   292  	gasCount, _ := util.NewUint128FromInt(2)
   293  	highPrice, err := TransactionGasPrice.Mul(gasCount)
   294  	assert.Nil(t, err)
   295  	neb := testNeb(t)
   296  	bc := neb.chain
   297  	txPool := bc.txPool
   298  
   299  	assert.Equal(t, highPrice.Cmp(TransactionGasPrice), 1)
   300  	gasLimit, _ := util.NewUint128FromInt(200000)
   301  	tx1, _ := NewTransaction(bc.ChainID(), from, &Address{[]byte("to")}, util.NewUint128(), 3, TxPayloadBinaryType, []byte("1"), TransactionGasPrice, gasLimit)
   302  	tx2, _ := NewTransaction(bc.ChainID(), other, &Address{[]byte("to")}, util.NewUint128(), 2, TxPayloadBinaryType, []byte("2"), highPrice, gasLimit)
   303  	tx3, _ := NewTransaction(bc.ChainID(), from, &Address{[]byte("to")}, util.NewUint128(), 2, TxPayloadBinaryType, []byte("3"), TransactionGasPrice, gasLimit)
   304  	tx4, _ := NewTransaction(bc.ChainID(), from, &Address{[]byte("to")}, util.NewUint128(), 1, TxPayloadBinaryType, []byte("4"), TransactionGasPrice, gasLimit)
   305  	tx5, _ := NewTransaction(bc.ChainID(), other, &Address{[]byte("to")}, util.NewUint128(), 1, TxPayloadBinaryType, []byte("5"), highPrice, gasLimit)
   306  	txs := []*Transaction{tx1, tx2, tx3, tx4, tx5}
   307  
   308  	assert.Nil(t, txs[0].Sign(signature1))
   309  	assert.Nil(t, txPool.Push(txs[0]))
   310  	assert.Nil(t, txs[1].Sign(signature2))
   311  	assert.Nil(t, txPool.Push(txs[1]))
   312  	assert.Nil(t, txs[2].Sign(signature1))
   313  	assert.Nil(t, txPool.Push(txs[2]))
   314  	assert.Nil(t, txs[3].Sign(signature1))
   315  	assert.Nil(t, txPool.Push(txs[3]))
   316  	assert.Nil(t, txs[4].Sign(signature2))
   317  	assert.Nil(t, txPool.Push(txs[4]))
   318  
   319  	tx := txPool.Pop()
   320  	assert.Equal(t, tx.sign, txs[4].sign)
   321  	tx = txPool.Pop()
   322  	assert.Equal(t, tx.sign, txs[1].sign)
   323  	tx = txPool.Pop()
   324  	assert.Equal(t, tx.sign, txs[3].sign)
   325  	tx = txPool.Pop()
   326  	assert.Equal(t, tx.sign, txs[2].sign)
   327  	tx = txPool.Pop()
   328  	assert.Equal(t, tx.sign, txs[0].sign)
   329  }
   330  
   331  func TestTransactionPoolBucketUpdateTimeAndEvict(t *testing.T) {
   332  	ks := keystore.DefaultKS
   333  	priv1 := secp256k1.GeneratePrivateKey()
   334  	pubdata1, _ := priv1.PublicKey().Encoded()
   335  	from, _ := NewAddressFromPublicKey(pubdata1)
   336  	ks.SetKey(from.String(), priv1, []byte("passphrase"))
   337  	ks.Unlock(from.String(), []byte("passphrase"), time.Second*60*60*24*365)
   338  	key1, _ := ks.GetUnlocked(from.String())
   339  	signature1, _ := crypto.NewSignature(keystore.SECP256K1)
   340  	signature1.InitSign(key1.(keystore.PrivateKey))
   341  
   342  	priv2 := secp256k1.GeneratePrivateKey()
   343  	pubdata2, _ := priv2.PublicKey().Encoded()
   344  	other, _ := NewAddressFromPublicKey(pubdata2)
   345  	ks.SetKey(other.String(), priv2, []byte("passphrase"))
   346  	ks.Unlock(other.String(), []byte("passphrase"), time.Second*60*60*24*365)
   347  	key2, _ := ks.GetUnlocked(other.String())
   348  	signature2, _ := crypto.NewSignature(keystore.SECP256K1)
   349  	signature2.InitSign(key2.(keystore.PrivateKey))
   350  
   351  	gasCount, _ := util.NewUint128FromInt(2)
   352  	highPrice, err := TransactionGasPrice.Mul(gasCount)
   353  	assert.Nil(t, err)
   354  	neb := testNeb(t)
   355  	bc := neb.chain
   356  	txPool := bc.txPool
   357  
   358  	assert.Equal(t, highPrice.Cmp(TransactionGasPrice), 1)
   359  	gasLimit, _ := util.NewUint128FromInt(200000)
   360  	tx1, _ := NewTransaction(bc.ChainID(), from, &Address{[]byte("to")}, util.NewUint128(), 3, TxPayloadBinaryType, []byte("1"), TransactionGasPrice, gasLimit)
   361  	tx2, _ := NewTransaction(bc.ChainID(), other, &Address{[]byte("to")}, util.NewUint128(), 2, TxPayloadBinaryType, []byte("2"), highPrice, gasLimit)
   362  	tx3, _ := NewTransaction(bc.ChainID(), from, &Address{[]byte("to")}, util.NewUint128(), 2, TxPayloadBinaryType, []byte("3"), TransactionGasPrice, gasLimit)
   363  	tx4, _ := NewTransaction(bc.ChainID(), from, &Address{[]byte("to")}, util.NewUint128(), 1, TxPayloadBinaryType, []byte("4"), TransactionGasPrice, gasLimit)
   364  	tx5, _ := NewTransaction(bc.ChainID(), other, &Address{[]byte("to")}, util.NewUint128(), 1, TxPayloadBinaryType, []byte("5"), highPrice, gasLimit)
   365  	txs := []*Transaction{tx1, tx2, tx3, tx4, tx5}
   366  
   367  	assert.Nil(t, txs[0].Sign(signature1))
   368  	assert.Nil(t, txPool.Push(txs[0]))
   369  	assert.Nil(t, txs[1].Sign(signature2))
   370  	assert.Nil(t, txPool.Push(txs[1]))
   371  	assert.Nil(t, txs[2].Sign(signature1))
   372  	assert.Nil(t, txPool.Push(txs[2]))
   373  	assert.Nil(t, txs[3].Sign(signature1))
   374  	assert.Nil(t, txPool.Push(txs[3]))
   375  	assert.Nil(t, txs[4].Sign(signature2))
   376  	assert.Nil(t, txPool.Push(txs[4]))
   377  
   378  	// test bucket time is initialized but not updated
   379  	assert.Equal(t, time.Since(txPool.bucketsLastUpdate[txs[0].from.address.Hex()]) < time.Second*5, true)
   380  	assert.Equal(t, txPool.bucketsLastUpdate[txs[0].from.address.Hex()], txPool.bucketsLastUpdate[txs[2].from.address.Hex()])
   381  	assert.Equal(t, txPool.bucketsLastUpdate[txs[0].from.address.Hex()], txPool.bucketsLastUpdate[txs[3].from.address.Hex()])
   382  	assert.Equal(t, time.Since(txPool.bucketsLastUpdate[txs[1].from.address.Hex()]) < time.Second*5, true)
   383  	assert.Equal(t, txPool.bucketsLastUpdate[txs[1].from.address.Hex()], txPool.bucketsLastUpdate[txs[4].from.address.Hex()])
   384  	assert.NotNil(t, txPool.all[txs[0].hash.Hex()])
   385  	assert.NotNil(t, txPool.all[txs[2].hash.Hex()])
   386  	assert.NotNil(t, txPool.all[txs[3].hash.Hex()])
   387  
   388  	txPool.bucketsLastUpdate[txs[0].from.address.Hex()] = time.Now().Add(time.Minute * -89)
   389  	txPool.evictExpiredTransactions()
   390  	assert.NotNil(t, txPool.all[txs[0].hash.Hex()])
   391  	assert.NotNil(t, txPool.all[txs[2].hash.Hex()])
   392  	assert.NotNil(t, txPool.all[txs[3].hash.Hex()])
   393  	_, ok := txPool.buckets[txs[0].from.address.Hex()]
   394  	assert.Equal(t, ok, true)
   395  	_, ok = txPool.bucketsLastUpdate[txs[0].from.address.Hex()]
   396  	assert.Equal(t, ok, true)
   397  
   398  	txPool.bucketsLastUpdate[txs[0].from.address.Hex()] = time.Now().Add(time.Minute * -91)
   399  	txPool.evictExpiredTransactions()
   400  	assert.Nil(t, txPool.all[txs[0].hash.Hex()])
   401  	assert.Nil(t, txPool.all[txs[2].hash.Hex()])
   402  	assert.Nil(t, txPool.all[txs[3].hash.Hex()])
   403  	assert.NotNil(t, txPool.all[txs[1].hash.Hex()])
   404  	assert.NotNil(t, txPool.all[txs[4].hash.Hex()])
   405  
   406  	_, ok = txPool.buckets[txs[0].from.address.Hex()]
   407  	assert.Equal(t, ok, false)
   408  	_, ok = txPool.bucketsLastUpdate[txs[0].from.address.Hex()]
   409  	assert.Equal(t, ok, false)
   410  
   411  }