| 458 | } |
| 459 | |
| 460 | func TestMultiReturnWithDeeplyNestedArray(t *testing.T) { |
| 461 | // Similar to TestMultiReturnWithArray, but with a special case in mind: |
| 462 | // values of nested static arrays count towards the size as well, and any element following |
| 463 | // after such nested array argument should be read with the correct offset, |
| 464 | // so that it does not read content from the previous array argument. |
| 465 | const definition = `[{"name" : "multi", "outputs": [{"type": "uint64[3][2][4]"}, {"type": "uint64"}]}]` |
| 466 | abi, err := JSON(strings.NewReader(definition)) |
| 467 | if err != nil { |
| 468 | t.Fatal(err) |
| 469 | } |
| 470 | buff := new(bytes.Buffer) |
| 471 | // construct the test array, each 3 char element is joined with 61 '0' chars, |
| 472 | // to from the ((3 + 61) * 0.5) = 32 byte elements in the array. |
| 473 | buff.Write(common.Hex2Bytes(strings.Join([]string{ |
| 474 | "", //empty, to apply the 61-char separator to the first element as well. |
| 475 | "111", "112", "113", "121", "122", "123", |
| 476 | "211", "212", "213", "221", "222", "223", |
| 477 | "311", "312", "313", "321", "322", "323", |
| 478 | "411", "412", "413", "421", "422", "423", |
| 479 | }, "0000000000000000000000000000000000000000000000000000000000000"))) |
| 480 | buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000009876")) |
| 481 | |
| 482 | ret1, ret1Exp := new([4][2][3]uint64), [4][2][3]uint64{ |
| 483 | {{0x111, 0x112, 0x113}, {0x121, 0x122, 0x123}}, |
| 484 | {{0x211, 0x212, 0x213}, {0x221, 0x222, 0x223}}, |
| 485 | {{0x311, 0x312, 0x313}, {0x321, 0x322, 0x323}}, |
| 486 | {{0x411, 0x412, 0x413}, {0x421, 0x422, 0x423}}, |
| 487 | } |
| 488 | ret2, ret2Exp := new(uint64), uint64(0x9876) |
| 489 | if err := abi.Unpack(&[]interface{}{ret1, ret2}, "multi", buff.Bytes()); err != nil { |
| 490 | t.Fatal(err) |
| 491 | } |
| 492 | if !reflect.DeepEqual(*ret1, ret1Exp) { |
| 493 | t.Error("array result", *ret1, "!= Expected", ret1Exp) |
| 494 | } |
| 495 | if *ret2 != ret2Exp { |
| 496 | t.Error("int result", *ret2, "!= Expected", ret2Exp) |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | func TestUnmarshal(t *testing.T) { |
| 501 | const definition = `[ |