Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multichain API E2E test: wallet_sessionChanged #29706

Open
wants to merge 3 commits into
base: jl/caip-multichain-migrate-core
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions test/e2e/flask/multichain-api/wallet_sessionChanged.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { strict as assert } from 'assert';
import {
ACCOUNT_1,
ACCOUNT_2,
largeDelayMs,
WINDOW_TITLES,
withFixtures,
} from '../../helpers';
import { Driver } from '../../webdriver/driver';
import FixtureBuilder from '../../fixture-builder';
import {
addAccountInWalletAndAuthorize,
DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS,
getExpectedSessionScope,
initCreateSessionScopes,
openMultichainDappAndConnectWalletWithExternallyConnectable,
updateNetworkCheckboxes,
} from './testHelpers';

describe('Call `wallet_createSession`, then update the accounts and/or scopes in the permissions page of the wallet for that dapp', function () {
const INITIAL_SCOPES = ['eip155:1337', 'eip155:1338'];
const REMOVED_SCOPE = INITIAL_SCOPES[0];
const UPDATED_SCOPE = INITIAL_SCOPES[1];

const ACCOUNTS = [ACCOUNT_1, ACCOUNT_2];
const UPDATED_ACCOUNT = ACCOUNTS[1];
it('should receive a `wallet_sessionChanged` event with the full new session scopes', async function () {
await withFixtures(
{
title: this.test?.fullTitle(),
fixtures: new FixtureBuilder()
.withNetworkControllerTripleGanache()
.build(),
...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS,
},
async ({
driver,
extensionId,
}: {
driver: Driver;
extensionId: string;
}) => {
await openMultichainDappAndConnectWalletWithExternallyConnectable(
driver,
extensionId,
);
await initCreateSessionScopes(driver, INITIAL_SCOPES, ACCOUNTS);
await addAccountInWalletAndAuthorize(driver);
await driver.clickElement({ text: 'Connect', tag: 'button' });
await driver.delay(largeDelayMs);
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);

/**
* We make sure to update selected accounts via wallet extension UI
*/
await driver.clickElementSafe(
'[data-testid="account-options-menu-button"]',
);
await driver.clickElementSafe(
'[data-testid="global-menu-connected-sites"]',
);
await driver.clickElementSafe('[data-testid="connection-list-item"]');

const editButtons = await driver.findElements('[data-testid="edit"]');
await editButtons[0].click();
const checkboxes = await driver.findElements(
'input[type="checkbox" i]',
);
const firstAccountCheckbox = checkboxes[1];
await firstAccountCheckbox.click();
await driver.clickElementSafe({ text: 'Update', tag: 'button' });
jiexi marked this conversation as resolved.
Show resolved Hide resolved

/**
* And also update selected scope to {@link UPDATED_SCOPE}
*/
await updateNetworkCheckboxes(driver, ['Localhost 8546']);
await driver.switchToWindowWithTitle(WINDOW_TITLES.MultichainTestDApp);

const walletSessionChangedNotificationWebElement =
await driver.findElement('#wallet-session-changed-result-0');
jiexi marked this conversation as resolved.
Show resolved Hide resolved

const resultSummaries = await driver.findElements('.result-summary');
await resultSummaries[1].click();

const expectedScope = getExpectedSessionScope(UPDATED_SCOPE, [
UPDATED_ACCOUNT,
]);

const parsedNotificationResult = JSON.parse(
await walletSessionChangedNotificationWebElement.getText(),
);
const sessionChangedScope =
parsedNotificationResult.params.sessionScopes;

const currentScope = sessionChangedScope[UPDATED_SCOPE];
const scopedAccounts = currentScope.accounts;

assert.deepEqual(
currentScope,
expectedScope,
`scope ${UPDATED_SCOPE} should be present in 'wallet_sessionChanged' event data`,
);

assert.deepEqual(
scopedAccounts,
expectedScope.accounts,
`${expectedScope.accounts} does not match accounts in scope ${currentScope}`,
);

assert.deepEqual(
sessionChangedScope[REMOVED_SCOPE],
undefined,
`scope ${REMOVED_SCOPE} should NOT be present in 'wallet_sessionChanged' event data`,
);
},
);
});
});
Loading