Skip to content

Commit

Permalink
Merge pull request #212 from Synthetixio/dev
Browse files Browse the repository at this point in the history
promote dev to master
  • Loading branch information
drptbl authored Sep 8, 2021
2 parents 2b48f5c + 37e9419 commit 4f82a19
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/audit_and_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Upload lint results
# run if lint failed and only on master/dev branch and pull requests
if: always() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || github.event_name == 'pull_request')
uses: github/codeql-action/upload-sarif@b0e70410b40f1a9af3bba1cecd95b4b57896af26 # pin@codeql-bundle-20210517
uses: github/codeql-action/upload-sarif@89d78ba4572c7854683ec144d212bf0b52cd2a2a # pin@codeql-bundle-20210517
with:
sarif_file: lint-results.sarif
continue-on-error: true
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # pin@v2

- name: Initialize CodeQL
uses: github/codeql-action/init@b0e70410b40f1a9af3bba1cecd95b4b57896af26
uses: github/codeql-action/init@89d78ba4572c7854683ec144d212bf0b52cd2a2a
with:
queries: security-and-quality
languages: javascript

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@b0e70410b40f1a9af3bba1cecd95b4b57896af26
uses: github/codeql-action/analyze@89d78ba4572c7854683ec144d212bf0b52cd2a2a
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ There is a global [`before()`](https://github.com/synthetixio/synpress/blob/mast
- changes network (defaults to `kovan`) or creates custom network and changes to it (depending on your setup)
- switches back to Cypress window and starts testing

It requires environmental variable called `SECRET_WORDS` to be present in following format => `'word1, word2, etc..'`.
It requires environmental variable called `SECRET_WORDS` to be present in following format => `'word1, word2, etc..'` or private key in an environmental variable called `PRIVATE_KEY`.

To change default network (`kovan`), you can use `NETWORK_NAME` environmental variable, for example: `NETWORK_NAME=rinkeby`.

Expand All @@ -109,9 +109,9 @@ Metamask version is hardcoded and frequently updated under supervision to avoid

If you don't want to use environmental variables, you can modify [`setupMetamask()`](https://github.com/synthetixio/synpress/blob/master/support/index.js#L26) to following:

`setupMetamask(secretWords, network, password)`, for example: `setupMetamask('word1, word2, etc..', 'mainnet', 'password')`.
`setupMetamask(secretWordsOrPrivateKey, network, password)`, for example: `setupMetamask('word1, word2, etc..', 'mainnet', 'password')`.

You can also add and switch to custom network by passing an `object` instead of `string` inside `setupMetamask(secretWords, network, password)` function for `network` parameter.
You can also add and switch to custom network by passing an `object` instead of `string` inside `setupMetamask(secretWordsOrPrivateKey, network, password)` function for `network` parameter.

If you want to use Etherscan API helpers, you will have to provide Etherscan API key using `ETHERSCAN_KEY` enironmental variable.

Expand Down
54 changes: 52 additions & 2 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const {
firstTimeFlowPageElements,
metametricsPageElements,
firstTimeFlowFormPageElements,
secureYourWalletPageElements,
revealSeedPageElements,
endOfFlowPageElements,
} = require('../pages/metamask/first-time-flow-page');
const { mainPageElements } = require('../pages/metamask/main-page');
Expand Down Expand Up @@ -86,6 +88,49 @@ module.exports = {
}
return true;
},
createWallet: async password => {
await puppeteer.waitAndClick(firstTimeFlowPageElements.createWalletButton);
await puppeteer.waitAndClick(metametricsPageElements.optOutAnalyticsButton);
await puppeteer.waitAndType(
firstTimeFlowFormPageElements.newPasswordInput,
password,
);
await puppeteer.waitAndType(
firstTimeFlowFormPageElements.confirmPasswordInput,
password,
);
await puppeteer.waitAndClick(
firstTimeFlowFormPageElements.newSignupCheckbox,
);
await puppeteer.waitAndClick(firstTimeFlowFormPageElements.importButton);

await puppeteer.waitFor(pageElements.loadingSpinner);
await puppeteer.waitAndClick(secureYourWalletPageElements.nextButton);
await puppeteer.waitAndClick(revealSeedPageElements.remindLaterButton);
await puppeteer.waitFor(mainPageElements.walletOverview);

// close popup if present
if (
(await puppeteer.metamaskWindow().$(mainPageElements.popup.container)) !==
null
) {
await puppeteer.waitAndClick(mainPageElements.popup.closeButton);
}
return true;
},
importFromPrivateKey: async privateKey => {
await puppeteer.waitAndClick(mainPageElements.accountMenu.button);
await puppeteer.waitAndClick(
mainPageElements.accountMenu.importAccountButton,
);

await puppeteer.waitAndType(
mainPageElements.importAccount.input,
privateKey,
);
await puppeteer.waitAndClick(mainPageElements.importAccount.importButton);
return true;
},
changeNetwork: async network => {
setNetwork(network);
await puppeteer.waitAndClick(mainPageElements.networkSwitcher.button);
Expand Down Expand Up @@ -320,7 +365,7 @@ module.exports = {
await puppeteer.waitAndClick(mainPageElements.accountModal.closeButton);
return walletAddress;
},
initialSetup: async ({ secretWords, network, password }) => {
initialSetup: async ({ secretWordsOrPrivateKey, network, password }) => {
const isCustomNetwork =
process.env.NETWORK_NAME && process.env.RPC_URL && process.env.CHAIN_ID;

Expand All @@ -332,7 +377,12 @@ module.exports = {
null
) {
await module.exports.confirmWelcomePage();
await module.exports.importWallet(secretWords, password);
if (secretWordsOrPrivateKey.includes(' ')) {
await module.exports.importWallet(secretWordsOrPrivateKey, password);
} else {
await module.exports.createWallet(password);
await module.exports.importFromPrivateKey(secretWordsOrPrivateKey);
}
if (isCustomNetwork) {
await module.exports.addNetwork(network);
} else {
Expand Down
81 changes: 52 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"bytes32": "0.0.3",
"commander": "8.1.0",
"cross-zip": "4.0.0",
"cypress": "8.3.0",
"cypress": "8.3.1",
"cypress-wait-until": "1.7.1",
"eslint": "7.32.0",
"eslint-config-prettier": "8.3.0",
Expand Down
16 changes: 15 additions & 1 deletion pages/metamask/first-time-flow-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ module.exports.welcomePageElements = {
};

const firstTimeFlowPage = '.first-time-flow';
const importWalletButton = `${firstTimeFlowPage} .first-time-flow__button`;
const importWalletButton = `${firstTimeFlowPage} .select-action__select-button:nth-child(1) .first-time-flow__button`;
const createWalletButton = `${firstTimeFlowPage} .select-action__select-button:nth-child(2) .first-time-flow__button`;
module.exports.firstTimeFlowPageElements = {
firstTimeFlowPage,
importWalletButton,
createWalletButton,
};

const metametricsPage = '.metametrics-opt-in';
Expand All @@ -27,13 +29,25 @@ const passwordInput = `${firstTimeFlowFormPage} #password`;
const confirmPasswordInput = `${firstTimeFlowFormPage} #confirm-password`;
const termsCheckbox = `${firstTimeFlowFormPage} .first-time-flow__terms`;
const importButton = `${firstTimeFlowFormPage} .first-time-flow__button`;
const newPasswordInput = `${firstTimeFlowFormPage} #create-password`;
const newSignupCheckbox = `${firstTimeFlowFormPage} .first-time-flow__checkbox`;

module.exports.firstTimeFlowFormPageElements = {
firstTimeFlowFormPage,
secretWordsInput,
passwordInput,
confirmPasswordInput,
termsCheckbox,
importButton,
newPasswordInput,
newSignupCheckbox,
};

const secureYourWalletPage = '.first-time-flow__wrapper';
const nextButton = `${secureYourWalletPage} button`;
module.exports.secureYourWalletPageElements = {
secureYourWalletPage,
nextButton,
};

const endOfFlowPage = '.end-of-flow';
Expand Down
Loading

0 comments on commit 4f82a19

Please sign in to comment.