|
2 | 2 |
|
3 | 3 | from typing import List
|
4 | 4 | from string import Template
|
| 5 | +import subprocess |
| 6 | +import os |
5 | 7 |
|
6 | 8 | import pyevmasm as asm
|
7 | 9 |
|
@@ -66,14 +68,33 @@ def generate_header_str(inputs: List[int]) -> str:
|
66 | 68 | def generate_header_binary(inputs: List[int]) -> str:
|
67 | 69 | asm.assemble_hex(generate_header_str(inputs))
|
68 | 70 |
|
| 71 | +def generate_function_binary(filename: str, offset: int) -> str: |
| 72 | + assert offset > 0 |
| 73 | + # being lazy |
| 74 | + pass |
| 75 | + |
69 | 76 | def generate_contract(inputs: List[int], func: str) -> str:
|
70 | 77 | assert len(inputs) < 3
|
71 | 78 | complete_str = generate_header_str(inputs) + func
|
72 | 79 | return asm.assemble_hex(complete_str)
|
73 | 80 |
|
74 | 81 | def execute_in_evm(code: str, expected: str) -> str:
|
75 |
| - pass |
| 82 | + # we could use py-evm to do it so everything will be in python. |
| 83 | + emv_path = "" |
| 84 | + try: |
| 85 | + emv_path = os.environ['EVM_PATH'] |
| 86 | + except KeyError(key): |
| 87 | + print("\"" + key + "\" not defined, using pwd instead") |
76 | 88 |
|
| 89 | + command = [emv_path + "/evm", "--code", code, "run"] |
| 90 | + result = subprocess.run(command, stdout=subprocess.PIPE) |
| 91 | + result.check_returncode() |
| 92 | + return result.stdout |
| 93 | + |
| 94 | +def load_assembly_from_file(filename: str) -> str: |
| 95 | + pass |
77 | 96 |
|
78 |
| -print(generate_contract( |
79 |
| - inputs=["0x12345678", "0x87654321"], func="JUMPDEST\nADD\nSWAP1\nJUMP")) |
| 97 | +contract = generate_contract( |
| 98 | + inputs=["0x12345678", "0x87654321"], func="JUMPDEST\nADD\nSWAP1\nJUMP") |
| 99 | +result = execute_in_evm(contract, "") |
| 100 | +print(result) |
0 commit comments