Skip to content

Commit

Permalink
Merge branch 'develop' into MMI-fix-pw-test
Browse files Browse the repository at this point in the history
  • Loading branch information
zone-live committed Apr 30, 2024
2 parents aac4fde + 8a0e455 commit 6851000
Show file tree
Hide file tree
Showing 131 changed files with 540 additions and 99 deletions.
2 changes: 2 additions & 0 deletions app/loading.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<% if (it.shouldIncludeSnow) { %>
<script src="./scripts/snow.js"></script>
<script src="./scripts/use-snow.js"></script>
<% } %>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>MetaMask Loading</title>
Expand Down
20 changes: 14 additions & 6 deletions app/scripts/app-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ function importAllScripts() {

const startImportScriptsTime = Date.now();

// value of useSnow below is dynamically replaced at build time with actual value
const useSnow = process.env.USE_SNOW;
if (typeof useSnow !== 'boolean') {
throw new Error('Missing USE_SNOW environment variable');
}

// value of applyLavaMoat below is dynamically replaced at build time with actual value
const applyLavaMoat = process.env.APPLY_LAVAMOAT;
if (typeof applyLavaMoat !== 'boolean') {
Expand All @@ -57,13 +63,15 @@ function importAllScripts() {

loadFile('../scripts/sentry-install.js');

// eslint-disable-next-line no-undef
const isWorker = !self.document;
if (!isWorker) {
loadFile('../scripts/snow.js');
}
if (useSnow) {
// eslint-disable-next-line no-undef
const isWorker = !self.document;
if (!isWorker) {
loadFile('../scripts/snow.js');
}

loadFile('../scripts/use-snow.js');
loadFile('../scripts/use-snow.js');
}

// Always apply LavaMoat in e2e test builds, so that we can capture initialization stats
if (testMode || applyLavaMoat) {
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/metamask-controller.actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { PermissionsRequestNotFoundError } from '@metamask/permission-controller
import nock from 'nock';
import mockEncryptor from '../../test/lib/mock-encryptor';

const { Ganache } = require('../../test/e2e/ganache');
const { Ganache } = require('../../test/e2e/seeder/ganache');

const ganacheServer = new Ganache();

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6058,7 +6058,7 @@ export default class MetamaskController extends EventEmitter {

this.controllerMessenger.publish(
'TransactionController:transactionStatusUpdated',
{ updatedTransactionMeta },
{ transactionMeta: updatedTransactionMeta },
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/metamask-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { flushPromises } from '../../test/lib/timer-helpers';
import { deferredPromise } from './lib/util';
import MetaMaskController from './metamask-controller';

const { Ganache } = require('../../test/e2e/ganache');
const { Ganache } = require('../../test/e2e/seeder/ganache');

const ganacheServer = new Ganache();

Expand Down
2 changes: 2 additions & 0 deletions app/trezor-usb-permissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8" />
<% if (it.shouldIncludeSnow) { %>
<script src="./scripts/snow.js"></script>
<script src="./scripts/use-snow.js"></script>
<% } %>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
<title>TrezorConnect | Trezor</title>
Expand Down
1 change: 1 addition & 0 deletions builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ env:
# TODO(ritave): Move ManifestV3 into a feature?
- ENABLE_MV3: false
# These are exclusively used for MV3
- USE_SNOW
- APPLY_LAVAMOAT
- FILE_NAMES

Expand Down
1 change: 1 addition & 0 deletions development/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ async function defineAndRunBuildTasks() {
const styleTasks = createStyleTasks({ livereload });

const scriptTasks = createScriptTasks({
shouldIncludeSnow,
applyLavaMoat,
browserPlatforms,
buildType,
Expand Down
47 changes: 44 additions & 3 deletions development/build/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ module.exports = createScriptTasks;
* @param {boolean} options.shouldLintFenceFiles - Whether files with code
* fences should be linted after fences have been removed.
* @param {string} options.version - The current version of the extension.
* @param options.shouldIncludeSnow - Whether the build should use
* Snow at runtime or not.
* @returns {object} A set of tasks, one for each build target.
*/
function createScriptTasks({
shouldIncludeSnow,
applyLavaMoat,
browserPlatforms,
buildType,
Expand Down Expand Up @@ -193,6 +196,7 @@ function createScriptTasks({
const standardSubtask = createTask(
`${taskPrefix}:standardEntryPoints`,
createFactoredBuild({
shouldIncludeSnow,
applyLavaMoat,
browserPlatforms,
buildTarget,
Expand Down Expand Up @@ -257,6 +261,7 @@ function createScriptTasks({
installSentrySubtask,
].map((subtask) =>
runInChildProcess(subtask, {
shouldIncludeSnow,
applyLavaMoat,
buildType,
isLavaMoat,
Expand Down Expand Up @@ -408,9 +413,12 @@ function createScriptTasks({
* @param {boolean} options.shouldLintFenceFiles - Whether files with code
* fences should be linted after fences have been removed.
* @param {string} options.version - The current version of the extension.
* @param options.shouldIncludeSnow - Whether the build should use
* Snow at runtime or not.
* @returns {Function} A function that creates the set of bundles.
*/
async function createManifestV3AppInitializationBundle({
shouldIncludeSnow,
applyLavaMoat,
browserPlatforms,
buildTarget,
Expand All @@ -436,6 +444,7 @@ async function createManifestV3AppInitializationBundle({
}

const extraEnvironmentVariables = {
USE_SNOW: shouldIncludeSnow,
APPLY_LAVAMOAT: applyLavaMoat,
FILE_NAMES: jsBundles.join(','),
};
Expand Down Expand Up @@ -497,9 +506,12 @@ async function createManifestV3AppInitializationBundle({
* @param {boolean} options.shouldLintFenceFiles - Whether files with code
* fences should be linted after fences have been removed.
* @param {string} options.version - The current version of the extension.
* @param options.shouldIncludeSnow - Whether the build should use
* Snow at runtime or not.
* @returns {Function} A function that creates the set of bundles.
*/
function createFactoredBuild({
shouldIncludeSnow,
applyLavaMoat,
browserPlatforms,
buildTarget,
Expand Down Expand Up @@ -646,21 +658,31 @@ function createFactoredBuild({
buildTarget === BUILD_TARGETS.TEST_DEV;
switch (groupLabel) {
case 'ui': {
renderHtmlFile({
htmlName: 'loading',
browserPlatforms,
shouldIncludeSnow,
applyLavaMoat,
isMMI: buildType === 'mmi',
});
renderHtmlFile({
htmlName: 'popup',
browserPlatforms,
shouldIncludeSnow,
applyLavaMoat,
});
renderHtmlFile({
htmlName: 'notification',
browserPlatforms,
shouldIncludeSnow,
applyLavaMoat,
isMMI: buildType === 'mmi',
isTest,
});
renderHtmlFile({
htmlName: 'home',
browserPlatforms,
shouldIncludeSnow,
applyLavaMoat,
isMMI: buildType === 'mmi',
isTest,
Expand All @@ -669,6 +691,7 @@ function createFactoredBuild({
groupSet,
commonSet,
browserPlatforms,
shouldIncludeSnow,
applyLavaMoat,
destinationFileName: 'load-app.js',
});
Expand All @@ -680,12 +703,14 @@ function createFactoredBuild({
groupSet,
commonSet,
browserPlatforms,
shouldIncludeSnow,
applyLavaMoat,
});
renderJavaScriptLoader({
groupSet,
commonSet,
browserPlatforms,
shouldIncludeSnow,
applyLavaMoat,
destinationFileName: 'load-background.js',
});
Expand All @@ -695,6 +720,7 @@ function createFactoredBuild({
...groupSet.values(),
].map((label) => `../${label}.js`);
await createManifestV3AppInitializationBundle({
shouldIncludeSnow,
applyLavaMoat,
browserPlatforms,
buildTarget,
Expand All @@ -714,6 +740,7 @@ function createFactoredBuild({
groupSet,
commonSet,
browserPlatforms,
shouldIncludeSnow,
applyLavaMoat: false,
});
break;
Expand All @@ -723,6 +750,7 @@ function createFactoredBuild({
groupSet,
commonSet,
browserPlatforms,
shouldIncludeSnow,
applyLavaMoat,
destinationFileName: 'load-offscreen.js',
});
Expand Down Expand Up @@ -1109,6 +1137,7 @@ function renderJavaScriptLoader({
groupSet,
commonSet,
browserPlatforms,
shouldIncludeSnow,
applyLavaMoat,
destinationFileName,
}) {
Expand Down Expand Up @@ -1136,8 +1165,9 @@ function renderJavaScriptLoader({
];

const requiredScripts = [
'./scripts/snow.js',
'./scripts/use-snow.js',
...(shouldIncludeSnow
? ['./scripts/snow.js', './scripts/use-snow.js']
: []),
'./scripts/sentry-install.js',
...securityScripts,
...jsBundles,
Expand All @@ -1160,6 +1190,7 @@ function renderJavaScriptLoader({
function renderHtmlFile({
htmlName,
browserPlatforms,
shouldIncludeSnow,
applyLavaMoat,
isMMI,
isTest,
Expand All @@ -1169,11 +1200,21 @@ function renderHtmlFile({
'build/scripts/renderHtmlFile - must specify "applyLavaMoat" option',
);
}
if (shouldIncludeSnow === undefined) {
throw new Error(
'build/scripts/renderHtmlFile - must specify "shouldIncludeSnow" option',
);
}

const htmlFilePath = `./app/${htmlName}.html`;
const htmlTemplate = readFileSync(htmlFilePath, 'utf8');

const eta = new Eta();
const htmlOutput = eta.renderString(htmlTemplate, { isMMI, isTest });
const htmlOutput = eta.renderString(htmlTemplate, {
isMMI,
isTest,
shouldIncludeSnow,
});
browserPlatforms.forEach((platform) => {
const dest = `./dist/${platform}/${htmlName}.html`;
// we dont have a way of creating async events atm
Expand Down
28 changes: 14 additions & 14 deletions development/build/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,20 @@ function getCopyTargets(
pattern: `*.css`,
dest: ``,
},
{
src: `./app/loading.html`,
dest: `loading.html`,
},
{
src: shouldIncludeSnow
? `./node_modules/@lavamoat/snow/snow.prod.js`
: EMPTY_JS_FILE,
dest: `scripts/snow.js`,
},
{
src: shouldIncludeSnow ? `./app/scripts/use-snow.js` : EMPTY_JS_FILE,
dest: `scripts/use-snow.js`,
},
...(shouldIncludeSnow
? [
{
src: shouldIncludeSnow
? `./node_modules/@lavamoat/snow/snow.prod.js`
: EMPTY_JS_FILE,
dest: `scripts/snow.js`,
},
{
src: `./app/scripts/use-snow.js`,
dest: `scripts/use-snow.js`,
},
]
: []),
{
src: shouldIncludeLockdown
? getPathInsideNodeModules('ses', 'dist/lockdown.umd.min.js')
Expand Down
10 changes: 9 additions & 1 deletion development/build/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ function createTask(taskName, taskFn) {

function runInChildProcess(
task,
{ applyLavaMoat, buildType, isLavaMoat, policyOnly, shouldLintFenceFiles },
{
shouldIncludeSnow,
applyLavaMoat,
buildType,
isLavaMoat,
policyOnly,
shouldLintFenceFiles,
},
) {
const taskName = typeof task === 'string' ? task : task.taskName;
if (!taskName) {
Expand All @@ -68,6 +75,7 @@ function runInChildProcess(
// LavaMoat if the parent process also ran in LavaMoat.
isLavaMoat ? 'build' : 'build:dev',
taskName,
`--snow=${shouldIncludeSnow ? 'true' : 'false'}`,
`--apply-lavamoat=${applyLavaMoat ? 'true' : 'false'}`,
`--build-type=${buildType}`,
`--lint-fence-files=${shouldLintFenceFiles ? 'true' : 'false'}`,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
},
"scripts": {
"start": "yarn build:dev dev --apply-lavamoat=false --snow=false",
"start:mv3": "ENABLE_MV3=true yarn build:dev dev --apply-lavamoat=false",
"start:mv3": "ENABLE_MV3=true yarn build:dev dev --apply-lavamoat=false --snow=false",
"start:flask": "yarn start --build-type flask",
"start:mmi": "yarn start --build-type mmi",
"start:lavamoat": "yarn build:dev dev --apply-lavamoat=true",
"dist": "yarn build dist",
"dist:mv3": "ENABLE_MV3=true yarn build dist",
"dist:mmi": "yarn dist --build-type mmi",
"dist:mmi:debug": "yarn dist --build-type mmi --apply-lavamoat=false",
"dist:mmi:debug": "yarn dist --build-type mmi --apply-lavamoat=false --snow=false",
"build": "yarn lavamoat:build",
"build:dev": "node development/build/index.js",
"start:test": "BLOCKAID_FILE_CDN=static.cx.metamask.io/api/v1/confirmations/ppom SEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='FAKE' SENTRY_DSN_DEV=https://fake@sentry.io/0000000 yarn build:dev testDev --apply-lavamoat=false --snow=false",
Expand Down
File renamed without changes.
10 changes: 8 additions & 2 deletions test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { difference } = require('lodash');
const createStaticServer = require('../../development/create-static-server');
const { tEn } = require('../lib/i18n-helpers');
const { setupMocking } = require('./mock-e2e');
const { Ganache } = require('./ganache');
const { Ganache } = require('./seeder/ganache');
const FixtureServer = require('./fixture-server');
const PhishingWarningPageServer = require('./phishing-warning-page-server');
const { buildWebDriver } = require('./webdriver');
Expand Down Expand Up @@ -71,7 +71,13 @@ async function withFixtures(options, testSuite) {

if (smartContract) {
const ganacheSeeder = new GanacheSeeder(ganacheServer.getProvider());
await ganacheSeeder.deploySmartContract(smartContract);
const contracts =
smartContract instanceof Array ? smartContract : [smartContract];
await Promise.all(
contracts.map((contract) =>
ganacheSeeder.deploySmartContract(contract),
),
);
contractRegistry = ganacheSeeder.getContractRegistry();
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 6851000

Please sign in to comment.