Add opcode tests (#4)
This commit is contained in:
parent
078f7abf22
commit
284a026e51
|
@ -8,7 +8,7 @@ license = "Apache License 2.0"
|
|||
skipDirs = @["tests"]
|
||||
|
||||
requires "nim >= 0.18.1",
|
||||
"https://github.com/status-im/nim-keccak-tiny.git >= 0.1.0",
|
||||
"https://github.com/status-im/nim-keccak-tiny.git >= 0.2.0",
|
||||
"https://github.com/alehander42/nim-rlp#fix-ordinal", #TODO switching to the Status repo throws: "Error: undeclared identifier: 'Range'"
|
||||
"https://github.com/status-im/nim-ttmath#master"
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import
|
||||
../constants, ../types, ../errors, ../computation, ../vm_state, .. / db / [db_chain, state_db], .. / vm / [stack, gas_meter, message], strformat, ttmath, utils / header
|
||||
../constants, ../types, ../errors, ../computation, ../vm_state,
|
||||
../utils/header,
|
||||
../db/[db_chain, state_db], ../vm/[stack, gas_meter, message],
|
||||
strformat, ttmath
|
||||
|
||||
{.this: computation.}
|
||||
{.experimental.}
|
||||
|
@ -23,7 +26,7 @@ proc sstore*(computation) =
|
|||
let gasCost = if isCurrentlyEmpty and not isGoingToBeEmpty: GAS_SSET else: GAS_SRESET
|
||||
|
||||
computation.gasMeter.consumeGas(gasCost, &"SSTORE: {computation.msg.storageAddress}[slot] -> {value} ({currentValue})")
|
||||
|
||||
|
||||
if gasRefund > 0: computation.gasMeter.refundGas(gasRefund)
|
||||
|
||||
computation.vmState.db(readOnly=false):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import
|
||||
../logging, ../constants, ../errors, ../transaction, ../types, ../computation, "../block", ../vm_state, ../vm_state_transactions, ../db/db_chain, ../utils/header
|
||||
../logging, ../constants, ../errors, ../transaction, ../types, ../computation, ../block_obj, ../vm_state, ../vm_state_transactions, ../db/db_chain, ../utils/header
|
||||
|
||||
type
|
||||
VM* = ref object of RootObj
|
||||
|
@ -7,7 +7,7 @@ type
|
|||
# such as the Frontier or Homestead network. Defining an Chain defining
|
||||
# individual VM classes for each fork of the protocol rules within that
|
||||
# network
|
||||
|
||||
|
||||
chainDB*: BaseChainDB
|
||||
isStateless*: bool
|
||||
state*: BaseVMState
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import
|
||||
logging, constants, errors, transaction, "block", utils/header
|
||||
../../../logging, ../../../constants, ../../../errors, ../../../transaction,
|
||||
../../../block_obj,
|
||||
../../../utils/header
|
||||
|
||||
type
|
||||
FrontierBlock* = object of Block
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import
|
||||
strformat,
|
||||
constants, errors, ttmath, vm_state, transaction, utils/header
|
||||
strformat, ttmath,
|
||||
../../../constants, ../../../errors, ../../../vm_state, ../../../transaction, ../../../utils/header
|
||||
|
||||
proc validateFrontierTransaction*(vmState: BaseVmState, transaction: BaseTransaction) =
|
||||
let gasCost = transaction.gas * transaction.gasPrice
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import
|
||||
logging, constants, errors, vm_state, utils/header, db/db_chain
|
||||
../../../logging, ../../../constants, ../../../errors, ../../../vm_state,
|
||||
../../../utils/header, ../../../db/db_chain
|
||||
|
||||
type
|
||||
FrontierVMState* = ref object of BaseVMState
|
||||
# receipts*:
|
||||
# receipts*:
|
||||
# computationClass*: Any
|
||||
# accessLogs*: AccessLogs
|
||||
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import
|
||||
logging, constants, errors, ttmath, "block", vm / [base, stack], db / db_chain, utils / header,
|
||||
frontier_block, frontier_vm_state, frontier_validation
|
||||
../../../logging, ../../../constants, ../../../errors,
|
||||
ttmath,
|
||||
../../../block_obj,
|
||||
../../../vm/[base, stack], ../../../db/db_chain, ../../../utils/header,
|
||||
./frontier_block, ./frontier_vm_state, ./frontier_validation
|
||||
|
||||
|
||||
type
|
||||
type
|
||||
FrontierVM* = ref object of VM
|
||||
|
||||
method name*(vm: FrontierVM): string =
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import
|
||||
strformat, tables,
|
||||
logging, constants, errors, computation, transaction, types, vm_state, "block", db / db_chain, utils / [state, header]
|
||||
logging, constants, errors, computation, transaction, types, vm_state, block_obj, db / db_chain, utils / [state, header]
|
||||
|
||||
method executeTransaction(vmState: var BaseVMState, transaction: BaseTransaction): (BaseComputation, Header) =
|
||||
# Execute the transaction in the vm
|
||||
|
@ -45,7 +45,7 @@ method applyTransaction*(
|
|||
# transaction: the transaction need to be applied
|
||||
# b: the block which the transaction applies on
|
||||
# isStateless: if isStateless, call vmState.addTransaction to set block
|
||||
|
||||
|
||||
if isStateless:
|
||||
var ourBlock = b # deepcopy
|
||||
vmState.blockHeader = b.header
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import ./test_code_stream,
|
||||
./test_gas_meter,
|
||||
./test_memory,
|
||||
./test_stack
|
||||
./test_stack,
|
||||
./test_opcode
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import
|
||||
os, macros, json, strformat, strutils, ttmath, utils / [hexadecimal, address, padding], chain, vm_state, constants, db / [db_chain, state_db], vm / forks / frontier / vm, parseutils, ospaths, tables
|
||||
os, macros, json, strformat, strutils, parseutils, ospaths, tables,
|
||||
ttmath,
|
||||
../src/utils/[hexadecimal, address, padding],
|
||||
../src/[chain, vm_state, constants],
|
||||
../src/db/[db_chain, state_db], ../src/vm/forks/frontier/vm
|
||||
|
||||
type
|
||||
Status* {.pure.} = enum OK, Fail, Skip
|
||||
|
||||
proc validTest*(folder: string, name: string): bool =
|
||||
# tests we want to skip or which segfault will be skipped here
|
||||
# TODO fix
|
||||
# TODO fix
|
||||
result = "calldatacopy" notin name and
|
||||
"balanceAddressInputTooBigRightMyAddress." notin name and
|
||||
"callstatelessToReturn1" notin name and
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
import
|
||||
unittest, test_helpers,
|
||||
constants, types, errors, logging, ttmath,
|
||||
tables, parseutils, chain, vm_state, computation, opcode, opcode_table, utils / [header, padding], vm / [gas_meter, message, code_stream, stack], vm / forks / frontier / vm, db / [db_chain, state_db], db / backends / memory_backend
|
||||
import
|
||||
unittest, ttmath, tables, parseutils,
|
||||
../src/[constants, types, errors, logging],
|
||||
../src/[chain, vm_state, computation, opcode, opcode_table],
|
||||
../src/[utils/header, utils/padding],
|
||||
../src/vm/[gas_meter, message, code_stream, stack],
|
||||
../src/vm/forks/frontier/vm,
|
||||
../src/db/[db_chain, state_db, backends/memory_backend],
|
||||
test_helpers
|
||||
|
||||
|
||||
proc testCode(code: string, gas: UInt256): BaseComputation =
|
||||
var vm = newFrontierVM(Header(), newBaseChainDB(newMemoryDB()))
|
||||
|
@ -11,7 +17,7 @@ proc testCode(code: string, gas: UInt256): BaseComputation =
|
|||
# blockNumber: fixture{"env"}{"currentNumber"}.getHexadecimalInt.u256,
|
||||
# gasLimit: fixture{"env"}{"currentGasLimit"}.getHexadecimalInt.u256,
|
||||
# timestamp: fixture{"env"}{"currentTimestamp"}.getHexadecimalInt)
|
||||
|
||||
|
||||
let message = newMessage(
|
||||
to="", #fixture{"exec"}{"address"}.getStr,
|
||||
sender="", #fixture{"exec"}{"caller"}.getStr,
|
||||
|
@ -57,4 +63,4 @@ suite "opcodes":
|
|||
|
||||
# assert_eq!(gas_left, U256::from(79_988));
|
||||
# assert_store(&ext, 0, "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe");
|
||||
# }
|
||||
# }
|
||||
|
|
Loading…
Reference in New Issue