Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mholtzman committed Mar 12, 2024
1 parent 48d8f0d commit ff95795
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 97 deletions.
6 changes: 3 additions & 3 deletions main/store/migrate/migrations/42/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function removeGoerliPylonPreset(connection: v38Connection) {
const isPylon = connection.current === 'pylon'

if (isPylon) {
log.info('Migration 41: removing Pylon presets from Goerli')
log.info('Migration 42: removing Pylon presets from Goerli')
}

return {
Expand All @@ -148,7 +148,7 @@ function removeBaseGoerliConnection(connection: v38Connection) {
const isPylon = connection.current === 'pylon'

if (isPylon) {
log.info('Migration 41: removing Pylon presets from Base Goerli')
log.info('Migration 42: removing Pylon presets from Base Goerli')
}

return {
Expand Down Expand Up @@ -208,7 +208,7 @@ const migrate = (initial: unknown) => {

return state
} catch (e) {
log.error('Migration 41: could not parse state', e)
log.error('Migration 42: could not parse state', e)
}

return initial
Expand Down
18 changes: 9 additions & 9 deletions test/main/chains/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ const state = {
main: {
currentNetwork: {
type: 'ethereum',
id: '5'
id: '11155111'
},
networks: {
ethereum: {
5: {
id: 5,
11155111: {
id: 11155111,
type: 'ethereum',
name: 'Goerli',
name: 'Sepolia',
connection: {
primary: {
on: false,
Expand Down Expand Up @@ -115,7 +115,7 @@ const state = {
},
networksMeta: {
ethereum: {
5: {
11155111: {
gas: {
price: {
selected: 'standard',
Expand All @@ -142,10 +142,10 @@ jest.mock('../../../main/accounts', () => ({ updatePendingFees: jest.fn() }))
jest.mock('../../../main/store/persist')

const mockConnections = {
'wss://evm.pylon.link/goerli': {
id: '5',
name: 'goerli',
connection: new MockConnection(5)
'wss://evm.pylon.link/sepolia': {
id: '11155111',
name: 'sepolia',
connection: new MockConnection(11155111)
},
'wss://evm.pylon.link/polygon': {
id: '137',
Expand Down
78 changes: 39 additions & 39 deletions test/main/provider/chains/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ const chains = {
connection: { primary: { connected: true }, secondary: { connected: false } },
on: true
},
5: {
name: 'Ethereum Testnet Görli',
id: 5,
explorer: 'https://goerli.etherscan.io',
connection: {
primary: { status: 'disconnected', connected: false, on: true },
secondary: { status: 'disconnected', connected: false, on: true }
},
on: true
},
137: {
name: 'Polygon',
id: 137,
connection: { primary: { connected: true }, secondary: { connected: false } },
on: false
},
11155111: {
name: 'Ethereum Testnet Sepolia',
id: 11155111,
explorer: 'https://sepolia.etherscan.io',
connection: {
primary: { status: 'disconnected', connected: false, on: true },
secondary: { status: 'disconnected', connected: false, on: true }
},
on: true
}
}

Expand All @@ -45,14 +45,14 @@ const chainMeta = {
nativeCurrency: ether,
primaryColor: 'accent1'
},
5: {
137: { nativeCurrency: {}, primaryColor: 'accent6' },
11155111: {
nativeCurrency: {
...ether,
name: 'Görli Ether'
name: 'Sepolia Ether'
},
primaryColor: 'accent2'
},
137: { nativeCurrency: {}, primaryColor: 'accent6' }
}
}

const selectedAddress = '0x2796317b0ff8538f253012862c06787adfb8ceb6'
Expand All @@ -63,7 +63,7 @@ beforeEach(() => {

describe('#getActiveChains', () => {
it('returns all chains that are active', () => {
expect(getActiveChains().map((chain) => chain.chainId)).toEqual([1, 5])
expect(getActiveChains().map((chain) => chain.chainId)).toEqual([1, 11155111])
})

it('returns an EVM chain object', () => {
Expand Down Expand Up @@ -149,48 +149,48 @@ describe('#createChainsObserver', () => {
connected: true
},
{
chainId: 5,
networkId: 5,
name: 'Ethereum Testnet Görli',
chainId: 10,
networkId: 10,
name: 'Optimism',
icon: [{ url: 'https://assets.coingecko.com/coins/images/ethereum.png' }],
nativeCurrency: {
name: 'Görli Ether',
name: 'Ether',
symbol: 'ETH',
decimals: 18
},
explorers: [
{
url: 'https://goerli.etherscan.io'
url: 'https://optimistic.etherscan.io'
}
],
external: {
wallet: {
colors: [{ r: 255, g: 153, b: 51, hex: '#ff9933' }]
colors: [{ r: 246, g: 36, b: 35, hex: '#f62423' }]
}
},
connected: false
connected: true
},
{
chainId: 10,
networkId: 10,
name: 'Optimism',
chainId: 11155111,
networkId: 11155111,
name: 'Ethereum Testnet Sepolia',
icon: [{ url: 'https://assets.coingecko.com/coins/images/ethereum.png' }],
nativeCurrency: {
name: 'Ether',
name: 'Sepolia Ether',
symbol: 'ETH',
decimals: 18
},
explorers: [
{
url: 'https://optimistic.etherscan.io'
url: 'https://sepolia.etherscan.io'
}
],
external: {
wallet: {
colors: [{ r: 246, g: 36, b: 35, hex: '#f62423' }]
colors: [{ r: 255, g: 153, b: 51, hex: '#ff9933' }]
}
},
connected: true
connected: false
}
])
})
Expand All @@ -209,11 +209,11 @@ describe('#createChainsObserver', () => {
fireObserver()

const changedChains = handler.chainsChanged.mock.calls[0][1]
expect(changedChains.map((c) => c.chainId)).toEqual([1, 5, 10])
expect(changedChains.map((c) => c.chainId)).toEqual([1, 10, 11155111])
})

it('invokes the handler when a chain is removed', () => {
const { 5: goerli, ...remaining } = chains
const { 11155111: sepolia, ...remaining } = chains
setChains(remaining)

fireObserver()
Expand All @@ -233,16 +233,16 @@ describe('#createChainsObserver', () => {
fireObserver()

const changedChains = handler.chainsChanged.mock.calls[0][1]
expect(changedChains.map((c) => c.chainId)).toEqual([1, 5, 137])
expect(changedChains.map((c) => c.chainId)).toEqual([1, 137, 11155111])
})

it('invokes the handler when a chain is deactivated', () => {
const {
5: { ...goerli }
11155111: { ...sepolia }
} = chains
goerli.on = false
sepolia.on = false

setChains({ ...chains, 5: goerli })
setChains({ ...chains, 11155111: sepolia })

fireObserver()

Expand All @@ -252,16 +252,16 @@ describe('#createChainsObserver', () => {

it('invokes the handler when a chain name changes', () => {
const {
5: { ...goerli }
11155111: { ...sepolia }
} = chains
goerli.name = 'Girly'
sepolia.name = 'Seppohleea'

setChains({ ...chains, 5: goerli })
setChains({ ...chains, 11155111: sepolia })

fireObserver()

const changedChains = handler.chainsChanged.mock.calls[0][1]
expect(changedChains.map((c) => c.chainId)).toEqual([1, 5])
expect(changedChains.map((c) => c.chainId)).toEqual([1, 11155111])
})

it('does not invoke the handler when no chains have changed', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/main/provider/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('#send', () => {
done()
}

sendRequest({ chainId: '0x5', chainName: 'Goerli' }, cb)
sendRequest({ chainId: '0xaa36a7', chainName: 'Sepolia' }, cb)
})

it('should create a request to add the chain', (done) => {
Expand Down
6 changes: 0 additions & 6 deletions test/main/signers/hot/RingSigner/worker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ describe('#signTransaction', () => {
expectedSignature:
'0xf8698084b2d05e0082520894be188d6641e8b680743a4815dfa0f6208038960f86b5e620f480008025a0c8ca5f76f568578bebbdfc257be09d8e8a4512d0ffd45e991da86be8141d97e0a037179047d9810e211657d9dd60d4bac66ed576fd65ef65a55f007314587036ec'
},
{
name: 'goerli',
chainId: 5,
expectedSignature:
'0xf8698084b2d05e0082520894be188d6641e8b680743a4815dfa0f6208038960f86b5e620f48000802da074c3b69fa979e92253c7f66d323f91f7f11eb16dd2b4838a274b584ddb708895a03e76e91351b2be3fd4a065195a0c71a4359d0fe4230f5f3ae457b2cb5a30bf03'
},
{
name: 'optimism',
chainId: 10,
Expand Down
38 changes: 21 additions & 17 deletions test/main/store/state/types/chain.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { EthereumChainsSchema } from '../../../../../main/store/state/types/chain'

const validChain = {
id: 5,
id: 11155111,
type: 'ethereum',
layer: 'testnet',
isTestnet: true,
on: false,
name: 'Görli',
explorer: 'https://goerli.etherscan.io',
name: 'Sepolia',
explorer: 'https://sepolia.etherscan.io',
connection: {
primary: {
on: true,
Expand All @@ -27,9 +27,9 @@ const validChain = {
}

it('parses a valid chain', () => {
const { ethereum: chains } = EthereumChainsSchema.parse({ ethereum: { 5: validChain } })
const { ethereum: chains } = EthereumChainsSchema.parse({ ethereum: { 11155111: validChain } })

expect(chains['5']).toEqual(validChain)
expect(chains['11155111']).toEqual(validChain)
})

it('sets the primary connection to disconnected to start', () => {
Expand All @@ -43,9 +43,11 @@ it('sets the primary connection to disconnected to start', () => {
}
}

const { ethereum: chains } = EthereumChainsSchema.parse({ ethereum: { 5: previouslyConnectedChain } })
const { ethereum: chains } = EthereumChainsSchema.parse({
ethereum: { 11155111: previouslyConnectedChain }
})

expect(chains['5'].connection.primary.connected).toBe(false)
expect(chains['11155111'].connection.primary.connected).toBe(false)
})

it('sets the secondary connection to disconnected to start', () => {
Expand All @@ -59,27 +61,29 @@ it('sets the secondary connection to disconnected to start', () => {
}
}

const { ethereum: chains } = EthereumChainsSchema.parse({ ethereum: { 5: previouslyConnectedChain } })
const { ethereum: chains } = EthereumChainsSchema.parse({
ethereum: { 11155111: previouslyConnectedChain }
})

expect(chains['5'].connection.secondary.connected).toBe(false)
expect(chains['11155111'].connection.secondary.connected).toBe(false)
})

it('replaces a corrupt chain with a known id with the default value from the state', () => {
const chain = {
id: 5,
id: 11155111,
test: 'bogusvalue'
}

const { ethereum: chains } = EthereumChainsSchema.parse({ ethereum: { 5: chain } })
const { ethereum: chains } = EthereumChainsSchema.parse({ ethereum: { 11155111: chain } })

expect(chains['5']).toEqual({
id: 5,
expect(chains['11155111']).toEqual({
id: 11155111,
type: 'ethereum',
layer: 'testnet',
isTestnet: true,
on: false,
name: 'Görli',
explorer: 'https://goerli.etherscan.io',
name: 'Sepolia',
explorer: 'https://sepolia.etherscan.io',
connection: {
primary: {
on: true,
Expand All @@ -104,9 +108,9 @@ it('removes an unknown corrupt chain from the state', () => {
test: 'bogusvalue'
}

const { ethereum: chains } = EthereumChainsSchema.parse({ ethereum: { 5: chain } })
const { ethereum: chains } = EthereumChainsSchema.parse({ ethereum: { 11155111: chain } })

expect(chains['5']).toBeUndefined()
expect(chains['11155111']).toBeUndefined()
})

it('adds mainnet if not present in the state', () => {
Expand Down
22 changes: 0 additions & 22 deletions test/resources/utils/chains.test.js

This file was deleted.

0 comments on commit ff95795

Please sign in to comment.