Skip to content

Commit

Permalink
Merge branch 'develop' into fb/fix-snap-ui-text-overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding authored Mar 16, 2023
2 parents c01074f + 1482cd1 commit b0edcf3
Show file tree
Hide file tree
Showing 21 changed files with 266 additions and 118 deletions.
24 changes: 1 addition & 23 deletions app/scripts/controllers/network/network-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ import { strict as assert } from 'assert';
import EventEmitter from 'events';
import { ComposedStore, ObservableStore } from '@metamask/obs-store';
import { JsonRpcEngine } from 'json-rpc-engine';
import {
providerFromEngine,
providerFromMiddleware,
} from '@metamask/eth-json-rpc-middleware';
import { providerFromEngine } from '@metamask/eth-json-rpc-middleware';
import log from 'loglevel';
import {
createSwappableProxy,
createEventEmitterProxy,
} from 'swappable-obj-proxy';
import EthQuery from 'eth-query';
import createFilterMiddleware from 'eth-json-rpc-filters';
import createSubscriptionManager from 'eth-json-rpc-filters/subscriptionManager';
import { v4 as random } from 'uuid';
import {
INFURA_PROVIDER_TYPES,
Expand Down Expand Up @@ -460,26 +455,9 @@ export default class NetworkController extends EventEmitter {
}

_setNetworkClient({ networkMiddleware, blockTracker }) {
const networkProvider = providerFromMiddleware(networkMiddleware);
const filterMiddleware = createFilterMiddleware({
provider: networkProvider,
blockTracker,
});
const subscriptionManager = createSubscriptionManager({
provider: networkProvider,
blockTracker,
});

const engine = new JsonRpcEngine();
subscriptionManager.events.on('notification', (message) =>
engine.emit('notification', message),
);
engine.push(filterMiddleware);
engine.push(subscriptionManager.middleware);
engine.push(networkMiddleware);

const provider = providerFromEngine(engine);

this._setProviderAndBlockTracker({ provider, blockTracker });
}

Expand Down
2 changes: 0 additions & 2 deletions app/scripts/controllers/permissions/specifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,10 @@ export const unrestrictedMethods = Object.freeze([
'eth_signTypedData_v1',
'eth_signTypedData_v3',
'eth_signTypedData_v4',
'eth_subscribe',
'eth_submitHashrate',
'eth_submitWork',
'eth_syncing',
'eth_uninstallFilter',
'eth_unsubscribe',
'metamask_getProviderState',
'metamask_watchAsset',
'net_listening',
Expand Down
25 changes: 16 additions & 9 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
KeyringController,
keyringBuilderFactory,
} from '@metamask/eth-keyring-controller';
import createFilterMiddleware from 'eth-json-rpc-filters';
import createSubscriptionManager from 'eth-json-rpc-filters/subscriptionManager';
import {
errorCodes as rpcErrorCodes,
EthereumRpcError,
Expand Down Expand Up @@ -3898,19 +3900,21 @@ export default class MetamaskController extends EventEmitter {
* @param {tabId} [options.tabId] - The tab ID of the sender - if the sender is within a tab
*/
setupProviderEngine({ origin, subjectType, sender, tabId }) {
const { provider } = this;

// setup json rpc engine stack
const engine = new JsonRpcEngine();
const { blockTracker, provider } = this;

// forward notifications from network provider
provider.on('data', (error, message) => {
if (error) {
// This should never happen, this error parameter is never set
throw error;
}
engine.emit('notification', message);
// create filter polyfill middleware
const filterMiddleware = createFilterMiddleware({ provider, blockTracker });

// create subscription polyfill middleware
const subscriptionManager = createSubscriptionManager({
provider,
blockTracker,
});
subscriptionManager.events.on('notification', (message) =>
engine.emit('notification', message),
);

if (isManifestV3) {
engine.push(createDupeReqFilterMiddleware());
Expand Down Expand Up @@ -4063,6 +4067,9 @@ export default class MetamaskController extends EventEmitter {
);
///: END:ONLY_INCLUDE_IN

// filter and subscription polyfills
engine.push(filterMiddleware);
engine.push(subscriptionManager.middleware);
if (subjectType !== SubjectType.Internal) {
// permissions
engine.push(
Expand Down
14 changes: 8 additions & 6 deletions test/e2e/snaps/test-snap-bip-32.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ describe('Test Snap bip-32', function () {
tag: 'button',
});

// delay for npm installation
await driver.delay(2000);

// switch back to test-snaps window
windowHandles = await driver.waitUntilXWindowHandles(1, 1000, 10000);
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);

// wait for npm installation success
await driver.waitForSelector({
css: '#connectBip32',
text: 'Reconnect to BIP-32 Snap',
});

// scroll to and click get public key
await driver.delay(1000);
const snapButton2 = await driver.findElement('#bip32GetPublic');
Expand Down Expand Up @@ -122,7 +124,7 @@ describe('Test Snap bip-32', function () {

// wait then run SECP256K1 test
await driver.delay(1000);
await driver.fill('#bip32Message-secp256k1', 'foo bar');
await driver.pasteIntoField('#bip32Message-secp256k1', 'foo bar');
await driver.clickElement('#sendBip32-secp256k1');

// hit 'approve' on the custom confirm
Expand Down Expand Up @@ -157,7 +159,7 @@ describe('Test Snap bip-32', function () {

// wait then run ed25519 test
await driver.delay(1000);
await driver.fill('#bip32Message-ed25519', 'foo bar');
await driver.pasteIntoField('#bip32Message-ed25519', 'foo bar');
await driver.clickElement('#sendBip32-ed25519');

// hit 'approve' on the custom confirm
Expand Down
16 changes: 9 additions & 7 deletions test/e2e/snaps/test-snap-bip-44.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,21 @@ describe('Test Snap bip-44', function () {
// deal with permissions popover
await driver.delay(1000);
await driver.clickElement('#key-access-bip44-1-0');
await driver.delay(1000);
await driver.delay(1500);
await driver.clickElement({
text: 'Confirm',
tag: 'button',
});

// delay for npm installation
await driver.delay(2000);

// click send inputs on test snap page
windowHandles = await driver.waitUntilXWindowHandles(1, 1000, 10000);
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
await driver.delay(1000);

// wait for npm installation success
await driver.waitForSelector({
css: '#connectBip44Snap',
text: 'Reconnect to BIP-44 Snap',
});

await driver.clickElement('#sendBip44Test');

// check the results of the public key test
Expand All @@ -94,7 +96,7 @@ describe('Test Snap bip-44', function () {
);

// enter a message to sign
await driver.fill('#bip44Message', '1234');
await driver.pasteIntoField('#bip44Message', '1234');
await driver.delay(1000);
const snapButton3 = await driver.findElement('#signBip44Message');
await driver.scrollToElement(snapButton3);
Expand Down
10 changes: 6 additions & 4 deletions test/e2e/snaps/test-snap-cronjob.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ describe('Test Snap Cronjob', function () {
tag: 'button',
});

// delay for npm installation
await driver.delay(2000);

// click send inputs on test snap page
windowHandles = await driver.waitUntilXWindowHandles(2, 1000, 10000);
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);

// wait for npm installation success
await driver.waitForSelector({
css: '#connectCronjobSnap',
text: 'Reconnect to Cronjob Snap',
});

// switch to dialog popup, wait for a maximum of 65 seconds
windowHandles = await driver.waitUntilXWindowHandles(3, 1000, 65000);
await driver.switchToWindowWithTitle(
Expand Down
12 changes: 7 additions & 5 deletions test/e2e/snaps/test-snap-dialog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ describe('Test Snap Dialog', function () {
tag: 'button',
});

// delay for npm installation
await driver.delay(2000);

// switch to test snaps tab
windowHandles = await driver.waitUntilXWindowHandles(2, 1000, 10000);
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);

// wait for npm installation success
await driver.waitForSelector({
css: '#connectDialogSnap',
text: 'Reconnect to Dialog Snap',
});

// click on alert dialog
await driver.clickElement('#sendAlertButton');
await driver.delay(1000);
Expand Down Expand Up @@ -199,7 +201,7 @@ describe('Test Snap Dialog', function () {
await driver.delay(1000);

// fill '2323' in form field
await driver.fill('.MuiInput-input', '2323');
await driver.pasteIntoField('.MuiInput-input', '2323');

// click submit button
await driver.clickElement({
Expand Down
11 changes: 6 additions & 5 deletions test/e2e/snaps/test-snap-error.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ describe('Test Snap Error', function () {
tag: 'button',
});

// delay for npm installation
await driver.delay(2000);

// click send inputs on test snap page
windowHandles = await driver.waitUntilXWindowHandles(2, 1000, 10000);
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
await driver.delay(1000);

// wait for npm installation success
await driver.waitForSelector({
css: '#connectErrorSnap',
text: 'Reconnect to Error Snap',
});

// find and click on send error
await driver.clickElement('#sendError');
Expand Down
19 changes: 12 additions & 7 deletions test/e2e/snaps/test-snap-installed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ describe('Test Snap Installed', function () {
tag: 'button',
});

// delay for npm installation
await driver.delay(2000);

// click send inputs on test snap page
windowHandles = await driver.waitUntilXWindowHandles(2, 1000, 10000);
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);

// wait for npm installation success
await driver.waitForSelector({
css: '#connectDialogSnap',
text: 'Reconnect to Dialog Snap',
});

const errorButton = await driver.findElement('#connectErrorSnap');
await driver.scrollToElement(errorButton);
await driver.delay(1000);
Expand Down Expand Up @@ -101,12 +103,15 @@ describe('Test Snap Installed', function () {
tag: 'button',
});

// delay for npm installation
await driver.delay(2000);

windowHandles = await driver.waitUntilXWindowHandles(2, 1000, 10000);
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);

// wait for npm installation success
await driver.waitForSelector({
css: '#connectErrorSnap',
text: 'Reconnect to Error Snap',
});

const result = await driver.findElement('#installedSnapsResult');
await driver.scrollToElement(result);
await driver.delay(1000);
Expand Down
13 changes: 8 additions & 5 deletions test/e2e/snaps/test-snap-managestate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@ describe('Test Snap manageState', function () {
tag: 'button',
});

// delay for npm installation
await driver.delay(2000);

// fill and click send inputs on test snap page
windowHandles = await driver.waitUntilXWindowHandles(1, 1000, 10000);
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);

// wait for npm installation success
await driver.waitForSelector({
css: '#connectManageState',
text: 'Reconnect to Manage State Snap',
});

await driver.delay(1000);
await driver.fill('#dataManageState', '23');
await driver.pasteIntoField('#dataManageState', '23');
const snapButton2 = await driver.findElement(
'#retrieveManageStateResult',
);
Expand Down
12 changes: 7 additions & 5 deletions test/e2e/snaps/test-snap-notification.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ describe('Test Snap Notification', function () {
tag: 'button',
});

// delay for npm installation
await driver.delay(2000);

// click send inputs on test snap page
windowHandles = await driver.waitUntilXWindowHandles(2, 1000, 10000);
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
await driver.delay(1000);

// wait for npm installation success
await driver.waitForSelector({
css: '#connectNotification',
text: 'Reconnect to Notification Snap',
});

await driver.clickElement('#sendInAppNotification');

// switch back to the extension page
Expand Down
1 change: 0 additions & 1 deletion test/e2e/snaps/test-snap-rpc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ describe('Test Snap RPC', function () {
});

// switch back to test snaps page
windowHandles = await driver.waitUntilXWindowHandles(1, 1000, 10000);
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);

// wait for npm installation success
Expand Down
11 changes: 6 additions & 5 deletions test/e2e/snaps/test-snap-update.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ describe('Test Snap update', function () {
tag: 'button',
});

// delay for npm installation
await driver.delay(2000);

// navigate to test snap page
windowHandles = await driver.waitUntilXWindowHandles(1, 1000, 10000);
await driver.switchToWindowWithTitle('Test Snaps', windowHandles);
await driver.delay(1000);

// wait for npm installation success
await driver.waitForSelector({
css: '#connectUpdate',
text: 'Reconnect to Update Snap',
});

// find and scroll to the correct card and click first
const snapButton2 = await driver.findElement('#connectUpdateNew');
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/swaps/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const reviewQuote = async (driver, options) => {
'Error: SwapFrom has wrong symbol',
);
const swapToSymbol = await driver.waitForSelector(
'.main-quote-summary__destination-row',
'.main-quote-summary__destination-row > span',
);
assert.equal(
await swapToSymbol.getText(),
Expand Down
Loading

0 comments on commit b0edcf3

Please sign in to comment.