diff --git a/packages/caliper-ethereum/lib/ethereum.js b/packages/caliper-ethereum/lib/ethereum.js index 44732d3f7..f547b38fe 100644 --- a/packages/caliper-ethereum/lib/ethereum.js +++ b/packages/caliper-ethereum/lib/ethereum.js @@ -68,12 +68,14 @@ class Ethereum extends BlockchainInterface { for (const key of Object.keys(this.ethereumConfig.contracts)) { let contractData = require(CaliperUtils.resolvePath(this.ethereumConfig.contracts[key].path, this.workspaceRoot)); // TODO remove path property let contractGas = this.ethereumConfig.contracts[key].gas; + let estimateGas = this.ethereumConfig.contracts[key].estimateGas; this.ethereumConfig.contracts[key].abi = contractData.abi; promises.push(new Promise(async function(resolve, reject) { let contractInstance = await self.deployContract(contractData); logger.info('Deployed contract ' + contractData.name + ' at ' + contractInstance.options.address); self.ethereumConfig.contracts[key].address = contractInstance.options.address; self.ethereumConfig.contracts[key].gas = contractGas; + self.ethereumConfig.contracts[key].estimateGas = estimateGas; resolve(contractInstance); })); } @@ -99,11 +101,12 @@ class Ethereum extends BlockchainInterface { for (const key of Object.keys(args.contracts)) { context.contracts[key] = { contract: new this.web3.eth.Contract(args.contracts[key].abi, args.contracts[key].address), - gas: args.contracts[key].gas + gas: args.contracts[key].gas, + estimateGas: args.contracts[key].estimateGas }; } - context.nonces[this.ethereumConfig.fromAddress] = await this.web3.eth.getTransactionCount(this.ethereumConfig.fromAddress); if (this.ethereumConfig.fromAddressPrivateKey) { + context.nonces[this.ethereumConfig.fromAddress] = await this.web3.eth.getTransactionCount(this.ethereumConfig.fromAddress); this.web3.eth.accounts.wallet.add(this.ethereumConfig.fromAddressPrivateKey); } else if (this.ethereumConfig.fromAddressPassword) { await context.web3.eth.personal.unlockAccount(this.ethereumConfig.fromAddress, this.ethereumConfig.fromAddressPassword, 1000); @@ -186,7 +189,7 @@ class Ethereum extends BlockchainInterface { let methodType = 'send'; if (methodCall.isView) { methodType = 'call'; - } else { + } else if (context.nonces && context.nonces[context.fromAddress]) { let nonce = context.nonces[context.fromAddress]; context.nonces[context.fromAddress] = nonce + 1; params.nonce = nonce; @@ -194,14 +197,14 @@ class Ethereum extends BlockchainInterface { if (methodCall.args) { if (contractInfo.gas && contractInfo.gas[methodCall.verb]) { params.gas = contractInfo.gas[methodCall.verb]; - } else { + } else if (contractInfo.estimateGas) { params.gas = 1000 + await contractInfo.contract.methods[methodCall.verb](...methodCall.args).estimateGas(); } receipt = await contractInfo.contract.methods[methodCall.verb](...methodCall.args)[methodType](params); } else { if (contractInfo.gas && contractInfo.gas[methodCall.verb]) { params.gas = contractInfo.gas[methodCall.verb]; - } else { + } else if (contractInfo.estimateGas) { params.gas = 1000 + await contractInfo.contract.methods[methodCall.verb].estimateGas(params); } receipt = await contractInfo.contract.methods[methodCall.verb]()[methodType](params); diff --git a/packages/caliper-samples/network/besu/1node-clique/ethereum.json b/packages/caliper-samples/network/besu/1node-clique/ethereum.json index 944418c2d..f521fae94 100644 --- a/packages/caliper-samples/network/besu/1node-clique/ethereum.json +++ b/packages/caliper-samples/network/besu/1node-clique/ethereum.json @@ -19,7 +19,7 @@ "gas": { "open": 45000, "query": 100000, - "transfer": 36000 + "transfer": 70000 } } } diff --git a/packages/caliper-tests-integration/besu_tests/networkconfig.json b/packages/caliper-tests-integration/besu_tests/networkconfig.json index 96b61cd75..b7b6497c6 100644 --- a/packages/caliper-tests-integration/besu_tests/networkconfig.json +++ b/packages/caliper-tests-integration/besu_tests/networkconfig.json @@ -2,7 +2,7 @@ "caliper": { "blockchain": "ethereum", "command" : { - "start": "docker-compose -f config/docker-compose.yml up -d && sleep 10", + "start": "docker-compose -f config/docker-compose.yml up -d && sleep 15", "end" : "docker-compose -f config/docker-compose.yml down" } }, @@ -16,10 +16,9 @@ "contracts": { "simple": { "path": "src/simple/simple.json", + "estimateGas": true, "gas": { - "open": 45000, - "query": 100000, - "transfer": 36000 + "transfer": 70000 } } }