From ea23882fee74271d2db79b6dd923aa0edb51d3c7 Mon Sep 17 00:00:00 2001 From: Alan Li Date: Sun, 17 Nov 2019 09:58:20 -0500 Subject: [PATCH] Issue #27: Using envvar to locate go-ethereum's evm command path --- tools/evm-test/evm_test.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) mode change 100644 => 100755 tools/evm-test/evm_test.py diff --git a/tools/evm-test/evm_test.py b/tools/evm-test/evm_test.py old mode 100644 new mode 100755 index c9bedb3f64f2a..b0457d7c71140 --- a/tools/evm-test/evm_test.py +++ b/tools/evm-test/evm_test.py @@ -2,6 +2,8 @@ from typing import List from string import Template +import subprocess +import os import pyevmasm as asm @@ -66,14 +68,33 @@ def generate_header_str(inputs: List[int]) -> str: def generate_header_binary(inputs: List[int]) -> str: asm.assemble_hex(generate_header_str(inputs)) +def generate_function_binary(filename: str, offset: int) -> str: + assert offset > 0 + # being lazy + pass + def generate_contract(inputs: List[int], func: str) -> str: assert len(inputs) < 3 complete_str = generate_header_str(inputs) + func return asm.assemble_hex(complete_str) def execute_in_evm(code: str, expected: str) -> str: - pass + # we could use py-evm to do it so everything will be in python. + emv_path = "" + try: + emv_path = os.environ['EVM_PATH'] + except KeyError(key): + print("\"" + key + "\" not defined, using pwd instead") + command = [emv_path + "/evm", "--code", code, "run"] + result = subprocess.run(command, stdout=subprocess.PIPE) + result.check_returncode() + return result.stdout + +def load_assembly_from_file(filename: str) -> str: + pass -print(generate_contract( - inputs=["0x12345678", "0x87654321"], func="JUMPDEST\nADD\nSWAP1\nJUMP")) +contract = generate_contract( + inputs=["0x12345678", "0x87654321"], func="JUMPDEST\nADD\nSWAP1\nJUMP") +result = execute_in_evm(contract, "") +print(result)