move contracts manager to its own module

This commit is contained in:
Iuri Matias 2018-08-07 18:44:48 -04:00
parent 16aae66756
commit 53d944e801
3 changed files with 26 additions and 40 deletions

View File

@ -168,18 +168,7 @@ class Engine {
this.registerModule('deploytracker');
this.registerModule('specialconfigs');
this.registerModule('console_listener', {ipc: this.ipc});
// TODO: need to refactor dependencies before moving into a module
const ContractsManager = require('../contracts/contracts.js');
this.contractsManager = new ContractsManager({
contractFiles: this.config.contractsFiles,
contractsConfig: this.config.contractsConfig,
logger: this.logger,
plugins: this.plugins,
gasLimit: false,
events: this.events
});
this.registerModule('contracts');
this.registerModule('deployment', {plugins: this.plugins, onlyCompile: options.onlyCompile});
this.events.on('file-event', function (fileType) {

View File

@ -2,22 +2,19 @@ let toposort = require('toposort');
let async = require('async');
const cloneDeep = require('clone-deep');
let utils = require('../utils/utils.js');
let utils = require('../../utils/utils.js');
// TODO: create a contract object
class ContractsManager {
constructor(options) {
constructor(embark) {
const self = this;
this.contractFiles = options.contractFiles;
this.contractsConfig = cloneDeep(options.contractsConfig || {});
this.logger = embark.logger;
this.events = embark.events;
this.contracts = {};
this.logger = options.logger;
this.plugins = options.plugins;
this.contractDependencies = {};
this.gasLimit = options.gasLimit;
this.deployOnlyOnConfig = false;
this.events = options.events;
this.compileError = false;
self.events.setCommandHandler('contracts:list', (cb) => {
@ -87,7 +84,7 @@ class ContractsManager {
// Only compile once for tests
return callback();
}
self.events.request("compiler:contracts", self.contractFiles, function (err, compiledObject) {
self.events.request("compiler:contracts", self.contractsFiles, function (err, compiledObject) {
self.compiledContracts = compiledObject;
callback(err);
});

View File

@ -1,5 +1,5 @@
/*globals describe, it*/
let ContractsManager = require('../lib/contracts/contracts.js');
let ContractsManager = require('../lib/modules/contracts/index.js');
let Compiler = require('../lib/modules/compiler/');
let Logger = require('../lib/core/logger.js');
let File = require('../lib/core/file.js');
@ -45,7 +45,10 @@ describe('embark.Contracts', function() {
});
events.setCommandHandler("config:contractsFiles", (cb) => {
cb([]);
cb([
readFile('test/contracts/simple_storage.sol'),
readFile('test/contracts/token.sol')
]);
});
events.setCommandHandler("blockchain:gasPrice", (cb) => {
@ -81,16 +84,13 @@ describe('embark.Contracts', function() {
}
};
let contractsManager = new ContractsManager({
plugins: plugins,
contractFiles: [
readFile('test/contracts/simple_storage.sol'),
readFile('test/contracts/token.sol')
],
contractDirectories: ['app/contracts'],
contractsConfig: contractsConfig,
let embarkObj = {
logger: new Logger({}),
events: events
};
let contractsManager = new ContractsManager(embarkObj, {
contractDirectories: ['app/contracts']
});
describe('#build', function() {
@ -151,7 +151,10 @@ describe('embark.Contracts', function() {
});
events.setCommandHandler("config:contractsFiles", (cb) => {
cb([]);
cb([
readFile('test/contracts/simple_storage.sol'),
readFile('test/contracts/token_storage.sol')
]);
});
events.setCommandHandler("blockchain:gasPrice", (cb) => {
@ -197,16 +200,13 @@ describe('embark.Contracts', function() {
}
}
let contractsManager = new ContractsManager({
plugins: plugins,
contractFiles: [
readFile('test/contracts/simple_storage.sol'),
readFile('test/contracts/token_storage.sol')
],
contractDirectories: ['app/contracts'],
contractsConfig: contractsConfig,
let embarkObj = {
logger: new Logger({}),
events: events
}
let contractsManager = new ContractsManager(embarkObj, {
contractDirectories: ['app/contracts']
});
describe('#build', function() {