Skip to content

Commit

Permalink
Integrate pylon evm (#1478)
Browse files Browse the repository at this point in the history
* bump version

* remove infura and alchemy presets, use pylon

* update package lock

* remove gnosis chain preset

* fix chain name
  • Loading branch information
mholtzman committed Apr 19, 2023
1 parent 0d8ebee commit 186c9f6
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 39 deletions.
4 changes: 1 addition & 3 deletions main/chains/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 16 additions & 32 deletions main/store/state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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'
}
}
},
Expand All @@ -296,7 +280,7 @@ const initial = {
connection: {
primary: {
on: true,
current: 'infura',
current: 'pylon',
status: 'loading',
connected: false,
type: '',
Expand Down Expand Up @@ -331,7 +315,7 @@ const initial = {
connection: {
primary: {
on: true,
current: 'infura',
current: 'pylon',
status: 'loading',
connected: false,
type: '',
Expand Down Expand Up @@ -366,7 +350,7 @@ const initial = {
connection: {
primary: {
on: true,
current: 'infura',
current: 'pylon',
status: 'loading',
connected: false,
type: '',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -436,7 +420,7 @@ const initial = {
connection: {
primary: {
on: true,
current: 'infura',
current: 'pylon',
status: 'loading',
connected: false,
type: '',
Expand Down Expand Up @@ -471,7 +455,7 @@ const initial = {
connection: {
primary: {
on: true,
current: 'infura',
current: 'pylon',
status: 'loading',
connected: false,
type: '',
Expand Down Expand Up @@ -541,7 +525,7 @@ const initial = {
connection: {
primary: {
on: true,
current: 'infura',
current: 'pylon',
status: 'loading',
connected: false,
type: '',
Expand Down
180 changes: 176 additions & 4 deletions test/main/store/migrations/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {} })
})
})

0 comments on commit 186c9f6

Please sign in to comment.