-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
4,836 additions
and
3,626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
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 | ||
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 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 | ||
working-directory: backend | ||
run: pnpm install | ||
|
||
- name: Build backend | ||
working-directory: backend | ||
run: pnpm build | ||
|
||
- name: Deploy backend | ||
working-directory: backend | ||
run: pnpm hardhat deploy --network sapphire-localnet | ||
|
||
- name: Install dependencies | ||
working-directory: frontend | ||
run: pnpm install | ||
|
||
- name: Install Playwright dependencies | ||
run: pnpm test:setup | ||
working-directory: frontend | ||
|
||
- name: Run playwright tests (with xvfb-run to support headed extension test) | ||
working-directory: frontend | ||
run: xvfb-run pnpm test | ||
|
||
- name: Upload playwright test-results | ||
if: ${{ failure() }} | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: playwright-test-results | ||
path: frontend/test-results | ||
retention-days: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# VITE_NETWORK=0x5afd | ||
# VITE_WEB3_GATEWAY=http://localhost:8545 | ||
VITE_NETWORK=0x5aff | ||
VITE_WEB3_GATEWAY=https://testnet.sapphire.oasis.dev | ||
VITE_MESSAGE_BOX_ADDR=0x2dE080e97B0caE9825375D31f5D0eD5751fDf16D | ||
VITE_NETWORK=0x5afd | ||
VITE_WEB3_GATEWAY=http://localhost:8545 | ||
VITE_MESSAGE_BOX_ADDR=0x5FbDB2315678afecb367f032d93F642f64180aa3 | ||
# VITE_NETWORK=0x5aff | ||
# VITE_WEB3_GATEWAY=https://testnet.sapphire.oasis.dev | ||
# VITE_MESSAGE_BOX_ADDR=0x2dE080e97B0caE9825375D31f5D0eD5751fDf16D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/", | ||
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 ? 1 : 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:5173/", | ||
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 dev', | ||
url: process.env.FRONTEND_URL || "http://localhost:5173/", | ||
reuseExistingServer: !process.env.CI, | ||
stdout: 'pipe', | ||
stderr: 'pipe', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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 Sapphire Localnet 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 }) => { | ||
// Use first account from seed. dAppwright adds two accounts by default. | ||
await wallet.switchAccount(1); // Selector queries as a string | ||
await page.bringToFront(); | ||
}); | ||
|
||
// TODO: improve test without reloading wallet page | ||
test("set and view message", async ({ wallet, page }) => { | ||
await page.goto("http://localhost:5173"); | ||
|
||
// load | ||
await page.getByRole('button', { name: 'Connect Wallet', exact: true }).click(); | ||
await wallet.page.reload(); | ||
await wallet.page.getByRole('button', { name: 'Next' }).click(); | ||
|
||
// confirm | ||
await wallet.page.getByRole('button', { name: 'Confirm' }).click(); | ||
|
||
// sign twice | ||
await wallet.page.getByTestId('signature-request-scroll-button').click(); | ||
await wallet.page.getByRole('button', { name: 'Sign' }).click(); | ||
await wallet.page.waitForLoadState(); | ||
await wallet.page.goBack(); | ||
await wallet.page.reload(); | ||
await wallet.page.getByTestId('signature-request-scroll-button').click(); | ||
await wallet.page.getByRole('button', { name: 'Sign' }).click(); | ||
|
||
// Set a message | ||
await page.fill('text=New Message:', 'hola amigos'); | ||
await page.getByRole('button', { name: 'Set Message' }).click(); | ||
|
||
await wallet.page.reload(); | ||
await wallet.page.getByRole('button', { name: 'Confirm' }).click(); | ||
|
||
// Assert message has been set | ||
await expect(page.getByTestId('message')).toHaveText('hola amigos'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.