예제 #1
0
def test_contract_add_function_signature():
    add = Function(
        "add",
        inputs=[{'type': 'int256', 'name': 'a'}, {'type': 'int256', 'name': 'b'}],
        outputs=[{'type': 'int256', 'name': 'result'}],
    )
    assert add.abi_signature == 2784215611
    assert add.encoded_abi_signature == '\xa5\xf3\xc2;'
    assert add.get_call_data((3, 4)) == 'a5f3c23b00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004'
예제 #2
0
def test_contract_multiply7_function_signature():
    multiply7 = Function(
        'multiply7',
        inputs=[{'type': 'int256', 'name': 'a'}],
        outputs=[{'type': 'int256', 'name': 'result'}],
    )
    assert multiply7.abi_signature == 3707058097
    assert multiply7.encoded_abi_signature == '\xdc\xf57\xb1'
    assert multiply7.get_call_data((3,)) == 'dcf537b10000000000000000000000000000000000000000000000000000000000000003'
예제 #3
0
def test_contract_return13_function_signature():
    return13 = Function("return13",
                        inputs=[],
                        outputs=[{
                            'type': 'int256',
                            'name': 'result'
                        }])
    assert return13.abi_signature == 371289913
    assert return13.encoded_abi_signature == '\x16!o9'
    assert return13.get_call_data([]) == '16216f39'
예제 #4
0
def test_abi_args_signature_with_0x_prefixed_address():
    func = Function("multiply", [{
        'type': 'address',
        'name': 'to'
    }, {
        'type': 'uint256',
        'name': 'deposit'
    }])
    args_signature = func.abi_args_signature(
        ('0xd3cda913deb6f67967b99d67acdfa1712c293601', 12345))
    assert args_signature == '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd3\xcd\xa9\x13\xde\xb6\xf6yg\xb9\x9dg\xac\xdf\xa1q,)6\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0009'
예제 #5
0
def test_contract_multiply7_function_signature():
    multiply7 = Function(
        'multiply7',
        inputs=[{
            'type': 'int256',
            'name': 'a'
        }],
        outputs=[{
            'type': 'int256',
            'name': 'result'
        }],
    )
    assert multiply7.abi_signature == 3707058097
    assert multiply7.encoded_abi_signature == '\xdc\xf57\xb1'
    assert multiply7.get_call_data(
        (3, )
    ) == 'dcf537b10000000000000000000000000000000000000000000000000000000000000003'
예제 #6
0
def test_signature_multiple_args():
    func = Function("multiply", [{
        'type': 'int256',
        'name': 'a'
    }, {
        'type': 'int256',
        'name': 'b'
    }])
    assert str(func) == "multiply(int256 a, int256 b)"
예제 #7
0
def test_abi_signature_multiple_args():
    func = Function("multiply", [{
        'type': 'int256',
        'name': 'a'
    }, {
        'type': 'int256',
        'name': 'b'
    }])
    assert hex(func.abi_signature) == "0x3c4308a8"
예제 #8
0
def test_contract_add_function_signature():
    add = Function(
        "add",
        inputs=[{
            'type': 'int256',
            'name': 'a'
        }, {
            'type': 'int256',
            'name': 'b'
        }],
        outputs=[{
            'type': 'int256',
            'name': 'result'
        }],
    )
    assert add.abi_signature == 2784215611
    assert add.encoded_abi_signature == '\xa5\xf3\xc2;'
    assert add.get_call_data(
        (3, 4)
    ) == 'a5f3c23b00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004'
예제 #9
0
def test_contract_return13_function_signature():
    return13 = Function("return13", inputs=[], outputs=[{'type': 'int256', 'name': 'result'}])
    assert return13.abi_signature == 371289913
    assert return13.encoded_abi_signature == '\x16!o9'
    assert return13.get_call_data([]) == '16216f39'
예제 #10
0
def test_abi_args_signature_with_0x_prefixed_address():
    func = Function("multiply", [{'type': 'address', 'name': 'to'}, {'type': 'uint256', 'name': 'deposit'}])
    args_signature = func.abi_args_signature(('0xd3cda913deb6f67967b99d67acdfa1712c293601', 12345))
    assert args_signature == '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd3\xcd\xa9\x13\xde\xb6\xf6yg\xb9\x9dg\xac\xdf\xa1q,)6\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0009'
예제 #11
0
int8_b = {'type': 'int8', 'name': 'b'}
int8_c = {'type': 'int8', 'name': 'c'}
uint8_a = {'type': 'uint8', 'name': 'a'}
uint8_b = {'type': 'uint8', 'name': 'b'}
int256_a = {'type': 'int256', 'name': 'a'}
int256_b = {'type': 'int256', 'name': 'b'}
uint256_a = {'type': 'uint256', 'name': 'a'}
uint256_b = {'type': 'uint256', 'name': 'b'}
bytes8_x = {'type': 'bytes8', 'name': 'x'}
bytes8_y = {'type': 'bytes8', 'name': 'y'}
bytes32_x = {'type': 'bytes32', 'name': 'x'}
bytes32_y = {'type': 'bytes32', 'name': 'y'}
address_m = {'type': 'address', 'name': 'm'}
address_n = {'type': 'address', 'name': 'n'}

f_1a = Function('doit', [int8_a, uint8_a, int256_a, uint256_a])
f_1b = Function('doit', [int8_a, uint8_a, int8_b, int8_c])

f_group_1 = FunctionGroup([f_1a, f_1b])


def test_matching_with_similar_integers():
    assert f_group_1.get_function_for_call_signature((1, 2, 500, 500)) == f_1a
    with pytest.raises(TypeError):
        assert f_group_1.get_function_for_call_signature((1, 2, 100, 100))
    assert f_group_1.get_function_for_call_signature((1, 2, 100, -100)) == f_1b


f_2a = Function('doit', [uint256_a, bytes32_x, address_m])
f_2b = Function('doit', [uint256_a, address_n, bytes8_x])
예제 #12
0
def test_abi_signature_no_args():
    func = Function("doit", [])
    assert hex(func.abi_function_signature) == "0x4d536fe3"
예제 #13
0
def test_signature_single_arg():
    func = Function("register", [{'type': 'bytes32', 'name': 'name'}])
    assert str(func) == "register(bytes32 name)"
예제 #14
0
def test_signature_no_args():
    func = Function("doit", [])
    assert str(func) == "doit()"
예제 #15
0
def test_abi_signature_single_arg():
    func = Function("register", [{'type': 'bytes32', 'name': 'name'}])
    assert hex(func.abi_function_signature) == "0xe1fa8e84"