Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playwright test for ReefKnot #203

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2957649
feat: create playwright test for reef-knot
jake4take Nov 20, 2024
50ab383
fix: fix env naming
jake4take Nov 29, 2024
9c69efb
fix: fix env naming
jake4take Nov 29, 2024
d9051e6
fix: fixed the setup extension process
jake4take Nov 29, 2024
bcedc93
fix: some fixes after review
jake4take Dec 4, 2024
dafb5e9
Merge branch 'main' of github.com:lidofinance/reef-knot into playwrig…
jake4take Dec 4, 2024
fdfb991
chore: merge with main
jake4take Dec 4, 2024
d94114f
fix: fix test.yaml
jake4take Dec 4, 2024
0a2660e
fix: fix test.yaml
jake4take Dec 4, 2024
02be069
fix: fix test.yaml
jake4take Dec 4, 2024
e91f8c5
fix: fix test.yaml
jake4take Dec 5, 2024
9b1957c
fix: fix test.yaml
jake4take Dec 5, 2024
d55bb14
fix: fix test.yaml
jake4take Dec 5, 2024
8967f64
fix: fix test.yaml
jake4take Dec 5, 2024
94a7c52
fix: fix test.yaml
jake4take Dec 5, 2024
bda5e06
fix: config fixes
jake4take Dec 5, 2024
2bfb564
fix: fix test.yaml
jake4take Dec 5, 2024
a2a4508
fix: fix reporter config
jake4take Dec 5, 2024
73d13b7
fix: fix tags
jake4take Dec 5, 2024
4e5ecf6
fix: fix reporter
jake4take Dec 5, 2024
b1888d3
fix: fix tests
jake4take Dec 5, 2024
bc0d644
fix: fixes after review
jake4take Dec 12, 2024
5103968
fix: fix initWalletSetup()
jake4take Dec 12, 2024
8bdc461
test: update wallets=testing-modules version
jake4take Dec 23, 2024
5d6c703
fix: check the stat ETH balance with SDK (instead of wallet balance)
jake4take Dec 24, 2024
b670095
chore: remove test run for pull request
jake4take Dec 24, 2024
3e8876d
feat: add test of stake tx
jake4take Dec 28, 2024
07b2b43
fix: fix report config naming
jake4take Dec 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Test ReefKnot

on:
workflow_dispatch:
inputs:
STAND_ENV:
description: 'Stand env'
required: true
type: choice
default: testnet
options:
- mainnet
- testnet
WALLETS:
description: 'Select wallet to run tests'
required: true
type: choice
default: All
options:
- All
- metamask
- okx


jobs:
test:
runs-on: ubuntu-latest
environment: test
env:
TEST_BRANCH: ${{ github.event.inputs.branch }}
RPC_URL_KEY: ${{ secrets.RPC_URL_KEY }}
QASE_API_TOKEN: ${{ secrets.QASE_API_TOKEN }}
WALLET_SECRET_PHRASE: ${{ secrets.WALLET_SECRET_PHRASE }}
WALLET_PASSWORD: ${{ secrets.WALLET_PASSWORD }}
STAND_ENV: ${{ github.event.inputs.STAND_ENV || 'testnet' }}
WALLETS: ${{ github.event.inputs.WALLETS || 'All' }}
STAND_TYPE: stand
NODE_OPTIONS: --max-old-space-size=4096

steps:
- uses: actions/checkout@v4
with:
jake4take marked this conversation as resolved.
Show resolved Hide resolved
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}

- uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: yarn install --immutable
working-directory: playwright-tests

- name: Install Playwright Browsers
run: yarn playwright install chromium --with-deps
working-directory: playwright-tests

- name: Run tests
working-directory: playwright-tests
run: |
echo "Running All tests"
xvfb-run --auto-servernum -- yarn test:reef-knot

- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-tests/playwright-report/
retention-days: 30
2 changes: 1 addition & 1 deletion apps/demo-react/components/action-item/action-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const ActionItem: FC<PropsWithChildren<ActionItemProps>> = (props) => {

return (
<WrapperStyle>
<ActionStyle title={title} walletAction action={action}>
<ActionStyle title={title} walletAction action={action} data-testid={title+'Block'}>
{children}
</ActionStyle>
</WrapperStyle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const WalletButton: FC<ButtonProps> = (props) => {
variant="text"
color="secondary"
onClick={openModal}
data-testid="walletBtn"
{...rest}
>
<WalletButtonWrapperStyle>
Expand Down
2 changes: 1 addition & 1 deletion apps/demo-react/components/stats-item/stats-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const StatsItem: FC<StatsItemProps> = ({ value, token, loading }) => {

return (
<StatsWrapperStyle>
<ContentWrapperStyle>
<ContentWrapperStyle data-testid={token}>
<StatsValueStyle>
{loading ? <InlineLoaderStyle /> : shortValue}
</StatsValueStyle>
Expand Down
3 changes: 2 additions & 1 deletion apps/demo-react/components/walletModal/walletModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const WalletModal: FC<ModalProps> = (props) => {
};
return (
<Modal title="Account" {...props}>
<WalletModalContentStyle>
<WalletModalContentStyle data-testid='walletModal'>
<WalletModalConnectedStyle>
{connectorName && (
<WalletModalConnectorStyle>
Expand All @@ -66,6 +66,7 @@ const WalletModal: FC<ModalProps> = (props) => {
size="xs"
variant="outlined"
onClick={handleDisconnect}
data-testid='disconnectBtn'
>
Disconnect
</WalletModalDisconnectStyle>
Expand Down
7 changes: 4 additions & 3 deletions apps/demo-react/features/stats/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const StatsComponent = () => {
: formatEther(wstethBalance.data || BigInt(0));

return (
<StatsWrapperStyle>
<StatsWrapperStyle data-testid="statsBlock">
<LeftColumnStyle>
<TokenInputWrapperStyle>
<ThemeProvider theme={themeLight}>
Expand All @@ -51,6 +51,7 @@ const StatsComponent = () => {
fullwidth
onChange={setInputValue}
value={inputValue}
data-testid="amountInput"
/>
</ThemeProvider>
</TokenInputWrapperStyle>
Expand All @@ -59,11 +60,11 @@ const StatsComponent = () => {
<InfoWrapperStyle>
<div>
<WalletInfoTitleStyle>Provider:</WalletInfoTitleStyle>
<WalletInfoValueStyle>{connectorName}</WalletInfoValueStyle>
<WalletInfoValueStyle data-testid="providerName">{connectorName}</WalletInfoValueStyle>
</div>
<div>
<WalletInfoTitleStyle>Network:</WalletInfoTitleStyle>
<WalletInfoValueStyle>{web3Info.chainId}</WalletInfoValueStyle>
<WalletInfoValueStyle data-testid="chainId">{web3Info.chainId}</WalletInfoValueStyle>
</div>
</InfoWrapperStyle>
<BalancesWrapperStyle>
Expand Down
18 changes: 18 additions & 0 deletions playwright-tests/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Playwright test run .env configuration

# Stand env for the wallet setup. Can be equal: testnet, mainnet
STAND_ENV=testnet

# Link type for a test run. Can be equal: stand, localhost
STAND_TYPE=localhost

# Wallet configurations
## Secret phase of the wallet to set up the wallet extension
WALLET_SECRET_PHRASE=
## Wallet password (use minimal 10 symbols with uppercase, lowercase, numbers, and symbols)
WALLET_PASSWORD=
## Drpc private key
RPC_URL_KEY=

# Qase reporter
QASE_API_TOKEN=
9 changes: 9 additions & 0 deletions playwright-tests/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
dist
playwright-report
test-results

/.jest

/.yarn/*
/.pnp.*
46 changes: 46 additions & 0 deletions playwright-tests/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint", "import"],
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"prettier/prettier": ["error", {}, { "usePrettierrc": true }],
"no-irregular-whitespace": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unnecessary-type-constraint": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ "ignoreRestSiblings": true }
]
},
"overrides": [
{
"files": ["*.js"],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off"
}
}
],
"settings": {
"import/resolver": {
"typescript": {
"alwaysTryTypes": true,
"project": "./tsconfig.json"
}
}
}
}
8 changes: 8 additions & 0 deletions playwright-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# playwright
test-results/
playwright-report/
.browser_context_*
logs/
.yalc
18 changes: 18 additions & 0 deletions playwright-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# <img src="logo.svg" alt='Reef Knot logo' height='45' align='top'/> Reef-Knot. Playwright test

## ❖ Installation
1. Install dependencies from the `/playwright-tests` directory:
```
yarn && yarn playwright install chromium
```
1. Fill the `.env` file in the `/playwright-tests` folder using the `.env.example` file as a template.

## ❖ How to run tests on a Deployed Stand
1. Set up the `.env` variable: `STAND_TYPE=stand`
2. Navigate to the `/playwright-tests` folder and run: `yarn test:reef-knot`

## ❖ How to run tests on Localhost
1. Start the `reef-knot` demo app on your local machine: `yarn run dev`
2. Verify the localhost link in `/playwright-tests/config/env.config.ts`, see the `STAND_LINK.localhost` property (_default value is http://localhost:3000_)
3. Set the `.env` variable: `STAND_TYPE=localhost`
4. Navigate to the `/playwright-tests` directory and run: `yarn test:reef-knot`
55 changes: 55 additions & 0 deletions playwright-tests/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
STAND_CONFIGS,
STAND_LINK,
STAND_ENV,
WALLETS,
TestWalletConfig,
} from './env.config';
import * as dotenv from 'dotenv';
import * as path from 'path';

dotenv.config({ path: path.resolve(__dirname, '../.env') });

export const REEF_KNOT_CONFIG = {
STAND_TYPE: process.env.STAND_TYPE,
STAND_CONFIG: getStandConfig(),
STAND_URL: getStandUrl(),
STAND_ENV: process.env.STAND_ENV,
WALLETS: getWalletsForTestRun(),
};

function getStandConfig() {
switch (process.env.STAND_ENV) {
case 'mainnet':
return STAND_CONFIGS.get(STAND_ENV.mainnet);
case 'testnet':
return STAND_CONFIGS.get(STAND_ENV.testnet);
default:
throw Error(
`CONFIG_VALIDATION_ERROR: STAND_ENV is not correctly defined (value is "${process.env.STAND_ENV}")`,
);
}
}

function getStandUrl() {
switch (process.env.STAND_TYPE) {
case 'stand':
return STAND_LINK.stand;
case 'localhost':
return STAND_LINK.localhost;
default:
throw Error(
`CONFIG_VALIDATION_ERROR: STAND_TYPE is not correctly defined (value is "${process.env.STAND_TYPE}")`,
);
}
}

function getWalletsForTestRun() {
const wallets: TestWalletConfig[] = [];
if (!process.env.WALLETS || process.env.WALLETS === 'All') {
WALLETS.forEach((wallet) => wallets.push(wallet));
} else {
wallets.push(WALLETS.get(process.env.WALLETS));
}
return wallets;
}
65 changes: 65 additions & 0 deletions playwright-tests/config/env.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
export interface StandConfig {
chainId: number;
tokenSymbol: string;
chainName: string;
rpcUrl: string;
scan: string;
contracts: {
stake: string;
wrap: string;
withdraw: string;
};
}

export const STAND_ENV = {
testnet: 'testnet',
mainnet: 'mainnet',
};

export const STAND_LINK = {
stand: 'https://lidofinance.github.io/reef-knot/',
localhost: 'http://localhost:3000/',
};

export const STAND_CONFIGS = new Map<string, StandConfig>([
[
STAND_ENV.testnet,
{
chainId: 17000,
tokenSymbol: 'ETH',
chainName: 'Holesky',
scan: 'https://holesky.etherscan.io/',
contracts: {
stake: '0x3F1c547b21f65e10480dE3ad8E19fAAC46C95034',
wrap: '0x8d09a4502Cc8Cf1547aD300E066060D043f6982D',
withdraw: '0xc7cc160b58F8Bb0baC94b80847E2CF2800565C50',
},
rpcUrl: `https://lb.drpc.org/ogrpc?network=holesky&dkey=${process.env.RPC_URL_KEY}`,
},
],
[
STAND_ENV.mainnet,
{
chainId: 1,
tokenSymbol: 'ETH',
chainName: 'Ethereum Mainnet',
scan: 'https://etherscan.io/',
contracts: {
stake: '0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84',
wrap: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
withdraw: '0x889edC2eDab5f40e902b864aD4d7AdE8E412F9B1',
},
rpcUrl: `https://lb.drpc.org/ogrpc?network=ethereum&dkey=${process.env.RPC_URL_KEY}`,
},
],
]);

export interface TestWalletConfig {
name: string;
connectWalletEvent: string;
}

export const WALLETS = new Map<string, TestWalletConfig>([
['metamask', { name: 'metamask', connectWalletEvent: 'metaMask connected' }],
['okx', { name: 'okx', connectWalletEvent: 'okx connected' }],
]);
3 changes: 3 additions & 0 deletions playwright-tests/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './config';
export * from './env.config';
export * from './reporter.config';
Loading