-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1609b3e
commit 7343863
Showing
1 changed file
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Context } from './context' | ||
import { VoidSigner } from '@ethersproject/abstract-signer' | ||
import { Provider } from '@ethersproject/providers' | ||
|
||
test('Context: update chainId', async () => { | ||
const context = new Context(1, {}) | ||
let chainId = await context.chainId | ||
expect(chainId).toEqual(1) | ||
|
||
// works | ||
chainId = await context.updateChainId(4) | ||
expect(chainId).toEqual(4) | ||
}) | ||
|
||
test('Context: update chainId fails', () => { | ||
const context = new Context(1, {}) | ||
|
||
expect(() => { | ||
context.updateChainId(123) | ||
}).toThrow('Invalid chainId: 123') | ||
}) | ||
|
||
test('Context: get chainId from provider - matches context', async () => { | ||
const mockProvider = jest.fn<Provider, []>() | ||
const provider = new mockProvider() | ||
provider.getNetwork = jest.fn(async () => ({ chainId: 1, name: 'bla' })) | ||
|
||
const signer = new VoidSigner('', provider) | ||
|
||
const context = new Context(1, { signer }) | ||
|
||
const chainId = await context.chainId | ||
|
||
expect(chainId).toEqual(1) | ||
expect(provider.getNetwork).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
test('Context: get chainId from provider - differs from context', async () => { | ||
const mockProvider = jest.fn<Provider, []>() | ||
const provider = new mockProvider() | ||
provider.getNetwork = jest.fn(async () => ({ chainId: 100, name: 'bla' })) | ||
|
||
const signer = new VoidSigner('', provider) | ||
|
||
const context = new Context(1, { signer }) | ||
|
||
const chainId = await context.chainId | ||
|
||
expect(chainId).toEqual(100) | ||
expect(provider.getNetwork).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
test('Context: ') |