-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* All Connectors emit Disconnect Event * Connectors emit connected events with params * make emit protected, ONLY callable by connectors, also fix cew test * switch address change to be emited event * WIP * replace loadConfig with resurector + loadPreviusState Move celo provider helpers to their own files. add listeners * remove persists * fix connector stub * end reducer effecting local storage * fix tests, no local storage * connector listerns must be listening BEFORE initialise is called * remove clearPreviousConfig calls from connectors * split up client settup from fetching URI. allow getURI to be called multiple times without creating new clients * expend test for wallet connect * missed extra import * WIP better netowkr changers * a little cleanup * remove unused code * fix tests * tests pass * wip Wallet connect connector connecting steps, changing networks, disconnecting, and inbetween steps * improve wc, handle CBW disconnect, remove account * update todos * fix lint errors * fix ts build * cleanup * replace console.xxx with our custom logger * self review * clear up verbose test runs * lint up * clean up tests. remove weird exit code * revert * add second test condition * more self review * review (@nicolasbrugneaux) rename destroy to disconnect for linguistic symmetry with connect action * a more reasonable time * unmount in the tests * mocking the balance might be why there is a balance Co-authored-by: Aaron DeRuvo <aaron.deruvo@clabs.co>
- Loading branch information
Showing
55 changed files
with
1,736 additions
and
1,128 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,6 @@ | ||
export const mockLogger = { | ||
log: jest.fn(), | ||
error: jest.fn(), | ||
debug: jest.fn(), | ||
warn: jest.fn(), | ||
}; |
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
108 changes: 108 additions & 0 deletions
108
packages/react-celo/__tests__/connectors/celo-extension-wallet.test.ts
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,108 @@ | ||
import { CeloContract } from '@celo/contractkit/lib/base'; | ||
import { generateTestingUtils } from 'eth-testing'; | ||
|
||
import { | ||
CeloExtensionWalletConnector, | ||
ConnectorEvents, | ||
} from '../../src/connectors'; | ||
import { Alfajores, Baklava, WalletTypes } from '../../src/constants'; | ||
import { setApplicationLogger } from '../../src/utils/logger'; | ||
import { mockLogger } from '../test-logger'; | ||
|
||
const ACCOUNT = '0xf61B443A155b07D2b2cAeA2d99715dC84E839EEf'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const CEW_CALLBACKS = new Map<string, (args: any) => void>(); | ||
|
||
describe('CeloExtensionWalletConnector', () => { | ||
const testingUtils = generateTestingUtils({ | ||
providerType: 'MetaMask', | ||
verbose: false, | ||
}); | ||
|
||
const provider = testingUtils.getProvider(); | ||
|
||
beforeAll(() => { | ||
// Manually inject the mocked provider in the window as MetaMask does | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
(global.window.celo = { | ||
...provider, | ||
send: (params, cb) => | ||
cb(null, { | ||
jsonrpc: params.jsonrpc, | ||
id: Number(params.id), | ||
result: [ACCOUNT], | ||
}), | ||
enable: () => Promise.resolve(undefined), | ||
publicConfigStore: { | ||
on: (e: string, cb: (args: { networkVersion: number }) => void) => { | ||
CEW_CALLBACKS.set(e, cb); | ||
}, | ||
}, | ||
}), | ||
testingUtils.mockConnectedWallet([ACCOUNT], { | ||
chainId: Alfajores.chainId, | ||
}); | ||
testingUtils.mockAccounts([ACCOUNT]); | ||
testingUtils.mockRequestAccounts([ACCOUNT]); | ||
setApplicationLogger(mockLogger); | ||
}); | ||
let connector: CeloExtensionWalletConnector; | ||
const onConnect = jest.fn(); | ||
const onDisconnect = jest.fn(); | ||
const onChangeAddress = jest.fn(); | ||
const onChangeNetwork = jest.fn(); | ||
beforeEach(() => { | ||
connector = new CeloExtensionWalletConnector( | ||
Alfajores, | ||
CeloContract.GoldToken | ||
); | ||
connector.on(ConnectorEvents.CONNECTED, onConnect); | ||
connector.on(ConnectorEvents.DISCONNECTED, onDisconnect); | ||
connector.on(ConnectorEvents.ADDRESS_CHANGED, onChangeAddress); | ||
connector.on(ConnectorEvents.NETWORK_CHANGED, onChangeNetwork); | ||
}); | ||
|
||
afterEach(() => { | ||
// Clear all mocks between tests | ||
testingUtils.clearAllMocks(); | ||
}); | ||
describe('initialise()', () => { | ||
it('emits CONNECTED with network, address, walletType', async () => { | ||
await connector.initialise(); | ||
expect(connector.initialised).toBe(true); | ||
expect(onConnect).toBeCalledWith({ | ||
networkName: Alfajores.name, | ||
address: ACCOUNT, | ||
walletType: WalletTypes.CeloExtensionWallet, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('startNetworkChangeFromApp()', () => { | ||
it('throws since CEW doesnt support that', () => { | ||
expect(() => connector.startNetworkChangeFromApp()).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('continueNetworkUpdateFromWallet()', () => { | ||
it('emits NETWORK_CHANGED EVENT', () => { | ||
connector.continueNetworkUpdateFromWallet(Baklava); | ||
expect(onChangeNetwork).toBeCalledWith(Baklava.name); | ||
}); | ||
|
||
it('creates a new kit', () => { | ||
const originalKit = connector.kit; | ||
connector.continueNetworkUpdateFromWallet(Baklava); | ||
expect(connector.kit).not.toBe(originalKit); | ||
}); | ||
}); | ||
|
||
describe('close()', () => { | ||
it('emits DISCONNECTED event', () => { | ||
connector.close(); | ||
expect(onDisconnect).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
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.