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

Willc/test scaffolding #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@
"prepare": "npx simple-git-hooks"
},
"dependencies": {
"@eth-optimism/contracts-ts": "^0.15.0"
"@eth-optimism/contracts-ts": "^0.15.0",
"@testing-library/react-hooks": "^8.0.1"
},
"peerDependencies": {
"@tanstack/query-core": ">=5.0.0",
"@tanstack/react-query": "beta",
"@wagmi/core": "alpha",
"@wagmi/core": "2.0.0-alpha.11",
"op-viem": "1.3.0-alpha",
"typescript": ">=5.0.4",
"viem": "2.0.0-alpha.17",
Expand Down
96 changes: 80 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added src/_test/chains.ts
Empty file.
40 changes: 40 additions & 0 deletions src/_test/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { createConfig, http } from '@wagmi/core'
import { mock } from '@wagmi/core/internal'
import { opStackL2ChainContracts } from 'op-viem'
import { baseAddresses } from 'op-viem/chains'
import { base as viem_base, mainnet } from 'viem/chains'
import { type OpConfig } from '../types/OpConfig.js'
import { accounts } from './constants.js'
import { getRpcUrls } from './utils.js'

const base = {
chainId: viem_base.id,
l1ChaindId: mainnet.id,
l1Addresses: baseAddresses,
l2Addresses: opStackL2ChainContracts,
...getRpcUrls({ port: 8547 }),
...viem_base,
fork: {
blockNumber: process.env.VITE_OPTIMISM_FORK_BLOCK_NUMBER
? BigInt(Number(process.env.VITE_OPTIMISM_FORK_BLOCK_NUMBER))
: 5940037n,
url: process.env.VITE_OPTIMISM_FORK_URL ?? 'https://mainnet.base.org',
},
}

export const config: OpConfig = {
l2chains: {
// @ts-expect-error this seems to have a mismatch that is likely a bug
[base.id]: base,
},

...createConfig({
chains: [base],
connectors: [mock({ accounts })],
pollingInterval: 100,
storage: null,
transports: {
[base.id]: http(),
},
}),
}
75 changes: 75 additions & 0 deletions src/_test/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* The id of the current test worker.
*
* This is used by the anvil proxy to route requests to the correct anvil instance.
*/
export const pool = Number(process.env.VITEST_POOL_ID ?? 1)

// Test accounts
export const accounts = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'] as const

const messages = new Map()
function warn(message: string) {
if (!messages.has(message)) {
messages.set(message, true)
console.warn(message)
}
}

export let forkBlockNumber: bigint
if (process.env.VITE_ANVIL_BLOCK_NUMBER) {
forkBlockNumber = BigInt(Number(process.env.VITE_ANVIL_BLOCK_NUMBER))
} else {
forkBlockNumber = 18136086n
warn(
`\`VITE_ANVIL_BLOCK_NUMBER\` not found. Falling back to \`${forkBlockNumber}\`.`,
)
}

export let forkUrl: string
if (process.env.VITE_ANVIL_FORK_URL) {
forkUrl = process.env.VITE_ANVIL_FORK_URL
} else {
forkUrl = 'https://cloudflare-eth.com'
warn(`\`VITE_ANVIL_FORK_URL\` not found. Falling back to \`${forkUrl}\`.`)
}

export let blockTime: number
if (process.env.VITE_ANVIL_BLOCK_TIME) {
blockTime = Number(process.env.VITE_ANVIL_BLOCK_TIME)
} else {
blockTime = 1
warn(`\`VITE_ANVIL_BLOCK_TIME\` not found. Falling back to \`${blockTime}\`.`)
}

export let rollupForkBlockNumber: bigint
if (process.env.VITE_ANVIL_ROLLUP_BLOCK_NUMBER) {
rollupForkBlockNumber = BigInt(
Number(process.env.VITE_ANVIL_ROLLUP_BLOCK_NUMBER),
)
} else {
rollupForkBlockNumber = 3709321n
warn(
`\`VITE_ANVIL_ROLLUP_BLOCK_NUMBER\` not found. Falling back to \`${rollupForkBlockNumber}\`.`,
)
}

export let rollupForkUrl: string
if (process.env.VITE_ANVIL_ROLLUP_FORK_URL) {
rollupForkUrl = process.env.VITE_ANVIL_ROLLUP_FORK_URL
} else {
rollupForkUrl = 'https://mainnet.base.org'
warn(
`\`VITE_ANVIL_ROLLUP_FORK_URL\` not found. Falling back to \`${rollupForkUrl}\`.`,
)
}

export let rollupBlockTime: number
if (process.env.VITE_ANVIL_ROLLUP_BLOCK_TIME) {
rollupBlockTime = Number(process.env.VITE_ANVIL_ROLLUP_BLOCK_TIME)
} else {
rollupBlockTime = 1
warn(
`\`VITE_ANVIL_ROLLUP_BLOCK_TIME\` not found. Falling back to \`${rollupBlockTime}\`.`,
)
}
Loading
Loading