mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-13 05:44:40 +00:00
allow test_block_witness to run single test
This commit is contained in:
parent
a1a6b7b9c4
commit
692bed176e
@ -2,7 +2,7 @@ import
|
||||
unittest2, os, json, strutils,
|
||||
eth/[common, rlp], eth/trie/[hexary, db, trie_defs],
|
||||
stew/byteutils, faststreams/input_stream,
|
||||
../tests/test_helpers,
|
||||
../tests/[test_helpers, test_config],
|
||||
../nimbus/db/accounts_cache,
|
||||
../stateless/[witness_from_tree, tree_from_witness]
|
||||
|
||||
@ -97,8 +97,38 @@ proc testFixtureGST(node: JsonNode, testStatusIMPL: var TestStatus) =
|
||||
|
||||
fixture["pre"].testBlockWitness(emptyRlpHash, testStatusIMPL)
|
||||
|
||||
#suite "Block Witness":
|
||||
#jsonTest("newBlockChainTests", "witnessBuilderBC", testFixtureBC)
|
||||
|
||||
proc blockWitnessMain*(debugMode = false) =
|
||||
if paramCount() == 0 or not debugMode:
|
||||
# run all test fixtures
|
||||
suite "Block Witness":
|
||||
jsonTest("newBlockChainTests", "witnessBuilderBC", testFixtureBC)
|
||||
suite "Block Witness":
|
||||
jsonTest("GeneralStateTests", "witnessBuilderGST", testFixtureGST)
|
||||
else:
|
||||
# execute single test in debug mode
|
||||
let config = getConfiguration()
|
||||
if config.testSubject.len == 0:
|
||||
echo "missing test subject"
|
||||
quit(QuitFailure)
|
||||
|
||||
let folder = if config.legacy: "GeneralStateTests" else: "newGeneralStateTests"
|
||||
let path = "tests" / "fixtures" / folder
|
||||
let n = json.parseFile(path / config.testSubject)
|
||||
var testStatusIMPL: TestStatus
|
||||
if config.legacy:
|
||||
testFixtureGST(n, testStatusIMPL)
|
||||
else:
|
||||
testFixtureBC(n, testStatusIMPL)
|
||||
|
||||
when isMainModule:
|
||||
var message: string
|
||||
|
||||
## Processing command line arguments
|
||||
if processArguments(message) != Success:
|
||||
echo message
|
||||
quit(QuitFailure)
|
||||
else:
|
||||
if len(message) > 0:
|
||||
echo message
|
||||
quit(QuitSuccess)
|
||||
blockWitnessMain(true)
|
||||
|
@ -1,9 +1,26 @@
|
||||
import
|
||||
randutils, stew/byteutils, random,
|
||||
eth/[common, rlp], eth/trie/[hexary, db],
|
||||
faststreams/input_stream,
|
||||
faststreams/input_stream, nimcrypto/[utils, sysrand],
|
||||
../stateless/[witness_from_tree, tree_from_witness]
|
||||
|
||||
proc randU256(): UInt256 =
|
||||
var bytes: array[32, byte]
|
||||
discard randomBytes(bytes[0].addr, sizeof(result))
|
||||
result = UInt256.fromBytesBE(bytes)
|
||||
|
||||
proc randNonce(): AccountNonce =
|
||||
discard randomBytes(result.addr, sizeof(result))
|
||||
|
||||
proc randHash(): Hash256 =
|
||||
discard randomBytes(result.data[0].addr, sizeof(result))
|
||||
|
||||
proc randAccount(): Account =
|
||||
result.nonce = randNonce()
|
||||
result.balance = randU256()
|
||||
result.codeHash = randHash()
|
||||
result.storageRoot = randHash()
|
||||
|
||||
proc runTest(keyBytes: int, valBytes: int, numPairs: int) =
|
||||
var memDB = newMemoryDB()
|
||||
var trie = initHexaryTrie(memDB)
|
||||
|
@ -1,9 +1,9 @@
|
||||
import
|
||||
stew/[byteutils, endians2],
|
||||
nimcrypto/[keccak, hash], eth/rlp,
|
||||
nimcrypto/[keccak, hash], eth/[common, rlp],
|
||||
eth/trie/[trie_defs, nibbles, db],
|
||||
faststreams/output_stream,
|
||||
./witness_types
|
||||
./witness_types, ../nimbus/constants
|
||||
|
||||
type
|
||||
DB = TrieDatabaseRef
|
||||
@ -42,7 +42,7 @@ proc rlpListToBitmask(r: var Rlp): uint =
|
||||
proc writeU32(wb: var WitnessBuilder, x: uint32) =
|
||||
wb.output.append(toBytesBE(x))
|
||||
|
||||
proc writeNibbles(wb: var WitnessBuilder; n: NibblesSeq) =
|
||||
proc writeNibbles(wb: var WitnessBuilder; n: NibblesSeq, withLen: bool = true) =
|
||||
let nibblesLen = n.len
|
||||
let numBytes = nibblesLen div 2 + nibblesLen mod 2
|
||||
var bytes: array[32, byte]
|
||||
@ -54,6 +54,7 @@ proc writeNibbles(wb: var WitnessBuilder; n: NibblesSeq) =
|
||||
else:
|
||||
bytes[pos div 2] = bytes[pos div 2] or (n[pos] shl 4)
|
||||
|
||||
if withLen:
|
||||
# write nibblesLen
|
||||
wb.output.append(nibblesLen.byte)
|
||||
# write nibbles
|
||||
@ -86,7 +87,7 @@ proc writeBranchNode(wb: var WitnessBuilder, mask: uint, depth: int, node: openA
|
||||
when defined(debugHash):
|
||||
wb.output.append(keccak(node).data)
|
||||
|
||||
proc writeAccountNode(wb: var WitnessBuilder, node: openArray[byte], depth: int) =
|
||||
proc writeAccountNode(wb: var WitnessBuilder, acc: Account, nibbles: NibblesSeq, node: openArray[byte], depth: int) =
|
||||
# write type
|
||||
wb.output.append(AccountNodeType.byte)
|
||||
wb.writeU32(node.len.uint32)
|
||||
@ -95,6 +96,25 @@ proc writeAccountNode(wb: var WitnessBuilder, node: openArray[byte], depth: int)
|
||||
when defined(debugDepth):
|
||||
wb.output.append(depth.byte)
|
||||
|
||||
#EIP170_CODE_SIZE_LIMIT
|
||||
|
||||
doAssert(nibbles.len == 64 - depth)
|
||||
let accountType = if acc.codeHash == blankStringHash or acc.storageRoot == emptyRlpHash: SimpleAccountType
|
||||
else: ExtendedAccountType
|
||||
|
||||
#wb.output.append(accountType.byte)
|
||||
#wb.writeNibbles(nibbles, false)
|
||||
#wb.output.append(acc.address)
|
||||
#wb.output.append(acc.balance.toBytesBE)
|
||||
#wb.output.append(acc.nonce.u256.toBytesBE)
|
||||
|
||||
#if accountType == ExtendedAccountType:
|
||||
|
||||
#0x00 pathnibbles:<Nibbles(64-d)> address:<Address> balance:<Bytes32> nonce:<Bytes32>
|
||||
#0x01 pathnibbles:<Nibbles(64-d)> address:<Address> balance:<Bytes32> nonce:<Bytes32> bytecode:<Bytecode> storage:<Tree_Node(0,1)>
|
||||
|
||||
#<Bytecode> := len:<U32> b:<Byte>^len
|
||||
|
||||
proc writeHashNode(wb: var WitnessBuilder, node: openArray[byte]) =
|
||||
# write type
|
||||
wb.output.append(HashNodeType.byte)
|
||||
@ -107,7 +127,8 @@ proc writeShortNode(wb: var WitnessBuilder, node: openArray[byte], depth: int) =
|
||||
of 2:
|
||||
let (isLeaf, k) = nodeRlp.extensionNodeKey
|
||||
if isLeaf:
|
||||
writeAccountNode(wb, node, depth)
|
||||
let acc = nodeRlp.listElem(1).toBytes.decode(Account)
|
||||
writeAccountNode(wb, acc, k, node, depth)
|
||||
else:
|
||||
# why this short extension node have no
|
||||
# child and still valid when we reconstruct
|
||||
@ -151,7 +172,7 @@ proc getBranchRecurseAux(wb: var WitnessBuilder, node: openArray[byte], path: Ni
|
||||
getBranchRecurseAux(wb, nextLookup, path.slice(sharedNibbles), depth + sharedNibbles)
|
||||
else:
|
||||
# AccountNodeType
|
||||
writeAccountNode(wb, node, depth)
|
||||
writeAccountNode(wb, value.toBytes.decode(Account), k, node, depth)
|
||||
else:
|
||||
# this is a potential branch for multiproof
|
||||
writeHashNode(wb, keccak(node).data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user