mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-13 23:48:47 +00:00
Merge pull request #556 from embark-framework/bug_fix/hanging-test-node
Fix hanging tests when using a wrong node
This commit is contained in:
commit
b363873da2
@ -256,45 +256,8 @@ class Blockchain {
|
|||||||
if (!self.contractsConfig || !self.contractsConfig.deployment || !self.contractsConfig.deployment.host) {
|
if (!self.contractsConfig || !self.contractsConfig.deployment || !self.contractsConfig.deployment.host) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
const origin = self.blockchainConfig.wsOrigins.split(',')[0];
|
const {host, port, type, protocol} = self.contractsConfig.deployment;
|
||||||
const options = {
|
utils.pingEndpoint(host, port, type, protocol, self.blockchainConfig.wsOrigins.split(',')[0], next);
|
||||||
protocolVersion: 13,
|
|
||||||
perMessageDeflate: true,
|
|
||||||
origin: origin,
|
|
||||||
host: self.contractsConfig.deployment.host,
|
|
||||||
port: self.contractsConfig.deployment.port
|
|
||||||
};
|
|
||||||
if (self.contractsConfig.deployment.type === 'ws') {
|
|
||||||
options.headers = {
|
|
||||||
'Sec-WebSocket-Version': 13,
|
|
||||||
Connection: 'Upgrade',
|
|
||||||
Upgrade: 'websocket',
|
|
||||||
'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits',
|
|
||||||
Origin: origin
|
|
||||||
};
|
|
||||||
}
|
|
||||||
let req;
|
|
||||||
// remove trailing api key from infura, ie rinkeby.infura.io/nmY8WtT4QfEwz2S7wTbl
|
|
||||||
if(options.host.indexOf('/') > -1){
|
|
||||||
options.host = options.host.split('/')[0];
|
|
||||||
}
|
|
||||||
if((self.contractsConfig.deployment.protocol || 'http') === 'https'){
|
|
||||||
req = require('https').get(options);
|
|
||||||
}else{
|
|
||||||
req = require('http').get(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
req.on('error', (err) => {
|
|
||||||
next(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
req.on('response', (_response) => {
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
req.on('upgrade', (_res, _socket, _head) => {
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
], function (err) {
|
], function (err) {
|
||||||
if (!noLogs && err === NO_NODE_ERROR) {
|
if (!noLogs && err === NO_NODE_ERROR) {
|
||||||
|
@ -7,6 +7,7 @@ const Events = require('../core/events');
|
|||||||
const cloneDeep = require('clone-deep');
|
const cloneDeep = require('clone-deep');
|
||||||
const AccountParser = require('../contracts/accountParser');
|
const AccountParser = require('../contracts/accountParser');
|
||||||
const Provider = require('../contracts/provider');
|
const Provider = require('../contracts/provider');
|
||||||
|
const utils = require('../utils/utils');
|
||||||
|
|
||||||
const EmbarkJS = require('../../js/embark_node');
|
const EmbarkJS = require('../../js/embark_node');
|
||||||
|
|
||||||
@ -44,18 +45,29 @@ class Test {
|
|||||||
|
|
||||||
initWeb3Provider(callback) {
|
initWeb3Provider(callback) {
|
||||||
if (this.simOptions.host) {
|
if (this.simOptions.host) {
|
||||||
const protocol = (this.simOptions.type === "rpc") ? 'http' : 'ws';
|
let {host, port, type, protocol, accounts} = this.simOptions;
|
||||||
|
if (!protocol) {
|
||||||
|
protocol = (this.simOptions.type === "rpc") ? 'http' : 'ws';
|
||||||
|
}
|
||||||
|
const endpoint = `${protocol}://${host}:${port}`;
|
||||||
const providerOptions = {
|
const providerOptions = {
|
||||||
web3: this.web3,
|
web3: this.web3,
|
||||||
type: this.simOptions.type,
|
type,
|
||||||
accountsConfig: this.simOptions.accounts,
|
accountsConfig: accounts,
|
||||||
blockchainConfig: this.engine.config.blockchainConfig,
|
blockchainConfig: this.engine.config.blockchainConfig,
|
||||||
logger: this.engine.logger,
|
logger: this.engine.logger,
|
||||||
isDev: false,
|
isDev: false,
|
||||||
web3Endpoint: `${protocol}://${this.simOptions.host}:${this.simOptions.port}`
|
web3Endpoint: endpoint
|
||||||
};
|
};
|
||||||
this.provider = new Provider(providerOptions);
|
console.info(`Connecting to node at ${endpoint}`.cyan);
|
||||||
return this.provider.startWeb3Provider(callback);
|
return utils.pingEndpoint(host, port, type, protocol, this.engine.config.blockchainConfig.wsOrigins.split(',')[0], (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(`Error connecting to the node, there might be an error in ${endpoint}`.red);
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
this.provider = new Provider(providerOptions);
|
||||||
|
return this.provider.startWeb3Provider(callback);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.simOptions.accounts) {
|
if (this.simOptions.accounts) {
|
||||||
@ -214,7 +226,12 @@ class Test {
|
|||||||
next(null, accounts);
|
next(null, accounts);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
], callback);
|
], (err, accounts) => {
|
||||||
|
if (err) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
callback(null, accounts);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_deploy(config, callback) {
|
_deploy(config, callback) {
|
||||||
|
@ -73,6 +73,47 @@ function httpsGetJson(url, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pingEndpoint(host, port, type, protocol, origin, callback) {
|
||||||
|
const options = {
|
||||||
|
protocolVersion: 13,
|
||||||
|
perMessageDeflate: true,
|
||||||
|
origin: origin,
|
||||||
|
host: host,
|
||||||
|
port: port
|
||||||
|
};
|
||||||
|
if (type === 'ws') {
|
||||||
|
options.headers = {
|
||||||
|
'Sec-WebSocket-Version': 13,
|
||||||
|
Connection: 'Upgrade',
|
||||||
|
Upgrade: 'websocket',
|
||||||
|
'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits',
|
||||||
|
Origin: origin
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let req;
|
||||||
|
// remove trailing api key from infura, ie rinkeby.infura.io/nmY8WtT4QfEwz2S7wTbl
|
||||||
|
if (options.host.indexOf('/') > -1){
|
||||||
|
options.host = options.host.split('/')[0];
|
||||||
|
}
|
||||||
|
if (protocol === 'https') {
|
||||||
|
req = require('https').get(options);
|
||||||
|
} else {
|
||||||
|
req = require('http').get(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
req.on('error', (err) => {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('response', (_response) => {
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('upgrade', (_res, _socket, _head) => {
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function runCmd(cmd, options) {
|
function runCmd(cmd, options) {
|
||||||
const shelljs = require('shelljs');
|
const shelljs = require('shelljs');
|
||||||
let result = shelljs.exec(cmd, options || {silent: true});
|
let result = shelljs.exec(cmd, options || {silent: true});
|
||||||
@ -267,6 +308,7 @@ module.exports = {
|
|||||||
httpGetJson: httpGetJson,
|
httpGetJson: httpGetJson,
|
||||||
httpsGetJson: httpsGetJson,
|
httpsGetJson: httpsGetJson,
|
||||||
hexToNumber: hexToNumber,
|
hexToNumber: hexToNumber,
|
||||||
|
pingEndpoint,
|
||||||
decodeParams: decodeParams,
|
decodeParams: decodeParams,
|
||||||
runCmd: runCmd,
|
runCmd: runCmd,
|
||||||
cd: cd,
|
cd: cd,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user