Remove localhost provider type (#9551)

* Delete localhost provider type

* Use ganache-cli default chain ID for tests

* Delete unused test firstTimeState variable

* Migrate default ganache-cli network to frequentRpcListDetail

* Add default test provider state

* Add test functionality to createJsonRpcClient

* Lint locales

* Update test middleware creation

* fixup! Update test middleware creation
feature/default_network_editable
Erik Marks 4 years ago committed by GitHub
parent 33b755fa66
commit 5b8c07817a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/_locales/am/messages.json
  2. 3
      app/_locales/ar/messages.json
  3. 3
      app/_locales/bg/messages.json
  4. 3
      app/_locales/bn/messages.json
  5. 3
      app/_locales/ca/messages.json
  6. 3
      app/_locales/da/messages.json
  7. 3
      app/_locales/de/messages.json
  8. 3
      app/_locales/el/messages.json
  9. 3
      app/_locales/en/messages.json
  10. 3
      app/_locales/es/messages.json
  11. 3
      app/_locales/es_419/messages.json
  12. 3
      app/_locales/et/messages.json
  13. 3
      app/_locales/fa/messages.json
  14. 3
      app/_locales/fi/messages.json
  15. 3
      app/_locales/fil/messages.json
  16. 3
      app/_locales/fr/messages.json
  17. 3
      app/_locales/he/messages.json
  18. 3
      app/_locales/hi/messages.json
  19. 3
      app/_locales/hr/messages.json
  20. 3
      app/_locales/hu/messages.json
  21. 3
      app/_locales/id/messages.json
  22. 3
      app/_locales/it/messages.json
  23. 3
      app/_locales/kn/messages.json
  24. 3
      app/_locales/ko/messages.json
  25. 3
      app/_locales/lt/messages.json
  26. 3
      app/_locales/lv/messages.json
  27. 3
      app/_locales/ms/messages.json
  28. 3
      app/_locales/no/messages.json
  29. 3
      app/_locales/pl/messages.json
  30. 3
      app/_locales/pt_BR/messages.json
  31. 3
      app/_locales/ro/messages.json
  32. 3
      app/_locales/ru/messages.json
  33. 3
      app/_locales/sk/messages.json
  34. 3
      app/_locales/sl/messages.json
  35. 3
      app/_locales/sr/messages.json
  36. 3
      app/_locales/sv/messages.json
  37. 3
      app/_locales/sw/messages.json
  38. 3
      app/_locales/uk/messages.json
  39. 3
      app/_locales/zh_CN/messages.json
  40. 3
      app/_locales/zh_TW/messages.json
  41. 3
      app/scripts/background.js
  42. 31
      app/scripts/controllers/network/createJsonRpcClient.js
  43. 36
      app/scripts/controllers/network/createLocalhostClient.js
  44. 1
      app/scripts/controllers/network/enums.js
  45. 34
      app/scripts/controllers/network/network.js
  46. 5
      app/scripts/controllers/preferences.js
  47. 11
      app/scripts/first-time-state.js
  48. 21
      app/scripts/migrations/048.js
  49. 2
      development/run-ganache
  50. 2
      test/e2e/ethereum-on.spec.js
  51. 10
      test/e2e/fixtures/imported-account/state.json
  52. 10
      test/e2e/fixtures/localization/state.json
  53. 12
      test/e2e/fixtures/personal-sign/state.json
  54. 2
      test/e2e/ganache.js
  55. 6
      test/unit/app/controllers/metamask-controller-test.js
  56. 23
      test/unit/app/controllers/preferences-controller-test.js
  57. 1
      test/unit/localhostState.js
  58. 78
      test/unit/migrations/048-test.js
  59. 29
      ui/app/components/app/dropdowns/network-dropdown.js
  60. 11
      ui/app/components/app/dropdowns/tests/network-dropdown.test.js
  61. 2
      ui/app/components/app/loading-network-screen/loading-network-screen.component.js
  62. 6
      ui/app/components/app/network.js
  63. 2
      ui/app/helpers/utils/util.js
  64. 4
      ui/app/pages/routes/routes.component.js
  65. 9
      ui/app/pages/settings/networks-tab/networks-tab.constants.js

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "ከ Kovan የሙከራ አውታረ መረብ መገናኘት"
},
"connectingToLocalhost": {
"message": "ከ Localhost 8545 ጋር መገናኘት"
},
"connectingToMainnet": {
"message": "ከዋናው የ Ethereum አውታረ መረብ ጋር መገናኘት"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "الاتصال بشبكة اختبار Kovan"
},
"connectingToLocalhost": {
"message": "جاري الاتصال بالمضيف المحلي 8545"
},
"connectingToMainnet": {
"message": "جارِ الاتصال بشبكة إيثيريوم الرئيسية"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Свързване с тестовата мрежа на Kovan"
},
"connectingToLocalhost": {
"message": "Свързване с Localhost 8545"
},
"connectingToMainnet": {
"message": "Свързване с главната мрежа Ethereum"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "কন টট নটওয়র সগ করছ"
},
"connectingToLocalhost": {
"message": "ললহট 8545 এর সগ করছ"
},
"connectingToMainnet": {
"message": "ময Ethereum নটওয়র সগ করছ"
},

@ -215,9 +215,6 @@
"connectingToKovan": {
"message": "Conectant a la xarxa de Kovan Test"
},
"connectingToLocalhost": {
"message": "Connectant al host local 8545"
},
"connectingToMainnet": {
"message": "Connectant a Xarxa Principal Ethereum"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Forbinder til Kovan Testnetværk"
},
"connectingToLocalhost": {
"message": "Opretter forbindelse til Localhost 8545"
},
"connectingToMainnet": {
"message": "Forbinder til dit Primære Ethereum Netværk"
},

@ -209,9 +209,6 @@
"connectingToKovan": {
"message": " Verbinde zum Kovan Testnetzwerk"
},
"connectingToLocalhost": {
"message": "Verbindung mit Localhost 8545 herstellen"
},
"connectingToMainnet": {
"message": "Verbinde zum Ethereum Main Net"
},

@ -215,9 +215,6 @@
"connectingToKovan": {
"message": "Σύνδεση στο Δοκιμαστικό Δίκτυο Kovan"
},
"connectingToLocalhost": {
"message": "Σύνδεση στον Τοπικό Υπολογιστή 8545"
},
"connectingToMainnet": {
"message": "Σύνδεση στο Κύριο Δίκτυο Ethereum"
},

@ -340,9 +340,6 @@
"connectingToKovan": {
"message": "Connecting to Kovan Test Network"
},
"connectingToLocalhost": {
"message": "Connecting to Localhost 8545"
},
"connectingToMainnet": {
"message": "Connecting to Ethereum Mainnet"
},

@ -187,9 +187,6 @@
"connectingToKovan": {
"message": "Conectando a la red de test Kovan"
},
"connectingToLocalhost": {
"message": "Conectando to Localhost 8545"
},
"connectingToMainnet": {
"message": "Conectando a la red principal de Ethereum (Main Net)"
},

@ -215,9 +215,6 @@
"connectingToKovan": {
"message": "Conexión con la red de prueba Kovan"
},
"connectingToLocalhost": {
"message": "Conexión con Localhost 8545"
},
"connectingToMainnet": {
"message": "Conexión con la red principal de Ethereum"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Ühendamine Kovani testvõrguga"
},
"connectingToLocalhost": {
"message": "Ühenduse loomine Localhost 8545"
},
"connectingToMainnet": {
"message": "Ühenduse loomine peamise Etherumi võrguga"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "در حال اتصال به شبکه آزمایشی Kovan"
},
"connectingToLocalhost": {
"message": "در حال اتصال با Localhost 8545"
},
"connectingToMainnet": {
"message": "در حال اتصال به شبکه اصلی ایتریم"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Yhdistetään Kovanin koeverkkoon"
},
"connectingToLocalhost": {
"message": "Yhdistetään kohteeseen Localhost 8545"
},
"connectingToMainnet": {
"message": "Yhdistetään Ethereumin pääverkkoon"
},

@ -197,9 +197,6 @@
"connectingToKovan": {
"message": "Kumokonekta sa Kovan Test Network"
},
"connectingToLocalhost": {
"message": "Kumokonekta sa Localhost 8545"
},
"connectingToMainnet": {
"message": "Kumokonekta sa Ethereum Mainnet"
},

@ -209,9 +209,6 @@
"connectingToKovan": {
"message": "Connexion au réseau de test Kovan"
},
"connectingToLocalhost": {
"message": "Connexion à Localhost 8545"
},
"connectingToMainnet": {
"message": "Connexion au réseau principal Ethereum"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "מתחבר ל-Kovan Test Network"
},
"connectingToLocalhost": {
"message": "מתחבר אל Localhost 8545"
},
"connectingToMainnet": {
"message": "מתחבר לרשת אתריום הראשית"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "कवन टट नटवरक सड़ रह\n"
},
"connectingToLocalhost": {
"message": "लकलहट 8545 स "
},
"connectingToMainnet": {
"message": "मय Ethereum नटवरक स कनट ह रह"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Povezivanje na testnu mrežu Kovan"
},
"connectingToLocalhost": {
"message": "Povezivanje na Localhost 8545"
},
"connectingToMainnet": {
"message": "Povezivanje na glavnu mrežu Ethereum"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Csatlakozás a Kovan teszthálózathoz"
},
"connectingToLocalhost": {
"message": "Csatlakozás a Localhost 8645-höz"
},
"connectingToMainnet": {
"message": "Csatlakozás a fő Ethereum hálózathoz"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Menyambung ke Jaringan Tes Kovan"
},
"connectingToLocalhost": {
"message": "Menghubungkan ke Localhost 8545"
},
"connectingToMainnet": {
"message": "Menghubungkan ke Jaringan Ethereum Utama"
},

@ -333,9 +333,6 @@
"connectingToKovan": {
"message": "Connessione alla Rete di test Kovan"
},
"connectingToLocalhost": {
"message": "Connessione a Localhost 8545"
},
"connectingToMainnet": {
"message": "Connessione alla Rete Ethereum Principale"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Kovan ಪರವರಪರಿಸಲಿ "
},
"connectingToLocalhost": {
"message": "ಲಕಲ 8545 ಗಪರಿಸಲಿ"
},
"connectingToMainnet": {
"message": "ಮಯ ಎಥಿಯಮವರಪರಿಸಲಿ"
},

@ -215,9 +215,6 @@
"connectingToKovan": {
"message": "Kovan 테스트넷 접속 중"
},
"connectingToLocalhost": {
"message": "로컬호스트 8545에 연결 중"
},
"connectingToMainnet": {
"message": "이더리움 메인넷 접속 중"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Jungiamasi prie „Kovan“ bandomojo tinklo"
},
"connectingToLocalhost": {
"message": "Jungiamasi prie vietinio serverio 8545"
},
"connectingToMainnet": {
"message": "Jungiamasi prie pagrindinio „Ethereum“ tinklo"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Savienojas ar Kovan testa tīklu"
},
"connectingToLocalhost": {
"message": "Savienojas ar vietējo resursdatoru 8545"
},
"connectingToMainnet": {
"message": "Savienojas ar galveno Ethereum tīklu"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Menyambungkan kepada Rangkaian Ujian Kovan"
},
"connectingToLocalhost": {
"message": "Menyambung kepada Localhost 8545"
},
"connectingToMainnet": {
"message": "Menyambung kepada Rangkaian Ethereum Utama"
},

@ -215,9 +215,6 @@
"connectingToKovan": {
"message": "Kobler til Kovan testnettverk"
},
"connectingToLocalhost": {
"message": "Kobler til lokalvert 8545"
},
"connectingToMainnet": {
"message": "Forbinder med hoved-Ethereumnettverk "
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Łączenie z siecią testową Kovan"
},
"connectingToLocalhost": {
"message": "Połączono z serwerem lokalnym 8545"
},
"connectingToMainnet": {
"message": "Łączenie z główną siecią Ethereum"
},

@ -212,9 +212,6 @@
"connectingToKovan": {
"message": "Conectando-se à Rede de Testes Kovan"
},
"connectingToLocalhost": {
"message": "Conectando ao Localhost 8545"
},
"connectingToMainnet": {
"message": "Conectando à rede principal Etherum"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Se conectează la rețeaua de test Kovan"
},
"connectingToLocalhost": {
"message": "Se conectează la localhost 8545"
},
"connectingToMainnet": {
"message": "Se conectează la rețeaua Ethereum principală"
},

@ -217,9 +217,6 @@
"connectingToKovan": {
"message": "Соединение с тестовой сетью Kovan"
},
"connectingToLocalhost": {
"message": "Подключение к Localhost:8545"
},
"connectingToMainnet": {
"message": "Соединение с основной сетью Ethereum"
},

@ -212,9 +212,6 @@
"connectingToKovan": {
"message": "Připojuji se k Kovan Test Network"
},
"connectingToLocalhost": {
"message": "Pripája sa k Localhost 8545"
},
"connectingToMainnet": {
"message": "Připojuji se k Ethereum Mainnet"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Povezovanje na testno omrežje Kovan"
},
"connectingToLocalhost": {
"message": "Povezovanje na lokalnega gostitelja 8545 "
},
"connectingToMainnet": {
"message": "Povezovanje na glavno omrežje"
},

@ -215,9 +215,6 @@
"connectingToKovan": {
"message": "Povezuje se na test mrežu Kovan"
},
"connectingToLocalhost": {
"message": "Povezuje se na lokalnog hosta 8545"
},
"connectingToMainnet": {
"message": "Povezuje se na glavnu Ethereum mrežu"
},

@ -212,9 +212,6 @@
"connectingToKovan": {
"message": "Ansluter till Kovans testnätverk"
},
"connectingToLocalhost": {
"message": "Ansluter till Localhost 8545"
},
"connectingToMainnet": {
"message": "Koppla till Ethereums huvudnätverk"
},

@ -212,9 +212,6 @@
"connectingToKovan": {
"message": "Inaunganisha kwenye Mtandao wa Majaribio wa Kovan"
},
"connectingToLocalhost": {
"message": "Inaunganisha kwenye Localhost 8545"
},
"connectingToMainnet": {
"message": "Inaunganisha kwenye Mtandao Mkuu wa Ethereum"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "Підключення до тестової мережі Kovan"
},
"connectingToLocalhost": {
"message": "Під'єднуємось до локального хосту 8545"
},
"connectingToMainnet": {
"message": "З'єднуємось з Головною мережею Ethereum"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "正在连接到Kovan测试网络"
},
"connectingToLocalhost": {
"message": "正在连接 Localhost 8545"
},
"connectingToMainnet": {
"message": "正在连接到以太坊主网"
},

@ -218,9 +218,6 @@
"connectingToKovan": {
"message": "連線到 Kovan 測試網路"
},
"connectingToLocalhost": {
"message": "連接至本地主機 8545"
},
"connectingToMainnet": {
"message": "連線到主 Ethereum 網路"
},

@ -41,8 +41,7 @@ import {
} from './lib/enums'
/* eslint-enable import/first */
// METAMASK_TEST_CONFIG is used in e2e tests to set the default network to localhost
const firstTimeState = { ...rawFirstTimeState, ...global.METAMASK_TEST_CONFIG }
const firstTimeState = { ...rawFirstTimeState }
log.setDefaultLevel(process.env.METAMASK_DEBUG ? 'debug' : 'warn')

@ -1,3 +1,4 @@
import createAsyncMiddleware from 'json-rpc-engine/src/createAsyncMiddleware'
import mergeMiddleware from 'json-rpc-engine/src/mergeMiddleware'
import createFetchMiddleware from 'eth-json-rpc-middleware/fetch'
import createBlockRefRewriteMiddleware from 'eth-json-rpc-middleware/block-ref-rewrite'
@ -7,12 +8,26 @@ import createBlockTrackerInspectorMiddleware from 'eth-json-rpc-middleware/block
import providerFromMiddleware from 'eth-json-rpc-middleware/providerFromMiddleware'
import BlockTracker from 'eth-block-tracker'
const inTest = process.env.IN_TEST === 'true'
const blockTrackerOpts = inTest
? { pollingInterval: 1000 }
: {}
const getTestMiddlewares = () => {
return inTest
? [createEstimateGasDelayTestMiddleware()]
: []
}
export default function createJsonRpcClient ({ rpcUrl, chainId }) {
const fetchMiddleware = createFetchMiddleware({ rpcUrl })
const blockProvider = providerFromMiddleware(fetchMiddleware)
const blockTracker = new BlockTracker({ provider: blockProvider })
const blockTracker = new BlockTracker({
...blockTrackerOpts,
provider: blockProvider,
})
const networkMiddleware = mergeMiddleware([
...getTestMiddlewares(),
createChainIdMiddleware(chainId),
createBlockRefRewriteMiddleware({ blockTracker }),
createBlockCacheMiddleware({ blockTracker }),
@ -20,6 +35,7 @@ export default function createJsonRpcClient ({ rpcUrl, chainId }) {
createBlockTrackerInspectorMiddleware({ blockTracker }),
fetchMiddleware,
])
return { networkMiddleware, blockTracker }
}
@ -32,3 +48,16 @@ function createChainIdMiddleware (chainId) {
return next()
}
}
/**
* For use in tests only.
* Adds a delay to `eth_estimateGas` calls.
*/
function createEstimateGasDelayTestMiddleware () {
return createAsyncMiddleware(async (req, _, next) => {
if (req.method === 'eth_estimateGas') {
await new Promise((resolve) => setTimeout(resolve, 2000))
}
return next()
})
}

@ -1,36 +0,0 @@
import mergeMiddleware from 'json-rpc-engine/src/mergeMiddleware'
import createFetchMiddleware from 'eth-json-rpc-middleware/fetch'
import createBlockRefRewriteMiddleware from 'eth-json-rpc-middleware/block-ref-rewrite'
import createBlockTrackerInspectorMiddleware from 'eth-json-rpc-middleware/block-tracker-inspector'
import createAsyncMiddleware from 'json-rpc-engine/src/createAsyncMiddleware'
import providerFromMiddleware from 'eth-json-rpc-middleware/providerFromMiddleware'
import BlockTracker from 'eth-block-tracker'
const inTest = process.env.IN_TEST === 'true'
export default function createLocalhostClient () {
const fetchMiddleware = createFetchMiddleware({ rpcUrl: 'http://localhost:8545/' })
const blockProvider = providerFromMiddleware(fetchMiddleware)
const blockTracker = new BlockTracker({ provider: blockProvider, pollingInterval: 1000 })
const networkMiddleware = mergeMiddleware([
createEstimateGasMiddleware(),
createBlockRefRewriteMiddleware({ blockTracker }),
createBlockTrackerInspectorMiddleware({ blockTracker }),
fetchMiddleware,
])
return { networkMiddleware, blockTracker }
}
function delay (time) {
return new Promise((resolve) => setTimeout(resolve, time))
}
function createEstimateGasMiddleware () {
return createAsyncMiddleware(async (req, _, next) => {
if (req.method === 'eth_estimateGas' && inTest) {
await delay(2000)
}
return next()
})
}

@ -3,7 +3,6 @@ export const RINKEBY = 'rinkeby'
export const KOVAN = 'kovan'
export const MAINNET = 'mainnet'
export const GOERLI = 'goerli'
export const LOCALHOST = 'localhost'
export const MAINNET_NETWORK_ID = '1'
export const ROPSTEN_NETWORK_ID = '3'

@ -10,36 +10,33 @@ import EthQuery from 'eth-query'
import createMetamaskMiddleware from './createMetamaskMiddleware'
import createInfuraClient from './createInfuraClient'
import createJsonRpcClient from './createJsonRpcClient'
import createLocalhostClient from './createLocalhostClient'
import {
RINKEBY,
MAINNET,
LOCALHOST,
INFURA_PROVIDER_TYPES,
NETWORK_TYPE_TO_ID_MAP,
} from './enums'
const env = process.env.METAMASK_ENV
let defaultProviderConfigType
let defaultProviderChainId
let defaultProviderConfigOpts
if (process.env.IN_TEST === 'true') {
defaultProviderConfigType = LOCALHOST
// Decimal 5777, an arbitrary chain ID we use for testing
defaultProviderChainId = '0x1691'
defaultProviderConfigOpts = {
type: 'rpc',
rpcUrl: 'http://localhost:8545',
chainId: '0x539',
nickname: 'Localhost 8545',
}
} else if (process.env.METAMASK_DEBUG || env === 'test') {
defaultProviderConfigType = RINKEBY
defaultProviderConfigOpts = { type: RINKEBY }
} else {
defaultProviderConfigType = MAINNET
defaultProviderConfigOpts = { type: MAINNET }
}
const defaultProviderConfig = {
type: defaultProviderConfigType,
ticker: 'ETH',
}
if (defaultProviderChainId) {
defaultProviderConfig.chainId = defaultProviderChainId
...defaultProviderConfigOpts,
}
export default class NetworkController extends EventEmitter {
@ -169,7 +166,7 @@ export default class NetworkController extends EventEmitter {
async setProviderType (type, rpcUrl = '', ticker = 'ETH', nickname = '') {
assert.notEqual(type, 'rpc', `NetworkController - cannot call "setProviderType" with type 'rpc'. use "setRpcTarget"`)
assert(INFURA_PROVIDER_TYPES.includes(type) || type === LOCALHOST, `NetworkController - Unknown rpc type "${type}"`)
assert(INFURA_PROVIDER_TYPES.includes(type), `NetworkController - Unknown rpc type "${type}"`)
const { chainId } = NETWORK_TYPE_TO_ID_MAP[type]
this.setProviderConfig({ type, rpcUrl, chainId, ticker, nickname })
}
@ -205,9 +202,6 @@ export default class NetworkController extends EventEmitter {
const isInfura = INFURA_PROVIDER_TYPES.includes(type)
if (isInfura) {
this._configureInfuraProvider(type, this._infuraProjectId)
// other type-based rpc endpoints
} else if (type === LOCALHOST) {
this._configureLocalhostProvider()
// url-based rpc endpoints
} else if (type === 'rpc') {
this._configureStandardProvider(rpcUrl, chainId)
@ -225,12 +219,6 @@ export default class NetworkController extends EventEmitter {
this._setNetworkClient(networkClient)
}
_configureLocalhostProvider () {
log.info('NetworkController - configureLocalhostProvider')
const networkClient = createLocalhostClient()
this._setNetworkClient(networkClient)
}
_configureStandardProvider (rpcUrl, chainId) {
log.info('NetworkController - configureStandardProvider', rpcUrl)
const networkClient = createJsonRpcClient({ rpcUrl, chainId })

@ -553,11 +553,8 @@ export default class PreferencesController {
*
*/
addToFrequentRpcList (rpcUrl, chainId, ticker = 'ETH', nickname = '', rpcPrefs = {}) {
if (rpcUrl === 'http://localhost:8545') {
return
}
const rpcList = this.getFrequentRpcListDetail()
const index = rpcList.findIndex((element) => {
return element.rpcUrl === rpcUrl
})

@ -10,6 +10,17 @@
*/
const initialState = {
config: {},
PreferencesController: {
frequentRpcListDetail: [
{
rpcUrl: 'http://localhost:8545',
chainId: '0x539',
ticker: 'ETH',
nickname: 'Localhost 8545',
rpcPrefs: {},
},
],
},
}
export default initialState

@ -4,9 +4,10 @@ const version = 48
/**
* 1. Delete NetworkController.settings
* 2a. Delete NetworkController.provider if set to type 'rpc'.
* 2a. Delete NetworkController.provider if set to type 'rpc' or 'localhost'.
* It will be re-set to Mainnet on background initialization.
* 2b. Re-key provider.rpcTarget to provider.rpcUrl
* 3. Add localhost network to frequentRpcListDetail.
*/
export default {
version,
@ -24,7 +25,8 @@ function transformState (state = {}) {
delete state.NetworkController?.settings
// 2. Delete NetworkController.provider or rename rpcTarget key
if (state.NetworkController?.provider?.type === 'rpc') {
const providerType = state.NetworkController?.provider?.type
if (providerType === 'rpc' || providerType === 'localhost') {
delete state.NetworkController.provider
} else if (state.NetworkController?.provider) {
if ('rpcTarget' in state.NetworkController.provider) {
@ -34,5 +36,20 @@ function transformState (state = {}) {
delete state.NetworkController?.provider?.rpcTarget
}
// 3. Add localhost network to frequentRpcListDetail.
if (!state.PreferencesController) {
state.PreferencesController = {}
}
if (!state.PreferencesController.frequentRpcListDetail) {
state.PreferencesController.frequentRpcListDetail = []
}
state.PreferencesController.frequentRpcListDetail.unshift({
rpcUrl: 'http://localhost:8545',
chainId: '0x539',
ticker: 'ETH',
nickname: 'Localhost 8545',
rpcPrefs: {},
})
return state
}

@ -23,7 +23,7 @@ trap _term SIGTERM
trap _int SIGINT
# shellcheck disable=SC2086
$ganache_cli --noVMErrorsOnRPCResponse --networkId 5777 --mnemonic "$seed_phrase" ${GANACHE_ARGS:-} &
$ganache_cli --noVMErrorsOnRPCResponse --networkId 1337 --mnemonic "$seed_phrase" ${GANACHE_ARGS:-} &
child=$!
wait "$child"

@ -136,7 +136,7 @@ describe('MetaMask', function () {
it('has the ganache network id within the dapp', async function () {
const networkDiv = await driver.findElement(By.css('#network'))
await driver.delay(regularDelayMs)
assert.equal(await networkDiv.getText(), '5777')
assert.equal(await networkDiv.getText(), '1337')
})
it('changes the network', async function () {

@ -28,13 +28,13 @@
"vault": "{\"data\":\"s6TpYjlUNsn7ifhEFTkuDGBUM1GyOlPrim7JSjtfIxgTt8/6MiXgiR/CtFfR4dWW2xhq85/NGIBYEeWrZThGdKGarBzeIqBfLFhw9n509jprzJ0zc2Rf+9HVFGLw+xxC4xPxgCS0IIWeAJQ+XtGcHmn0UZXriXm8Ja4kdlow6SWinB7sr/WM3R0+frYs4WgllkwggDf2/Tv6VHygvLnhtzp6hIJFyTjh+l/KnyJTyZW1TkZhDaNDzX3SCOHT\",\"iv\":\"FbeHDAW5afeWNORfNJBR0Q==\",\"salt\":\"TxZ+WbCW6891C9LK/hbMAoUsSEW1E8pyGLVBU6x5KR8=\"}"
},
"NetworkController": {
"network": "5777",
"network": "1337",
"provider": {
"nickname": "",
"rpcUrl": "",
"chainId": "0x1691",
"nickname": "Localhost 8545",
"rpcUrl": "http://localhost:8545",
"chainId": "0x539",
"ticker": "ETH",
"type": "localhost"
"type": "rpc"
}
},
"OnboardingController": {

@ -28,13 +28,13 @@
"vault": "{\"data\":\"s6TpYjlUNsn7ifhEFTkuDGBUM1GyOlPrim7JSjtfIxgTt8/6MiXgiR/CtFfR4dWW2xhq85/NGIBYEeWrZThGdKGarBzeIqBfLFhw9n509jprzJ0zc2Rf+9HVFGLw+xxC4xPxgCS0IIWeAJQ+XtGcHmn0UZXriXm8Ja4kdlow6SWinB7sr/WM3R0+frYs4WgllkwggDf2/Tv6VHygvLnhtzp6hIJFyTjh+l/KnyJTyZW1TkZhDaNDzX3SCOHT\",\"iv\":\"FbeHDAW5afeWNORfNJBR0Q==\",\"salt\":\"TxZ+WbCW6891C9LK/hbMAoUsSEW1E8pyGLVBU6x5KR8=\"}"
},
"NetworkController": {
"network": "5777",
"network": "1337",
"provider": {
"nickname": "",
"rpcUrl": "",
"chainId": "0x1691",
"nickname": "Localhost 8545",
"rpcUrl": "http://localhost:8545",
"chainId": "0x539",
"ticker": "ETH",
"type": "localhost"
"type": "rpc"
}
},
"OnboardingController": {

@ -7,7 +7,7 @@
"CachedBalancesController": {
"cachedBalances": {
"4": {},
"5777": {
"1337": {
"0x5cfe73b6021e818b776b421b1c4db2474086a7e1": "0x15af1d78b58c40000"
}
}
@ -33,13 +33,13 @@
},
"NetworkController": {
"provider": {
"nickname": "",
"rpcUrl": "",
"chainId": "0x1691",
"nickname": "Localhost 8545",
"rpcUrl": "http://localhost:8545",
"chainId": "0x539",
"ticker": "ETH",
"type": "localhost"
"type": "rpc"
},
"network": "5777"
"network": "1337"
},
"OnboardingController": {
"onboardingTabs": {},

@ -3,7 +3,7 @@ const ganache = require('ganache-core')
const defaultOptions = {
blockTime: 2,
network_id: 5777,
network_id: 1337,
mnemonic: 'phrase upgrade clock rough situate wedding elder clever doctor stamp excess tent',
port: 8545,
vmErrorsOnRPCResponse: false,

@ -76,6 +76,7 @@ const TEST_ADDRESS_3 = '0xeb9e64b93097bc15f01f13eae97015c57ab64823'
const TEST_SEED_ALT = 'setup olympic issue mobile velvet surge alcohol burger horse view reopen gentle'
const TEST_ADDRESS_ALT = '0xc42edfcc21ed14dda456aa0756c153f7985d8813'
const CUSTOM_RPC_URL = 'http://localhost:8545'
const CUSTOM_RPC_CHAIN_ID = '0x539'
describe('MetaMaskController', function () {
let metamaskController
@ -530,7 +531,10 @@ describe('MetaMaskController', function () {
let rpcUrl
beforeEach(function () {
rpcUrl = metamaskController.setCustomRpc(CUSTOM_RPC_URL)
rpcUrl = metamaskController.setCustomRpc(
CUSTOM_RPC_URL,
CUSTOM_RPC_CHAIN_ID,
)
})
it('returns custom RPC that when called', async function () {

@ -522,10 +522,27 @@ describe('preferences controller', function () {
describe('adding and removing from frequentRpcListDetail', function () {
it('should add custom RPC url to state', function () {
preferencesController.addToFrequentRpcList('rpc_url', '0x1')
preferencesController.addToFrequentRpcList('http://localhost:8545', '0x1')
assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: '0x1', ticker: 'ETH', nickname: '', rpcPrefs: {} }])
assert.deepEqual(
preferencesController.store.getState().frequentRpcListDetail,
[{
rpcUrl: 'rpc_url',
chainId: '0x1',
ticker: 'ETH',
nickname: '',
rpcPrefs: {},
}],
)
preferencesController.addToFrequentRpcList('rpc_url', '0x1')
assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [{ rpcUrl: 'rpc_url', chainId: '0x1', ticker: 'ETH', nickname: '', rpcPrefs: {} }])
assert.deepEqual(
preferencesController.store.getState().frequentRpcListDetail,
[{
rpcUrl: 'rpc_url',
chainId: '0x1',
ticker: 'ETH',
nickname: '',
rpcPrefs: {},
}],
)
})
it('should throw if chainId is invalid', function () {

@ -14,6 +14,7 @@ const initialState = {
provider: {
type: 'rpc',
rpcUrl: 'http://localhost:8545',
chainId: '0x539',
},
},
}

@ -1,6 +1,21 @@
import { strict as assert } from 'assert'
import migration48 from '../../../app/scripts/migrations/048'
const localhostNetwork = {
rpcUrl: 'http://localhost:8545',
chainId: '0x539',
ticker: 'ETH',
nickname: 'Localhost 8545',
rpcPrefs: {},
}
const expectedPreferencesState = {
PreferencesController: {
frequentRpcListDetail: [{
...localhostNetwork,
}],
},
}
describe('migration #48', function () {
it('should update the version metadata', async function () {
const oldStorage = {
@ -34,6 +49,7 @@ describe('migration #48', function () {
const newStorage = await migration48.migrate(oldStorage)
assert.deepEqual(newStorage.data, {
...expectedPreferencesState,
NetworkController: {
provider: {
type: 'notRpc',
@ -60,6 +76,7 @@ describe('migration #48', function () {
const newStorage = await migration48.migrate(oldStorage)
assert.deepEqual(newStorage.data, {
...expectedPreferencesState,
NetworkController: {
foo: 'bar',
},
@ -67,7 +84,32 @@ describe('migration #48', function () {
})
})
it('should re-key NetworkController.provider.rpcTarget to rpcUrl if the type is not "rpc"', async function () {
it('should delete NetworkController.provider if the type is "localhost"', async function () {
const oldStorage = {
meta: {},
data: {
NetworkController: {
provider: {
type: 'localhost',
fizz: 'buzz',
},
foo: 'bar',
},
foo: 'bar',
},
}
const newStorage = await migration48.migrate(oldStorage)
assert.deepEqual(newStorage.data, {
...expectedPreferencesState,
NetworkController: {
foo: 'bar',
},
foo: 'bar',
})
})
it('should re-key NetworkController.provider.rpcTarget to rpcUrl if the type is not "rpc" or "localhost"', async function () {
const oldStorage = {
meta: {},
data: {
@ -85,6 +127,7 @@ describe('migration #48', function () {
const newStorage = await migration48.migrate(oldStorage)
assert.deepEqual(newStorage.data, {
...expectedPreferencesState,
NetworkController: {
foo: 'bar',
provider: {
@ -97,7 +140,7 @@ describe('migration #48', function () {
})
})
it('should do nothing if affected state does not exist', async function () {
it('should do nothing to NetworkController if affected state does not exist', async function () {
const oldStorage = {
meta: {},
data: {
@ -111,16 +154,39 @@ describe('migration #48', function () {
}
const newStorage = await migration48.migrate(oldStorage)
assert.deepEqual(oldStorage.data, newStorage.data)
assert.deepEqual(
{ ...oldStorage.data, ...expectedPreferencesState },
{ ...newStorage.data, ...expectedPreferencesState },
)
})
it('should do nothing if state is empty', async function () {
it('should add frequentRpcListDetail item to beginning of list', async function () {
const existingList = [
{ rpcUrl: 'foo', chainId: '0x1' },
{ rpcUrl: 'bar', chainId: '0x2' },
]
const oldStorage = {
meta: {},
data: {},
data: {
PreferencesController: {
frequentRpcListDetail: [
...existingList,
],
},
foo: 'bar',
},
}
const newStorage = await migration48.migrate(oldStorage)
assert.deepEqual(oldStorage.data, newStorage.data)
assert.deepEqual(newStorage.data, {
PreferencesController: {
frequentRpcListDetail: [
{ ...localhostNetwork },
...existingList,
],
},
foo: 'bar',
})
})
})

@ -101,10 +101,6 @@ class NetworkDropdown extends Component {
provider.type === 'rpc' && rpcUrl === provider.rpcUrl
)
if (rpcUrl === 'http://localhost:8545') {
return null
}
return (
<DropdownMenuItem
key={`common${rpcUrl}`}
@ -170,8 +166,6 @@ class NetworkDropdown extends Component {
name = this.context.t('kovan')
} else if (providerName === 'rinkeby') {
name = this.context.t('rinkeby')
} else if (providerName === 'localhost') {
name = this.context.t('localhost')
} else if (providerName === 'goerli') {
name = this.context.t('goerli')
} else {
@ -339,29 +333,6 @@ class NetworkDropdown extends Component {
{this.context.t('goerli')}
</span>
</DropdownMenuItem>
<DropdownMenuItem
key="default"
closeMenu={() => this.props.hideNetworkDropdown()}
onClick={() => this.handleClick('localhost')}
style={dropdownMenuItemStyle}
>
{
providerType === 'localhost'
? <i className="fa fa-check" />
: <div className="network-check__transparent"></div>
}
<NetworkDropdownIcon isSelected={providerType === 'localhost'} innerBorder="1px solid #9b9b9b" />
<span
className="network-name-item"
style={{
color: providerType === 'localhost'
? '#ffffff'
: '#9b9b9b',
}}
>
{this.context.t('localhost')}
</span>
</DropdownMenuItem>
{this.renderCustomRpcList(rpcListDetail, this.props.provider)}
<DropdownMenuItem
closeMenu={() => this.props.hideNetworkDropdown()}

@ -66,8 +66,8 @@ describe('Network Dropdown', function () {
)
})
it('renders 9 DropDownMenuItems ', function () {
assert.equal(wrapper.find(DropdownMenuItem).length, 9)
it('renders 8 DropDownMenuItems ', function () {
assert.equal(wrapper.find(DropdownMenuItem).length, 8)
})
it('checks background color for first NetworkDropdownIcon', function () {
@ -95,12 +95,7 @@ describe('Network Dropdown', function () {
})
it('checks dropdown for frequestRPCList from state', function () {
assert.equal(wrapper.find(DropdownMenuItem).at(6).text(), '✓http://localhost:7546')
assert.equal(wrapper.find(DropdownMenuItem).at(6).text(), '✓http://localhost:7545')
})
it('checks background color for seventh NetworkDropdownIcon', function () {
assert.equal(wrapper.find(NetworkDropdownIcon).at(6).prop('innerBorder'), '1px solid #9b9b9b')
})
})
})

@ -45,8 +45,6 @@ export default class LoadingNetworkScreen extends PureComponent {
name = this.context.t('connectingToKovan')
} else if (providerName === 'rinkeby') {
name = this.context.t('connectingToRinkeby')
} else if (providerName === 'localhost') {
name = this.context.t('connectingToLocalhost')
} else if (providerName === 'goerli') {
name = this.context.t('connectingToGoerli')
} else {

@ -153,11 +153,7 @@ export default class Network extends Component {
)
}
<div className="network-name">
{
providerName === 'localhost'
? t('localhost')
: providerNick || t('privateNetwork')
}
{providerNick || t('privateNetwork')}
</div>
</NetworkIndicator>
)

@ -34,7 +34,7 @@ Object.keys(valueTable).forEach((currency) => {
})
export function isEthNetwork (netId) {
if (!netId || netId === '1' || netId === '3' || netId === '4' || netId === '42' || netId === '5777') {
if (!netId || netId === '1' || netId === '3' || netId === '4' || netId === '42' || netId === '1337') {
return true
}

@ -315,8 +315,6 @@ export default class Routes extends Component {
return this.context.t('connectingToKovan')
case 'rinkeby':
return this.context.t('connectingToRinkeby')
case 'localhost':
return this.context.t('connectingToLocalhost')
case 'goerli':
return this.context.t('connectingToGoerli')
default:
@ -334,8 +332,6 @@ export default class Routes extends Component {
return this.context.t('kovan')
case 'rinkeby':
return this.context.t('rinkeby')
case 'localhost':
return this.context.t('localhost')
case 'goerli':
return this.context.t('goerli')
default:

@ -3,7 +3,6 @@ import {
GOERLI_CHAIN_ID,
KOVAN,
KOVAN_CHAIN_ID,
LOCALHOST,
MAINNET,
MAINNET_CHAIN_ID,
RINKEBY,
@ -58,14 +57,6 @@ const defaultNetworksData = [
ticker: 'ETH',
blockExplorerUrl: 'https://etherscan.io',
},
{
labelKey: LOCALHOST,
iconColor: 'white',
border: '1px solid #6A737D',
providerType: LOCALHOST,
rpcUrl: 'http://localhost:8545/',
blockExplorerUrl: 'https://etherscan.io',
},
]
export {

Loading…
Cancel
Save