github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/core/tx_list_test.go (about) 1 package core 2 3 import ( 4 "math/rand" 5 "testing" 6 7 "github.com/quickchainproject/quickchain/core/types" 8 "github.com/quickchainproject/quickchain/crypto" 9 ) 10 11 // Tests that transactions can be added to strict lists and list contents and 12 // nonce boundaries are correctly maintained. 13 func TestStrictTxListAdd(t *testing.T) { 14 // Generate a list of transactions to insert 15 key, _ := crypto.GenerateKey() 16 17 txs := make(types.Transactions, 1024) 18 for i := 0; i < len(txs); i++ { 19 txs[i] = transaction(uint64(i), 0, key) 20 } 21 // Insert the transactions in a random order 22 list := newTxList(true) 23 for _, v := range rand.Perm(len(txs)) { 24 list.Add(txs[v], DefaultTxPoolConfig.PriceBump) 25 } 26 // Verify internal state 27 if len(list.txs.items) != len(txs) { 28 t.Errorf("transaction count mismatch: have %d, want %d", len(list.txs.items), len(txs)) 29 } 30 for i, tx := range txs { 31 if list.txs.items[tx.Nonce()] != tx { 32 t.Errorf("item %d: transaction mismatch: have %v, want %v", i, list.txs.items[tx.Nonce()], tx) 33 } 34 } 35 }