mirror of https://github.com/embarklabs/embark.git
Merge pull request #680 from embark-framework/tests_remove_contracts_manager
remove contracts manager dependency from tests
This commit is contained in:
commit
904cef4b6b
|
@ -24,6 +24,10 @@ class ContractsManager {
|
||||||
cb(self.compileError, self.listContracts());
|
cb(self.compileError, self.listContracts());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.events.setCommandHandler('contracts:all', (cb) => {
|
||||||
|
cb(self.compileError, self.contracts);
|
||||||
|
});
|
||||||
|
|
||||||
self.events.setCommandHandler('contracts:dependencies', (cb) => {
|
self.events.setCommandHandler('contracts:dependencies', (cb) => {
|
||||||
cb(self.compileError, self.contractDependencies);
|
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.on("deploy:contract:error", (_contract) => {
|
||||||
self.events.emit('contractsState', self.contractsState());
|
self.events.emit('contractsState', self.contractsState());
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,7 +4,6 @@ const TestLogger = require('./test_logger.js');
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const constants = require('../constants');
|
const constants = require('../constants');
|
||||||
const Events = require('../core/events');
|
const Events = require('../core/events');
|
||||||
const cloneDeep = require('clone-deep');
|
|
||||||
const AccountParser = require('../utils/accountParser');
|
const AccountParser = require('../utils/accountParser');
|
||||||
// TODO: breaks module isolation; tests need to be refactored to use the engine and avoid this
|
// TODO: breaks module isolation; tests need to be refactored to use the engine and avoid this
|
||||||
const Provider = require('../modules/blockchain_connector/provider.js');
|
const Provider = require('../modules/blockchain_connector/provider.js');
|
||||||
|
@ -39,8 +38,7 @@ class Test {
|
||||||
this.firstRunConfig = true;
|
this.firstRunConfig = true;
|
||||||
this.error = false;
|
this.error = false;
|
||||||
this.contracts = {};
|
this.contracts = {};
|
||||||
this.builtContracts = {};
|
this.firstDeployment = true;
|
||||||
this.compiledContracts = {};
|
|
||||||
this.logsSubscription = null;
|
this.logsSubscription = null;
|
||||||
this.needConfig = true;
|
this.needConfig = true;
|
||||||
this.web3 = new Web3();
|
this.web3 = new Web3();
|
||||||
|
@ -236,25 +234,17 @@ class Test {
|
||||||
self.checkDeploymentOptions(options, next);
|
self.checkDeploymentOptions(options, next);
|
||||||
},
|
},
|
||||||
function compileContracts(next) {
|
function compileContracts(next) {
|
||||||
if (Object.keys(self.builtContracts).length > 0) {
|
if (!self.firstDeployment) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
console.info('Compiling contracts'.cyan);
|
console.info('Compiling contracts'.cyan);
|
||||||
self.engine.contractsManager.build(() => {
|
self.engine.events.request("contracts:build", false, (err) => {
|
||||||
self.builtContracts = cloneDeep(self.engine.contractsManager.contracts);
|
self.firstDeployment = false;
|
||||||
let className;
|
next(err);
|
||||||
for (className in self.builtContracts) {
|
|
||||||
self.builtContracts[className].dependencyCount = null;
|
|
||||||
}
|
|
||||||
self.compiledContracts = cloneDeep(self.engine.contractsManager.compiledContracts);
|
|
||||||
next();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function resetContracts(next) {
|
function resetContracts(next) {
|
||||||
self.engine.contractsManager.contracts = cloneDeep(self.builtContracts);
|
self.engine.events.request("contracts:reset:dependencies", next);
|
||||||
self.engine.contractsManager.compiledContracts = cloneDeep(self.compiledContracts);
|
|
||||||
self.engine.contractsManager.contractDependencies = {};
|
|
||||||
next();
|
|
||||||
},
|
},
|
||||||
function deploy(next) {
|
function deploy(next) {
|
||||||
self._deploy(options, (err, accounts) => {
|
self._deploy(options, (err, accounts) => {
|
||||||
|
@ -311,32 +301,35 @@ class Test {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function createContractObject(accounts, next) {
|
function createContractObject(accounts, next) {
|
||||||
async.each(Object.keys(self.engine.contractsManager.contracts), (contractName, eachCb) => {
|
self.engine.events.request('contracts:all', (err, contracts) => {
|
||||||
const contract = self.engine.contractsManager.contracts[contractName];
|
|
||||||
if (!self.contracts[contractName]) {
|
|
||||||
self.contracts[contractName] = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
let newContract = new EmbarkJS.Contract({
|
async.each(contracts, (contract, eachCb) => {
|
||||||
abi: contract.abiDefinition,
|
if (!self.contracts[contract.className]) {
|
||||||
address: contract.deployedAddress,
|
self.contracts[contract.className] = {};
|
||||||
from: self.web3.eth.defaultAccount,
|
}
|
||||||
gas: 6000000,
|
|
||||||
web3: self.web3
|
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) {
|
], function (err, accounts) {
|
||||||
|
|
Loading…
Reference in New Issue