diff --git a/packages/caliper-application/benchmark/simple/open.js b/packages/caliper-application/benchmark/simple/open.js index b296c7a73..9bbda5c7f 100644 --- a/packages/caliper-application/benchmark/simple/open.js +++ b/packages/caliper-application/benchmark/simple/open.js @@ -72,6 +72,11 @@ function generateWorkload() { chaincodeFunction: 'open', chaincodeArguments: [acc_id, initMoney.toString()], }); + } else if (bc.bcType === 'ethereum') { + workload.push({ + verb: 'open', + args: [acc_id, initMoney] + }); } else { workload.push({ 'verb': 'open', diff --git a/packages/caliper-ethereum/lib/ethereum.js b/packages/caliper-ethereum/lib/ethereum.js index 9bd3b2f8c..163c48e30 100644 --- a/packages/caliper-ethereum/lib/ethereum.js +++ b/packages/caliper-ethereum/lib/ethereum.js @@ -1,9 +1,17 @@ /** - * Copyright 2017 HUAWEI. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * SPDX-License-Identifier: Apache-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * @file, definition of the Burrow class, which implements the Caliper's NBI for Hyperledger Burrow. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @file, definition of the Ethereum class, which implements the Caliper's NBI for Ethereum Web3 interface. */ 'use strict'; @@ -14,13 +22,13 @@ const {BlockchainInterface, CaliperUtils, TxStatus} = require('caliper-core'); const logger = CaliperUtils.getLogger('ethereum.js'); /** - * Implements {BlockchainInterface} for a Geth backend. + * Implements {BlockchainInterface} for a web3 Ethereum backend. */ class Ethereum extends BlockchainInterface { /** - * Create a new instance of the {Burrow} class. - * @param {string} config_path The path of the Burrow network configuration file. + * Create a new instance of the {Ethereum} class. + * @param {string} config_path The path of the network configuration file. * @param {string} workspace_root The absolute path to the root location for the application configuration files. */ constructor(config_path, workspace_root) { @@ -43,17 +51,20 @@ class Ethereum extends BlockchainInterface { } /** - * Deploy the smart contracts specified in the network configuration file. + * Deploy smart contracts specified in the network configuration file. * @return {object} Promise execution for all the contract creations. */ async installSmartContract() { let promises = []; let self = this; + logger.info("Creating contracts...") 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 promises.push(new Promise(function(resolve, reject) { self.deployContract(contractData).then((contractInstance) => { + logger.info("Deployed contract " + contractData.name + " at " + contractInstance.options.address); self.bindContract(key, contractInstance.address).then((receipt) => { + logger.info("Registered contract " + contractData.name); resolve() }) }) @@ -84,8 +95,8 @@ class Ethereum extends BlockchainInterface { } /** - * Release the given Burrow context. - * @param {object} context The Burrow context to release. + * Release the given Ethereum context. + * @param {object} context The Ethereum context to release. * @async */ async releaseContext(context) { @@ -97,14 +108,14 @@ class Ethereum extends BlockchainInterface { * @param {Object} context Context object. * @param {String} contractID Identity of the contract. * @param {String} contractVer Version of the contract. - * @param {Array} args Array of JSON formatted arguments for multiple transactions. + * @param {Array} invokeData Array of methods calls. * @param {Number} timeout Request timeout, in seconds. * @return {Promise} The promise for the result of the execution. */ - async invokeSmartContract(context, contractID, contractVer, args, timeout) { + async invokeSmartContract(context, contractID, contractVer, invokeData, timeout) { let promises = []; - args.forEach((item, index) => { - promises.push(this.sendTransaction(context, contractID, contractVer, item, 100)); + invokeData.forEach((item, index) => { + promises.push(this.sendTransaction(context, contractID, contractVer, item, timeout)); }); return Promise.all(promises); } @@ -114,17 +125,15 @@ class Ethereum extends BlockchainInterface { * @param {Object} context Context object. * @param {String} contractID Identity of the contract. * @param {String} contractVer Version of the contract. - * @param {Array} args Array of JSON formatted arguments for multiple transactions. + * @param {Object} methodCall Array of JSON containing methods data. * @param {Number} timeout Request timeout, in seconds. * @return {Promise} Result and stats of the transaction invocation. */ - async sendTransaction(context, contractID, contractVer, args, timeout) { - let verb = args.verb; - delete args.verb + async sendTransaction(context, contractID, contractVer, methodCall, timeout) { let status = new TxStatus(); try { context.engine.submitCallback(1); - let receipt = await context.contracts[contractID].methods[verb](...Object.values(args)).send({from: context.fromAddress}); + let receipt = await context.contracts[contractID].methods[methodCall.verb](...methodCall.args).send({from: context.fromAddress}); status.SetID(receipt.transactionHash); status.SetResult(receipt); status.SetVerification(true); @@ -155,7 +164,7 @@ class Ethereum extends BlockchainInterface { try { let receipt = await context.contracts[contractID].methods[fcn](key).call(); - status.SetID(receipt.transactionHash); + status.SetID(null); status.SetResult(receipt); status.SetVerification(true); status.SetStatusSuccess(); @@ -166,15 +175,6 @@ class Ethereum extends BlockchainInterface { return Promise.resolve(status); } - /** - * Get adapter specific transaction statistics. - * @param {JSON} stats txStatistics object - * @param {Array} results array of txStatus objects. - */ - getDefaultTxStats(stats, results) { - // empty - } - /** * Fetch the address for the contract with the given label from the registry * @param {string} contract_id @@ -195,7 +195,7 @@ class Ethereum extends BlockchainInterface { /** * Deploys a new contract using the given web3 instance - * @param {JSON} contractData Contract data with abi and bytecode properties + * @param {JSON} contractData Contract data with abi, bytecode and gas properties * @returns {Promise} The deployed contract instance */ deployContract(contractData) { @@ -212,7 +212,6 @@ class Ethereum extends BlockchainInterface { }).on('error', (error) => { reject(error) }).then((newContractInstance) => { - logger.info("Deployed contract " + contractData.name + " at " + newContractInstance.options.address); resolve(newContractInstance) }); }); diff --git a/packages/caliper-ethereum/lib/ethereumClientFactory.js b/packages/caliper-ethereum/lib/ethereumClientFactory.js index 30329f59a..7f5197b1d 100644 --- a/packages/caliper-ethereum/lib/ethereumClientFactory.js +++ b/packages/caliper-ethereum/lib/ethereumClientFactory.js @@ -1,6 +1,15 @@ /** + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * SPDX-License-Identifier: Apache-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * * @file, definition of the Ethereum client factory */ diff --git a/packages/caliper-ethereum/lib/ethereumClientWorker.js b/packages/caliper-ethereum/lib/ethereumClientWorker.js index f1a49412f..4e50d2188 100644 --- a/packages/caliper-ethereum/lib/ethereumClientWorker.js +++ b/packages/caliper-ethereum/lib/ethereumClientWorker.js @@ -1,6 +1,15 @@ /** + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * SPDX-License-Identifier: Apache-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * * @file, definition of the Ethereum client worker */