Skip to content

Commit

Permalink
add encoded subname test
Browse files Browse the repository at this point in the history
  • Loading branch information
sugh01 committed Dec 13, 2023
1 parent 5f1b84c commit 144eb10
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 14 deletions.
97 changes: 95 additions & 2 deletions packages/ensjs/src/test/usage/registerName.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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[]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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}",
}
`)
})
35 changes: 23 additions & 12 deletions packages/ensjs/src/test/usage/setRecords.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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",
},
]
`)
})

0 comments on commit 144eb10

Please sign in to comment.