Example #1
0
def test_has_arrlist_has_expected_behavior_for_parsable_types(type_str):
    # Should not match tuple types
    if type_str.startswith('('):
        assert not has_arrlist(type_str)
        event('No match for tuple type')

    # Should match array types
    elif ARRAY_RE.search(type_str):
        assert has_arrlist(type_str)
        event('Match for array type')

    # Should not match any other types
    else:
        assert not has_arrlist(type_str)
        event('No match for non-array type')
def test_has_arrlist_has_expected_behavior_for_parsable_types(type_str):
    # Should not match tuple types
    if type_str.startswith('('):
        assert not has_arrlist(type_str)
        event('No match for tuple type')

    # Should match array types
    elif ARRAY_RE.search(type_str):
        assert has_arrlist(type_str)
        event('Match for array type')

    # Should not match any other types
    else:
        assert not has_arrlist(type_str)
        event('No match for non-array type')
Example #3
0
def test_predicates_have_expected_behavior_for_malformed_types(malformed_type_str):
    is_int = BaseEquals('int')
    is_int_with_sub = BaseEquals('int', with_sub=True)
    is_int_with_no_sub = BaseEquals('int', with_sub=False)

    # Should not match unparsable types
    assert not is_int(malformed_type_str)
    assert not is_int_with_sub(malformed_type_str)
    assert not is_int_with_no_sub(malformed_type_str)

    assert not has_arrlist(malformed_type_str)
    assert not is_tuple_type(malformed_type_str)
def test_predicates_have_expected_behavior_for_malformed_types(malformed_type_str):
    is_int = BaseEquals('int')
    is_int_with_sub = BaseEquals('int', with_sub=True)
    is_int_with_no_sub = BaseEquals('int', with_sub=False)

    # Should not match unparsable types
    assert not is_int(malformed_type_str)
    assert not is_int_with_sub(malformed_type_str)
    assert not is_int_with_no_sub(malformed_type_str)

    assert not has_arrlist(malformed_type_str)
    assert not is_base_tuple(malformed_type_str)
def encode_single_packed(_type, value):
    import codecs
    from eth_abi import (
        grammar as abi_type_parser,
    )
    from eth_abi.registry import has_arrlist, registry
    abi_type = abi_type_parser.parse(_type)
    if has_arrlist(_type):
        item_encoder = registry.get_encoder(abi_type.item_type.to_type_str())
        if abi_type.arrlist[-1] != 1:
            return DynamicArrayPackedEncoder(item_encoder=item_encoder).encode(value)
        else:
            raise NotImplementedError(
                "Fixed arrays are not implemented in this packed encoder prototype")
    elif abi_type.base == "string":
        return codecs.encode(value, 'utf8')
    elif abi_type.base == "bytes":
        return value