mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-20 02:58:05 +00:00
enable connecting to ws node in tests
This commit is contained in:
parent
c8c0a5c42f
commit
f32ac90e71
@ -251,6 +251,9 @@ class Blockchain {
|
|||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
function pingEndpoint(next) {
|
function pingEndpoint(next) {
|
||||||
|
if (!self.contractsConfig || !self.contractsConfig.deployment || !self.contractsConfig.deployment.host) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
const origin = self.blockchainConfig.wsOrigins.split(',')[0];
|
const origin = self.blockchainConfig.wsOrigins.split(',')[0];
|
||||||
const options = {
|
const options = {
|
||||||
protocolVersion: 13,
|
protocolVersion: 13,
|
||||||
|
@ -44,12 +44,15 @@ class Test {
|
|||||||
|
|
||||||
initWeb3Provider(callback) {
|
initWeb3Provider(callback) {
|
||||||
if (this.simOptions.host) {
|
if (this.simOptions.host) {
|
||||||
|
const protocol = (this.simOptions.type === "rpc") ? 'http' : 'ws';
|
||||||
const providerOptions = {
|
const providerOptions = {
|
||||||
web3: this.web3,
|
web3: this.web3,
|
||||||
|
type: this.simOptions.type,
|
||||||
accountsConfig: this.simOptions.accounts,
|
accountsConfig: this.simOptions.accounts,
|
||||||
|
blockchainConfig: this.engine.config.blockchainConfig,
|
||||||
logger: this.engine.logger,
|
logger: this.engine.logger,
|
||||||
isDev: false,
|
isDev: false,
|
||||||
web3Endpoint: 'http://' + this.simOptions.host + ':' + this.simOptions.port
|
web3Endpoint: `${protocol}://${this.simOptions.host}:${this.simOptions.port}`
|
||||||
};
|
};
|
||||||
this.provider = new Provider(providerOptions);
|
this.provider = new Provider(providerOptions);
|
||||||
return this.provider.startWeb3Provider(callback);
|
return this.provider.startWeb3Provider(callback);
|
||||||
@ -78,10 +81,6 @@ class Test {
|
|||||||
init(callback) {
|
init(callback) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
this.initWeb3Provider((err) => {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
this.engine = new Engine({
|
this.engine = new Engine({
|
||||||
env: this.options.env || 'test',
|
env: this.options.env || 'test',
|
||||||
// TODO: config will need to detect if this is a obj
|
// TODO: config will need to detect if this is a obj
|
||||||
@ -89,6 +88,11 @@ class Test {
|
|||||||
interceptLogs: false
|
interceptLogs: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.initWeb3Provider((err) => {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
this.engine.init({
|
this.engine.init({
|
||||||
logger: new TestLogger({logLevel: this.options.loglevel})
|
logger: new TestLogger({logLevel: this.options.loglevel})
|
||||||
});
|
});
|
||||||
@ -106,6 +110,7 @@ class Test {
|
|||||||
this.engine.startService("codeGenerator");
|
this.engine.startService("codeGenerator");
|
||||||
|
|
||||||
this.engine.contractsManager.build(() => {
|
this.engine.contractsManager.build(() => {
|
||||||
|
console.log('BUILT');
|
||||||
self.builtContracts = cloneDeep(self.engine.contractsManager.contracts);
|
self.builtContracts = cloneDeep(self.engine.contractsManager.contracts);
|
||||||
self.compiledContracts = cloneDeep(self.engine.contractsManager.compiledContracts);
|
self.compiledContracts = cloneDeep(self.engine.contractsManager.compiledContracts);
|
||||||
callback();
|
callback();
|
||||||
@ -138,6 +143,41 @@ class Test {
|
|||||||
this.events.once('deployError', errorCallback);
|
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) {
|
config(options, callback) {
|
||||||
const self = this;
|
const self = this;
|
||||||
if (typeof (options) === 'function') {
|
if (typeof (options) === 'function') {
|
||||||
@ -154,38 +194,9 @@ class Test {
|
|||||||
self.ready = false;
|
self.ready = false;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function checkDeploymentOptions(next) {
|
function checkDeploymentOpts(next) {
|
||||||
if (!options.deployment) {
|
console.log('check', options);
|
||||||
if (!self.simOptions.host && !self.simOptions.accounts) {
|
self.checkDeploymentOptions(options, next);
|
||||||
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 resetContracts(next) {
|
function resetContracts(next) {
|
||||||
self.engine.contractsManager.contracts = cloneDeep(self.builtContracts);
|
self.engine.contractsManager.contracts = cloneDeep(self.builtContracts);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user