aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi/bind/bind_test.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-04-05 23:20:50 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-04-05 23:20:50 +0800
commitfc4fffd5ac341b6e7c9644045b66420f777940c5 (patch)
tree3f7fcb9ebad8c822e8d657ab43a2ca23ba27ce99 /accounts/abi/bind/bind_test.go
parent7e02105672cda92889a78db864a5701d78f45eb2 (diff)
downloaddexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.tar
dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.tar.gz
dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.tar.bz2
dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.tar.lz
dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.tar.xz
dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.tar.zst
dexon-fc4fffd5ac341b6e7c9644045b66420f777940c5.zip
accounts/abi/bind: support generating bindings for various arrays
Diffstat (limited to 'accounts/abi/bind/bind_test.go')
-rw-r--r--accounts/abi/bind/bind_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/accounts/abi/bind/bind_test.go b/accounts/abi/bind/bind_test.go
index 12c849669..3f02af017 100644
--- a/accounts/abi/bind/bind_test.go
+++ b/accounts/abi/bind/bind_test.go
@@ -228,6 +228,50 @@ var bindTests = []struct {
}
`,
},
+ // Tests that arrays/slices can be properly returned and deserialized.
+ // Only addresses are tested, remainder just compiled to keep the test small.
+ {
+ `Slicer`,
+ `
+ contract Slicer {
+ function echoAddresses(address[] input) constant returns (address[] output) {
+ return input;
+ }
+ function echoInts(int[] input) constant returns (int[] output) {
+ return input;
+ }
+ function echoFancyInts(uint24[23] input) constant returns (uint24[23] output) {
+ return input;
+ }
+ function echoBools(bool[] input) constant returns (bool[] output) {
+ return input;
+ }
+ }
+ `,
+ `606060405261015c806100126000396000f3606060405260e060020a6000350463be1127a3811461003c578063d88becc014610092578063e15a3db71461003c578063f637e5891461003c575b005b604080516020600480358082013583810285810185019096528085526100ee959294602494909392850192829185019084908082843750949650505050505050604080516020810190915260009052805b919050565b604080516102e0818101909252610138916004916102e491839060179083908390808284375090955050505050506102e0604051908101604052806017905b60008152602001906001900390816100d15790505081905061008d565b60405180806020018281038252838181518152602001915080519060200190602002808383829060006004602084601f0104600f02600301f1509050019250505060405180910390f35b60405180826102e0808381846000600461015cf15090500191505060405180910390f3`,
+ `[{"constant":true,"inputs":[{"name":"input","type":"address[]"}],"name":"echoAddresses","outputs":[{"name":"output","type":"address[]"}],"type":"function"},{"constant":true,"inputs":[{"name":"input","type":"uint24[23]"}],"name":"echoFancyInts","outputs":[{"name":"output","type":"uint24[23]"}],"type":"function"},{"constant":true,"inputs":[{"name":"input","type":"int256[]"}],"name":"echoInts","outputs":[{"name":"output","type":"int256[]"}],"type":"function"},{"constant":true,"inputs":[{"name":"input","type":"bool[]"}],"name":"echoBools","outputs":[{"name":"output","type":"bool[]"}],"type":"function"}]`,
+ `
+ // Generate a new random account and a funded simulator
+ key := crypto.NewKey(rand.Reader)
+ sim := backends.NewSimulatedBackend(core.GenesisAccount{Address: key.Address, Balance: big.NewInt(10000000000)})
+
+ // Convert the tester key to an authorized transactor for ease of use
+ auth := bind.NewKeyedTransactor(key)
+
+ // Deploy a slice tester contract and execute a n array call on it
+ _, _, slicer, err := DeploySlicer(auth, sim)
+ if err != nil {
+ t.Fatalf("Failed to deploy slicer contract: %v", err)
+ }
+ sim.Commit()
+
+ if out, err := slicer.EchoAddresses(nil, []common.Address{key.Address, common.Address{}}); err != nil {
+ t.Fatalf("Failed to call slice echoer: %v", err)
+ } else if !reflect.DeepEqual(out, []common.Address{key.Address, common.Address{}}) {
+ t.Fatalf("Slice return mismatch: have %v, want %v", out, []common.Address{key.Address, common.Address{}})
+ }
+ `,
+ },
// Tests that anonymous default methods can be correctly invoked
{
`Defaulter`,