enable connecting to ws node in tests

This commit is contained in:
Jonathan Rainville 2018-06-15 15:16:55 -04:00
parent c8c0a5c42f
commit f32ac90e71
2 changed files with 53 additions and 39 deletions

View File

@ -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,

View File

@ -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);