@@ -7,9 +7,14 @@ import type { BrowserContext, Page } from '@playwright/test';
77
88import 'dotenv/config' ;
99
10+ import { IotaNamesTransaction } from '@iota/iota-names-sdk' ;
11+ import { Signer } from '@iota/iota-sdk/cryptography' ;
12+ import { Transaction } from '@iota/iota-sdk/transactions' ;
13+
1014import { CONFIG } from '@/config' ;
1115
1216import { expect } from './helpers/fixtures' ;
17+ import { iotaClient , iotaNamesClient } from './setup/utils' ;
1318
1419export async function connectWallet ( page : Page , context : BrowserContext , extensionName : string ) {
1520 await page . getByRole ( 'button' , { name : / C o n n e c t / i } ) . click ( ) ;
@@ -63,11 +68,15 @@ export async function createWallet(page: Page) {
6368
6469 await page . getByText ( 'I saved my mnemonic' ) . click ( ) ;
6570 await page . getByRole ( 'button' , { name : 'Open Wallet' } ) . click ( ) ;
71+
6672 await page . getByLabel ( 'Open settings menu' ) . click ( ) ;
6773 await page . getByText ( 'Network' ) . click ( ) ;
6874 await page . getByText ( 'Custom RPC' ) . click ( ) ;
69- await page . getByPlaceholder ( 'http://localhost:3000/' ) . fill ( CONFIG . baseUrl ) ;
75+ const networkId = CONFIG . network ;
76+ const networkConfig = getNetwork ( networkId ) ;
77+ await page . getByPlaceholder ( 'http://localhost:3000/' ) . fill ( networkConfig . url ) ;
7078 await page . getByRole ( 'button' , { name : 'Save' } ) . click ( ) ;
79+
7180 await page . getByTestId ( 'close-icon' ) . click ( ) ;
7281
7382 return {
@@ -95,6 +104,40 @@ export async function requestFaucetTokens(recipient: string) {
95104 }
96105}
97106
107+ export async function purchaseName ( address : string , signer : Signer ) {
108+ const tx = new Transaction ( ) ;
109+ const iotaNamesTx = new IotaNamesTransaction ( iotaNamesClient , tx ) ;
110+ const [ coin ] = iotaNamesTx . transaction . splitCoins ( tx . gas , [ 50_000_000_000 ] ) ;
111+ const name = `mycoolname${ Math . floor ( Math . random ( ) * 1000 ) } .iota` ;
112+ const nft = await iotaNamesTx . register ( {
113+ name,
114+ coin,
115+ address,
116+ } ) ;
117+ iotaNamesTx . transaction . transferObjects ( [ nft , coin ] , address ) ;
118+ iotaNamesTx . transaction . setSender ( address ) ;
119+ const txBytes = await iotaNamesTx . transaction . build ( {
120+ client : iotaClient ,
121+ } ) ;
122+
123+ const txDryRun = await iotaClient . dryRunTransactionBlock ( {
124+ transactionBlock : txBytes ,
125+ } ) ;
126+
127+ if ( txDryRun . effects . status . status !== 'success' ) {
128+ throw new Error ( txDryRun . effects . status . error || 'Transaction dry run failed' ) ;
129+ }
130+ console . log ( `Purchased name: ${ name } to address: ${ address } ` ) ;
131+ const response = await iotaClient . signAndExecuteTransaction ( {
132+ transaction : txBytes ,
133+ signer,
134+ options : {
135+ showEffects : true ,
136+ } ,
137+ } ) ;
138+ return { nft, name, response } ;
139+ }
140+
98141export function deriveAddressFromMnemonic ( mnemonic : string , path ?: string ) {
99142 const keypair = Ed25519Keypair . deriveKeypair ( mnemonic , path ) ;
100143 const address = keypair . getPublicKey ( ) . toIotaAddress ( ) ;
@@ -104,3 +147,8 @@ export function deriveAddressFromMnemonic(mnemonic: string, path?: string) {
104147export function getAddressByIndexPath ( mnemonic : string , index : number ) {
105148 return deriveAddressFromMnemonic ( mnemonic , `m/44'/4218'/0'/0'/${ index } '` ) ;
106149}
150+
151+ export function generateRandomName ( name : string ) {
152+ const random = Math . floor ( Math . random ( ) * 10_000 ) ;
153+ return `${ name } ${ random } .iota` ;
154+ }
0 commit comments