From 4ad566a86a313af35ff400c663258038b6c6b5c1 Mon Sep 17 00:00:00 2001 From: Jordan Hrycaj Date: Mon, 4 Apr 2022 09:34:59 +0100 Subject: [PATCH] Test bed for chasing issue #1031 --- tests/test_txpool.nim | 25 ++------- tests/test_txpool/helpers.nim | 21 +++++++- tests/test_txpool2.nim | 96 ++++++++++++++++++++++++++++++++--- 3 files changed, 115 insertions(+), 27 deletions(-) diff --git a/tests/test_txpool.nim b/tests/test_txpool.nim index 209c9e5f1..40462029a 100644 --- a/tests/test_txpool.nim +++ b/tests/test_txpool.nim @@ -133,24 +133,6 @@ proc addOrFlushGroupwise(xp: TxPoolRef; return true -proc findFilePath(file: string): string = - result = "?unknown?" / file - for dir in baseDir: - for repo in repoDir: - let path = dir / repo / file - if path.fileExists: - return path - -proc setTraceLevel = - discard - when defined(chronicles_runtime_filtering) and loggingEnabled: - setLogLevel(LogLevel.TRACE) - -proc setErrorLevel = - discard - when defined(chronicles_runtime_filtering) and loggingEnabled: - setLogLevel(LogLevel.ERROR) - # ------------------------------------------------------------------------------ # Test Runners # ------------------------------------------------------------------------------ @@ -160,7 +142,7 @@ proc runTxLoader(noisy = true; capture = loadSpecs) = elapNoisy = noisy veryNoisy = false # noisy fileInfo = capture.file.splitFile.name.split(".")[0] - filePath = capture.file.findFilePath + filePath = capture.file.findFilePath(baseDir,repoDir).value # Reset/initialise statCount.reset @@ -938,7 +920,10 @@ when isMainModule: noisy.runTxLoader(capture = capts1) noisy.runTxPoolTests - true.runTxPackerTests + noisy.runTxPackerTests + + #runTxPoolCliqueTest() + #runTxPoolPosTest() #noisy.runTxLoader(dir = ".") #noisy.runTxPoolTests diff --git a/tests/test_txpool/helpers.nim b/tests/test_txpool/helpers.nim index 14c44bc6c..8f91b4615 100644 --- a/tests/test_txpool/helpers.nim +++ b/tests/test_txpool/helpers.nim @@ -9,10 +9,11 @@ # according to those terms. import - std/[strformat, sequtils, strutils, times], + std/[os, strformat, sequtils, strutils, times], ../../nimbus/utils/tx_pool/[tx_chain, tx_desc, tx_gauge, tx_item, tx_tabs], ../../nimbus/utils/tx_pool/tx_tasks/[tx_packer, tx_recover], ../replay/[pp, undump], + chronicles, eth/[common, keys], stew/[keyed_queue, sorted_set], stint @@ -195,6 +196,24 @@ proc say*(noisy = false; pfx = "***"; args: varargs[string, `$`]) = else: echo pfx, args.toSeq.join +proc setTraceLevel* = + discard + when defined(chronicles_runtime_filtering) and loggingEnabled: + setLogLevel(LogLevel.TRACE) + +proc setErrorLevel* = + discard + when defined(chronicles_runtime_filtering) and loggingEnabled: + setLogLevel(LogLevel.ERROR) + +proc findFilePath*(file: string; + baseDir, repoDir: openArray[string]): Result[string,void] = + for dir in baseDir: + for repo in repoDir: + let path = dir / repo / file + if path.fileExists: + return ok(path) + # ------------------------------------------------------------------------------ # End # ------------------------------------------------------------------------------ diff --git a/tests/test_txpool2.nim b/tests/test_txpool2.nim index 5bfb7cf1e..386e6d07f 100644 --- a/tests/test_txpool2.nim +++ b/tests/test_txpool2.nim @@ -1,7 +1,7 @@ import - std/[os, strutils, math, tables, options], + std/[strutils, math, tables, options, times], eth/[trie/db, keys, common, trie/hexary], - stew/byteutils, nimcrypto, unittest2, + stew/[byteutils, results], nimcrypto, unittest2, ../nimbus/db/[db_chain, state_db], ../nimbus/p2p/chain, ../nimbus/p2p/clique/[clique_sealer, clique_desc], @@ -11,8 +11,9 @@ import ./macro_assembler const - baseFolder = "tests" / "customgenesis" - genesisFile = baseFolder / "merge.json" + baseDir = [".", "tests"] + repoDir = [".", "customgenesis"] + genesisFile = "merge.json" type TestEnv = object @@ -69,7 +70,7 @@ proc initEnv(ttd: Option[UInt256] = none(UInt256)): TestEnv = var conf = makeConfig(@[ "--engine-signer:658bdf435d810c91414ec09147daa6db62406379", - "--custom-network:" & genesisFile + "--custom-network:" & genesisFile.findFilePath(baseDir,repoDir).value ]) conf.networkParams.genesis.alloc[recipient] = GenesisAccount( @@ -230,4 +231,87 @@ proc runTxPoolPosTest*() = let bal = sdb.getBalance(feeRecipient) check not bal.isZero -runTxPoolPosTest() \ No newline at end of file +#runTxPoolPosTest() + + +proc runTxMissingTxNoce*(noisy = true) = + ## see github.com/status-im/nimbus-eth1/issues/1031 + + suite "TxPool: Issue #1031": + test "Reproducing issue #1031": + var + env = initEnv(some(100.u256)) + xp = env.xp + chainDB = env.chainDB + chain = env.chain + head = chainDB.getCanonicalHead() + timestamp = head.timestamp + + const + txPerblock = 20 + numBlocks = 10 + + # setTraceLevel() + + block processBlocks: + for n in 0..