diff --git a/packages/ensjs/src/test/usage/registerName.e2e.test.ts b/packages/ensjs/src/test/usage/registerName.e2e.test.ts index 767bb3f4..8ea8b043 100644 --- a/packages/ensjs/src/test/usage/registerName.e2e.test.ts +++ b/packages/ensjs/src/test/usage/registerName.e2e.test.ts @@ -1,4 +1,4 @@ -import { labelhash, type Address, type Hex } from 'viem' +import { labelhash, type Address, type Hex, hexToString, bytesToString, hexToBigInt } from 'viem' import { getChainContractAddress } from '../../contracts/getChainContractAddress.js' import { nameWrapperOwnerOfSnippet } from '../../contracts/nameWrapper.js' import { @@ -29,7 +29,11 @@ import setRecords from '../../functions/wallet/setRecords.js' import { encodeAbi } from '../../utils/index.js' import { commitAndRegisterName } from './helper.js' import getSubnames from '../../functions/subgraph/getSubnames.js' +import {decodeLabelhash, decryptName, isEncodedLabelhash} from '../../utils/labels.js' +import { hexToBytes } from 'viem' +// import {namehash} from '../../utils/normalise.js' import * as exp from 'constants' +import getDecodedName from '../../functions/subgraph/getDecodedName.js' let snapshot: Hex let accounts: Address[] @@ -673,7 +677,7 @@ it('Register - unwrap 2LD - wrap Subname', async () => { expect(owner!.ownershipLevel).toBe('nameWrapper') }) -it.only('Register - Renew Name - Add Subname - Expire Subname - Create Subname', async () => { +it('Register - Renew Name - Add Subname - Expire Subname - Create Subname', async () => { const name = `test${Math.floor(Math.random() * 1000000)}.eth` const params: RegistrationParameters = { name: name, @@ -709,4 +713,93 @@ it.only('Register - Renew Name - Add Subname - Expire Subname - Create Subname', expect(result.length).toBeGreaterThan(0) expect(result[0].expiryDate).toBeTruthy() +}) + +it('Register - Set Subname - Decode enrypted subname', async () => { + const params: RegistrationParameters = { + name: 'cool-swag-wrap.eth', + duration: 31536000, + owner: accounts[1], + secret, + resolverAddress: testClient.chain.contracts.ensPublicResolver.address, + } + + await commitAndRegisterName(params, accounts[1]) + const label = `unknown-label-${Date.now()}` + const subName = `${label}.${params.name}` + const _labelhash = labelhash(label) + + const createSubnameTx = await createSubname(walletClient, { + name: subName, + contract: 'nameWrapper', + owner: accounts[2], + account: accounts[1], + }) + expect(createSubnameTx).toBeTruthy() + const createSubnameTxReceipt = await waitForTransaction(createSubnameTx) + expect(createSubnameTxReceipt.status).toBe('success') + + await new Promise((resolve) => setTimeout(resolve, 30000)); + const esubname = `[${_labelhash.slice(2)}]` + const ename = `${esubname}.${params.name}` + const dsubname = await getDecodedName(publicClient, { + name: ename, + }) + + const owner = await publicClient.readContract({ + abi: nameWrapperOwnerOfSnippet, + functionName: 'ownerOf', + address: getChainContractAddress({ + client: publicClient, + contract: 'ensNameWrapper', + }), + args: [BigInt(namehash(dsubname!))], + }) + expect(owner).toBe(accounts[2]) + + const resolver = await getResolver(publicClient, { name: subName }) + + console.log(resolver) + + const setAddressRecordTx = await setAddressRecord(walletClient, { + name: subName, + coin: 'eth', + value: accounts[2], + resolverAddress: resolver as Address, + account: accounts[2], + }) + expect(setAddressRecordTx).toBeTruthy() + const setAddressRecordTxReceipt = await waitForTransaction(setAddressRecordTx) + expect(setAddressRecordTxReceipt.status).toBe('success') + + testClient.mine({ blocks: 1 }) + + const getAddressRecordResult = await getAddressRecord(publicClient, { + name: subName, + }) + + console.log(getAddressRecordResult) + + const setPrimaryNameTx = await setPrimaryName(walletClient, { + name: subName, + account: accounts[2], + }) + expect(setPrimaryNameTx).toBeTruthy() + const setPrimaryNameTxReceipt = await waitForTransaction(setPrimaryNameTx) + expect(setPrimaryNameTxReceipt.status).toBe('success') + + await testClient.mine({ blocks: 1 }) + + const result = await getName(publicClient, { + address: accounts[2], + }) + + expect(result).toMatchInlineSnapshot(` + { + "match": true, + "name": "${subName}", + "resolverAddress": "${testClient.chain.contracts.ensPublicResolver.address}", + "reverseResolverAddress": "${testClient.chain.contracts.ensPublicResolver.address}", + } + `) }) \ No newline at end of file diff --git a/packages/ensjs/src/test/usage/setRecords.e2e.test.ts b/packages/ensjs/src/test/usage/setRecords.e2e.test.ts index 20887cda..913e36e7 100644 --- a/packages/ensjs/src/test/usage/setRecords.e2e.test.ts +++ b/packages/ensjs/src/test/usage/setRecords.e2e.test.ts @@ -249,7 +249,7 @@ it('should return a transaction to the resolver and ignore undefined', async () expect(records.contentHash).not.toBeNull() expect(records.abi).not.toBeNull() }) -it.skip('should return a transaction to the resolver and retrieve multiple keys successfully', async () => { +it('should return a transaction to the resolver and retrieve multiple keys successfully', async () => { //generate random name const name = `test${Math.floor(Math.random() * 1000000)}.eth` const params: RegistrationParameters = { @@ -353,27 +353,38 @@ it.skip('should return a transaction to the resolver and retrieve multiple keys "protocolType": "ipfs", } `) - expect(records.abi!.abi).toStrictEqual([...dummyABI,{stateMutability: 'readonly',}]) + expect(records.abi!.abi).toStrictEqual(dummyABI) expect(records.coins).toMatchInlineSnapshot(` [ { - id: 501, - name: 'sol', - value: 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH' + "id": 501, + "name": "sol", + "value": "HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH" }, { - id: 60, - name: 'eth', - value: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8' + "id": 60, + "name": "eth", + "value": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" }, - { id: 0, name: 'btc', value: '1PzAJcFtEiXo9UGtRU6iqXQKj8NXtcC7DE' } + { "id": 0, + "name": "btc", + "value": "1PzAJcFtEiXo9UGtRU6iqXQKj8NXtcC7DE" } ] `) expect(records.texts).toMatchInlineSnapshot(` [ - { key: 'name', value: 'e2e' }, - { key: 'location', value: 'metaverse' }, - { key: 'description', value: 'e2e' } + { + "key": "name", + "value": "e2e", + }, + { + "key": "location", + "value": "metaverse", + }, + { + "key": "description", + "value": "e2e", + }, ] `) }) \ No newline at end of file