Skip to content

Commit

Permalink
Merge pull request #668 from Synthetixio/dev
Browse files Browse the repository at this point in the history
promote dev to master
  • Loading branch information
drptbl authored Mar 7, 2023
2 parents 74ffcc6 + 19929ef commit 13d098f
Show file tree
Hide file tree
Showing 18 changed files with 396 additions and 178 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ dist
coverage
# don't lint metamask download folder
downloads
# dont lint examples
examples
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ tests/e2e/screenshots

images/demo.gif
images/synpress.png

examples
4 changes: 2 additions & 2 deletions commands/etherscan.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
return { txStatus, txReceipt };
},
async waitForTxSuccess(txid) {
const txStatus = await this.getTransactionStatus(txid);
const txStatus = await module.exports.getTransactionStatus(txid);
if (
// status success
txStatus.txReceipt.result &&
Expand All @@ -38,7 +38,7 @@ module.exports = {
console.log(`Transaction ${txid} is still pending.. waiting..`);
retries++;
await sleep(5000);
const result = await this.waitForTxSuccess(txid);
const result = await module.exports.waitForTxSuccess(txid);
return result;
} else {
retries = 0;
Expand Down
119 changes: 52 additions & 67 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,28 @@ const metamask = {
await playwright.waitUntilStable();
},
async goToHome() {
await this.goTo(extensionHomeUrl);
await module.exports.goTo(extensionHomeUrl);
},
async goToSettings() {
await this.goTo(extensionSettingsUrl);
await module.exports.goTo(extensionSettingsUrl);
},
async goToAdvancedSettings() {
await this.goTo(extensionAdvancedSettingsUrl);
await module.exports.goTo(extensionAdvancedSettingsUrl);
},
async goToExperimentalSettings() {
await this.goTo(extensionExperimentalSettingsUrl);
await module.exports.goTo(extensionExperimentalSettingsUrl);
},
async goToAddNetwork() {
await this.goTo(extensionAddNetworkUrl);
await module.exports.goTo(extensionAddNetworkUrl);
},
async goToNewAccount() {
await this.goTo(extensionNewAccountUrl);
await module.exports.goTo(extensionNewAccountUrl);
},
async goToImportAccount() {
await this.goTo(extensionImportAccountUrl);
await module.exports.goTo(extensionImportAccountUrl);
},
async goToImportToken() {
await this.goTo(extensionImportTokenUrl);
await module.exports.goTo(extensionImportTokenUrl);
},
async getExtensionDetails() {
extensionInitialUrl = await playwright.metamaskWindow().url();
Expand Down Expand Up @@ -202,7 +202,7 @@ const metamask = {
return true;
},
async unlock(password) {
await this.fixBlankPage();
await module.exports.fixBlankPage();
await playwright.waitAndType(unlockPageElements.passwordInput, password);
await playwright.waitAndClick(
unlockPageElements.unlockButton,
Expand All @@ -211,7 +211,7 @@ const metamask = {
waitForEvent: 'navi',
},
);
await this.closePopupAndTooltips();
await module.exports.closePopupAndTooltips();
return true;
},
async optOutAnalytics() {
Expand All @@ -232,7 +232,7 @@ const metamask = {
waitForEvent: 'navi',
},
);
await this.optOutAnalytics();
await module.exports.optOutAnalytics();
// todo: add support for more secret words (15/18/21/24)
for (const [index, word] of secretWords.split(' ').entries()) {
await playwright.waitAndType(
Expand Down Expand Up @@ -280,7 +280,7 @@ const metamask = {
waitForEvent: 'navi',
},
);
await this.closePopupAndTooltips();
await module.exports.closePopupAndTooltips();
return true;
},
async createWallet(password) {
Expand All @@ -291,7 +291,7 @@ const metamask = {
waitForEvent: 'navi',
},
);
await this.optOutAnalytics();
await module.exports.optOutAnalytics();
await playwright.waitAndType(
firstTimeFlowImportPageElements.passwordInput,
password,
Expand Down Expand Up @@ -334,12 +334,12 @@ const metamask = {
waitForEvent: 'navi',
},
);
await this.closePopupAndTooltips();
await module.exports.closePopupAndTooltips();
return true;
},
async importAccount(privateKey) {
await switchToMetamaskIfNotActive();
await this.goToImportAccount();
await module.exports.goToImportAccount();
await playwright.waitAndType(
mainPageElements.importAccount.input,
privateKey,
Expand All @@ -351,7 +351,7 @@ const metamask = {
waitForEvent: 'navi',
},
);
await this.closePopupAndTooltips();
await module.exports.closePopupAndTooltips();
await switchToCypressIfNotActive();
return true;
},
Expand All @@ -360,15 +360,15 @@ const metamask = {
accountName = accountName.toLowerCase();
}
await switchToMetamaskIfNotActive();
await this.goToNewAccount();
await module.exports.goToNewAccount();
if (accountName) {
await playwright.waitAndType(
mainPageElements.createAccount.input,
accountName,
);
}
await playwright.waitAndClick(mainPageElements.createAccount.createButton);
await this.closePopupAndTooltips();
await module.exports.closePopupAndTooltips();
await switchToCypressIfNotActive();
return true;
},
Expand All @@ -379,7 +379,7 @@ const metamask = {
await switchToMetamaskIfNotActive();
// note: closePopupAndTooltips() is required after changing createAccount() to use direct urls (popup started appearing)
// ^ this change also introduced 500ms delay for closePopupAndTooltips() function
await this.closePopupAndTooltips();
await module.exports.closePopupAndTooltips();
await playwright.waitAndClick(mainPageElements.accountMenu.button);
if (typeof accountNameOrAccountNumber === 'number') {
await playwright.waitAndClick(
Expand All @@ -391,7 +391,7 @@ const metamask = {
accountNameOrAccountNumber,
);
}
await this.closePopupAndTooltips();
await module.exports.closePopupAndTooltips();
await switchToCypressIfNotActive();
return true;
},
Expand Down Expand Up @@ -438,7 +438,7 @@ const metamask = {
);
}
await playwright.waitUntilStable();
await this.closePopupAndTooltips();
await module.exports.closePopupAndTooltips();
await setNetwork(network);
await switchToCypressIfNotActive();
return true;
Expand All @@ -464,7 +464,7 @@ const metamask = {
} else if (typeof network === 'object') {
network.networkName = network.networkName.toLowerCase();
}
await this.goToAddNetwork();
await module.exports.goToAddNetwork();
await playwright.waitAndType(
addNetworkPageElements.networkNameInput,
network.networkName,
Expand Down Expand Up @@ -496,7 +496,7 @@ const metamask = {
waitForEvent: 'navi',
},
);
await this.closePopupAndTooltips();
await module.exports.closePopupAndTooltips();
await setNetwork(network);
await playwright.waitForText(
mainPageElements.networkSwitcher.networkName,
Expand Down Expand Up @@ -531,7 +531,7 @@ const metamask = {
'[disconnectWalletFromDapp] Wallet is not connected to a dapp, skipping..',
);
}
await this.closeModal();
await module.exports.closeModal();
await switchToCypressIfNotActive();
return true;
},
Expand Down Expand Up @@ -562,7 +562,7 @@ const metamask = {
'[disconnectWalletFromAllDapps] Wallet is not connected to any dapps, skipping..',
);
}
await this.closeModal();
await module.exports.closeModal();
await switchToCypressIfNotActive();
return true;
},
Expand All @@ -573,13 +573,6 @@ const metamask = {
skipSetup,
);
},
async activateEnhancedTokenDetection(skipSetup) {
return await activateAdvancedSetting(
advancedPageElements.enhancedTokenDetectionToggleOn,
advancedPageElements.enhancedTokenDetectionToggleOff,
skipSetup,
);
},
async activateShowHexData(skipSetup) {
return await activateAdvancedSetting(
advancedPageElements.showHexDataToggleOn,
Expand Down Expand Up @@ -623,17 +616,9 @@ const metamask = {
true,
);
},
async activateShowCustomNetworkList(skipSetup) {
return await activateAdvancedSetting(
experimentalSettingsPageElements.showCustomNetworkListToggleOn,
experimentalSettingsPageElements.showCustomNetworkListToggleOff,
skipSetup,
true,
);
},
async resetAccount() {
await switchToMetamaskIfNotActive();
await this.goToAdvancedSettings();
await module.exports.goToAdvancedSettings();
await playwright.waitAndClick(advancedPageElements.resetAccountButton);
await playwright.waitAndClick(resetAccountModalElements.resetButton);
await playwright.waitAndClick(
Expand All @@ -643,7 +628,7 @@ const metamask = {
waitForEvent: 'navi',
},
);
await this.closePopupAndTooltips();
await module.exports.closePopupAndTooltips();
await switchToCypressIfNotActive();
return true;
},
Expand Down Expand Up @@ -708,7 +693,7 @@ const metamask = {
async importToken(tokenConfig) {
let tokenData = {};
await switchToMetamaskIfNotActive();
await this.goToImportToken();
await module.exports.goToImportToken();
if (typeof tokenConfig === 'string') {
await playwright.waitAndType(
mainPageElements.importToken.tokenContractAddressInput,
Expand Down Expand Up @@ -761,7 +746,7 @@ const metamask = {
waitForEvent: 'navi',
},
);
await this.closePopupAndTooltips();
await module.exports.closePopupAndTooltips();
await switchToCypressIfNotActive();
tokenData.imported = true;
return tokenData;
Expand Down Expand Up @@ -830,7 +815,7 @@ const metamask = {
notificationPage,
{ waitForEvent: 'navi' },
);
await this.confirmSignatureRequest();
await module.exports.confirmSignatureRequest();
} else {
await playwright.waitAndClick(
permissionsPageElements.connectButton,
Expand Down Expand Up @@ -1145,8 +1130,8 @@ const metamask = {
return true;
},
async allowToAddAndSwitchNetwork() {
await this.allowToAddNetwork();
await this.allowToSwitchNetwork();
await module.exports.allowToAddNetwork();
await module.exports.allowToSwitchNetwork();
return true;
},
async getWalletAddress() {
Expand All @@ -1162,23 +1147,24 @@ const metamask = {
await switchToCypressIfNotActive();
return walletAddress;
},
async initialSetup({
secretWordsOrPrivateKey,
network,
password,
enableAdvancedSettings,
}) {
async initialSetup(
playwrightInstance,
{ secretWordsOrPrivateKey, network, password, enableAdvancedSettings },
) {
const isCustomNetwork =
(process.env.NETWORK_NAME &&
process.env.RPC_URL &&
process.env.CHAIN_ID) ||
typeof network == 'object';

await playwright.init();
if (playwrightInstance) {
await playwright.init(playwrightInstance);
} else {
await playwright.init();
}
await playwright.assignWindows();
await playwright.assignActiveTabName('metamask');
await this.getExtensionDetails();
await this.fixBlankPage();
await module.exports.getExtensionDetails();
await module.exports.fixBlankPage();
if (
await playwright
.metamaskWindow()
Expand All @@ -1187,21 +1173,21 @@ const metamask = {
) {
if (secretWordsOrPrivateKey.includes(' ')) {
// secret words
await this.importWallet(secretWordsOrPrivateKey, password);
await module.exports.importWallet(secretWordsOrPrivateKey, password);
} else {
// private key
await this.createWallet(password);
await this.importAccount(secretWordsOrPrivateKey);
await module.exports.createWallet(password);
await module.exports.importAccount(secretWordsOrPrivateKey);
}

await setupSettings(enableAdvancedSettings);

if (isCustomNetwork) {
await this.addNetwork(network);
await module.exports.addNetwork(network);
} else {
await this.changeNetwork(network);
await module.exports.changeNetwork(network);
}
walletAddress = await this.getWalletAddress();
walletAddress = await module.exports.getWalletAddress();
await playwright.switchToCypressWindow();
return true;
} else if (
Expand All @@ -1210,8 +1196,8 @@ const metamask = {
.locator(unlockPageElements.passwordInput)
.isVisible()
) {
await this.unlock(password);
walletAddress = await this.getWalletAddress();
await module.exports.unlock(password);
walletAddress = await module.exports.getWalletAddress();
await playwright.switchToCypressWindow();
return true;
} else {
Expand All @@ -1223,7 +1209,7 @@ const metamask = {
!process.env.RESET_METAMASK
) {
await switchToMetamaskIfNotActive();
walletAddress = await this.getWalletAddress();
walletAddress = await module.exports.getWalletAddress();
await playwright.switchToCypressWindow();
return true;
} else {
Expand Down Expand Up @@ -1289,7 +1275,6 @@ async function setupSettings(enableAdvancedSettings) {
await metamask.activateCustomNonce(true);
await metamask.activateDismissBackupReminder(true);
if (enableAdvancedSettings) {
await metamask.activateEnhancedTokenDetection(true);
await metamask.activateTestnetConversion(true);
}
await metamask.goToExperimentalSettings();
Expand Down
Loading

0 comments on commit 13d098f

Please sign in to comment.