wip fixes
This commit is contained in:
parent
abb3d4e327
commit
01900f8c6e
|
@ -23,7 +23,7 @@ var Blockchain = function(options) {
|
|||
console.log("===> " + __("warning: running default config on a non-development environment"));
|
||||
}
|
||||
|
||||
let defaultWsApi = ['eth', 'web3', 'net', 'shh', 'debug'];
|
||||
let defaultWsApi = ['eth', 'web3', 'net', 'shh', 'debug', 'pubsub'];
|
||||
if (this.isDev) {
|
||||
defaultWsApi.push('personal');
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ var Blockchain = function(options) {
|
|||
whisper: (this.blockchainConfig.whisper === undefined) || this.blockchainConfig.whisper,
|
||||
maxpeers: ((this.blockchainConfig.maxpeers === 0) ? 0 : (this.blockchainConfig.maxpeers || 25)),
|
||||
bootnodes: this.blockchainConfig.bootnodes || "",
|
||||
rpcApi: (this.blockchainConfig.rpcApi || ['eth', 'web3', 'net', 'debug']),
|
||||
rpcApi: (this.blockchainConfig.rpcApi || ['eth', 'web3', 'net', 'debug', 'pubsub']),
|
||||
wsRPC: (this.blockchainConfig.wsRPC === undefined) || this.blockchainConfig.wsRPC,
|
||||
wsHost: dockerHostSwap(this.blockchainConfig.wsHost) || defaultHost,
|
||||
wsPort: this.blockchainConfig.wsPort || 8546,
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
const ProviderEngine = require('embark-web3-provider-engine');
|
||||
const RpcSubprovider = require('embark-web3-provider-engine/subproviders/rpc');
|
||||
const WsSubprovider = require('embark-web3-provider-engine/subproviders/websocket');
|
||||
const CacheSubprovider = require('embark-web3-provider-engine/subproviders/cache.js');
|
||||
const FixtureSubprovider = require('embark-web3-provider-engine/subproviders/fixture.js');
|
||||
const FilterSubprovider = require('embark-web3-provider-engine/subproviders/filters.js');
|
||||
const VmSubprovider = require('embark-web3-provider-engine/subproviders/vm.js');
|
||||
const NonceSubprovider = require('embark-web3-provider-engine/subproviders/nonce-tracker.js');
|
||||
const SubscriptionSubprovider = require('embark-web3-provider-engine/subproviders/subscriptions');
|
||||
const async = require('async');
|
||||
const AccountParser = require('./accountParser');
|
||||
const fundAccount = require('./fundAccount');
|
||||
|
@ -26,11 +32,18 @@ class Provider extends ProviderEngine {
|
|||
startWeb3Provider(callback) {
|
||||
const self = this;
|
||||
|
||||
// cache layer
|
||||
// self.addProvider(new CacheSubprovider())
|
||||
|
||||
// self.addProvider(new NonceSubprovider())
|
||||
|
||||
if (this.type === 'rpc') {
|
||||
self.addProvider(new RpcSubprovider({
|
||||
rpcUrl: self.web3Endpoint
|
||||
}));
|
||||
} else if (this.type === 'ws') {
|
||||
console.log('USing ws');
|
||||
self.addProvider(new SubscriptionSubprovider());
|
||||
self.addProvider(new WsSubprovider({
|
||||
rpcUrl: self.web3Endpoint,
|
||||
origin: this.blockchainConfig.wsOrigins.split(',')[0]
|
||||
|
@ -40,17 +53,19 @@ class Provider extends ProviderEngine {
|
|||
}
|
||||
|
||||
|
||||
|
||||
// network connectivity error
|
||||
self.on('error', (err) => {
|
||||
console.log('ERR', JSON.stringify(err));
|
||||
// report connectivity errors as trace due to polling
|
||||
self.logger.trace('web3 provider error: ', err);
|
||||
self.logger.trace('stopping web3 provider due to error');
|
||||
|
||||
|
||||
// prevent continuous polling errors
|
||||
self.engine.stop();
|
||||
self.stop();
|
||||
});
|
||||
|
||||
self.web3.setProvider(self);
|
||||
self.web3.setProvider(self);
|
||||
self.start();
|
||||
|
||||
self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger);
|
||||
|
|
|
@ -44,6 +44,7 @@ class Test {
|
|||
}
|
||||
|
||||
initWeb3Provider(callback) {
|
||||
const self = this;
|
||||
if (this.provider) {
|
||||
this.provider.stop();
|
||||
}
|
||||
|
@ -63,13 +64,30 @@ class Test {
|
|||
web3Endpoint: endpoint
|
||||
};
|
||||
console.info(`Connecting to node at ${endpoint}`.cyan);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/*const ProviderEngine = require('embark-web3-provider-engine');
|
||||
const WsSubprovider = require('embark-web3-provider-engine/subproviders/websocket');
|
||||
const SubscriptionSubprovider = require('embark-web3-provider-engine/subproviders/subscriptions');
|
||||
const engine = new ProviderEngine();
|
||||
self.web3 = new Web3(engine);
|
||||
|
||||
engine.addProvider(new SubscriptionSubprovider());
|
||||
engine.addProvider(new WsSubprovider({
|
||||
rpcUrl: endpoint,
|
||||
origin: self.engine.config.blockchainConfig.wsOrigins.split(',')[0]
|
||||
}));
|
||||
|
||||
engine.start();
|
||||
return callback();*/
|
||||
|
||||
this.provider = new Provider(providerOptions);
|
||||
return this.provider.startWeb3Provider(callback);
|
||||
this.provider.startWeb3Provider(callback);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,11 @@ const SimpleStorage = require('Embark/contracts/SimpleStorage');
|
|||
let accounts;
|
||||
|
||||
config({
|
||||
deployment: {
|
||||
type: 'ws',
|
||||
host: 'localhost',
|
||||
port: '8546'
|
||||
},
|
||||
contracts: {
|
||||
"SimpleStorage": {
|
||||
args: [100],
|
||||
|
@ -38,14 +43,20 @@ contract("SimpleStorage", function () {
|
|||
});
|
||||
|
||||
it('listens to events', function (done) {
|
||||
SimpleStorage.once('EventOnSet2', async function(error, _result){
|
||||
assert.strictEqual(error, null);
|
||||
SimpleStorage.once('EventOnSet2', function(error, _result){
|
||||
console.log('error', error);
|
||||
console.log('result', _result);
|
||||
|
||||
/*assert.strictEqual(error, null);
|
||||
let result = await SimpleStorage.methods.get().call();
|
||||
assert.strictEqual(parseInt(result, 10), 150);
|
||||
done();
|
||||
assert.strictEqual(parseInt(result, 10), 150);*/
|
||||
done(error);
|
||||
});
|
||||
|
||||
SimpleStorage.methods.set2(150, 100).send();
|
||||
console.log('TEST');
|
||||
SimpleStorage.methods.set2(150, 100).send(() => {
|
||||
console.log('Done');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue