Skip to content

Commit

Permalink
Removes registry contract and adds ethereum to tests
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Russo <[email protected]>
  • Loading branch information
russanto committed Oct 2, 2019
1 parent 09ffc60 commit 90dd29c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .travis/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ if [[ "${BENCHMARK}" == "composer" ]]; then
npx caliper bind --caliper-bind-sut composer
elif [[ "${BENCHMARK}" == "fabric" ]]; then
npx caliper bind --caliper-bind-sut fabric
elif [[ "${BENCHMARK}" == "ethereum" ]]; then
npx caliper bind --caliper-bind-sut ethereum
else
echo "Unknown target benchmark ${BENCHMARK}"
npm run cleanup
Expand Down
49 changes: 19 additions & 30 deletions packages/caliper-ethereum/lib/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ class Ethereum extends BlockchainInterface {
this.bcType = 'ethereum';
this.workspaceRoot = workspace_root;
this.ethereumConfig = require(config_path).ethereum;
let registryData = require(CaliperUtils.resolvePath(this.ethereumConfig.registry.path, workspace_root));
this.web3 = new Web3(this.ethereumConfig.url);
this.web3.transactionConfirmationBlocks = this.ethereumConfig.transactionConfirmationBlocks;
this.registry = new this.web3.eth.Contract(registryData.abi, this.ethereumConfig.registry.address);
}

/**
Expand All @@ -59,13 +57,12 @@ class Ethereum extends BlockchainInterface {
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
this.ethereumConfig.contracts[key].abi = contractData.abi;
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.options.address).then((receipt) => {
logger.info('Registered contract ' + contractData.name);
resolve();
});
self.ethereumConfig.contracts[key].address = contractInstance.options.address;
resolve(contractInstance);
});
}));
}
Expand All @@ -83,12 +80,10 @@ class Ethereum extends BlockchainInterface {
let context = {fromAddress: this.ethereumConfig.fromAddress};
context.web3 = this.web3;
context.contracts = {};
await context.web3.eth.personal.unlockAccount(this.ethereumConfig.fromAddress, this.ethereumConfig.fromAddressPassword, 1000);
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 contractAddress = await this.lookupContract(key);
context.contracts[key] = new context.web3.eth.Contract(contractData.abi, contractAddress);
for (const key of Object.keys(args.contracts)) {
context.contracts[key] = new this.web3.eth.Contract(args.contracts[key].abi, args.contracts[key].address);
}
await context.web3.eth.personal.unlockAccount(this.ethereumConfig.fromAddress, this.ethereumConfig.fromAddressPassword, 1000);
return context;
}

Expand Down Expand Up @@ -177,25 +172,6 @@ class Ethereum extends BlockchainInterface {
return Promise.resolve(status);
}

/**
* Fetch the address for the contract with the given label from the registry
* @param {string} contract_id id to search for
* @return {string} The contract address
*/
lookupContract(contract_id) {
return this.registry.methods.lookup(contract_id).call();
}

/**
* Binds the address to the label registering on the registry
* @param {string} contract_id contract_id to bind address to
* @param {string} address deployed contract address
* @returns {Promise<PromiEvent>} PromiEvent is a web3js type. Refer to web3js doc.
*/
bindContract(contract_id, address) {
return this.registry.methods.bind(contract_id, address).send({from: this.ethereumConfig.contractDeployerAddress});
}

/**
* Deploys a new contract using the given web3 instance
* @param {JSON} contractData Contract data with abi, bytecode and gas properties
Expand All @@ -219,6 +195,19 @@ class Ethereum extends BlockchainInterface {
});
});
}

/**
* It passes deployed contracts addresses to all clients
* @param {Number} number of clients to prepare
* @returns {Array} client args
*/
async prepareClients(number) {
let result = [];
for (let i = 0 ; i< number ; i++) {
result[i] = {contracts: this.ethereumConfig.contracts};
}
return result;
}
}

module.exports = Ethereum;
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
"fromAddress": "0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2",
"fromAddressPassword": "password",
"transactionConfirmationBlocks": 2,
"registry": {
"address": "0x91496eafe3C54C48D1Add5c1Fb30655d6b76e56b",
"path": "src/contract/ethereum/registry/registry.json"
},
"contracts": {
"simple": {
"path": "src/contract/ethereum/simple/simple.json"
Expand Down
4 changes: 0 additions & 4 deletions packages/caliper-samples/network/ethereum/1node/ethereum.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
"fromAddress": "0xc0A8e4D217eB85b812aeb1226fAb6F588943C2C2",
"fromAddressPassword": "password",
"transactionConfirmationBlocks": 2,
"registry": {
"address": "0xB1B0e1Fd4c456146A808fDF668aCC2FaF16Ee2ab",
"path": "src/contract/ethereum/registry/registry.json"
},
"contracts": {
"simple": {
"path": "src/contract/ethereum/simple/simple.json"
Expand Down

This file was deleted.

This file was deleted.

4 changes: 4 additions & 0 deletions packages/caliper-tests-integration/scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ elif [[ "${BENCHMARK}" == "fabric" ]]; then
rc=$?
exit $rc;
fi
elif [[ "${BENCHMARK}" == "ethereum" ]]; then
${CALL_METHOD} benchmark run --caliper-benchconfig benchmark/simple/config-ethereum.yaml --caliper-networkconfig network/ethereum/1node-clique/ethereum.json --caliper-workspace ../caliper-samples/
rc=$?
exit $rc;
else
echo "Unknown target benchmark ${BENCHMARK}"
exit 1
Expand Down

0 comments on commit 90dd29c

Please sign in to comment.