diff options
author | obscuren <geffobscura@gmail.com> | 2015-01-02 19:09:38 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-01-02 19:09:38 +0800 |
commit | 48d2a8b8ee9621810a988e3561e4213749c54da7 (patch) | |
tree | cbce2a2427287116420e074f4a5ecd8d4f35fbbc /core/transaction_pool_test.go | |
parent | 477a6d426cd798f036df85b15d73935060503a48 (diff) | |
download | dexon-48d2a8b8ee9621810a988e3561e4213749c54da7.tar dexon-48d2a8b8ee9621810a988e3561e4213749c54da7.tar.gz dexon-48d2a8b8ee9621810a988e3561e4213749c54da7.tar.bz2 dexon-48d2a8b8ee9621810a988e3561e4213749c54da7.tar.lz dexon-48d2a8b8ee9621810a988e3561e4213749c54da7.tar.xz dexon-48d2a8b8ee9621810a988e3561e4213749c54da7.tar.zst dexon-48d2a8b8ee9621810a988e3561e4213749c54da7.zip |
Refactored tx pool and added extra fields to block
* chain manager sets td on block + td output w/ String
* added tx pool tests for removing/adding/validating
* tx pool now uses a set for txs instead of list.List
Diffstat (limited to 'core/transaction_pool_test.go')
-rw-r--r-- | core/transaction_pool_test.go | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/core/transaction_pool_test.go b/core/transaction_pool_test.go new file mode 100644 index 000000000..296c6bd8a --- /dev/null +++ b/core/transaction_pool_test.go @@ -0,0 +1,82 @@ +package core + +import ( + "crypto/ecdsa" + "testing" + + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/state" +) + +// State query interface +type stateQuery struct{} + +func (self stateQuery) GetAccount(addr []byte) *state.StateObject { + return state.NewStateObject(addr) +} + +// State query interface +type invalidStateQuery struct{} + +func (self invalidStateQuery) GetAccount(addr []byte) *state.StateObject { + o := state.NewStateObject(addr) + o.Nonce++ + return o +} + +func transaction() *types.Transaction { + return types.NewTransactionMessage(make([]byte, 20), ethutil.Big0, ethutil.Big0, ethutil.Big0, nil) +} + +func setup() (*TxPool, *ecdsa.PrivateKey) { + var m event.TypeMux + key, _ := crypto.GenerateKey() + return NewTxPool(stateQuery{}, &m), key +} + +func TestTxAdding(t *testing.T) { + pool, key := setup() + tx1 := transaction() + tx1.SignECDSA(key) + err := pool.Add(tx1) + if err != nil { + t.Error(err) + } + + err = pool.Add(tx1) + if err == nil { + t.Error("added tx twice") + } +} + +func TestAddInvalidTx(t *testing.T) { + pool, _ := setup() + tx1 := transaction() + err := pool.Add(tx1) + if err == nil { + t.Error("expected error") + } +} + +func TestRemoveSet(t *testing.T) { + pool, _ := setup() + tx1 := transaction() + pool.pool.Add(tx1) + pool.RemoveSet(types.Transactions{tx1}) + if pool.Size() > 0 { + t.Error("expected pool size to be 0") + } +} + +func TestRemoveInvalid(t *testing.T) { + pool, _ := setup() + tx1 := transaction() + pool.pool.Add(tx1) + pool.RemoveInvalid(invalidStateQuery{}) + if pool.Size() > 0 { + t.Error("expected pool size to be 0") + } +} |