Merge branch 'unittest2-serialised'

This commit is contained in:
Ștefan Talpalaru 2019-11-01 17:56:50 +01:00
commit 66020ea752
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
27 changed files with 158 additions and 122 deletions

6
.gitmodules vendored
View File

@ -111,6 +111,12 @@
[submodule "vendor/news"] [submodule "vendor/news"]
path = vendor/news path = vendor/news
url = https://github.com/tormund/news url = https://github.com/tormund/news
ignore = dirty
branch = master
[submodule "vendor/nim-unittest2"]
path = vendor/nim-unittest2
url = https://github.com/stefantalpalaru/nim-unittest2.git
ignore = dirty
branch = master branch = master
[submodule "vendor/nim-metrics"] [submodule "vendor/nim-metrics"]
path = vendor/nim-metrics path = vendor/nim-metrics

View File

@ -11,6 +11,10 @@
--passL:"-Wl,--stack,8388608" --passL:"-Wl,--stack,8388608"
# https://github.com/nim-lang/Nim/issues/4057 # https://github.com/nim-lang/Nim/issues/4057
--tlsEmulation:off --tlsEmulation:off
@if i386:
# set the IMAGE_FILE_LARGE_ADDRESS_AWARE flag so we can use PAE, if enabled, and access more than 2 GiB of RAM
--passL:"-Wl,--large-address-aware"
@end
@end @end
--threads:on --threads:on

View File

@ -5,7 +5,11 @@
# * 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 macros, strutils, os, unittest, osproc import macros, strutils, os, unittest2, osproc
import threadpool
# AppVeyor may go out of memory with the default of 4
setMinPoolSize(2)
proc executeMyself(numModules: int): int = proc executeMyself(numModules: int): int =
let appName = getAppFilename() let appName = getAppFilename()

View File

@ -1,5 +1,5 @@
import import
macrocache, strutils, unittest, macrocache, strutils, unittest2,
stew/byteutils, chronicles, stew/ranges, eth/common, stew/byteutils, chronicles, stew/ranges, eth/common,
../nimbus/vm/interpreter/opcode_values, ../nimbus/vm/interpreter/opcode_values,
stew/shims/macros stew/shims/macros
@ -185,6 +185,7 @@ proc generateVMProxy(boa: Assembler): NimNode =
proc `vmProxy`(): bool = proc `vmProxy`(): bool =
let boa = `body` let boa = `body`
runVM(`blockNumber`, `chainDB`, boa) runVM(`blockNumber`, `chainDB`, boa)
{.gcsafe.}:
check `vmProxy`() check `vmProxy`()
when defined(macro_assembler_debug): when defined(macro_assembler_debug):

View File

@ -1,3 +1,5 @@
-d:chronicles_line_numbers -d:chronicles_line_numbers
-d:"chronicles_sinks=textblocks" -d:"chronicles_sinks=textblocks"
# comment this out, to run the tests in a serial manner:
#-d:nimtestParallel

View File

@ -6,7 +6,7 @@
# 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 import
unittest, json, os, tables, strutils, sets, strformat, times, unittest2, json, os, tables, strutils, sets, strformat, times,
options, options,
eth/[common, rlp, bloom], eth/trie/[db, trie_defs], eth/[common, rlp, bloom], eth/trie/[db, trie_defs],
ethash, stew/endians2, nimcrypto, ethash, stew/endians2, nimcrypto,

View File

@ -5,7 +5,7 @@
# * 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 unittest, strutils, sequtils, import unittest2, strutils, sequtils,
../nimbus/vm/interpreter ../nimbus/vm/interpreter
proc codeStreamMain*() = proc codeStreamMain*() =

View File

@ -1,4 +1,4 @@
import unittest, strutils, tables, ospaths, json, import unittest2, strutils, tables, ospaths, json,
../nimbus/utils/difficulty, stint, times, ../nimbus/utils/difficulty, stint, times,
eth/common, test_helpers, stew/byteutils eth/common, test_helpers, stew/byteutils
@ -41,6 +41,7 @@ proc parseTests(name: string, hex: static[bool]): Tests =
result[title] = t result[title] = t
template runTests(name: string, hex: bool, calculator: typed) = template runTests(name: string, hex: bool, calculator: typed) =
test name:
let data = parseTests(name, hex) let data = parseTests(name, hex)
for title, t in data: for title, t in data:
var p = BlockHeader( var p = BlockHeader(
@ -50,7 +51,6 @@ template runTests(name: string, hex: bool, calculator: typed) =
ommersHash: t.parentUncles) ommersHash: t.parentUncles)
let diff = calculator(times.fromUnix(t.currentTimeStamp), p) let diff = calculator(times.fromUnix(t.currentTimeStamp), p)
test name & " " & title:
check diff == t.currentDifficulty check diff == t.currentDifficulty
proc difficultyMain*() = proc difficultyMain*() =

View File

@ -6,7 +6,7 @@
# 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 import
unittest, macros, strformat, unittest2, macros, strformat,
eth/common/eth_types, eth/common/eth_types,
../nimbus/[vm_types, errors, vm/interpreter] ../nimbus/[vm_types, errors, vm/interpreter]

View File

@ -6,7 +6,7 @@
# 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 import
unittest, strformat, strutils, tables, json, ospaths, times, os, unittest2, strformat, strutils, tables, json, ospaths, times, os,
stew/byteutils, stew/ranges/typedranges, nimcrypto, options, stew/byteutils, stew/ranges/typedranges, nimcrypto, options,
eth/[rlp, common], eth/trie/[db, trie_defs], chronicles, eth/[rlp, common], eth/trie/[db, trie_defs], chronicles,
./test_helpers, ../nimbus/p2p/executor, test_config, ./test_helpers, ../nimbus/p2p/executor, test_config,

View File

@ -1,4 +1,4 @@
import unittest, ../nimbus/[genesis, config], eth/common, nimcrypto/hash import unittest2, ../nimbus/[genesis, config], eth/common, nimcrypto/hash
proc genesisMain*() = proc genesisMain*() =
suite "Genesis": suite "Genesis":

View File

@ -7,7 +7,7 @@
import import
os, macros, json, strformat, strutils, parseutils, ospaths, tables, os, macros, json, strformat, strutils, parseutils, ospaths, tables,
stew/byteutils, stew/ranges/typedranges, net, eth/[common, keys, rlp, p2p], stew/byteutils, stew/ranges/typedranges, net, eth/[common, keys, rlp, p2p], unittest2,
../nimbus/[vm_state, constants, config, transaction, utils, errors], ../nimbus/[vm_state, constants, config, transaction, utils, errors],
../nimbus/db/[db_chain, state_db], ../nimbus/db/[db_chain, state_db],
../nimbus/vm/interpreter/[gas_costs, vm_forks], ../nimbus/vm/interpreter/[gas_costs, vm_forks],
@ -143,8 +143,7 @@ func validTest*(folder: string, name: string): bool =
not allowedFailInCurrentBuild(folder, name) not allowedFailInCurrentBuild(folder, name)
proc lacksSupportedForks*(fixtures: JsonNode): bool = proc lacksSupportedForks*(fixtures: JsonNode): bool =
# XXX: Until Nimbus supports Byzantine or newer forks, as opposed # XXX: Until Nimbus supports all forks, some of the GeneralStateTests won't work.
# to Homestead, ~1k of ~2.5k GeneralStateTests won't work.
var fixture: JsonNode var fixture: JsonNode
for label, child in fixtures: for label, child in fixtures:
@ -161,9 +160,12 @@ proc lacksSupportedForks*(fixtures: JsonNode): bool =
result = false result = false
break break
var status = initOrderedTable[string, OrderedTable[string, Status]]()
macro jsonTest*(s: static[string], handler: untyped): untyped = macro jsonTest*(s: static[string], handler: untyped): untyped =
let let
testStatusIMPL = ident("testStatusIMPL") testStatusIMPL = ident("testStatusIMPL")
testName = ident("testName")
# workaround for strformat in quote do: https://github.com/nim-lang/Nim/issues/8220 # workaround for strformat in quote do: https://github.com/nim-lang/Nim/issues/8220
symbol = newIdentNode"symbol" symbol = newIdentNode"symbol"
final = newIdentNode"final" final = newIdentNode"final"
@ -171,8 +173,7 @@ macro jsonTest*(s: static[string], handler: untyped): untyped =
formatted = newStrLitNode"{symbol[final]} {name:<64}{$final}{'\n'}" formatted = newStrLitNode"{symbol[final]} {name:<64}{$final}{'\n'}"
result = quote: result = quote:
var filenames: seq[(string, string, string)] = @[] var filenames: seq[string] = @[]
var status = initOrderedTable[string, OrderedTable[string, Status]]()
for filename in walkDirRec("tests" / "fixtures" / `s`): for filename in walkDirRec("tests" / "fixtures" / `s`):
if not filename.endsWith(".json"): if not filename.endsWith(".json"):
continue continue
@ -182,21 +183,28 @@ macro jsonTest*(s: static[string], handler: untyped): untyped =
status[last] = initOrderedTable[string, Status]() status[last] = initOrderedTable[string, Status]()
status[last][name] = Status.Skip status[last][name] = Status.Skip
if last.validTest(name): if last.validTest(name):
filenames.add((filename, last, name)) filenames.add(filename)
for child in filenames: for fname in filenames:
let (filename, folder, name) = child test fname:
{.gcsafe.}:
let
filename = `testName` # the first argument passed to the `test` template
(folder, name) = filename.splitPath()
last = folder.splitPath().tail
# we set this here because exceptions might be raised in the handler: # we set this here because exceptions might be raised in the handler:
status[folder][name] = Status.Fail status[last][name] = Status.Fail
let fixtures = parseJSON(readFile(filename)) let fixtures = parseJSON(readFile(filename))
if fixtures.lacksSupportedForks: if fixtures.lacksSupportedForks:
status[folder][name] = Status.Skip status[last][name] = Status.Skip
continue skip()
test filename: else:
echo folder / name when not paralleliseTests:
echo filename
`handler`(fixtures, `testStatusIMPL`) `handler`(fixtures, `testStatusIMPL`)
if `testStatusIMPL` == OK: if `testStatusIMPL` == OK:
status[folder][name] = Status.OK status[last][name] = Status.OK
suiteTeardown:
status.sort do (a: (string, OrderedTable[string, Status]), status.sort do (a: (string, OrderedTable[string, Status]),
b: (string, OrderedTable[string, Status])) -> int: cmp(a[0], b[0]) b: (string, OrderedTable[string, Status])) -> int: cmp(a[0], b[0])
@ -233,6 +241,7 @@ macro jsonTest*(s: static[string], handler: untyped): untyped =
raw.add("\n---TOTAL---\n") raw.add("\n---TOTAL---\n")
raw.add("OK: $1/$4 Fail: $2/$4 Skip: $3/$4\n" % [$okCountTotal, $failCountTotal, $skipCountTotal, $sumTotal]) raw.add("OK: $1/$4 Fail: $2/$4 Skip: $3/$4\n" % [$okCountTotal, $failCountTotal, $skipCountTotal, $sumTotal])
writeFile(`s` & ".md", raw) writeFile(`s` & ".md", raw)
status.clear()
func ethAddressFromHex*(s: string): EthAddress = hexToByteArray(s, result) func ethAddressFromHex*(s: string): EthAddress = hexToByteArray(s, result)

View File

@ -6,7 +6,7 @@
# 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 import
unittest, sequtils, unittest2, sequtils,
eth/common/eth_types, eth/common/eth_types,
../nimbus/[constants, errors, vm/memory] ../nimbus/[constants, errors, vm/memory]

View File

@ -1,7 +1,8 @@
import macro_assembler, unittest import macro_assembler, unittest2
proc opArithMain*() = proc opArithMain*() =
suite "Arithmetic Opcodes": suite "Arithmetic Opcodes":
setup:
let (blockNumber, chainDB) = initDatabase() let (blockNumber, chainDB) = initDatabase()
assembler: assembler:

View File

@ -1,7 +1,8 @@
import macro_assembler, unittest import macro_assembler, unittest2
proc opBitMain*() = proc opBitMain*() =
suite "Bitwise Opcodes": suite "Bitwise Opcodes":
setup:
let (blockNumber, chainDB) = initDatabase() let (blockNumber, chainDB) = initDatabase()
assembler: # AND OP assembler: # AND OP

View File

@ -1,10 +1,11 @@
import import
macro_assembler, unittest, macros, strutils, macro_assembler, unittest2, macros, strutils,
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
proc opCustomMain*() = proc opCustomMain*() =
suite "Custom Opcodes Test": suite "Custom Opcodes Test":
setup:
let (blockNumber, chainDB) = initDatabase() let (blockNumber, chainDB) = initDatabase()
assembler: # CALLDATASIZE OP assembler: # CALLDATASIZE OP

View File

@ -1,10 +1,11 @@
import import
macro_assembler, unittest, macros, strutils, macro_assembler, unittest2, macros, strutils,
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
proc opEnvMain*() = proc opEnvMain*() =
suite "Environmental Information Opcodes": suite "Environmental Information Opcodes":
setup:
let (blockNumber, chainDB) = initDatabase() let (blockNumber, chainDB) = initDatabase()
assembler: # CODECOPY OP assembler: # CODECOPY OP
@ -176,6 +177,9 @@ proc opEnvMain*() =
"0x5e" "0x5e"
"0x07" "0x07"
suite "Environmental Information Opcodes 2":
setup:
let (blockNumber, chainDB) = initDatabase()
var acc: EthAddress var acc: EthAddress
hexToByteArray("0xfbe0afcd7658ba86be41922059dd879c192d4c73", acc) hexToByteArray("0xfbe0afcd7658ba86be41922059dd879c192d4c73", acc)
var var

View File

@ -1,7 +1,8 @@
import macro_assembler, unittest, macros, strutils import macro_assembler, unittest2, macros, strutils
proc opMemoryMain*() = proc opMemoryMain*() =
suite "Memory Opcodes": suite "Memory Opcodes":
setup:
let (blockNumber, chainDB) = initDatabase() let (blockNumber, chainDB) = initDatabase()
assembler: # PUSH1 OP assembler: # PUSH1 OP

View File

@ -1,10 +1,11 @@
import import
macro_assembler, unittest, macros, strutils, macro_assembler, unittest2, macros, strutils,
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
proc opMiscMain*() = proc opMiscMain*() =
suite "Misc Opcodes": suite "Misc Opcodes":
setup:
let (blockNumber, chainDB) = initDatabase() let (blockNumber, chainDB) = initDatabase()
assembler: # LOG0 OP assembler: # LOG0 OP

View File

@ -6,17 +6,11 @@
# 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 import
unittest, json, os, tables, strformat, strutils, unittest2, json, os, tables, strformat, strutils,
eth/[common, rlp], stew/byteutils, eth/trie/db, eth/[common, rlp], stew/byteutils, eth/trie/db,
./test_helpers, ../nimbus/db/[db_chain, storage_types], ../nimbus/[tracer, vm_types], ./test_helpers, ../nimbus/db/[db_chain, storage_types], ../nimbus/[tracer, vm_types],
../nimbus/p2p/chain ../nimbus/p2p/chain
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
proc persistBlockJsonMain*() =
suite "persist block json tests":
jsonTest("PersistBlockTests", testFixture)
# use tracerTestGen.nim to generate additional test data # use tracerTestGen.nim to generate additional test data
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus) = proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus) =
var var
@ -43,3 +37,8 @@ proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus) =
chainDB.setHead(parent, true) chainDB.setHead(parent, true)
let validationResult = chain.persistBlocks(headers, bodies) let validationResult = chain.persistBlocks(headers, bodies)
check validationResult == ValidationResult.OK check validationResult == ValidationResult.OK
proc persistBlockJsonMain*() =
suite "persist block json tests":
jsonTest("PersistBlockTests", testFixture)

View File

@ -6,7 +6,7 @@
# 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 import
unittest, ../nimbus/vm/precompiles, json, stew/byteutils, test_helpers, ospaths, tables, unittest2, ../nimbus/vm/precompiles, json, stew/byteutils, test_helpers, ospaths, tables,
strformat, strutils, eth/trie/db, eth/common, ../nimbus/db/[db_chain, state_db], strformat, strutils, eth/trie/db, eth/common, ../nimbus/db/[db_chain, state_db],
../nimbus/[constants, vm_types, vm_state], ../nimbus/vm/[computation, message], macros ../nimbus/[constants, vm_types, vm_state], ../nimbus/vm/[computation, message], macros

View File

@ -6,7 +6,7 @@
# 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 import
unittest, unittest2,
eth/common/eth_types, eth/common/eth_types,
../nimbus/[constants, errors, vm/interpreter] ../nimbus/[constants, errors, vm/interpreter]

View File

@ -5,12 +5,13 @@
# * 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 unittest, strutils, eth/trie/[hexary, db], import unittest2, 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
proc stateDBMain*() = proc stateDBMain*() =
suite "Account State DB": suite "Account State DB":
setup:
var var
memDB = newMemoryDB() memDB = newMemoryDB()
trie = initHexaryTrie(memDB) trie = initHexaryTrie(memDB)

View File

@ -6,7 +6,7 @@
# 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 import
unittest, json, os, tables, strformat, strutils, unittest2, json, os, tables, strformat, strutils,
eth/common, stew/byteutils, eth/trie/db, eth/common, stew/byteutils, eth/trie/db,
./test_helpers, ../nimbus/db/db_chain, ../nimbus/[tracer, vm_types] ./test_helpers, ../nimbus/db/db_chain, ../nimbus/[tracer, vm_types]

View File

@ -1,5 +1,5 @@
import import
unittest, json, os, tables, strformat, strutils, unittest2, json, os, tables, strformat, strutils,
eth/[common, rlp], eth/[common, rlp],
./test_helpers, ../nimbus/[transaction, utils, errors] ./test_helpers, ../nimbus/[transaction, utils, errors]

View File

@ -6,7 +6,7 @@
# 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 import
unittest, strformat, strutils, sequtils, tables, json, ospaths, times, unittest2, strformat, strutils, sequtils, tables, json, ospaths, times,
stew/byteutils, stew/ranges/typedranges, eth/[rlp, common], eth/trie/db, stew/byteutils, stew/ranges/typedranges, eth/[rlp, common], eth/trie/db,
./test_helpers, ../nimbus/vm/interpreter, ./test_helpers, ../nimbus/vm/interpreter,
../nimbus/[constants, errors, vm_state, vm_types, utils], ../nimbus/[constants, errors, vm_state, vm_types, utils],

1
vendor/nim-unittest2 vendored Submodule

@ -0,0 +1 @@
Subproject commit 30c7d332d8ebab28d3240018f48f145ff20af239