Skip to content

Commit

Permalink
core: added a test for missing nonces
Browse files Browse the repository at this point in the history
This test showed the logic in the queue was slightly flawed sending out
transactions to its peer it couldn't even resolve itself.
  • Loading branch information
obscuren committed Jun 8, 2015
1 parent 55b7c14 commit 5245bd7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/transaction_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (pool *TxPool) checkQueue() {
// current account nonce.
sort.Sort(addq)
for _, e := range addq {
if e.AccountNonce > curnonce+1 {
if e.AccountNonce > curnonce {
break
}
delete(txs, e.hash)
Expand Down
23 changes: 23 additions & 0 deletions core/transaction_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,26 @@ func TestTransactionDoubleNonce(t *testing.T) {
t.Error("expected 2 pending txs. Got", len(pool.pending))
}
}

func TestMissingNonce(t *testing.T) {
pool, key := setupTxPool()
addr := crypto.PubkeyToAddress(key.PublicKey)
pool.currentState().AddBalance(addr, big.NewInt(100000000000000))
tx := transaction()
tx.AccountNonce = 1
tx.GasLimit = big.NewInt(100000)
tx.SignECDSA(key)

err := pool.add(tx)
if err != nil {
t.Error("didn't expect error", err)
}

if len(pool.pending) != 0 {
t.Error("expected 0 pending transactions, got", len(pool.pending))
}

if len(pool.queue[addr]) != 1 {
t.Error("expected 1 queued transaction, got", len(pool.queue[addr]))
}
}

0 comments on commit 5245bd7

Please sign in to comment.