Skip to content

Commit a686e2b

Browse files
authored
add test case (#29885)
Add missing test case
1 parent b1b2f8e commit a686e2b

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

test/e2e/json-rpc/wallet_addEthereumChain.spec.ts

+62-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ describe('Add Ethereum Chain', function () {
310310
});
311311
});
312312

313-
describe('the dapp is already permitted to use the chain being added', () => {
313+
describe('the dapp is already permitted to use the chain being added, and the dapp is on a different chain from the chain being added', () => {
314314
it('automatically switches to the chain when the rpc endpoint is added but a different rpc endpoint already existed for the chain', async function () {
315315
await withFixtures(
316316
{
@@ -434,4 +434,65 @@ describe('Add Ethereum Chain', function () {
434434
);
435435
});
436436
});
437+
describe('the dapp is already permitted to use the chain being added, and the dapp is on the same chain as the chain being added, but the rpcEndpoint being proposed does not match any existing rpcEndpoints for the chain', () => {
438+
it('prompts to add the rpc endpoint to the chain networkConfiguration and set it as the default', async function () {
439+
await withFixtures(
440+
{
441+
dapp: true,
442+
fixtures: new FixtureBuilder()
443+
.withPermissionControllerConnectedToTestDappWithChains(['0x539'])
444+
.build(),
445+
ganacheOptions: defaultGanacheOptions,
446+
title: this.test?.fullTitle(),
447+
},
448+
async ({ driver }: { driver: Driver }) => {
449+
await unlockWallet(driver);
450+
await openDapp(driver);
451+
452+
const beforePermittedChains = await getPermittedChains(driver);
453+
assert.deepEqual(beforePermittedChains, ['0x539']);
454+
455+
await driver.findElement({ css: '#chainId', text: '0x539' });
456+
457+
const addEthereumChainRequest = JSON.stringify({
458+
jsonrpc: '2.0',
459+
method: 'wallet_addEthereumChain',
460+
params: [
461+
{
462+
chainId: '0x539',
463+
chainName: 'Alternative localhost chain 0x539',
464+
nativeCurrency: {
465+
name: '',
466+
symbol: 'ETH',
467+
decimals: 18,
468+
},
469+
// this does not match what already exists in the NetworkController as an endpoint for this chain
470+
rpcUrls: ['http://127.0.0.1:8545'],
471+
blockExplorerUrls: [],
472+
},
473+
],
474+
});
475+
476+
await driver.executeScript(
477+
`window.ethereum.request(${addEthereumChainRequest})`,
478+
);
479+
480+
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
481+
await driver.findElement({ text: 'Update Localhost 8545' });
482+
await driver.clickElement({ text: 'Approve', tag: 'button' });
483+
await driver.switchToWindowWithTitle(
484+
WINDOW_TITLES.ExtensionInFullScreenView,
485+
);
486+
487+
// go to network selector
488+
await driver.findElement({ text: 'Localhost 8545' });
489+
await driver.clickElement({ text: 'Localhost 8545' });
490+
491+
await driver.findElement({
492+
text: 'Alternative localhost chain 0x539',
493+
});
494+
},
495+
);
496+
});
497+
});
437498
});

0 commit comments

Comments
 (0)