aboutsummaryrefslogtreecommitdiffstats
path: root/core/transaction_pool_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-09 02:47:32 +0800
committerobscuren <geffobscura@gmail.com>2015-04-09 02:47:32 +0800
commit6184781b49242b8029522612ad94cd45b508abc1 (patch)
tree4e8822e2000a885018e712b9cefb2a2ac3a512ca /core/transaction_pool_test.go
parenta7750c929b926d164195fd4f7a7e2b4642c66173 (diff)
downloaddexon-6184781b49242b8029522612ad94cd45b508abc1.tar
dexon-6184781b49242b8029522612ad94cd45b508abc1.tar.gz
dexon-6184781b49242b8029522612ad94cd45b508abc1.tar.bz2
dexon-6184781b49242b8029522612ad94cd45b508abc1.tar.lz
dexon-6184781b49242b8029522612ad94cd45b508abc1.tar.xz
dexon-6184781b49242b8029522612ad94cd45b508abc1.tar.zst
dexon-6184781b49242b8029522612ad94cd45b508abc1.zip
Improved transaction pool
The transaction pool will now some easily be able to pre determine the validity of a transaction by checking the following: * Account existst * gas limit higher than the instrinsic gas * enough funds to pay upfront costs * nonce check
Diffstat (limited to 'core/transaction_pool_test.go')
-rw-r--r--core/transaction_pool_test.go97
1 files changed, 30 insertions, 67 deletions
diff --git a/core/transaction_pool_test.go b/core/transaction_pool_test.go
index abdc2709f..b7486adb3 100644
--- a/core/transaction_pool_test.go
+++ b/core/transaction_pool_test.go
@@ -13,87 +13,50 @@ import (
"github.com/ethereum/go-ethereum/event"
)
-// State query interface
-type stateQuery struct{ db common.Database }
-
-func SQ() stateQuery {
- db, _ := ethdb.NewMemDatabase()
- return stateQuery{db: db}
-}
-
-func (self stateQuery) GetAccount(addr []byte) *state.StateObject {
- return state.NewStateObject(common.BytesToAddress(addr), self.db)
-}
-
func transaction() *types.Transaction {
- return types.NewTransactionMessage(common.Address{}, common.Big0, common.Big0, common.Big0, nil)
+ return types.NewTransactionMessage(common.Address{}, big.NewInt(100), big.NewInt(100), big.NewInt(100), nil)
}
-func setup() (*TxPool, *ecdsa.PrivateKey) {
+func setupTxPool() (*TxPool, *ecdsa.PrivateKey) {
+ db, _ := ethdb.NewMemDatabase()
+ statedb := state.New(common.Hash{}, db)
+
var m event.TypeMux
key, _ := crypto.GenerateKey()
- return NewTxPool(&m), key
+ return NewTxPool(&m, func() *state.StateDB { return statedb }), 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 TestInvalidTransactions(t *testing.T) {
+ pool, key := setupTxPool()
-func TestAddInvalidTx(t *testing.T) {
- pool, _ := setup()
- tx1 := transaction()
- err := pool.Add(tx1)
- if err == nil {
- t.Error("expected error")
+ tx := transaction()
+ tx.SignECDSA(key)
+ err := pool.Add(tx)
+ if err != ErrNonExistentAccount {
+ t.Error("expected", ErrNonExistentAccount)
}
-}
-func TestRemoveSet(t *testing.T) {
- pool, _ := setup()
- tx1 := transaction()
- pool.addTx(tx1)
- pool.RemoveSet(types.Transactions{tx1})
- if pool.Size() > 0 {
- t.Error("expected pool size to be 0")
+ from, _ := tx.From()
+ pool.currentState().AddBalance(from, big.NewInt(1))
+ err = pool.Add(tx)
+ if err != ErrInsufficientFunds {
+ t.Error("expected", ErrInsufficientFunds)
}
-}
-func TestRemoveInvalid(t *testing.T) {
- pool, key := setup()
- tx1 := transaction()
- pool.addTx(tx1)
- pool.RemoveInvalid(SQ())
- if pool.Size() > 0 {
- t.Error("expected pool size to be 0")
+ pool.currentState().AddBalance(from, big.NewInt(100*100))
+ err = pool.Add(tx)
+ if err != ErrIntrinsicGas {
+ t.Error("expected", ErrIntrinsicGas)
}
- tx1.SetNonce(1)
- tx1.SignECDSA(key)
- pool.addTx(tx1)
- pool.RemoveInvalid(SQ())
- if pool.Size() != 1 {
- t.Error("expected pool size to be 1, is", pool.Size())
- }
-}
+ pool.currentState().SetNonce(from, 1)
+ pool.currentState().AddBalance(from, big.NewInt(0xffffffffffffff))
+ tx.GasLimit = big.NewInt(100000)
+ tx.Price = big.NewInt(1)
+ tx.SignECDSA(key)
-func TestInvalidSender(t *testing.T) {
- pool, _ := setup()
- tx := new(types.Transaction)
- tx.R = new(big.Int)
- tx.S = new(big.Int)
- err := pool.ValidateTransaction(tx)
- if err != ErrInvalidSender {
- t.Errorf("expected %v, got %v", ErrInvalidSender, err)
+ err = pool.Add(tx)
+ if err != ErrImpossibleNonce {
+ t.Error("expected", ErrImpossibleNonce)
}
}