예제 #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'))
예제 #2
0
def test_bool():
    f = abi.Function(f4)
    assert f.selector.hex() == '12a7b914'

    expected = {
        "0": True
    }

    assert expected == f.decode(bytes.fromhex('0000000000000000000000000000000000000000000000000000000000000001'))
예제 #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'))
예제 #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'))
예제 #5
0
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
예제 #6
0
def get_vtho_balance():
    return abi.Function(abi.FUNCTION(FUNC_CHECK_VTHO_BALANCE))
예제 #7
0
def find_master():
    return abi.Function(abi.FUNCTION(FUNC_FIND_MASTER))
예제 #8
0
def move_vtho():
    return abi.Function(abi.FUNCTION(FUNC_MOVE_VTHO))