core: added fork test & double nonce test

release/0.9.36
obscuren 10 years ago
parent 0f51ee6c88
commit 912cf7ba04
  1. 10
      core/transaction_pool.go
  2. 49
      core/transaction_pool_test.go

@ -68,6 +68,14 @@ func (pool *TxPool) Start() {
pool.events = pool.eventMux.Subscribe(ChainEvent{})
for _ = range pool.events.Chan() {
pool.mu.Lock()
pool.resetState()
pool.mu.Unlock()
}
}
func (pool *TxPool) resetState() {
pool.state = state.ManageState(pool.currentState())
// validate the pool of pending transactions, this will remove
@ -89,8 +97,6 @@ func (pool *TxPool) Start() {
// Check the queue and move transactions over to the pending if possible
// or remove those that have become invalid
pool.checkQueue()
pool.mu.Unlock()
}
}
func (pool *TxPool) Stop() {

@ -152,3 +152,52 @@ func TestNegativeValue(t *testing.T) {
t.Error("expected", ErrNegativeValue, "got", err)
}
}
func TestTransactionChainFork(t *testing.T) {
pool, key := setupTxPool()
addr := crypto.PubkeyToAddress(key.PublicKey)
pool.currentState().AddBalance(addr, big.NewInt(100000000000000))
tx := transaction()
tx.GasLimit = big.NewInt(100000)
tx.SignECDSA(key)
err := pool.add(tx)
if err != nil {
t.Error("didn't expect error", err)
}
pool.RemoveTransactions([]*types.Transaction{tx})
// reset the pool's internal state
pool.resetState()
err = pool.add(tx)
if err != nil {
t.Error("didn't expect error", err)
}
}
func TestTransactionDoubleNonce(t *testing.T) {
pool, key := setupTxPool()
addr := crypto.PubkeyToAddress(key.PublicKey)
pool.currentState().AddBalance(addr, big.NewInt(100000000000000))
tx := transaction()
tx.GasLimit = big.NewInt(100000)
tx.SignECDSA(key)
err := pool.add(tx)
if err != nil {
t.Error("didn't expect error", err)
}
tx2 := transaction()
tx2.GasLimit = big.NewInt(1000000)
tx2.SignECDSA(key)
err = pool.add(tx2)
if err != nil {
t.Error("didn't expect error", err)
}
if len(pool.pending) != 2 {
t.Error("expected 2 pending txs. Got", len(pool.pending))
}
}

Loading…
Cancel
Save