Example #1
0
def test_string():
    f = abi.Function(f3)
    assert f.selector.hex() == 'b8c9e4ed'

    expected = {
        "0": "Hello World!"
    }
    assert expected == f.decode(bytes.fromhex('0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000c48656c6c6f20576f726c64210000000000000000000000000000000000000000'))
Example #2
0
def test_bool():
    f = abi.Function(f4)
    assert f.selector.hex() == '12a7b914'

    expected = {
        "0": True
    }

    assert expected == f.decode(bytes.fromhex('0000000000000000000000000000000000000000000000000000000000000001'))
Example #3
0
def test_big_number():
    f = abi.Function(f5)
    assert f.selector.hex() == 'ff0d6c7d'
    expected = {
        "0": 123456,
        "1": -123456,
        "a": 123456,
        "b": -123456
    }

    assert expected == f.decode(bytes.fromhex('000000000000000000000000000000000000000000000000000000000001e240fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1dc0'))
Example #4
0
def test_function():
    f = abi.Function(f1)
    assert f.selector.hex() == '27fcbb2f'

    assert f.encode([1, 'foo'], to_hex=True) == '0x27fcbb2f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003666f6f0000000000000000000000000000000000000000000000000000000000'

    expected = {
        "0": '0xabc0000000000000000000000000000000000001',
        "1": bytes.fromhex('666f6f'),
        "r1": '0xabc0000000000000000000000000000000000001',
        "r2": bytes.fromhex('666f6f')
    }
    assert expected == f.decode(bytes.fromhex('000000000000000000000000abc000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003666f6f0000000000000000000000000000000000000000000000000000000000'))
def call_function(network:str, chainTag: str, abi_dict: dict, func_params: list, priv: str, to: str, value: int, gas: int) -> str:
    ''' Call a smart contract function on-chain '''
    f1 = abi.FUNCTION(abi_dict)
    print(f'Call contract: {to}')
    print(f'function: {f1["name"]}')
    print(f'params: {func_params}')
    f = abi.Function(f1)
    data = f.encode(func_params, to_hex=True)

    raw = build_tx(priv, network, chainTag, to, value, data, gas, None)
    tx_id = post_tx(network, raw)
    print(f'tx: {tx_id}')

    receipt = wait_for_receipt(network, tx_id)

    if is_reverted(receipt):
        raise Exception('Call reverted')
    
    return tx_id
def get_vtho_balance():
    return abi.Function(abi.FUNCTION(FUNC_CHECK_VTHO_BALANCE))
def find_master():
    return abi.Function(abi.FUNCTION(FUNC_FIND_MASTER))
def move_vtho():
    return abi.Function(abi.FUNCTION(FUNC_MOVE_VTHO))