diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-07-01 23:59:55 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-09-02 19:12:03 +0800 |
commit | 0ef327bbee79c01a69ba59258acc6ce3a48bc288 (patch) | |
tree | 1d43179977d96c5ca7de85e0727cfa69dbb230ed /core/tx_list_test.go | |
parent | 795b70423eac7180ab85b735f64aae9d6a10449d (diff) | |
download | go-tangerine-0ef327bbee79c01a69ba59258acc6ce3a48bc288.tar go-tangerine-0ef327bbee79c01a69ba59258acc6ce3a48bc288.tar.gz go-tangerine-0ef327bbee79c01a69ba59258acc6ce3a48bc288.tar.bz2 go-tangerine-0ef327bbee79c01a69ba59258acc6ce3a48bc288.tar.lz go-tangerine-0ef327bbee79c01a69ba59258acc6ce3a48bc288.tar.xz go-tangerine-0ef327bbee79c01a69ba59258acc6ce3a48bc288.tar.zst go-tangerine-0ef327bbee79c01a69ba59258acc6ce3a48bc288.zip |
core, eth, internal, miner: optimize txpool for quick ops
Diffstat (limited to 'core/tx_list_test.go')
-rw-r--r-- | core/tx_list_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/core/tx_list_test.go b/core/tx_list_test.go new file mode 100644 index 000000000..ea83ca479 --- /dev/null +++ b/core/tx_list_test.go @@ -0,0 +1,58 @@ +// Copyright 2016 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. + +package core + +import ( + "math/big" + "math/rand" + "testing" + + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" +) + +// Tests that transactions can be added to strict lists and list contents and +// nonce boundaries are correctly maintained. +func TestStrictTxListAdd(t *testing.T) { + // Generate a list of transactions to insert + key, _ := crypto.GenerateKey() + + txs := make(types.Transactions, 1024) + for i := 0; i < len(txs); i++ { + txs[i] = transaction(uint64(i), new(big.Int), key) + } + // Insert the transactions in a random order + list := newTxList(true) + for _, v := range rand.Perm(len(txs)) { + list.Add(txs[v]) + } + // Verify internal state + if list.first != 0 { + t.Errorf("lowest nonce mismatch: have %d, want %d", list.first, 0) + } + if int(list.last) != len(txs)-1 { + t.Errorf("highest nonce mismatch: have %d, want %d", list.last, len(txs)-1) + } + if len(list.items) != len(txs) { + t.Errorf("transaction count mismatch: have %d, want %d", len(list.items), len(txs)) + } + for i, tx := range txs { + if list.items[tx.Nonce()] != tx { + t.Errorf("item %d: transaction mismatch: have %v, want %v", i, list.items[tx.Nonce()], tx) + } + } +} |