UNPKG

@assert-equals/dappdriver

Version:

DappDriver is an e2e testing framework designed for testing decentralized applications (dApps) using MetaMask, Rainbow or Zerion

43 lines (42 loc) 2.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.enableMetaMaskAutomation = exports.install = void 0; const fs_1 = require("fs"); const path_1 = __importDefault(require("path")); const constants_1 = require("../constants"); const log_1 = require("../log"); const install_1 = require("../wallet/install"); async function install(directory, version = constants_1.DEFAULT_METAMASK_FLASK_VERSION) { try { const assetName = `${constants_1.DEFAULT_METAMASK_FLASK_ASSET}-${version}-flask.0`; let destDir = `${directory}/${assetName}`; const exists = (0, install_1.fileExists)(destDir); if (exists) { (0, log_1.logInfo)(`MetaMask Flask version <v${version}> already exists in ${destDir}`); return destDir; } (0, install_1.compareVersion)(constants_1.METAMASK_FLASK, version, constants_1.RECOMMENDED_METAMASK_FLASK_VERSIONS); const release = await (0, install_1.fetchGithubRelease)(constants_1.METAMASK_FLASK, version, constants_1.METAMASK_GITHUB_API); const asset = (0, install_1.findGithubAsset)(assetName, release); (0, install_1.createDirectory)(directory); const fileName = await (0, install_1.downloadAssetZipFile)(asset, directory); destDir = (0, install_1.extractZipContents)(fileName); await enableMetaMaskAutomation(destDir); (0, log_1.logSuccess)(`Installed MetaMask Flask version <v${version}>\n${destDir}`); return destDir; } catch (error) { (0, log_1.logError)(error.message); } } exports.install = install; async function enableMetaMaskAutomation(metaMaskPath) { const runtimeLavaMoatPath = path_1.default.resolve(metaMaskPath, 'scripts', 'runtime-lavamoat.js'); const file = (0, fs_1.readFileSync)(runtimeLavaMoatPath, 'utf8'); const updatedRuntimeLavaMoatData = file.replace(`"scuttleGlobalThis":{"enabled":true`, `"scuttleGlobalThis":{"enabled":false`); (0, fs_1.writeFileSync)(runtimeLavaMoatPath, updatedRuntimeLavaMoatData); } exports.enableMetaMaskAutomation = enableMetaMaskAutomation;