temp/poc for eth_call coverage

This commit is contained in:
Iuri Matias 2018-09-10 14:42:16 -04:00 committed by Andre Medeiros
parent cbd208cae1
commit 4f50229beb
2 changed files with 75 additions and 1 deletions

View File

@ -28,6 +28,7 @@ class Provider {
self.web3.setProvider(self.provider); self.web3.setProvider(self.provider);
console.dir("hello world")
self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger); self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger);
self.addresses = []; self.addresses = [];
@ -50,6 +51,10 @@ class Provider {
cb(null, result); cb(null, result);
}); });
} }
if (payload.method === 'eth_call') {
console.dir("payload: ")
console.dir(payload)
}
realSend(payload, cb); realSend(payload, cb);
}; };

View File

@ -10,6 +10,38 @@ const utils = require('../utils/utils');
const EmbarkJS = require('embarkjs'); const EmbarkJS = require('embarkjs');
class ProxyProvider extends Web3.providers.WebsocketProvider {
constructor(realProvider) {
super(realProvider)
this.realProvider = realProvider
}
sendAsync(payload, callback) {
console.log('payload method is ', payload.method)
// if (payload.method === 'eth_call') {
// this.realProvider.sendAsync({id: 123456, method: 'eth_sendTransaction', params: payload.params, jsonrpc: payload.jsonrpc}, () => {
// console.log("===== eth_call duplicated as a tx")
// console.dir(arguments)
// })
// }
return this.realProvider.sendAsync(payload, callback)
// let method = this.methods[payload.method]
// if (method) {
// return method.call(method, payload, (err, result) => {
// if (err) {
// return callback(err)
// }
// let response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result}
// callback(null, response)
// })
// }
// callback(new Error('unknown method ' + payload.method))
}
}
function getSimulator() { function getSimulator() {
try { try {
return require('ganache-cli'); return require('ganache-cli');
@ -99,7 +131,44 @@ class Test {
if (!this.sim) { if (!this.sim) {
this.sim = getSimulator(); this.sim = getSimulator();
} }
this.web3.setProvider(this.sim.provider(this.simOptions));
console.dir("-----> tests")
//let proxyProvider = new ProxyProvider(this.sim.provider(this.simOptions))
//this.web3.setProvider(proxyProvider);
let simProvider = this.sim.provider(this.simOptions)
simProvider.real_sendAsync = simProvider.sendAsync
simProvider.sendAsync = function(payload, callback) {
if (payload.method === 'eth_call') {
let newParams = Object.assign({}, payload.params[0], {gasPrice: '0x77359400'})
console.dir(newParams)
return simProvider.real_sendAsync.apply(simProvider.real_sendAsync, [{id: 123456 + parseInt(Math.random(100000)*100000), method: 'eth_sendTransaction', params: [newParams], jsonrpc: payload.jsonrpc}, (error, response) => {
console.log("===== eth_call duplicated as a tx")
console.dir(error)
console.dir(response)
let txHash = response.result;
self.web3.eth.getTransactionReceipt(txHash, (_err, res) => {
console.dir('------------')
console.dir(_err)
console.dir(res)
console.dir('------------')
simProvider.real_sendAsync.apply(simProvider.real_sendAsync, [payload, callback])
})
}])
} else if (payload.method === 'eth_sendTransaction') {
console.log("=== eth_sendTransaction");
console.dir(payload);
}
simProvider.real_sendAsync.apply(simProvider.real_sendAsync, [payload, callback])
};
this.web3.setProvider(simProvider);
callback(); callback();
} }