Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
57a3fab8
Unverified
Commit
57a3fab8
authored
Sep 22, 2021
by
gary rong
Committed by
GitHub
Sep 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi: fix resolving single struct argument (#23573)
parent
ca9bce9a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
8 deletions
+83
-8
argument.go
accounts/abi/argument.go
+1
-1
bind_test.go
accounts/abi/bind/bind_test.go
+71
-0
unpack_test.go
accounts/abi/unpack_test.go
+11
-7
No files found.
accounts/abi/argument.go
View file @
57a3fab8
...
@@ -137,7 +137,7 @@ func (arguments Arguments) copyAtomic(v interface{}, marshalledValues interface{
...
@@ -137,7 +137,7 @@ func (arguments Arguments) copyAtomic(v interface{}, marshalledValues interface{
dst
:=
reflect
.
ValueOf
(
v
)
.
Elem
()
dst
:=
reflect
.
ValueOf
(
v
)
.
Elem
()
src
:=
reflect
.
ValueOf
(
marshalledValues
)
src
:=
reflect
.
ValueOf
(
marshalledValues
)
if
dst
.
Kind
()
==
reflect
.
Struct
&&
src
.
Kind
()
!=
reflect
.
Struct
{
if
dst
.
Kind
()
==
reflect
.
Struct
{
return
set
(
dst
.
Field
(
0
),
src
)
return
set
(
dst
.
Field
(
0
),
src
)
}
}
return
set
(
dst
,
src
)
return
set
(
dst
,
src
)
...
...
accounts/abi/bind/bind_test.go
View file @
57a3fab8
...
@@ -1785,6 +1785,77 @@ var bindTests = []struct {
...
@@ -1785,6 +1785,77 @@ var bindTests = []struct {
nil
,
nil
,
nil
,
nil
,
},
},
// Test resolving single struct argument
{
`NewSingleStructArgument`
,
`
pragma solidity ^0.8.0;
contract NewSingleStructArgument {
struct MyStruct{
uint256 a;
uint256 b;
}
event StructEvent(MyStruct s);
function TestEvent() public {
emit StructEvent(MyStruct({a: 1, b: 2}));
}
}
`
,
[]
string
{
"608060405234801561001057600080fd5b50610113806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c806324ec1d3f14602d575b600080fd5b60336035565b005b7fb4b2ff75e30cb4317eaae16dd8a187dd89978df17565104caa6c2797caae27d460405180604001604052806001815260200160028152506040516078919060ba565b60405180910390a1565b6040820160008201516096600085018260ad565b50602082015160a7602085018260ad565b50505050565b60b48160d3565b82525050565b600060408201905060cd60008301846082565b92915050565b600081905091905056fea26469706673582212208823628796125bf9941ce4eda18da1be3cf2931b231708ab848e1bd7151c0c9a64736f6c63430008070033"
},
[]
string
{
`[{"anonymous":false,"inputs":[{"components":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"uint256","name":"b","type":"uint256"}],"indexed":false,"internalType":"struct Test.MyStruct","name":"s","type":"tuple"}],"name":"StructEvent","type":"event"},{"inputs":[],"name":"TestEvent","outputs":[],"stateMutability":"nonpayable","type":"function"}]`
},
`
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/ethconfig"
`
,
`
var (
key, _ = crypto.GenerateKey()
user, _ = bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
sim = backends.NewSimulatedBackend(core.GenesisAlloc{user.From: {Balance: big.NewInt(1000000000000000000)}}, ethconfig.Defaults.Miner.GasCeil)
)
defer sim.Close()
_, _, d, err := DeployNewSingleStructArgument(user, sim)
if err != nil {
t.Fatalf("Failed to deploy contract %v", err)
}
sim.Commit()
_, err = d.TestEvent(user)
if err != nil {
t.Fatalf("Failed to call contract %v", err)
}
sim.Commit()
it, err := d.FilterStructEvent(nil)
if err != nil {
t.Fatalf("Failed to filter contract event %v", err)
}
var count int
for it.Next() {
if it.Event.S.A.Cmp(big.NewInt(1)) != 0 {
t.Fatal("Unexpected contract event")
}
if it.Event.S.B.Cmp(big.NewInt(2)) != 0 {
t.Fatal("Unexpected contract event")
}
count += 1
}
if count != 1 {
t.Fatal("Unexpected contract event number")
}
`
,
nil
,
nil
,
nil
,
nil
,
},
}
}
// Tests that packages generated by the binder can be successfully compiled and
// Tests that packages generated by the binder can be successfully compiled and
...
...
accounts/abi/unpack_test.go
View file @
57a3fab8
...
@@ -762,20 +762,24 @@ func TestUnpackTuple(t *testing.T) {
...
@@ -762,20 +762,24 @@ func TestUnpackTuple(t *testing.T) {
buff
.
Write
(
common
.
Hex2Bytes
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
))
// ret[b] = -1
buff
.
Write
(
common
.
Hex2Bytes
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
))
// ret[b] = -1
// If the result is single tuple, use struct as return value container directly.
// If the result is single tuple, use struct as return value container directly.
v
:=
struct
{
type
v
struct
{
A
*
big
.
Int
A
*
big
.
Int
B
*
big
.
Int
B
*
big
.
Int
}{
new
(
big
.
Int
),
new
(
big
.
Int
)}
}
type
r
struct
{
Result
v
}
var
ret0
=
new
(
r
)
err
=
abi
.
UnpackIntoInterface
(
ret0
,
"tuple"
,
buff
.
Bytes
())
err
=
abi
.
UnpackIntoInterface
(
&
v
,
"tuple"
,
buff
.
Bytes
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Error
(
err
)
}
else
{
}
else
{
if
v
.
A
.
Cmp
(
big
.
NewInt
(
1
))
!=
0
{
if
ret0
.
Result
.
A
.
Cmp
(
big
.
NewInt
(
1
))
!=
0
{
t
.
Errorf
(
"unexpected value unpacked: want %x, got %x"
,
1
,
v
.
A
)
t
.
Errorf
(
"unexpected value unpacked: want %x, got %x"
,
1
,
ret0
.
Result
.
A
)
}
}
if
v
.
B
.
Cmp
(
big
.
NewInt
(
-
1
))
!=
0
{
if
ret0
.
Result
.
B
.
Cmp
(
big
.
NewInt
(
-
1
))
!=
0
{
t
.
Errorf
(
"unexpected value unpacked: want %x, got %x"
,
-
1
,
v
.
B
)
t
.
Errorf
(
"unexpected value unpacked: want %x, got %x"
,
-
1
,
ret0
.
Result
.
B
)
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment