-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #917 from rainlanguage/2024-10-04-walletconnect-fi…
…x-cont Add network name to wallet connect error message
- Loading branch information
Showing
3 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { expect, vi, describe, it } from 'vitest'; | ||
import ModalExecute from './ModalExecute.svelte'; | ||
import { render, screen } from '@testing-library/svelte'; | ||
import { settings } from '$lib/stores/settings'; | ||
|
||
vi.mock('$lib/stores/walletconnect', async () => { | ||
const { writable } = await import('svelte/store'); | ||
return { | ||
walletconnectAccount: writable('0x123'), | ||
walletconnectIsDisconnecting: writable(false), | ||
walletconnectIsConnecting: writable(false), | ||
walletconnectProvider: writable(undefined), | ||
walletConnectNetwork: writable(1), | ||
walletConnectConnect: vi.fn(), | ||
walletconnectDisconnect: vi.fn(), | ||
}; | ||
}); | ||
|
||
vi.mock('$lib/stores/settings', async (importOriginal) => { | ||
return { | ||
...((await importOriginal()) as object), | ||
}; | ||
}); | ||
|
||
describe('ModalExecute', () => { | ||
describe('should show network connection error if wallet is connected to wrong network', () => { | ||
it('should show unknown network name', () => { | ||
render(ModalExecute, { | ||
props: { | ||
open: true, | ||
title: 'Test', | ||
execButtonLabel: 'Execute', | ||
executeLedger: vi.fn(), | ||
executeWalletconnect: vi.fn(), | ||
isSubmitting: false, | ||
overrideNetwork: { | ||
name: 'test', | ||
rpc: 'https://test.com', | ||
'chain-id': 2, | ||
}, | ||
}, | ||
}); | ||
|
||
const errorElement = screen.getByTestId('network-connection-error'); | ||
expect(errorElement).toHaveTextContent( | ||
'You are connected to an unknown network. Please connect your wallet to test network.', | ||
); | ||
}); | ||
|
||
it('should show current connected network name', () => { | ||
settings.set({ | ||
networks: { | ||
mainnet: { | ||
'chain-id': 1, | ||
rpc: 'https://mainnet.com', | ||
}, | ||
}, | ||
}); | ||
|
||
render(ModalExecute, { | ||
props: { | ||
open: true, | ||
title: 'Test', | ||
execButtonLabel: 'Execute', | ||
executeLedger: vi.fn(), | ||
executeWalletconnect: vi.fn(), | ||
isSubmitting: false, | ||
overrideNetwork: { | ||
name: 'test', | ||
rpc: 'https://test.com', | ||
'chain-id': 2, | ||
}, | ||
}, | ||
}); | ||
|
||
const errorElement = screen.getByTestId('network-connection-error'); | ||
expect(errorElement).toHaveTextContent( | ||
'You are connected to mainnet network. Please connect your wallet to test network.', | ||
); | ||
}); | ||
}); | ||
}); |