|
1 | 1 | // Copyright (c) 2025 IOTA Stiftung |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
| 4 | +import 'dotenv/config'; |
| 5 | + |
| 6 | +import { normalizeIotaName } from '@iota/iota-names-sdk'; |
| 7 | +import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519'; |
| 8 | +import { formatAddress } from '@iota/iota-sdk/utils'; |
4 | 9 | import { expect } from '@playwright/test'; |
5 | 10 |
|
6 | 11 | import { test } from '../helpers/fixtures'; |
| 12 | +import { |
| 13 | + bidOnExistingAuction, |
| 14 | + connectWallet, |
| 15 | + createAndSendAuctionTransaction, |
| 16 | + createWallet, |
| 17 | + requestFaucetTokens, |
| 18 | +} from '../utils'; |
| 19 | + |
| 20 | +test.beforeAll(async ({ appPage, context, extensionPage, extensionName, sharedState }) => { |
| 21 | + const { address, mnemonic } = await createWallet(extensionPage); |
| 22 | + |
| 23 | + await appPage.bringToFront(); |
| 24 | + |
| 25 | + await connectWallet(appPage, context, extensionName); |
| 26 | + |
| 27 | + await expect(appPage.getByRole('button', { name: formatAddress(address) })).toBeVisible({ |
| 28 | + timeout: 10_000, |
| 29 | + }); |
| 30 | + |
| 31 | + sharedState.wallet.address = address; |
| 32 | + sharedState.wallet.mnemonic = mnemonic; |
| 33 | +}); |
| 34 | + |
| 35 | +test('Check "Outbid" pills', async ({ sharedState, appPage: page }) => { |
| 36 | + const name = `outbid${Date.now().toString().slice(-6)}`; |
| 37 | + const nameToAuction = `${name}.iota`; |
| 38 | + await page.bringToFront(); |
| 39 | + const navPromise = page.goto(`/my-names`); |
| 40 | + |
| 41 | + const walletSigner = Ed25519Keypair.deriveKeypair(sharedState.wallet.mnemonic!); |
| 42 | + const newSigner = Ed25519Keypair.deriveKeypair( |
| 43 | + sharedState.wallet.mnemonic!, |
| 44 | + `m/44'/4218'/0'/0'/1'`, |
| 45 | + ); |
| 46 | + |
| 47 | + await Promise.all([ |
| 48 | + requestFaucetTokens(walletSigner.toIotaAddress()), |
| 49 | + requestFaucetTokens(newSigner.toIotaAddress()), |
| 50 | + ]); |
| 51 | + |
| 52 | + const startAuctionResult = await createAndSendAuctionTransaction({ |
| 53 | + name: nameToAuction, |
| 54 | + signer: walletSigner, |
| 55 | + }); |
| 56 | + expect(startAuctionResult.effects?.status.status).toBe('success'); |
| 57 | + |
| 58 | + const bidResult = await bidOnExistingAuction({ |
| 59 | + name: nameToAuction, |
| 60 | + signer: newSigner, |
| 61 | + }); |
| 62 | + expect(bidResult.effects?.status.status).toBe('success'); |
| 63 | + |
| 64 | + await navPromise; |
| 65 | + await page.locator("h2:has-text('My Names')").waitFor({ state: 'visible', timeout: 10_000 }); |
| 66 | + |
| 67 | + await page.getByTestId('refresh-button').click(); |
| 68 | + await page.getByText('Refreshed successfully!').waitFor({ state: 'visible', timeout: 10_000 }); |
| 69 | + |
| 70 | + const auctionNameCard = page |
| 71 | + .getByTestId('auction-name-card') |
| 72 | + .filter({ hasText: normalizeIotaName(nameToAuction, 'at') }); |
| 73 | + |
| 74 | + await expect(auctionNameCard.getByTestId('auction-status-badge')).toHaveText('Outbid', { |
| 75 | + timeout: 10_000, |
| 76 | + }); |
| 77 | +}); |
| 78 | + |
| 79 | +test('Check "Top Bidder" pills', async ({ sharedState, appPage: page, context }) => { |
| 80 | + const name = `topbid${Date.now().toString().slice(-6)}`; |
| 81 | + const nameToAuction = `${name}.iota`; |
| 82 | + await page.bringToFront(); |
| 83 | + const navPromise = page.goto(`/my-names`); |
| 84 | + |
| 85 | + const walletSigner = Ed25519Keypair.deriveKeypair(sharedState.wallet.mnemonic!); |
| 86 | + |
| 87 | + await requestFaucetTokens(walletSigner.toIotaAddress()); |
| 88 | + |
| 89 | + const startAuctionResult = await createAndSendAuctionTransaction({ |
| 90 | + name: nameToAuction, |
| 91 | + signer: walletSigner, |
| 92 | + }); |
| 93 | + expect(startAuctionResult.effects?.status.status).toBe('success'); |
| 94 | + |
| 95 | + await navPromise; |
| 96 | + await page.locator("h2:has-text('My Names')").waitFor({ state: 'visible', timeout: 10_000 }); |
| 97 | + |
| 98 | + await page.getByTestId('refresh-button').click(); |
| 99 | + await page.getByText('Refreshed successfully!').waitFor({ state: 'visible', timeout: 10_000 }); |
| 100 | + |
| 101 | + const auctionNameCard = page |
| 102 | + .getByTestId('auction-name-card') |
| 103 | + .filter({ hasText: normalizeIotaName(nameToAuction, 'at') }); |
| 104 | + |
| 105 | + await expect(auctionNameCard.getByTestId('auction-status-badge')).toHaveText('Top Bidder', { |
| 106 | + timeout: 10_000, |
| 107 | + }); |
| 108 | + |
| 109 | + await page.getByRole('link', { name: 'Auctions' }).click(); |
| 110 | + await page.getByPlaceholder('Search auction').fill(nameToAuction); |
| 111 | + const auctionCard = page.getByTestId('auction-name-card').filter({ |
| 112 | + hasText: normalizeIotaName(nameToAuction, 'at'), |
| 113 | + }); |
| 114 | + |
| 115 | + await expect(auctionCard).toBeVisible({ timeout: 10_000 }); |
| 116 | + await expect(auctionCard.getByTestId('auction-status-badge')).toHaveText('Top Bidder', { |
| 117 | + timeout: 10_000, |
| 118 | + }); |
| 119 | + |
| 120 | + await page.getByLabel('Go to homepage').filter({ visible: true }).first().click(); |
| 121 | + await page.getByText('Live Auctions').scrollIntoViewIfNeeded(); |
7 | 122 |
|
8 | | -test('Auction flow works', async ({ appPage }) => { |
9 | | - await expect(appPage).toHaveTitle(/IOTA Names/); |
10 | | - await expect(appPage.getByText('Your On-Chain Name')).toBeVisible(); |
| 123 | + const carousel = page.getByTestId('auction-carousel'); |
| 124 | + const auctionInCarousel = carousel.getByTestId('auction-name-card').filter({ |
| 125 | + hasText: normalizeIotaName(nameToAuction, 'at'), |
| 126 | + }); |
| 127 | + await expect(auctionInCarousel.getByTestId('auction-status-badge')).toHaveText('Top Bidder', { |
| 128 | + timeout: 10_000, |
| 129 | + }); |
11 | 130 | }); |
0 commit comments