NetworkController: Normalize INFURA_NETWORKS array#1306
Conversation
The unit tests for NetworkController use an object of networks which is used in order to exercise code that creates an Infura provider. The NetworkController unit tests on the extension side, however, use an array instead of an object. This commit makes the two sides more consistent.
| chainId: NetworksChainId.mainnet, | ||
| ticker: NetworksTicker.mainnet, | ||
| blockExplorerUrl: `https://etherscan.io`, | ||
| chainId: '1', |
There was a problem hiding this comment.
Nit: While the constants we're using in this package aren't great, using a constant here rather than hard-coding a value did seem like a good idea. Have you considered restoring the use of NetworksChainId and NetworksTicker?
There was a problem hiding this comment.
Yes, so my feeling in general is that tests shouldn't share constants with implementation code if they don't have to. The thought here is that if the value in the constant is wrong, then you won't know it's wrong just by running the tests. It sort of feels like stubbing the thing under test to return a value, calling that thing, and then asserting that the expected and actual values match. But if you repeat the value in the test, then it gives you another opportunity to confirm that it's right. I thought it was okay to share NetworkType because it's a type as much as it is a value, so if it's wrong, then our whole interface is wrong. But we don't use NetworksChainId and NetworksTicker as types, so I chose to repeat them. Maybe this is not a huge deal, and it certainly is convenient just to reuse values. I could be convinced otherwise, I suppose. But that's where that's coming from.
There was a problem hiding this comment.
Ah OK. I'm generally a fan of using constants in tests. It can make the test suite much friendlier, easier to modfiy when code changes and easier to read.
The type of errors this would protect against can happen in the reverse direction as well (e.g. a test appears to pass only because the hard-coded constant is wrong), so it's not necessarily safer to hard-code constants either.
But we can discuss some other time, this is good for now. These constants you've replaced here were confusing anyway; this is a readability improvement for that reason alone.
The unit tests for NetworkController use an object of networks which is used in order to exercise code that creates an Infura provider. The NetworkController unit tests on the extension side, however, use an array instead of an object. This commit makes the two sides more consistent.
The unit tests for NetworkController use an object of networks which is used in order to exercise code that creates an Infura provider. The NetworkController unit tests on the extension side, however, use an array instead of an object. This commit makes the two sides more consistent.
Description
The unit tests for NetworkController use an object of networks which is used in order to exercise code that creates an Infura provider. The NetworkController unit tests on the extension side, however, use an array instead of an object. This commit makes the two sides more consistent.
Changes
N/A
References
Reduces the scope of #1116.
Checklist