aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcroath <croathliu@gmail.com>2017-12-31 19:12:55 +0800
committercroath <croathliu@gmail.com>2017-12-31 19:12:55 +0800
commit88e67c552e5da4d114d80be3ff471f4f2ed030f5 (patch)
treecfae638c7bbcb6e96666ae03c94c4d5d39992268
parente7cd627d93d43ff52d13c66b336e12b96d9bfdef (diff)
downloadgo-tangerine-88e67c552e5da4d114d80be3ff471f4f2ed030f5.tar
go-tangerine-88e67c552e5da4d114d80be3ff471f4f2ed030f5.tar.gz
go-tangerine-88e67c552e5da4d114d80be3ff471f4f2ed030f5.tar.bz2
go-tangerine-88e67c552e5da4d114d80be3ff471f4f2ed030f5.tar.lz
go-tangerine-88e67c552e5da4d114d80be3ff471f4f2ed030f5.tar.xz
go-tangerine-88e67c552e5da4d114d80be3ff471f4f2ed030f5.tar.zst
go-tangerine-88e67c552e5da4d114d80be3ff471f4f2ed030f5.zip
accounts/abi: add a test case for unpacking mobile interfaces
-rw-r--r--accounts/abi/unpack_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/accounts/abi/unpack_test.go b/accounts/abi/unpack_test.go
index 391095073..a7901896a 100644
--- a/accounts/abi/unpack_test.go
+++ b/accounts/abi/unpack_test.go
@@ -287,6 +287,42 @@ func TestUnpack(t *testing.T) {
}
}
+var unpackMobileTests = []unpackTest{
+ {
+ def: `[{"type": "uint256"}]`,
+ enc: "0000000000000000000000000000000000000000000000000000000000000001",
+ want: big.NewInt(1),
+ },
+}
+
+func TestUnpackMobileOnly(t *testing.T) {
+ for i, test := range unpackMobileTests {
+ t.Run(strconv.Itoa(i), func(t *testing.T) {
+ def := fmt.Sprintf(`[{ "name" : "method", "outputs": %s}]`, test.def)
+ abi, err := JSON(strings.NewReader(def))
+ if err != nil {
+ t.Fatalf("invalid ABI definition %s: %v", def, err)
+ }
+ encb, err := hex.DecodeString(test.enc)
+ if err != nil {
+ t.Fatalf("invalid hex: %s" + test.enc)
+ }
+ outptr := reflect.New(reflect.TypeOf(test.want))
+ results := make([]interface{}, 1)
+ copy(results, []interface{}{outptr.Interface()})
+ err = abi.Unpack(&results, "method", encb)
+ if err := test.checkError(err); err != nil {
+ t.Errorf("test %d (%v) failed: %v", i, test.def, err)
+ return
+ }
+ out := outptr.Elem().Interface()
+ if !reflect.DeepEqual(test.want, out) {
+ t.Errorf("test %d (%v) failed: expected %v, got %v", i, test.def, test.want, out)
+ }
+ })
+ }
+}
+
type methodMultiOutput struct {
Int *big.Int
String string