diff options
author | bas-vk <bas-vk@users.noreply.github.com> | 2018-12-22 18:26:49 +0800 |
---|---|---|
committer | Guillaume Ballet <gballet@gmail.com> | 2018-12-22 18:26:49 +0800 |
commit | 7df52e324c1393f9dad3daa8c724782f4ade5b42 (patch) | |
tree | d9676d352f19aab7e2e8f3f97fd939c0d97265b9 /accounts/abi/unpack_test.go | |
parent | 5e4fd8e7dbfe701b3b544c52c433c5d7c2e302c3 (diff) | |
download | go-tangerine-7df52e324c1393f9dad3daa8c724782f4ade5b42.tar go-tangerine-7df52e324c1393f9dad3daa8c724782f4ade5b42.tar.gz go-tangerine-7df52e324c1393f9dad3daa8c724782f4ade5b42.tar.bz2 go-tangerine-7df52e324c1393f9dad3daa8c724782f4ade5b42.tar.lz go-tangerine-7df52e324c1393f9dad3daa8c724782f4ade5b42.tar.xz go-tangerine-7df52e324c1393f9dad3daa8c724782f4ade5b42.tar.zst go-tangerine-7df52e324c1393f9dad3daa8c724782f4ade5b42.zip |
accounts/abi: add support for unpacking returned bytesN arrays (#15242)
Diffstat (limited to 'accounts/abi/unpack_test.go')
-rw-r--r-- | accounts/abi/unpack_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/accounts/abi/unpack_test.go b/accounts/abi/unpack_test.go index 29ed4522c..de7953770 100644 --- a/accounts/abi/unpack_test.go +++ b/accounts/abi/unpack_test.go @@ -364,6 +364,55 @@ func TestUnpack(t *testing.T) { } } +func TestUnpackSetDynamicArrayOutput(t *testing.T) { + abi, err := JSON(strings.NewReader(`[{"constant":true,"inputs":[],"name":"testDynamicFixedBytes15","outputs":[{"name":"","type":"bytes15[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"testDynamicFixedBytes32","outputs":[{"name":"","type":"bytes32[]"}],"payable":false,"stateMutability":"view","type":"function"}]`)) + if err != nil { + t.Fatal(err) + } + + var ( + marshalledReturn32 = common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000230783132333435363738393000000000000000000000000000000000000000003078303938373635343332310000000000000000000000000000000000000000") + marshalledReturn15 = common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000230783031323334350000000000000000000000000000000000000000000000003078393837363534000000000000000000000000000000000000000000000000") + + out32 [][32]byte + out15 [][15]byte + ) + + // test 32 + err = abi.Unpack(&out32, "testDynamicFixedBytes32", marshalledReturn32) + if err != nil { + t.Fatal(err) + } + if len(out32) != 2 { + t.Fatalf("expected array with 2 values, got %d", len(out32)) + } + expected := common.Hex2Bytes("3078313233343536373839300000000000000000000000000000000000000000") + if !bytes.Equal(out32[0][:], expected) { + t.Errorf("expected %x, got %x\n", expected, out32[0]) + } + expected = common.Hex2Bytes("3078303938373635343332310000000000000000000000000000000000000000") + if !bytes.Equal(out32[1][:], expected) { + t.Errorf("expected %x, got %x\n", expected, out32[1]) + } + + // test 15 + err = abi.Unpack(&out15, "testDynamicFixedBytes32", marshalledReturn15) + if err != nil { + t.Fatal(err) + } + if len(out15) != 2 { + t.Fatalf("expected array with 2 values, got %d", len(out15)) + } + expected = common.Hex2Bytes("307830313233343500000000000000") + if !bytes.Equal(out15[0][:], expected) { + t.Errorf("expected %x, got %x\n", expected, out15[0]) + } + expected = common.Hex2Bytes("307839383736353400000000000000") + if !bytes.Equal(out15[1][:], expected) { + t.Errorf("expected %x, got %x\n", expected, out15[1]) + } +} + type methodMultiOutput struct { Int *big.Int String string |