diff options
author | Matt K <1036969+mkrump@users.noreply.github.com> | 2018-12-29 18:32:58 +0800 |
---|---|---|
committer | Guillaume Ballet <gballet@gmail.com> | 2018-12-29 18:32:58 +0800 |
commit | a4af734328d50b9ea89405c7e5050065a8087946 (patch) | |
tree | 5741ded89a84cef4ca38faf10b5cc9094a1c7529 /accounts/abi/unpack_test.go | |
parent | 735343430dec74a340f5c9a18822537e18165caa (diff) | |
download | go-tangerine-a4af734328d50b9ea89405c7e5050065a8087946.tar go-tangerine-a4af734328d50b9ea89405c7e5050065a8087946.tar.gz go-tangerine-a4af734328d50b9ea89405c7e5050065a8087946.tar.bz2 go-tangerine-a4af734328d50b9ea89405c7e5050065a8087946.tar.lz go-tangerine-a4af734328d50b9ea89405c7e5050065a8087946.tar.xz go-tangerine-a4af734328d50b9ea89405c7e5050065a8087946.tar.zst go-tangerine-a4af734328d50b9ea89405c7e5050065a8087946.zip |
accounts/abi: change unpacking of abi fields w/ underscores (#16513)
* accounts/abi: fix name styling when unpacking abi fields w/ underscores
ABI fields with underscores that are being unpacked
into structs expect structs with following form:
int_one -> Int_one
whereas in abigen the generated structs are camelcased
int_one -> IntOne
so updated the unpack method to expect camelcased structs as well.
Diffstat (limited to 'accounts/abi/unpack_test.go')
-rw-r--r-- | accounts/abi/unpack_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/accounts/abi/unpack_test.go b/accounts/abi/unpack_test.go index 22aa1a857..3873414c9 100644 --- a/accounts/abi/unpack_test.go +++ b/accounts/abi/unpack_test.go @@ -311,6 +311,53 @@ var unpackTests = []unpackTest{ }{big.NewInt(1), big.NewInt(2)}, }, { + def: `[{"name":"int_one","type":"int256"}]`, + enc: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + want: struct { + IntOne *big.Int + }{big.NewInt(1)}, + }, + { + def: `[{"name":"int__one","type":"int256"}]`, + enc: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + want: struct { + IntOne *big.Int + }{big.NewInt(1)}, + }, + { + def: `[{"name":"int_one_","type":"int256"}]`, + enc: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + want: struct { + IntOne *big.Int + }{big.NewInt(1)}, + }, + { + def: `[{"name":"int_one","type":"int256"}, {"name":"intone","type":"int256"}]`, + enc: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + want: struct { + IntOne *big.Int + Intone *big.Int + }{big.NewInt(1), big.NewInt(2)}, + }, + { + def: `[{"name":"___","type":"int256"}]`, + enc: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + want: struct { + IntOne *big.Int + Intone *big.Int + }{}, + err: "abi: purely underscored output cannot unpack to struct", + }, + { + def: `[{"name":"int_one","type":"int256"},{"name":"IntOne","type":"int256"}]`, + enc: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + want: struct { + Int1 *big.Int + Int2 *big.Int + }{}, + err: "abi: multiple outputs mapping to the same struct field 'IntOne'", + }, + { def: `[{"name":"int","type":"int256"},{"name":"Int","type":"int256"}]`, enc: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", want: struct { |