diff --git a/packages/ensjs/deploy/00_register_concurrently.cjs b/packages/ensjs/deploy/00_register_concurrently.cjs index ad43ee50..87c6571c 100644 --- a/packages/ensjs/deploy/00_register_concurrently.cjs +++ b/packages/ensjs/deploy/00_register_concurrently.cjs @@ -30,23 +30,53 @@ const { makeNonceManager } = require('../utils/nonceManager.cjs') * }[]} */ +const sameExpiryNames = Array.from({ length: 20 }, (_, index) => ({ + label: `same-expiry-legacy-name-${index}`, + type: 'legacy', + namedOwner: 'owner4', + reverseRecord: true, + duration: 3600, +})) + +const expiryNames = Array.from({ length: 20 }, (_, index) => ({ + label: `wrapped-name-${index}`, + // type: 'wrapped', + namedOwner: 'owner4', + // reverseRecord: true, + expiry: 31556000 + index + 1, + // duration: 31556000 + index + 1, +})) + const names = [ - { - label: 'concurrent-legacy-name', - type: 'legacy', - namedOwner: 'owner4', - reverseRecord: true, - }, + ...sameExpiryNames, + // ...expiryNames, + // { + // label: 'concurrent-legacy-name', + // type: 'legacy', + // namedOwner: 'owner4', + // reverseRecord: true, + // duration: 3600, + // }, + // { + // label: 'concurrent-legacy-name-2', + // type: 'legacy', + // namedOwner: 'owner4', + // reverseRecord: true, + // duration: 3600, + // }, { label: 'concurrent-wrapped-name', type: 'wrapped', namedOwner: 'owner4', reverseRecord: true, subnames: [ - { label: 'test', namedOwner: 'owner4' }, - { label: 'legacy', namedOwner: 'owner4' }, - { label: 'xyz', namedOwner: 'owner4' }, - { label: 'addr', namedOwner: 'owner4' }, + // { label: 'subname-1', namedOwner: 'owner4', duration: 36000 }, + // { label: 'subname-2', namedOwner: 'owner4' }, + // { label: 'test', namedOwner: 'owner4' }, + // { label: 'legacy', namedOwner: 'owner4' }, + // { label: 'xyz', namedOwner: 'owner4', expiry: 3600 }, + // { label: 'addr', namedOwner: 'owner4' }, + ...expiryNames, ], }, ] @@ -88,18 +118,17 @@ const func = async function (hre) { namedOwner, namedAddr, }) - else - return wrappedNameGenerator.commit({ - label, - namedOwner, - data, - reverseRecord, - fuses, - duration, - }) + return wrappedNameGenerator.commit({ + label, + namedOwner, + data, + reverseRecord, + fuses, + duration, + }) }, ), - await network.provider.send('evm_mine') + await network.provider.send('evm_mine'), ) network.provider.send('evm_mine') @@ -209,7 +238,7 @@ const func = async function (hre) { 'status after registration', await network.provider.send('txpool_content'), ) - + return true } diff --git a/packages/ensjs/src/functions/subgraph/getNamesForAddress.test.ts b/packages/ensjs/src/functions/subgraph/getNamesForAddress.test.ts index 198b17de..60a4aaa5 100644 --- a/packages/ensjs/src/functions/subgraph/getNamesForAddress.test.ts +++ b/packages/ensjs/src/functions/subgraph/getNamesForAddress.test.ts @@ -35,279 +35,384 @@ it('has registration date on .eth names', async () => { } } }) -describe('filter', () => { - it('filters by owner', async () => { - const result = await getNamesForAddress(publicClient, { - address: accounts[1], - filter: { - owner: true, - registrant: false, - resolvedAddress: false, - wrappedOwner: false, - }, - }) - if (!result.length) throw new Error('No names found') - for (const name of result) { - expect(name.owner).toBe(accounts[1]) - expect(name.relation.owner).toBe(true) - } - }) - it('filters by registrant', async () => { - const result = await getNamesForAddress(publicClient, { - address: accounts[1], - filter: { - owner: false, - registrant: true, - resolvedAddress: false, - wrappedOwner: false, - }, - }) - if (!result.length) throw new Error('No names found') - for (const name of result) { - expect(name.registrant).toBe(accounts[1]) - expect(name.relation.registrant).toBe(true) - } - }) - it('filters by resolved address', async () => { - const result = await getNamesForAddress(publicClient, { - address: accounts[1], - filter: { - owner: false, - registrant: false, - resolvedAddress: true, - wrappedOwner: false, - }, - }) - if (!result.length) throw new Error('No names found') - for (const name of result) { - expect(name.resolvedAddress).toBe(accounts[1]) - expect(name.relation.resolvedAddress).toBe(true) - } - }) - it('filters by wrapped owner', async () => { - const result = await getNamesForAddress(publicClient, { - address: accounts[1], - filter: { - owner: false, - registrant: false, - resolvedAddress: false, - wrappedOwner: true, - }, - }) - if (!result.length) throw new Error('No names found') - for (const name of result) { - expect(name.wrappedOwner).toBe(accounts[1]) - expect(name.relation.wrappedOwner).toBe(true) - } - }) - it('allows including expired names', async () => { - const result = await getNamesForAddress(publicClient, { - address: accounts[1], - filter: { - owner: true, - registrant: true, - resolvedAddress: true, - wrappedOwner: true, - allowExpired: true, - }, - }) - if (!result.length) throw new Error('No names found') - const expiredNames = result.filter( - (x) => x.expiryDate?.date && x.expiryDate.date < new Date(), - ) - expect(expiredNames.length).toBeGreaterThan(0) - }) - it('allows including reverse record', async () => { - const result = await getNamesForAddress(publicClient, { - address: accounts[2], - filter: { - owner: true, - registrant: true, - resolvedAddress: true, - wrappedOwner: true, - allowReverseRecord: true, - }, - }) - if (!result.length) throw new Error('No names found') - const reverseRecordNames = result.filter( - (x) => x.parentName === 'addr.reverse', - ) - expect(reverseRecordNames.length).toBeGreaterThan(0) - }) - it('does not include deleted names by default', async () => { - const result = await getNamesForAddress(publicClient, { - address: accounts[1], - pageSize: 1000, - }) - if (!result.length) throw new Error('No names found') - const deletedNames = result.filter( - (x) => x.parentName === 'deletable.eth' && x.owner === EMPTY_ADDRESS, - ) - expect(deletedNames.length).toBe(0) +it('test', async () => { + let fullResult = await getNamesForAddress(publicClient, { + address: accounts[4], + orderBy: 'expiryDate', + orderDirection: 'asc', + pageSize: 20, }) - it('allows including deleted names', async () => { - const result = await getNamesForAddress(publicClient, { - address: accounts[1], - pageSize: 1000, - filter: { - owner: true, - registrant: true, - resolvedAddress: true, - wrappedOwner: true, - allowDeleted: true, - }, - }) - if (!result.length) throw new Error('No names found') - const deletedNames = result.filter( - (x) => x.parentName === 'deletable.eth' && x.owner === EMPTY_ADDRESS, - ) - expect(deletedNames.length).toBe(1) + console.log( + fullResult.map((name) => ({ + name: name?.name, + expiry: name?.expiryDate?.value, + })), + ) + if (!fullResult.length) throw new Error('No names found') + const previousPage = fullResult + fullResult = await getNamesForAddress(publicClient, { + address: accounts[4], + orderBy: 'expiryDate', + orderDirection: 'asc', + pageSize: 20, + previousPage, }) - it('filters by search string', async () => { - const result = await getNamesForAddress(publicClient, { - address: accounts[1], - pageSize: 1000, - filter: { - owner: true, - registrant: true, - resolvedAddress: true, - wrappedOwner: true, - searchString: 'test123', - }, - }) + console.log( + fullResult.map((name) => ({ + name: name?.name, + expiry: name?.expiryDate?.value, + })), + ) + expect(fullResult).toEqual(fullResult) +}) - if (!result.length) throw new Error('No names found') - for (const name of result) { - expect(name.labelName).toContain('test123') - } - }) - it('filters by search string - name', async () => { - const result = await getNamesForAddress(publicClient, { - address: accounts[2], - pageSize: 1000, - filter: { - owner: true, - registrant: true, - resolvedAddress: true, - wrappedOwner: true, - searchString: 'wrapped-with-subnames', - searchType: 'name', - }, - }) +// describe('filter', () => { +// it('filters by owner', async () => { +// const result = await getNamesForAddress(publicClient, { +// address: accounts[1], +// filter: { +// owner: true, +// registrant: false, +// resolvedAddress: false, +// wrappedOwner: false, +// }, +// }) +// if (!result.length) throw new Error('No names found') +// for (const name of result) { +// expect(name.owner).toBe(accounts[1]) +// expect(name.relation.owner).toBe(true) +// } +// }) +// it('filters by registrant', async () => { +// const result = await getNamesForAddress(publicClient, { +// address: accounts[1], +// filter: { +// owner: false, +// registrant: true, +// resolvedAddress: false, +// wrappedOwner: false, +// }, +// }) +// if (!result.length) throw new Error('No names found') +// for (const name of result) { +// expect(name.registrant).toBe(accounts[1]) +// expect(name.relation.registrant).toBe(true) +// } +// }) +// it('filters by resolved address', async () => { +// const result = await getNamesForAddress(publicClient, { +// address: accounts[1], +// filter: { +// owner: false, +// registrant: false, +// resolvedAddress: true, +// wrappedOwner: false, +// }, +// }) +// if (!result.length) throw new Error('No names found') +// for (const name of result) { +// expect(name.resolvedAddress).toBe(accounts[1]) +// expect(name.relation.resolvedAddress).toBe(true) +// } +// }) +// it('filters by wrapped owner', async () => { +// const result = await getNamesForAddress(publicClient, { +// address: accounts[1], +// filter: { +// owner: false, +// registrant: false, +// resolvedAddress: false, +// wrappedOwner: true, +// }, +// }) +// if (!result.length) throw new Error('No names found') +// for (const name of result) { +// expect(name.wrappedOwner).toBe(accounts[1]) +// expect(name.relation.wrappedOwner).toBe(true) +// } +// }) +// it('allows including expired names', async () => { +// const result = await getNamesForAddress(publicClient, { +// address: accounts[1], +// filter: { +// owner: true, +// registrant: true, +// resolvedAddress: true, +// wrappedOwner: true, +// allowExpired: true, +// }, +// }) +// if (!result.length) throw new Error('No names found') +// const expiredNames = result.filter( +// (x) => x.expiryDate?.date && x.expiryDate.date < new Date(), +// ) +// expect(expiredNames.length).toBeGreaterThan(0) +// }) +// it('allows including reverse record', async () => { +// const result = await getNamesForAddress(publicClient, { +// address: accounts[2], +// filter: { +// owner: true, +// registrant: true, +// resolvedAddress: true, +// wrappedOwner: true, +// allowReverseRecord: true, +// }, +// }) +// if (!result.length) throw new Error('No names found') +// const reverseRecordNames = result.filter( +// (x) => x.parentName === 'addr.reverse', +// ) +// expect(reverseRecordNames.length).toBeGreaterThan(0) +// }) +// it('does not include deleted names by default', async () => { +// const result = await getNamesForAddress(publicClient, { +// address: accounts[1], +// pageSize: 1000, +// }) +// if (!result.length) throw new Error('No names found') +// const deletedNames = result.filter( +// (x) => x.parentName === 'deletable.eth' && x.owner === EMPTY_ADDRESS, +// ) +// expect(deletedNames.length).toBe(0) +// }) +// it('allows including deleted names', async () => { +// const result = await getNamesForAddress(publicClient, { +// address: accounts[1], +// pageSize: 1000, +// filter: { +// owner: true, +// registrant: true, +// resolvedAddress: true, +// wrappedOwner: true, +// allowDeleted: true, +// }, +// }) +// if (!result.length) throw new Error('No names found') +// const deletedNames = result.filter( +// (x) => x.parentName === 'deletable.eth' && x.owner === EMPTY_ADDRESS, +// ) +// expect(deletedNames.length).toBe(1) +// }) +// it('filters by search string', async () => { +// const result = await getNamesForAddress(publicClient, { +// address: accounts[1], +// pageSize: 1000, +// filter: { +// owner: true, +// registrant: true, +// resolvedAddress: true, +// wrappedOwner: true, +// searchString: 'test123', +// }, +// }) - if (!result.length) throw new Error('No names found') - const subnames = result.filter( - (x) => x.parentName === 'wrapped-with-subnames.eth', - ) - expect(subnames.length).toBeGreaterThan(0) - }) -}) +// if (!result.length) throw new Error('No names found') +// for (const name of result) { +// expect(name.labelName).toContain('test123') +// } +// }) +// it('filters by search string - name', async () => { +// const result = await getNamesForAddress(publicClient, { +// address: accounts[2], +// pageSize: 1000, +// filter: { +// owner: true, +// registrant: true, +// resolvedAddress: true, +// wrappedOwner: true, +// searchString: 'wrapped-with-subnames', +// searchType: 'name', +// }, +// }) -describe.each([ - { - orderBy: 'name', - orderDirection: 'asc', - compareFn: (a: NameWithRelation, b: NameWithRelation) => - (a.name || '').localeCompare(b.name || ''), - }, - { - orderBy: 'name', - orderDirection: 'desc', - compareFn: (a: NameWithRelation, b: NameWithRelation) => - (b.name || '').localeCompare(a.name || ''), - }, - { - orderBy: 'labelName', - orderDirection: 'asc', - compareFn: (a: NameWithRelation, b: NameWithRelation) => { - const aLabelName = a.labelName || '' - const bLabelName = b.labelName || '' - return aLabelName.localeCompare(bLabelName) - }, - }, - { - orderBy: 'labelName', - orderDirection: 'desc', - compareFn: (a: NameWithRelation, b: NameWithRelation) => { - const aLabelName = a.labelName || '' - const bLabelName = b.labelName || '' - return bLabelName.localeCompare(aLabelName) - }, - }, - { - orderBy: 'expiryDate', - orderDirection: 'asc', - compareFn: (a: NameWithRelation, b: NameWithRelation) => { - const aExpiryDate = a.expiryDate?.value || Infinity - const bExpiryDate = b.expiryDate?.value || Infinity - return aExpiryDate - bExpiryDate - }, - }, - { - orderBy: 'expiryDate', - orderDirection: 'desc', - compareFn: (a: NameWithRelation, b: NameWithRelation) => { - const aExpiryDate = a.expiryDate?.value || Infinity - const bExpiryDate = b.expiryDate?.value || Infinity - return bExpiryDate - aExpiryDate - }, - }, - { - orderBy: 'createdAt', - orderDirection: 'asc', - compareFn: (a: NameWithRelation, b: NameWithRelation) => { - const aCreatedAt = a.createdAt.value - const bCreatedAt = b.createdAt.value - return aCreatedAt - bCreatedAt - }, - }, - { - orderBy: 'createdAt', - orderDirection: 'desc', - compareFn: (a: NameWithRelation, b: NameWithRelation) => { - const aCreatedAt = a.createdAt.value - const bCreatedAt = b.createdAt.value - return bCreatedAt - aCreatedAt - }, - }, -])( - 'filters by $orderBy $orderDirection', - ({ orderBy, orderDirection, compareFn }) => { - it('is consistent between full result and paginated results', async () => { - const fullResult = await getNamesForAddress(publicClient, { - address: accounts[1], - orderBy: orderBy as any, - orderDirection: orderDirection as any, - pageSize: 1000, - }) - if (!fullResult.length) throw new Error('No names found') - const paginatedResults = [] - let lastResult: NameWithRelation[] = [] - do { - const result = await getNamesForAddress(publicClient, { - address: accounts[1], - orderBy: orderBy as any, - orderDirection: orderDirection as any, - previousPage: lastResult, - pageSize: 5, - }) - paginatedResults.push(...result) - lastResult = result - } while (lastResult.length) +// if (!result.length) throw new Error('No names found') +// const subnames = result.filter( +// (x) => x.parentName === 'wrapped-with-subnames.eth', +// ) +// expect(subnames.length).toBeGreaterThan(0) +// }) +// }) + +// describe.each([ +// { +// orderBy: 'name', +// orderDirection: 'asc', +// compareFn: (a: NameWithRelation, b: NameWithRelation) => +// (a.name || '').localeCompare(b.name || ''), +// }, +// { +// orderBy: 'name', +// orderDirection: 'desc', +// compareFn: (a: NameWithRelation, b: NameWithRelation) => +// (b.name || '').localeCompare(a.name || ''), +// }, +// { +// orderBy: 'labelName', +// orderDirection: 'asc', +// compareFn: (a: NameWithRelation, b: NameWithRelation) => { +// const aLabelName = a.labelName || '' +// const bLabelName = b.labelName || '' +// return aLabelName.localeCompare(bLabelName) +// }, +// }, +// { +// orderBy: 'labelName', +// orderDirection: 'desc', +// compareFn: (a: NameWithRelation, b: NameWithRelation) => { +// const aLabelName = a.labelName || '' +// const bLabelName = b.labelName || '' +// return bLabelName.localeCompare(aLabelName) +// }, +// }, +// { +// orderBy: 'expiryDate', +// orderDirection: 'asc', +// compareFn: (a: NameWithRelation, b: NameWithRelation) => { +// const aExpiryDate = a.expiryDate?.value || Infinity +// const bExpiryDate = b.expiryDate?.value || Infinity +// return aExpiryDate - bExpiryDate +// }, +// }, +// { +// orderBy: 'expiryDate', +// orderDirection: 'desc', +// compareFn: (a: NameWithRelation, b: NameWithRelation) => { +// const aExpiryDate = a.expiryDate?.value || Infinity +// const bExpiryDate = b.expiryDate?.value || Infinity +// return bExpiryDate - aExpiryDate +// }, +// }, +// { +// orderBy: 'createdAt', +// orderDirection: 'asc', +// compareFn: (a: NameWithRelation, b: NameWithRelation) => { +// const aCreatedAt = a.createdAt.value +// const bCreatedAt = b.createdAt.value +// return aCreatedAt - bCreatedAt +// }, +// }, +// { +// orderBy: 'createdAt', +// orderDirection: 'desc', +// compareFn: (a: NameWithRelation, b: NameWithRelation) => { +// const aCreatedAt = a.createdAt.value +// const bCreatedAt = b.createdAt.value +// return bCreatedAt - aCreatedAt +// }, +// }, +// ])( +// 'filters by $orderBy $orderDirection', +// ({ orderBy, orderDirection, compareFn }) => { +// it('is consistent between full result and paginated results', async () => { +// const fullResult = await getNamesForAddress(publicClient, { +// address: accounts[1], +// orderBy: orderBy as any, +// orderDirection: orderDirection as any, +// pageSize: 1000, +// }) +// if (!fullResult.length) throw new Error('No names found') +// const paginatedResults = [] +// let lastResult: NameWithRelation[] = [] +// do { +// const result = await getNamesForAddress(publicClient, { +// address: accounts[1], +// orderBy: orderBy as any, +// orderDirection: orderDirection as any, +// previousPage: lastResult, +// pageSize: 5, +// }) +// paginatedResults.push(...result) +// lastResult = result +// } while (lastResult.length) - expect(paginatedResults.length).toBe(fullResult.length) - expect(paginatedResults).toStrictEqual(fullResult) - }) - it('is sorted correctly', async () => { - const fullResult = await getNamesForAddress(publicClient, { - address: accounts[1], - orderBy: orderBy as any, - orderDirection: orderDirection as any, - pageSize: 1000, - }) - if (!fullResult.length) throw new Error('No names found') - const sortedResult = [...fullResult].sort(compareFn) - expect(fullResult).toEqual(sortedResult) - }) - }, -) +// expect(paginatedResults.length).toBe(fullResult.length) +// expect(paginatedResults).toStrictEqual(fullResult) +// }) +// it('is sorted correctly', async () => { +// const fullResult = await getNamesForAddress(publicClient, { +// address: accounts[1], +// orderBy: orderBy as any, +// orderDirection: orderDirection as any, +// pageSize: 1000, +// }) +// if (!fullResult.length) throw new Error('No names found') +// const sortedResult = [...fullResult].sort(compareFn) +// expect(fullResult).toEqual(sortedResult) +// }) +// /// ///////////////// +// // it('more than 1 page (30 expiry names)', async () => { +// // const fullResult = await getNamesForAddress(publicClient, { +// // address: accounts[1], +// // orderBy: orderBy as any, +// // orderDirection: orderDirection as any, +// // pageSize: 20, +// // }) +// // console.log(fullResult) +// // if (!fullResult.length) throw new Error('No names found') +// // const sortedResult = [...fullResult].sort(compareFn) +// // expect(fullResult).toEqual(sortedResult) +// // }) +// // it('more than 1 page (30 same expiry names)', async () => { +// // const fullResult = await getNamesForAddress(publicClient, { +// // address: accounts[1], +// // orderBy: orderBy as any, +// // orderDirection: orderDirection as any, +// // pageSize: 20, +// // }) +// // console.log(fullResult) +// // if (!fullResult.length) throw new Error('No names found') +// // const sortedResult = [...fullResult].sort(compareFn) +// // expect(fullResult).toEqual(sortedResult) +// // }) +// // it('more than 1 page (30 non-expiry names)', async () => { +// // const fullResult = await getNamesForAddress(publicClient, { +// // address: accounts[1], +// // orderBy: orderBy as any, +// // orderDirection: orderDirection as any, +// // pageSize: 20, +// // }) +// // console.log(fullResult) +// // if (!fullResult.length) throw new Error('No names found') +// // const sortedResult = [...fullResult].sort(compareFn) +// // expect(fullResult).toEqual(sortedResult) +// // }) +// // it('mix names (30 expiry, 10 non-expiry)', async () => { +// // const fullResult = await getNamesForAddress(publicClient, { +// // address: accounts[1], +// // orderBy: orderBy as any, +// // orderDirection: orderDirection as any, +// // pageSize: 20, +// // }) +// // console.log(fullResult) +// // if (!fullResult.length) throw new Error('No names found') +// // const sortedResult = [...fullResult].sort(compareFn) +// // expect(fullResult).toEqual(sortedResult) +// // }) +// // it('mix names (30 same expiry, 10 expiry)', async () => { +// // const fullResult = await getNamesForAddress(publicClient, { +// // address: accounts[1], +// // orderBy: orderBy as any, +// // orderDirection: orderDirection as any, +// // pageSize: 20, +// // }) +// // console.log(fullResult) +// // if (!fullResult.length) throw new Error('No names found') +// // const sortedResult = [...fullResult].sort(compareFn) +// // expect(fullResult).toEqual(sortedResult) +// // }) +// // it('mix names (30 same expiry , 10 no-expiry)', async () => { +// // const fullResult = await getNamesForAddress(publicClient, { +// // address: accounts[1], +// // orderBy: orderBy as any, +// // orderDirection: orderDirection as any, +// // pageSize: 20, +// // }) +// // console.log(fullResult) +// // if (!fullResult.length) throw new Error('No names found') +// // const sortedResult = [...fullResult].sort(compareFn) +// // expect(fullResult).toEqual(sortedResult) +// // }) +// /// ////////////////// +// }, +// )