Skip to content

Commit 88e67c5

Browse files
committed
accounts/abi: add a test case for unpacking mobile interfaces
1 parent e7cd627 commit 88e67c5

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

‎accounts/abi/unpack_test.go‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,42 @@ func TestUnpack(t *testing.T) {
287287
}
288288
}
289289

290+
var unpackMobileTests = []unpackTest{
291+
{
292+
def: `[{"type": "uint256"}]`,
293+
enc: "0000000000000000000000000000000000000000000000000000000000000001",
294+
want: big.NewInt(1),
295+
},
296+
}
297+
298+
func TestUnpackMobileOnly(t *testing.T) {
299+
for i, test := range unpackMobileTests {
300+
t.Run(strconv.Itoa(i), func(t *testing.T) {
301+
def := fmt.Sprintf(`[{ "name" : "method", "outputs": %s}]`, test.def)
302+
abi, err := JSON(strings.NewReader(def))
303+
if err != nil {
304+
t.Fatalf("invalid ABI definition %s: %v", def, err)
305+
}
306+
encb, err := hex.DecodeString(test.enc)
307+
if err != nil {
308+
t.Fatalf("invalid hex: %s" + test.enc)
309+
}
310+
outptr := reflect.New(reflect.TypeOf(test.want))
311+
results := make([]interface{}, 1)
312+
copy(results, []interface{}{outptr.Interface()})
313+
err = abi.Unpack(&results, "method", encb)
314+
if err := test.checkError(err); err != nil {
315+
t.Errorf("test %d (%v) failed: %v", i, test.def, err)
316+
return
317+
}
318+
out := outptr.Elem().Interface()
319+
if !reflect.DeepEqual(test.want, out) {
320+
t.Errorf("test %d (%v) failed: expected %v, got %v", i, test.def, test.want, out)
321+
}
322+
})
323+
}
324+
}
325+
290326
type methodMultiOutput struct {
291327
Int *big.Int
292328
String string

0 commit comments

Comments
 (0)