MCPcopy Create free account
hub / github.com/CPChain/chain / TestMethodMultiReturn

Function TestMethodMultiReturn

accounts/abi/unpack_test.go:378–435  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

376}
377
378func TestMethodMultiReturn(t *testing.T) {
379 type reversed struct {
380 String string
381 Int *big.Int
382 }
383
384 abi, data, expected := methodMultiReturn(require.New(t))
385 bigint := new(big.Int)
386 var testCases = []struct {
387 dest interface{}
388 expected interface{}
389 error string
390 name string
391 }{{
392 &methodMultiOutput{},
393 &expected,
394 "",
395 "Can unpack into structure",
396 }, {
397 &reversed{},
398 &reversed{expected.String, expected.Int},
399 "",
400 "Can unpack into reversed structure",
401 }, {
402 &[]interface{}{&bigint, new(string)},
403 &[]interface{}{&expected.Int, &expected.String},
404 "",
405 "Can unpack into a slice",
406 }, {
407 &[2]interface{}{&bigint, new(string)},
408 &[2]interface{}{&expected.Int, &expected.String},
409 "",
410 "Can unpack into an array",
411 }, {
412 &[]interface{}{new(int), new(int)},
413 &[]interface{}{&expected.Int, &expected.String},
414 "abi: cannot unmarshal *big.Int in to int",
415 "Can not unpack into a slice with wrong types",
416 }, {
417 &[]interface{}{new(int)},
418 &[]interface{}{},
419 "abi: insufficient number of elements in the list/array for unpack, want 2, got 1",
420 "Can not unpack into a slice with wrong types",
421 }}
422 for _, tc := range testCases {
423 tc := tc
424 t.Run(tc.name, func(t *testing.T) {
425 require := require.New(t)
426 err := abi.Unpack(tc.dest, "multi", data)
427 if tc.error == "" {
428 require.Nil(err, "Should be able to unpack method outputs.")
429 require.Equal(tc.expected, tc.dest)
430 } else {
431 require.EqualError(err, tc.error)
432 }
433 })
434 }
435}

Callers

nothing calls this directly

Calls 4

methodMultiReturnFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65
UnpackMethod · 0.45

Tested by

no test coverage detected