mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 05:14:14 +00:00
attempt to add simple cli to all_tests
This commit is contained in:
parent
013688c44b
commit
321f13dc19
@ -5,7 +5,56 @@
|
|||||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
import ./test_code_stream,
|
import macros, strutils, os, unittest, osproc
|
||||||
|
|
||||||
|
proc executeMyself(numModules: int) =
|
||||||
|
let appName = getAppFilename()
|
||||||
|
for i in 0..<numModules:
|
||||||
|
discard execCmd appName & " " & $i
|
||||||
|
|
||||||
|
macro cliBuilder(stmtList: typed): untyped =
|
||||||
|
let importStmt = stmtList[0]
|
||||||
|
importStmt.expectKind nnkImportStmt
|
||||||
|
let moduleCount = importStmt.len
|
||||||
|
|
||||||
|
var caseStmt = newNimNode(nnkCaseStmt)
|
||||||
|
caseStmt.add quote do: paramStr(1).parseInt
|
||||||
|
|
||||||
|
for idx, singleModule in importStmt:
|
||||||
|
# remove the "test_" prefix
|
||||||
|
let moduleName = normalize(singleModule.toStrLit.strVal).substr(4)
|
||||||
|
let moduleMain = newIdentNode(moduleName & "Main")
|
||||||
|
# construct `of` branch
|
||||||
|
let branchNode = newNimNode(nnkOfBranch)
|
||||||
|
branchNode.add newIntLitNode(idx)
|
||||||
|
branchNode.add newCall(moduleMain)
|
||||||
|
caseStmt.add branchNode
|
||||||
|
|
||||||
|
var elseBranch = newNimNode(nnkElse)
|
||||||
|
elseBranch.add quote do:
|
||||||
|
echo "invalid argument"
|
||||||
|
caseStmt.add elseBranch
|
||||||
|
|
||||||
|
result = quote do:
|
||||||
|
if paramCount() == 0:
|
||||||
|
executeMyself `moduleCount`
|
||||||
|
else:
|
||||||
|
disableParamFiltering()
|
||||||
|
`caseStmt`
|
||||||
|
|
||||||
|
# if you want to add new test module(s)
|
||||||
|
# make sure you define an entry poin
|
||||||
|
# e.g.
|
||||||
|
# proc mytestMain*() =
|
||||||
|
# # put anything you want here
|
||||||
|
# and then give it a name `test_mytest.nim`
|
||||||
|
|
||||||
|
# if this executable called without any params
|
||||||
|
# it will return the number of submodules
|
||||||
|
# you can execute the submodules by a number start from zero.
|
||||||
|
|
||||||
|
cliBuilder:
|
||||||
|
import ./test_code_stream,
|
||||||
./test_gas_meter,
|
./test_gas_meter,
|
||||||
./test_memory,
|
./test_memory,
|
||||||
./test_stack,
|
./test_stack,
|
||||||
@ -25,4 +74,3 @@ import ./test_code_stream,
|
|||||||
./test_state_db,
|
./test_state_db,
|
||||||
./test_difficulty,
|
./test_difficulty,
|
||||||
./test_transaction_json
|
./test_transaction_json
|
||||||
|
|
||||||
|
@ -8,17 +8,18 @@
|
|||||||
import unittest, strutils, sequtils,
|
import unittest, strutils, sequtils,
|
||||||
../nimbus/vm/interpreter
|
../nimbus/vm/interpreter
|
||||||
|
|
||||||
suite "parse bytecode":
|
proc codeStreamMain*() =
|
||||||
|
suite "parse bytecode":
|
||||||
test "accepts bytes":
|
test "accepts bytes":
|
||||||
let codeStream = newCodeStream("\x01")
|
let codeStream = newCodeStream("\x01")
|
||||||
check(codeStream.len == 1)
|
check(codeStream.len == 1)
|
||||||
|
|
||||||
|
|
||||||
# quicktest
|
# quicktest
|
||||||
# @pytest.mark.parametrize("code_bytes", (1010, '1010', True, bytearray(32)))
|
# @pytest.mark.parametrize("code_bytes", (1010, '1010', True, bytearray(32)))
|
||||||
# def test_codeStream_rejects_invalid_code_byte_values(code_bytes):
|
# def test_codeStream_rejects_invalid_code_byte_values(code_bytes):
|
||||||
# with pytest.raises(ValidationError):
|
# with pytest.raises(ValidationError):
|
||||||
# CodeStream(code_bytes)
|
# CodeStream(code_bytes)
|
||||||
|
|
||||||
test "next returns the correct opcode":
|
test "next returns the correct opcode":
|
||||||
var codeStream = newCodeStream("\x01\x02\x30")
|
var codeStream = newCodeStream("\x01\x02\x30")
|
||||||
|
@ -53,7 +53,8 @@ template runTests(name: string, hex: bool, calculator: typed) =
|
|||||||
test title:
|
test title:
|
||||||
check diff == t.currentDifficulty
|
check diff == t.currentDifficulty
|
||||||
|
|
||||||
suite "DifficultyTest":
|
proc difficultyMain*() =
|
||||||
|
suite "DifficultyTest":
|
||||||
runTests("Byzantium", true, calcDifficultyByzantium)
|
runTests("Byzantium", true, calcDifficultyByzantium)
|
||||||
runTests("Constantinople", true, calcDifficultyConstantinople)
|
runTests("Constantinople", true, calcDifficultyConstantinople)
|
||||||
runTests("Homestead", true, calcDifficultyHomestead)
|
runTests("Homestead", true, calcDifficultyHomestead)
|
||||||
|
@ -57,8 +57,8 @@ macro all(element: untyped, handler: untyped): untyped =
|
|||||||
# gas_meter.refund_gas(amount)
|
# gas_meter.refund_gas(amount)
|
||||||
# doAssert gas_meter.gas_refunded == amount
|
# doAssert gas_meter.gas_refunded == amount
|
||||||
|
|
||||||
|
proc gasMeterMain*() =
|
||||||
suite "gasMeter":
|
suite "gasMeter":
|
||||||
# types
|
# types
|
||||||
# test "consume rejects negative":
|
# test "consume rejects negative":
|
||||||
# all(gasMeter):
|
# all(gasMeter):
|
||||||
|
@ -172,8 +172,8 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus,
|
|||||||
if not testedInFork:
|
if not testedInFork:
|
||||||
echo "test subject '", tester.name, "' not tested in any forks"
|
echo "test subject '", tester.name, "' not tested in any forks"
|
||||||
|
|
||||||
proc main() =
|
proc generalStateJsonMain*(debugMode = false) =
|
||||||
if paramCount() == 0:
|
if paramCount() == 0 or not debugMode:
|
||||||
# run all test fixtures
|
# run all test fixtures
|
||||||
suite "generalstate json tests":
|
suite "generalstate json tests":
|
||||||
jsonTest("GeneralStateTests", testFixture)
|
jsonTest("GeneralStateTests", testFixture)
|
||||||
@ -202,5 +202,4 @@ when isMainModule:
|
|||||||
if len(message) > 0:
|
if len(message) > 0:
|
||||||
echo message
|
echo message
|
||||||
quit(QuitSuccess)
|
quit(QuitSuccess)
|
||||||
|
generalStateJsonMain(true)
|
||||||
main()
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import unittest, ../nimbus/[genesis, config], eth/common, nimcrypto/hash
|
import unittest, ../nimbus/[genesis, config], eth/common, nimcrypto/hash
|
||||||
|
|
||||||
suite "Genesis":
|
proc genesisMain*() =
|
||||||
|
suite "Genesis":
|
||||||
test "Correct mainnet hash":
|
test "Correct mainnet hash":
|
||||||
let g = defaultGenesisBlockForNetwork(MainNet)
|
let g = defaultGenesisBlockForNetwork(MainNet)
|
||||||
let b = g.toBlock
|
let b = g.toBlock
|
||||||
|
@ -18,7 +18,8 @@ proc memory128: Memory =
|
|||||||
result = newMemory()
|
result = newMemory()
|
||||||
result.extend(0, 128)
|
result.extend(0, 128)
|
||||||
|
|
||||||
suite "memory":
|
proc memoryMain*() =
|
||||||
|
suite "memory":
|
||||||
test "write":
|
test "write":
|
||||||
var mem = memory32()
|
var mem = memory32()
|
||||||
# Test that write creates 32byte string == value padded with zeros
|
# Test that write creates 32byte string == value padded with zeros
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import macro_assembler, unittest
|
import macro_assembler, unittest
|
||||||
|
|
||||||
suite "Arithmetic Opcodes":
|
proc opArithMain*() =
|
||||||
|
suite "Arithmetic Opcodes":
|
||||||
let (blockNumber, chainDB) = initDatabase()
|
let (blockNumber, chainDB) = initDatabase()
|
||||||
|
|
||||||
assembler:
|
assembler:
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import macro_assembler, unittest
|
import macro_assembler, unittest
|
||||||
|
|
||||||
suite "Bitwise Opcodes":
|
proc opBitMain*() =
|
||||||
|
suite "Bitwise Opcodes":
|
||||||
let (blockNumber, chainDB) = initDatabase()
|
let (blockNumber, chainDB) = initDatabase()
|
||||||
|
|
||||||
assembler: # AND OP
|
assembler: # AND OP
|
||||||
|
@ -3,7 +3,8 @@ import
|
|||||||
stew/byteutils, eth/common, ../nimbus/db/state_db,
|
stew/byteutils, eth/common, ../nimbus/db/state_db,
|
||||||
../nimbus/db/db_chain, stew/ranges
|
../nimbus/db/db_chain, stew/ranges
|
||||||
|
|
||||||
suite "Custom Opcodes Test":
|
proc opCustomMain*() =
|
||||||
|
suite "Custom Opcodes Test":
|
||||||
let (blockNumber, chainDB) = initDatabase()
|
let (blockNumber, chainDB) = initDatabase()
|
||||||
|
|
||||||
assembler: # CALLDATASIZE OP
|
assembler: # CALLDATASIZE OP
|
||||||
|
@ -3,7 +3,8 @@ import
|
|||||||
stew/byteutils, eth/common, ../nimbus/db/state_db,
|
stew/byteutils, eth/common, ../nimbus/db/state_db,
|
||||||
../nimbus/db/db_chain, stew/ranges
|
../nimbus/db/db_chain, stew/ranges
|
||||||
|
|
||||||
suite "Environmental Information Opcodes":
|
proc opEnvMain*() =
|
||||||
|
suite "Environmental Information Opcodes":
|
||||||
let (blockNumber, chainDB) = initDatabase()
|
let (blockNumber, chainDB) = initDatabase()
|
||||||
|
|
||||||
assembler: # CODECOPY OP
|
assembler: # CODECOPY OP
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import macro_assembler, unittest, macros, strutils
|
import macro_assembler, unittest, macros, strutils
|
||||||
|
|
||||||
suite "Memory Opcodes":
|
proc opMemoryMain*() =
|
||||||
|
suite "Memory Opcodes":
|
||||||
let (blockNumber, chainDB) = initDatabase()
|
let (blockNumber, chainDB) = initDatabase()
|
||||||
|
|
||||||
assembler: # PUSH1 OP
|
assembler: # PUSH1 OP
|
||||||
@ -515,7 +516,7 @@ suite "Memory Opcodes":
|
|||||||
SSTORE
|
SSTORE
|
||||||
success: false
|
success: false
|
||||||
stack: "0x22"
|
stack: "0x22"
|
||||||
#[
|
#[
|
||||||
assembler: # SSTORE EIP1283
|
assembler: # SSTORE EIP1283
|
||||||
title: "SSTORE_NET_1"
|
title: "SSTORE_NET_1"
|
||||||
code: "60006000556000600055"
|
code: "60006000556000600055"
|
||||||
@ -654,7 +655,7 @@ suite "Memory Opcodes":
|
|||||||
fork: constantinople
|
fork: constantinople
|
||||||
# assertEquals(10218, program.getResult().getGasUsed())
|
# assertEquals(10218, program.getResult().getGasUsed())
|
||||||
# assertEquals(19800, program.getResult().getFutureRefund())
|
# assertEquals(19800, program.getResult().getFutureRefund())
|
||||||
]#
|
]#
|
||||||
assembler: # SLOAD OP
|
assembler: # SLOAD OP
|
||||||
title: "SLOAD_1"
|
title: "SLOAD_1"
|
||||||
code:
|
code:
|
||||||
|
@ -3,7 +3,8 @@ import
|
|||||||
stew/byteutils, eth/common, ../nimbus/db/state_db,
|
stew/byteutils, eth/common, ../nimbus/db/state_db,
|
||||||
../nimbus/db/db_chain, stew/ranges
|
../nimbus/db/db_chain, stew/ranges
|
||||||
|
|
||||||
suite "Misc Opcodes":
|
proc opMiscMain*() =
|
||||||
|
suite "Misc Opcodes":
|
||||||
let (blockNumber, chainDB) = initDatabase()
|
let (blockNumber, chainDB) = initDatabase()
|
||||||
|
|
||||||
assembler: # LOG0 OP
|
assembler: # LOG0 OP
|
||||||
|
@ -13,7 +13,8 @@ import
|
|||||||
|
|
||||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
||||||
|
|
||||||
suite "persist block json tests":
|
proc persistBlockJsonMain*() =
|
||||||
|
suite "persist block json tests":
|
||||||
jsonTest("PersistBlockTests", testFixture)
|
jsonTest("PersistBlockTests", testFixture)
|
||||||
|
|
||||||
# use tracerTestGen.nim to generate additional test data
|
# use tracerTestGen.nim to generate additional test data
|
||||||
|
@ -51,5 +51,6 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
|||||||
#raise newException(ValueError, "Unknown test vector '" & $label & "'")
|
#raise newException(ValueError, "Unknown test vector '" & $label & "'")
|
||||||
echo "Unknown test vector '" & $label & "'"
|
echo "Unknown test vector '" & $label & "'"
|
||||||
|
|
||||||
suite "Precompiles":
|
proc precompilesMain*() =
|
||||||
|
suite "Precompiles":
|
||||||
jsonTest("PrecompileTests", testFixture)
|
jsonTest("PrecompileTests", testFixture)
|
||||||
|
@ -27,7 +27,8 @@ func toBytes(s: string): seq[byte] =
|
|||||||
func bigEndianToInt*(value: openarray[byte]): UInt256 =
|
func bigEndianToInt*(value: openarray[byte]): UInt256 =
|
||||||
result.initFromBytesBE(value)
|
result.initFromBytesBE(value)
|
||||||
|
|
||||||
suite "stack":
|
proc stackMain*() =
|
||||||
|
suite "stack":
|
||||||
test "push only valid":
|
test "push only valid":
|
||||||
testPush(0'u, 0.u256)
|
testPush(0'u, 0.u256)
|
||||||
testPush(UINT_256_MAX, UINT_256_MAX)
|
testPush(UINT_256_MAX, UINT_256_MAX)
|
||||||
|
@ -9,7 +9,8 @@ import unittest, strutils, eth/trie/[hexary, db],
|
|||||||
../nimbus/db/state_db, stew/byteutils, eth/common,
|
../nimbus/db/state_db, stew/byteutils, eth/common,
|
||||||
stew/ranges
|
stew/ranges
|
||||||
|
|
||||||
suite "Account State DB":
|
proc stateDBMain*() =
|
||||||
|
suite "Account State DB":
|
||||||
var
|
var
|
||||||
memDB = newMemoryDB()
|
memDB = newMemoryDB()
|
||||||
trie = initHexaryTrie(memDB)
|
trie = initHexaryTrie(memDB)
|
||||||
|
@ -12,7 +12,8 @@ import
|
|||||||
|
|
||||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
||||||
|
|
||||||
suite "tracer json tests":
|
proc tracerJsonMain*() =
|
||||||
|
suite "tracer json tests":
|
||||||
jsonTest("TracerTests", testFixture)
|
jsonTest("TracerTests", testFixture)
|
||||||
|
|
||||||
# use tracerTestGen.nim to generate additional test data
|
# use tracerTestGen.nim to generate additional test data
|
||||||
|
@ -8,9 +8,13 @@ const
|
|||||||
|
|
||||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
||||||
|
|
||||||
suite "Transactions tests":
|
proc transactionJsonMain*() =
|
||||||
|
suite "Transactions tests":
|
||||||
jsonTest("TransactionTests", testFixture)
|
jsonTest("TransactionTests", testFixture)
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
transactionJsonMain()
|
||||||
|
|
||||||
proc txHash(tx: Transaction): string =
|
proc txHash(tx: Transaction): string =
|
||||||
toLowerAscii($keccakHash(rlp.encode(tx)))
|
toLowerAscii($keccakHash(rlp.encode(tx)))
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ import
|
|||||||
|
|
||||||
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus)
|
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus)
|
||||||
|
|
||||||
suite "vm json tests":
|
proc vmJsonMain*() =
|
||||||
|
suite "vm json tests":
|
||||||
jsonTest("VMTests", testFixture)
|
jsonTest("VMTests", testFixture)
|
||||||
|
|
||||||
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user