def test_bad_abi(): with pytest.raises(InvalidABI): format_output({'outputs': []}, []) with pytest.raises(InvalidABI): format_output({'name': "bad"}, []) with pytest.raises(InvalidABI): format_output([], [])
def decode_abi(self, hexstr): '''Decodes hexstring data returned by this method. Args: hexstr: Hexstring of returned call data Returns: Decoded values.''' result = eth_abi.decode_abi([i['type'] for i in self.abi['outputs']], HexBytes(hexstr)) result = format_output(self.abi, result) if len(result) == 1: return result[0] return ReturnValue(result, self.abi)
def decode_abi(self, hexstr): '''Decodes hexstring data returned by this method. Args: hexstr: Hexstring of returned call data Returns: Decoded values.''' types = [i[1] for i in _params(self.abi['outputs'])] result = eth_abi.decode_abi(types, HexBytes(hexstr)) result = format_output(self.abi, result) if len(result) == 1: result = result[0] return result
def test_non_sequence(): with pytest.raises(TypeError): format_output(abi, ["123", (1, ), ([1, 1], [2, 2]), b"\xff"])
def test_wrong_length_nested_array(): with pytest.raises(ValueError): format_output(abi, [(1, 2, 3), (2, ), ([2, 2, 2], [2, 2, 2]), b"\xff"])
def test_wrong_length_initial(): with pytest.raises(TypeError): format_output(abi, [(1, 2, 3), (1, ), ([1, 1], [2, 2])]) with pytest.raises(TypeError): format_output(abi, [(1, 2, 3), (1, ), ([1, 1], [2, 2]), b"\xff", b"\xff"])
def test_success(): assert format_output(abi, [(1, 2, 3), (1, ), ([1, 1], [2, 2]), b"\xff"])
def test_empty(): with pytest.raises(TypeError): format_output({'outputs': [], 'name': "empty"}, [1])
def test_empty(): with pytest.raises(TypeError): format_output({"outputs": [], "name": "empty"}, [1])