(t *testing.T)
| 376 | } |
| 377 | |
| 378 | func 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 | } |
nothing calls this directly
no test coverage detected