From 600d6863420d390e01d6c8e910506db939a7a757 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 6 Aug 2018 15:16:58 -0400 Subject: [PATCH] requests instead of contract object directly --- lib/contracts/contracts.js | 4 +++ lib/tests/test.js | 51 ++++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/lib/contracts/contracts.js b/lib/contracts/contracts.js index a9876a9c7..537088b79 100644 --- a/lib/contracts/contracts.js +++ b/lib/contracts/contracts.js @@ -24,6 +24,10 @@ class ContractsManager { cb(self.compileError, self.listContracts()); }); + self.events.setCommandHandler('contracts:all', (cb) => { + cb(self.compileError, self.contracts); + }); + self.events.setCommandHandler('contracts:dependencies', (cb) => { cb(self.compileError, self.contractDependencies); }); diff --git a/lib/tests/test.js b/lib/tests/test.js index ee1fb5216..bf2e8c00c 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -240,7 +240,7 @@ class Test { return next(); } console.info('Compiling contracts'.cyan); - self.engine.contractsManager.build(() => { + self.engine.events.request("contracts:build", false, (err) => { self.builtContracts = cloneDeep(self.engine.contractsManager.contracts); let className; for (className in self.builtContracts) { @@ -311,32 +311,35 @@ class Test { }); }, function createContractObject(accounts, next) { - async.each(Object.keys(self.engine.contractsManager.contracts), (contractName, eachCb) => { - const contract = self.engine.contractsManager.contracts[contractName]; - if (!self.contracts[contractName]) { - self.contracts[contractName] = {}; - } + self.engine.events.request('contracts:all', (err, contracts) => { - let newContract = new EmbarkJS.Contract({ - abi: contract.abiDefinition, - address: contract.deployedAddress, - from: self.web3.eth.defaultAccount, - gas: 6000000, - web3: self.web3 + async.each(contracts, (contract, eachCb) => { + if (!self.contracts[contract.className]) { + self.contracts[contract.className] = {}; + } + + let newContract = new EmbarkJS.Contract({ + abi: contract.abiDefinition, + address: contract.deployedAddress, + from: self.web3.eth.defaultAccount, + gas: 6000000, + web3: self.web3 + }); + + if (newContract.options) { + newContract.options.from = self.web3.eth.defaultAccount; + newContract.options.data = contract.code; + newContract.options.gas = 6000000; + } + + Object.setPrototypeOf(self.contracts[contract.className], newContract); + Object.assign(self.contracts[contract.className], newContract); + + eachCb(); + }, (err) => { + next(err, accounts); }); - if (newContract.options) { - newContract.options.from = self.web3.eth.defaultAccount; - newContract.options.data = contract.code; - newContract.options.gas = 6000000; - } - - Object.setPrototypeOf(self.contracts[contractName], newContract); - Object.assign(self.contracts[contractName], newContract); - - eachCb(); - }, (err) => { - next(err, accounts); }); } ], function (err, accounts) {