diff --git a/lib/contracts/blockchain.js b/lib/contracts/blockchain.js index 3b647b32..bffb3baa 100644 --- a/lib/contracts/blockchain.js +++ b/lib/contracts/blockchain.js @@ -251,6 +251,9 @@ class Blockchain { next(); }, function pingEndpoint(next) { + if (!self.contractsConfig || !self.contractsConfig.deployment || !self.contractsConfig.deployment.host) { + return next(); + } const origin = self.blockchainConfig.wsOrigins.split(',')[0]; const options = { protocolVersion: 13, diff --git a/lib/tests/test.js b/lib/tests/test.js index 43be482e..2e29be3e 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -44,12 +44,15 @@ class Test { initWeb3Provider(callback) { if (this.simOptions.host) { + const protocol = (this.simOptions.type === "rpc") ? 'http' : 'ws'; const providerOptions = { web3: this.web3, + type: this.simOptions.type, accountsConfig: this.simOptions.accounts, + blockchainConfig: this.engine.config.blockchainConfig, logger: this.engine.logger, isDev: false, - web3Endpoint: 'http://' + this.simOptions.host + ':' + this.simOptions.port + web3Endpoint: `${protocol}://${this.simOptions.host}:${this.simOptions.port}` }; this.provider = new Provider(providerOptions); return this.provider.startWeb3Provider(callback); @@ -78,16 +81,17 @@ class Test { init(callback) { const self = this; + this.engine = new Engine({ + env: this.options.env || 'test', + // TODO: config will need to detect if this is a obj + embarkConfig: this.options.embarkConfig || 'embark.json', + interceptLogs: false + }); + this.initWeb3Provider((err) => { if (err) { return callback(err); } - this.engine = new Engine({ - env: this.options.env || 'test', - // TODO: config will need to detect if this is a obj - embarkConfig: this.options.embarkConfig || 'embark.json', - interceptLogs: false - }); this.engine.init({ logger: new TestLogger({logLevel: this.options.loglevel}) @@ -106,6 +110,7 @@ class Test { this.engine.startService("codeGenerator"); this.engine.contractsManager.build(() => { + console.log('BUILT'); self.builtContracts = cloneDeep(self.engine.contractsManager.contracts); self.compiledContracts = cloneDeep(self.engine.contractsManager.compiledContracts); callback(); @@ -138,6 +143,41 @@ class Test { this.events.once('deployError', errorCallback); } + checkDeploymentOptions(options, callback) { + const self = this; + if (!options.deployment) { + if (!self.simOptions.host && !self.simOptions.accounts) { + return callback(); + } + self.simOptions = {}; + } else { + self.simOptions = {}; + let resetServices = false; + if (options.deployment.accounts) { + // Account setup + self.simOptions.accounts = AccountParser.parseAccountsConfig(options.deployment.accounts, self.web3); + resetServices = true; + } + if (options.deployment.host && options.deployment.port && options.deployment.type) { + if (options.deployment.type !== 'rpc' && options.deployment.type !== 'ws') { + callback(__("contracts config error: unknown deployment type %s", options.deployment.type)); + } + Object.assign(self.simOptions, {host: options.deployment.host, port: options.deployment.port, type: options.deployment.type}); + resetServices = true; + } + if (!resetServices) { + return callback(); + } + } + self.initWeb3Provider((err) => { + if (err) { + return callback(err); + } + self.initDeployServices(); + callback(); + }); + } + config(options, callback) { const self = this; if (typeof (options) === 'function') { @@ -154,38 +194,9 @@ class Test { self.ready = false; async.waterfall([ - function checkDeploymentOptions(next) { - if (!options.deployment) { - if (!self.simOptions.host && !self.simOptions.accounts) { - return next(); - } - self.simOptions = {}; - } else { - self.simOptions = {}; - let resetServices = false; - if (options.deployment.accounts) { - // Account setup - self.simOptions.accounts = AccountParser.parseAccountsConfig(options.deployment.accounts, self.web3); - resetServices = true; - } - if (options.deployment.host && options.deployment.port && options.deployment.type) { - if (options.deployment.type !== 'rpc') { - throw new Error(__("contracts config error: unknown deployment type %s", options.deployment.type)); - } - Object.assign(self.simOptions, {host: options.deployment.host, port: options.deployment.port}); - resetServices = true; - } - if (!resetServices) { - return next(); - } - } - self.initWeb3Provider((err) => { - if (err) { - return next(err); - } - self.initDeployServices(); - next(); - }); + function checkDeploymentOpts(next) { + console.log('check', options); + self.checkDeploymentOptions(options, next); }, function resetContracts(next) { self.engine.contractsManager.contracts = cloneDeep(self.builtContracts);