Skip to content

Commit

Permalink
add sample and tests for concurrent name generation
Browse files Browse the repository at this point in the history
  • Loading branch information
storywithoutend committed Sep 19, 2024
1 parent e848364 commit 2a84283
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 7 deletions.
38 changes: 32 additions & 6 deletions packages/ensjs/deploy/00_register_concurrently.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const {
makeNameGenerator: makeLegacyNameGenerator,
} = require('../utils/legacyNameGenerator.cjs')
const { makeNonceManager } = require('../utils/nonceManager.cjs')
const { encodeFuses } = require('../dist/cjs/utils/fuses')

const DURATION = 31556000

/**
* @type {{
Expand All @@ -35,15 +38,16 @@ const sameExpiryNames = Array.from({ length: 20 }, (_, index) => ({
type: 'legacy',
namedOwner: 'owner4',
reverseRecord: true,
duration: 3600,
duration: DURATION,
}))

const expiryNames = Array.from({ length: 20 }, (_, index) => ({
label: `wrapped-name-${index}`,
// type: 'wrapped',
type: 'wrapped',
namedOwner: 'owner4',

// reverseRecord: true,
expiry: 31556000 + index + 1,
expiry: DURATION + index + 1,
// duration: 31556000 + index + 1,
}))

Expand All @@ -68,15 +72,37 @@ const names = [
label: 'concurrent-wrapped-name',
type: 'wrapped',
namedOwner: 'owner4',
fuses: encodeFuses({
input: {
child: {
named: ['CANNOT_UNWRAP'],
},
},
}),
reverseRecord: true,
duration: DURATION,
subnames: [
// { label: 'subname-1', namedOwner: 'owner4', duration: 36000 },
{
label: 'subname-1',
namedOwner: 'owner4',
type: 'wrapped',
subnameFuses: encodeFuses({
input: {
parent: {
named: ['PARENT_CANNOT_CONTROL'],
},
child: {
named: ['CANNOT_UNWRAP'],
},
},
}),
},
// { label: 'subname-2', namedOwner: 'owner4' },
// { label: 'test', namedOwner: 'owner4' },
// { label: 'legacy', namedOwner: 'owner4' },
// { label: 'xyz', namedOwner: 'owner4', expiry: 3600 },
// { label: 'addr', namedOwner: 'owner4' },
...expiryNames,
// ...expiryNames,
],
},
]
Expand Down Expand Up @@ -128,7 +154,6 @@ const func = async function (hre) {
})
},
),
await network.provider.send('evm_mine'),
)

network.provider.send('evm_mine')
Expand Down Expand Up @@ -165,6 +190,7 @@ const func = async function (hre) {
label,
namedOwner,
namedAddr,
duration
})
else
return wrappedNameGenerator.register({
Expand Down
40 changes: 39 additions & 1 deletion packages/ensjs/src/functions/subgraph/getNamesForAddress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,55 @@
import type { Address } from 'viem'
import { beforeAll, describe, expect, it } from 'vitest'
import { publicClient, walletClient } from '../../test/addTestContracts.js'
import { EMPTY_ADDRESS } from '../../utils/consts.js'
import { GRACE_PERIOD_SECONDS } from '../../utils/consts.js'
import getNamesForAddress, {
type NameWithRelation,

Check failure on line 8 in packages/ensjs/src/functions/subgraph/getNamesForAddress.test.ts

View workflow job for this annotation

GitHub Actions / Lint

'NameWithRelation' is defined but never used
} from './getNamesForAddress.js'
import getOwner from '../public/getOwner.js'
import getExpiry from '../public/getExpiry.js'
import getWrapperData from '../public/getWrapperData.js'

let accounts: Address[]

beforeAll(async () => {
accounts = await walletClient.getAddresses()
})

const legacyNamesList = Array.from(
{ length: 20 },
(_, i) => `same-expiry-legacy-name-${i}.eth`,
)

const user4 = '0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65'
let expiry: bigint

describe.only('validate data', () => {
it.each([
...legacyNamesList,
'concurrent-wrapped-name.eth',
'subname-1.concurrent-wrapped-name.eth',
])('%s', async (name) => {
const ownerData = await getOwner(publicClient, { name })
const owner = ownerData?.registrant ?? ownerData?.owner
expect(owner).toEqual(user4)
const expiryData = await getExpiry(publicClient, { name })
const expiryValue = expiryData?.expiry?.value || 0n

if (!expiry) expiry = expiryValue
const wrapperData = await getWrapperData(publicClient, { name })

// expiry value from wrapper datat includes grace period
const wrappedExpiryValue =
(wrapperData?.expiry?.value || 0n) - BigInt(GRACE_PERIOD_SECONDS)
const expectedExpiry =
ownerData?.ownershipLevel === 'nameWrapper'
? wrappedExpiryValue
: expiryValue

expect(expectedExpiry).toEqual(expiry)
})
})

it('returns with default values', async () => {
const result = await getNamesForAddress(publicClient, {
address: accounts[1],
Expand Down

0 comments on commit 2a84283

Please sign in to comment.