use blockchain_connector's provider for nodes
This commit is contained in:
parent
5a5485d447
commit
7516bad619
|
@ -105,6 +105,7 @@ class BlockchainConnector {
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
self.provider.fundAccounts(() => {
|
self.provider.fundAccounts(() => {
|
||||||
self._emitWeb3Ready();
|
self._emitWeb3Ready();
|
||||||
|
cb();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
// const Engine = require('../../core/engine.js');
|
|
||||||
// const TestLogger = require('./test_logger.js');
|
|
||||||
// const Web3 = require('web3');
|
|
||||||
const AccountParser = require('../../utils/accountParser');
|
const AccountParser = require('../../utils/accountParser');
|
||||||
// TODO: breaks module isolation; tests need to be refactored to use the engine and avoid this
|
|
||||||
const Provider = require('../blockchain_connector/provider.js');
|
|
||||||
const utils = require('../../utils/utils');
|
|
||||||
|
|
||||||
class Test {
|
class Test {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
@ -23,13 +17,6 @@ class Test {
|
||||||
this.blockchainConnector = null;
|
this.blockchainConnector = null;
|
||||||
this.provider = null;
|
this.provider = null;
|
||||||
this.accounts = [];
|
this.accounts = [];
|
||||||
|
|
||||||
/*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
|
|
||||||
});*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init(callback) {
|
init(callback) {
|
||||||
|
@ -39,47 +26,9 @@ class Test {
|
||||||
this.blockchainConnector = connector;
|
this.blockchainConnector = connector;
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
|
||||||
/*let self = this;
|
|
||||||
async.waterfall([
|
|
||||||
function initEngine(cb) {
|
|
||||||
self.engine.init({
|
|
||||||
logger: new TestLogger({logLevel: self.options.loglevel})
|
|
||||||
}, cb);
|
|
||||||
},
|
|
||||||
function startServices(cb) {
|
|
||||||
self.versions_default = self.engine.config.contractsConfig.versions;
|
|
||||||
// Reset contract config to nothing to make sure we deploy only what we want
|
|
||||||
self.engine.config.contractsConfig = {
|
|
||||||
contracts: {},
|
|
||||||
versions: self.versions_default
|
|
||||||
};
|
|
||||||
|
|
||||||
self.engine.startService("libraryManager");
|
|
||||||
self.engine.startService("codeRunner");
|
|
||||||
self.initDeployServices();
|
|
||||||
self.engine.startService("codeGenerator");
|
|
||||||
self.engine.startService("codeCoverage");
|
|
||||||
|
|
||||||
if (self.options.node === 'embark') {
|
|
||||||
if (!self.engine.ipc.connected) {
|
|
||||||
self.engine.logger.error("Could not connect to Embark's IPC. Is embark running?");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
return self.connectToIpcNode(cb);
|
|
||||||
}
|
|
||||||
self.showNodeHttpWarning();
|
|
||||||
cb();
|
|
||||||
}
|
|
||||||
], callback);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initWeb3Provider(callback) {
|
initWeb3Provider(callback) {
|
||||||
const self = this;
|
|
||||||
if (this.provider) {
|
|
||||||
this.provider.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.simOptions.accounts) {
|
if (this.simOptions.accounts) {
|
||||||
this.simOptions.accounts = this.simOptions.accounts.map((account) => {
|
this.simOptions.accounts = this.simOptions.accounts.map((account) => {
|
||||||
if (!account.hexBalance) {
|
if (!account.hexBalance) {
|
||||||
|
@ -90,7 +39,7 @@ class Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO use event for this
|
// TODO use event for this
|
||||||
if (!this.simOptions.host || (this.options.node && this.options.node === 'vm')) {
|
if (!this.simOptions.host && (this.options.node && this.options.node === 'vm')) {
|
||||||
this.simOptions.type = 'vm';
|
this.simOptions.type = 'vm';
|
||||||
}
|
}
|
||||||
this.configObj.contractsConfig.deployment = this.simOptions;
|
this.configObj.contractsConfig.deployment = this.simOptions;
|
||||||
|
@ -98,51 +47,6 @@ class Test {
|
||||||
this.blockchainConnector.isWeb3Ready = false;
|
this.blockchainConnector.isWeb3Ready = false;
|
||||||
this.blockchainConnector.wait = false;
|
this.blockchainConnector.wait = false;
|
||||||
|
|
||||||
// TODO change this
|
|
||||||
if (this.simOptions.host || (this.options.node && this.options.node !== 'vm')) {
|
|
||||||
let options = this.simOptions;
|
|
||||||
if (this.options.node) {
|
|
||||||
options = utils.deconstructUrl(this.options.node);
|
|
||||||
}
|
|
||||||
|
|
||||||
let {host, port, type, protocol, accounts} = options;
|
|
||||||
if (!protocol) {
|
|
||||||
protocol = (options.type === "rpc") ? 'http' : 'ws';
|
|
||||||
}
|
|
||||||
const endpoint = `${protocol}://${host}:${port}`;
|
|
||||||
const providerOptions = {
|
|
||||||
web3: this.web3,
|
|
||||||
type,
|
|
||||||
accountsConfig: accounts,
|
|
||||||
blockchainConfig: this.configObj.blockchainConfig,
|
|
||||||
logger: this.logger,
|
|
||||||
isDev: false,
|
|
||||||
web3Endpoint: endpoint
|
|
||||||
};
|
|
||||||
self.logger.info(`Connecting to node at ${endpoint}`.cyan);
|
|
||||||
|
|
||||||
return utils.pingEndpoint(host, port, type, protocol, this.configObj.blockchainConfig.wsOrigins.split(',')[0], (err) => {
|
|
||||||
if (err) {
|
|
||||||
self.logger.error(`Error connecting to the node, there might be an error in ${endpoint}`.red);
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.provider = new Provider(providerOptions);
|
|
||||||
return self.provider.startWeb3Provider((err) => {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (!this.sim) {
|
|
||||||
// this.sim = getSimulator();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let simProvider = this.sim.provider(this.simOptions);
|
|
||||||
|
|
||||||
// TODO change this
|
// TODO change this
|
||||||
/*if (this.options.coverage) {
|
/*if (this.options.coverage) {
|
||||||
// Here we patch the sendAsync method on the provider. The goal behind this is to force pure/constant/view calls to become
|
// Here we patch the sendAsync method on the provider. The goal behind this is to force pure/constant/view calls to become
|
||||||
|
@ -180,8 +84,6 @@ class Test {
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
this.blockchainConnector.initWeb3(callback);
|
this.blockchainConnector.initWeb3(callback);
|
||||||
// this.web3.setProvider(simProvider);
|
|
||||||
// callback();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*initDeployServices() {
|
/*initDeployServices() {
|
||||||
|
@ -276,7 +178,6 @@ class Test {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
self.firstRunConfig = false;
|
self.firstRunConfig = false;
|
||||||
// self.initDeployServices();
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue