|
|
|
@ -1448,6 +1448,88 @@ var bindTests = []struct { |
|
|
|
|
map[string]string{"_myVar": "pubVar"}, // alias MyVar to PubVar
|
|
|
|
|
nil, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
"MultiContracts", |
|
|
|
|
` |
|
|
|
|
pragma solidity ^0.5.11; |
|
|
|
|
pragma experimental ABIEncoderV2; |
|
|
|
|
|
|
|
|
|
library ExternalLib { |
|
|
|
|
struct SharedStruct{ |
|
|
|
|
uint256 f1; |
|
|
|
|
bytes32 f2; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
contract ContractOne { |
|
|
|
|
function foo(ExternalLib.SharedStruct memory s) pure public { |
|
|
|
|
// Do stuff
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
contract ContractTwo { |
|
|
|
|
function bar(ExternalLib.SharedStruct memory s) pure public { |
|
|
|
|
// Do stuff
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
`, |
|
|
|
|
[]string{ |
|
|
|
|
`60806040523480156100115760006000fd5b50610017565b6101b5806100266000396000f3fe60806040523480156100115760006000fd5b50600436106100305760003560e01c80639d8a8ba81461003657610030565b60006000fd5b610050600480360361004b91908101906100d1565b610052565b005b5b5056610171565b6000813590506100698161013d565b92915050565b6000604082840312156100825760006000fd5b61008c60406100fb565b9050600061009c848285016100bc565b60008301525060206100b08482850161005a565b60208301525092915050565b6000813590506100cb81610157565b92915050565b6000604082840312156100e45760006000fd5b60006100f28482850161006f565b91505092915050565b6000604051905081810181811067ffffffffffffffff8211171561011f5760006000fd5b8060405250919050565b6000819050919050565b6000819050919050565b61014681610129565b811415156101545760006000fd5b50565b61016081610133565b8114151561016e5760006000fd5b50565bfea365627a7a72315820749274eb7f6c01010d5322af4e1668b0a154409eb7968bd6cae5524c7ed669bb6c6578706572696d656e74616cf564736f6c634300050c0040`, |
|
|
|
|
`60806040523480156100115760006000fd5b50610017565b6101b5806100266000396000f3fe60806040523480156100115760006000fd5b50600436106100305760003560e01c8063db8ba08c1461003657610030565b60006000fd5b610050600480360361004b91908101906100d1565b610052565b005b5b5056610171565b6000813590506100698161013d565b92915050565b6000604082840312156100825760006000fd5b61008c60406100fb565b9050600061009c848285016100bc565b60008301525060206100b08482850161005a565b60208301525092915050565b6000813590506100cb81610157565b92915050565b6000604082840312156100e45760006000fd5b60006100f28482850161006f565b91505092915050565b6000604051905081810181811067ffffffffffffffff8211171561011f5760006000fd5b8060405250919050565b6000819050919050565b6000819050919050565b61014681610129565b811415156101545760006000fd5b50565b61016081610133565b8114151561016e5760006000fd5b50565bfea365627a7a723158209bc28ee7ea97c131a13330d77ec73b4493b5c59c648352da81dd288b021192596c6578706572696d656e74616cf564736f6c634300050c0040`, |
|
|
|
|
`606c6026600b82828239805160001a6073141515601857fe5b30600052607381538281f350fe73000000000000000000000000000000000000000030146080604052600436106023575b60006000fdfea365627a7a72315820518f0110144f5b3de95697d05e456a064656890d08e6f9cff47f3be710cc46a36c6578706572696d656e74616cf564736f6c634300050c0040`, |
|
|
|
|
}, |
|
|
|
|
[]string{ |
|
|
|
|
`[{"constant":true,"inputs":[{"components":[{"internalType":"uint256","name":"f1","type":"uint256"},{"internalType":"bytes32","name":"f2","type":"bytes32"}],"internalType":"struct ExternalLib.SharedStruct","name":"s","type":"tuple"}],"name":"foo","outputs":[],"payable":false,"stateMutability":"pure","type":"function"}]`, |
|
|
|
|
`[{"constant":true,"inputs":[{"components":[{"internalType":"uint256","name":"f1","type":"uint256"},{"internalType":"bytes32","name":"f2","type":"bytes32"}],"internalType":"struct ExternalLib.SharedStruct","name":"s","type":"tuple"}],"name":"bar","outputs":[],"payable":false,"stateMutability":"pure","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/crypto" |
|
|
|
|
"github.com/ethereum/go-ethereum/core" |
|
|
|
|
`, |
|
|
|
|
` |
|
|
|
|
key, _ := crypto.GenerateKey() |
|
|
|
|
addr := crypto.PubkeyToAddress(key.PublicKey) |
|
|
|
|
|
|
|
|
|
// Deploy registrar contract
|
|
|
|
|
sim := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}, 10000000) |
|
|
|
|
defer sim.Close() |
|
|
|
|
|
|
|
|
|
transactOpts := bind.NewKeyedTransactor(key) |
|
|
|
|
_, _, c1, err := DeployContractOne(transactOpts, sim) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal("Failed to deploy contract") |
|
|
|
|
} |
|
|
|
|
sim.Commit() |
|
|
|
|
err = c1.Foo(nil, ExternalLibSharedStruct{ |
|
|
|
|
F1: big.NewInt(100), |
|
|
|
|
F2: [32]byte{0x01, 0x02, 0x03}, |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal("Failed to invoke function") |
|
|
|
|
} |
|
|
|
|
_, _, c2, err := DeployContractTwo(transactOpts, sim) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal("Failed to deploy contract") |
|
|
|
|
} |
|
|
|
|
sim.Commit() |
|
|
|
|
err = c2.Bar(nil, ExternalLibSharedStruct{ |
|
|
|
|
F1: big.NewInt(100), |
|
|
|
|
F2: [32]byte{0x01, 0x02, 0x03}, |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal("Failed to invoke function") |
|
|
|
|
} |
|
|
|
|
`, |
|
|
|
|
nil, |
|
|
|
|
nil, |
|
|
|
|
nil, |
|
|
|
|
[]string{"ContractOne", "ContractTwo", "ExternalLib"}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests that packages generated by the binder can be successfully compiled and
|
|
|
|
|