github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/core/tx_list_test.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:35</date> 10 //</624450080845336576> 11 12 13 package core 14 15 import ( 16 "math/rand" 17 "testing" 18 19 "github.com/ethereum/go-ethereum/core/types" 20 "github.com/ethereum/go-ethereum/crypto" 21 ) 22 23 //测试可以将事务添加到严格的列表和列表内容以及 24 //正确维护当前边界。 25 func TestStrictTxListAdd(t *testing.T) { 26 //生成要插入的事务列表 27 key, _ := crypto.GenerateKey() 28 29 txs := make(types.Transactions, 1024) 30 for i := 0; i < len(txs); i++ { 31 txs[i] = transaction(uint64(i), 0, key) 32 } 33 //按随机顺序插入交易记录 34 list := newTxList(true) 35 for _, v := range rand.Perm(len(txs)) { 36 list.Add(txs[v], DefaultTxPoolConfig.PriceBump) 37 } 38 //验证内部状态 39 if len(list.txs.items) != len(txs) { 40 t.Errorf("transaction count mismatch: have %d, want %d", len(list.txs.items), len(txs)) 41 } 42 for i, tx := range txs { 43 if list.txs.items[tx.Nonce()] != tx { 44 t.Errorf("item %d: transaction mismatch: have %v, want %v", i, list.txs.items[tx.Nonce()], tx) 45 } 46 } 47 } 48