Skip to content

Commit

Permalink
feat: add support for goerli (Synthetixio#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
josepmc authored Oct 7, 2022
1 parent 80b66ee commit c71ed67
Show file tree
Hide file tree
Showing 9 changed files with 16,214 additions and 25,794 deletions.
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Release CI](https://github.com/Synthetixio/synpress/actions/workflows/release.yml/badge.svg?branch=master)](https://github.com/Synthetixio/synpress/actions/workflows/release.yml)
[![Discord](https://img.shields.io/discord/961408653502599171.svg?color=768AD4&label=discord&logo=https%3A%2F%2Fdiscordapp.com%2Fassets%2F8c9701b98ad4372b58f13fd9f65f966e.svg)](https://discordapp.com/channels/961408653502599171/)
[![Twitter Follow](https://img.shields.io/twitter/follow/synpress_.svg?label=Synpress_&style=social)](https://twitter.com/Synpress_)

#

<p align="center">
Expand Down Expand Up @@ -58,24 +59,33 @@ project_dir

```js
const path = require('path');
const synpressPath = path.join(process.cwd(), '/node_modules/@synthetixio/synpress');
const synpressPath = path.join(
process.cwd(),
'/node_modules/@synthetixio/synpress',
);

module.exports = {
extends: `${synpressPath}/.eslintrc.js`,
extends: `${synpressPath}/.eslintrc.js`,
};
```

2. Create `tsconfig.json` inside your tests folder (`/project_dir/tests/e2e`):

```json
{
"compilerOptions": {
"allowJs": true,
"baseUrl": "../../node_modules",
"types": ["cypress", "@types/puppeteer-core", "@synthetixio/synpress/support", "cypress-wait-until", "@testing-library/cypress"],
"outDir": "./output"
},
"include": ["**/*.*"]
"compilerOptions": {
"allowJs": true,
"baseUrl": "../../node_modules",
"types": [
"cypress",
"@types/puppeteer-core",
"@synthetixio/synpress/support",
"cypress-wait-until",
"@testing-library/cypress"
],
"outDir": "./output"
},
"include": ["**/*.*"]
}
```

Expand All @@ -95,14 +105,14 @@ There is a global [`before()`](https://github.com/synthetixio/synpress/blob/mast

- passes welcome page
- imports wallet
- changes network (defaults to `kovan`) or creates custom network and changes to it (depending on your setup)
- changes network (defaults to `goerli`) 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..'` 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`.
To change default network (`goerli`), you can use `NETWORK_NAME` environmental variable, for example: `NETWORK_NAME=rinkeby`.

Available choices are: `mainnet`, `ropsten`, `kovan`, `rinkeby`, `goerli` and `localhost`.
Available choices are: `mainnet`, `ropsten` (deprecated), `kovan` (deprecated), `rinkeby`, `goerli` and `localhost`.

To create and switch to custom network at metamask setup phase, use these:

Expand Down
3 changes: 2 additions & 1 deletion commands/etherscan.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const sleep = require('util').promisify(setTimeout);
const { getEnv } = require('../helpers');

let retries = 0;

Expand All @@ -7,7 +8,7 @@ module.exports = {
const { getNetwork } = require('../helpers');
const currentNetwork = getNetwork().networkName;
const etherscanApi = require('etherscan-api').init(
process.env.ETHERSCAN_KEY,
getEnv('ETHERSCAN_KEY'),
currentNetwork,
30000,
);
Expand Down
40 changes: 17 additions & 23 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const {
const {
confirmationPageElements,
} = require('../pages/metamask/confirmation-page');
const { setNetwork, getNetwork } = require('../helpers');
const { setNetwork, getNetwork, getEnv } = require('../helpers');

let walletAddress;
let switchBackToCypressWindow;
Expand Down Expand Up @@ -274,18 +274,14 @@ module.exports = {
addNetwork: async network => {
await switchToMetamaskIfNotActive();

if (
process.env.NETWORK_NAME &&
process.env.RPC_URL &&
process.env.CHAIN_ID
) {
if (getEnv('NETWORK_NAME') && getEnv('RPC_URL') && getEnv('CHAIN_ID')) {
network = {
networkName: process.env.NETWORK_NAME,
rpcUrl: process.env.RPC_URL,
chainId: process.env.CHAIN_ID,
symbol: process.env.SYMBOL,
blockExplorer: process.env.BLOCK_EXPLORER,
isTestnet: process.env.IS_TESTNET,
networkName: getEnv('NETWORK_NAME'),
rpcUrl: getEnv('RPC_URL'),
chainId: getEnv('CHAIN_ID'),
symbol: getEnv('SYMBOL'),
blockExplorer: getEnv('BLOCK_EXPLORER'),
isTestnet: getEnv('IS_TESTNET'),
};
}

Expand Down Expand Up @@ -483,13 +479,13 @@ module.exports = {
return true;
},
confirmTransaction: async gasConfig => {
const isKovanTestnet = getNetwork().networkName === 'kovan';
const isTestnet = getNetwork().networkName !== 'mainnet';
// todo: remove waitForTimeout below after improving switchToMetamaskNotification
await puppeteer.metamaskWindow().waitForTimeout(1000);
const notificationPage = await puppeteer.switchToMetamaskNotification();
// No notification is present
if (!notificationPage) return notificationPage;
if (isKovanTestnet) {
if (isTestnet) {
await puppeteer.waitAndSetValue(
'1',
confirmPageElements.gasFeeInput,
Expand Down Expand Up @@ -653,11 +649,9 @@ module.exports = {
defaultAction = 'ignore',
}) => {
const isCustomNetwork =
(process.env.NETWORK_NAME &&
process.env.RPC_URL &&
process.env.CHAIN_ID) ||
(getEnv('NETWORK_NAME') && getEnv('RPC_URL') && cy.env('CHAIN_ID')) ||
typeof network == 'object';

console.log(`isNetwork: ${isCustomNetwork} and ${network}`);
await puppeteer.init();
await puppeteer.assignWindows();
await puppeteer.assignActiveTabName('metamask');
Expand Down Expand Up @@ -697,17 +691,17 @@ module.exports = {
await module.exports.createWallet(password);
await module.exports.importAccount(secretWordsOrPrivateKey);
}
if (isCustomNetwork) {
await module.exports.addNetwork(network);
} else {
await module.exports.changeNetwork(network);
}
} else if (defaultAction === 'reset') {
await module.exports.importWallet(secretWordsOrPrivateKey, password);
} else {
await module.exports.unlock(password);
}
}
if (isCustomNetwork) {
await module.exports.addNetwork(network);
} else {
await module.exports.changeNetwork(network);
}
if (
(await puppeteer
.metamaskWindow()
Expand Down
7 changes: 7 additions & 0 deletions helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ let networkId = 1;
let isTestnet = false;

module.exports = {
getEnv: envVar => {
if (global.cy) {
debugger;
return cy.env(envVar);
}
return process.env[envVar];
},
setNetwork: network => {
if (network === 'mainnet') {
networkName = 'mainnet';
Expand Down
Loading

0 comments on commit c71ed67

Please sign in to comment.