Skip to content

Commit

Permalink
[wip] dappwright
Browse files Browse the repository at this point in the history
  • Loading branch information
aefhm committed Nov 3, 2024
1 parent 88143e1 commit 40d5d70
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 34 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/ci-playwright.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: playwright-test
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
playwright-test:
runs-on: ubuntu-latest
services:
sapphire-localnet-ci:
image: ghcr.io/oasisprotocol/sapphire-localnet:latest
ports:
- 8545:8545
- 8546:8546
env:
OASIS_DEPOSIT_BINARY: /oasis-deposit -test-mnemonic -n 5
options: >-
--rm
--health-cmd="test -f /CONTAINER_READY"
--health-start-period=90s
env:
SAPPHIRE_LOCALNET_HTTP_PROXY_PORT: 3001
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install jq
run: sudo apt install -y jq
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
- name: Build JS client
run: make -C clients/js build
- name: Build Integrations
run: make -C integrations build
- uses: JarvusInnovations/background-action@v1
name: RPC proxy will error if non-encrypted calls are made
with:
run: pnpm run proxy &
wait-on: http://127.0.0.1:${{ env.SAPPHIRE_LOCALNET_HTTP_PROXY_PORT }}
tail: true
log-output-resume: true
wait-for: 31sec
log-output: true
log-output-if: true
working-directory: clients/js
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: npx pnpm install
- name: Set up playwright tests
run: npx playwright install --with-deps
working-directory: examples/wagmi-v2

- name: Run playwright tests (with xvfb-run to support headed extension test)
working-directory: examples/wagmi-v2
run: xvfb-run npx playwright test

- name: 'Upload playwright test-results'
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: playwright-test-results
path: playwright/test-results
retention-days: 5
2 changes: 2 additions & 0 deletions examples/wagmi-v2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ node_modules
dist
dist-ssr
*.local
playwright-report
test-results

# Editor directories and files
.vscode/*
Expand Down
5 changes: 4 additions & 1 deletion examples/wagmi-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
"lint": "biome check .",
"format": "biome format --write .",
"preview": "vite preview",
"test": "playwright test",
"start:server": "vite --port 3000"
},
"dependencies": {
"@oasisprotocol/sapphire-wagmi-v2": "workspace:^",
"@oasisprotocol/sapphire-paratime": "workspace:^",
"@oasisprotocol/sapphire-wagmi-v2": "workspace:^",
"@playwright/test": "^1.48.2",
"@tanstack/react-query": "5.0.5",
"@tenkeylabs/dappwright": "^2.8.6",
"abitype": "^1.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
46 changes: 46 additions & 0 deletions examples/wagmi-v2/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { defineConfig, devices } from "@playwright/test";

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
timeout: 2 * 60 * 1000,
testDir: "./test/e2e/",
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [["html"], ["list", { printSteps: true }]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL: process.env.FRONTEND_URL || "http://localhost:3000/",
trace: "on-first-retry",
headless: false,
screenshot: {
mode: "only-on-failure",
fullPage: true,
},
},
/* Configure projects for major browsers */
projects: [
{
name: 'main',
testDir: './test/',
use: {
...devices['Desktop Chrome'],
},
},
],
/* Run your local dev server before starting the tests */
webServer: {
command: 'pnpm run start:server',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
stderr: 'pipe',
},
});
4 changes: 2 additions & 2 deletions examples/wagmi-v2/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function App() {
</span>
<br />
Write Tx Calldata:&nbsp;
<span id="isWriteEnveloped">
<span id="isWriteEnveloped" data-testid="is-write-enveloped">
{isCalldataEnveloped(writeTxInfo?.input) ? 'encrypted' : 'plaintext'}
</span>
</>
Expand All @@ -199,7 +199,7 @@ function App() {
</button>
{readResult !== undefined && (
<>
<span id="readResult">{readResult.toString()}</span>
<span id="readResult" data-testid="read-result">{readResult.toString()}</span>
</>
)}
<br />
Expand Down
58 changes: 58 additions & 0 deletions examples/wagmi-v2/test/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { BrowserContext, expect, test as baseTest } from "@playwright/test";
import dappwright, { Dappwright, MetaMaskWallet } from "@tenkeylabs/dappwright";

export const test = baseTest.extend<{
context: BrowserContext;
wallet: Dappwright;
}>({
context: async ({}, use) => {
// Launch context with extension
const [wallet, _, context] = await dappwright.bootstrap("", {
wallet: "metamask",
version: MetaMaskWallet.recommendedVersion,
seed: "test test test test test test test test test test test junk", // Hardhat's default https://hardhat.org/hardhat-network/docs/reference#accounts
headless: false,
});

// Add Hardhat as a custom network
await wallet.addNetwork({
networkName: "Sapphire Localnet",
rpc: "http://localhost:8545",
chainId: 23293,
symbol: "ROSE",
});

await use(context);
},

wallet: async ({ context }, use) => {
const metamask = await dappwright.getWallet("metamask", context);

await use(metamask);
},
});

test.beforeEach(async ({ wallet, page }) => {
await wallet.switchAccount(1);
await page.bringToFront();
});

test("deploy contract and send encrypted transaction", async ({ wallet, page }) => {
await page.goto("http://localhost:3000");

await page.getByText("Injected (Sapphire)").click();
await wallet.approve();
await expect(page.getByText("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")).toBeVisible();

await page.getByText("Deploy").click();
await wallet.confirmTransaction();
await expect(page.getByText("Contract:")).toBeVisible();

await page.getByText("Write").click();
await wallet.confirmTransaction();
await expect(page.getByText("Contract:")).toBeVisible();
await expect(page.getByTestId('is-write-enveloped')).toHaveText('encrypted');

await page.getByText("Read").click();
await expect(page.getByTestId("read-result")).not.toBeEmpty();
});
Loading

0 comments on commit 40d5d70

Please sign in to comment.