예제 #1
0
파일: test_abi.py 프로젝트: siraben/vyper
def test_struct_abi():
    code = """
struct MyStruct:
    a: address
    b: uint256

@public
@constant
def foo(s: MyStruct) -> MyStruct:
    return s
    """

    data = CompilerData(code)
    abi = build_abi_output(data)
    func_abi = abi[0]

    assert func_abi["name"] == "foo"
    expected = {
        'type':
        'tuple',
        'name':
        '',
        'components': [{
            'type': 'address',
            'name': 'a'
        }, {
            'type': 'uint256',
            'name': 'b'
        }]
    }

    assert func_abi["outputs"][0] == expected

    expected['name'] = "s"
    assert func_abi["inputs"][0] == expected
예제 #2
0
def test_struct_abi():
    code = """
struct MyStruct:
    a: address
    b: uint256

@external
@view
def foo(s: MyStruct) -> MyStruct:
    return s
    """

    data = CompilerData(code)
    abi = build_abi_output(data)
    func_abi = abi[0]

    assert func_abi["name"] == "foo"

    expected_output = [
        {
            "type": "tuple",
            "name": "",
            "components": [{"type": "address", "name": "a"}, {"type": "uint256", "name": "b"}],
        }
    ]

    assert func_abi["outputs"] == expected_output

    expected_input = {
        "type": "tuple",
        "name": "s",
        "components": [{"type": "address", "name": "a"}, {"type": "uint256", "name": "b"}],
    }

    assert func_abi["inputs"][0] == expected_input
예제 #3
0
def test_only_init_function(source_code):
    empty_sig = [
        {"outputs": [], "inputs": [], "stateMutability": "nonpayable", "type": "constructor"}
    ]

    data = CompilerData(source_code)
    assert build_abi_output(data) == empty_sig
예제 #4
0
def test_default_abi():
    default_code = """
@payable
@external
def __default__():
    pass
    """

    data = CompilerData(default_code)
    assert build_abi_output(data) == [{"stateMutability": "payable", "type": "fallback"}]
예제 #5
0
파일: test_abi.py 프로젝트: siraben/vyper
def test_only_init_function(source_code):
    empty_sig = [{
        'outputs': [],
        'inputs': [],
        'constant': False,
        'payable': False,
        'type': 'constructor'
    }]

    data = CompilerData(source_code)
    assert build_abi_output(data) == empty_sig
예제 #6
0
파일: test_abi.py 프로젝트: siraben/vyper
def test_default_abi():
    default_code = """
@payable
@public
def __default__():
    pass
    """

    data = CompilerData(default_code)
    assert build_abi_output(data) == [{
        'constant': False,
        'payable': True,
        'type': 'fallback'
    }]