77 ../ nimbus/ core/ clique/ [clique_sealer, clique_desc],
88 ../ nimbus/ [config, transaction, constants],
99 ../ nimbus/ core/ tx_pool,
10+ ../ nimbus/ core/ tx_pool/ tx_item,
1011 ../ nimbus/ core/ casper,
1112 ../ nimbus/ core/ executor,
1213 ../ nimbus/ common/ common,
@@ -70,6 +71,11 @@ proc makeTx*(t: var TestEnv, recipient: EthAddress, amount: UInt256, payload: op
7071 inc t.nonce
7172 signTransaction (tx, t.vaultKey, t.chainId, eip155 = true )
7273
74+ proc signTxWithNonce (t: TestEnv , tx: Transaction , nonce: AccountNonce ): Transaction =
75+ var tx = tx
76+ tx.nonce = nonce
77+ signTransaction (tx, t.vaultKey, t.chainId, eip155 = true )
78+
7379proc initEnv (envFork: HardFork ): TestEnv =
7480 var
7581 conf = makeConfig (@ [
@@ -265,12 +271,18 @@ proc runTxPoolPosTest*() =
265271 let bal = sdb.getBalance (feeRecipient)
266272 check not bal.isZero
267273
274+ proc inPoolAndOk (txPool: TxPoolRef , txHash: Hash256 ): bool =
275+ let res = txPool.getItem (txHash)
276+ if res.isErr: return false
277+ res.get ().reject == txInfoOk
278+
268279proc runTxPoolBlobhashTest * () =
269280 var
270281 env = initEnv (Cancun )
271282
272283 var
273- tx = env.makeTx (recipient, amount)
284+ tx1 = env.makeTx (recipient, amount)
285+ tx2 = env.makeTx (recipient, amount)
274286 xp = env.xp
275287 com = env.com
276288 chain = env.chain
@@ -279,14 +291,16 @@ proc runTxPoolBlobhashTest*() =
279291
280292 suite " Test TxPool with blobhash block" :
281293 test " TxPool addLocal" :
282- let res = xp.addLocal (tx , force = true )
294+ let res = xp.addLocal (tx1 , force = true )
283295 check res.isOk
284296 if res.isErr:
285297 debugEcho res.error
286298 return
299+ let res2 = xp.addLocal (tx2, force = true )
300+ check res2.isOk
287301
288302 test " TxPool jobCommit" :
289- check xp.nItems.total == 1
303+ check xp.nItems.total == 2
290304
291305 test " TxPool ethBlock" :
292306 com.pos.prevRandao = prevRandao
@@ -302,7 +316,7 @@ proc runTxPoolBlobhashTest*() =
302316 uncles: blk.uncles,
303317 withdrawals: some [seq [Withdrawal ]](@ [])
304318 )
305- check blk.txs.len == 1
319+ check blk.txs.len == 2
306320
307321 test " Blobhash persistBlocks" :
308322 let rr = chain.persistBlocks ([blk.header], [body])
@@ -321,6 +335,21 @@ proc runTxPoolBlobhashTest*() =
321335 let bal = sdb.getBalance (feeRecipient)
322336 check not bal.isZero
323337
338+ test " add tx with nonce too low" :
339+ let
340+ tx3 = env.makeTx (recipient, amount)
341+ tx4 = env.signTxWithNonce (tx3, AccountNonce (env.nonce- 2 ))
342+ xp = env.xp
343+
344+ check xp.smartHead (blk.header)
345+ let res = xp.addLocal (tx4, force = true )
346+ check res.isOk
347+ if res.isErr:
348+ debugEcho res.error
349+ return
350+
351+ check inPoolAndOk (xp, rlpHash (tx4)) == false
352+
324353proc runTxHeadDelta * (noisy = true ) =
325354 # # see github.com/status-im/nimbus-eth1/issues/1031
326355
@@ -399,6 +428,6 @@ when isMainModule:
399428 runTxPoolCliqueTest ()
400429 runTxPoolPosTest ()
401430 runTxPoolBlobhashTest ()
402- noisy.runTxHeadDelta
431+ # noisy.runTxHeadDelta
403432
404433# End
0 commit comments