Deprecating the Rinkeby, Ropsten, and Kovan test networks (#15989)
* Deprecating Rinkeby, setting default debug network to Goerli * Deprecating Ropsten and Kovan * Conflict fix * Remove unused localization, test fixes * Add migration for moving used deprecated testnets to custom networks * Fix migrator test * Add more unit tests * Migration updates provider type to rpc if deprecated network is selected * Migration fully and correctly updates the provider if selected network is a deprecated testnet * Continue to show deprecation warning on each of rinkeby, ropsten and kovan * Add rpcUrl deprecation message to loading screen * Removing mayBeFauceting prop Co-authored-by: Dan Miller <danjm.com@gmail.com>feature/default_network_editable
parent
99808eb02c
commit
0bc1eeaf37
@ -0,0 +1,132 @@ |
||||
import { cloneDeep, uniq } from 'lodash'; |
||||
import BigNumber from 'bignumber.js'; |
||||
import { getRpcUrl } from '../../../shared/constants/network'; |
||||
|
||||
const version = 74; |
||||
|
||||
const hexNumberIsGreaterThanZero = (hexNumber) => |
||||
new BigNumber(hexNumber || '0x0', 16).gt(0); |
||||
|
||||
const DEPRECATED_TEST_NET_CHAINIDS = ['0x3', '0x2a', '0x4']; |
||||
const DEPRECATED_TEST_NET_DETAILS = { |
||||
'0x3': { |
||||
rpcUrl: getRpcUrl({ network: 'ropsten' }), |
||||
nickname: 'Ropsten', |
||||
ticker: 'RopstenETH', |
||||
}, |
||||
'0x2a': { |
||||
rpcUrl: getRpcUrl({ network: 'kovan' }), |
||||
nickname: 'Kovan', |
||||
ticker: 'KovanETH', |
||||
}, |
||||
'0x4': { |
||||
rpcUrl: getRpcUrl({ network: 'rinkeby' }), |
||||
nickname: 'Rinkeby', |
||||
ticker: 'RinkebyETH', |
||||
}, |
||||
}; |
||||
|
||||
/** |
||||
* Migrates the user default but deprecated testnet networks to custom networks, and |
||||
* if the current network is one such network, updates the network provider details so that it |
||||
* will work as a custom rpc |
||||
*/ |
||||
export default { |
||||
version, |
||||
async migrate(originalVersionedData) { |
||||
const versionedData = cloneDeep(originalVersionedData); |
||||
versionedData.meta.version = version; |
||||
const state = versionedData.data; |
||||
const newState = transformState(state); |
||||
versionedData.data = newState; |
||||
return versionedData; |
||||
}, |
||||
}; |
||||
|
||||
function transformState(state) { |
||||
const PreferencesController = state?.PreferencesController || {}; |
||||
const preferences = PreferencesController.preferences || {}; |
||||
const NetworkController = state?.NetworkController || {}; |
||||
const provider = NetworkController?.provider || {}; |
||||
|
||||
const currentlyOnDeprecatedNetwork = DEPRECATED_TEST_NET_CHAINIDS.filter( |
||||
(chainId) => chainId === provider?.chainId, |
||||
); |
||||
|
||||
// If the user does not want to see test networks, and if the the user is not on a deprecated test network, then
|
||||
// no need to migrate the test network data to a custom network
|
||||
if ( |
||||
!preferences.showTestNetworks && |
||||
currentlyOnDeprecatedNetwork.length === 0 |
||||
) { |
||||
return state; |
||||
} |
||||
|
||||
const transactions = state?.TransactionController?.transactions || {}; |
||||
const cachedBalances = state.CachedBalancesController?.cachedBalances || {}; |
||||
|
||||
const deprecatedTestnetsOnWhichTheUserHasMadeATransaction = Object.values( |
||||
transactions, |
||||
) |
||||
.filter(({ chainId }) => DEPRECATED_TEST_NET_CHAINIDS.includes(chainId)) |
||||
.map(({ chainId }) => chainId); |
||||
const deprecatedTestnetsOnWhichTheUserHasCachedBalance = |
||||
DEPRECATED_TEST_NET_CHAINIDS.filter((chainId) => { |
||||
const cachedBalancesForChain = Object.values( |
||||
cachedBalances[chainId] || {}, |
||||
); |
||||
const userHasABalanceGreaterThanZeroOnThisChain = |
||||
cachedBalancesForChain.some(hexNumberIsGreaterThanZero); |
||||
return userHasABalanceGreaterThanZeroOnThisChain; |
||||
}); |
||||
const deprecatedTestnetsThatHaveBeenUsed = uniq([ |
||||
...deprecatedTestnetsOnWhichTheUserHasCachedBalance, |
||||
...deprecatedTestnetsOnWhichTheUserHasMadeATransaction, |
||||
...currentlyOnDeprecatedNetwork, |
||||
]); |
||||
|
||||
const newFrequentRpcListDetail = |
||||
PreferencesController.frequentRpcListDetail ?? []; |
||||
|
||||
deprecatedTestnetsThatHaveBeenUsed.forEach((chainId) => { |
||||
if ( |
||||
!newFrequentRpcListDetail.find( |
||||
(rpcDetails) => rpcDetails.chainId === chainId, |
||||
) |
||||
) { |
||||
newFrequentRpcListDetail.unshift({ |
||||
rpcUrl: DEPRECATED_TEST_NET_DETAILS[chainId].rpcUrl, |
||||
chainId, |
||||
ticker: DEPRECATED_TEST_NET_DETAILS[chainId].ticker, |
||||
nickname: DEPRECATED_TEST_NET_DETAILS[chainId].nickname, |
||||
rpcPrefs: {}, |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
if (newFrequentRpcListDetail.length) { |
||||
PreferencesController.frequentRpcListDetail = newFrequentRpcListDetail; |
||||
} |
||||
|
||||
if (currentlyOnDeprecatedNetwork.length) { |
||||
const selectedNetworkChainId = currentlyOnDeprecatedNetwork[0]; |
||||
NetworkController.provider = { |
||||
...NetworkController.provider, |
||||
type: 'rpc', |
||||
rpcUrl: DEPRECATED_TEST_NET_DETAILS[selectedNetworkChainId].rpcUrl, |
||||
chainId: selectedNetworkChainId, |
||||
nickname: DEPRECATED_TEST_NET_DETAILS[selectedNetworkChainId].nickname, |
||||
ticker: DEPRECATED_TEST_NET_DETAILS[selectedNetworkChainId].ticker, |
||||
}; |
||||
} |
||||
|
||||
return { |
||||
...state, |
||||
PreferencesController: { |
||||
...PreferencesController, |
||||
}, |
||||
NetworkController: { |
||||
...NetworkController, |
||||
}, |
||||
}; |
||||
} |
@ -0,0 +1,561 @@ |
||||
import migration74 from './074'; |
||||
|
||||
describe('migration #74', () => { |
||||
it('should update the version metadata', async () => { |
||||
const oldStorage = { |
||||
meta: { |
||||
version: 73, |
||||
}, |
||||
data: {}, |
||||
}; |
||||
|
||||
const newStorage = await migration74.migrate(oldStorage); |
||||
expect(newStorage.meta).toStrictEqual({ |
||||
version: 74, |
||||
}); |
||||
}); |
||||
|
||||
it('should add a deprecated testnet to custom networks if that network is currently selected and modify the provider', async () => { |
||||
const oldStorage = { |
||||
meta: { |
||||
version: 73, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0x4', |
||||
type: 'rinkeby', |
||||
}, |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration74.migrate(oldStorage); |
||||
expect(newStorage).toStrictEqual({ |
||||
meta: { |
||||
version: 74, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0x4', |
||||
type: 'rpc', |
||||
rpcUrl: `https://rinkeby.infura.io/v3/${process.env.INFURA_PROJECT_ID}`, |
||||
nickname: 'Rinkeby', |
||||
ticker: 'RinkebyETH', |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
frequentRpcListDetail: [ |
||||
{ |
||||
rpcUrl: `https://rinkeby.infura.io/v3/${process.env.INFURA_PROJECT_ID}`, |
||||
chainId: '0x4', |
||||
nickname: 'Rinkeby', |
||||
ticker: 'RinkebyETH', |
||||
rpcPrefs: {}, |
||||
}, |
||||
], |
||||
}, |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
it('should not add a deprecated testnet to custom networks if no deprecated testnet is selected', async () => { |
||||
const oldStorage = { |
||||
meta: { |
||||
version: 73, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0xabc', |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
preferences: { |
||||
showTestNetworks: true, |
||||
}, |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration74.migrate(oldStorage); |
||||
expect(newStorage).toStrictEqual({ |
||||
meta: { |
||||
version: 74, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0xabc', |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
preferences: { |
||||
showTestNetworks: true, |
||||
}, |
||||
}, |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
it('should add a deprecated testnet to custom networks if a transaction has been sent from that network', async () => { |
||||
const oldStorage = { |
||||
meta: { |
||||
version: 73, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0x1', |
||||
}, |
||||
}, |
||||
TransactionController: { |
||||
transactions: { |
||||
1: { |
||||
chainId: '0x3', |
||||
}, |
||||
2: { |
||||
chainId: '0x4', |
||||
}, |
||||
3: { |
||||
chainId: '0xabc', |
||||
}, |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
preferences: { |
||||
showTestNetworks: true, |
||||
}, |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration74.migrate(oldStorage); |
||||
expect(newStorage).toStrictEqual({ |
||||
meta: { |
||||
version: 74, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0x1', |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
frequentRpcListDetail: [ |
||||
{ |
||||
rpcUrl: `https://rinkeby.infura.io/v3/${process.env.INFURA_PROJECT_ID}`, |
||||
chainId: '0x4', |
||||
nickname: 'Rinkeby', |
||||
ticker: 'RinkebyETH', |
||||
rpcPrefs: {}, |
||||
}, |
||||
{ |
||||
rpcUrl: `https://ropsten.infura.io/v3/${process.env.INFURA_PROJECT_ID}`, |
||||
chainId: '0x3', |
||||
nickname: 'Ropsten', |
||||
ticker: 'RopstenETH', |
||||
rpcPrefs: {}, |
||||
}, |
||||
], |
||||
preferences: { |
||||
showTestNetworks: true, |
||||
}, |
||||
}, |
||||
TransactionController: { |
||||
transactions: { |
||||
1: { |
||||
chainId: '0x3', |
||||
}, |
||||
2: { |
||||
chainId: '0x4', |
||||
}, |
||||
3: { |
||||
chainId: '0xabc', |
||||
}, |
||||
}, |
||||
}, |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
it('should add a deprecated testnet to custom networks if there is balance on that network', async () => { |
||||
const oldStorage = { |
||||
meta: { |
||||
version: 73, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0x1', |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
preferences: { |
||||
showTestNetworks: true, |
||||
}, |
||||
}, |
||||
CachedBalancesController: { |
||||
cachedBalances: { |
||||
'0x2a': { |
||||
'0x123456789': '0x1', |
||||
}, |
||||
}, |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration74.migrate(oldStorage); |
||||
expect(newStorage).toStrictEqual({ |
||||
meta: { |
||||
version: 74, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0x1', |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
frequentRpcListDetail: [ |
||||
{ |
||||
rpcUrl: `https://kovan.infura.io/v3/${process.env.INFURA_PROJECT_ID}`, |
||||
chainId: '0x2a', |
||||
nickname: 'Kovan', |
||||
ticker: 'KovanETH', |
||||
rpcPrefs: {}, |
||||
}, |
||||
], |
||||
preferences: { |
||||
showTestNetworks: true, |
||||
}, |
||||
}, |
||||
CachedBalancesController: { |
||||
cachedBalances: { |
||||
'0x2a': { |
||||
'0x123456789': '0x1', |
||||
}, |
||||
}, |
||||
}, |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
it('should add all three deprecated testnets to custom networks if each has a different reason for being added', async () => { |
||||
const oldStorage = { |
||||
meta: { |
||||
version: 73, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0x2a', |
||||
}, |
||||
}, |
||||
TransactionController: { |
||||
transactions: { |
||||
1: { |
||||
chainId: '0x3', |
||||
}, |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
preferences: { |
||||
showTestNetworks: true, |
||||
}, |
||||
}, |
||||
CachedBalancesController: { |
||||
cachedBalances: { |
||||
'0x4': { |
||||
'0x123456789': '0x1', |
||||
}, |
||||
}, |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration74.migrate(oldStorage); |
||||
expect(newStorage).toStrictEqual({ |
||||
meta: { |
||||
version: 74, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
rpcUrl: `https://kovan.infura.io/v3/${process.env.INFURA_PROJECT_ID}`, |
||||
chainId: '0x2a', |
||||
nickname: 'Kovan', |
||||
ticker: 'KovanETH', |
||||
type: 'rpc', |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
frequentRpcListDetail: [ |
||||
{ |
||||
rpcUrl: `https://kovan.infura.io/v3/${process.env.INFURA_PROJECT_ID}`, |
||||
chainId: '0x2a', |
||||
nickname: 'Kovan', |
||||
ticker: 'KovanETH', |
||||
rpcPrefs: {}, |
||||
}, |
||||
{ |
||||
rpcUrl: `https://ropsten.infura.io/v3/${process.env.INFURA_PROJECT_ID}`, |
||||
chainId: '0x3', |
||||
nickname: 'Ropsten', |
||||
ticker: 'RopstenETH', |
||||
rpcPrefs: {}, |
||||
}, |
||||
{ |
||||
rpcUrl: `https://rinkeby.infura.io/v3/${process.env.INFURA_PROJECT_ID}`, |
||||
chainId: '0x4', |
||||
nickname: 'Rinkeby', |
||||
ticker: 'RinkebyETH', |
||||
rpcPrefs: {}, |
||||
}, |
||||
], |
||||
preferences: { |
||||
showTestNetworks: true, |
||||
}, |
||||
}, |
||||
CachedBalancesController: { |
||||
cachedBalances: { |
||||
'0x4': { |
||||
'0x123456789': '0x1', |
||||
}, |
||||
}, |
||||
}, |
||||
TransactionController: { |
||||
transactions: { |
||||
1: { |
||||
chainId: '0x3', |
||||
}, |
||||
}, |
||||
}, |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
it('should not add deprecated testnets to custom networks if none is selected and showTestNetworks is false', async () => { |
||||
const oldStorage = { |
||||
meta: { |
||||
version: 73, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0xabc', |
||||
}, |
||||
}, |
||||
TransactionController: { |
||||
transactions: { |
||||
1: { |
||||
chainId: '0x3', |
||||
}, |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
preferences: { |
||||
showTestNetworks: false, |
||||
}, |
||||
}, |
||||
CachedBalancesController: { |
||||
cachedBalances: { |
||||
'0x4': { |
||||
'0x123456789': '0x1', |
||||
}, |
||||
}, |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration74.migrate(oldStorage); |
||||
expect(newStorage).toStrictEqual({ |
||||
meta: { |
||||
version: 74, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0xabc', |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
preferences: { |
||||
showTestNetworks: false, |
||||
}, |
||||
}, |
||||
CachedBalancesController: { |
||||
cachedBalances: { |
||||
'0x4': { |
||||
'0x123456789': '0x1', |
||||
}, |
||||
}, |
||||
}, |
||||
TransactionController: { |
||||
transactions: { |
||||
1: { |
||||
chainId: '0x3', |
||||
}, |
||||
}, |
||||
}, |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
it('should not alter or remove existing custom networks when no deprecated testnets are being added', async () => { |
||||
const oldStorage = { |
||||
meta: { |
||||
version: 73, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0xabc', |
||||
}, |
||||
}, |
||||
TransactionController: { |
||||
transactions: { |
||||
1: { |
||||
chainId: '0x3', |
||||
}, |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
frequentRpcListDetail: [ |
||||
{ |
||||
rpcUrl: `https://example.com`, |
||||
chainId: '0xdef', |
||||
ticker: 'ETH', |
||||
nickname: 'Kovan', |
||||
rpcPrefs: {}, |
||||
}, |
||||
], |
||||
preferences: { |
||||
showTestNetworks: false, |
||||
}, |
||||
}, |
||||
CachedBalancesController: { |
||||
cachedBalances: { |
||||
'0x4': { |
||||
'0x123456789': '0x1', |
||||
}, |
||||
}, |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration74.migrate(oldStorage); |
||||
expect(newStorage).toStrictEqual({ |
||||
meta: { |
||||
version: 74, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0xabc', |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
frequentRpcListDetail: [ |
||||
{ |
||||
rpcUrl: `https://example.com`, |
||||
chainId: '0xdef', |
||||
ticker: 'ETH', |
||||
nickname: 'Kovan', |
||||
rpcPrefs: {}, |
||||
}, |
||||
], |
||||
preferences: { |
||||
showTestNetworks: false, |
||||
}, |
||||
}, |
||||
CachedBalancesController: { |
||||
cachedBalances: { |
||||
'0x4': { |
||||
'0x123456789': '0x1', |
||||
}, |
||||
}, |
||||
}, |
||||
TransactionController: { |
||||
transactions: { |
||||
1: { |
||||
chainId: '0x3', |
||||
}, |
||||
}, |
||||
}, |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
it('should not modify an existing custom network with the same chainId as a deprecated testnet', async () => { |
||||
const oldStorage = { |
||||
meta: { |
||||
version: 73, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0x1', |
||||
}, |
||||
}, |
||||
TransactionController: { |
||||
transactions: { |
||||
1: { |
||||
chainId: '0x3', |
||||
}, |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
preferences: { |
||||
showTestNetworks: true, |
||||
}, |
||||
frequentRpcListDetail: [ |
||||
{ |
||||
rpcUrl: `https://example.com`, |
||||
chainId: '0x3', |
||||
ticker: 'ETH', |
||||
nickname: 'Ropsten', |
||||
rpcPrefs: {}, |
||||
}, |
||||
], |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration74.migrate(oldStorage); |
||||
expect(newStorage).toStrictEqual({ |
||||
meta: { |
||||
version: 74, |
||||
}, |
||||
data: { |
||||
NetworkController: { |
||||
provider: { |
||||
chainId: '0x1', |
||||
}, |
||||
}, |
||||
TransactionController: { |
||||
transactions: { |
||||
1: { |
||||
chainId: '0x3', |
||||
}, |
||||
}, |
||||
}, |
||||
PreferencesController: { |
||||
preferences: { |
||||
showTestNetworks: true, |
||||
}, |
||||
frequentRpcListDetail: [ |
||||
{ |
||||
rpcUrl: `https://example.com`, |
||||
chainId: '0x3', |
||||
ticker: 'ETH', |
||||
nickname: 'Ropsten', |
||||
rpcPrefs: {}, |
||||
}, |
||||
], |
||||
}, |
||||
}, |
||||
}); |
||||
}); |
||||
}); |
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue