def test_encode_abi(self, multiple_of_eight): type = "uint{}".format(multiple_of_eight) assert tohex(encode_abi([type], [0])) == \ b'0000000000000000000000000000000000000000000000000000000000000000' assert tohex(encode_abi([type], [1])) == \ b'0000000000000000000000000000000000000000000000000000000000000001' assert tohex(encode_abi([type], [42])) == \ b'000000000000000000000000000000000000000000000000000000000000002a'
def test_encode_abi(self, one_to_thirtytwo): t = "bytes{}".format(one_to_thirtytwo) assert tohex(encode_abi([t], [b'\x00'])) == \ b'0000000000000000000000000000000000000000000000000000000000000000' assert tohex(encode_abi([t], [b'\x01'])) == \ b'0100000000000000000000000000000000000000000000000000000000000000' assert tohex(encode_abi([t], [b'\xff'])) == \ b'ff00000000000000000000000000000000000000000000000000000000000000' assert tohex(encode_abi([t], [b'A'])) == \ b'4100000000000000000000000000000000000000000000000000000000000000'
def test_dynamic_2_args(self): assert tohex(encode_abi( ["uint32[]"], [[6, 69]])) == (b'00000000000000000000000000000000' b'00000000000000000000000000000020' b'00000000000000000000000000000000' b'00000000000000000000000000000002' b'00000000000000000000000000000000' b'00000000000000000000000000000006' b'00000000000000000000000000000000' b'00000000000000000000000000000045')
def test_enc_bytes_encode_abi(self): res = encode_abi( ["string"], ['Hello World How Are you? ' '123456789012345678901234567890']) assert tohex(res) == (b"00000000000000000000000000000000" b"00000000000000000000000000000020" b"00000000000000000000000000000000" b"00000000000000000000000000000037" b"48656c6c6f20576f726c6420486f7720" b"41726520796f753f2031323334353637" b"38393031323334353637383930313233" b"34353637383930000000000000000000")
def test_complex(self): assert tohex( encode_abi( ["uint256", "uint32[]", "bytes10", "bytes"], (0x123, [0x456, 0x789], b"1234567890", b"Hello, world!")) ) == ( b'0000000000000000000000000000000000000000000000000000000000000123' b'0000000000000000000000000000000000000000000000000000000000000080' b'3132333435363738393000000000000000000000000000000000000000000000' b'00000000000000000000000000000000000000000000000000000000000000e0' b'0000000000000000000000000000000000000000000000000000000000000002' b'0000000000000000000000000000000000000000000000000000000000000456' b'0000000000000000000000000000000000000000000000000000000000000789' b'000000000000000000000000000000000000000000000000000000000000000d' b'48656c6c6f2c20776f726c642100000000000000000000000000000000000000' )
def test_multiple_dynamics(self): res = tohex( encode_abi(["uint256[]", "uint256[]", "uint256[]"], [[1], [1, 2], [1, 2, 3]])) assert res == ( b'0000000000000000000000000000000000000000000000000000000000000060' b'00000000000000000000000000000000000000000000000000000000000000a0' b'0000000000000000000000000000000000000000000000000000000000000100' b'0000000000000000000000000000000000000000000000000000000000000001' b'0000000000000000000000000000000000000000000000000000000000000001' b'0000000000000000000000000000000000000000000000000000000000000002' b'0000000000000000000000000000000000000000000000000000000000000001' b'0000000000000000000000000000000000000000000000000000000000000002' b'0000000000000000000000000000000000000000000000000000000000000003' b'0000000000000000000000000000000000000000000000000000000000000001' b'0000000000000000000000000000000000000000000000000000000000000002' b'0000000000000000000000000000000000000000000000000000000000000003' )
def test_static_size_2(self): assert tohex(encode_abi( ["uint32[2]"], [[6, 69]])) == (b'00000000000000000000000000000000' b'00000000000000000000000000000006' b'00000000000000000000000000000000' b'00000000000000000000000000000045')
def test_simple(self): assert tohex(encode_abi(["uint32"], [6])) == (b'00000000000000000000000000000000' b'00000000000000000000000000000006')
def test_encode_abi(self): assert tohex(encode_abi(["bool"], [True])) == \ b'0000000000000000000000000000000000000000000000000000000000000001' assert tohex(encode_abi(["bool"], [False])) == \ b'0000000000000000000000000000000000000000000000000000000000000000'
def test_encode_abi(self, one_to_thirtytwo): t = "string{}".format(one_to_thirtytwo) assert tohex(encode_abi([t], ['A'])) == \ b'4100000000000000000000000000000000000000000000000000000000000000'