From ed01201233c8b3ebcfce99a4798a4a947acdf600 Mon Sep 17 00:00:00 2001 From: andri lim Date: Mon, 23 Sep 2019 22:52:57 +0700 Subject: [PATCH] fixes fork choice --- BlockchainTests.md | 10 +++++----- tests/test_blockchain_json.nim | 15 ++++++--------- tests/test_generalstate_failing.nim | 9 --------- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/BlockchainTests.md b/BlockchainTests.md index a399ab805..0e08697ff 100644 --- a/BlockchainTests.md +++ b/BlockchainTests.md @@ -50,13 +50,13 @@ OK: 2/2 Fail: 0/2 Skip: 0/2 ```diff + CallContractThatCreateContractBeforeAndAfterSwitchover.json OK + ContractCreationFailsOnHomestead.json OK - HomesteadOverrideFrontier.json Skip ++ HomesteadOverrideFrontier.json OK + UncleFromFrontierInHomestead.json OK + UnclePopulation.json OK - blockChainFrontierWithLargerTDvsHomesteadBlockchain.json Skip - blockChainFrontierWithLargerTDvsHomesteadBlockchain2.json Skip ++ blockChainFrontierWithLargerTDvsHomesteadBlockchain.json OK ++ blockChainFrontierWithLargerTDvsHomesteadBlockchain2.json OK ``` -OK: 4/7 Fail: 0/7 Skip: 3/7 +OK: 7/7 Fail: 0/7 Skip: 0/7 ## bcGasPricerTest ```diff + RPC_API_Test.json OK @@ -404,4 +404,4 @@ OK: 20/20 Fail: 0/20 Skip: 0/20 OK: 5/5 Fail: 0/5 Skip: 0/5 ---TOTAL--- -OK: 266/318 Fail: 0/318 Skip: 52/318 +OK: 269/318 Fail: 0/318 Skip: 49/318 diff --git a/tests/test_blockchain_json.nim b/tests/test_blockchain_json.nim index 7677847a8..604d58c34 100644 --- a/tests/test_blockchain_json.nim +++ b/tests/test_blockchain_json.nim @@ -329,7 +329,7 @@ proc checkPOW(blockNumber: Uint256, miningHash, mixHash: Hash256, nonce: BlockNo let cache = blockNumber.getCache() let size = getDataSize(blockNumber) - let miningOutput = hashimotoLight(size, cache, miningHash, uint64.fromBytesBE(nonce)) + let miningOutput = hashimotoLight(size, cache, miningHash, uint64.fromBytesBE(nonce)) if miningOutput.mixDigest != mixHash: echo "actual: ", miningOutput.mixDigest echo "expected: ", mixHash @@ -516,9 +516,10 @@ proc importBlock(tester: var Tester, chainDB: BaseChainDB, discard chainDB.persistHeaderToDb(preminedBlock.header) proc applyFixtureBlockToChain(tester: var Tester, tb: TesterBlock, - chainDB: BaseChainDB, fork: Fork, checkSeal, validation = true): (PlainBlock, PlainBlock, Blob) = + chainDB: BaseChainDB, checkSeal, validation = true): (PlainBlock, PlainBlock, Blob) = var preminedBlock = rlp.decode(tb.headerRLP, PlainBlock) + fork = vmConfigToFork(tester.vmConfig, preminedBlock.header.blockNumber) minedBlock = tester.importBlock(chainDB, preminedBlock, fork, checkSeal, validation) rlpEncodedMinedBlock = rlp.encode(minedBlock) result = (preminedBlock, minedBlock, rlpEncodedMinedBlock) @@ -532,22 +533,18 @@ proc runTester(tester: var Tester, chainDB: BaseChainDB, testStatusIMPL: var Tes check chainDB.getCanonicalHead().blockHash == tester.genesisBlockHeader.blockHash let checkSeal = tester.shouldCheckSeal - for testerBlock in tester.blocks: + for idx, testerBlock in tester.blocks: let shouldBeGoodBlock = testerBlock.blockHeader.isSome if shouldBeGoodBlock: - let blockNumber = testerBlock.blockHeader.get().blockNumber - let fork = vmConfigToFork(tester.vmConfig, blockNumber) - let (preminedBlock, minedBlock, blockRlp) = tester.applyFixtureBlockToChain( - testerBlock, chainDB, fork, checkSeal, validation = false) # we manually validate below + testerBlock, chainDB, checkSeal, validation = false) # we manually validate below check validateBlock(chainDB, preminedBlock, checkSeal) == true else: var noError = true try: - let fork = vmConfigToFork(tester.vmConfig, 1.u256) let (_, _, _) = tester.applyFixtureBlockToChain(testerBlock, - chainDB, fork, checkSeal, validation = true) + chainDB, checkSeal, validation = true) except ValueError, ValidationError, BlockNotFound, MalformedRlpError, RlpTypeMismatch: # failure is expected on this bad block noError = false diff --git a/tests/test_generalstate_failing.nim b/tests/test_generalstate_failing.nim index d30952142..654b937d3 100644 --- a/tests/test_generalstate_failing.nim +++ b/tests/test_generalstate_failing.nim @@ -73,14 +73,5 @@ func allowedFailingGeneralStateTest*(folder, name: string): bool = "randomStatetest623BC.json", "randomStatetest76BC.json", "randomStatetest79BC.json", - - # bcFrontierToHomestead - "HomesteadOverrideFrontier.json", - "blockChainFrontierWithLargerTDvsHomesteadBlockchain.json", - "blockChainFrontierWithLargerTDvsHomesteadBlockchain2.json", - - # bcInvalidHeaderTest - #"DifficultyIsZero.json", - #"wrongDifficulty.json", ] result = name in allowedFailingGeneralStateTests