def test_can_register_simple_callables(registry: ABIRegistry): encode_bool = lambda x: x decode_bool = lambda x: x registry.register('bool', encode_bool, decode_bool) assert registry.get_encoder('bool') is encode_bool assert registry.get_decoder('bool') is decode_bool
def test_has_encoder_raises(registry: ABIRegistry): registry.register( BaseEquals('address', with_sub=False), encoding.AddressEncoder, decoding.AddressDecoder, label='other_address', ) with pytest.raises(exceptions.MultipleEntriesFound): assert registry.has_encoder('address')
def test_can_register_simple_callables(registry: ABIRegistry): def encode_bool(x): return x decode_bool = encode_bool registry.register('bool', encode_bool, decode_bool) assert registry.get_encoder('bool') is encode_bool assert registry.get_decoder('bool') is decode_bool
def test_can_register_and_unregister_string_lookups(registry: ABIRegistry): registry.register( 'bool', encoding.BooleanEncoder, decoding.BooleanDecoder, ) assert isinstance(registry.get_encoder('bool'), encoding.BooleanEncoder) assert isinstance(registry.get_decoder('bool'), decoding.BooleanDecoder) registry.unregister('bool') with pytest.raises(exceptions.NoEntriesFound): registry.get_encoder('bool') with pytest.raises(exceptions.NoEntriesFound): registry.get_decoder('bool')
def registry(): reg = ABIRegistry() reg.register( has_arrlist, encoding.BaseArrayEncoder, decoding.BaseArrayDecoder, label='has_arrlist', ) reg.register( BaseEquals('address'), encoding.AddressEncoder, decoding.AddressDecoder, label='address', ) return reg
def test_cache_resets_after_register_and_register_works(registry: ABIRegistry): # Populate cache registry.get_encoder('address') registry.get_decoder('address') # Perform cache resetting action registry.register( BaseEquals('address', with_sub=False), encoding.AddressEncoder, decoding.AddressDecoder, label='address without sub', ) # Confirm cache reset with pytest.raises(exceptions.MultipleEntriesFound): registry.get_encoder('address') with pytest.raises(exceptions.MultipleEntriesFound): registry.get_decoder('address')
def test_can_register_and_unregister_string_lookups(registry: ABIRegistry): registry.register( 'bool', encoding.BooleanEncoder, decoding.BooleanDecoder, ) assert isinstance(registry.get_encoder('bool'), encoding.BooleanEncoder) assert isinstance(registry.get_decoder('bool'), decoding.BooleanDecoder) registry.unregister('bool') with pytest.raises(ValueError, match=r'No matching entries .* encoder registry'): registry.get_encoder('bool') with pytest.raises(ValueError, match=r'No matching entries .* decoder registry'): registry.get_decoder('bool')
def test_cache_resets_after_register_and_register_works(registry: ABIRegistry): # Populate cache registry.get_encoder('address') registry.get_decoder('address') # Perform cache resetting action registry.register( BaseEquals('address', with_sub=False), encoding.AddressEncoder, decoding.AddressDecoder, label='address without sub', ) # Confirm cache reset pattern = r'Multiple matching entries .* encoder registry' with pytest.raises(ValueError, match=pattern): registry.get_encoder('address') pattern = r'Multiple matching entries .* decoder registry' with pytest.raises(ValueError, match=pattern): registry.get_decoder('address')
def test_registry_should_reject_unknown_types(registry: ABIRegistry): with pytest.raises(TypeError): registry.register(True, None, None) with pytest.raises(TypeError): registry.unregister(True)