Exemplo n.º 1
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)
Exemplo n.º 2
0
Arquivo: abi.py Projeto: andelf/tronpy
def do_patching(registry):
    registry.unregister("address")

    registry.register(
        BaseEquals("address"),
        TronAddressEncoder,
        TronAddressDecoder,
        label="address",
    )

    registry.register(
        BaseEquals('trcToken'),
        eth_abi.encoding.UnsignedIntegerEncoder,
        eth_abi.decoding.UnsignedIntegerDecoder,
        label='trcToken',
    )
Exemplo n.º 3
0
def test_base_equals_has_expected_behavior_for_parsable_types(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 tuple types
    if type_str.startswith('('):
        assert not is_int(type_str)
        assert not is_int_with_sub(type_str)
        assert not is_int_with_no_sub(type_str)
        event('No match for tuple type')

    # Should not match array types
    elif ARRAY_RE.search(type_str):
        assert not is_int(type_str)
        assert not is_int_with_sub(type_str)
        assert not is_int_with_no_sub(type_str)
        event('No match for array type')

    # Should match types with int base
    elif type_str.startswith('int'):
        assert is_int(type_str)
        event('Match for base')

        if type_str == 'int':
            assert is_int_with_no_sub(type_str)
            assert not is_int_with_sub(type_str)
            event('Match for base with no sub')
        else:
            assert not is_int_with_no_sub(type_str)
            assert is_int_with_sub(type_str)
            event('Match for base with sub')

    # Should not match any other types
    else:
        assert not is_int(type_str)
        assert not is_int_with_sub(type_str)
        assert not is_int_with_no_sub(type_str)
        event('No match for other base')
Exemplo n.º 4
0
        return st.lists(item_strategy, min_size=dim_size, max_size=dim_size)


def get_tuple_strategy(abi_type: ABIType, registry: StrategyRegistry) -> st.SearchStrategy:
    component_strategies = [
        registry.get_strategy(comp_abi_type.to_type_str())
        for comp_abi_type in abi_type.components
    ]

    return st.tuples(*component_strategies)


strategy_registry = StrategyRegistry()

strategy_registry.register_strategy(
    BaseEquals('uint'),
    get_uint_strategy,
    label='uint',
)
strategy_registry.register_strategy(
    BaseEquals('int'),
    get_int_strategy,
    label='int',
)
strategy_registry.register_strategy(
    BaseEquals('address', with_sub=False),
    address_strategy,
    label='address',
)
strategy_registry.register_strategy(
    BaseEquals('bool', with_sub=False),