aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi/bind/bind_test.go
diff options
context:
space:
mode:
authorbas-vk <bas-vk@users.noreply.github.com>2017-03-16 19:24:22 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-03-16 19:24:22 +0800
commit6d038e762b2ff5785d6884f09f869c45964647aa (patch)
treeb7e71d4270a55bbe8d9552a0b67b37c008980fea /accounts/abi/bind/bind_test.go
parent4e4e5fca541ae2c2c0bf5cde0b556fedfafa8d54 (diff)
downloaddexon-6d038e762b2ff5785d6884f09f869c45964647aa.tar
dexon-6d038e762b2ff5785d6884f09f869c45964647aa.tar.gz
dexon-6d038e762b2ff5785d6884f09f869c45964647aa.tar.bz2
dexon-6d038e762b2ff5785d6884f09f869c45964647aa.tar.lz
dexon-6d038e762b2ff5785d6884f09f869c45964647aa.tar.xz
dexon-6d038e762b2ff5785d6884f09f869c45964647aa.tar.zst
dexon-6d038e762b2ff5785d6884f09f869c45964647aa.zip
accounts/abi/bind: allow client to specify sender address for call (#3782)
Diffstat (limited to 'accounts/abi/bind/bind_test.go')
-rw-r--r--accounts/abi/bind/bind_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/accounts/abi/bind/bind_test.go b/accounts/abi/bind/bind_test.go
index eb46bc081..8ac4aa44e 100644
--- a/accounts/abi/bind/bind_test.go
+++ b/accounts/abi/bind/bind_test.go
@@ -408,6 +408,45 @@ var bindTests = []struct {
}
`,
},
+ // Test that constant functions can be called from an (optional) specified address
+ {
+ `CallFrom`,
+ `
+ contract CallFrom {
+ function callFrom() constant returns(address) {
+ return msg.sender;
+ }
+ }
+ `, `6060604052346000575b6086806100176000396000f300606060405263ffffffff60e060020a60003504166349f8e98281146022575b6000565b34600057602c6055565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b335b905600a165627a7a72305820aef6b7685c0fa24ba6027e4870404a57df701473fe4107741805c19f5138417c0029`,
+ `[{"constant":true,"inputs":[],"name":"callFrom","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"}]`,
+ `
+ // Generate a new random account and a funded simulator
+ key, _ := crypto.GenerateKey()
+ auth := bind.NewKeyedTransactor(key)
+ sim := backends.NewSimulatedBackend(core.GenesisAccount{Address: auth.From, Balance: big.NewInt(10000000000)})
+
+ // Deploy a sender tester contract and execute a structured call on it
+ _, _, callfrom, err := DeployCallFrom(auth, sim)
+ if err != nil {
+ t.Fatalf("Failed to deploy sender contract: %v", err)
+ }
+ sim.Commit()
+
+ if res, err := callfrom.CallFrom(nil); err != nil {
+ t.Errorf("Failed to call constant function: %v", err)
+ } else if res != (common.Address{}) {
+ t.Errorf("Invalid address returned, want: %x, got: %x", (common.Address{}), res)
+ }
+
+ for _, addr := range []common.Address{common.Address{}, common.Address{1}, common.Address{2}} {
+ if res, err := callfrom.CallFrom(&bind.CallOpts{From: addr}); err != nil {
+ t.Fatalf("Failed to call constant function: %v", err)
+ } else if res != addr {
+ t.Fatalf("Invalid address returned, want: %x, got: %x", addr, res)
+ }
+ }
+ `,
+ },
}
// Tests that packages generated by the binder can be successfully compiled and