def cast_return_data(self, outputs): if len(self.output_types) != 1: try: return decode_multi(self.output_types, outputs) except AssertionError: raise EmptyDataError("call to {0} unexpectedly returned no data".format(self)) output_type = self.output_types[0] try: return decode_single(output_type, outputs) except AssertionError: raise EmptyDataError("call to {0} unexpectedly returned no data".format(self))
def get_log_data(self, log_entry, indexed=False): values = self.cast_return_data(log_entry['data'], raw=True) event_data = { output['name']: value for output, value in zip(self.outputs, values) } if indexed: for idx, _input in enumerate(self.inputs): if _input['indexed']: event_data[_input['name']] = decode_single( _input['type'], log_entry['topics'][idx + 1], ) return event_data
def cast_return_data(self, outputs): if len(self.output_types) != 1: try: return decode_multi(self.output_types, outputs) except AssertionError: raise EmptyDataError( "call to {0} unexpectedly returned no data".format(self)) output_type = self.output_types[0] try: return decode_single(output_type, outputs) except AssertionError: raise EmptyDataError( "call to {0} unexpectedly returned no data".format(self))
def test_decode_bool(input, expected): output = decode_single('bool', input) assert output == expected
def test_decode_uint256(input, expected): output = decode_single('uint256', input) assert output == expected
def test_raises_on_empty_data(_type): with pytest.raises(AssertionError): decode_single(_type, '0x')
def test_decode_address(input, expected): output = decode_single('address', input) assert output == expected
def test_decode_bytes(): input = '0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000024b0f07e44616263646162636461626364616263646162636461626364616263646162636400000000000000000000000000000000000000000000000000000000' output = decode_single('bytes', input) assert output == '\xb0\xf0~Dabcdabcdabcdabcdabcdabcdabcdabcd'
def cast_return_data(self, outputs): if len(self.output_types) != 1: return decode_multi(self.output_types, outputs) output_type = self.output_types[0] return decode_single(output_type, outputs)
def test_decode_bytes32(input, expected): output = decode_single('bytes32', input) assert output == expected