attempt to add simple cli to all_tests
This commit is contained in:
parent
013688c44b
commit
321f13dc19
|
@ -5,24 +5,72 @@
|
|||
# * 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,
|
||||
./test_gas_meter,
|
||||
./test_memory,
|
||||
./test_stack,
|
||||
./test_genesis,
|
||||
./test_vm_json,
|
||||
./test_precompiles,
|
||||
./test_generalstate_json,
|
||||
./test_tracer_json,
|
||||
./test_persistblock_json,
|
||||
#./test_rpc, # it crash if we combine it here
|
||||
./test_op_arith,
|
||||
./test_op_bit,
|
||||
./test_op_env,
|
||||
./test_op_memory,
|
||||
./test_op_misc,
|
||||
./test_op_custom,
|
||||
./test_state_db,
|
||||
./test_difficulty,
|
||||
./test_transaction_json
|
||||
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,
|
||||
./test_genesis,
|
||||
./test_vm_json,
|
||||
./test_precompiles,
|
||||
./test_generalstate_json,
|
||||
./test_tracer_json,
|
||||
./test_persistblock_json,
|
||||
#./test_rpc, # it crash if we combine it here
|
||||
./test_op_arith,
|
||||
./test_op_bit,
|
||||
./test_op_env,
|
||||
./test_op_memory,
|
||||
./test_op_misc,
|
||||
./test_op_custom,
|
||||
./test_state_db,
|
||||
./test_difficulty,
|
||||
./test_transaction_json
|
||||
|
|
|
@ -8,110 +8,111 @@
|
|||
import unittest, strutils, sequtils,
|
||||
../nimbus/vm/interpreter
|
||||
|
||||
suite "parse bytecode":
|
||||
test "accepts bytes":
|
||||
let codeStream = newCodeStream("\x01")
|
||||
check(codeStream.len == 1)
|
||||
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")
|
||||
check(codeStream.next == Op.ADD)
|
||||
check(codeStream.next == Op.MUL)
|
||||
check(codeStream.next == Op.ADDRESS)
|
||||
test "next returns the correct opcode":
|
||||
var codeStream = newCodeStream("\x01\x02\x30")
|
||||
check(codeStream.next == Op.ADD)
|
||||
check(codeStream.next == Op.MUL)
|
||||
check(codeStream.next == Op.ADDRESS)
|
||||
|
||||
|
||||
test "peek returns next opcode without changing location":
|
||||
var codeStream = newCodeStream("\x01\x02\x30")
|
||||
check(codeStream.pc == 0)
|
||||
check(codeStream.peek == Op.ADD)
|
||||
check(codeStream.pc == 0)
|
||||
check(codeStream.next == Op.ADD)
|
||||
check(codeStream.pc == 1)
|
||||
check(codeStream.peek == Op.MUL)
|
||||
check(codeStream.pc == 1)
|
||||
test "peek returns next opcode without changing location":
|
||||
var codeStream = newCodeStream("\x01\x02\x30")
|
||||
check(codeStream.pc == 0)
|
||||
check(codeStream.peek == Op.ADD)
|
||||
check(codeStream.pc == 0)
|
||||
check(codeStream.next == Op.ADD)
|
||||
check(codeStream.pc == 1)
|
||||
check(codeStream.peek == Op.MUL)
|
||||
check(codeStream.pc == 1)
|
||||
|
||||
|
||||
test "stop opcode is returned when end reached":
|
||||
var codeStream = newCodeStream("\x01\x02")
|
||||
discard codeStream.next
|
||||
discard codeStream.next
|
||||
check(codeStream.next == Op.STOP)
|
||||
test "stop opcode is returned when end reached":
|
||||
var codeStream = newCodeStream("\x01\x02")
|
||||
discard codeStream.next
|
||||
discard codeStream.next
|
||||
check(codeStream.next == Op.STOP)
|
||||
|
||||
# Seek has been dommented out for future deletion
|
||||
# test "seek reverts to original position on exit":
|
||||
# var codeStream = newCodeStream("\x01\x02\x30")
|
||||
# check(codeStream.pc == 0)
|
||||
# codeStream.seek(1):
|
||||
# check(codeStream.pc == 1)
|
||||
# check(codeStream.next == Op.MUL)
|
||||
# check(codeStream.pc == 0)
|
||||
# check(codeStream.peek == Op.ADD)
|
||||
# Seek has been dommented out for future deletion
|
||||
# test "seek reverts to original position on exit":
|
||||
# var codeStream = newCodeStream("\x01\x02\x30")
|
||||
# check(codeStream.pc == 0)
|
||||
# codeStream.seek(1):
|
||||
# check(codeStream.pc == 1)
|
||||
# check(codeStream.next == Op.MUL)
|
||||
# check(codeStream.pc == 0)
|
||||
# check(codeStream.peek == Op.ADD)
|
||||
|
||||
test "[] returns opcode":
|
||||
let codeStream = newCodeStream("\x01\x02\x30")
|
||||
check(codeStream[0] == Op.ADD)
|
||||
check(codeStream[1] == Op.MUL)
|
||||
check(codeStream[2] == Op.ADDRESS)
|
||||
test "[] returns opcode":
|
||||
let codeStream = newCodeStream("\x01\x02\x30")
|
||||
check(codeStream[0] == Op.ADD)
|
||||
check(codeStream[1] == Op.MUL)
|
||||
check(codeStream[2] == Op.ADDRESS)
|
||||
|
||||
test "isValidOpcode invalidates after PUSHXX":
|
||||
var codeStream = newCodeStream("\x02\x60\x02\x04")
|
||||
check(codeStream.isValidOpcode(0))
|
||||
check(codeStream.isValidOpcode(1))
|
||||
check(not codeStream.isValidOpcode(2))
|
||||
check(codeStream.isValidOpcode(3))
|
||||
check(not codeStream.isValidOpcode(4))
|
||||
test "isValidOpcode invalidates after PUSHXX":
|
||||
var codeStream = newCodeStream("\x02\x60\x02\x04")
|
||||
check(codeStream.isValidOpcode(0))
|
||||
check(codeStream.isValidOpcode(1))
|
||||
check(not codeStream.isValidOpcode(2))
|
||||
check(codeStream.isValidOpcode(3))
|
||||
check(not codeStream.isValidOpcode(4))
|
||||
|
||||
|
||||
test "isValidOpcode 0":
|
||||
var codeStream = newCodeStream(@[2.byte, 3.byte, 0x72.byte].concat(repeat(4.byte, 32)).concat(@[5.byte]))
|
||||
# valid: 0 - 2 :: 22 - 35
|
||||
# invalid: 3-21 (PUSH19) :: 36+ (too long)
|
||||
check(codeStream.isValidOpcode(0))
|
||||
check(codeStream.isValidOpcode(1))
|
||||
check(codeStream.isValidOpcode(2))
|
||||
check(not codeStream.isValidOpcode(3))
|
||||
check(not codeStream.isValidOpcode(21))
|
||||
check(codeStream.isValidOpcode(22))
|
||||
check(codeStream.isValidOpcode(35))
|
||||
check(not codeStream.isValidOpcode(36))
|
||||
test "isValidOpcode 0":
|
||||
var codeStream = newCodeStream(@[2.byte, 3.byte, 0x72.byte].concat(repeat(4.byte, 32)).concat(@[5.byte]))
|
||||
# valid: 0 - 2 :: 22 - 35
|
||||
# invalid: 3-21 (PUSH19) :: 36+ (too long)
|
||||
check(codeStream.isValidOpcode(0))
|
||||
check(codeStream.isValidOpcode(1))
|
||||
check(codeStream.isValidOpcode(2))
|
||||
check(not codeStream.isValidOpcode(3))
|
||||
check(not codeStream.isValidOpcode(21))
|
||||
check(codeStream.isValidOpcode(22))
|
||||
check(codeStream.isValidOpcode(35))
|
||||
check(not codeStream.isValidOpcode(36))
|
||||
|
||||
|
||||
test "isValidOpcode 1":
|
||||
let test = @[2.byte, 3.byte, 0x7d.byte].concat(repeat(4.byte, 32)).concat(@[5.byte, 0x7e.byte]).concat(repeat(4.byte, 35)).concat(@[1.byte, 0x61.byte, 1.byte, 1.byte, 1.byte])
|
||||
var codeStream = newCodeStream(test)
|
||||
# valid: 0 - 2 :: 33 - 36 :: 68 - 73 :: 76
|
||||
# invalid: 3 - 32 (PUSH30) :: 37 - 67 (PUSH31) :: 74, 75 (PUSH2) :: 77+ (too long)
|
||||
check(codeStream.isValidOpcode(0))
|
||||
check(codeStream.isValidOpcode(1))
|
||||
check(codeStream.isValidOpcode(2))
|
||||
check(not codeStream.isValidOpcode(3))
|
||||
check(not codeStream.isValidOpcode(32))
|
||||
check(codeStream.isValidOpcode(33))
|
||||
check(codeStream.isValidOpcode(36))
|
||||
check(not codeStream.isValidOpcode(37))
|
||||
check(not codeStream.isValidOpcode(67))
|
||||
check(codeStream.isValidOpcode(68))
|
||||
check(codeStream.isValidOpcode(71))
|
||||
check(codeStream.isValidOpcode(72))
|
||||
check(codeStream.isValidOpcode(73))
|
||||
check(not codeStream.isValidOpcode(74))
|
||||
check(not codeStream.isValidOpcode(75))
|
||||
check(codeStream.isValidOpcode(76))
|
||||
check(not codeStream.isValidOpcode(77))
|
||||
test "isValidOpcode 1":
|
||||
let test = @[2.byte, 3.byte, 0x7d.byte].concat(repeat(4.byte, 32)).concat(@[5.byte, 0x7e.byte]).concat(repeat(4.byte, 35)).concat(@[1.byte, 0x61.byte, 1.byte, 1.byte, 1.byte])
|
||||
var codeStream = newCodeStream(test)
|
||||
# valid: 0 - 2 :: 33 - 36 :: 68 - 73 :: 76
|
||||
# invalid: 3 - 32 (PUSH30) :: 37 - 67 (PUSH31) :: 74, 75 (PUSH2) :: 77+ (too long)
|
||||
check(codeStream.isValidOpcode(0))
|
||||
check(codeStream.isValidOpcode(1))
|
||||
check(codeStream.isValidOpcode(2))
|
||||
check(not codeStream.isValidOpcode(3))
|
||||
check(not codeStream.isValidOpcode(32))
|
||||
check(codeStream.isValidOpcode(33))
|
||||
check(codeStream.isValidOpcode(36))
|
||||
check(not codeStream.isValidOpcode(37))
|
||||
check(not codeStream.isValidOpcode(67))
|
||||
check(codeStream.isValidOpcode(68))
|
||||
check(codeStream.isValidOpcode(71))
|
||||
check(codeStream.isValidOpcode(72))
|
||||
check(codeStream.isValidOpcode(73))
|
||||
check(not codeStream.isValidOpcode(74))
|
||||
check(not codeStream.isValidOpcode(75))
|
||||
check(codeStream.isValidOpcode(76))
|
||||
check(not codeStream.isValidOpcode(77))
|
||||
|
||||
|
||||
test "right number of bytes invalidates":
|
||||
var codeStream = newCodeStream("\x02\x03\x60\x02\x02")
|
||||
check(codeStream.isValidOpcode(0))
|
||||
check(codeStream.isValidOpcode(1))
|
||||
check(codeStream.isValidOpcode(2))
|
||||
check(not codeStream.isValidOpcode(3))
|
||||
check(codeStream.isValidOpcode(4))
|
||||
check(not codeStream.isValidOpcode(5))
|
||||
test "right number of bytes invalidates":
|
||||
var codeStream = newCodeStream("\x02\x03\x60\x02\x02")
|
||||
check(codeStream.isValidOpcode(0))
|
||||
check(codeStream.isValidOpcode(1))
|
||||
check(codeStream.isValidOpcode(2))
|
||||
check(not codeStream.isValidOpcode(3))
|
||||
check(codeStream.isValidOpcode(4))
|
||||
check(not codeStream.isValidOpcode(5))
|
||||
|
|
|
@ -53,9 +53,10 @@ template runTests(name: string, hex: bool, calculator: typed) =
|
|||
test title:
|
||||
check diff == t.currentDifficulty
|
||||
|
||||
suite "DifficultyTest":
|
||||
runTests("Byzantium", true, calcDifficultyByzantium)
|
||||
runTests("Constantinople", true, calcDifficultyConstantinople)
|
||||
runTests("Homestead", true, calcDifficultyHomestead)
|
||||
runTests("Frontier", true, calcDifficultyFrontier)
|
||||
runTests("", false, calcDifficulty)
|
||||
proc difficultyMain*() =
|
||||
suite "DifficultyTest":
|
||||
runTests("Byzantium", true, calcDifficultyByzantium)
|
||||
runTests("Constantinople", true, calcDifficultyConstantinople)
|
||||
runTests("Homestead", true, calcDifficultyHomestead)
|
||||
runTests("Frontier", true, calcDifficultyFrontier)
|
||||
runTests("", false, calcDifficulty)
|
||||
|
|
|
@ -57,45 +57,45 @@ macro all(element: untyped, handler: untyped): untyped =
|
|||
# gas_meter.refund_gas(amount)
|
||||
# doAssert gas_meter.gas_refunded == amount
|
||||
|
||||
proc gasMeterMain*() =
|
||||
suite "gasMeter":
|
||||
# types
|
||||
# test "consume rejects negative":
|
||||
# all(gasMeter):
|
||||
# expect(ValidationError):
|
||||
# gasMeter.consumeGas(-1.i256, "independent")
|
||||
|
||||
suite "gasMeter":
|
||||
# types
|
||||
# test "consume rejects negative":
|
||||
# all(gasMeter):
|
||||
# expect(ValidationError):
|
||||
# gasMeter.consumeGas(-1.i256, "independent")
|
||||
# test "return rejects negative":
|
||||
# all(gasMeter):
|
||||
# expect(ValidationError):
|
||||
# gasMeter.returnGas(-1.i256)
|
||||
|
||||
# test "return rejects negative":
|
||||
# all(gasMeter):
|
||||
# expect(ValidationError):
|
||||
# gasMeter.returnGas(-1.i256)
|
||||
# test "refund rejects negative":
|
||||
# all(gasMeter):
|
||||
# expect(ValidationError):
|
||||
# gasMeter.returnGas(-1.i256)
|
||||
|
||||
# test "refund rejects negative":
|
||||
# all(gasMeter):
|
||||
# expect(ValidationError):
|
||||
# gasMeter.returnGas(-1.i256)
|
||||
# TODO: -0/+0
|
||||
test "consume spends":
|
||||
all(gasMeter):
|
||||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
||||
let consume = gasMeter.startGas
|
||||
gasMeter.consumeGas(consume, "0")
|
||||
check(gasMeter.gasRemaining - (gasMeter.startGas - consume) == 0)
|
||||
|
||||
# TODO: -0/+0
|
||||
test "consume spends":
|
||||
all(gasMeter):
|
||||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
||||
let consume = gasMeter.startGas
|
||||
gasMeter.consumeGas(consume, "0")
|
||||
check(gasMeter.gasRemaining - (gasMeter.startGas - consume) == 0)
|
||||
test "consume errors":
|
||||
all(gasMeter):
|
||||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
||||
expect(OutOfGas):
|
||||
gasMeter.consumeGas(gasMeter.startGas + 1, "")
|
||||
|
||||
test "consume errors":
|
||||
all(gasMeter):
|
||||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
||||
expect(OutOfGas):
|
||||
gasMeter.consumeGas(gasMeter.startGas + 1, "")
|
||||
|
||||
test "return refund works correctly":
|
||||
all(gasMeter):
|
||||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
||||
check(gasMeter.gasRefunded == 0)
|
||||
gasMeter.consumeGas(5, "")
|
||||
check(gasMeter.gasRemaining == gasMeter.startGas - 5)
|
||||
gasMeter.returnGas(5)
|
||||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
||||
gasMeter.refundGas(5)
|
||||
check(gasMeter.gasRefunded == 5)
|
||||
test "return refund works correctly":
|
||||
all(gasMeter):
|
||||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
||||
check(gasMeter.gasRefunded == 0)
|
||||
gasMeter.consumeGas(5, "")
|
||||
check(gasMeter.gasRemaining == gasMeter.startGas - 5)
|
||||
gasMeter.returnGas(5)
|
||||
check(gasMeter.gasRemaining == gasMeter.startGas)
|
||||
gasMeter.refundGas(5)
|
||||
check(gasMeter.gasRefunded == 5)
|
||||
|
|
|
@ -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,7 +1,8 @@
|
|||
import unittest, ../nimbus/[genesis, config], eth/common, nimcrypto/hash
|
||||
|
||||
suite "Genesis":
|
||||
test "Correct mainnet hash":
|
||||
let g = defaultGenesisBlockForNetwork(MainNet)
|
||||
let b = g.toBlock
|
||||
check(b.blockHash == "D4E56740F876AEF8C010B86A40D5F56745A118D0906A34E69AEC8C0DB1CB8FA3".toDigest)
|
||||
proc genesisMain*() =
|
||||
suite "Genesis":
|
||||
test "Correct mainnet hash":
|
||||
let g = defaultGenesisBlockForNetwork(MainNet)
|
||||
let b = g.toBlock
|
||||
check(b.blockHash == "D4E56740F876AEF8C010B86A40D5F56745A118D0906A34E69AEC8C0DB1CB8FA3".toDigest)
|
||||
|
|
|
@ -18,53 +18,54 @@ proc memory128: Memory =
|
|||
result = newMemory()
|
||||
result.extend(0, 128)
|
||||
|
||||
suite "memory":
|
||||
test "write":
|
||||
var mem = memory32()
|
||||
# Test that write creates 32byte string == value padded with zeros
|
||||
mem.write(startPos = 0, value = @[1.byte, 0.byte, 1.byte, 0.byte])
|
||||
check(mem.bytes == @[1.byte, 0.byte, 1.byte, 0.byte].concat(repeat(0.byte, 28)))
|
||||
proc memoryMain*() =
|
||||
suite "memory":
|
||||
test "write":
|
||||
var mem = memory32()
|
||||
# Test that write creates 32byte string == value padded with zeros
|
||||
mem.write(startPos = 0, value = @[1.byte, 0.byte, 1.byte, 0.byte])
|
||||
check(mem.bytes == @[1.byte, 0.byte, 1.byte, 0.byte].concat(repeat(0.byte, 28)))
|
||||
|
||||
# test "write rejects invalid position":
|
||||
# expect(ValidationError):
|
||||
# var mem = memory32()
|
||||
# mem.write(startPosition = -1.i256, size = 2.i256, value = @[1.byte, 0.byte])
|
||||
# expect(ValidationError):
|
||||
# TODO: work on 256
|
||||
# var mem = memory32()
|
||||
# echo "pow ", pow(2.i256, 255) - 1.i256
|
||||
# mem.write(startPosition = pow(2.i256, 256), size = 2.i256, value = @[1.byte, 0.byte])
|
||||
# test "write rejects invalid position":
|
||||
# expect(ValidationError):
|
||||
# var mem = memory32()
|
||||
# mem.write(startPosition = -1.i256, size = 2.i256, value = @[1.byte, 0.byte])
|
||||
# expect(ValidationError):
|
||||
# TODO: work on 256
|
||||
# var mem = memory32()
|
||||
# echo "pow ", pow(2.i256, 255) - 1.i256
|
||||
# mem.write(startPosition = pow(2.i256, 256), size = 2.i256, value = @[1.byte, 0.byte])
|
||||
|
||||
# test "write rejects invalid size":
|
||||
# # expect(ValidationError):
|
||||
# # var mem = memory32()
|
||||
# # mem.write(startPosition = 0.i256, size = -1.i256, value = @[1.byte, 0.byte])
|
||||
# test "write rejects invalid size":
|
||||
# # expect(ValidationError):
|
||||
# # var mem = memory32()
|
||||
# # mem.write(startPosition = 0.i256, size = -1.i256, value = @[1.byte, 0.byte])
|
||||
|
||||
# #TODO deactivated because of no pow support in Stint: https://github.com/status-im/nim-stint/issues/37
|
||||
# expect(ValidationError):
|
||||
# var mem = memory32()
|
||||
# mem.write(startPosition = 0.u256, size = pow(2.u256, 256), value = @[1.byte, 0.byte])
|
||||
# #TODO deactivated because of no pow support in Stint: https://github.com/status-im/nim-stint/issues/37
|
||||
# expect(ValidationError):
|
||||
# var mem = memory32()
|
||||
# mem.write(startPosition = 0.u256, size = pow(2.u256, 256), value = @[1.byte, 0.byte])
|
||||
|
||||
test "write rejects valyes beyond memory size":
|
||||
expect(ValidationError):
|
||||
var mem = memory128()
|
||||
mem.write(startPos = 128, value = @[1.byte, 0.byte, 1.byte, 0.byte])
|
||||
test "write rejects valyes beyond memory size":
|
||||
expect(ValidationError):
|
||||
var mem = memory128()
|
||||
mem.write(startPos = 128, value = @[1.byte, 0.byte, 1.byte, 0.byte])
|
||||
|
||||
test "extends appropriately extends memory":
|
||||
var mem = newMemory()
|
||||
# Test extends to 32 byte array: 0 < (start_position + size) <= 32
|
||||
mem.extend(startPos = 0, size = 10)
|
||||
check(mem.bytes == repeat(0.byte, 32))
|
||||
# Test will extend past length if params require: 32 < (start_position + size) <= 64
|
||||
mem.extend(startPos = 28, size = 32)
|
||||
check(mem.bytes == repeat(0.byte, 64))
|
||||
# Test won't extend past length unless params require: 32 < (start_position + size) <= 64
|
||||
mem.extend(startPos = 48, size = 10)
|
||||
check(mem.bytes == repeat(0.byte, 64))
|
||||
test "extends appropriately extends memory":
|
||||
var mem = newMemory()
|
||||
# Test extends to 32 byte array: 0 < (start_position + size) <= 32
|
||||
mem.extend(startPos = 0, size = 10)
|
||||
check(mem.bytes == repeat(0.byte, 32))
|
||||
# Test will extend past length if params require: 32 < (start_position + size) <= 64
|
||||
mem.extend(startPos = 28, size = 32)
|
||||
check(mem.bytes == repeat(0.byte, 64))
|
||||
# Test won't extend past length unless params require: 32 < (start_position + size) <= 64
|
||||
mem.extend(startPos = 48, size = 10)
|
||||
check(mem.bytes == repeat(0.byte, 64))
|
||||
|
||||
test "read returns correct bytes":
|
||||
var mem = memory32()
|
||||
mem.write(startPos = 5, value = @[1.byte, 0.byte, 1.byte, 0.byte])
|
||||
check(mem.read(startPos = 5, size = 4) == @[1.byte, 0.byte, 1.byte, 0.byte])
|
||||
check(mem.read(startPos = 6, size = 4) == @[0.byte, 1.byte, 0.byte, 0.byte])
|
||||
check(mem.read(startPos = 1, size = 3) == @[0.byte, 0.byte, 0.byte])
|
||||
test "read returns correct bytes":
|
||||
var mem = memory32()
|
||||
mem.write(startPos = 5, value = @[1.byte, 0.byte, 1.byte, 0.byte])
|
||||
check(mem.read(startPos = 5, size = 4) == @[1.byte, 0.byte, 1.byte, 0.byte])
|
||||
check(mem.read(startPos = 6, size = 4) == @[0.byte, 1.byte, 0.byte, 0.byte])
|
||||
check(mem.read(startPos = 1, size = 3) == @[0.byte, 0.byte, 0.byte])
|
||||
|
|
|
@ -1,439 +1,440 @@
|
|||
import macro_assembler, unittest
|
||||
|
||||
suite "Arithmetic Opcodes":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
proc opArithMain*() =
|
||||
suite "Arithmetic Opcodes":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
|
||||
assembler:
|
||||
title: "ADD_1"
|
||||
code:
|
||||
PUSH1 "0x02"
|
||||
PUSH1 "0x02"
|
||||
ADD
|
||||
stack: "0x04"
|
||||
assembler:
|
||||
title: "ADD_1"
|
||||
code:
|
||||
PUSH1 "0x02"
|
||||
PUSH1 "0x02"
|
||||
ADD
|
||||
stack: "0x04"
|
||||
|
||||
assembler:
|
||||
title: "ADD_2"
|
||||
code:
|
||||
PUSH2 "0x1002"
|
||||
PUSH1 "0x02"
|
||||
ADD
|
||||
stack: "0x1004"
|
||||
assembler:
|
||||
title: "ADD_2"
|
||||
code:
|
||||
PUSH2 "0x1002"
|
||||
PUSH1 "0x02"
|
||||
ADD
|
||||
stack: "0x1004"
|
||||
|
||||
assembler:
|
||||
title: "ADD_3"
|
||||
code:
|
||||
PUSH2 "0x1002"
|
||||
PUSH6 "0x123456789009"
|
||||
ADD
|
||||
stack: "0x12345678A00B"
|
||||
assembler:
|
||||
title: "ADD_3"
|
||||
code:
|
||||
PUSH2 "0x1002"
|
||||
PUSH6 "0x123456789009"
|
||||
ADD
|
||||
stack: "0x12345678A00B"
|
||||
|
||||
assembler:
|
||||
title: "ADD_4"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
ADD
|
||||
success: false
|
||||
stack: "0x1234"
|
||||
assembler:
|
||||
title: "ADD_4"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
ADD
|
||||
success: false
|
||||
stack: "0x1234"
|
||||
|
||||
assembler:
|
||||
title: "ADDMOD_1"
|
||||
code:
|
||||
PUSH1 "0x02"
|
||||
PUSH1 "0x02"
|
||||
PUSH1 "0x03"
|
||||
ADDMOD
|
||||
stack: "0x01"
|
||||
assembler:
|
||||
title: "ADDMOD_1"
|
||||
code:
|
||||
PUSH1 "0x02"
|
||||
PUSH1 "0x02"
|
||||
PUSH1 "0x03"
|
||||
ADDMOD
|
||||
stack: "0x01"
|
||||
|
||||
assembler:
|
||||
title: "ADDMOD_2"
|
||||
code:
|
||||
PUSH2 "0x1000"
|
||||
PUSH1 "0x02"
|
||||
PUSH2 "0x1002"
|
||||
ADDMOD
|
||||
PUSH1 "0x00"
|
||||
stack:
|
||||
"0x04"
|
||||
"0x00"
|
||||
assembler:
|
||||
title: "ADDMOD_2"
|
||||
code:
|
||||
PUSH2 "0x1000"
|
||||
PUSH1 "0x02"
|
||||
PUSH2 "0x1002"
|
||||
ADDMOD
|
||||
PUSH1 "0x00"
|
||||
stack:
|
||||
"0x04"
|
||||
"0x00"
|
||||
|
||||
assembler:
|
||||
title: "ADDMOD_3"
|
||||
code:
|
||||
PUSH2 "0x1002"
|
||||
PUSH6 "0x123456789009"
|
||||
PUSH1 "0x02"
|
||||
ADDMOD
|
||||
stack: "0x093B"
|
||||
assembler:
|
||||
title: "ADDMOD_3"
|
||||
code:
|
||||
PUSH2 "0x1002"
|
||||
PUSH6 "0x123456789009"
|
||||
PUSH1 "0x02"
|
||||
ADDMOD
|
||||
stack: "0x093B"
|
||||
|
||||
assembler:
|
||||
title: "ADDMOD_4"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
ADDMOD
|
||||
stack: "0x1234"
|
||||
success: false
|
||||
assembler:
|
||||
title: "ADDMOD_4"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
ADDMOD
|
||||
stack: "0x1234"
|
||||
success: false
|
||||
|
||||
assembler:
|
||||
title: "MUL_1"
|
||||
code:
|
||||
PUSH1 "0x03"
|
||||
PUSH1 "0x02"
|
||||
MUL
|
||||
stack: "0x06"
|
||||
assembler:
|
||||
title: "MUL_1"
|
||||
code:
|
||||
PUSH1 "0x03"
|
||||
PUSH1 "0x02"
|
||||
MUL
|
||||
stack: "0x06"
|
||||
|
||||
assembler:
|
||||
title: "MUL_2"
|
||||
code:
|
||||
PUSH3 "0x222222"
|
||||
PUSH1 "0x03"
|
||||
MUL
|
||||
stack: "0x666666"
|
||||
assembler:
|
||||
title: "MUL_2"
|
||||
code:
|
||||
PUSH3 "0x222222"
|
||||
PUSH1 "0x03"
|
||||
MUL
|
||||
stack: "0x666666"
|
||||
|
||||
assembler:
|
||||
title: "MUL_3"
|
||||
code:
|
||||
PUSH3 "0x222222"
|
||||
PUSH3 "0x333333"
|
||||
MUL
|
||||
stack: "0x6D3A05F92C6"
|
||||
assembler:
|
||||
title: "MUL_3"
|
||||
code:
|
||||
PUSH3 "0x222222"
|
||||
PUSH3 "0x333333"
|
||||
MUL
|
||||
stack: "0x6D3A05F92C6"
|
||||
|
||||
assembler:
|
||||
title: "MUL_4"
|
||||
code:
|
||||
PUSH1 "0x01"
|
||||
MUL
|
||||
stack: "0x01"
|
||||
success: false
|
||||
assembler:
|
||||
title: "MUL_4"
|
||||
code:
|
||||
PUSH1 "0x01"
|
||||
MUL
|
||||
stack: "0x01"
|
||||
success: false
|
||||
|
||||
assembler: # MULMOD OP
|
||||
title: "MULMOD_2"
|
||||
code:
|
||||
PUSH3 "0x222222"
|
||||
PUSH1 "0x03"
|
||||
PUSH1 "0x04"
|
||||
MULMOD
|
||||
stack: "0x000000000000000000000000000000000000000000000000000000000000000C"
|
||||
assembler: # MULMOD OP
|
||||
title: "MULMOD_2"
|
||||
code:
|
||||
PUSH3 "0x222222"
|
||||
PUSH1 "0x03"
|
||||
PUSH1 "0x04"
|
||||
MULMOD
|
||||
stack: "0x000000000000000000000000000000000000000000000000000000000000000C"
|
||||
|
||||
assembler: # MULMOD OP
|
||||
title: "MULMOD_3"
|
||||
code:
|
||||
PUSH3 "0x222222"
|
||||
PUSH3 "0x333333"
|
||||
PUSH3 "0x444444"
|
||||
MULMOD
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
assembler: # MULMOD OP
|
||||
title: "MULMOD_3"
|
||||
code:
|
||||
PUSH3 "0x222222"
|
||||
PUSH3 "0x333333"
|
||||
PUSH3 "0x444444"
|
||||
MULMOD
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
assembler: # MULMOD OP mal
|
||||
title: "MULMOD_4"
|
||||
code:
|
||||
PUSH1 "0x01"
|
||||
MULMOD
|
||||
success: false
|
||||
stack: "0x01"
|
||||
assembler: # MULMOD OP mal
|
||||
title: "MULMOD_4"
|
||||
code:
|
||||
PUSH1 "0x01"
|
||||
MULMOD
|
||||
success: false
|
||||
stack: "0x01"
|
||||
|
||||
assembler: # DIV OP
|
||||
title: "DIV_1"
|
||||
code:
|
||||
PUSH1 "0x02"
|
||||
PUSH1 "0x04"
|
||||
DIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000002"
|
||||
assembler: # DIV OP
|
||||
title: "DIV_1"
|
||||
code:
|
||||
PUSH1 "0x02"
|
||||
PUSH1 "0x04"
|
||||
DIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000002"
|
||||
|
||||
assembler: # DIV OP
|
||||
title: "DIV_2"
|
||||
code:
|
||||
PUSH1 "0x33"
|
||||
PUSH1 "0x99"
|
||||
DIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000003"
|
||||
assembler: # DIV OP
|
||||
title: "DIV_2"
|
||||
code:
|
||||
PUSH1 "0x33"
|
||||
PUSH1 "0x99"
|
||||
DIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000003"
|
||||
|
||||
assembler: # DIV OP
|
||||
title: "DIV_3"
|
||||
code:
|
||||
PUSH1 "0x22"
|
||||
PUSH1 "0x99"
|
||||
DIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000004"
|
||||
assembler: # DIV OP
|
||||
title: "DIV_3"
|
||||
code:
|
||||
PUSH1 "0x22"
|
||||
PUSH1 "0x99"
|
||||
DIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000004"
|
||||
|
||||
assembler: # DIV OP
|
||||
title: "DIV_4"
|
||||
code:
|
||||
PUSH1 "0x15"
|
||||
PUSH1 "0x99"
|
||||
DIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000007"
|
||||
assembler: # DIV OP
|
||||
title: "DIV_4"
|
||||
code:
|
||||
PUSH1 "0x15"
|
||||
PUSH1 "0x99"
|
||||
DIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000007"
|
||||
|
||||
assembler: # DIV OP
|
||||
title: "DIV_5"
|
||||
code:
|
||||
PUSH1 "0x04"
|
||||
PUSH1 "0x07"
|
||||
DIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
assembler: # DIV OP
|
||||
title: "DIV_5"
|
||||
code:
|
||||
PUSH1 "0x04"
|
||||
PUSH1 "0x07"
|
||||
DIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
|
||||
assembler: # DIV OP
|
||||
title: "DIV_6"
|
||||
code:
|
||||
PUSH1 "0x07"
|
||||
DIV
|
||||
success: false
|
||||
stack: "0x07"
|
||||
assembler: # DIV OP
|
||||
title: "DIV_6"
|
||||
code:
|
||||
PUSH1 "0x07"
|
||||
DIV
|
||||
success: false
|
||||
stack: "0x07"
|
||||
|
||||
assembler: # SDIV OP
|
||||
title: "SDIV_1"
|
||||
code:
|
||||
PUSH2 "0x03E8"
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC18"
|
||||
SDIV
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
|
||||
assembler: # SDIV OP
|
||||
title: "SDIV_1"
|
||||
code:
|
||||
PUSH2 "0x03E8"
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC18"
|
||||
SDIV
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
|
||||
|
||||
assembler: # SDIV OP
|
||||
title: "SDIV_2"
|
||||
code:
|
||||
PUSH1 "0xFF"
|
||||
PUSH1 "0xFF"
|
||||
SDIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
assembler: # SDIV OP
|
||||
title: "SDIV_2"
|
||||
code:
|
||||
PUSH1 "0xFF"
|
||||
PUSH1 "0xFF"
|
||||
SDIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
|
||||
assembler: # SDIV OP, SDIV by zero should be zero
|
||||
title: "SDIV_3"
|
||||
code:
|
||||
PUSH1 "0x00"
|
||||
PUSH1 "0xFF"
|
||||
SDIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
assembler: # SDIV OP, SDIV by zero should be zero
|
||||
title: "SDIV_3"
|
||||
code:
|
||||
PUSH1 "0x00"
|
||||
PUSH1 "0xFF"
|
||||
SDIV
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
assembler: # SDIV OP mal
|
||||
title: "SDIV_4"
|
||||
code:
|
||||
PUSH1 "0xFF"
|
||||
SDIV
|
||||
success: false
|
||||
stack: "0xFF"
|
||||
assembler: # SDIV OP mal
|
||||
title: "SDIV_4"
|
||||
code:
|
||||
PUSH1 "0xFF"
|
||||
SDIV
|
||||
success: false
|
||||
stack: "0xFF"
|
||||
|
||||
assembler: # -2^255 SDIV -1 = -2^255 (special case in yellow paper)
|
||||
title: "SDIV_5"
|
||||
code:
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" # -1
|
||||
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000" # -2^255 == low(int256)
|
||||
SDIV
|
||||
stack: "0x8000000000000000000000000000000000000000000000000000000000000000" # -2^255 == low(int256)
|
||||
assembler: # -2^255 SDIV -1 = -2^255 (special case in yellow paper)
|
||||
title: "SDIV_5"
|
||||
code:
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" # -1
|
||||
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000" # -2^255 == low(int256)
|
||||
SDIV
|
||||
stack: "0x8000000000000000000000000000000000000000000000000000000000000000" # -2^255 == low(int256)
|
||||
|
||||
assembler: # -2^255 SDIV 1 = -2^255
|
||||
title: "SDIV_6"
|
||||
code:
|
||||
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000001" # 1
|
||||
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000" # -2^255 == low(int256)
|
||||
SDIV
|
||||
stack: "0x8000000000000000000000000000000000000000000000000000000000000000" # -2^255 == low(int256)
|
||||
assembler: # -2^255 SDIV 1 = -2^255
|
||||
title: "SDIV_6"
|
||||
code:
|
||||
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000001" # 1
|
||||
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000" # -2^255 == low(int256)
|
||||
SDIV
|
||||
stack: "0x8000000000000000000000000000000000000000000000000000000000000000" # -2^255 == low(int256)
|
||||
|
||||
assembler: # -2 SDIV 2 = -1
|
||||
title: "SDIV_7"
|
||||
code:
|
||||
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000002" # 2
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE" # -2
|
||||
SDIV
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" # -1
|
||||
assembler: # -2 SDIV 2 = -1
|
||||
title: "SDIV_7"
|
||||
code:
|
||||
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000002" # 2
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE" # -2
|
||||
SDIV
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" # -1
|
||||
|
||||
assembler: # 4 SDIV -2 = -2
|
||||
title: "SDIV_8"
|
||||
code:
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE" # -2
|
||||
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000004" # 4
|
||||
SDIV
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE" # -2
|
||||
assembler: # 4 SDIV -2 = -2
|
||||
title: "SDIV_8"
|
||||
code:
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE" # -2
|
||||
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000004" # 4
|
||||
SDIV
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE" # -2
|
||||
|
||||
assembler: # -4 SDIV 2 = -2
|
||||
title: "SDIV_9"
|
||||
code:
|
||||
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000002" # -4
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC" # 2
|
||||
SDIV
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE" # -2
|
||||
assembler: # -4 SDIV 2 = -2
|
||||
title: "SDIV_9"
|
||||
code:
|
||||
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000002" # -4
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC" # 2
|
||||
SDIV
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE" # -2
|
||||
|
||||
assembler: # -1 SDIV 2 = 0
|
||||
title: "SDIV_10"
|
||||
code:
|
||||
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000002" # 2
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" # -1
|
||||
SDIV
|
||||
stack: "0x00" # 0
|
||||
assembler: # -1 SDIV 2 = 0
|
||||
title: "SDIV_10"
|
||||
code:
|
||||
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000002" # 2
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" # -1
|
||||
SDIV
|
||||
stack: "0x00" # 0
|
||||
|
||||
assembler: # low(int256) SDIV low(int256) = 1
|
||||
title: "SDIV_11"
|
||||
code:
|
||||
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000" # low(int256)
|
||||
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000" # low(int256)
|
||||
SDIV
|
||||
stack: "0x01" # 1
|
||||
assembler: # low(int256) SDIV low(int256) = 1
|
||||
title: "SDIV_11"
|
||||
code:
|
||||
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000" # low(int256)
|
||||
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000" # low(int256)
|
||||
SDIV
|
||||
stack: "0x01" # 1
|
||||
|
||||
assembler: # low(int256) SDIV 2
|
||||
title: "SDIV_12"
|
||||
code:
|
||||
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000002" # 2
|
||||
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000" # low(int256)
|
||||
SDIV
|
||||
stack: "0xC000000000000000000000000000000000000000000000000000000000000000" # negative half low(int256)
|
||||
assembler: # low(int256) SDIV 2
|
||||
title: "SDIV_12"
|
||||
code:
|
||||
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000002" # 2
|
||||
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000" # low(int256)
|
||||
SDIV
|
||||
stack: "0xC000000000000000000000000000000000000000000000000000000000000000" # negative half low(int256)
|
||||
|
||||
assembler: # low(int256) SDIV -2
|
||||
title: "SDIV_13"
|
||||
code:
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE" # -2
|
||||
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000" # low(int256)
|
||||
SDIV
|
||||
stack: "0x4000000000000000000000000000000000000000000000000000000000000000" # positive version of SDIV_12
|
||||
assembler: # low(int256) SDIV -2
|
||||
title: "SDIV_13"
|
||||
code:
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE" # -2
|
||||
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000" # low(int256)
|
||||
SDIV
|
||||
stack: "0x4000000000000000000000000000000000000000000000000000000000000000" # positive version of SDIV_12
|
||||
|
||||
assembler:
|
||||
title: "SDIV_14"
|
||||
code:
|
||||
PUSH1 "0x01" # 1
|
||||
PUSH1 "0x7F" # 127
|
||||
SHL # 1 shl 127 (move the bit to the center or 128th position)
|
||||
assembler:
|
||||
title: "SDIV_14"
|
||||
code:
|
||||
PUSH1 "0x01" # 1
|
||||
PUSH1 "0x7F" # 127
|
||||
SHL # 1 shl 127 (move the bit to the center or 128th position)
|
||||
|
||||
PUSH1 "0x01" # 1
|
||||
PUSH1 "0xFF" # 255
|
||||
SHL # 1 shl 255 (create low(int256))
|
||||
PUSH1 "0x01" # 1
|
||||
PUSH1 "0xFF" # 255
|
||||
SHL # 1 shl 255 (create low(int256))
|
||||
|
||||
SDIV
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000" # half of the hi bits are set
|
||||
fork: constantinople
|
||||
SDIV
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000" # half of the hi bits are set
|
||||
fork: constantinople
|
||||
|
||||
assembler: # SUB OP
|
||||
title: "SUB_1"
|
||||
code:
|
||||
PUSH1 "0x04"
|
||||
PUSH1 "0x06"
|
||||
SUB
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000002"
|
||||
assembler: # SUB OP
|
||||
title: "SUB_1"
|
||||
code:
|
||||
PUSH1 "0x04"
|
||||
PUSH1 "0x06"
|
||||
SUB
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000002"
|
||||
|
||||
assembler: # SUB OP
|
||||
title: "SUB_2"
|
||||
code:
|
||||
PUSH2 "0x4444"
|
||||
PUSH2 "0x6666"
|
||||
SUB
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000002222"
|
||||
assembler: # SUB OP
|
||||
title: "SUB_2"
|
||||
code:
|
||||
PUSH2 "0x4444"
|
||||
PUSH2 "0x6666"
|
||||
SUB
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000002222"
|
||||
|
||||
assembler: # SUB OP
|
||||
title: "SUB_3"
|
||||
code:
|
||||
PUSH2 "0x4444"
|
||||
PUSH4 "0x99996666"
|
||||
SUB
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000099992222"
|
||||
assembler: # SUB OP
|
||||
title: "SUB_3"
|
||||
code:
|
||||
PUSH2 "0x4444"
|
||||
PUSH4 "0x99996666"
|
||||
SUB
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000099992222"
|
||||
|
||||
assembler: # SUB OP mal
|
||||
title: "SUB_4"
|
||||
code:
|
||||
PUSH4 "0x99996666"
|
||||
SUB
|
||||
success: false
|
||||
stack: "0x99996666"
|
||||
assembler: # SUB OP mal
|
||||
title: "SUB_4"
|
||||
code:
|
||||
PUSH4 "0x99996666"
|
||||
SUB
|
||||
success: false
|
||||
stack: "0x99996666"
|
||||
|
||||
assembler: # EXP OP
|
||||
title: "EXP_1"
|
||||
code:
|
||||
PUSH1 "0x03"
|
||||
PUSH1 "0x02"
|
||||
EXP
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000008"
|
||||
#assertEquals(4, gas);
|
||||
assembler: # EXP OP
|
||||
title: "EXP_1"
|
||||
code:
|
||||
PUSH1 "0x03"
|
||||
PUSH1 "0x02"
|
||||
EXP
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000008"
|
||||
#assertEquals(4, gas);
|
||||
|
||||
assembler: # EXP OP
|
||||
title: "EXP_2"
|
||||
code:
|
||||
PUSH1 "0x00"
|
||||
PUSH3 "0x123456"
|
||||
EXP
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
#assertEquals(3, gas);
|
||||
assembler: # EXP OP
|
||||
title: "EXP_2"
|
||||
code:
|
||||
PUSH1 "0x00"
|
||||
PUSH3 "0x123456"
|
||||
EXP
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
#assertEquals(3, gas);
|
||||
|
||||
assembler: # EXP OP
|
||||
title: "EXP_3"
|
||||
code:
|
||||
PUSH2 "0x1122"
|
||||
PUSH1 "0x01"
|
||||
EXP
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
#assertEquals(5, gas);
|
||||
assembler: # EXP OP
|
||||
title: "EXP_3"
|
||||
code:
|
||||
PUSH2 "0x1122"
|
||||
PUSH1 "0x01"
|
||||
EXP
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
#assertEquals(5, gas);
|
||||
|
||||
assembler: # EXP OP mal
|
||||
title: "EXP_4"
|
||||
code:
|
||||
PUSH3 "0x123456"
|
||||
EXP
|
||||
success: false
|
||||
stack: "0x123456"
|
||||
assembler: # EXP OP mal
|
||||
title: "EXP_4"
|
||||
code:
|
||||
PUSH3 "0x123456"
|
||||
EXP
|
||||
success: false
|
||||
stack: "0x123456"
|
||||
|
||||
assembler: # MOD OP
|
||||
title: "MOD_1"
|
||||
code:
|
||||
PUSH1 "0x03"
|
||||
PUSH1 "0x04"
|
||||
MOD
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
assembler: # MOD OP
|
||||
title: "MOD_1"
|
||||
code:
|
||||
PUSH1 "0x03"
|
||||
PUSH1 "0x04"
|
||||
MOD
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
|
||||
assembler: # MOD OP
|
||||
title: "MOD_2"
|
||||
code:
|
||||
PUSH2 "0x012C"
|
||||
PUSH2 "0x01F4"
|
||||
MOD
|
||||
stack: "0x00000000000000000000000000000000000000000000000000000000000000C8"
|
||||
assembler: # MOD OP
|
||||
title: "MOD_2"
|
||||
code:
|
||||
PUSH2 "0x012C"
|
||||
PUSH2 "0x01F4"
|
||||
MOD
|
||||
stack: "0x00000000000000000000000000000000000000000000000000000000000000C8"
|
||||
|
||||
assembler: # MOD OP
|
||||
title: "MOD_3"
|
||||
code:
|
||||
PUSH1 "0x04"
|
||||
PUSH1 "0x02"
|
||||
MOD
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000002"
|
||||
assembler: # MOD OP
|
||||
title: "MOD_3"
|
||||
code:
|
||||
PUSH1 "0x04"
|
||||
PUSH1 "0x02"
|
||||
MOD
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000002"
|
||||
|
||||
assembler: # MOD OP mal
|
||||
title: "MOD_4"
|
||||
code:
|
||||
PUSH1 "0x04"
|
||||
MOD
|
||||
success: false
|
||||
stack: "0x04"
|
||||
assembler: # MOD OP mal
|
||||
title: "MOD_4"
|
||||
code:
|
||||
PUSH1 "0x04"
|
||||
MOD
|
||||
success: false
|
||||
stack: "0x04"
|
||||
|
||||
assembler: # SMOD OP
|
||||
title: "SMOD_1"
|
||||
code:
|
||||
PUSH1 "0x03"
|
||||
PUSH1 "0x04"
|
||||
SMOD
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
assembler: # SMOD OP
|
||||
title: "SMOD_1"
|
||||
code:
|
||||
PUSH1 "0x03"
|
||||
PUSH1 "0x04"
|
||||
SMOD
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
|
||||
assembler: # SMOD OP
|
||||
title: "SMOD_2"
|
||||
code:
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE2" # -30
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" # -170
|
||||
SMOD
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEC"
|
||||
assembler: # SMOD OP
|
||||
title: "SMOD_2"
|
||||
code:
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE2" # -30
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" # -170
|
||||
SMOD
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEC"
|
||||
|
||||
assembler: # SMOD OP
|
||||
title: "SMOD_3"
|
||||
code:
|
||||
PUSH32 "0x000000000000000000000000000000000000000000000000000000000000001E" # 30
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" # -170
|
||||
SMOD
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEC"
|
||||
assembler: # SMOD OP
|
||||
title: "SMOD_3"
|
||||
code:
|
||||
PUSH32 "0x000000000000000000000000000000000000000000000000000000000000001E" # 30
|
||||
PUSH32 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" # -170
|
||||
SMOD
|
||||
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEC"
|
||||
|
||||
assembler: # SMOD OP mal
|
||||
title: "SMOD_4"
|
||||
code:
|
||||
PUSH32 "0x000000000000000000000000000000000000000000000000000000000000001E" # 30
|
||||
SMOD
|
||||
success: false
|
||||
stack: "0x000000000000000000000000000000000000000000000000000000000000001E"
|
||||
assembler: # SMOD OP mal
|
||||
title: "SMOD_4"
|
||||
code:
|
||||
PUSH32 "0x000000000000000000000000000000000000000000000000000000000000001E" # 30
|
||||
SMOD
|
||||
success: false
|
||||
stack: "0x000000000000000000000000000000000000000000000000000000000000001E"
|
||||
|
||||
# real case, EVM bug, integer over flow
|
||||
assembler: # SIGNEXTEND OP
|
||||
title: "SIGNEXTEND_1"
|
||||
code:
|
||||
PUSH32 "0x000000000000000000000000000000003f9b347132d29b62d161117bca8c7307"
|
||||
PUSH1 "0x0F"
|
||||
SIGNEXTEND
|
||||
stack: "0x000000000000000000000000000000003f9b347132d29b62d161117bca8c7307"
|
||||
# real case, EVM bug, integer over flow
|
||||
assembler: # SIGNEXTEND OP
|
||||
title: "SIGNEXTEND_1"
|
||||
code:
|
||||
PUSH32 "0x000000000000000000000000000000003f9b347132d29b62d161117bca8c7307"
|
||||
PUSH1 "0x0F"
|
||||
SIGNEXTEND
|
||||
stack: "0x000000000000000000000000000000003f9b347132d29b62d161117bca8c7307"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,301 +3,302 @@ import
|
|||
stew/byteutils, eth/common, ../nimbus/db/state_db,
|
||||
../nimbus/db/db_chain, stew/ranges
|
||||
|
||||
suite "Custom Opcodes Test":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
proc opCustomMain*() =
|
||||
suite "Custom Opcodes Test":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
|
||||
assembler: # CALLDATASIZE OP
|
||||
title: "CALLDATASIZE_1"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
CallDataSize
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000040"
|
||||
assembler: # CALLDATASIZE OP
|
||||
title: "CALLDATASIZE_1"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
CallDataSize
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000040"
|
||||
|
||||
assembler: # CALLDATALOAD OP
|
||||
title: "CALLDATALOAD_1"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x00"
|
||||
CallDataLoad
|
||||
stack: "0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
assembler: # CALLDATALOAD OP
|
||||
title: "CALLDATALOAD_1"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x00"
|
||||
CallDataLoad
|
||||
stack: "0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
|
||||
assembler: # CALLDATALOAD OP
|
||||
title: "CALLDATALOAD_2"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x02"
|
||||
CallDataLoad
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000A10000"
|
||||
assembler: # CALLDATALOAD OP
|
||||
title: "CALLDATALOAD_2"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x02"
|
||||
CallDataLoad
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000A10000"
|
||||
|
||||
assembler: # CALLDATALOAD OP
|
||||
title: "CALLDATALOAD_3"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x20"
|
||||
CallDataLoad
|
||||
stack: "0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
assembler: # CALLDATALOAD OP
|
||||
title: "CALLDATALOAD_3"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x20"
|
||||
CallDataLoad
|
||||
stack: "0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
|
||||
assembler: # CALLDATALOAD OP
|
||||
title: "CALLDATALOAD_4"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x23"
|
||||
CallDataLoad
|
||||
stack: "0x00000000000000000000000000000000000000000000000000000000B1000000"
|
||||
assembler: # CALLDATALOAD OP
|
||||
title: "CALLDATALOAD_4"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x23"
|
||||
CallDataLoad
|
||||
stack: "0x00000000000000000000000000000000000000000000000000000000B1000000"
|
||||
|
||||
assembler: # CALLDATALOAD OP
|
||||
title: "CALLDATALOAD_5"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x3F"
|
||||
CallDataLoad
|
||||
stack: "0xB100000000000000000000000000000000000000000000000000000000000000"
|
||||
assembler: # CALLDATALOAD OP
|
||||
title: "CALLDATALOAD_5"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x3F"
|
||||
CallDataLoad
|
||||
stack: "0xB100000000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
assembler: # CALLDATALOAD OP mal
|
||||
title: "CALLDATALOAD_6"
|
||||
code:
|
||||
CallDataLoad
|
||||
success: false
|
||||
assembler: # CALLDATALOAD OP mal
|
||||
title: "CALLDATALOAD_6"
|
||||
code:
|
||||
CallDataLoad
|
||||
success: false
|
||||
|
||||
assembler: # CALLDATALOAD OP
|
||||
title: "CALLDATALOAD_7"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x40"
|
||||
CallDataLoad
|
||||
stack: "0x00"
|
||||
assembler: # CALLDATALOAD OP
|
||||
title: "CALLDATALOAD_7"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x40"
|
||||
CallDataLoad
|
||||
stack: "0x00"
|
||||
|
||||
assembler: # CALLDATACOPY OP
|
||||
title: "CALLDATACOPY_1"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x20"
|
||||
Push1 "0x00"
|
||||
Push1 "0x00"
|
||||
CallDataCopy
|
||||
memory: "0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
assembler: # CALLDATACOPY OP
|
||||
title: "CALLDATACOPY_1"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x20"
|
||||
Push1 "0x00"
|
||||
Push1 "0x00"
|
||||
CallDataCopy
|
||||
memory: "0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
|
||||
assembler: # CALLDATACOPY OP
|
||||
title: "CALLDATACOPY_2"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x40"
|
||||
Push1 "0x00"
|
||||
Push1 "0x00"
|
||||
CallDataCopy
|
||||
memory:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
assembler: # CALLDATACOPY OP
|
||||
title: "CALLDATACOPY_2"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x40"
|
||||
Push1 "0x00"
|
||||
Push1 "0x00"
|
||||
CallDataCopy
|
||||
memory:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
|
||||
assembler: # CALLDATACOPY OP
|
||||
title: "CALLDATACOPY_3"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x40"
|
||||
Push1 "0x04"
|
||||
Push1 "0x00"
|
||||
CallDataCopy
|
||||
memory:
|
||||
"0x000000000000000000000000000000000000000000000000000000A100000000"
|
||||
"0x000000000000000000000000000000000000000000000000000000B100000000"
|
||||
assembler: # CALLDATACOPY OP
|
||||
title: "CALLDATACOPY_3"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x40"
|
||||
Push1 "0x04"
|
||||
Push1 "0x00"
|
||||
CallDataCopy
|
||||
memory:
|
||||
"0x000000000000000000000000000000000000000000000000000000A100000000"
|
||||
"0x000000000000000000000000000000000000000000000000000000B100000000"
|
||||
|
||||
assembler: # CALLDATACOPY OP
|
||||
title: "CALLDATACOPY_4"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x40"
|
||||
Push1 "0x00"
|
||||
Push1 "0x04"
|
||||
CallDataCopy
|
||||
memory:
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
"0x000000A100000000000000000000000000000000000000000000000000000000"
|
||||
"0x000000B100000000000000000000000000000000000000000000000000000000"
|
||||
assembler: # CALLDATACOPY OP
|
||||
title: "CALLDATACOPY_4"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x40"
|
||||
Push1 "0x00"
|
||||
Push1 "0x04"
|
||||
CallDataCopy
|
||||
memory:
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
"0x000000A100000000000000000000000000000000000000000000000000000000"
|
||||
"0x000000B100000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
assembler: # CALLDATACOPY OP
|
||||
title: "CALLDATACOPY_5"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x40"
|
||||
Push1 "0x00"
|
||||
Push1 "0x04"
|
||||
CallDataCopy
|
||||
memory:
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
"0x000000A100000000000000000000000000000000000000000000000000000000"
|
||||
"0x000000B100000000000000000000000000000000000000000000000000000000"
|
||||
assembler: # CALLDATACOPY OP
|
||||
title: "CALLDATACOPY_5"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x40"
|
||||
Push1 "0x00"
|
||||
Push1 "0x04"
|
||||
CallDataCopy
|
||||
memory:
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
"0x000000A100000000000000000000000000000000000000000000000000000000"
|
||||
"0x000000B100000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
assembler: # CALLDATACOPY OP mal
|
||||
title: "CALLDATACOPY_6"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x40"
|
||||
Push1 "0x00"
|
||||
CallDataCopy
|
||||
success: false
|
||||
stack:
|
||||
"0x40"
|
||||
"0x00"
|
||||
assembler: # CALLDATACOPY OP mal
|
||||
title: "CALLDATACOPY_6"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code:
|
||||
Push1 "0x40"
|
||||
Push1 "0x00"
|
||||
CallDataCopy
|
||||
success: false
|
||||
stack:
|
||||
"0x40"
|
||||
"0x00"
|
||||
|
||||
assembler: # CALLDATACOPY OP mal
|
||||
title: "CALLDATACOPY_7"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code: "0x6020600073CC0929EB16730E7C14FEFC63006AC2D794C5795637"
|
||||
success: false
|
||||
assembler: # CALLDATACOPY OP mal
|
||||
title: "CALLDATACOPY_7"
|
||||
data:
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000A1"
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000B1"
|
||||
code: "0x6020600073CC0929EB16730E7C14FEFC63006AC2D794C5795637"
|
||||
success: false
|
||||
|
||||
assembler: # ADDRESS OP
|
||||
title: "ADDRESS_1"
|
||||
code:
|
||||
Address
|
||||
stack: "0x000000000000000000000000c669eaad75042be84daaf9b461b0e868b9ac1871"
|
||||
assembler: # ADDRESS OP
|
||||
title: "ADDRESS_1"
|
||||
code:
|
||||
Address
|
||||
stack: "0x000000000000000000000000c669eaad75042be84daaf9b461b0e868b9ac1871"
|
||||
|
||||
assembler: # BALANCE OP
|
||||
title: "BALANCE_1"
|
||||
code:
|
||||
Address
|
||||
Balance
|
||||
stack: "0x000000000000000000000000000000000000000000000000cff56a1b273a8000"
|
||||
assembler: # BALANCE OP
|
||||
title: "BALANCE_1"
|
||||
code:
|
||||
Address
|
||||
Balance
|
||||
stack: "0x000000000000000000000000000000000000000000000000cff56a1b273a8000"
|
||||
|
||||
assembler: # ORIGIN OP
|
||||
title: "ORIGIN_1"
|
||||
code:
|
||||
Origin
|
||||
stack: "0x000000000000000000000000fbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
assembler: # ORIGIN OP
|
||||
title: "ORIGIN_1"
|
||||
code:
|
||||
Origin
|
||||
stack: "0x000000000000000000000000fbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
|
||||
assembler: # CALLER OP
|
||||
title: "CALLER_1"
|
||||
code:
|
||||
Caller
|
||||
stack: "0x000000000000000000000000fbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
assembler: # CALLER OP
|
||||
title: "CALLER_1"
|
||||
code:
|
||||
Caller
|
||||
stack: "0x000000000000000000000000fbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
|
||||
assembler: # CALLVALUE OP
|
||||
title: "CALLVALUE_1"
|
||||
code:
|
||||
CallValue
|
||||
stack: "0xcff56a1b273a8000"
|
||||
assembler: # CALLVALUE OP
|
||||
title: "CALLVALUE_1"
|
||||
code:
|
||||
CallValue
|
||||
stack: "0xcff56a1b273a8000"
|
||||
|
||||
assembler: # SHA3 OP
|
||||
title: "SHA3_1"
|
||||
code:
|
||||
Push1 "0x01"
|
||||
Push1 "0x00"
|
||||
Mstore8
|
||||
Push1 "0x01"
|
||||
Push1 "0x00"
|
||||
Sha3
|
||||
stack: "0x5FE7F977E71DBA2EA1A68E21057BEEBB9BE2AC30C6410AA38D4F3FBE41DCFFD2"
|
||||
memory: "0x0100000000000000000000000000000000000000000000000000000000000000"
|
||||
assembler: # SHA3 OP
|
||||
title: "SHA3_1"
|
||||
code:
|
||||
Push1 "0x01"
|
||||
Push1 "0x00"
|
||||
Mstore8
|
||||
Push1 "0x01"
|
||||
Push1 "0x00"
|
||||
Sha3
|
||||
stack: "0x5FE7F977E71DBA2EA1A68E21057BEEBB9BE2AC30C6410AA38D4F3FBE41DCFFD2"
|
||||
memory: "0x0100000000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
assembler: # SHA3 OP
|
||||
title: "SHA3_2"
|
||||
code:
|
||||
Push2 "0x0201"
|
||||
Push1 "0x00"
|
||||
Mstore
|
||||
Push1 "0x02"
|
||||
Push1 "0x1E"
|
||||
Sha3
|
||||
stack: "0x114A3FE82A0219FCC31ABD15617966A125F12B0FD3409105FC83B487A9D82DE4"
|
||||
memory: "0x0000000000000000000000000000000000000000000000000000000000000201"
|
||||
assembler: # SHA3 OP
|
||||
title: "SHA3_2"
|
||||
code:
|
||||
Push2 "0x0201"
|
||||
Push1 "0x00"
|
||||
Mstore
|
||||
Push1 "0x02"
|
||||
Push1 "0x1E"
|
||||
Sha3
|
||||
stack: "0x114A3FE82A0219FCC31ABD15617966A125F12B0FD3409105FC83B487A9D82DE4"
|
||||
memory: "0x0000000000000000000000000000000000000000000000000000000000000201"
|
||||
|
||||
assembler: # SHA3 OP mal
|
||||
title: "SHA3_3"
|
||||
code:
|
||||
Push2 "0x0201"
|
||||
Push1 "0x00"
|
||||
Mstore
|
||||
Push1 "0x02"
|
||||
Sha3
|
||||
success: false
|
||||
stack: "0x02"
|
||||
memory: "0x0000000000000000000000000000000000000000000000000000000000000201"
|
||||
assembler: # SHA3 OP mal
|
||||
title: "SHA3_3"
|
||||
code:
|
||||
Push2 "0x0201"
|
||||
Push1 "0x00"
|
||||
Mstore
|
||||
Push1 "0x02"
|
||||
Sha3
|
||||
success: false
|
||||
stack: "0x02"
|
||||
memory: "0x0000000000000000000000000000000000000000000000000000000000000201"
|
||||
|
||||
assembler: # BLOCKHASH OP
|
||||
title: "BLOCKHASH_1"
|
||||
code:
|
||||
Push2 "0xb864" # 47204, parent header number
|
||||
Blockhash
|
||||
stack: "0xa85842a20755232169db76c5bd4ad4672c1551fca4b07d0bd139cd0e6fef684d"
|
||||
assembler: # BLOCKHASH OP
|
||||
title: "BLOCKHASH_1"
|
||||
code:
|
||||
Push2 "0xb864" # 47204, parent header number
|
||||
Blockhash
|
||||
stack: "0xa85842a20755232169db76c5bd4ad4672c1551fca4b07d0bd139cd0e6fef684d"
|
||||
|
||||
# current block coinbase/miner
|
||||
assembler: # COINBASE OP
|
||||
title: "COINBASE_1"
|
||||
code:
|
||||
Coinbase
|
||||
stack: "0x000000000000000000000000bb7b8287f3f0a933474a79eae42cbca977791171"
|
||||
# current block coinbase/miner
|
||||
assembler: # COINBASE OP
|
||||
title: "COINBASE_1"
|
||||
code:
|
||||
Coinbase
|
||||
stack: "0x000000000000000000000000bb7b8287f3f0a933474a79eae42cbca977791171"
|
||||
|
||||
# current block timestamp
|
||||
assembler: # TIMESTAMP OP
|
||||
title: "TIMESTAMP_1"
|
||||
code:
|
||||
TimeStamp
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000055c46bba"
|
||||
# current block timestamp
|
||||
assembler: # TIMESTAMP OP
|
||||
title: "TIMESTAMP_1"
|
||||
code:
|
||||
TimeStamp
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000055c46bba"
|
||||
|
||||
# current block number
|
||||
assembler: # NUMBER OP
|
||||
title: "NUMBER_1"
|
||||
code:
|
||||
Number
|
||||
stack: "0x000000000000000000000000000000000000000000000000000000000000b865"
|
||||
# current block number
|
||||
assembler: # NUMBER OP
|
||||
title: "NUMBER_1"
|
||||
code:
|
||||
Number
|
||||
stack: "0x000000000000000000000000000000000000000000000000000000000000b865"
|
||||
|
||||
# current difficulty
|
||||
assembler: # DIFFICULTY OP
|
||||
title: "DIFFICULTY_1"
|
||||
code:
|
||||
Difficulty
|
||||
stack: "0x000000000000000000000000000000000000000000000000000001547c73822d"
|
||||
# current difficulty
|
||||
assembler: # DIFFICULTY OP
|
||||
title: "DIFFICULTY_1"
|
||||
code:
|
||||
Difficulty
|
||||
stack: "0x000000000000000000000000000000000000000000000000000001547c73822d"
|
||||
|
||||
# ??
|
||||
assembler: # GASPRICE OP
|
||||
title: "GASPRICE_1"
|
||||
code:
|
||||
GasPrice
|
||||
stack: "0x000000000000000000000000000000000000000000000000000000746a528800"
|
||||
# ??
|
||||
assembler: # GASPRICE OP
|
||||
title: "GASPRICE_1"
|
||||
code:
|
||||
GasPrice
|
||||
stack: "0x000000000000000000000000000000000000000000000000000000746a528800"
|
||||
|
||||
# ??
|
||||
assembler: # GAS OP
|
||||
title: "GAS_1"
|
||||
code:
|
||||
Gas
|
||||
stack: "0x000000000000000000000000000000000000000000000000000000001dcd64fe"
|
||||
# ??
|
||||
assembler: # GAS OP
|
||||
title: "GAS_1"
|
||||
code:
|
||||
Gas
|
||||
stack: "0x000000000000000000000000000000000000000000000000000000001dcd64fe"
|
||||
|
||||
# ??
|
||||
assembler: # GASLIMIT OP
|
||||
title: "GASLIMIT_1"
|
||||
code:
|
||||
GasLimit
|
||||
stack: "0x000000000000000000000000000000000000000000000000000000000000a298"
|
||||
# ??
|
||||
assembler: # GASLIMIT OP
|
||||
title: "GASLIMIT_1"
|
||||
code:
|
||||
GasLimit
|
||||
stack: "0x000000000000000000000000000000000000000000000000000000000000a298"
|
||||
|
||||
assembler: # INVALID OP
|
||||
title: "INVALID_1"
|
||||
code: "0x60012F6002"
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
success: false
|
||||
assembler: # INVALID OP
|
||||
title: "INVALID_1"
|
||||
code: "0x60012F6002"
|
||||
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
|
||||
success: false
|
||||
|
|
|
@ -3,302 +3,303 @@ import
|
|||
stew/byteutils, eth/common, ../nimbus/db/state_db,
|
||||
../nimbus/db/db_chain, stew/ranges
|
||||
|
||||
suite "Environmental Information Opcodes":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
proc opEnvMain*() =
|
||||
suite "Environmental Information Opcodes":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
|
||||
assembler: # CODECOPY OP
|
||||
title: "CODECOPY_1"
|
||||
code:
|
||||
PUSH1 "0x03" # size
|
||||
PUSH1 "0x08" # copy start pos
|
||||
PUSH1 "0x00" # mem start pos
|
||||
CODECOPY
|
||||
STOP
|
||||
SLT
|
||||
CALLVALUE
|
||||
JUMP
|
||||
memory: "0x1234560000000000000000000000000000000000000000000000000000000000"
|
||||
# assertEquals(6, gas); ??
|
||||
assembler: # CODECOPY OP
|
||||
title: "CODECOPY_1"
|
||||
code:
|
||||
PUSH1 "0x03" # size
|
||||
PUSH1 "0x08" # copy start pos
|
||||
PUSH1 "0x00" # mem start pos
|
||||
CODECOPY
|
||||
STOP
|
||||
SLT
|
||||
CALLVALUE
|
||||
JUMP
|
||||
memory: "0x1234560000000000000000000000000000000000000000000000000000000000"
|
||||
# assertEquals(6, gas); ??
|
||||
|
||||
assembler: # CODECOPY OP
|
||||
title: "CODECOPY_2"
|
||||
code:
|
||||
PUSH1 "0x5E" # size
|
||||
PUSH1 "0x08" # copy start pos
|
||||
PUSH1 "0x00" # mem start pos
|
||||
CODECOPY
|
||||
STOP
|
||||
PUSH1 "0x00"
|
||||
PUSH1 "0x5f"
|
||||
SSTORE
|
||||
PUSH1 "0x14"
|
||||
PUSH1 "0x00"
|
||||
SLOAD
|
||||
PUSH1 "0x1e"
|
||||
PUSH1 "0x20"
|
||||
SLOAD
|
||||
PUSH4 "0xabcddcba"
|
||||
PUSH1 "0x40"
|
||||
SLOAD
|
||||
JUMPDEST
|
||||
MLOAD
|
||||
PUSH1 "0x20"
|
||||
ADD
|
||||
PUSH1 "0x0a"
|
||||
MSTORE
|
||||
SLOAD
|
||||
MLOAD
|
||||
PUSH1 "0x40"
|
||||
ADD
|
||||
PUSH1 "0x14"
|
||||
MSTORE
|
||||
SLOAD
|
||||
MLOAD
|
||||
PUSH1 "0x60"
|
||||
ADD
|
||||
PUSH1 "0x1e"
|
||||
MSTORE
|
||||
SLOAD
|
||||
MLOAD
|
||||
PUSH1 "0x80"
|
||||
ADD
|
||||
PUSH1 "0x28"
|
||||
MSTORE
|
||||
SLOAD
|
||||
PUSH1 "0xa0"
|
||||
MSTORE
|
||||
SLOAD
|
||||
PUSH1 "0x16"
|
||||
PUSH1 "0x48"
|
||||
PUSH1 "0x00"
|
||||
CODECOPY
|
||||
PUSH1 "0x16"
|
||||
PUSH1 "0x00"
|
||||
CALLCODE
|
||||
PUSH1 "0x00"
|
||||
PUSH1 "0x3f"
|
||||
SSTORE
|
||||
PUSH2 "0x03e7"
|
||||
JUMP
|
||||
PUSH1 "0x00"
|
||||
SLOAD
|
||||
PUSH1 "0x00"
|
||||
MSTORE8
|
||||
PUSH1 "0x20"
|
||||
MUL
|
||||
CALLDATALOAD
|
||||
PUSH1 "0x20"
|
||||
SLOAD
|
||||
memory:
|
||||
"0x6000605F556014600054601E60205463ABCDDCBA6040545B51602001600A5254"
|
||||
"0x516040016014525451606001601E5254516080016028525460A0525460166048"
|
||||
"0x60003960166000F26000603F556103E756600054600053602002356020540000"
|
||||
#assertEquals(10, gas); ??
|
||||
assembler: # CODECOPY OP
|
||||
title: "CODECOPY_2"
|
||||
code:
|
||||
PUSH1 "0x5E" # size
|
||||
PUSH1 "0x08" # copy start pos
|
||||
PUSH1 "0x00" # mem start pos
|
||||
CODECOPY
|
||||
STOP
|
||||
PUSH1 "0x00"
|
||||
PUSH1 "0x5f"
|
||||
SSTORE
|
||||
PUSH1 "0x14"
|
||||
PUSH1 "0x00"
|
||||
SLOAD
|
||||
PUSH1 "0x1e"
|
||||
PUSH1 "0x20"
|
||||
SLOAD
|
||||
PUSH4 "0xabcddcba"
|
||||
PUSH1 "0x40"
|
||||
SLOAD
|
||||
JUMPDEST
|
||||
MLOAD
|
||||
PUSH1 "0x20"
|
||||
ADD
|
||||
PUSH1 "0x0a"
|
||||
MSTORE
|
||||
SLOAD
|
||||
MLOAD
|
||||
PUSH1 "0x40"
|
||||
ADD
|
||||
PUSH1 "0x14"
|
||||
MSTORE
|
||||
SLOAD
|
||||
MLOAD
|
||||
PUSH1 "0x60"
|
||||
ADD
|
||||
PUSH1 "0x1e"
|
||||
MSTORE
|
||||
SLOAD
|
||||
MLOAD
|
||||
PUSH1 "0x80"
|
||||
ADD
|
||||
PUSH1 "0x28"
|
||||
MSTORE
|
||||
SLOAD
|
||||
PUSH1 "0xa0"
|
||||
MSTORE
|
||||
SLOAD
|
||||
PUSH1 "0x16"
|
||||
PUSH1 "0x48"
|
||||
PUSH1 "0x00"
|
||||
CODECOPY
|
||||
PUSH1 "0x16"
|
||||
PUSH1 "0x00"
|
||||
CALLCODE
|
||||
PUSH1 "0x00"
|
||||
PUSH1 "0x3f"
|
||||
SSTORE
|
||||
PUSH2 "0x03e7"
|
||||
JUMP
|
||||
PUSH1 "0x00"
|
||||
SLOAD
|
||||
PUSH1 "0x00"
|
||||
MSTORE8
|
||||
PUSH1 "0x20"
|
||||
MUL
|
||||
CALLDATALOAD
|
||||
PUSH1 "0x20"
|
||||
SLOAD
|
||||
memory:
|
||||
"0x6000605F556014600054601E60205463ABCDDCBA6040545B51602001600A5254"
|
||||
"0x516040016014525451606001601E5254516080016028525460A0525460166048"
|
||||
"0x60003960166000F26000603F556103E756600054600053602002356020540000"
|
||||
#assertEquals(10, gas); ??
|
||||
|
||||
assembler: # CODECOPY OP
|
||||
title: "CODECOPY_3"
|
||||
# cost for that:
|
||||
# 94 - data copied
|
||||
# 95 - new bytes allocated
|
||||
code:
|
||||
Push1 "0x5E"
|
||||
Push1 "0x08"
|
||||
Push1 "0x00"
|
||||
CodeCopy
|
||||
STOP
|
||||
"0x6000605f556014600054601e60205463abcddcba6040545b"
|
||||
"0x51602001600a5254516040016014525451606001601e52545160800160285254"
|
||||
"0x60a052546016604860003960166000f26000603f556103e75660005460005360"
|
||||
"0x20023500"
|
||||
memory:
|
||||
"0x6000605F556014600054601E60205463ABCDDCBA6040545B51602001600A5254"
|
||||
"0x516040016014525451606001601E5254516080016028525460A0525460166048"
|
||||
"0x60003960166000F26000603F556103E756600054600053602002350000000000"
|
||||
#assertEquals(10, program.getResult().getGasUsed());
|
||||
assembler: # CODECOPY OP
|
||||
title: "CODECOPY_3"
|
||||
# cost for that:
|
||||
# 94 - data copied
|
||||
# 95 - new bytes allocated
|
||||
code:
|
||||
Push1 "0x5E"
|
||||
Push1 "0x08"
|
||||
Push1 "0x00"
|
||||
CodeCopy
|
||||
STOP
|
||||
"0x6000605f556014600054601e60205463abcddcba6040545b"
|
||||
"0x51602001600a5254516040016014525451606001601e52545160800160285254"
|
||||
"0x60a052546016604860003960166000f26000603f556103e75660005460005360"
|
||||
"0x20023500"
|
||||
memory:
|
||||
"0x6000605F556014600054601E60205463ABCDDCBA6040545B51602001600A5254"
|
||||
"0x516040016014525451606001601E5254516080016028525460A0525460166048"
|
||||
"0x60003960166000F26000603F556103E756600054600053602002350000000000"
|
||||
#assertEquals(10, program.getResult().getGasUsed());
|
||||
|
||||
assembler: # CODECOPY OP
|
||||
title: "CODECOPY_4"
|
||||
code:
|
||||
Push1 "0x5E"
|
||||
Push1 "0x07"
|
||||
Push1 "0x00"
|
||||
CodeCopy
|
||||
STOP
|
||||
"0x6000605f556014600054601e60205463abcddcba6040545b51"
|
||||
"0x602001600a5254516040016014525451606001601e5254516080016028525460"
|
||||
"0xa052546016604860003960166000f26000603f556103e756600054600053602002351234"
|
||||
memory:
|
||||
"0x006000605F556014600054601E60205463ABCDDCBA6040545B51602001600A52"
|
||||
"0x54516040016014525451606001601E5254516080016028525460A05254601660"
|
||||
"0x4860003960166000F26000603F556103E7566000546000536020023512340000"
|
||||
#assertEquals(10, program.getResult().getGasUsed());
|
||||
assembler: # CODECOPY OP
|
||||
title: "CODECOPY_4"
|
||||
code:
|
||||
Push1 "0x5E"
|
||||
Push1 "0x07"
|
||||
Push1 "0x00"
|
||||
CodeCopy
|
||||
STOP
|
||||
"0x6000605f556014600054601e60205463abcddcba6040545b51"
|
||||
"0x602001600a5254516040016014525451606001601e5254516080016028525460"
|
||||
"0xa052546016604860003960166000f26000603f556103e756600054600053602002351234"
|
||||
memory:
|
||||
"0x006000605F556014600054601E60205463ABCDDCBA6040545B51602001600A52"
|
||||
"0x54516040016014525451606001601E5254516080016028525460A05254601660"
|
||||
"0x4860003960166000F26000603F556103E7566000546000536020023512340000"
|
||||
#assertEquals(10, program.getResult().getGasUsed());
|
||||
|
||||
assembler: # CODECOPY OP
|
||||
title: "CODECOPY_5"
|
||||
code:
|
||||
Push2 "0x1234"
|
||||
Push1 "0x00"
|
||||
Sload
|
||||
Push2 "0x5566"
|
||||
Push1 "0x20"
|
||||
Sload
|
||||
Push1 "0x70"
|
||||
Push1 "0x00"
|
||||
Push1 "0x20"
|
||||
CodeCopy
|
||||
STOP
|
||||
"0x6000605f55601460"
|
||||
"0x0054601e60205463abcddcba6040545b51602001600a525451604001"
|
||||
"0x6014525451606001601e5254516080016028525460a0525460166048"
|
||||
"0x60003960166000f26000603f556103e75660005460005360200235123400"
|
||||
stack:
|
||||
"0x1234"
|
||||
"0x00"
|
||||
"0x5566"
|
||||
"0x00"
|
||||
memory:
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
"0x61123460005461556660205460706000602039006000605f556014600054601e"
|
||||
"0x60205463abcddcba6040545b51602001600a5254516040016014525451606001"
|
||||
"0x601e5254516080016028525460a052546016604860003960166000f26000603f"
|
||||
"0x556103e756600054600053602002351200000000000000000000000000000000"
|
||||
assembler: # CODECOPY OP
|
||||
title: "CODECOPY_5"
|
||||
code:
|
||||
Push2 "0x1234"
|
||||
Push1 "0x00"
|
||||
Sload
|
||||
Push2 "0x5566"
|
||||
Push1 "0x20"
|
||||
Sload
|
||||
Push1 "0x70"
|
||||
Push1 "0x00"
|
||||
Push1 "0x20"
|
||||
CodeCopy
|
||||
STOP
|
||||
"0x6000605f55601460"
|
||||
"0x0054601e60205463abcddcba6040545b51602001600a525451604001"
|
||||
"0x6014525451606001601e5254516080016028525460a0525460166048"
|
||||
"0x60003960166000f26000603f556103e75660005460005360200235123400"
|
||||
stack:
|
||||
"0x1234"
|
||||
"0x00"
|
||||
"0x5566"
|
||||
"0x00"
|
||||
memory:
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
"0x61123460005461556660205460706000602039006000605f556014600054601e"
|
||||
"0x60205463abcddcba6040545b51602001600a5254516040016014525451606001"
|
||||
"0x601e5254516080016028525460a052546016604860003960166000f26000603f"
|
||||
"0x556103e756600054600053602002351200000000000000000000000000000000"
|
||||
|
||||
assembler: # CODECOPY OP mal
|
||||
title: "CODECOPY_6"
|
||||
code:
|
||||
"0x605E6007396000605f556014600054601e60205463abcddcba604054"
|
||||
"0x5b51602001600a5254516040016014525451606001601e5254516080"
|
||||
"0x016028525460a052546016604860003960166000f26000603f556103"
|
||||
"0xe756600054600053602002351234"
|
||||
success: false
|
||||
stack:
|
||||
"0x5e"
|
||||
"0x07"
|
||||
assembler: # CODECOPY OP mal
|
||||
title: "CODECOPY_6"
|
||||
code:
|
||||
"0x605E6007396000605f556014600054601e60205463abcddcba604054"
|
||||
"0x5b51602001600a5254516040016014525451606001601e5254516080"
|
||||
"0x016028525460a052546016604860003960166000f26000603f556103"
|
||||
"0xe756600054600053602002351234"
|
||||
success: false
|
||||
stack:
|
||||
"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")
|
||||
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"
|
||||
code:
|
||||
Push1 "0x04" # size
|
||||
Push1 "0x07" # code pos
|
||||
Push1 "0x00" # mem pos
|
||||
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
ExtCodeCopy
|
||||
STOP
|
||||
Slt
|
||||
CallValue
|
||||
Jump
|
||||
Stop
|
||||
memory: "0x08090a0b00000000000000000000000000000000000000000000000000000000"
|
||||
assembler: # EXTCODECOPY OP
|
||||
title: "EXTCODECOPY_1"
|
||||
code:
|
||||
Push1 "0x04" # size
|
||||
Push1 "0x07" # code pos
|
||||
Push1 "0x00" # mem pos
|
||||
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
ExtCodeCopy
|
||||
STOP
|
||||
Slt
|
||||
CallValue
|
||||
Jump
|
||||
Stop
|
||||
memory: "0x08090a0b00000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
assembler: # EXTCODECOPY OP
|
||||
title: "EXTCODECOPY_2"
|
||||
code:
|
||||
Push1 "0x3E"
|
||||
Push1 "0x07"
|
||||
Push1 "0x00"
|
||||
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
ExtCodeCopy
|
||||
STOP
|
||||
"0x6000605f"
|
||||
"0x556014600054601e60205463abcddcba6040545b51602001600a525451604001"
|
||||
"0x6014525451606001601e5254516080016028525460a052546016604860003960"
|
||||
"0x166000f26000603f556103e75660005460005360200235602054"
|
||||
memory:
|
||||
"0x08090a0b0c0d0e0f611234600054615566602054603e6000602073471fd3ad3e"
|
||||
"0x9eeadeec4608b92d16ce6b500704cc3c6000605f556014600054601e60200000"
|
||||
assembler: # EXTCODECOPY OP
|
||||
title: "EXTCODECOPY_2"
|
||||
code:
|
||||
Push1 "0x3E"
|
||||
Push1 "0x07"
|
||||
Push1 "0x00"
|
||||
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
ExtCodeCopy
|
||||
STOP
|
||||
"0x6000605f"
|
||||
"0x556014600054601e60205463abcddcba6040545b51602001600a525451604001"
|
||||
"0x6014525451606001601e5254516080016028525460a052546016604860003960"
|
||||
"0x166000f26000603f556103e75660005460005360200235602054"
|
||||
memory:
|
||||
"0x08090a0b0c0d0e0f611234600054615566602054603e6000602073471fd3ad3e"
|
||||
"0x9eeadeec4608b92d16ce6b500704cc3c6000605f556014600054601e60200000"
|
||||
|
||||
assembler: # EXTCODECOPY OP
|
||||
title: "EXTCODECOPY_3"
|
||||
code:
|
||||
Push1 "0x5E"
|
||||
Push1 "0x07"
|
||||
Push1 "0x00"
|
||||
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
ExtCodeCopy
|
||||
STOP
|
||||
"0x6000605f"
|
||||
"0x556014600054601e60205463abcddcba6040545b51602001600a525451604001"
|
||||
"0x6014525451606001601e5254516080016028525460a052546016604860003960"
|
||||
"0x166000f26000603f556103e75660005460005360200235"
|
||||
memory:
|
||||
"0x08090a0b0c0d0e0f611234600054615566602054603e6000602073471fd3ad3e"
|
||||
"0x9eeadeec4608b92d16ce6b500704cc3c6000605f556014600054601e60205463"
|
||||
"0xabcddcba6040545b51602001600a5254516040016014525451606001601e0000"
|
||||
assembler: # EXTCODECOPY OP
|
||||
title: "EXTCODECOPY_3"
|
||||
code:
|
||||
Push1 "0x5E"
|
||||
Push1 "0x07"
|
||||
Push1 "0x00"
|
||||
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
ExtCodeCopy
|
||||
STOP
|
||||
"0x6000605f"
|
||||
"0x556014600054601e60205463abcddcba6040545b51602001600a525451604001"
|
||||
"0x6014525451606001601e5254516080016028525460a052546016604860003960"
|
||||
"0x166000f26000603f556103e75660005460005360200235"
|
||||
memory:
|
||||
"0x08090a0b0c0d0e0f611234600054615566602054603e6000602073471fd3ad3e"
|
||||
"0x9eeadeec4608b92d16ce6b500704cc3c6000605f556014600054601e60205463"
|
||||
"0xabcddcba6040545b51602001600a5254516040016014525451606001601e0000"
|
||||
|
||||
assembler: # EXTCODECOPY OP
|
||||
title: "EXTCODECOPY_4"
|
||||
code:
|
||||
Push2 "0x1234"
|
||||
Push1 "0x00"
|
||||
Sload
|
||||
Push2 "0x5566"
|
||||
Push1 "0x20"
|
||||
Sload
|
||||
Push1 "0x3E"
|
||||
Push1 "0x00"
|
||||
Push1 "0x20"
|
||||
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
ExtCodeCopy
|
||||
STOP
|
||||
"0x6000605f556014600054601e60205463abcddcba6040545b"
|
||||
"0x51602001600a5254516040016014525451606001601e52545160800160285254"
|
||||
"0x60a052546016604860003960166000f26000603f556103e756600054600053602002351234"
|
||||
stack:
|
||||
"0x1234"
|
||||
"0x00"
|
||||
"0x5566"
|
||||
"0x00"
|
||||
memory:
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
"0x0102030405060708090a0b0c0d0e0f611234600054615566602054603e600060"
|
||||
"0x2073471fd3ad3e9eeadeec4608b92d16ce6b500704cc3c6000605f5560140000"
|
||||
assembler: # EXTCODECOPY OP
|
||||
title: "EXTCODECOPY_4"
|
||||
code:
|
||||
Push2 "0x1234"
|
||||
Push1 "0x00"
|
||||
Sload
|
||||
Push2 "0x5566"
|
||||
Push1 "0x20"
|
||||
Sload
|
||||
Push1 "0x3E"
|
||||
Push1 "0x00"
|
||||
Push1 "0x20"
|
||||
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
ExtCodeCopy
|
||||
STOP
|
||||
"0x6000605f556014600054601e60205463abcddcba6040545b"
|
||||
"0x51602001600a5254516040016014525451606001601e52545160800160285254"
|
||||
"0x60a052546016604860003960166000f26000603f556103e756600054600053602002351234"
|
||||
stack:
|
||||
"0x1234"
|
||||
"0x00"
|
||||
"0x5566"
|
||||
"0x00"
|
||||
memory:
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
"0x0102030405060708090a0b0c0d0e0f611234600054615566602054603e600060"
|
||||
"0x2073471fd3ad3e9eeadeec4608b92d16ce6b500704cc3c6000605f5560140000"
|
||||
|
||||
assembler: # EXTCODECOPY OP mal
|
||||
title: "EXTCODECOPY_5"
|
||||
code:
|
||||
Push1 "0x5E"
|
||||
Push1 "0x07"
|
||||
Push20 "0x471FD3AD3E9EEADEEC4608B92D16CE6B500704CC"
|
||||
ExtCodeCopy
|
||||
success: false
|
||||
stack:
|
||||
"0x5E"
|
||||
"0x07"
|
||||
assembler: # EXTCODECOPY OP mal
|
||||
title: "EXTCODECOPY_5"
|
||||
code:
|
||||
Push1 "0x5E"
|
||||
Push1 "0x07"
|
||||
Push20 "0x471FD3AD3E9EEADEEC4608B92D16CE6B500704CC"
|
||||
ExtCodeCopy
|
||||
success: false
|
||||
stack:
|
||||
"0x5E"
|
||||
"0x07"
|
||||
|
||||
assembler: # CODESIZE OP
|
||||
title: "CODESIZE_1"
|
||||
code:
|
||||
"0x385E60076000396000605f556014600054601e60205463abcddcba6040545b51"
|
||||
"0x602001600a5254516040016014525451606001601e5254516080016028525460"
|
||||
"0xa052546016604860003960166000f26000603f556103e75660005460005360200235"
|
||||
stack:
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000062"
|
||||
success: false
|
||||
assembler: # CODESIZE OP
|
||||
title: "CODESIZE_1"
|
||||
code:
|
||||
"0x385E60076000396000605f556014600054601e60205463abcddcba6040545b51"
|
||||
"0x602001600a5254516040016014525451606001601e5254516080016028525460"
|
||||
"0xa052546016604860003960166000f26000603f556103e75660005460005360200235"
|
||||
stack:
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000062"
|
||||
success: false
|
||||
|
||||
# 0x94 == 148 bytes
|
||||
assembler: # EXTCODESIZE OP
|
||||
title: "EXTCODESIZE_1"
|
||||
code:
|
||||
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
ExtCodeSize
|
||||
STOP
|
||||
"0x5E60076000396000605f"
|
||||
"0x556014600054601e60205463abcddcba6040545b51602001600a525451604001"
|
||||
"0x6014525451606001601e5254516080016028525460a052546016604860003960"
|
||||
"0x166000f26000603f556103e75660005460005360200235"
|
||||
stack: "0x94"
|
||||
# 0x94 == 148 bytes
|
||||
assembler: # EXTCODESIZE OP
|
||||
title: "EXTCODESIZE_1"
|
||||
code:
|
||||
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
|
||||
ExtCodeSize
|
||||
STOP
|
||||
"0x5E60076000396000605f"
|
||||
"0x556014600054601e60205463abcddcba6040545b51602001600a525451604001"
|
||||
"0x6014525451606001601e5254516080016028525460a052546016604860003960"
|
||||
"0x166000f26000603f556103e75660005460005360200235"
|
||||
stack: "0x94"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,174 +3,175 @@ import
|
|||
stew/byteutils, eth/common, ../nimbus/db/state_db,
|
||||
../nimbus/db/db_chain, stew/ranges
|
||||
|
||||
suite "Misc Opcodes":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
proc opMiscMain*() =
|
||||
suite "Misc Opcodes":
|
||||
let (blockNumber, chainDB) = initDatabase()
|
||||
|
||||
assembler: # LOG0 OP
|
||||
title: "Log0"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
LOG0
|
||||
memory:
|
||||
"0x1234"
|
||||
logs:
|
||||
(
|
||||
address: "0xc669eaad75042be84daaf9b461b0e868b9ac1871",
|
||||
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
||||
)
|
||||
assembler: # LOG0 OP
|
||||
title: "Log0"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
LOG0
|
||||
memory:
|
||||
"0x1234"
|
||||
logs:
|
||||
(
|
||||
address: "0xc669eaad75042be84daaf9b461b0e868b9ac1871",
|
||||
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
||||
)
|
||||
|
||||
assembler: # LOG1 OP
|
||||
title: "Log1"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH2 "0x9999"
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
LOG1
|
||||
memory:
|
||||
"0x1234"
|
||||
logs:
|
||||
(
|
||||
address: "0xc669eaad75042be84daaf9b461b0e868b9ac1871",
|
||||
topics: ["0x9999"],
|
||||
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
||||
)
|
||||
assembler: # LOG1 OP
|
||||
title: "Log1"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH2 "0x9999"
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
LOG1
|
||||
memory:
|
||||
"0x1234"
|
||||
logs:
|
||||
(
|
||||
address: "0xc669eaad75042be84daaf9b461b0e868b9ac1871",
|
||||
topics: ["0x9999"],
|
||||
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
||||
)
|
||||
|
||||
assembler: # LOG2 OP
|
||||
title: "Log2"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH2 "0x9999"
|
||||
PUSH2 "0x6666"
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
LOG2
|
||||
memory:
|
||||
"0x1234"
|
||||
logs:
|
||||
(
|
||||
address: "0xc669eaad75042be84daaf9b461b0e868b9ac1871",
|
||||
topics: ["0x6666", "0x9999"],
|
||||
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
||||
)
|
||||
assembler: # LOG2 OP
|
||||
title: "Log2"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH2 "0x9999"
|
||||
PUSH2 "0x6666"
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
LOG2
|
||||
memory:
|
||||
"0x1234"
|
||||
logs:
|
||||
(
|
||||
address: "0xc669eaad75042be84daaf9b461b0e868b9ac1871",
|
||||
topics: ["0x6666", "0x9999"],
|
||||
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
||||
)
|
||||
|
||||
assembler: # LOG3 OP
|
||||
title: "Log3"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH2 "0x9999"
|
||||
PUSH2 "0x6666"
|
||||
PUSH2 "0x3333"
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
LOG3
|
||||
memory:
|
||||
"0x1234"
|
||||
logs:
|
||||
(
|
||||
address: "0xc669eaad75042be84daaf9b461b0e868b9ac1871",
|
||||
topics: ["0x3333", "0x6666", "0x9999"],
|
||||
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
||||
)
|
||||
assembler: # LOG3 OP
|
||||
title: "Log3"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH2 "0x9999"
|
||||
PUSH2 "0x6666"
|
||||
PUSH2 "0x3333"
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
LOG3
|
||||
memory:
|
||||
"0x1234"
|
||||
logs:
|
||||
(
|
||||
address: "0xc669eaad75042be84daaf9b461b0e868b9ac1871",
|
||||
topics: ["0x3333", "0x6666", "0x9999"],
|
||||
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
||||
)
|
||||
|
||||
assembler: # LOG4 OP
|
||||
title: "Log4"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH2 "0x9999"
|
||||
PUSH2 "0x6666"
|
||||
PUSH2 "0x3333"
|
||||
PUSH2 "0x5555"
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
LOG4
|
||||
memory:
|
||||
"0x1234"
|
||||
logs:
|
||||
(
|
||||
address: "0xc669eaad75042be84daaf9b461b0e868b9ac1871",
|
||||
topics: ["0x5555", "0x3333", "0x6666", "0x9999"],
|
||||
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
||||
)
|
||||
assembler: # LOG4 OP
|
||||
title: "Log4"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH2 "0x9999"
|
||||
PUSH2 "0x6666"
|
||||
PUSH2 "0x3333"
|
||||
PUSH2 "0x5555"
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
LOG4
|
||||
memory:
|
||||
"0x1234"
|
||||
logs:
|
||||
(
|
||||
address: "0xc669eaad75042be84daaf9b461b0e868b9ac1871",
|
||||
topics: ["0x5555", "0x3333", "0x6666", "0x9999"],
|
||||
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
||||
)
|
||||
|
||||
assembler: # STOP OP
|
||||
title: "STOP_1"
|
||||
code:
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x30"
|
||||
PUSH1 "0x10"
|
||||
PUSH1 "0x30"
|
||||
PUSH1 "0x11"
|
||||
PUSH1 "0x23"
|
||||
STOP
|
||||
stack:
|
||||
"0x20"
|
||||
"0x30"
|
||||
"0x10"
|
||||
"0x30"
|
||||
"0x11"
|
||||
"0x23"
|
||||
assembler: # STOP OP
|
||||
title: "STOP_1"
|
||||
code:
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x30"
|
||||
PUSH1 "0x10"
|
||||
PUSH1 "0x30"
|
||||
PUSH1 "0x11"
|
||||
PUSH1 "0x23"
|
||||
STOP
|
||||
stack:
|
||||
"0x20"
|
||||
"0x30"
|
||||
"0x10"
|
||||
"0x30"
|
||||
"0x11"
|
||||
"0x23"
|
||||
|
||||
assembler: # RETURN OP
|
||||
title: "RETURN_1"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
RETURN
|
||||
memory: "0x1234"
|
||||
output: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
||||
assembler: # RETURN OP
|
||||
title: "RETURN_1"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
RETURN
|
||||
memory: "0x1234"
|
||||
output: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
||||
|
||||
assembler: # RETURN OP
|
||||
title: "RETURN_2"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x1F"
|
||||
RETURN
|
||||
memory:
|
||||
"0x1234"
|
||||
"0x00"
|
||||
output: "0x3400000000000000000000000000000000000000000000000000000000000000"
|
||||
assembler: # RETURN OP
|
||||
title: "RETURN_2"
|
||||
code:
|
||||
PUSH2 "0x1234"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x1F"
|
||||
RETURN
|
||||
memory:
|
||||
"0x1234"
|
||||
"0x00"
|
||||
output: "0x3400000000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
assembler: # RETURN OP
|
||||
title: "RETURN_3"
|
||||
code:
|
||||
PUSH32 "0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
RETURN
|
||||
memory: "0xa0b0c0d0e0f0a1b1c1d1e1f1a2b2c2d2e2f2a3b3c3d3e3f3a4b4c4d4e4f4a1b1"
|
||||
output: "0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
|
||||
assembler: # RETURN OP
|
||||
title: "RETURN_3"
|
||||
code:
|
||||
PUSH32 "0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x00"
|
||||
RETURN
|
||||
memory: "0xa0b0c0d0e0f0a1b1c1d1e1f1a2b2c2d2e2f2a3b3c3d3e3f3a4b4c4d4e4f4a1b1"
|
||||
output: "0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
|
||||
|
||||
assembler: # RETURN OP
|
||||
title: "RETURN_4"
|
||||
code:
|
||||
PUSH32 "0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x10"
|
||||
RETURN
|
||||
output: "0xE2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B100000000000000000000000000000000"
|
||||
memory:
|
||||
"0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
|
||||
"0x00"
|
||||
assembler: # RETURN OP
|
||||
title: "RETURN_4"
|
||||
code:
|
||||
PUSH32 "0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
|
||||
PUSH1 "0x00"
|
||||
MSTORE
|
||||
PUSH1 "0x20"
|
||||
PUSH1 "0x10"
|
||||
RETURN
|
||||
output: "0xE2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B100000000000000000000000000000000"
|
||||
memory:
|
||||
"0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
|
||||
"0x00"
|
||||
|
|
|
@ -13,8 +13,9 @@ import
|
|||
|
||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
||||
|
||||
suite "persist block json tests":
|
||||
jsonTest("PersistBlockTests", testFixture)
|
||||
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) =
|
||||
|
|
|
@ -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":
|
||||
jsonTest("PrecompileTests", testFixture)
|
||||
proc precompilesMain*() =
|
||||
suite "Precompiles":
|
||||
jsonTest("PrecompileTests", testFixture)
|
||||
|
|
|
@ -27,77 +27,78 @@ func toBytes(s: string): seq[byte] =
|
|||
func bigEndianToInt*(value: openarray[byte]): UInt256 =
|
||||
result.initFromBytesBE(value)
|
||||
|
||||
suite "stack":
|
||||
test "push only valid":
|
||||
testPush(0'u, 0.u256)
|
||||
testPush(UINT_256_MAX, UINT_256_MAX)
|
||||
testPush("ves".toBytes, "ves".toBytes.bigEndianToInt)
|
||||
proc stackMain*() =
|
||||
suite "stack":
|
||||
test "push only valid":
|
||||
testPush(0'u, 0.u256)
|
||||
testPush(UINT_256_MAX, UINT_256_MAX)
|
||||
testPush("ves".toBytes, "ves".toBytes.bigEndianToInt)
|
||||
|
||||
testFailPush("yzyzyzyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz".toBytes)
|
||||
testFailPush("yzyzyzyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz".toBytes)
|
||||
|
||||
test "push does not allow stack to exceed 1024":
|
||||
var stack = newStack()
|
||||
for z in 0 .. < 1024:
|
||||
stack.push(z.uint)
|
||||
check(stack.len == 1024)
|
||||
expect(FullStack):
|
||||
stack.push(1025)
|
||||
test "push does not allow stack to exceed 1024":
|
||||
var stack = newStack()
|
||||
for z in 0 .. < 1024:
|
||||
stack.push(z.uint)
|
||||
check(stack.len == 1024)
|
||||
expect(FullStack):
|
||||
stack.push(1025)
|
||||
|
||||
test "dup does not allow stack to exceed 1024":
|
||||
var stack = newStack()
|
||||
stack.push(1.u256)
|
||||
for z in 0 ..< 1023:
|
||||
stack.dup(1)
|
||||
check(stack.len == 1024)
|
||||
expect(FullStack):
|
||||
test "dup does not allow stack to exceed 1024":
|
||||
var stack = newStack()
|
||||
stack.push(1.u256)
|
||||
for z in 0 ..< 1023:
|
||||
stack.dup(1)
|
||||
check(stack.len == 1024)
|
||||
expect(FullStack):
|
||||
stack.dup(1)
|
||||
|
||||
test "pop returns latest stack item":
|
||||
var stack = newStack()
|
||||
for element in @[1'u, 2'u, 3'u]:
|
||||
stack.push(element)
|
||||
check(stack.popInt == 3.u256)
|
||||
|
||||
test "swap correct":
|
||||
var stack = newStack()
|
||||
for z in 0 ..< 5:
|
||||
stack.push(z.uint)
|
||||
check(stack.values == @[0.u256, 1.u256, 2.u256, 3.u256, 4.u256])
|
||||
stack.swap(3)
|
||||
check(stack.values == @[0.u256, 4.u256, 2.u256, 3.u256, 1.u256])
|
||||
stack.swap(1)
|
||||
check(stack.values == @[0.u256, 4.u256, 2.u256, 1.u256, 3.u256])
|
||||
|
||||
test "dup correct":
|
||||
var stack = newStack()
|
||||
for z in 0 ..< 5:
|
||||
stack.push(z.uint)
|
||||
check(stack.values == @[0.u256, 1.u256, 2.u256, 3.u256, 4.u256])
|
||||
stack.dup(1)
|
||||
check(stack.values == @[0.u256, 1.u256, 2.u256, 3.u256, 4.u256, 4.u256])
|
||||
stack.dup(5)
|
||||
check(stack.values == @[0.u256, 1.u256, 2.u256, 3.u256, 4.u256, 4.u256, 1.u256])
|
||||
|
||||
test "pop returns latest stack item":
|
||||
var stack = newStack()
|
||||
for element in @[1'u, 2'u, 3'u]:
|
||||
stack.push(element)
|
||||
check(stack.popInt == 3.u256)
|
||||
test "pop raises InsufficientStack appropriately":
|
||||
var stack = newStack()
|
||||
expect(InsufficientStack):
|
||||
discard stack.popInt()
|
||||
|
||||
test "swap correct":
|
||||
var stack = newStack()
|
||||
for z in 0 ..< 5:
|
||||
stack.push(z.uint)
|
||||
check(stack.values == @[0.u256, 1.u256, 2.u256, 3.u256, 4.u256])
|
||||
stack.swap(3)
|
||||
check(stack.values == @[0.u256, 4.u256, 2.u256, 3.u256, 1.u256])
|
||||
stack.swap(1)
|
||||
check(stack.values == @[0.u256, 4.u256, 2.u256, 1.u256, 3.u256])
|
||||
test "swap raises InsufficientStack appropriately":
|
||||
var stack = newStack()
|
||||
expect(InsufficientStack):
|
||||
stack.swap(0)
|
||||
|
||||
test "dup correct":
|
||||
var stack = newStack()
|
||||
for z in 0 ..< 5:
|
||||
stack.push(z.uint)
|
||||
check(stack.values == @[0.u256, 1.u256, 2.u256, 3.u256, 4.u256])
|
||||
stack.dup(1)
|
||||
check(stack.values == @[0.u256, 1.u256, 2.u256, 3.u256, 4.u256, 4.u256])
|
||||
stack.dup(5)
|
||||
check(stack.values == @[0.u256, 1.u256, 2.u256, 3.u256, 4.u256, 4.u256, 1.u256])
|
||||
test "dup raises InsufficientStack appropriately":
|
||||
var stack = newStack()
|
||||
expect(InsufficientStack):
|
||||
stack.dup(0)
|
||||
|
||||
test "pop raises InsufficientStack appropriately":
|
||||
var stack = newStack()
|
||||
expect(InsufficientStack):
|
||||
discard stack.popInt()
|
||||
test "binary operations raises InsufficientStack appropriately":
|
||||
# https://github.com/status-im/nimbus/issues/31
|
||||
# ./tests/fixtures/VMTests/vmArithmeticTest/mulUnderFlow.json
|
||||
|
||||
test "swap raises InsufficientStack appropriately":
|
||||
var stack = newStack()
|
||||
expect(InsufficientStack):
|
||||
stack.swap(0)
|
||||
|
||||
test "dup raises InsufficientStack appropriately":
|
||||
var stack = newStack()
|
||||
expect(InsufficientStack):
|
||||
stack.dup(0)
|
||||
|
||||
test "binary operations raises InsufficientStack appropriately":
|
||||
# https://github.com/status-im/nimbus/issues/31
|
||||
# ./tests/fixtures/VMTests/vmArithmeticTest/mulUnderFlow.json
|
||||
|
||||
var stack = newStack()
|
||||
stack.push(123)
|
||||
expect(InsufficientStack):
|
||||
discard stack.popInt(2)
|
||||
var stack = newStack()
|
||||
stack.push(123)
|
||||
expect(InsufficientStack):
|
||||
discard stack.popInt(2)
|
||||
|
|
|
@ -9,37 +9,38 @@ import unittest, strutils, eth/trie/[hexary, db],
|
|||
../nimbus/db/state_db, stew/byteutils, eth/common,
|
||||
stew/ranges
|
||||
|
||||
suite "Account State DB":
|
||||
var
|
||||
memDB = newMemoryDB()
|
||||
trie = initHexaryTrie(memDB)
|
||||
stateDB = newAccountStateDB(memDB, trie.rootHash, true)
|
||||
address: EthAddress
|
||||
proc stateDBMain*() =
|
||||
suite "Account State DB":
|
||||
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
|
||||
check stateDB.isDeadAccount(address) == true
|
||||
test "accountExists and isDeadAccount":
|
||||
check stateDB.accountExists(address) == false
|
||||
check stateDB.isDeadAccount(address) == true
|
||||
|
||||
var acc = stateDB.getAccount(address)
|
||||
acc.balance = 1000.u256
|
||||
stateDB.setAccount(address, acc)
|
||||
var acc = stateDB.getAccount(address)
|
||||
acc.balance = 1000.u256
|
||||
stateDB.setAccount(address, acc)
|
||||
|
||||
check stateDB.accountExists(address) == true
|
||||
check stateDB.isDeadAccount(address) == false
|
||||
check stateDB.accountExists(address) == true
|
||||
check stateDB.isDeadAccount(address) == false
|
||||
|
||||
acc.balance = 0.u256
|
||||
acc.nonce = 1
|
||||
stateDB.setAccount(address, acc)
|
||||
check stateDB.isDeadAccount(address) == false
|
||||
acc.balance = 0.u256
|
||||
acc.nonce = 1
|
||||
stateDB.setAccount(address, acc)
|
||||
check stateDB.isDeadAccount(address) == false
|
||||
|
||||
var code = hexToSeqByte("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6")
|
||||
stateDB.setCode(address, code.toRange)
|
||||
stateDB.setNonce(address, 0)
|
||||
check stateDB.isDeadAccount(address) == false
|
||||
var code = hexToSeqByte("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6")
|
||||
stateDB.setCode(address, code.toRange)
|
||||
stateDB.setNonce(address, 0)
|
||||
check stateDB.isDeadAccount(address) == false
|
||||
|
||||
code = @[]
|
||||
stateDB.setCode(address, code.toRange)
|
||||
check stateDB.isDeadAccount(address) == true
|
||||
check stateDB.accountExists(address) == true
|
||||
code = @[]
|
||||
stateDB.setCode(address, code.toRange)
|
||||
check stateDB.isDeadAccount(address) == true
|
||||
check stateDB.accountExists(address) == true
|
||||
|
|
|
@ -12,8 +12,9 @@ import
|
|||
|
||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
||||
|
||||
suite "tracer json tests":
|
||||
jsonTest("TracerTests", testFixture)
|
||||
proc tracerJsonMain*() =
|
||||
suite "tracer json tests":
|
||||
jsonTest("TracerTests", testFixture)
|
||||
|
||||
# use tracerTestGen.nim to generate additional test data
|
||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus) =
|
||||
|
|
|
@ -8,8 +8,12 @@ const
|
|||
|
||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
||||
|
||||
suite "Transactions tests":
|
||||
jsonTest("TransactionTests", testFixture)
|
||||
proc transactionJsonMain*() =
|
||||
suite "Transactions tests":
|
||||
jsonTest("TransactionTests", testFixture)
|
||||
|
||||
when isMainModule:
|
||||
transactionJsonMain()
|
||||
|
||||
proc txHash(tx: Transaction): string =
|
||||
toLowerAscii($keccakHash(rlp.encode(tx)))
|
||||
|
|
|
@ -14,8 +14,9 @@ import
|
|||
|
||||
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus)
|
||||
|
||||
suite "vm json tests":
|
||||
jsonTest("VMTests", testFixture)
|
||||
proc vmJsonMain*() =
|
||||
suite "vm json tests":
|
||||
jsonTest("VMTests", testFixture)
|
||||
|
||||
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
||||
var fixture: JsonNode
|
||||
|
|
Loading…
Reference in New Issue