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)
|
||||
# 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_memory,
|
||||
./test_stack,
|
||||
|
@ -25,4 +74,3 @@ import ./test_code_stream,
|
|||
./test_state_db,
|
||||
./test_difficulty,
|
||||
./test_transaction_json
|
||||
|
||||
|
|
|
@ -8,17 +8,18 @@
|
|||
import unittest, strutils, sequtils,
|
||||
../nimbus/vm/interpreter
|
||||
|
||||
suite "parse bytecode":
|
||||
proc codeStreamMain*() =
|
||||
suite "parse bytecode":
|
||||
test "accepts bytes":
|
||||
let codeStream = newCodeStream("\x01")
|
||||
check(codeStream.len == 1)
|
||||
|
||||
|
||||
# quicktest
|
||||
# @pytest.mark.parametrize("code_bytes", (1010, '1010', True, bytearray(32)))
|
||||
# def test_codeStream_rejects_invalid_code_byte_values(code_bytes):
|
||||
# with pytest.raises(ValidationError):
|
||||
# CodeStream(code_bytes)
|
||||
# quicktest
|
||||
# @pytest.mark.parametrize("code_bytes", (1010, '1010', True, bytearray(32)))
|
||||
# def test_codeStream_rejects_invalid_code_byte_values(code_bytes):
|
||||
# with pytest.raises(ValidationError):
|
||||
# CodeStream(code_bytes)
|
||||
|
||||
test "next returns the correct opcode":
|
||||
var codeStream = newCodeStream("\x01\x02\x30")
|
||||
|
|
|
@ -53,7 +53,8 @@ template runTests(name: string, hex: bool, calculator: typed) =
|
|||
test title:
|
||||
check diff == t.currentDifficulty
|
||||
|
||||
suite "DifficultyTest":
|
||||
proc difficultyMain*() =
|
||||
suite "DifficultyTest":
|
||||
runTests("Byzantium", true, calcDifficultyByzantium)
|
||||
runTests("Constantinople", true, calcDifficultyConstantinople)
|
||||
runTests("Homestead", true, calcDifficultyHomestead)
|
||||
|
|
|
@ -57,8 +57,8 @@ macro all(element: untyped, handler: untyped): untyped =
|
|||
# gas_meter.refund_gas(amount)
|
||||
# doAssert gas_meter.gas_refunded == amount
|
||||
|
||||
|
||||
suite "gasMeter":
|
||||
proc gasMeterMain*() =
|
||||
suite "gasMeter":
|
||||
# types
|
||||
# test "consume rejects negative":
|
||||
# all(gasMeter):
|
||||
|
|
|
@ -172,8 +172,8 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus,
|
|||
if not testedInFork:
|
||||
echo "test subject '", tester.name, "' not tested in any forks"
|
||||
|
||||
proc main() =
|
||||
if paramCount() == 0:
|
||||
proc generalStateJsonMain*(debugMode = false) =
|
||||
if paramCount() == 0 or not debugMode:
|
||||
# run all test fixtures
|
||||
suite "generalstate json tests":
|
||||
jsonTest("GeneralStateTests", testFixture)
|
||||
|
@ -202,5 +202,4 @@ when isMainModule:
|
|||
if len(message) > 0:
|
||||
echo message
|
||||
quit(QuitSuccess)
|
||||
|
||||
main()
|
||||
generalStateJsonMain(true)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import unittest, ../nimbus/[genesis, config], eth/common, nimcrypto/hash
|
||||
|
||||
suite "Genesis":
|
||||
proc genesisMain*() =
|
||||
suite "Genesis":
|
||||
test "Correct mainnet hash":
|
||||
let g = defaultGenesisBlockForNetwork(MainNet)
|
||||
let b = g.toBlock
|
||||
|
|
|
@ -18,7 +18,8 @@ proc memory128: Memory =
|
|||
result = newMemory()
|
||||
result.extend(0, 128)
|
||||
|
||||
suite "memory":
|
||||
proc memoryMain*() =
|
||||
suite "memory":
|
||||
test "write":
|
||||
var mem = memory32()
|
||||
# Test that write creates 32byte string == value padded with zeros
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import macro_assembler, unittest
|
||||
|
||||
suite "Arithmetic Opcodes":
|
||||
proc opArithMain*() =
|
||||
suite "Arithmetic Opcodes":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
|
||||
assembler:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import macro_assembler, unittest
|
||||
|
||||
suite "Bitwise Opcodes":
|
||||
proc opBitMain*() =
|
||||
suite "Bitwise Opcodes":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
|
||||
assembler: # AND OP
|
||||
|
|
|
@ -3,7 +3,8 @@ import
|
|||
stew/byteutils, eth/common, ../nimbus/db/state_db,
|
||||
../nimbus/db/db_chain, stew/ranges
|
||||
|
||||
suite "Custom Opcodes Test":
|
||||
proc opCustomMain*() =
|
||||
suite "Custom Opcodes Test":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
|
||||
assembler: # CALLDATASIZE OP
|
||||
|
|
|
@ -3,7 +3,8 @@ import
|
|||
stew/byteutils, eth/common, ../nimbus/db/state_db,
|
||||
../nimbus/db/db_chain, stew/ranges
|
||||
|
||||
suite "Environmental Information Opcodes":
|
||||
proc opEnvMain*() =
|
||||
suite "Environmental Information Opcodes":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
|
||||
assembler: # CODECOPY OP
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import macro_assembler, unittest, macros, strutils
|
||||
|
||||
suite "Memory Opcodes":
|
||||
proc opMemoryMain*() =
|
||||
suite "Memory Opcodes":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
|
||||
assembler: # PUSH1 OP
|
||||
|
@ -515,7 +516,7 @@ suite "Memory Opcodes":
|
|||
SSTORE
|
||||
success: false
|
||||
stack: "0x22"
|
||||
#[
|
||||
#[
|
||||
assembler: # SSTORE EIP1283
|
||||
title: "SSTORE_NET_1"
|
||||
code: "60006000556000600055"
|
||||
|
@ -654,7 +655,7 @@ suite "Memory Opcodes":
|
|||
fork: constantinople
|
||||
# assertEquals(10218, program.getResult().getGasUsed())
|
||||
# assertEquals(19800, program.getResult().getFutureRefund())
|
||||
]#
|
||||
]#
|
||||
assembler: # SLOAD OP
|
||||
title: "SLOAD_1"
|
||||
code:
|
||||
|
|
|
@ -3,7 +3,8 @@ import
|
|||
stew/byteutils, eth/common, ../nimbus/db/state_db,
|
||||
../nimbus/db/db_chain, stew/ranges
|
||||
|
||||
suite "Misc Opcodes":
|
||||
proc opMiscMain*() =
|
||||
suite "Misc Opcodes":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
|
||||
assembler: # LOG0 OP
|
||||
|
|
|
@ -13,7 +13,8 @@ import
|
|||
|
||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
||||
|
||||
suite "persist block json tests":
|
||||
proc persistBlockJsonMain*() =
|
||||
suite "persist block json tests":
|
||||
jsonTest("PersistBlockTests", testFixture)
|
||||
|
||||
# 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 & "'")
|
||||
echo "Unknown test vector '" & $label & "'"
|
||||
|
||||
suite "Precompiles":
|
||||
proc precompilesMain*() =
|
||||
suite "Precompiles":
|
||||
jsonTest("PrecompileTests", testFixture)
|
||||
|
|
|
@ -27,7 +27,8 @@ func toBytes(s: string): seq[byte] =
|
|||
func bigEndianToInt*(value: openarray[byte]): UInt256 =
|
||||
result.initFromBytesBE(value)
|
||||
|
||||
suite "stack":
|
||||
proc stackMain*() =
|
||||
suite "stack":
|
||||
test "push only valid":
|
||||
testPush(0'u, 0.u256)
|
||||
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,
|
||||
stew/ranges
|
||||
|
||||
suite "Account State DB":
|
||||
proc stateDBMain*() =
|
||||
suite "Account State DB":
|
||||
var
|
||||
memDB = newMemoryDB()
|
||||
trie = initHexaryTrie(memDB)
|
||||
|
|
|
@ -12,7 +12,8 @@ import
|
|||
|
||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
||||
|
||||
suite "tracer json tests":
|
||||
proc tracerJsonMain*() =
|
||||
suite "tracer json tests":
|
||||
jsonTest("TracerTests", testFixture)
|
||||
|
||||
# use tracerTestGen.nim to generate additional test data
|
||||
|
|
|
@ -8,9 +8,13 @@ const
|
|||
|
||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
||||
|
||||
suite "Transactions tests":
|
||||
proc transactionJsonMain*() =
|
||||
suite "Transactions tests":
|
||||
jsonTest("TransactionTests", testFixture)
|
||||
|
||||
when isMainModule:
|
||||
transactionJsonMain()
|
||||
|
||||
proc txHash(tx: Transaction): string =
|
||||
toLowerAscii($keccakHash(rlp.encode(tx)))
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@ import
|
|||
|
||||
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus)
|
||||
|
||||
suite "vm json tests":
|
||||
proc vmJsonMain*() =
|
||||
suite "vm json tests":
|
||||
jsonTest("VMTests", testFixture)
|
||||
|
||||
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
||||
|
|
Loading…
Reference in New Issue