From 186c9f6a619c578ccdd13a64cab5a7fb18346a18 Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Fri, 10 Mar 2023 08:46:18 +0800 Subject: [PATCH] Integrate pylon evm (#1478) * bump version * remove infura and alchemy presets, use pylon * update package lock * remove gnosis chain preset * fix chain name --- main/chains/index.js | 4 +- main/store/state/index.js | 48 ++---- test/main/store/migrations/index.test.js | 180 ++++++++++++++++++++++- 3 files changed, 193 insertions(+), 39 deletions(-) diff --git a/main/chains/index.js b/main/chains/index.js index 249456c99..b7c8b0d54 100644 --- a/main/chains/index.js +++ b/main/chains/index.js @@ -69,9 +69,7 @@ class ChainConnection extends EventEmitter { this[priority].provider = provider(target, { name: priority, - origin: 'frame', - infuraId: '786ade30f36244469480aa5c2bf0743b', - alchemyId: 'NBms1eV9i16RFHpFqQxod56OLdlucIq0' + origin: 'frame' }) this[priority].blockMonitor = this._createBlockMonitor(this[priority].provider, priority) diff --git a/main/store/state/index.js b/main/store/state/index.js index a663a34c9..80c10e347 100644 --- a/main/store/state/index.js +++ b/main/store/state/index.js @@ -164,7 +164,7 @@ const initial = { }, platform: process.platform, main: { - _version: main('_version', 32), + _version: main('_version', 36), instanceId: main('instanceId', generateUuid()), colorway: main('colorway', 'dark'), colorwayPrimary: { @@ -243,38 +243,22 @@ const initial = { local: 'direct' }, 1: { - alchemy: 'alchemy', - infura: 'infura' - }, - 3: { - alchemy: 'alchemyRopsten', - infura: 'infuraRopsten' - }, - 4: { - alchemy: 'alchemyRinkeby', - infura: 'infuraRinkeby' + pylon: 'wss://evm.pylon.link/mainnet' }, 5: { - infura: 'infuraGoerli' + pylon: 'wss://evm.pylon.link/goerli' }, 10: { - infura: 'infuraOptimism' - }, - 42: { - alchemy: 'alchemyKovan', - infura: 'infuraKovan' - }, - 100: { - poa: 'gnosis' + pylon: 'wss://evm.pylon.link/optimism' }, 137: { - infura: 'infuraPolygon' + pylon: 'wss://evm.pylon.link/polygon' }, 42161: { - infura: 'infuraArbitrum' + pylon: 'wss://evm.pylon.link/arbitrum' }, 11155111: { - infura: 'infuraSepolia' + pylon: 'wss://evm.pylon.link/sepolia' } } }, @@ -296,7 +280,7 @@ const initial = { connection: { primary: { on: true, - current: 'infura', + current: 'pylon', status: 'loading', connected: false, type: '', @@ -331,7 +315,7 @@ const initial = { connection: { primary: { on: true, - current: 'infura', + current: 'pylon', status: 'loading', connected: false, type: '', @@ -366,7 +350,7 @@ const initial = { connection: { primary: { on: true, - current: 'infura', + current: 'pylon', status: 'loading', connected: false, type: '', @@ -400,13 +384,13 @@ const initial = { }, connection: { primary: { - on: true, - current: 'poa', + on: false, + current: 'custom', status: 'loading', connected: false, type: '', network: '', - custom: '' + custom: 'https://rpc.gnosischain.com' }, secondary: { on: false, @@ -436,7 +420,7 @@ const initial = { connection: { primary: { on: true, - current: 'infura', + current: 'pylon', status: 'loading', connected: false, type: '', @@ -471,7 +455,7 @@ const initial = { connection: { primary: { on: true, - current: 'infura', + current: 'pylon', status: 'loading', connected: false, type: '', @@ -541,7 +525,7 @@ const initial = { connection: { primary: { on: true, - current: 'infura', + current: 'pylon', status: 'loading', connected: false, type: '', diff --git a/test/main/store/migrations/index.test.js b/test/main/store/migrations/index.test.js index a7c4ee186..fa59a81e8 100644 --- a/test/main/store/migrations/index.test.js +++ b/test/main/store/migrations/index.test.js @@ -14,6 +14,11 @@ afterAll(() => { log.transports.console.level = 'debug' }) +const createChainState = (chainId) => { + state.main.networks.ethereum[chainId] = { id: chainId } + state.main.networksMeta.ethereum[chainId] = { nativeCurrency: {} } +} + beforeEach(() => { state = { main: { @@ -1332,10 +1337,6 @@ describe('migration 32', () => { describe('migration 34', () => { const getNativeCurrency = (state, chainId) => state.main.networksMeta.ethereum[chainId].nativeCurrency - const createChainState = (chainId) => { - state.main.networks.ethereum[chainId] = { id: chainId } - state.main.networksMeta.ethereum[chainId] = { nativeCurrency: {} } - } const expectedData = { 1: { @@ -1475,3 +1476,174 @@ describe('migration 35', () => { }) }) }) + +describe('migration 36', () => { + beforeEach(() => { + state.main._version = 35 + }) + const providers = ['infura', 'alchemy'] + + const pylonChains = [ + [1, 'Mainnet'], + [5, 'Goerli'], + [10, 'Optimism'], + [137, 'Polygon'], + [42161, 'Arbitrum'], + [11155111, 'Sepolia'] + ] + + pylonChains.forEach(([id, chainName]) => { + providers.forEach((provider) => { + it(`should migrate a primary ${chainName} ${provider} connection to use Pylon`, () => { + createChainState(id) + state.main.networks.ethereum[id].connection = { + primary: { current: provider, on: true, connected: false }, + secondary: { current: 'custom', on: false, connected: false } + } + + const updatedState = migrations.apply(state, 36) + + const { + connection: { primary, secondary } + } = updatedState.main.networks.ethereum[id] + + expect(primary.current).toBe('pylon') + expect(secondary.current).toBe('custom') + }) + + it(`should migrate a secondary ${chainName} ${provider} connection to use Pylon`, () => { + createChainState(id) + state.main.networks.ethereum[id].connection = { + primary: { current: 'local', on: true, connected: false }, + secondary: { current: provider, on: false, connected: false } + } + + const updatedState = migrations.apply(state, 36) + + const { + connection: { primary, secondary } + } = updatedState.main.networks.ethereum[id] + + expect(primary.current).toBe('local') + expect(secondary.current).toBe('pylon') + }) + }) + }) + + // these chains will not be supported by Pylon + const retiredChains = [ + [3, 'Ropsten'], + [4, 'Rinkeby'], + [42, 'Kovan'] + ] + + retiredChains.forEach(([id, chainName]) => { + providers.forEach((provider) => { + it(`should remove a primary ${chainName} ${provider} connection`, () => { + createChainState(id) + state.main.networks.ethereum[id].connection = { + primary: { current: provider, on: true, connected: false }, + secondary: { current: 'custom', on: false, connected: false } + } + + const updatedState = migrations.apply(state, 36) + + const { + connection: { primary } + } = updatedState.main.networks.ethereum[id] + + expect(primary.current).toBe('custom') + expect(primary.on).toBe(false) + }) + + it(`should remove a secondary ${chainName} ${provider} connection`, () => { + createChainState(id) + state.main.networks.ethereum[id].connection = { + primary: { current: 'local', on: true, connected: false }, + secondary: { current: provider, on: false, connected: false } + } + + const updatedState = migrations.apply(state, 36) + + const { + connection: { secondary } + } = updatedState.main.networks.ethereum[id] + + expect(secondary.current).toBe('custom') + expect(secondary.on).toBe(false) + }) + }) + }) + + it('should not migrate an existing custom infura connection on a Pylon chain', () => { + createChainState(10) + state.main.networks.ethereum[10].connection = { + primary: { + current: 'custom', + custom: 'https://optimism-mainnet.infura.io/v3/myapikey', + on: true, + connected: false + }, + secondary: { current: 'custom', on: false, connected: false } + } + + const updatedState = migrations.apply(state, 36) + + const { + connection: { primary, secondary } + } = updatedState.main.networks.ethereum[10] + + expect(primary.current).toBe('custom') + expect(primary.on).toBe(true) + expect(primary.custom).toBe('https://optimism-mainnet.infura.io/v3/myapikey') + expect(secondary.current).toBe('custom') + }) +}) + +describe('migration 37', () => { + beforeEach(() => { + state.main._version = 36 + + state.main.networks.ethereum = { + 100: { + connection: { + primary: { current: 'custom' }, + secondary: { current: 'local' } + } + } + } + }) + + const connectionPriorities = ['primary', 'secondary'] + + connectionPriorities.forEach((priority) => { + it(`updates a ${priority} Gnosis connection`, () => { + state.main.networks.ethereum[100].connection[priority].current = 'poa' + + const updatedState = migrations.apply(state, 37) + const gnosis = updatedState.main.networks.ethereum[100] + + expect(gnosis.connection[priority].current).toBe('custom') + expect(gnosis.connection[priority].custom).toBe('https://rpc.gnosischain.com') + }) + + it(`does not update an existing custom ${priority} Gnosis connection`, () => { + state.main.networks.ethereum[100].connection[priority].current = 'custom' + state.main.networks.ethereum[100].connection[priority].custom = 'https://myconnection.io' + + const updatedState = migrations.apply(state, 37) + const gnosis = updatedState.main.networks.ethereum[100] + + expect(gnosis.connection[priority].current).toBe('custom') + expect(gnosis.connection[priority].custom).toBe('https://myconnection.io') + }) + }) + + it('takes no action if no Gnosis chain is present', () => { + delete state.main.networks.ethereum[100] + + const updatedState = migrations.apply(state, 37) + + expect(updatedState.main.networks).toStrictEqual({ ethereum: {} }) + }) +})