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"]
path = vendor/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
[submodule "vendor/nim-metrics"]
path = vendor/nim-metrics

View File

@ -11,6 +11,10 @@
--passL:"-Wl,--stack,8388608"
# https://github.com/nim-lang/Nim/issues/4057
--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
--threads:on

View File

@ -5,7 +5,11 @@
# * 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 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 =
let appName = getAppFilename()

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
import unittest, strutils, tables, ospaths, json,
import unittest2, strutils, tables, ospaths, json,
../nimbus/utils/difficulty, stint, times,
eth/common, test_helpers, stew/byteutils
@ -41,16 +41,16 @@ proc parseTests(name: string, hex: static[bool]): Tests =
result[title] = t
template runTests(name: string, hex: bool, calculator: typed) =
let data = parseTests(name, hex)
for title, t in data:
var p = BlockHeader(
difficulty: t.parentDifficulty,
timestamp: times.fromUnix(t.parentTimestamp),
blockNumber: t.currentBlockNumber - 1,
ommersHash: t.parentUncles)
test name:
let data = parseTests(name, hex)
for title, t in data:
var p = BlockHeader(
difficulty: t.parentDifficulty,
timestamp: times.fromUnix(t.parentTimestamp),
blockNumber: t.currentBlockNumber - 1,
ommersHash: t.parentUncles)
let diff = calculator(times.fromUnix(t.currentTimeStamp), p)
test name & " " & title:
let diff = calculator(times.fromUnix(t.currentTimeStamp), p)
check diff == t.currentDifficulty
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.
import
unittest, macros, strformat,
unittest2, macros, strformat,
eth/common/eth_types,
../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.
import
unittest, strformat, strutils, tables, json, ospaths, times, os,
unittest2, strformat, strutils, tables, json, ospaths, times, os,
stew/byteutils, stew/ranges/typedranges, nimcrypto, options,
eth/[rlp, common], eth/trie/[db, trie_defs], chronicles,
./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*() =
suite "Genesis":

View File

@ -7,7 +7,7 @@
import
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/db/[db_chain, state_db],
../nimbus/vm/interpreter/[gas_costs, vm_forks],
@ -143,8 +143,7 @@ func validTest*(folder: string, name: string): bool =
not allowedFailInCurrentBuild(folder, name)
proc lacksSupportedForks*(fixtures: JsonNode): bool =
# XXX: Until Nimbus supports Byzantine or newer forks, as opposed
# to Homestead, ~1k of ~2.5k GeneralStateTests won't work.
# XXX: Until Nimbus supports all forks, some of the GeneralStateTests won't work.
var fixture: JsonNode
for label, child in fixtures:
@ -161,9 +160,12 @@ proc lacksSupportedForks*(fixtures: JsonNode): bool =
result = false
break
var status = initOrderedTable[string, OrderedTable[string, Status]]()
macro jsonTest*(s: static[string], handler: untyped): untyped =
let
testStatusIMPL = ident("testStatusIMPL")
testName = ident("testName")
# workaround for strformat in quote do: https://github.com/nim-lang/Nim/issues/8220
symbol = newIdentNode"symbol"
final = newIdentNode"final"
@ -171,8 +173,7 @@ macro jsonTest*(s: static[string], handler: untyped): untyped =
formatted = newStrLitNode"{symbol[final]} {name:<64}{$final}{'\n'}"
result = quote:
var filenames: seq[(string, string, string)] = @[]
var status = initOrderedTable[string, OrderedTable[string, Status]]()
var filenames: seq[string] = @[]
for filename in walkDirRec("tests" / "fixtures" / `s`):
if not filename.endsWith(".json"):
continue
@ -182,57 +183,65 @@ macro jsonTest*(s: static[string], handler: untyped): untyped =
status[last] = initOrderedTable[string, Status]()
status[last][name] = Status.Skip
if last.validTest(name):
filenames.add((filename, last, name))
for child in filenames:
let (filename, folder, name) = child
# we set this here because exceptions might be raised in the handler:
status[folder][name] = Status.Fail
let fixtures = parseJSON(readFile(filename))
if fixtures.lacksSupportedForks:
status[folder][name] = Status.Skip
continue
test filename:
echo folder / name
`handler`(fixtures, `testStatusIMPL`)
if `testStatusIMPL` == OK:
status[folder][name] = Status.OK
filenames.add(filename)
for fname in filenames:
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:
status[last][name] = Status.Fail
let fixtures = parseJSON(readFile(filename))
if fixtures.lacksSupportedForks:
status[last][name] = Status.Skip
skip()
else:
when not paralleliseTests:
echo filename
`handler`(fixtures, `testStatusIMPL`)
if `testStatusIMPL` == OK:
status[last][name] = Status.OK
status.sort do (a: (string, OrderedTable[string, Status]),
b: (string, OrderedTable[string, Status])) -> int: cmp(a[0], b[0])
suiteTeardown:
status.sort do (a: (string, OrderedTable[string, Status]),
b: (string, OrderedTable[string, Status])) -> int: cmp(a[0], b[0])
let `symbol`: array[Status, string] = ["+", "-", " "]
var raw = ""
var okCountTotal = 0
var failCountTotal = 0
var skipCountTotal = 0
raw.add(`s` & "\n")
raw.add("===\n")
for folder, statuses in status:
raw.add("## " & folder & "\n")
raw.add("```diff\n")
var sortedStatuses = statuses
sortedStatuses.sort do (a: (string, Status), b: (string, Status)) -> int:
cmp(a[0], b[0])
var okCount = 0
var failCount = 0
var skipCount = 0
for `name`, `final` in sortedStatuses:
raw.add(&`formatted`)
case `final`:
of Status.OK: okCount += 1
of Status.Fail: failCount += 1
of Status.Skip: skipCount += 1
raw.add("```\n")
let sum = okCount + failCount + skipCount
okCountTotal += okCount
failCountTotal += failCount
skipCountTotal += skipCount
raw.add("OK: " & $okCount & "/" & $sum & " Fail: " & $failCount & "/" & $sum & " Skip: " & $skipCount & "/" & $sum & "\n")
let `symbol`: array[Status, string] = ["+", "-", " "]
var raw = ""
var okCountTotal = 0
var failCountTotal = 0
var skipCountTotal = 0
raw.add(`s` & "\n")
raw.add("===\n")
for folder, statuses in status:
raw.add("## " & folder & "\n")
raw.add("```diff\n")
var sortedStatuses = statuses
sortedStatuses.sort do (a: (string, Status), b: (string, Status)) -> int:
cmp(a[0], b[0])
var okCount = 0
var failCount = 0
var skipCount = 0
for `name`, `final` in sortedStatuses:
raw.add(&`formatted`)
case `final`:
of Status.OK: okCount += 1
of Status.Fail: failCount += 1
of Status.Skip: skipCount += 1
raw.add("```\n")
let sum = okCount + failCount + skipCount
okCountTotal += okCount
failCountTotal += failCount
skipCountTotal += skipCount
raw.add("OK: " & $okCount & "/" & $sum & " Fail: " & $failCount & "/" & $sum & " Skip: " & $skipCount & "/" & $sum & "\n")
let sumTotal = okCountTotal + failCountTotal + skipCountTotal
raw.add("\n---TOTAL---\n")
raw.add("OK: $1/$4 Fail: $2/$4 Skip: $3/$4\n" % [$okCountTotal, $failCountTotal, $skipCountTotal, $sumTotal])
writeFile(`s` & ".md", raw)
let sumTotal = okCountTotal + failCountTotal + skipCountTotal
raw.add("\n---TOTAL---\n")
raw.add("OK: $1/$4 Fail: $2/$4 Skip: $3/$4\n" % [$okCountTotal, $failCountTotal, $skipCountTotal, $sumTotal])
writeFile(`s` & ".md", raw)
status.clear()
func ethAddressFromHex*(s: string): EthAddress = hexToByteArray(s, result)
@ -336,4 +345,4 @@ proc setupEthNode*(capabilities: varargs[ProtocolInfo, `protocolInfo`]): Ethereu
result = newEthereumNode(keypair, srvAddress, conf.net.networkId,
nil, "nimbus 0.1.0", addAllCapabilities = false)
for capability in capabilities:
result.addCapability capability
result.addCapability capability

View File

@ -6,7 +6,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
unittest, sequtils,
unittest2, sequtils,
eth/common/eth_types,
../nimbus/[constants, errors, vm/memory]

View File

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

View File

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

View File

@ -1,11 +1,12 @@
import
macro_assembler, unittest, macros, strutils,
macro_assembler, unittest2, macros, strutils,
stew/byteutils, eth/common, ../nimbus/db/state_db,
../nimbus/db/db_chain, stew/ranges
proc opCustomMain*() =
suite "Custom Opcodes Test":
let (blockNumber, chainDB) = initDatabase()
setup:
let (blockNumber, chainDB) = initDatabase()
assembler: # CALLDATASIZE OP
title: "CALLDATASIZE_1"

View File

@ -1,11 +1,12 @@
import
macro_assembler, unittest, macros, strutils,
macro_assembler, unittest2, macros, strutils,
stew/byteutils, eth/common, ../nimbus/db/state_db,
../nimbus/db/db_chain, stew/ranges
proc opEnvMain*() =
suite "Environmental Information Opcodes":
let (blockNumber, chainDB) = initDatabase()
setup:
let (blockNumber, chainDB) = initDatabase()
assembler: # CODECOPY OP
title: "CODECOPY_1"
@ -176,20 +177,23 @@ proc opEnvMain*() =
"0x5e"
"0x07"
var acc: EthAddress
hexToByteArray("0xfbe0afcd7658ba86be41922059dd879c192d4c73", acc)
var
parent = chainDB.getBlockHeader(blockNumber - 1)
stateDB = newAccountStateDB(chainDB.db, parent.stateRoot, false)
code = hexToSeqByte("0x0102030405060708090A0B0C0D0E0F" &
"611234600054615566602054603E6000602073471FD3AD3E9EEADEEC4608B92D" &
"16CE6B500704CC3C6000605f556014600054601e60205463abcddcba6040545b" &
"51602001600a5254516040016014525451606001601e52545160800160285254" &
"60a052546016604860003960166000f26000603f556103e756600054600053602002351234")
suite "Environmental Information Opcodes 2":
setup:
let (blockNumber, chainDB) = initDatabase()
var acc: EthAddress
hexToByteArray("0xfbe0afcd7658ba86be41922059dd879c192d4c73", acc)
var
parent = chainDB.getBlockHeader(blockNumber - 1)
stateDB = newAccountStateDB(chainDB.db, parent.stateRoot, false)
code = hexToSeqByte("0x0102030405060708090A0B0C0D0E0F" &
"611234600054615566602054603E6000602073471FD3AD3E9EEADEEC4608B92D" &
"16CE6B500704CC3C6000605f556014600054601e60205463abcddcba6040545b" &
"51602001600a5254516040016014525451606001601e52545160800160285254" &
"60a052546016604860003960166000f26000603f556103e756600054600053602002351234")
stateDB.setCode(acc, code.toRange)
parent.stateRoot = stateDB.rootHash
chainDB.setHead(parent, true)
stateDB.setCode(acc, code.toRange)
parent.stateRoot = stateDB.rootHash
chainDB.setHead(parent, true)
assembler: # EXTCODECOPY OP
title: "EXTCODECOPY_1"

View File

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

View File

@ -1,11 +1,12 @@
import
macro_assembler, unittest, macros, strutils,
macro_assembler, unittest2, macros, strutils,
stew/byteutils, eth/common, ../nimbus/db/state_db,
../nimbus/db/db_chain, stew/ranges
proc opMiscMain*() =
suite "Misc Opcodes":
let (blockNumber, chainDB) = initDatabase()
setup:
let (blockNumber, chainDB) = initDatabase()
assembler: # LOG0 OP
title: "Log0"

View File

@ -6,17 +6,11 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
unittest, json, os, tables, strformat, strutils,
unittest2, json, os, tables, strformat, strutils,
eth/[common, rlp], stew/byteutils, eth/trie/db,
./test_helpers, ../nimbus/db/[db_chain, storage_types], ../nimbus/[tracer, vm_types],
../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
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus) =
var
@ -43,3 +37,8 @@ proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus) =
chainDB.setHead(parent, true)
let validationResult = chain.persistBlocks(headers, bodies)
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.
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],
../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.
import
unittest,
unittest2,
eth/common/eth_types,
../nimbus/[constants, errors, vm/interpreter]

View File

@ -5,19 +5,20 @@
# * 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 unittest, strutils, eth/trie/[hexary, db],
import unittest2, strutils, eth/trie/[hexary, db],
../nimbus/db/state_db, stew/byteutils, eth/common,
stew/ranges
proc stateDBMain*() =
suite "Account State DB":
var
memDB = newMemoryDB()
trie = initHexaryTrie(memDB)
stateDB = newAccountStateDB(memDB, trie.rootHash, true)
address: EthAddress
setup:
var
memDB = newMemoryDB()
trie = initHexaryTrie(memDB)
stateDB = newAccountStateDB(memDB, trie.rootHash, true)
address: EthAddress
hexToByteArray("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", address)
hexToByteArray("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", address)
test "accountExists and isDeadAccount":
check stateDB.accountExists(address) == false

View File

@ -6,7 +6,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
unittest, json, os, tables, strformat, strutils,
unittest2, json, os, tables, strformat, strutils,
eth/common, stew/byteutils, eth/trie/db,
./test_helpers, ../nimbus/db/db_chain, ../nimbus/[tracer, vm_types]

View File

@ -1,5 +1,5 @@
import
unittest, json, os, tables, strformat, strutils,
unittest2, json, os, tables, strformat, strutils,
eth/[common, rlp],
./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.
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,
./test_helpers, ../nimbus/vm/interpreter,
../nimbus/[constants, errors, vm_state, vm_types, utils],

1
vendor/nim-unittest2 vendored Submodule

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