forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added tests for new abi encoding features #4
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ func TestPack(t *testing.T) { | |
{ | ||
"uint8[]", | ||
[]uint8{1, 2}, | ||
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
}, | ||
{ | ||
"uint16", | ||
|
@@ -52,7 +52,7 @@ func TestPack(t *testing.T) { | |
{ | ||
"uint16[]", | ||
[]uint16{1, 2}, | ||
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
}, | ||
{ | ||
"uint32", | ||
|
@@ -62,7 +62,7 @@ func TestPack(t *testing.T) { | |
{ | ||
"uint32[]", | ||
[]uint32{1, 2}, | ||
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
}, | ||
{ | ||
"uint64", | ||
|
@@ -72,7 +72,7 @@ func TestPack(t *testing.T) { | |
{ | ||
"uint64[]", | ||
[]uint64{1, 2}, | ||
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
}, | ||
{ | ||
"uint256", | ||
|
@@ -82,7 +82,7 @@ func TestPack(t *testing.T) { | |
{ | ||
"uint256[]", | ||
[]*big.Int{big.NewInt(1), big.NewInt(2)}, | ||
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
}, | ||
{ | ||
"int8", | ||
|
@@ -92,7 +92,7 @@ func TestPack(t *testing.T) { | |
{ | ||
"int8[]", | ||
[]int8{1, 2}, | ||
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
}, | ||
{ | ||
"int16", | ||
|
@@ -102,7 +102,7 @@ func TestPack(t *testing.T) { | |
{ | ||
"int16[]", | ||
[]int16{1, 2}, | ||
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
}, | ||
{ | ||
"int32", | ||
|
@@ -112,7 +112,7 @@ func TestPack(t *testing.T) { | |
{ | ||
"int32[]", | ||
[]int32{1, 2}, | ||
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
}, | ||
{ | ||
"int64", | ||
|
@@ -122,7 +122,7 @@ func TestPack(t *testing.T) { | |
{ | ||
"int64[]", | ||
[]int64{1, 2}, | ||
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
}, | ||
{ | ||
"int256", | ||
|
@@ -132,7 +132,7 @@ func TestPack(t *testing.T) { | |
{ | ||
"int256[]", | ||
[]*big.Int{big.NewInt(1), big.NewInt(2)}, | ||
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), | ||
}, | ||
{ | ||
"bytes1", | ||
|
@@ -305,14 +305,21 @@ func TestPack(t *testing.T) { | |
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001300000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000018"), | ||
}, | ||
{ | ||
//web3.eth.abi.encodeParameter('address[]', ['0x0100000000000000000000000000000000000000','0x0200000000000000000000000000000000000000']); | ||
"address[]", | ||
[]common.Address{{1}, {2}}, | ||
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020" + | ||
"0000000000000000000000000000000000000000000000000000000000000002" + | ||
"0000000000000000000000000100000000000000000000000000000000000000" + | ||
"0000000000000000000000000200000000000000000000000000000000000000"), | ||
}, | ||
{ | ||
"bytes32[]", | ||
[]common.Hash{{1}, {2}}, | ||
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000201000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020" + //offset: 32 | ||
"0000000000000000000000000000000000000000000000000000000000000002" + //len: 2 | ||
"0100000000000000000000000000000000000000000000000000000000000000" + // 1 | ||
"0200000000000000000000000000000000000000000000000000000000000000"), // 2 | ||
}, | ||
{ | ||
"function", | ||
|
@@ -322,7 +329,41 @@ func TestPack(t *testing.T) { | |
{ | ||
"string", | ||
"foobar", | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000006666f6f6261720000000000000000000000000000000000000000000000000000"), | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020" + // offset: 32 | ||
"0000000000000000000000000000000000000000000000000000000000000006" + // len: 6 | ||
"666f6f6261720000000000000000000000000000000000000000000000000000"), // "foobar" | ||
}, | ||
{ | ||
"string[]", | ||
[]string{"hello", "foobar"}, | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020" + // offset array 32 | ||
"0000000000000000000000000000000000000000000000000000000000000002" + // len(array) = 2 | ||
"0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i=0 | ||
"0000000000000000000000000000000000000000000000000000000000000080" + // offset 128 to i=1 | ||
"0000000000000000000000000000000000000000000000000000000000000005" + // len(str[0]) = 5 | ||
"68656c6c6f000000000000000000000000000000000000000000000000000000" + // str[0] | ||
"0000000000000000000000000000000000000000000000000000000000000006" + // len(str[1]) = 6 | ||
"666f6f6261720000000000000000000000000000000000000000000000000000"), // str[1] | ||
}, | ||
{ | ||
|
||
//web3.eth.abi.encodeParameter('bytes32[][]', [['0x0100000000000000000000000000000000000000000000000000000000000000', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the web3.js calls as a comment for easier cross checking. We can remove them later |
||
// '0x0200000000000000000000000000000000000000000000000000000000000000'],['0x0300000000000000000000000000000000000000000000000000000000000000', | ||
// '0x0400000000000000000000000000000000000000000000000000000000000000','0x0500000000000000000000000000000000000000000000000000000000000000']]); | ||
"bytes32[][]", | ||
[][]common.Hash{{{1}, {2}}, {{3}, {4}, {5}}}, | ||
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020" + // offset array 32 | ||
"0000000000000000000000000000000000000000000000000000000000000002" + // len(array) = 2 | ||
"0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i=0 | ||
"00000000000000000000000000000000000000000000000000000000000000a0" + // offset 160 to i=1 | ||
"0000000000000000000000000000000000000000000000000000000000000002" + // len(array[0]) = 2 | ||
"0100000000000000000000000000000000000000000000000000000000000000" + // array[0] | ||
"0200000000000000000000000000000000000000000000000000000000000000" + // array[1] | ||
"0000000000000000000000000000000000000000000000000000000000000003" + // len(array[1]) = 3 | ||
"0300000000000000000000000000000000000000000000000000000000000000" + // array[0] | ||
"0400000000000000000000000000000000000000000000000000000000000000" + // array[1] | ||
"0500000000000000000000000000000000000000000000000000000000000000"), // array[2] | ||
|
||
}, | ||
} { | ||
typ, err := NewType(test.typ) | ||
|
@@ -336,7 +377,7 @@ func TestPack(t *testing.T) { | |
} | ||
|
||
if !bytes.Equal(output, test.output) { | ||
t.Errorf("%d failed. Expected bytes: '%x' Got: '%x'", i, test.output, output) | ||
t.Errorf("input %d for typ: %v failed. Expected bytes: '%x' Got: '%x'", i, typ.String(), test.output, output) | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for all these lines only
0000000000000000000000000000000000000000000000000000000000000020
has been added in the beginning