模拟钱包 - 使用 Playwright、人工和 AI 代理测试 Web3 应用程序
如果你尝试过使用 Playwright 测试去中心化应用(dApp),你就会知道这个问题。MetaMask 并不是为无头浏览器设计的。你最终会得到脆弱的黑客解决方案、不稳定的测试,以及一个随机崩溃的 CI 流水线。
我创建了 Mock Wallet 来解决这个问题——然后意识到它解决了更大的问题。
它有三个功能:
1. Playwright 原生钱包测试
像其他模拟工具一样将其放入你的测试套件中。模拟连接、签名和交易,而无需触碰浏览器扩展。支持无头模式,适用于 CI,且可靠性高。
```javascript
// 示例
const wallet = await MockWallet.connect(page);
await wallet.approve({ amount: '1.5', token: 'ETH' });
await expect(page.locator('.balance')).toHaveText('1.5 ETH');
```
2. AI 代理钱包
代理通过 API 获取可编程钱包。没有用户界面,没有弹窗,无需人工干预。你的代理通过调用端点进行签名和交易。
3. 人工 + 代理混合流程
其他人无法处理的部分——测试人类与代理在同一合约下交互的工作流程。批准流程、共同签名、代理发起 + 人工确认的交易。
在沙盒环境中使用模拟资金开始。切换一个标志即可上线。
mockwallet.dev — 免费沙盒,无需注册即可试用。
欢迎任何进行 Web3 应用端到端测试的人的严厉反馈。
查看原文
If you've tried to test a dApp with Playwright you already know the
problem. MetaMask wasn't built for headless browsers. You end up
with brittle hacks, flaky tests, and a CI pipeline that breaks
randomly.<p>I built Mock Wallet to fix this — and then realized it solves
something bigger.<p>Three things it does:<p>1. Playwright-native wallet testing
Drop it into your test suite like any other mock. Simulate
connects, signatures, and transactions without touching a
browser extension. Works headless, works in CI, works reliably.<p><pre><code> // example
const wallet = await MockWallet.connect(page);
await wallet.approve({ amount: '1.5', token: 'ETH' });
await expect(page.locator('.balance')).toHaveText('1.5 ETH');
</code></pre>
2. AI agent wallet
Agents get a programmable wallet via API. No UI, no popups,
no human required. Your agent signs and transacts by calling
an endpoint.<p>3. Human + agent hybrid flows
The part nobody else handles — testing workflows where a human
and an agent interact with the same contract. Approve flows,
co-signing, agent-initiated + human-confirmed transactions.<p>Start in sandbox with mock funds. Flip a flag to go live.<p>mockwallet.dev — free sandbox, no signup to try.<p>Brutal feedback welcome especially from anyone doing E2E testing
on Web3 apps.