Skip to content

Commit

Permalink
test(e2e): Fullset Solana tests FE-446 (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
nelitow authored Dec 5, 2024
1 parent fb025f8 commit 78ae803
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 69 deletions.
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

0 comments on commit 78ae803

Please sign in to comment.