mirror of https://github.com/embarklabs/embark.git
Clean up; Lint
This commit is contained in:
parent
4f50229beb
commit
799a87f35e
|
@ -28,7 +28,6 @@ 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 = [];
|
||||||
|
|
||||||
|
@ -51,10 +50,6 @@ 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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,38 +10,6 @@ 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');
|
||||||
|
@ -132,40 +100,40 @@ class Test {
|
||||||
this.sim = getSimulator();
|
this.sim = getSimulator();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.dir("-----> tests")
|
let simProvider = this.sim.provider(this.simOptions);
|
||||||
|
|
||||||
//let proxyProvider = new ProxyProvider(this.sim.provider(this.simOptions))
|
// Here we patch the sendAsync method on the provider. The goal behind this is to force pure/constant/view calls to become
|
||||||
//this.web3.setProvider(proxyProvider);
|
// transactions, so that we can pull in execution traces and account for those executions in code coverage.
|
||||||
|
//
|
||||||
let simProvider = this.sim.provider(this.simOptions)
|
// Instead of a simple call, here's what happens:
|
||||||
|
//
|
||||||
simProvider.real_sendAsync = simProvider.sendAsync
|
// 1) A transaction is sent with the same payload, and a pre-defined gas price;
|
||||||
simProvider.sendAsync = function(payload, callback) {
|
// 2) We wait for the transaction to be mined by asking for the receipt;
|
||||||
|
// 3) Once we get the receipt back, we dispatch the real call and pass the original callback;
|
||||||
if (payload.method === 'eth_call') {
|
//
|
||||||
let newParams = Object.assign({}, payload.params[0], {gasPrice: '0x77359400'})
|
// This will still allow tests to get the return value from the call and run contracts unmodified.
|
||||||
console.dir(newParams)
|
simProvider.realSendAsync = simProvider.sendAsync;
|
||||||
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) => {
|
simProvider.sendAsync = function(payload, cb) {
|
||||||
console.log("===== eth_call duplicated as a tx")
|
if(payload.method !== 'eth_call') {
|
||||||
console.dir(error)
|
return simProvider.realSendAsync.apply(simProvider.realSendAsync, [payload, cb]);
|
||||||
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])
|
|
||||||
|
let newParams = Object.assign({}, payload.params[0], {gasPrice: '0x77359400'});
|
||||||
|
let newPayload = {
|
||||||
|
id: parseInt(Math.random(1000000) * 1000000, 10),
|
||||||
|
method: 'eth_sendTransaction',
|
||||||
|
params: [newParams],
|
||||||
|
jsonrpc: payload.jsonrpc
|
||||||
|
};
|
||||||
|
|
||||||
|
let txCallback = (_err, response) => {
|
||||||
|
let txHash = response.result;
|
||||||
|
self.web3.eth.getTransactionReceipt(txHash, (_err, _res) => {
|
||||||
|
simProvider.realSendAsync.apply(simProvider.realSendAsync, [payload, cb]);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
simProvider.realSendAsync.apply(simProvider.realSendAsync, [newPayload, txCallback]);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.web3.setProvider(simProvider);
|
this.web3.setProvider(simProvider);
|
||||||
|
|
Loading…
Reference in New Issue