mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-27 12:35:00 +00:00
make tests green
This commit is contained in:
parent
dc3a897851
commit
85c36647d1
@ -22,9 +22,11 @@ proc gasMeters: seq[GasMeter] =
|
|||||||
|
|
||||||
macro all(element: untyped, handler: untyped): untyped =
|
macro all(element: untyped, handler: untyped): untyped =
|
||||||
let name = ident(&"{element.repr}s")
|
let name = ident(&"{element.repr}s")
|
||||||
|
let StartGas = ident("StartGas")
|
||||||
result = quote:
|
result = quote:
|
||||||
var res = `name`()
|
var res = `name`()
|
||||||
for `element` in res.mitems:
|
for `element` in res.mitems:
|
||||||
|
let `StartGas` = `element`.gasRemaining
|
||||||
`handler`
|
`handler`
|
||||||
|
|
||||||
# @pytest.mark.parametrize("value", (0, 10))
|
# @pytest.mark.parametrize("value", (0, 10))
|
||||||
@ -78,24 +80,27 @@ proc gasMeterMain*() =
|
|||||||
# TODO: -0/+0
|
# TODO: -0/+0
|
||||||
test "consume spends":
|
test "consume spends":
|
||||||
all(gasMeter):
|
all(gasMeter):
|
||||||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
check(gasMeter.gasRemaining == StartGas)
|
||||||
let consume = gasMeter.startGas
|
let consume = StartGas
|
||||||
gasMeter.consumeGas(consume, "0")
|
gasMeter.consumeGas(consume, "0")
|
||||||
check(gasMeter.gasRemaining - (gasMeter.startGas - consume) == 0)
|
check(gasMeter.gasRemaining - (StartGas - consume) == 0)
|
||||||
|
|
||||||
test "consume errors":
|
test "consume errors":
|
||||||
all(gasMeter):
|
all(gasMeter):
|
||||||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
check(gasMeter.gasRemaining == StartGas)
|
||||||
expect(OutOfGas):
|
expect(OutOfGas):
|
||||||
gasMeter.consumeGas(gasMeter.startGas + 1, "")
|
gasMeter.consumeGas(StartGas + 1, "")
|
||||||
|
|
||||||
test "return refund works correctly":
|
test "return refund works correctly":
|
||||||
all(gasMeter):
|
all(gasMeter):
|
||||||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
check(gasMeter.gasRemaining == StartGas)
|
||||||
check(gasMeter.gasRefunded == 0)
|
check(gasMeter.gasRefunded == 0)
|
||||||
gasMeter.consumeGas(5, "")
|
gasMeter.consumeGas(5, "")
|
||||||
check(gasMeter.gasRemaining == gasMeter.startGas - 5)
|
check(gasMeter.gasRemaining == StartGas - 5)
|
||||||
gasMeter.returnGas(5)
|
gasMeter.returnGas(5)
|
||||||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
check(gasMeter.gasRemaining == StartGas)
|
||||||
gasMeter.refundGas(5)
|
gasMeter.refundGas(5)
|
||||||
check(gasMeter.gasRefunded == 5)
|
check(gasMeter.gasRefunded == 5)
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
gasMeterMain()
|
||||||
|
@ -48,8 +48,8 @@ template doTest(fixture: JsonNode, address: byte, action: untyped): untyped =
|
|||||||
computation = newComputation(vmState, message)
|
computation = newComputation(vmState, message)
|
||||||
echo "Running ", action.astToStr, " - ", test["name"]
|
echo "Running ", action.astToStr, " - ", test["name"]
|
||||||
`action`(computation)
|
`action`(computation)
|
||||||
let c = computation.rawOutput == expected
|
let c = computation.output == expected
|
||||||
if not c: echo "Output : " & computation.rawOutput.toHex & "\nExpected: " & expected.toHex
|
if not c: echo "Output : " & computation.output.toHex & "\nExpected: " & expected.toHex
|
||||||
check c
|
check c
|
||||||
|
|
||||||
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user