mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
accounts/abi: more extensive testing of slices and arrays for all integer types
Signed-off-by: RJ Catalano <rj@monax.io>
This commit is contained in:
parent
89c3bfddc6
commit
9bb7fd7bd2
1 changed files with 119 additions and 0 deletions
|
|
@ -237,6 +237,34 @@ func TestArraysAndSlicesUnpack(t *testing.T) {
|
|||
outVar interface{} // the output variable (e.g. uint32, *big.Int, etc)
|
||||
err string // empty or error if expected
|
||||
}{
|
||||
{
|
||||
`[ { "type": "uint8[]" } ]`,
|
||||
append(pad(common.Hex2Bytes("20"), 32, true), formatSliceOutput([]byte{1}, []byte{2})...),
|
||||
[]uint8{1, 2},
|
||||
[]uint8{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "uint8[2]" } ]`,
|
||||
append(pad([]byte{1}, 32, true), pad([]byte{2}, 32, true)...),
|
||||
[2]uint8{1, 2},
|
||||
[2]uint8{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "uint16[]" } ]`,
|
||||
append(pad(common.Hex2Bytes("20"), 32, true), formatSliceOutput([]byte{1}, []byte{2})...),
|
||||
[]uint16{1, 2},
|
||||
[]uint16{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "uint16[2]" } ]`,
|
||||
append(pad([]byte{1}, 32, true), pad([]byte{2}, 32, true)...),
|
||||
[2]uint16{1, 2},
|
||||
[2]uint16{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "uint32[]" } ]`,
|
||||
append(pad(common.Hex2Bytes("20"), 32, true), formatSliceOutput([]byte{1}, []byte{2})...),
|
||||
|
|
@ -251,6 +279,27 @@ func TestArraysAndSlicesUnpack(t *testing.T) {
|
|||
[2]uint32{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "uint64[]" } ]`,
|
||||
append(pad(common.Hex2Bytes("20"), 32, true), formatSliceOutput([]byte{1}, []byte{2})...),
|
||||
[]uint64{1, 2},
|
||||
[]uint64{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "uint64[2]" } ]`,
|
||||
append(pad([]byte{1}, 32, true), pad([]byte{2}, 32, true)...),
|
||||
[2]uint64{1, 2},
|
||||
[2]uint64{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "uint256[]" } ]`,
|
||||
append(pad(common.Hex2Bytes("20"), 32, true), formatSliceOutput([]byte{1}, []byte{2})...),
|
||||
[]*big.Int{big.NewInt(1), big.NewInt(2)},
|
||||
[]*big.Int{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "uint256[3]" } ]`,
|
||||
append(pad([]byte{1}, 32, true), append(pad([]byte{2}, 32, true), pad([]byte{3}, 32, true)...)...),
|
||||
|
|
@ -258,6 +307,76 @@ func TestArraysAndSlicesUnpack(t *testing.T) {
|
|||
[3]*big.Int{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "int8[]" } ]`,
|
||||
append(pad(common.Hex2Bytes("20"), 32, true), formatSliceOutput([]byte{1}, []byte{2})...),
|
||||
[]int8{1, 2},
|
||||
[]int8{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "int8[2]" } ]`,
|
||||
append(pad([]byte{1}, 32, true), pad([]byte{2}, 32, true)...),
|
||||
[2]int8{1, 2},
|
||||
[2]int8{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "int16[]" } ]`,
|
||||
append(pad(common.Hex2Bytes("20"), 32, true), formatSliceOutput([]byte{1}, []byte{2})...),
|
||||
[]int16{1, 2},
|
||||
[]int16{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "int16[2]" } ]`,
|
||||
append(pad([]byte{1}, 32, true), pad([]byte{2}, 32, true)...),
|
||||
[2]int16{1, 2},
|
||||
[2]int16{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "int32[]" } ]`,
|
||||
append(pad(common.Hex2Bytes("20"), 32, true), formatSliceOutput([]byte{1}, []byte{2})...),
|
||||
[]int32{1, 2},
|
||||
[]int32{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "int32[2]" } ]`,
|
||||
append(pad([]byte{1}, 32, true), pad([]byte{2}, 32, true)...),
|
||||
[2]int32{1, 2},
|
||||
[2]int32{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "int64[]" } ]`,
|
||||
append(pad(common.Hex2Bytes("20"), 32, true), formatSliceOutput([]byte{1}, []byte{2})...),
|
||||
[]int64{1, 2},
|
||||
[]int64{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "int64[2]" } ]`,
|
||||
append(pad([]byte{1}, 32, true), pad([]byte{2}, 32, true)...),
|
||||
[2]int64{1, 2},
|
||||
[2]int64{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "int256[]" } ]`,
|
||||
append(pad(common.Hex2Bytes("20"), 32, true), formatSliceOutput([]byte{1}, []byte{2})...),
|
||||
[]*big.Int{big.NewInt(1), big.NewInt(2)},
|
||||
[]*big.Int{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "int256[3]" } ]`,
|
||||
append(pad([]byte{1}, 32, true), append(pad([]byte{2}, 32, true), pad([]byte{3}, 32, true)...)...),
|
||||
[3]*big.Int{big.NewInt(1), big.NewInt(2), big.NewInt(3)},
|
||||
[3]*big.Int{},
|
||||
"",
|
||||
},
|
||||
} {
|
||||
|
||||
abiDefinition := fmt.Sprintf(`[{ "name" : "method", "outputs": %s}]`, test.def)
|
||||
|
|
|
|||
Loading…
Reference in a new issue