Fix memory and gas tests
This commit is contained in:
parent
211d46e39e
commit
f918692496
|
@ -0,0 +1,8 @@
|
|||
sudo: required
|
||||
services:
|
||||
- docker
|
||||
before_install:
|
||||
- docker pull yglukhov/nim-base
|
||||
script:
|
||||
- docker run yglukhov/nim-base nim --version
|
||||
- docker run -v "$(pwd):/project" -w /project yglukhov/nim-base nimble install;./test.sh
|
|
@ -4,17 +4,25 @@ type
|
|||
Logger* = object
|
||||
name*: string
|
||||
|
||||
const DEBUG = true
|
||||
var DEBUG = true
|
||||
|
||||
proc log*(l: Logger, msg: string) =
|
||||
echo &"#{l.name}: {msg}"
|
||||
if DEBUG:
|
||||
echo &"#{l.name}: {msg}"
|
||||
|
||||
proc debug*(l: Logger, msg: string) =
|
||||
if DEBUG:
|
||||
l.log(msg)
|
||||
|
||||
proc trace*(l: Logger, msg: string) =
|
||||
l.log(msg)
|
||||
if DEBUG:
|
||||
l.log(msg)
|
||||
|
||||
proc getLogger*(name: string): Logger =
|
||||
result = Logger(name: name)
|
||||
|
||||
proc disableLogging* =
|
||||
DEBUG = false
|
||||
|
||||
proc enableLogging* =
|
||||
DEBUG = true
|
||||
|
|
|
@ -10,7 +10,7 @@ type
|
|||
proc newMemory*: Memory =
|
||||
new(result)
|
||||
result.bytes = @[]
|
||||
result.logger = logging.getLogger("evm.vm.memory.Memory")
|
||||
result.logger = logging.getLogger("memory.Memory")
|
||||
|
||||
proc len*(memory: Memory): int =
|
||||
result = memory.bytes.len
|
||||
|
|
|
@ -154,7 +154,7 @@ proc popBinary*(stack: var Stack; numItems: int): seq[string] =
|
|||
|
||||
proc newStack*(): Stack =
|
||||
new(result)
|
||||
result.logger = logging.getLogger("evm.vm.stack.Stack")
|
||||
result.logger = logging.getLogger("stack.Stack")
|
||||
result.values = @[]
|
||||
|
||||
proc swap*(stack: var Stack; position: int) =
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import unittest, macros, strformat, strutils, sequtils, constants, opcode_values, errors, vm / gas_meter, bigints
|
||||
import unittest, macros, strformat, strutils, sequtils, constants, opcode_values, errors, logging, vm / gas_meter, bigints
|
||||
|
||||
# TODO: quicktest
|
||||
# PS: parametrize can be easily immitated, but still quicktests would be even more useful
|
||||
|
||||
disableLogging()
|
||||
|
||||
proc gasMeters: seq[GasMeter] =
|
||||
@[newGasMeter(10.i256), newGasMeter(100.i256), newGasMeter(999.i256)]
|
||||
|
||||
|
@ -66,7 +68,7 @@ suite "gasMeter":
|
|||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
||||
let consume = gasMeter.startGas
|
||||
gasMeter.consumeGas(consume, "0")
|
||||
check(gasMeter.gasRemaining == gasMeter.startGas - consume)
|
||||
check(gasMeter.gasRemaining - (gasMeter.startGas - consume) == 0)
|
||||
|
||||
test "consume errors":
|
||||
all(gasMeter):
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
nim c tests/code_stream_test.nim
|
||||
nim c tests/gas_meter_test.nim
|
||||
nim c tests/memory_test.nim
|
||||
nim c tests/stack_test.nim
|
||||
# nim c tests/code_stream_test.nim
|
||||
# nim c tests/gas_meter_test.nim
|
||||
# nim c tests/memory_test.nim
|
||||
# nim c tests/stack_test.nim
|
||||
./tests/code_stream_test
|
||||
./tests/gas_meter_test
|
||||
./tests/memory_test
|
||||
|
|
Loading…
Reference in New Issue