diff --git a/lib/core/engine.js b/lib/core/engine.js index 571b24889..2b4f6d8f4 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -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) { diff --git a/lib/contracts/contracts.js b/lib/modules/contracts/index.js similarity index 97% rename from lib/contracts/contracts.js rename to lib/modules/contracts/index.js index 266060138..daeee3fc3 100644 --- a/lib/contracts/contracts.js +++ b/lib/modules/contracts/index.js @@ -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); }); diff --git a/test/contracts.js b/test/contracts.js index b5215544f..a46dfa837 100644 --- a/test/contracts.js +++ b/test/contracts.js @@ -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() {