Skip to content

Commit

Permalink
Add suppport for Goerli in optimism-networks
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjocke committed Aug 1, 2022
1 parent ad4f817 commit 10e3f8a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
17 changes: 17 additions & 0 deletions packages/optimism-networks/__tests__/switch-to-l1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ describe('switchToL1', () => {
params: [{ chainId: '0x2a' }],
});
});
test('Switch to gorli when optimism gorli is selected', async () => {
const requestMock = jest.fn().mockResolvedValue(undefined);
const arg = {
ethereum: {
isMetaMask: true,
request: requestMock,
chainId: '0x45',
},
} as any;

await switchToL1(arg);
expect(requestMock).toBeCalledTimes(1);
expect(requestMock).toHaveBeenCalledWith({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x2a' }],
});
});
test('Switch to mainnet when unsupported network selected', async () => {
const requestMock = jest.fn().mockResolvedValue(undefined);
const arg = {
Expand Down
17 changes: 17 additions & 0 deletions packages/optimism-networks/__tests__/switch-to-l2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ describe('switchToL2', () => {
params: [{ chainId: '0x45' }],
});
});
test('Switch to Optimism Goerli when Goerli selected ', async () => {
const requestMock = jest.fn().mockResolvedValue(undefined);
const deps = {
ethereum: {
isMetaMask: true,
request: requestMock,
chainId: '0x5',
},
} as any;

await switchToL2(deps);
expect(requestMock).toBeCalledTimes(1);
expect(requestMock).toHaveBeenCalledWith({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x1A4' }],
});
});
test('Switch to Optimism mainnet when unsupported network selected ', async () => {
const requestMock = jest.fn().mockResolvedValue(undefined);
const deps = {
Expand Down
13 changes: 7 additions & 6 deletions packages/optimism-networks/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export const DEFAULT_LAYER2_NETWORK = 10;
export const L1_TO_L2_NETWORK_MAPPER: NetworkMapper = {
1: 10,
42: 69,
31337: 420,
5: 420,
};

export const L2_TO_L1_NETWORK_MAPPER: NetworkMapper = {
10: 1,
69: 42,
420: 31337,
420: 5,
};

export const OPTIMISM_NETWORKS: Record<number, OptimismNetwork> = {
Expand All @@ -27,11 +27,12 @@ export const OPTIMISM_NETWORKS: Record<number, OptimismNetwork> = {
'https://optimism.io/images/metamask_icon.png',
],
},
69: {
chainId: '0x45',

420: {
chainId: '0x1A4',
chainName: 'Optimism Kovan',
rpcUrls: ['https://kovan.optimism.io'],
blockExplorerUrls: ['https://kovan-optimistic.etherscan.io'],
rpcUrls: ['https://goerli.optimism.io/'],
blockExplorerUrls: [''], // TODO should add when it becomes avaiable
iconUrls: [
'https://optimism.io/images/metamask_icon.svg',
'https://optimism.io/images/metamask_icon.png',
Expand Down
1 change: 1 addition & 0 deletions packages/optimism-networks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type OptimismNetwork = {
export enum NetworkId {
Mainnet = 10,
Kovan = 69,
Goerli = 420,
}

export type OptimismWatcher = {
Expand Down

0 comments on commit 10e3f8a

Please sign in to comment.