Skip to content

Commit

Permalink
add migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mholtzman committed Oct 6, 2021
1 parent 3b5d4c7 commit 64d02b1
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
14 changes: 13 additions & 1 deletion main/store/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ const migrations = {
return initial
},
10: initial => { // Add Optimism to persisted networks
// if (!initial.main.networks.ethereum[10]) {
initial.main.networks.ethereum[10] = {
id: 10,
type: 'ethereum',
Expand Down Expand Up @@ -338,6 +337,19 @@ const migrations = {
}
}

return initial
},
15: initial => {
// Polygon
if (initial.main.networks.ethereum['137']) {
const oldExplorer = initial.main.networks.ethereum['137'].explorer

if (!oldExplorer || oldExplorer.endsWith('explorer.matic.network')) {
// only replace if it hasn't been changed from the initial setting
initial.main.networks.ethereum['137'].explorer = 'https://polygonscan.com'
}
}

return initial
}
}
Expand Down
60 changes: 60 additions & 0 deletions test/main/store/migrations/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,63 @@ describe('migration 14', () => {
expect(arbitrum.gas.fees.maxFeePerGas).toBe('0xf')
})
})

describe('migration 15', () => {
beforeEach(() => {
state = {
main: {
_version: 14,
networks: {
ethereum: {
137: {
id: 1,
type: 'ethereum',
layer: 'sidechain',
symbol: 'MATIC',
name: 'Polygon',
explorer: 'https://explorer.matic.network',
connection: {
primary: {
on: true,
current: 'matic'
},
secondary: {
on: false,
current: 'local'
}
}
}
}
},
networksMeta: {
ethereum: { }
}
}
}
})

it('updates the initial explorer for Polygon', () => {
const updatedState = migrations.apply(state)
const polygon = updatedState.main.networks.ethereum['137']

expect(polygon.explorer).toBe('https://polygonscan.com')
})

it('adds the Polygon explorer if one does not exist', () => {
delete state.main.networks.ethereum['137'].explorer

const updatedState = migrations.apply(state)
const polygon = updatedState.main.networks.ethereum['137']

expect(polygon.explorer).toBe('https://polygonscan.com')
})

it('does not update the Polygon explorer if it has been manually changed', () => {
state.main.networks.ethereum['137'].explorer = 'https://custom-explorer.io'

const updatedState = migrations.apply(state)
const polygon = updatedState.main.networks.ethereum['137']

expect(polygon.explorer).toBe('https://custom-explorer.io')
})
})

0 comments on commit 64d02b1

Please sign in to comment.