datahaven/test/utils/viem.ts
Tim B b621f1c04a
test: Add E2E Tests (#36)
This PR adds the basic framework for E2E and the greater typescript
testing framework for the repo.

### Contents

- CI workflow for running E2E tests on push to main, PRs and manual
- Test suite for E2E
  - Currently only read-only tests
  - Using `bun:test` for time being but we can always change in future
- We are using the logging library `pino` so we can help with debugging
- set environment variable `LOG_LEVEL` to get extra information on
helpers
- Local `utils` namespace for all our test suites for easy importing
- Has helpers which interact with both the docker driver and also
blockscout backend
- Allows us to fetch deployed smart contracts by their name or address
and interact with them

---------

Co-authored-by: Facundo Farall <37149322+ffarall@users.noreply.github.com>
2025-04-14 16:22:43 -03:00

48 lines
1.2 KiB
TypeScript

import { ANVIL_FUNDED_ACCOUNTS, CHAIN_ID, getRPCUrl, getWSUrl } from "utils";
import {
http,
type PublicActions,
type WalletClient,
createPublicClient,
createWalletClient,
defineChain,
publicActions
} from "viem";
import { privateKeyToAccount } from "viem/accounts";
export const createChainConfig = async () =>
defineChain({
id: CHAIN_ID,
name: "Kurtosis",
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH"
},
rpcUrls: {
default: {
http: [await getRPCUrl()],
webSocket: [await getWSUrl()]
}
},
blockExplorers: {
default: { name: "Blockscout", url: "http://127.0.0.1:3000" }
}
// Example of how we can preload contracts into the API, useful for AVS
// contracts: {
// multicall3: {
// address: '0xcA11bde05977b3631167028862bE2a173976CA11',
// blockCreated: 5882,
// },
// },
});
export const createDefaultClient = async () =>
createWalletClient({
account: privateKeyToAccount(ANVIL_FUNDED_ACCOUNTS[0].privateKey),
chain: await createChainConfig(),
transport: http()
}).extend(publicActions);
export interface ViemClientInterface extends WalletClient, PublicActions {}