Merge pull request #680 from embark-framework/tests_remove_contracts_manager

remove contracts manager dependency from tests
This commit is contained in:
Iuri Matias 2018-08-07 09:54:10 -04:00 committed by GitHub
commit 904cef4b6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 39 deletions

View File

@ -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);
});
@ -39,6 +43,14 @@ class ContractsManager {
});
});
self.events.setCommandHandler("contracts:reset:dependencies", (cb) => {
for (let className in self.contracts) {
self.contracts[className].dependencyCount = null;
}
self.contractDependencies = {};
cb();
});
self.events.on("deploy:contract:error", (_contract) => {
self.events.emit('contractsState', self.contractsState());
});

View File

@ -4,7 +4,6 @@ const TestLogger = require('./test_logger.js');
const Web3 = require('web3');
const constants = require('../constants');
const Events = require('../core/events');
const cloneDeep = require('clone-deep');
const AccountParser = require('../utils/accountParser');
// TODO: breaks module isolation; tests need to be refactored to use the engine and avoid this
const Provider = require('../modules/blockchain_connector/provider.js');
@ -39,8 +38,7 @@ class Test {
this.firstRunConfig = true;
this.error = false;
this.contracts = {};
this.builtContracts = {};
this.compiledContracts = {};
this.firstDeployment = true;
this.logsSubscription = null;
this.needConfig = true;
this.web3 = new Web3();
@ -236,25 +234,17 @@ class Test {
self.checkDeploymentOptions(options, next);
},
function compileContracts(next) {
if (Object.keys(self.builtContracts).length > 0) {
if (!self.firstDeployment) {
return next();
}
console.info('Compiling contracts'.cyan);
self.engine.contractsManager.build(() => {
self.builtContracts = cloneDeep(self.engine.contractsManager.contracts);
let className;
for (className in self.builtContracts) {
self.builtContracts[className].dependencyCount = null;
}
self.compiledContracts = cloneDeep(self.engine.contractsManager.compiledContracts);
next();
self.engine.events.request("contracts:build", false, (err) => {
self.firstDeployment = false;
next(err);
});
},
function resetContracts(next) {
self.engine.contractsManager.contracts = cloneDeep(self.builtContracts);
self.engine.contractsManager.compiledContracts = cloneDeep(self.compiledContracts);
self.engine.contractsManager.contractDependencies = {};
next();
self.engine.events.request("contracts:reset:dependencies", next);
},
function deploy(next) {
self._deploy(options, (err, accounts) => {
@ -311,32 +301,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) {