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

test(e2e): Fullset Solana tests FE-446 #436

Merged
merged 36 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7dbde17
refactor(e2e): replace phantom commands with phantomExtended for impr…
nelitow Nov 28, 2024
5827258
fix(e2e): make approveTransfer optional in ConnectorFunctions interface
nelitow Nov 29, 2024
aa87785
refactor(e2e): streamline SolanaConnector by replacing phantom comman…
nelitow Nov 29, 2024
c058316
refactor(e2e): enhance SolanaConnector tests by integrating session a…
nelitow Nov 29, 2024
e450e98
fix(e2e): make approveTransfer mandatory in ConnectorFunctions interf…
nelitow Nov 29, 2024
1cf948d
docs(e2e): Add comprehensive README for running E2E tests locally, in…
nelitow Nov 29, 2024
8193f7f
test(e2e): Enhance SolanaConnector tests with wallet funding and skip…
nelitow Nov 29, 2024
c6014ac
ci: Add build and deploy step for Solana predicates in CI workflow
nelitow Dec 2, 2024
586202c
chore: Update configuration files to use environment variables for pr…
nelitow Dec 2, 2024
d956407
Update pr-tests.yml
nelitow Dec 2, 2024
635230c
Update pr-tests.yml
nelitow Dec 2, 2024
84198eb
Update pr-tests.yml
nelitow Dec 2, 2024
dcdfa2c
refactor(e2e): update fundWallet function to accept dynamic funding a…
nelitow Dec 2, 2024
42726fa
test(e2e): Enhanced wallet funding logic to conditionally fund based…
nelitow Dec 2, 2024
436c28d
test(e2e): Refactor SolanaConnector tests to include session management
nelitow Dec 2, 2024
5c825b0
Update Readme.md
nelitow Dec 2, 2024
f438614
test(e2e): Refactor SolanaConnector tests to improve test structure a…
nelitow Dec 2, 2024
a4a1ac4
Update playwright.config.ts
nelitow Dec 2, 2024
df886aa
undo
nelitow Dec 2, 2024
2e54750
Update SolanaConnector.test.ts
nelitow Dec 2, 2024
977e6e1
Update README.md
nelitow Dec 2, 2024
580a8b1
tests: new .env setup
nelitow Dec 3, 2024
5ea184c
fix(e2e): Remove unnecessary workspace-root command from e2e dev test…
nelitow Dec 3, 2024
6e0811c
chore(e2e): Update README.md for environment setup instructions
nelitow Dec 3, 2024
5eaba57
Update pnpm-lock.yaml
nelitow Dec 3, 2024
99fd291
chore: remove redundant env
nelitow Dec 3, 2024
4cc76a6
fix: next env
nelitow Dec 3, 2024
544701b
wp project id
nelitow Dec 3, 2024
6d32c7d
wc increment
nelitow Dec 3, 2024
a9d71b1
fix(e2e): Adjust Playwright configuration for consistent worker settings
nelitow Dec 3, 2024
5acd2ec
chore: Refactor configuration to use dotenv for environment variables
nelitow Dec 3, 2024
cdfb08f
Update playwright.config.ts
nelitow Dec 3, 2024
dac2b46
test(e2e): Add wait timeout before connecting wallet in WalletConnect…
nelitow Dec 4, 2024
5159dc1
Merge branch 'main' into nj/docs/e2e
nelitow Dec 4, 2024
b9de404
Merge branch 'main' into nj/tests/final-solana-tests
nelitow Dec 4, 2024
76379c8
Merge branch 'nj/docs/e2e' into nj/tests/final-solana-tests
nelitow Dec 4, 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
24 changes: 14 additions & 10 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ jobs:
id: pnpm-cache
run: pnpm install --frozen-lockfile

- name: Copy .env file for E2E Tests
run: cp e2e-tests/runner/.env.example e2e-tests/runner/.env

- name: Copy .env file for React Next
run: cp e2e-tests/react-next/.env.example e2e-tests/react-next/.env

- name: Copy .env file for React App
run: cp examples/react-app/.env.example examples/react-app/.env

- name: Run build:connectors
run: pnpm build:connectors

Expand All @@ -120,6 +129,10 @@ jobs:
run: pnpm fuels build && pnpm fuels deploy
working-directory: packages/evm-predicates

- name: Build & Deploy Solana Predicates
run: pnpm fuels build && pnpm fuels deploy
working-directory: packages/solana-connector

- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps chromium
working-directory: e2e-tests/runner
Expand All @@ -132,14 +145,5 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
run: xvfb-run --auto-servernum -- pnpm --filter @e2e-tests/runner test:e2e
env:
VITE_FUEL_PROVIDER_URL: "http://localhost:4000/v1/graphql"
NEXT_PUBLIC_PROVIDER_URL: "http://localhost:4000/v1/graphql"
NEXT_PUBLIC_WC_PROJECT_ID: e01471314fc69cc4efba6dce12dfd710
NEXT_PUBLIC_CHAIN_ID_NAME: local
REACT_APP_PORT: 5173
REACT_NEXT_PORT: 3002
VITE_WALLET_SECRET: "0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298"
VITE_MASTER_WALLET_MNEMONIC: ${{ secrets.VITE_MASTER_WALLET_MNEMONIC }}
VITE_APP_WC_PROJECT_ID: e01471314fc69cc4efba6dce12dfd710
VITE_CHAIN_ID_NAME: local
PORT: 5173

4 changes: 2 additions & 2 deletions e2e-tests/react-next/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NEXT_PUBLIC_WC_PROJECT_ID=
NEXT_PUBLIC_PROVIDER_URL=https://testnet.fuel.network/v1/graphql
NEXT_PUBLIC_WC_PROJECT_ID=e01471314fc69cc4efba6dce12dfd710
NEXT_PUBLIC_PROVIDER_URL=http://localhost:4000/v1/graphql
4 changes: 0 additions & 4 deletions e2e-tests/react-next/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ const wagmiConfig = createConfig({
],
});

if (!PROVIDER_URL) {
throw new Error(`PROVIDER_URL is not set: ${PROVIDER_URL}`);
}

const FUEL_CONFIG = {
connectors: defaultConnectors({
devMode: true,
Expand Down
13 changes: 3 additions & 10 deletions e2e-tests/runner/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@
VITE_FUEL_PROVIDER_URL="http://localhost:4000/v1/graphql"
NEXT_PUBLIC_PROVIDER_URL="http://localhost:4000/v1/graphql"

# Project and chain configuration
NEXT_PUBLIC_WC_PROJECT_ID="your_wc_project_id"
NEXT_PUBLIC_CHAIN_ID_NAME="testnet"
VITE_APP_WC_PROJECT_ID="your_wc_project_id"
VITE_CHAIN_ID_NAME="local"

# Wallet configuration
VITE_WALLET_SECRET="your_wallet_secret"
VITE_MASTER_WALLET_MNEMONIC="your_wallet_mnemonic"
VITE_WALLET_SECRET=0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298
VITE_MASTER_WALLET_MNEMONIC=shuffle become fold deputy sick shove wolf olympic breeze antique ball broom

# Port settings
REACT_APP_PORT=5173
REACT_NEXT_PORT=3002
PORT=5173
REACT_NEXT_PORT=3002
83 changes: 83 additions & 0 deletions e2e-tests/runner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Running E2E Tests Locally

## Prerequisites
- Node.js v20.11.0
- PNPM v9.5.0
- Rust toolchain with `forc` and `fuel-core`

## Environment Setup
1. Copy `e2e-tests/runner/.env.example` to `e2e-tests/runner/.env`. They will have the required environment variables for local testing providing you have a local Fuel node running.
2. Copy `examples/react-app/.env.example` to `examples/react-app/.env`.
3. Copy `examples/react-next/.env.example` to `examples/react-next/.env`.

## Steps to Run Tests

1. **Start the Local Node**
```bash
pnpm node:up
```

2. **Install Dependencies**
```bash
pnpm install --frozen-lockfile
```

3. **Build Connectors**
```bash
pnpm build:connectors
```

4. **Build and Deploy Contracts**
```bash
cd e2e-tests/runner/scripts
pnpm deploy:contracts
```

5. **Build and Deploy EVM Predicates**
Copy `packages/evm-predicates/.env.example` to `packages/evm-predicates/.env`.
From the root directory:
```bash
cd packages/evm-predicates
pnpm fuels build && pnpm fuels deploy
```

6. **Build and Deploy Solana Predicates**
Copy `packages/solana-connector/.env.example` to `packages/solana-connector/.env`.
```bash
cd packages/solana-connector
pnpm fuels build && pnpm fuels deploy
```

7. **Install Playwright Browser**
```bash
cd e2e-tests/runner
pnpm exec playwright install --with-deps chromium
```

8. **Setup Synpress**
```bash
cd e2e-tests/runner
pnpm synpress wallet-setup
```

9. **Run the Tests**
```bash
cd e2e-tests/runner
pnpm test:e2e
```
Or to run the Playwright UI and start the servers:
```bash
cd e2e-tests/runner
pnpm test:e2e:dev
```

## Environment Variables
- `VITE_FUEL_PROVIDER_URL`: URL for the local Fuel node (default: http://localhost:4000/v1/graphql)
- `NEXT_PUBLIC_WC_PROJECT_ID`: Your WalletConnect project ID
- `VITE_WALLET_SECRET`: Your wallet secret key
- `VITE_MASTER_WALLET_MNEMONIC`: Your wallet mnemonic phrase

## Notes
- The tests require a local Fuel node to be running
- All commands should be run from the project root unless specified otherwise
- Make sure you have the correct Rust toolchain version installed with `forc` and `fuel-core`
Original file line number Diff line number Diff line change
@@ -1,47 +1,77 @@
import {
expect,
getButtonByText,
getByAriaLabel,
} from '@fuels/playwright-utils';
import { getButtonByText, getByAriaLabel } from '@fuels/playwright-utils';
import type { Page } from '@playwright/test';
import phantom from '../../../node_modules/@phantom/synpress/commands/phantom';
import {
incrementTests,
sessionTests,
skipBridgeFunds,
transferTests,
} from '../../../common/common';
import type {
ApproveTransferFunction,
ConnectFunction,
} from '../../../common/types';
import { fundWallet } from '../setup';
import phantomExtended from './phantom/phantom';
import { test } from './setup';

phantom.confirmTransaction = async () => {
const notificationPage =
await phantom.playwright.switchToNotification('phantom');
await phantom.playwright.waitAndClick(
'phantom',
phantom.transactionPageElements.buttons.confirmTransaction, // Ensure this locator exists or define it
notificationPage,
{ waitForEvent: 'close' },
);
return true;
};

test.describe('SolanaConnector', () => {
test.slow();

const connect = async (page: Page) => {
await page.goto('/');
const connect: ConnectFunction = async (page: Page) => {
const connectButton = getButtonByText(page, 'Connect Wallet', true);
await connectButton.click();
await getByAriaLabel(page, 'Connect to Solana Wallets', true).click();
await page.getByText('Proceed anyway').click();
await getButtonByText(page, 'Phantom').click();
await phantom.acceptAccess();
await page.waitForTimeout(3000);
try {
await phantomExtended.acceptAccess();
} catch (error) {
// Phantom might not need to accept access if it already connected before
console.log('Error: ', error);
}
};

test('Fuel tests', async ({ page }) => {
const approveTransfer: ApproveTransferFunction = async () => {
await phantomExtended.confirmSignatureRequest();
};

test.beforeEach(async ({ page }) => {
await page.goto('/');
});

test('Solana tests', async ({ page }) => {
await test.step('Session tests', async () => {
await sessionTests(page, { connect, approveTransfer });
});

await connect(page);
await skipBridgeFunds(page);

const addressElement = await page.locator('#address');
let address = null;
let address: string | null = null;
if (addressElement) {
address = await addressElement.getAttribute('data-address');
}
test.step('Check if address is not null', () => {
expect(address).not.toBeNull();

if (address) {
await fundWallet({ publicKey: address });
} else {
throw new Error('Address is null');
}
await test.step('Transfer tests', async () => {
await transferTests(page, {
connect,
approveTransfer,
keepSession: true,
});
});

await test.step('Increment tests', async () => {
await incrementTests(page, {
connect,
approveTransfer,
keepSession: true,
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import phantomCommands from '../../../../node_modules/@phantom/synpress/commands/phantom';

export const phantomExtended = {
...phantomCommands,
};

export default phantomExtended;
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { BrowserContext } from '@playwright/test';
import { chromium } from '@playwright/test';
import phantomCommands from '../../../../node_modules/@phantom/synpress/commands/phantom';
import phantomHelpers from '../../../../node_modules/@phantom/synpress/helpers';
import { PHANTOM_CONFIG } from './config';
import phantomExtended from './phantom';

export async function phantomPath() {
return await phantomHelpers.prepareProvider('phantom', 'latest');
}
export async function setupPhantom(_context: BrowserContext) {
await phantomCommands.initialSetup(chromium, {
await phantomExtended.initialSetup(chromium, {
secretWordsOrPrivateKey: PHANTOM_CONFIG.MNEMONIC,
network: 'localhost',
password: PHANTOM_CONFIG.WALLET_PASSWORD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ test.describe('WalletConnectConnector', () => {
}

await transferTests(page, { connect, approveTransfer, keepSession: true });

await incrementTests(page, { connect, approveTransfer, keepSession: true });
});
});
7 changes: 6 additions & 1 deletion e2e-tests/runner/fuels.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import dotenv from 'dotenv';
import { createConfig } from 'fuels';

dotenv.config({
path: ['.env'],
});

export default createConfig({
output: './src/contracts',
contracts: ['./contracts/custom_asset'],
forcBuildFlags: ['--release'],
privateKey:
'0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298',
providerUrl: 'http://localhost:4000/v1/graphql',
providerUrl: process.env.PROVIDER_URL || 'http://localhost:4000/v1/graphql',
onDeploy: (_, contracts) => {
const contractIdsPath = join(__dirname, './src/contract-ids.json');
let contractIds = {};
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test:react-app": "pnpm test:react-app:ci -- --ui",
"test:react-app:ci": "playwright test e2e-tests/react-app --project=react-app",
"test:react-next": "pnpm playwright test --project=react-next",
"test:e2e:dev": "pnpm --workspace-root node:up && pnpm run start:servers & pnpm playwright test --ui",
"test:e2e:dev": "pnpm run start:servers & pnpm playwright test --ui",
"test:e2e:local": "pnpm run deploy:contracts && pnpm run test:e2e",
"start:react-app": "pnpm --filter react-app dev",
"start:react-next": "pnpm --filter @e2e-tests/react-next dev",
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/runner/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
defineConfig,
devices,
} from '@playwright/test';
import { synpressFixtures } from '@synthetixio/synpress';
// import { synpressFixtures } from '@synthetixio/synpress';

import dotenv from 'dotenv';
dotenv.config();
Expand Down
9 changes: 3 additions & 6 deletions examples/react-app/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
VITE_APP_WC_PROJECT_ID=
VITE_CHAIN_ID_NAME=testnet
VITE_FUEL_PROVIDER_URL=https://testnet.fuel.network/v1/graphql
VITE_WALLET_SECRET="0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298"
VITE_MASTER_WALLET_MNEMONIC="shuffle become fold deputy sick shove wolf olympic breeze antique ball broom"
PORT=5173
VITE_APP_WC_PROJECT_ID=e01471314fc69cc4efba6dce12dfd710
VITE_CHAIN_ID_NAME=local
VITE_FUEL_PROVIDER_URL=http://localhost:4000/v1/graphql
4 changes: 3 additions & 1 deletion examples/react-next/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
NEXT_PUBLIC_WC_PROJECT_ID=
NEXT_PUBLIC_WC_PROJECT_ID=e01471314fc69cc4efba6dce12dfd710
NEXT_PUBLIC_CHAIN_ID_NAME=testnet
NEXT_PUBLIC_PROVIDER_URL=http://localhost:4000/v1/graphql
2 changes: 2 additions & 0 deletions packages/evm-predicates/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PRIVATE_KEY=0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298
PROVIDER_URL=http://localhost:4000/v1/graphql
9 changes: 7 additions & 2 deletions packages/evm-predicates/fuels.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import dotenv from 'dotenv';
import { createConfig } from 'fuels';

dotenv.config({
path: ['.env'],
});

export default createConfig({
providerUrl: 'http://localhost:4000/v1/graphql',
providerUrl: process.env.PROVIDER_URL || 'http://localhost:4000/v1/graphql',
predicates: ['./predicate'],
output: './src/generated/tmp',
forcBuildFlags: ['--release'],
// needs the private key to deploy the predicate
privateKey:
'0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298', // genesis private key
'0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298',
});
1 change: 1 addition & 0 deletions packages/evm-predicates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"devDependencies": {
"@fuel-connectors/common": "workspace:*",
"dotenv": "16.4.5",
"fuels": "0.96.1",
"tsx": "4.9.3",
"typescript": "5.4.5"
Expand Down
2 changes: 2 additions & 0 deletions packages/solana-connector/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PRIVATE_KEY=0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298
PROVIDER_URL=http://localhost:4000/v1/graphql
Loading
Loading