Skip to content

Commit

Permalink
refactor: more slight changes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
ffmcgee725 committed Dec 18, 2024
1 parent a105b35 commit 396ec6f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 58 deletions.
31 changes: 17 additions & 14 deletions test/e2e/flask/multichain-api/get-session.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { strict as assert } from 'assert';
import _ from 'lodash';
import { withFixtures } from '../../helpers';
import { Driver } from '../../webdriver/driver';
import FixtureBuilder from '../../fixture-builder';
import { DEFAULT_FIXTURE_ACCOUNT } from '../../constants';
import {
DEFAULT_OPTIONS,
DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS,
getExpectedSessionScope,
getSessionScopes,
openDappAndConnectWallet,
openMultichainDappAndConnectWalletWithExternallyConnectable,
} from './testHelpers';

describe('Multichain API', function () {
Expand All @@ -17,7 +18,7 @@ describe('Multichain API', function () {
{
title: this.test?.fullTitle(),
fixtures: new FixtureBuilder().withPopularNetworks().build(),
...DEFAULT_OPTIONS,
...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS,
},
async ({
driver,
Expand All @@ -26,12 +27,14 @@ describe('Multichain API', function () {
driver: Driver;
extensionId: string;
}) => {
await openDappAndConnectWallet(driver, extensionId);
await openMultichainDappAndConnectWalletWithExternallyConnectable(driver, extensionId);
const parsedResult = await getSessionScopes(driver);

if (!_.isEqual(parsedResult.sessionScopes, {})) {
throw new Error('Should receive empty session scopes');
}
assert.deepStrictEqual(
parsedResult.sessionScopes,
{},
'Should receive empty session scopes',
);
},
);
});
Expand All @@ -46,7 +49,7 @@ describe('Multichain API', function () {
.withPopularNetworks()
.withPermissionControllerConnectedToTestDapp()
.build(),
...DEFAULT_OPTIONS,
...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS,
},
async ({
driver,
Expand All @@ -60,19 +63,19 @@ describe('Multichain API', function () {
*/
const DEFAULT_SCOPE = 'eip155:1337';

await openDappAndConnectWallet(driver, extensionId);
await openMultichainDappAndConnectWalletWithExternallyConnectable(driver, extensionId);
const parsedResult = await getSessionScopes(driver);

const sessionScope = parsedResult.sessionScopes[DEFAULT_SCOPE];
const expectedSessionScope = getExpectedSessionScope(DEFAULT_SCOPE, [
DEFAULT_FIXTURE_ACCOUNT,
]);

if (!_.isEqual(sessionScope, expectedSessionScope)) {
throw new Error(
`Should receive result that specifies expected session scopes for ${DEFAULT_SCOPE}`,
);
}
assert.deepStrictEqual(
sessionScope,
expectedSessionScope,
`Should receive result that specifies expected session scopes for ${DEFAULT_SCOPE}`,
);
},
);
});
Expand Down
49 changes: 5 additions & 44 deletions test/e2e/flask/multichain-api/testHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as path from 'path';
import { DAPP_URL, largeDelayMs, openDapp, unlockWallet } from '../../helpers';
import { Driver } from '../../webdriver/driver';
import { KnownRpcMethods, KnownNotifications } from '@metamask/multichain';

/**
* Default options for setting up Multichain E2E test environment
*/
export const DEFAULT_OPTIONS = {
export const DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS = {
dapp: true,
dappPaths: [
path.join(
Expand All @@ -25,7 +26,7 @@ export const DEFAULT_OPTIONS = {
* @param {Driver} driver - E2E test driver {@link Driver}, wrapping the Selenium WebDriver.
* @param extensionId - Extension identifier for web dapp to interact with wallet extension.
*/
export async function openDappAndConnectWallet(
export async function openMultichainDappAndConnectWalletWithExternallyConnectable(
driver: Driver,
extensionId: string,
): Promise<void> {
Expand Down Expand Up @@ -67,47 +68,7 @@ export async function getSessionScopes(
* @returns the expected session scope.
*/
export const getExpectedSessionScope = (scope: string, accounts: string[]) => ({
methods: [
'personal_sign',
'eth_signTypedData_v4',
'wallet_watchAsset',
'eth_sendTransaction',
'eth_decrypt',
'eth_getEncryptionPublicKey',
'web3_clientVersion',
'eth_subscribe',
'eth_unsubscribe',
'eth_blockNumber',
'eth_call',
'eth_chainId',
'eth_estimateGas',
'eth_feeHistory',
'eth_gasPrice',
'eth_getBalance',
'eth_getBlockByHash',
'eth_getBlockByNumber',
'eth_getBlockTransactionCountByHash',
'eth_getBlockTransactionCountByNumber',
'eth_getCode',
'eth_getFilterChanges',
'eth_getFilterLogs',
'eth_getLogs',
'eth_getProof',
'eth_getStorageAt',
'eth_getTransactionByBlockHashAndIndex',
'eth_getTransactionByBlockNumberAndIndex',
'eth_getTransactionByHash',
'eth_getTransactionCount',
'eth_getTransactionReceipt',
'eth_getUncleCountByBlockHash',
'eth_getUncleCountByBlockNumber',
'eth_newBlockFilter',
'eth_newFilter',
'eth_newPendingTransactionFilter',
'eth_sendRawTransaction',
'eth_syncing',
'eth_uninstallFilter',
],
notifications: ['eth_subscription'],
methods: KnownRpcMethods.eip155,
notifications: KnownNotifications.eip155,
accounts: accounts.map((acc) => `${scope}:${acc.toLowerCase()}`),
});

0 comments on commit 396ec6f

Please sign in to comment.