@@ -2,11 +2,12 @@ import { expect } from '@playwright/test'
22import { labelhash } from 'viem'
33
44import { getResolver } from '@ensdomains/ensjs/public'
5- import { setPrimaryName } from '@ensdomains/ensjs/wallet'
5+ import { setPrimaryName , setRecords } from '@ensdomains/ensjs/wallet'
66
77import { test } from '../../../playwright'
88import { createAccounts } from '../../../playwright/fixtures/accounts'
99import {
10+ testClient ,
1011 waitForTransaction ,
1112 walletClient ,
1213} from '../../../playwright/fixtures/contracts/utils/addTestContracts'
@@ -487,4 +488,130 @@ test.describe('profile', () => {
487488 accounts . getAddress ( 'user2' , 5 ) ,
488489 )
489490 } )
491+
492+ test ( 'should not show primary name when ETH address record points to different address' , async ( {
493+ page,
494+ login,
495+ makeName,
496+ accounts,
497+ time,
498+ } ) => {
499+ test . slow ( )
500+
501+ // Step 1: Create a name owned by user with ETH record pointing to user's own address
502+ const name = await makeName ( {
503+ label : 'primary-mismatch' ,
504+ type : 'legacy' ,
505+ owner : 'user' ,
506+ manager : 'user' ,
507+ addr : 'user' , // Initially points to user's own address
508+ } )
509+
510+ const userAddress = accounts . getAddress ( 'user' )
511+ const user2Address = accounts . getAddress ( 'user2' )
512+
513+ // Step 2: Set this name as primary name for user
514+ const tx = await setPrimaryName ( walletClient , {
515+ name,
516+ account : createAccounts ( ) . getAddress ( 'user' ) as `0x${string } `,
517+ } )
518+ await waitForTransaction ( tx )
519+
520+ await page . goto ( '/' )
521+ await login . connect ( )
522+
523+ // Step 3: Verify primary name shows on user's address page
524+ await page . getByPlaceholder ( 'Search for a name' ) . fill ( userAddress )
525+ await page . getByPlaceholder ( 'Search for a name' ) . press ( 'Enter' )
526+ await expect ( page . getByTestId ( 'profile-snippet' ) ) . toBeVisible ( { timeout : 25000 } )
527+ await expect ( page . getByTestId ( 'profile-title' ) ) . toHaveText ( name )
528+
529+ // Step 4: Change the ETH address record to point to user2's address
530+ const tx2 = await setRecords ( walletClient , {
531+ name,
532+ coins : [
533+ {
534+ coin : 'eth' ,
535+ value : user2Address ,
536+ } ,
537+ ] ,
538+ resolverAddress : walletClient . chain . contracts . legacyPublicResolver . address ,
539+ account : accounts . getAddress ( 'user' ) as `0x${string } `,
540+ } )
541+ await waitForTransaction ( tx2 )
542+
543+ await testClient . mine ( { blocks : 1 } )
544+ await time . sync ( )
545+
546+ await page . reload ( )
547+
548+ // Step 5: Verify primary name NO LONGER shows on user's address page
549+ await page . getByPlaceholder ( 'Search for a name' ) . fill ( userAddress )
550+ await page . getByPlaceholder ( 'Search for a name' ) . press ( 'Enter' )
551+ await expect ( page . getByTestId ( 'no-profile-snippet' ) ) . toBeVisible ( { timeout : 25000 } )
552+ await expect ( page . getByText ( 'No primary name set' ) ) . toBeVisible ( )
553+ } )
554+
555+ test ( 'name-wrapper - should not show primary name when ETH address record points to different address' , async ( {
556+ page,
557+ login,
558+ makeName,
559+ accounts,
560+ time,
561+ makePageObject,
562+ } ) => {
563+ test . slow ( )
564+
565+ // Step 1: Create a name owned by user with ETH record pointing to user's own address
566+ const name = await makeName ( {
567+ label : 'primary-mismatch' ,
568+ type : 'wrapped' ,
569+ owner : 'user' ,
570+ addr : accounts . getAddress ( 'user' ) as `0x${string } `,
571+ } )
572+
573+ const userAddress = accounts . getAddress ( 'user' )
574+ const user2Address = accounts . getAddress ( 'user2' )
575+
576+ await page . goto ( '/' )
577+ await login . connect ( )
578+
579+ const profilePage = makePageObject ( 'ProfilePage' )
580+
581+ await profilePage . goto ( name )
582+ await page . getByText ( 'Set as primary name' ) . click ( )
583+ const transactionModal = makePageObject ( 'TransactionModal' )
584+ await transactionModal . autoComplete ( )
585+
586+ // Step 3: Verify primary name shows on user's address page
587+ await page . getByPlaceholder ( 'Search for a name' ) . fill ( userAddress )
588+ await page . getByPlaceholder ( 'Search for a name' ) . press ( 'Enter' )
589+ await expect ( page . getByTestId ( 'profile-snippet' ) ) . toBeVisible ( { timeout : 25000 } )
590+ await expect ( page . getByTestId ( 'profile-title' ) ) . toHaveText ( name )
591+
592+ // Step 4: Change the ETH address record to point to user2's address
593+ const tx2 = await setRecords ( walletClient , {
594+ name,
595+ coins : [
596+ {
597+ coin : 'eth' ,
598+ value : user2Address ,
599+ } ,
600+ ] ,
601+ resolverAddress : walletClient . chain . contracts . ensPublicResolver . address as `0x${string } `,
602+ account : accounts . getAddress ( 'user' ) as `0x${string } `,
603+ } )
604+ await waitForTransaction ( tx2 )
605+
606+ await testClient . mine ( { blocks : 1 } )
607+ await time . sync ( )
608+
609+ await page . reload ( )
610+
611+ // Step 5: Verify primary name NO LONGER shows on user's address page
612+ await page . getByPlaceholder ( 'Search for a name' ) . fill ( userAddress )
613+ await page . getByPlaceholder ( 'Search for a name' ) . press ( 'Enter' )
614+ await expect ( page . getByTestId ( 'no-profile-snippet' ) ) . toBeVisible ( { timeout : 25000 } )
615+ await expect ( page . getByText ( 'No primary name set' ) ) . toBeVisible ( )
616+ } )
490617} )
0 commit comments