-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bridge-ui): selecting chain was not informing of errors (#13712)
Co-authored-by: Daniel Wang <[email protected]>
- Loading branch information
1 parent
523f95b
commit 5d29c6d
Showing
9 changed files
with
249 additions
and
53 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
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,5 @@ | ||
import debug from 'debug'; | ||
|
||
export function getLogger(namesapce: string) { | ||
return debug(`bridge:${namesapce}`); | ||
} |
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,74 @@ | ||
import { switchNetwork } from '@wagmi/core'; | ||
import { Signer, ethers } from 'ethers'; | ||
import { fromChain, toChain } from '../store/chain'; | ||
import { signer } from '../store/signer'; | ||
import { mainnetChain, taikoChain } from '../chain/chains'; | ||
import { selectChain } from './selectChain'; | ||
|
||
jest.mock('../constants/envVars'); | ||
|
||
jest.mock('@wagmi/core', () => ({ | ||
switchNetwork: jest.fn(), | ||
})); | ||
|
||
jest.mock('ethers', () => { | ||
const Web3Provider = jest.fn(); | ||
Web3Provider.prototype = { | ||
getSigner: jest.fn(), | ||
send: jest.fn(), | ||
}; | ||
return { | ||
ethers: { | ||
providers: { | ||
Web3Provider, | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
jest.mock('../store/chain', () => ({ | ||
fromChain: { | ||
set: jest.fn(), | ||
}, | ||
toChain: { | ||
set: jest.fn(), | ||
}, | ||
})); | ||
|
||
jest.mock('../store/signer', () => ({ | ||
signer: { | ||
set: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('selectChain', () => { | ||
it('should select chain', async () => { | ||
const mockSigner = {} as ethers.providers.JsonRpcSigner; | ||
jest | ||
.mocked(ethers.providers.Web3Provider.prototype.getSigner) | ||
.mockReturnValue(mockSigner); | ||
|
||
await selectChain(mainnetChain); | ||
|
||
expect(switchNetwork).toHaveBeenCalledWith({ chainId: mainnetChain.id }); | ||
expect(fromChain.set).toHaveBeenCalledWith(mainnetChain); | ||
expect(toChain.set).toHaveBeenCalledWith(taikoChain); | ||
expect(signer.set).toHaveBeenCalled(); | ||
|
||
expect(ethers.providers.Web3Provider.prototype.send).toHaveBeenCalledWith( | ||
'eth_requestAccounts', | ||
[], | ||
); | ||
|
||
expect( | ||
ethers.providers.Web3Provider.prototype.getSigner, | ||
).toHaveBeenCalled(); | ||
|
||
expect(signer.set).toHaveBeenCalledWith(mockSigner); | ||
|
||
// Select the other chain now | ||
await selectChain(taikoChain); | ||
|
||
expect(switchNetwork).toHaveBeenCalledWith({ chainId: taikoChain.id }); | ||
}); | ||
}); |
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
Oops, something went wrong.