|
| 1 | +import { test } from '../testFixture'; |
| 2 | +import { expect } from '@playwright/test'; |
| 3 | +import { prepareBasenameFlow, handleTransaction } from '../appSession'; |
| 4 | +import { initiateRegistration } from '../basenameHelpers'; |
| 5 | +import { ActionApprovalType } from '@coinbase/onchaintestkit'; |
| 6 | + |
| 7 | +test.describe('Basename Registration', () => { |
| 8 | + test('should fail registration when wallet has insufficient funds', async ({ |
| 9 | + page, |
| 10 | + metamask, |
| 11 | + node, |
| 12 | + }) => { |
| 13 | + // Validate prerequisites |
| 14 | + if (!metamask) { |
| 15 | + throw new Error('MetaMask is not defined'); |
| 16 | + } |
| 17 | + |
| 18 | + if (!node) { |
| 19 | + throw new Error('Node fixture is not defined'); |
| 20 | + } |
| 21 | + |
| 22 | + // Common preparation steps (wallet needs funds to connect) |
| 23 | + const { mainPage } = await prepareBasenameFlow(page, metamask); |
| 24 | + |
| 25 | + // Get the first default wallet address from Anvil (0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266) |
| 26 | + const walletAddress = (await node.getAccounts())[0]; |
| 27 | + console.log('[test] Using default Anvil wallet address:', walletAddress); |
| 28 | + |
| 29 | + // NOW set wallet balance to 0 after connection is established |
| 30 | + await node.setBalance(walletAddress, 0n); |
| 31 | + console.log('[test] Set wallet balance to 0'); |
| 32 | + |
| 33 | + // Attempt registration with no funds |
| 34 | + await initiateRegistration(mainPage); |
| 35 | + await page.waitForLoadState('networkidle'); |
| 36 | + |
| 37 | + // Approve the transaction (it should fail due to insufficient funds) |
| 38 | + await handleTransaction(metamask, ActionApprovalType.APPROVE); |
| 39 | + await page.waitForLoadState('networkidle'); |
| 40 | + |
| 41 | + // Look for failure message |
| 42 | + await expect(page.getByText(/failed|rejected|insufficient/i)).toBeVisible({ timeout: 30000 }); |
| 43 | + }); |
| 44 | +}); |
0 commit comments