From edd18fef1ddf292f9b5d773be7169ef3c95a7f22 Mon Sep 17 00:00:00 2001 From: Tom Meagher Date: Thu, 19 Dec 2024 11:33:25 -0500 Subject: [PATCH] test: start anvil --- .gitignore | 8 ++-- README.md | 8 ++-- package.json | 2 +- playwright.config.ts | 36 --------------- scripts/generate-typed-artifacts.ts | 32 ------------- test/browser/Caddyfile | 10 +++- test/browser/app/create-account/page.tsx | 9 +++- test/browser/chains.ts | 19 ++++++++ test/browser/playwright.config.ts | 58 ++++++++++++++++++++++++ 9 files changed, 103 insertions(+), 79 deletions(-) delete mode 100644 playwright.config.ts delete mode 100644 scripts/generate-typed-artifacts.ts create mode 100644 test/browser/chains.ts create mode 100644 test/browser/playwright.config.ts diff --git a/.gitignore b/.gitignore index 0609b5a..7966a03 100644 --- a/.gitignore +++ b/.gitignore @@ -39,10 +39,10 @@ src/_generated out # playwright -/test-results/ -/playwright-report/ -/blob-report/ -/playwright/.cache/ +test-results/ +playwright-report/ +blob-report/ +playwright/.cache/ # vercel .vercel diff --git a/README.md b/README.md index 50052f5..294f849 100644 --- a/README.md +++ b/README.md @@ -511,9 +511,9 @@ import { useConnect } from 'porto/wagmi' # Install pnpm $ curl -fsSL https://get.pnpm.io/install.sh | sh - -$ pnpm install # Install modules -$ pnpm wagmi generate # get ABIs, etc. -$ pnpm dev # Run playground +$ pnpm install # Install modules +$ pnpm wagmi generate # Get ABIs, etc. +$ pnpm dev # Run playground ``` ### Contracts @@ -523,7 +523,7 @@ $ pnpm dev # Run playground $ foundryup $ forge build --config-path ./contracts/foundry.toml # Build -$ forge test --config-path ./contracts/foundry.toml # Test +$ forge test --config-path ./contracts/foundry.toml # Test ``` ## License diff --git a/package.json b/package.json index 4c96723..0196d05 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "preinstall": "pnpx only-allow pnpm", "prepare": "pnpm simple-git-hooks", "test": "vitest dev", - "test:browser": "pnpm exec playwright test" + "test:browser": "pnpm exec playwright test -c test/browser/playwright.config.ts" }, "devDependencies": { "@arethetypeswrong/cli": "^0.17.1", diff --git a/playwright.config.ts b/playwright.config.ts deleted file mode 100644 index a6b0e58..0000000 --- a/playwright.config.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { defineConfig, devices } from '@playwright/test' - -/** https://playwright.dev/docs/test-configuration */ -export default defineConfig({ - forbidOnly: !!process.env.CI, - fullyParallel: true, - projects: [ - { - name: 'chromium', - use: { ...devices['Desktop Chrome'] }, - }, - // name: 'firefox', - // use: { ...devices['Desktop Firefox'] }, - // }, - // { - // name: 'webkit', - // use: { ...devices['Desktop Safari'] }, - // }, - ], - reporter: 'html', - retries: process.env.CI ? 2 : 0, - testDir: './test/browser', - use: { - baseURL: 'https://porto.localhost', - }, - webServer: { - command: - 'caddy start -c test/browser/Caddyfile && pnpm --filter browser-app dev', - url: 'http://127.0.0.1:3000', - reuseExistingServer: !process.env.CI, - stdout: 'pipe', - stderr: 'pipe', - timeout: 5_000, - }, - // workers: process.env.CI ? 1 : undefined, -}) diff --git a/scripts/generate-typed-artifacts.ts b/scripts/generate-typed-artifacts.ts deleted file mode 100644 index de57f91..0000000 --- a/scripts/generate-typed-artifacts.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { appendFile, glob, mkdir, readFile, writeFile } from 'node:fs/promises' -import { resolve } from 'node:path' - -await mkdir(resolve(import.meta.dirname, '../src/_generated'), { - recursive: true, -}) - -const out = resolve(import.meta.dirname, '../src/_generated/contracts.ts') -await writeFile(out, '') - -const fileNames: string[] = [] - -for await (const file of glob( - resolve(import.meta.dirname, '../contracts/out/**/*.json'), -)) { - if (file.includes('build-info')) continue - - const fileName = file.split('/').pop()?.replace('.json', '')! - if (fileNames.includes(fileName)) continue - - const { abi, bytecode } = JSON.parse(await readFile(file, 'utf-8')) - fileNames.push(fileName) - - appendFile( - out, - `export const ${fileName} = ${JSON.stringify( - { abi, bytecode }, - null, - 2, - )} as const;\n\n`, - ) -} diff --git a/test/browser/Caddyfile b/test/browser/Caddyfile index ee81190..3b0cff3 100644 --- a/test/browser/Caddyfile +++ b/test/browser/Caddyfile @@ -1,3 +1,11 @@ porto.localhost, www.porto.localhost { - reverse_proxy localhost:3000 + reverse_proxy localhost:3000 +} + +anvil.porto.localhost { + reverse_proxy localhost:8545 +} + +caddy.porto.localhost { + respond 200 } diff --git a/test/browser/app/create-account/page.tsx b/test/browser/app/create-account/page.tsx index 5897508..2f58316 100644 --- a/test/browser/app/create-account/page.tsx +++ b/test/browser/app/create-account/page.tsx @@ -1,9 +1,16 @@ 'use client' +import { odysseyTestnet } from '@/chains' import { Porto } from 'porto' import { useState } from 'react' +import { http } from 'viem' -const porto = Porto.create() +const porto = Porto.create({ + chains: [odysseyTestnet], + transports: { + [odysseyTestnet.id]: http(), + }, +}) export default function Page() { const [result, setResult] = useState(null) diff --git a/test/browser/chains.ts b/test/browser/chains.ts new file mode 100644 index 0000000..f20e410 --- /dev/null +++ b/test/browser/chains.ts @@ -0,0 +1,19 @@ +import { Chains } from 'porto' +import type { Chain } from 'viem' + +export const odysseyTestnet = { + ...Chains.odysseyTestnet, + rpcUrls: { + default: { + http: ['https://anvil.porto.localhost'], + webSocket: ['wss://anvil.porto.localhost'], + }, + public: { + http: ['https://anvil.porto.localhost'], + webSocket: ['wss://anvil.porto.localhost'], + }, + }, +} as const satisfies Chain + +export const chainLookup = { odysseyTestnet } +export const chains = [odysseyTestnet] diff --git a/test/browser/playwright.config.ts b/test/browser/playwright.config.ts new file mode 100644 index 0000000..c6716f2 --- /dev/null +++ b/test/browser/playwright.config.ts @@ -0,0 +1,58 @@ +import { defineConfig, devices } from '@playwright/test' + +/** https://playwright.dev/docs/test-configuration */ +export default defineConfig({ + forbidOnly: !!process.env.CI, + fullyParallel: true, + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + // { + // name: 'firefox', + // use: { ...devices['Desktop Firefox'] }, + // }, + // { + // name: 'webkit', + // use: { ...devices['Desktop Safari'] }, + // }, + ], + reporter: process.env.CI ? 'github' : 'list', + retries: process.env.CI ? 2 : 0, + testDir: './', + use: { + baseURL: 'https://porto.localhost', + }, + webServer: [ + { + command: ['pnpm dev'].join(' && '), + url: 'http://127.0.0.1:3000', + reuseExistingServer: !process.env.CI, + stdout: 'ignore', + stderr: 'pipe', + timeout: 5_000, + }, + { + command: [ + 'anvil', + '--chain-id 911867', + `--fork-url ${process.env.ODYSSEY_FORK_URL ?? 'https://911867.rpc.thirdweb.com'}`, + '--fork-block-number 6030102', + ].join(' '), + url: 'http://127.0.0.1:8545', + reuseExistingServer: !process.env.CI, + stdout: 'ignore', + stderr: 'pipe', + timeout: 5_000, + }, + { + command: 'caddy run -c Caddyfile', + url: 'http://localhost:2019/reverse_proxy/upstreams', + reuseExistingServer: !process.env.CI, + stdout: 'ignore', + stderr: 'pipe', + timeout: 5_000, + }, + ], +})