@@ -1530,6 +1530,61 @@ var bindTests = []struct {
15301530 nil ,
15311531 []string {"ContractOne" , "ContractTwo" , "ExternalLib" },
15321532 },
1533+ // Test the existence of the free retrieval calls
1534+ {
1535+ `PureAndView` ,
1536+ `pragma solidity >=0.6.0;
1537+ contract PureAndView {
1538+ function PureFunc() public pure returns (uint) {
1539+ return 42;
1540+ }
1541+ function ViewFunc() public view returns (uint) {
1542+ return block.number;
1543+ }
1544+ }
1545+ ` ,
1546+ []string {`608060405234801561001057600080fd5b5060b68061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806376b5686a146037578063bb38c66c146053575b600080fd5b603d606f565b6040518082815260200191505060405180910390f35b60596077565b6040518082815260200191505060405180910390f35b600043905090565b6000602a90509056fea2646970667358221220d158c2ab7fdfce366a7998ec79ab84edd43b9815630bbaede2c760ea77f29f7f64736f6c63430006000033` },
1547+ []string {`[{"inputs": [],"name": "PureFunc","outputs": [{"internalType": "uint256","name": "","type": "uint256"}],"stateMutability": "pure","type": "function"},{"inputs": [],"name": "ViewFunc","outputs": [{"internalType": "uint256","name": "","type": "uint256"}],"stateMutability": "view","type": "function"}]` },
1548+ `
1549+ "math/big"
1550+
1551+ "github.com/ethereum/go-ethereum/accounts/abi/bind"
1552+ "github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
1553+ "github.com/ethereum/go-ethereum/core"
1554+ "github.com/ethereum/go-ethereum/crypto"
1555+ ` ,
1556+ `
1557+ // Generate a new random account and a funded simulator
1558+ key, _ := crypto.GenerateKey()
1559+ auth := bind.NewKeyedTransactor(key)
1560+
1561+ sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
1562+ defer sim.Close()
1563+
1564+ // Deploy a tester contract and execute a structured call on it
1565+ _, _, pav, err := DeployPureAndView(auth, sim)
1566+ if err != nil {
1567+ t.Fatalf("Failed to deploy PureAndView contract: %v", err)
1568+ }
1569+ sim.Commit()
1570+
1571+ // This test the existence of the free retreiver call for view and pure functions
1572+ if num, err := pav.PureFunc(nil); err != nil {
1573+ t.Fatalf("Failed to call anonymous field retriever: %v", err)
1574+ } else if num.Cmp(big.NewInt(42)) != 0 {
1575+ t.Fatalf("Retrieved value mismatch: have %v, want %v", num, 42)
1576+ }
1577+ if num, err := pav.ViewFunc(nil); err != nil {
1578+ t.Fatalf("Failed to call anonymous field retriever: %v", err)
1579+ } else if num.Cmp(big.NewInt(1)) != 0 {
1580+ t.Fatalf("Retrieved value mismatch: have %v, want %v", num, 1)
1581+ }
1582+ ` ,
1583+ nil ,
1584+ nil ,
1585+ nil ,
1586+ nil ,
1587+ },
15331588}
15341589
15351590// Tests that packages generated by the binder can be successfully compiled and
0 commit comments