mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
d91eabfd16
We are working on migrating the extension to a unified network controller, but before we do so we want to extract some of the existing pieces, specifically `createInfuraClient` and `createJsonRpcClient`, which provide the majority of the behavior exhibited within the provider API that the existing NetworkController exposes. This necessitates that we understand and test that behavior as a whole. With that in mind, this commit starts with the Infura-specific network client and adds some initial functional tests for `createInfuraClient`, specifically covering three pieces of middleware provided by `eth-json-rpc-middleware`: `createNetworkAndChainIdMiddleware`, `createBlockCacheMiddleware`, and `createBlockRefMiddleware`. These tests exercise logic that originate from multiple different places and combine in sometimes surprising ways, and as a result, understanding the nature of the tests can be tricky. I've tried to explain the logic (both of the implementation and the tests) via comments. Additionally, debugging why a certain test is failing is not the most fun thing in the world, so to aid with this, I've added some logging to the underlying packages used when a request passes through the middleware stack. Because some middleware change the request being made, or make new requests altogether, this greatly helps to peel back the curtain, as failures from Nock do not supply much meaningful information on their own. This logging is disabled by default, but can be activated by setting `DEBUG=metamask:*,eth-query DEBUG_COLORS=1` alongside the `jest` command. We use this logging by bumping `eth-block-tracker`, and `eth-json-rpc-middleware`.
23 lines
926 B
Diff
23 lines
926 B
Diff
diff --git a/node_modules/eth-query/index.js b/node_modules/eth-query/index.js
|
|
index 13e9f3c..303d703 100644
|
|
--- a/node_modules/eth-query/index.js
|
|
+++ b/node_modules/eth-query/index.js
|
|
@@ -1,5 +1,6 @@
|
|
const extend = require('xtend')
|
|
const createRandomId = require('json-rpc-random-id')()
|
|
+const debug = require('debug')('eth-query');
|
|
|
|
module.exports = EthQuery
|
|
|
|
@@ -63,7 +64,9 @@ EthQuery.prototype.submitHashrate = generateFnFor('eth_subm
|
|
|
|
EthQuery.prototype.sendAsync = function(opts, cb){
|
|
const self = this
|
|
- self.currentProvider.sendAsync(createPayload(opts), function(err, response){
|
|
+ const payload = createPayload(opts)
|
|
+ debug('making request %o', payload)
|
|
+ self.currentProvider.sendAsync(payload, function(err, response){
|
|
if (!err && response.error) err = new Error('EthQuery - RPC Error - '+response.error.message)
|
|
if (err) return cb(err)
|
|
cb(null, response.result)
|