wjmelements / evm

Fast EVM assembler in C
The Unlicense
61 stars 6 forks source link

Feature: mock interpreter for testing #18

Closed wjmelements closed 11 months ago

wjmelements commented 1 year ago

Usage

expected.json

This configuration file describes the contracts being tested, the external calls we expect and how we should mock their response, and most fields are optional.

[
    {
        "account": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
        "construct": "exec.evm",
        "tests": [
            {
                "op": "CALL",
                "profile": "balanceOf",
                "gas": 31000,
                "output": "0x00000000000000000000000000000000000000000000000070a08231000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000"
            }
        ]
    },
    {
        "construct": "codecopy.evm",
        "tests": [
            {
                "op": "STATICCALL",
                "input": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
                "output": "0x6370a08231595273a0b86991c6218b36c1d19d4a2e9eb0ce3606eb485952602059596000600073a0b86991c6218b36c1d19d4a2e9eb0ce3606eb485af1596000f3"
            }
        ]
    },
    {
        "account": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
        "mock": [
            {
                "op": "STATICCALL",
                "from": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
                "input": "0x70a08231000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
                "output": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "gas": 8000
            }
        ]
    }
]

Invoke

evm -t expected.json

Unless specified by the configuration, the output should be empty in the case that the tests behave as expected.

Output should include gas used selected by the configuration, probably something like

balanceOf 29512
wjmelements commented 1 year ago

I plan to bring in the gmp dependency to provide the biginteger type.

wjmelements commented 12 months ago

I have begun work on the interpreter branch

wjmelements commented 12 months ago

I plan to bring in the gmp dependency to provide the biginteger type.

instead I am using uint256_t.c from https://github.com/LedgerHQ/app-zilliqa/tree/develop/src