Skip to content
Merged
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
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Dependencies
node_modules
.npm
.yarn-cache
.yarn

# Build
dist
coverage

# Logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Environment
.env
.env.*
!.env.example

# Development
.DS_Store
.idea
.vscode
.cache

*.code-workspace

*.gz
/test-results/
/playwright-report/
/blob-report/

.yarn/

example/smart-contracts/lib/
example/smart-contracts/out/
example/smart-contracts/cache/
140 changes: 138 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,138 @@
# https-github.com-joe10832-onchaintestkit
A Simple CLI Linux/Unix Utility, Written In C++
# Onchain Test Kit

End-to-end testing toolkit for blockchain applications, powered by Playwright.

## Overview

This toolkit provides a robust framework for testing blockchain applications, with built-in support for wallet interactions, network management, and common blockchain testing scenarios.

## Quick Start

1. Install dependencies:

Make sure you have yarn:

```bash
npm install -g corepack
yarn set version 4.9.2
```

And then run this to install the dependencies:

```bash
npm install --save-dev @playwright/test @coinbase/onchaintestkit
# or
yarn add -D @playwright/test @coinbase/onchaintestkit
```

Make sure you have foundry set up too

2. Set up environment variables:

```env
E2E_TEST_SEED_PHRASE="your test wallet seed phrase"
```

3. Create your wallet configuration:

```typescript
// walletConfig/metamaskWalletConfig.ts
import { configure } from 'e2e/onchainTestKit';
import { baseSepolia } from 'viem/chains';

export const DEFAULT_PASSWORD = 'PASSWORD';
export const DEFAULT_SEED_PHRASE = process.env.E2E_TEST_SEED_PHRASE;

export const metamaskWalletConfig = configure()
.withMetaMask()
.withSeedPhrase({
seedPhrase: DEFAULT_SEED_PHRASE ?? '',
password: DEFAULT_PASSWORD,
})
.withNetwork({
name: baseSepolia.name,
rpcUrl: baseSepolia.rpcUrls.default.http[0],
chainId: baseSepolia.id,
symbol: baseSepolia.nativeCurrency.symbol,
})
.build();
```

4. Write your test:

```typescript
import { metamaskWalletConfig } from 'e2e/walletConfig/metamaskWalletConfig';
import { BaseActionType, createOnchainTest } from './onchainTestKit';

const test = createOnchainTest(metamaskWalletConfig);
const { expect } = test;

test('connect wallet and swap', async ({ page, metamask }) => {
if (!metamask) throw new Error('MetaMask fixture is required');

// Connect wallet
await page.getByTestId('ockConnectButton').click();
await page
.getByTestId('ockModalOverlay')
.first()
.getByRole('button', { name: 'MetaMask' })
.click();
await metamask.handleAction(BaseActionType.CONNECT_TO_DAPP);

// Verify connection
await expect(page.getByTestId('wallet-connected')).toBeVisible();
});
```

## Features

- **Playwright Integration**: Built on top of Playwright for reliable browser automation
- **Multiple Wallet Support**: Support for MetaMask, Coinbase Wallet, and Phantom
- **Action Handling**: Simplified wallet action management
- Connect to DApp
- Handle transactions
- Manage token approvals
- Handle signatures
- Switch networks
- **Network Management**: Easy network configuration using viem chains
- **Type Safety**: Full TypeScript support

## Configuration Builder

The toolkit uses a fluent builder pattern for configuration:

```typescript
const config = configure()
.withMetaMask()
.withSeedPhrase({
seedPhrase: 'your seed phrase',
password: 'your password',
})
.withNetwork({
name: 'Network Name',
rpcUrl: 'RPC URL',
chainId: 1,
symbol: 'ETH',
})
.build();
```

### Available Methods

- `withMetaMask()`: Initialize MetaMask configuration
- `withCoinbase()`: Initialize Coinbase Wallet configuration
- `withPhantom()`: Initialize Phantom Wallet configuration
- `withSeedPhrase()`: Configure wallet with seed phrase
- `withNetwork()`: Configure network settings
- `withCustomSetup()`: Add custom setup steps

## Development

- Run `yarn` to install dependencies
- Run `yarn build` to build the project
- Run `yarn format` to format code
- Run `yarn lint` to check for linting issues

## Contributing

Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.
68 changes: 68 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"a11y": {
"noAutofocus": "off",
"useButtonType": "off"
},
"complexity": {
"noForEach": "off"
},
"correctness": {
"useExhaustiveDependencies": "off",
"noEmptyPattern": "off",
"noUnusedVariables": "warn"
},
"style": {
"noNegationElse": "warn",
"useFragmentSyntax": "off"
},
"suspicious": {
"noExplicitAny": "warn",
"noArrayIndexKey": "warn"
}
},
"ignore": ["**/.next/**"]
},
"javascript": {
"formatter": {
"enabled": true,
"semicolons": "asNeeded",
"quoteStyle": "double",
"bracketSpacing": true,
"jsxQuoteStyle": "double",
"arrowParentheses": "asNeeded",
"indentWidth": 2
}
},
"json": {
"formatter": {
"enabled": false
}
},
"formatter": {
"enabled": true,
"indentWidth": 2,
"indentStyle": "space",
"ignore": ["**/.next/**"]
},
"files": {
"ignore": [
"node_modules",
"dist",
".cache",
"**/.cache/**",
"src/.cache/**",
"**/*.min.js",
"coverage",
"build",
"**/.next/**"
]
}
}
27 changes: 27 additions & 0 deletions example/test-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { configure, createOnchainTest, BaseActionType } from '../dist/index.js';

// Example configuration
const testConfig = configure()
.withMetaMask()
.withSeedPhrase({
seedPhrase: 'test test test test test test test test test test test junk',
password: 'testpassword'
})
.withNetwork({
name: 'Local Test Network',
rpcUrl: 'http://localhost:8545',
chainId: 1337,
symbol: 'ETH'
})
.build();

console.log('Configuration created successfully!');
console.log('Config:', JSON.stringify(testConfig, null, 2));

// Test creating onchain test
try {
const test = createOnchainTest(testConfig);
console.log('Onchain test created successfully!');
} catch (error) {
console.error('Error creating onchain test:', error);
}
Loading