Skip to content

Commit 81ceac1

Browse files
committed
Merge pull request #1209 from obscuren/txpool_test_and_pending_fix
core: added a test for missing nonces
2 parents 55b7c14 + 5245bd7 commit 81ceac1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

core/transaction_pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func (pool *TxPool) checkQueue() {
331331
// current account nonce.
332332
sort.Sort(addq)
333333
for _, e := range addq {
334-
if e.AccountNonce > curnonce+1 {
334+
if e.AccountNonce > curnonce {
335335
break
336336
}
337337
delete(txs, e.hash)

core/transaction_pool_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,26 @@ func TestTransactionDoubleNonce(t *testing.T) {
201201
t.Error("expected 2 pending txs. Got", len(pool.pending))
202202
}
203203
}
204+
205+
func TestMissingNonce(t *testing.T) {
206+
pool, key := setupTxPool()
207+
addr := crypto.PubkeyToAddress(key.PublicKey)
208+
pool.currentState().AddBalance(addr, big.NewInt(100000000000000))
209+
tx := transaction()
210+
tx.AccountNonce = 1
211+
tx.GasLimit = big.NewInt(100000)
212+
tx.SignECDSA(key)
213+
214+
err := pool.add(tx)
215+
if err != nil {
216+
t.Error("didn't expect error", err)
217+
}
218+
219+
if len(pool.pending) != 0 {
220+
t.Error("expected 0 pending transactions, got", len(pool.pending))
221+
}
222+
223+
if len(pool.queue[addr]) != 1 {
224+
t.Error("expected 1 queued transaction, got", len(pool.queue[addr]))
225+
}
226+
}

0 commit comments

Comments
 (0)