@@ -6,6 +6,12 @@ import startPlebbitRpc from './start-plebbit-rpc.js'
66import signers from '../fixtures/signers.js'
77import { directory as getTmpFolderPath } from 'tempy'
88import http from 'http'
9+ import fs from 'fs'
10+ import path from 'path'
11+ import { fileURLToPath } from 'url'
12+
13+ const __filename = fileURLToPath ( import . meta. url )
14+ const __dirname = path . dirname ( __filename )
915const plebbitDataPath = getTmpFolderPath ( )
1016
1117// set up a subplebbit for testing
@@ -41,6 +47,32 @@ const plebbitDataPath = getTmpFolderPath()
4147 } )
4248 const signer = await plebbit . createSigner ( { privateKey, type : 'ed25519' } )
4349
50+ // Create a signer for testing ENS domain address editing
51+ // The 'my-sub.eth' domain should resolve to this signer's address
52+ const ensTestSigner = await plebbit . createSigner ( )
53+ const ensTestDomain = 'my-sub.eth'
54+
55+ // Mock the ENS text record for 'my-sub.eth' to point to ensTestSigner.address
56+ // This allows the test to successfully edit a subplebbit's address to 'my-sub.eth'
57+ const cacheKey = plebbit . _clientsManager . _getKeyOfCachedDomainTextRecord ( ensTestDomain , 'subplebbit-address' )
58+ const timestamp = ( ) => Math . floor ( Date . now ( ) / 1000 )
59+ await plebbit . _storage . setItem ( cacheKey , {
60+ timestampSeconds : timestamp ( ) ,
61+ valueOfTextRecord : ensTestSigner . address ,
62+ } )
63+ console . log ( `Mocked ENS text record '${ ensTestDomain } ' -> '${ ensTestSigner . address } '` )
64+
65+ // Export the ENS test signer info to a file so tests can use it
66+ const ensTestSignerInfo = {
67+ privateKey : ensTestSigner . privateKey ,
68+ address : ensTestSigner . address ,
69+ type : ensTestSigner . type ,
70+ domain : ensTestDomain ,
71+ }
72+ const signerInfoPath = path . join ( __dirname , 'ens-test-signer.json' )
73+ fs . writeFileSync ( signerInfoPath , JSON . stringify ( ensTestSignerInfo , null , 2 ) )
74+ console . log ( `Exported ENS test signer info to '${ signerInfoPath } '` )
75+
4476 console . log ( `creating subplebbit with address '${ signer . address } '...` )
4577 const subplebbit = await plebbit . createSubplebbit ( {
4678 signer : signer ,
@@ -82,7 +114,13 @@ const plebbitDataPath = getTmpFolderPath()
82114 http
83115 . createServer ( ( req , res ) => {
84116 res . setHeader ( 'Access-Control-Allow-Origin' , '*' )
85- res . end ( 'test server ready' )
117+ if ( req . url === '/ens-test-signer' ) {
118+ // Return the ENS test signer info for browser tests
119+ res . setHeader ( 'Content-Type' , 'application/json' )
120+ res . end ( JSON . stringify ( ensTestSignerInfo ) )
121+ } else {
122+ res . end ( 'test server ready' )
123+ }
86124 } )
87125 . listen ( 59281 )
88126 } )
0 commit comments