fix webserver errors

This commit is contained in:
Jonathan Rainville 2018-07-06 14:43:01 -04:00
parent 817c4a6209
commit 415df3312f
3 changed files with 26 additions and 19 deletions

View File

@ -28,6 +28,7 @@ class Provider {
self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger);
self.addresses = [];
if (!self.accounts.length) {
return callback();
}
@ -35,32 +36,35 @@ class Provider {
self.addresses.push(account.address);
self.web3.eth.accounts.wallet.add(account);
});
self.web3.eth.defaultAccount = self.addresses[0];
const realAccountFunction = self.web3.eth.getAccounts;
self.web3.eth.getAccounts = function (cb) {
cb = cb || function () {};
return new Promise((resolve, reject) => {
realAccountFunction((err, accounts) => {
const realSend = self.provider.send.bind(self.provider);
self.provider.send = function (payload, cb) {
if (payload.method === 'eth_accounts') {
return realSend(payload, function (err, result) {
if (err) {
cb(err);
return reject(err);
return cb(err);
}
// console.log('ACOUNTS', accounts);
// console.log('My addresses', self.addresses);
// accounts = self.addresses;
accounts = [accounts[0]].concat(self.addresses);
// accounts = accounts.concat(self.addresses);
// accounts = self.addresses.concat(accounts);
cb(null, accounts);
resolve(accounts);
});
result.result = result.result.concat(self.addresses);
cb(null, result);
});
}
realSend(payload, cb);
};
callback();
}
stop() {
if (this.provider && this.provider.removeAllListeners) {
this.provider.removeAllListeners('connect');
this.provider.removeAllListeners('error');
this.provider.removeAllListeners('end');
this.provider.removeAllListeners('data');
this.provider.responseCallbacks = {};
this.provider = null;
}
}
fundAccounts(callback) {
const self = this;
if (!self.accounts.length) {

View File

@ -77,6 +77,9 @@ class Test {
if (this.simOptions.accounts) {
this.simOptions.accounts = this.simOptions.accounts.map((account) => {
if (!account.hexBalance) {
account.hexBalance = '0x8AC7230489E80000'; // 10 ether
}
return {balance: account.hexBalance, secretKey: account.privateKey};
});
}

View File

@ -2,8 +2,8 @@ module.exports = {
default: {
deployment: {
host: "localhost",
port: 8545,
type: "rpc"
port: 8546,
type: "ws"
},
dappConnection: [
"$WEB3",