diff --git a/packages/ensjs/src/functions/wallet/ownership.e2e.test.ts b/packages/ensjs/src/functions/wallet/ownership.e2e.test.ts deleted file mode 100644 index f6b01880..00000000 --- a/packages/ensjs/src/functions/wallet/ownership.e2e.test.ts +++ /dev/null @@ -1,585 +0,0 @@ -import { labelhash, type Address, type Hex } from 'viem' -import { getChainContractAddress } from '../../contracts/getChainContractAddress.js' -import { nameWrapperOwnerOfSnippet } from '../../contracts/nameWrapper.js' -import { - publicClient, - testClient, - waitForTransaction, - walletClient, -} from '../../test/addTestContracts.js' -import { namehash } from '../../utils/normalise.js' -import type { RegistrationParameters } from '../../utils/registerHelpers.js' -import getPrice from '../public/getPrice.js' -import commitName from './commitName.js' -import registerName from './registerName.js' -import { baseRegistrarNameExpiresSnippet } from '../../contracts/baseRegistrar.js' -import setAddressRecord from './setAddressRecord.js' -import getResolver from '../public/getResolver.js' -import getOwner from '../public/getOwner.js' -import unwrapName from './unwrapName.js' -import transferName from './transferName.js' -import createSubname from './createSubname.js' -import { registrySetApprovalForAllSnippet } from '../../contracts/registry.js' -import { encodeAbi } from '../../utils/index.js' -import setRecords from './setRecords.js' - -let snapshot: Hex -let accounts: Address[] - -beforeAll(async () => { - accounts = await walletClient.getAddresses() - console.log(accounts[1]) - console.log(accounts[2]) -}) - -beforeEach(async () => { - snapshot = await testClient.snapshot() -}) - -afterEach(async () => { - await testClient.revert({ id: snapshot }) -}) - -const secret = `0x${'a'.repeat(64)}` as Hex - -const getNameWrapperOwner = async (name: string) => { - return publicClient.readContract({ - abi: nameWrapperOwnerOfSnippet, - functionName: 'ownerOf', - address: getChainContractAddress({ - client: publicClient, - contract: 'ensNameWrapper', - }), - args: [BigInt(namehash(name))], - }) -} - -const getExpiry = async (name: string) => { - return publicClient.readContract({ - abi: baseRegistrarNameExpiresSnippet, - functionName: 'nameExpires', - address: getChainContractAddress({ - client: publicClient, - contract: 'ensBaseRegistrarImplementation', - }), - args: [BigInt(labelhash(name.split('.')[0]))], - }) -} - -const approve = async (address: Address) => { - return walletClient.writeContract({ - abi: registrySetApprovalForAllSnippet, - address: getChainContractAddress({ - client: walletClient, - contract: 'ensRegistry', - }), - functionName: 'setApprovalForAll', - args: [ - getChainContractAddress({ - client: walletClient, - contract: 'ensNameWrapper', - }), - true, - ], - account: address, - }) -} - -const dummyABI = [ - { - type: 'function', - name: 'supportsInterface', - constant: true, - stateMutability: 'view', - payable: false, - inputs: [ - { - type: 'bytes4', - }, - ], - outputs: [ - { - type: 'bool', - }, - ], - }, -] - -const commitAndRegisterName = async (params: RegistrationParameters) => { - const commitTx = await commitName(walletClient, { - ...params, - account: accounts[1], - }) - expect(commitTx).toBeTruthy() - const commitReceipt = await waitForTransaction(commitTx) - - expect(commitReceipt.status).toBe('success') - - await testClient.increaseTime({ seconds: 61 }) - await testClient.mine({ blocks: 1 }) - - const price = await getPrice(publicClient, { - nameOrNames: params.name, - duration: params.duration, - }) - const total = price!.base + price!.premium - - const tx = await registerName(walletClient, { - ...params, - account: accounts[1], - value: total, - }) - expect(tx).toBeTruthy() - const receipt = await waitForTransaction(tx) - expect(receipt.status).toBe('success') -} - - - -it('Register - unwrapped 2LD', async () => { - const name = 'cool-swag-wrap.eth' - const params: RegistrationParameters = { - name: name, - duration: 31536000, - owner: accounts[1], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - } - await commitAndRegisterName(params) - - const unwrapNameTx = await unwrapName(walletClient, { - name: name, - newOwnerAddress: accounts[1], - newRegistrantAddress: accounts[1], - account: accounts[1], - }) - expect(unwrapNameTx).toBeTruthy() - const unwrapNameTxReceipt = await waitForTransaction(unwrapNameTx) - expect(unwrapNameTxReceipt.status).toBe('success') - - const nameOwner = await getOwner(publicClient, { - name: name, - }) - expect(nameOwner!.owner).toBe(accounts[1]) - expect(nameOwner!.registrant).toBe(accounts[1]) - expect(nameOwner!.ownershipLevel).toBe('registrar') - - - const resolver = await getResolver(publicClient, { name: name }) - - const setAddressRecordTx = await setAddressRecord(walletClient, { - name: name, - coin: 'eth', - value: accounts[2], - resolverAddress: resolver as Address, - account: accounts[1], - }) - expect(setAddressRecordTx).toBeTruthy() - const setAddressRecordTxReceipt = await waitForTransaction(setAddressRecordTx) - expect(setAddressRecordTxReceipt.status).toBe('success') - - const transferMgrTx = await transferName(walletClient, { - name: name, - newOwnerAddress: accounts[2], - contract: 'registrar', - account: accounts[1], - }) - expect(transferMgrTx).toBeTruthy() - const transferMgrTxReceipt = await waitForTransaction(transferMgrTx) - expect(transferMgrTxReceipt.status).toBe('success') - - const transferOwnerTx = await transferName(walletClient, { - name: name, - newOwnerAddress: accounts[2], - contract: 'registry', - account: accounts[1], - }) - expect(transferOwnerTx).toBeTruthy() - const transferOwnerTxReceipt = await waitForTransaction(transferOwnerTx) - expect(transferOwnerTxReceipt.status).toBe('success') - -}) - -it('Register - wrapped 2LD', async () => {`` - const name = 'cool-swag-wrap.eth' - const params: RegistrationParameters = { - name: name, - duration: 31536000, - owner: accounts[1], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - records: { - coins: [ - { - coin: 'etcLegacy', - value: accounts[1], - }, - { - coin: 'btc', - value: '1PzAJcFtEiXo9UGtRU6iqXQKj8NXtcC7DE', - }, - { - coin: 'sol', - value: 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH', - } - ], - texts: [{ key: 'foo', value: 'bar' }], - abi: await encodeAbi({ encodeAs: 'json', data: dummyABI }), - contentHash: 'ipns://k51qzi5uqu5dgox2z23r6e99oqency055a6xt92xzmyvpz8mwz5ycjavm0u150' - } - } - await commitAndRegisterName(params) - - const nameOwner = await getOwner(publicClient, { - name: name, - }) - expect(nameOwner!.owner).toBe(accounts[1]) - // expect(nameOwner!.registrant).toBe(accounts[1]) - expect(nameOwner!.ownershipLevel).toBe('nameWrapper') - - - const resolver = await getResolver(publicClient, { name: name }) - - const setAddressRecordTx = await setAddressRecord(walletClient, { - name: name, - coin: 'eth', - value: accounts[2], - resolverAddress: resolver as Address, - account: accounts[1], - }) - expect(setAddressRecordTx).toBeTruthy() - const setAddressRecordTxReceipt = await waitForTransaction(setAddressRecordTx) - expect(setAddressRecordTxReceipt.status).toBe('success') - - const tx = await setRecords(walletClient, { - name: name, - resolverAddress: (await getResolver(publicClient, { - name: name, - }))!, - clearRecords: true, - account: accounts[1], - }) - expect(tx).toBeTruthy() - const receipt = await waitForTransaction(tx) - expect(receipt.status).toBe('success') - - const transferMgrTx = await transferName(walletClient, { - name: name, - newOwnerAddress: accounts[2], - contract: 'nameWrapper', - account: accounts[1], - }) - expect(transferMgrTx).toBeTruthy() - const transferMgrTxReceipt = await waitForTransaction(transferMgrTx) - expect(transferMgrTxReceipt.status).toBe('success') -}) - -it('Register - unwrapped 2LD - unwrapped subname', async () => {`` - const name = 'cool-swag-wrap.eth' - const subname = 'subname.cool-swag-wrap.eth' - const params: RegistrationParameters = { - name: name, - duration: 31536000, - owner: accounts[1], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - records: { - coins: [ - { - coin: 'etcLegacy', - value: accounts[1], - }, - { - coin: 'btc', - value: '1PzAJcFtEiXo9UGtRU6iqXQKj8NXtcC7DE', - }, - { - coin: 'sol', - value: 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH', - } - ], - texts: [{ key: 'foo', value: 'bar' }], - abi: await encodeAbi({ encodeAs: 'json', data: dummyABI }), - contentHash: 'ipns://k51qzi5uqu5dgox2z23r6e99oqency055a6xt92xzmyvpz8mwz5ycjavm0u150' - } - } - await commitAndRegisterName(params) - - const nameOwner = await getOwner(publicClient, { - name: name, - }) - expect(nameOwner!.owner).toBe(accounts[1]) - // expect(nameOwner!.registrant).toBe(accounts[1]) - expect(nameOwner!.ownershipLevel).toBe('nameWrapper') - const resolver = await getResolver(publicClient, { name: name }) - - const unwrapNameTx = await unwrapName(walletClient, { - name: name, - newOwnerAddress: accounts[1], - newRegistrantAddress: accounts[1], - account: accounts[1], - }) - expect(unwrapNameTx).toBeTruthy() - const unwrapNameTxReceipt = await waitForTransaction(unwrapNameTx) - expect(unwrapNameTxReceipt.status).toBe('success') - - //get resolver - const resolverAddress = await getResolver(publicClient, { name: name }) - - //add subname - const createSubnameTx = await createSubname(walletClient, { - name: subname, - contract: 'registry', - owner: accounts[2], - account: accounts[1], - resolverAddress: resolverAddress as Address, - }) - - expect(createSubnameTx).toBeTruthy() - const createSubnameTxReceipt = await waitForTransaction(createSubnameTx) - expect(createSubnameTxReceipt.status).toBe('success') - - const setRecordsTx = await setRecords(walletClient, { - name: subname, - resolverAddress: resolverAddress as Address, - coins: [ - { - coin: 'etcLegacy', - value: accounts[1], - }, - { - coin: 'btc', - value: '1PzAJcFtEiXo9UGtRU6iqXQKj8NXtcC7DE', - }, - { - coin: 'sol', - value: 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH', - } - ], - texts: [{ key: 'foo', value: 'bar' }], - abi: await encodeAbi({ encodeAs: 'json', data: dummyABI }), - contentHash: 'ipns://k51qzi5uqu5dgox2z23r6e99oqency055a6xt92xzmyvpz8mwz5ycjavm0u150', - account: accounts[2], - }) - const setRecordsTxReceipt = await waitForTransaction(setRecordsTx) - expect(setRecordsTxReceipt.status).toBe('success') - - const setAddressRecordTx = await setAddressRecord(walletClient, { - name:subname, - coin: 'eth', - value: accounts[1], - resolverAddress: resolver as Address, - account: accounts[2], - }) - expect(setAddressRecordTx).toBeTruthy() - const setAddressRecordTxReceipt = await waitForTransaction(setAddressRecordTx) - expect(setAddressRecordTxReceipt.status).toBe('success') - - const transferMgrTx = await transferName(walletClient, { - name: subname, - newOwnerAddress: accounts[3], - contract: 'registry', - account: accounts[2], - }) - expect(transferMgrTx).toBeTruthy() - const transferMgrTxReceipt = await waitForTransaction(transferMgrTx) - expect(transferMgrTxReceipt.status).toBe('success') - - const transferMgrAsParentTx = await transferName(walletClient, { - name: subname, - newOwnerAddress: accounts[2], - contract: 'registry', - account: accounts[1], - asParent: true, - }) - expect(transferMgrAsParentTx).toBeTruthy() - const transferMgrAsParentTxReceipt = await waitForTransaction(transferMgrAsParentTx) - expect(transferMgrAsParentTxReceipt.status).toBe('success') -}) - -it('Register - wrapped 2LD - wrapped 3LD', async () => { - const name = 'cool-swag-wrap.eth' - const params: RegistrationParameters = { - name: name, - duration: 31536000, - owner: accounts[1], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - } - await commitAndRegisterName(params) - - //create subname - const subname = 'subname.cool-swag-wrap.eth' - 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') - - const resolver = await getResolver(publicClient, { name: name }) - - const setAddressRecordTx = await setAddressRecord(walletClient, { - name: subname, - coin: 'eth', - value: accounts[3], - resolverAddress: resolver as Address, - account: accounts[2], - }) - expect(setAddressRecordTx).toBeTruthy() - const setAddressRecordTxReceipt = await waitForTransaction(setAddressRecordTx) - expect(setAddressRecordTxReceipt.status).toBe('success') - - const transferMgrTx = await transferName(walletClient, { - name: subname, - newOwnerAddress: accounts[3], - contract: 'nameWrapper', - account: accounts[2], - }) - expect(transferMgrTx).toBeTruthy() - const transferMgrTxReceipt = await waitForTransaction(transferMgrTx) - expect(transferMgrTxReceipt.status).toBe('success') - -}) - -it('Register - wrapped 2LD - wrapped 3LD - PCC Burned', async () => { - const name = 'cool-swag-wrap.eth' - const params: RegistrationParameters = { - name: name, - duration: 31536000, - owner: accounts[1], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - fuses: { - named: [ - 'CANNOT_UNWRAP', - ], - } - } - await commitAndRegisterName(params) - - //create subname - const subname = 'subname.cool-swag-wrap.eth' - const createSubnameTx = await createSubname(walletClient, { - name: subname, - contract: 'nameWrapper', - owner: accounts[2], - account: accounts[1], - fuses: { - parent: { - named: [ - 'PARENT_CANNOT_CONTROL', - ], - }, - } - }) - - expect(createSubnameTx).toBeTruthy() - const createSubnameTxReceipt = await waitForTransaction(createSubnameTx) - expect(createSubnameTxReceipt.status).toBe('success') - - const resolver = await getResolver(publicClient, { name: name }) - - const transferMgrByParentTx = await transferName(walletClient, { - name: subname, - newOwnerAddress: accounts[3], - contract: 'nameWrapper', - account: accounts[1], - }) - expect(transferMgrByParentTx).toBeTruthy() - const transferMgrByParentTxReceipt = await waitForTransaction(transferMgrByParentTx) - expect(transferMgrByParentTxReceipt.status).toBe('reverted') - - const transferMgrTx = await transferName(walletClient, { - name: subname, - newOwnerAddress: accounts[3], - contract: 'nameWrapper', - account: accounts[2], - }) - expect(transferMgrTx).toBeTruthy() - const transferMgrTxReceipt = await waitForTransaction(transferMgrTx) - expect(transferMgrTxReceipt.status).toBe('success') - -}) - -it('Register - wrapped 2LD - wrapped 3LD - wrapped 4LD - PCC Burned', async () => { - const name = 'cool-swag-wrap.eth' - const params: RegistrationParameters = { - name: name, - duration: 31536000, - owner: accounts[1], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - fuses: { - named: [ - 'CANNOT_UNWRAP', - ], - } - } - await commitAndRegisterName(params) - - //create subname - const subname = 'subname.cool-swag-wrap.eth' - const createSubnameTx = await createSubname(walletClient, { - name: subname, - contract: 'nameWrapper', - owner: accounts[2], - account: accounts[1], - fuses: { - parent: { - named: [ 'PARENT_CANNOT_CONTROL' ], - }, - child: { - named: [ 'CANNOT_UNWRAP' ], - }, - } - }) - - expect(createSubnameTx).toBeTruthy() - const createSubnameTxReceipt = await waitForTransaction(createSubnameTx) - expect(createSubnameTxReceipt.status).toBe('success') - - //create subname - const subname2 = 'subname.subname.cool-swag-wrap.eth' - const createSubnameTx2 = await createSubname(walletClient, { - name: subname2, - contract: 'nameWrapper', - owner: accounts[3], - account: accounts[2], - fuses: { - parent: { - named: [ - 'PARENT_CANNOT_CONTROL', - ], - }, - } - }) - - expect(createSubnameTx2).toBeTruthy() - const createSubnameTxReceipt2 = await waitForTransaction(createSubnameTx2) - expect(createSubnameTxReceipt2.status).toBe('success') - - const transferMgrByParentTx = await transferName(walletClient, { - name: subname2, - newOwnerAddress: accounts[3], - contract: 'nameWrapper', - account: accounts[1], - }) - expect(transferMgrByParentTx).toBeTruthy() - const transferMgrByParentTxReceipt = await waitForTransaction(transferMgrByParentTx) - expect(transferMgrByParentTxReceipt.status).toBe('reverted') - - const transferMgrTx = await transferName(walletClient, { - name: subname2, - newOwnerAddress: accounts[2], - contract: 'nameWrapper', - account: accounts[3], - }) - expect(transferMgrTx).toBeTruthy() - const transferMgrTxReceipt = await waitForTransaction(transferMgrTx) - expect(transferMgrTxReceipt.status).toBe('success') -}) \ No newline at end of file diff --git a/packages/ensjs/src/functions/wallet/registerName.e2e.test.ts b/packages/ensjs/src/functions/wallet/registerName.e2e.test.ts deleted file mode 100644 index 8104a940..00000000 --- a/packages/ensjs/src/functions/wallet/registerName.e2e.test.ts +++ /dev/null @@ -1,791 +0,0 @@ -import { labelhash, type Address, type Hex } from 'viem' -import { getChainContractAddress } from '../../contracts/getChainContractAddress.js' -import { nameWrapperOwnerOfSnippet } from '../../contracts/nameWrapper.js' -import { - publicClient, - testClient, - waitForTransaction, - walletClient, -} from '../../test/addTestContracts.js' -import { namehash } from '../../utils/normalise.js' -import type { RegistrationParameters } from '../../utils/registerHelpers.js' -import getPrice from '../public/getPrice.js' -import commitName from './commitName.js' -import registerName from './registerName.js' -import { baseRegistrarNameExpiresSnippet } from '../../contracts/baseRegistrar.js' -import renewNames from './renewNames.js' -import getName from '../public/getName.js' -import setPrimaryName from './setPrimaryName.js' -import setAddressRecord from './setAddressRecord.js' -import getResolver from '../public/getResolver.js' -import getAddressRecord from '../public/getAddressRecord.js' -import getOwner from '../public/getOwner.js' -import unwrapName from './unwrapName.js' -import transferName from './transferName.js' -import createSubname from './createSubname.js' -import { registryOwnerSnippet, registrySetApprovalForAllSnippet } from '../../contracts/registry.js' -import wrapName from './wrapName.js' - -let snapshot: Hex -let accounts: Address[] - -beforeAll(async () => { - accounts = await walletClient.getAddresses() - console.log(accounts[1]) - console.log(accounts[2]) -}) - -beforeEach(async () => { - snapshot = await testClient.snapshot() -}) - -afterEach(async () => { - await testClient.revert({ id: snapshot }) -}) - -const secret = `0x${'a'.repeat(64)}` as Hex - -const getNameWrapperOwner = async (name: string) => { - return publicClient.readContract({ - abi: nameWrapperOwnerOfSnippet, - functionName: 'ownerOf', - address: getChainContractAddress({ - client: publicClient, - contract: 'ensNameWrapper', - }), - args: [BigInt(namehash(name))], - }) -} - -const getExpiry = async (name: string) => { - return publicClient.readContract({ - abi: baseRegistrarNameExpiresSnippet, - functionName: 'nameExpires', - address: getChainContractAddress({ - client: publicClient, - contract: 'ensBaseRegistrarImplementation', - }), - args: [BigInt(labelhash(name.split('.')[0]))], - }) -} - -const approve = async (address: Address) => { - return walletClient.writeContract({ - abi: registrySetApprovalForAllSnippet, - address: getChainContractAddress({ - client: walletClient, - contract: 'ensRegistry', - }), - functionName: 'setApprovalForAll', - args: [ - getChainContractAddress({ - client: walletClient, - contract: 'ensNameWrapper', - }), - true, - ], - account: address, - }) -} - -const dummyABI = [ - { - type: 'function', - name: 'supportsInterface', - constant: true, - stateMutability: 'view', - payable: false, - inputs: [ - { - type: 'bytes4', - }, - ], - outputs: [ - { - type: 'bool', - }, - ], - }, -] - -it('Register - Add Eth Address - Set Primary Name - Get Primary Name - Get Expiry - Renew Name', async () => { - const params: RegistrationParameters = { - name: 'coolest-swag.eth', - duration: 31536000, - owner: accounts[1], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - } - const commitTx = await commitName(walletClient, { - ...params, - account: accounts[1], - }) - expect(commitTx).toBeTruthy() - const commitReceipt = await waitForTransaction(commitTx) - - expect(commitReceipt.status).toBe('success') - - await testClient.increaseTime({ seconds: 61 }) - await testClient.mine({ blocks: 1 }) - - const price = await getPrice(publicClient, { - nameOrNames: params.name, - duration: params.duration, - }) - const total = price!.base + price!.premium - - const tx = await registerName(walletClient, { - ...params, - account: accounts[1], - value: total, - }) - expect(tx).toBeTruthy() - const receipt = await waitForTransaction(tx) - expect(receipt.status).toBe('success') - - const owner = await getNameWrapperOwner(params.name) - expect(owner).toBe(accounts[1]) - - // const registerNameTxBlock = (await publicClient.getTransaction({ hash: tx })).blockHash - // const blockTS = (await publicClient.getBlock({ blockHash: registerNameTxBlock })).timestamp - // testClient.increaseTime({ seconds: params.duration }) - // testClient.mine({ blocks: 1 }) - - const resolver = await getResolver(publicClient, { name: params.name }) - - console.log(resolver) - - const setAddressRecordTx = await setAddressRecord(walletClient, { - name: params.name, - coin: 'eth', - value: accounts[1], - resolverAddress: resolver!, - account: accounts[1], - }) - expect(setAddressRecordTx).toBeTruthy() - const setAddressRecordTxReceipt = await waitForTransaction(setAddressRecordTx) - expect(setAddressRecordTxReceipt.status).toBe('success') - - testClient.mine({ blocks: 1 }) - - const getAddressRecordResult = await getAddressRecord(publicClient, { - name: params.name, - }) - - console.log(getAddressRecordResult) - - const setPrimaryNameTx = await setPrimaryName(walletClient, { - name: params.name, - account: accounts[1], - }) - 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[1], - }) - - console.log(result) - - const expiredOwner = await getNameWrapperOwner(params.name) - expect(expiredOwner).toBe(accounts[1]) - - // const newExpiry = await getExpiry(params.name) - // expect(newExpiry).toBe(BigInt(blockTS) + BigInt(params.duration)) - - const renewTx = await renewNames(walletClient, { - nameOrNames: params.name, - duration: params.duration, - value: total, - account: accounts[0], - }) - expect(tx).toBeTruthy() - const renewTxReceipt = await waitForTransaction(renewTx) - expect(renewTxReceipt.status).toBe('success') - -}) - -it('Register - Get Expiry - Advance time - Renew Name', async () => { - const params: RegistrationParameters = { - name: 'coolest-swag.eth', - duration: 31536000, - owner: accounts[1], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - } - const commitTx = await commitName(walletClient, { - ...params, - account: accounts[1], - }) - expect(commitTx).toBeTruthy() - const commitReceipt = await waitForTransaction(commitTx) - - expect(commitReceipt.status).toBe('success') - - await testClient.increaseTime({ seconds: 61 }) - await testClient.mine({ blocks: 1 }) - - const price = await getPrice(publicClient, { - nameOrNames: params.name, - duration: params.duration, - }) - const total = price!.base + price!.premium - - const tx = await registerName(walletClient, { - ...params, - account: accounts[1], - value: total, - }) - expect(tx).toBeTruthy() - const receipt = await waitForTransaction(tx) - expect(receipt.status).toBe('success') - - const owner = await getNameWrapperOwner(params.name) - expect(owner).toBe(accounts[1]) - - const registerNameTxBlock = (await publicClient.getTransaction({ hash: tx })).blockHash - const blockTS = (await publicClient.getBlock({ blockHash: registerNameTxBlock })).timestamp - - const expiry = await getExpiry(params.name) - expect(expiry).toBe(BigInt(blockTS) + BigInt(params.duration)) - - testClient.increaseTime({ seconds: params.duration }) - testClient.mine({ blocks: 1 }) - - const resolver = await getResolver(publicClient, { name: params.name }) - - console.log(resolver) - - const setAddressRecordTx = await setAddressRecord(walletClient, { - name: params.name, - coin: 'eth', - value: accounts[1], - resolverAddress: resolver!, - account: accounts[1], - }) - expect(setAddressRecordTx).toBeTruthy() - const setAddressRecordTxReceipt = await waitForTransaction(setAddressRecordTx) - expect(setAddressRecordTxReceipt.status).toBe('success') - - testClient.mine({ blocks: 1 }) - - const getAddressRecordResult = await getAddressRecord(publicClient, { - name: params.name, - }) - - console.log(getAddressRecordResult) - - const setPrimaryNameTx = await setPrimaryName(walletClient, { - name: params.name, - account: accounts[1], - }) - 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[1], - }) - - console.log(result) - - const expiredOwner = await getNameWrapperOwner(params.name) - expect(expiredOwner).toBe(accounts[1]) - - const newExpiry = await getExpiry(params.name) - expect(newExpiry).toBe(BigInt(blockTS) + BigInt(params.duration)) - - const renewTx = await renewNames(walletClient, { - nameOrNames: params.name, - duration: params.duration, - value: total, - account: accounts[0], - }) - expect(renewTx).toBeTruthy() - const renewTxReceipt = await waitForTransaction(renewTx) - expect(renewTxReceipt.status).toBe('success') - - const renewTxTxBlock = (await publicClient.getTransaction({ hash: renewTx })).blockHash - const renewTxTxBlockTS = (await publicClient.getBlock({ blockHash: renewTxTxBlock })).timestamp - - const nextExpiry = await getExpiry(params.name) - expect(nextExpiry).toBeGreaterThan(BigInt(renewTxTxBlockTS)) - - testClient.increaseTime({ seconds: params.duration * 3}) - testClient.mine({ blocks: 1 }) - - const params2: RegistrationParameters = { - name: 'coolest-swag.eth', - duration: 31536000, - owner: accounts[2], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - } - const commitTx2 = await commitName(walletClient, { - ...params2, - account: accounts[2], - }) - expect(commitTx2).toBeTruthy() - const commitReceipt2 = await waitForTransaction(commitTx2) - - expect(commitReceipt2.status).toBe('success') - await testClient.increaseTime({ seconds: 61 }) - await testClient.mine({ blocks: 1 }) - - const price2 = await getPrice(publicClient, { - nameOrNames: params2.name, - duration: params2.duration, - }) - const total2 = price2!.base + price2!.premium - - const tx2 = await registerName(walletClient, { - ...params2, - account: accounts[2], - value: total2, - }) - - expect(tx2).toBeTruthy() - - const receipt2 = await waitForTransaction(tx2) - - expect(receipt2.status).toBe('success') - testClient.mine({ blocks: 1 }) - - console.log(receipt2) - - console.log(accounts[2]) - console.log(accounts[1]) - - const getAddressRecordResult2 = await getAddressRecord(publicClient, { - name: params.name, - }) - - console.log(getAddressRecordResult2) - - const result2 = await getName(publicClient, { - address: accounts[1], - }) - - console.log(result2) - - -}) - -it('Register - Set other as primary name', async () => { - const params: RegistrationParameters = { - name: 'other-eth-record-2.eth', - duration: 31536000, - owner: accounts[1], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - } - - type name = 'other-eth-record-2.eth' - const commitTx = await commitName(walletClient, { - ...params, - account: accounts[1], - }) - expect(commitTx).toBeTruthy() - const commitReceipt = await waitForTransaction(commitTx) - - expect(commitReceipt.status).toBe('success') - - await testClient.increaseTime({ seconds: 61 }) - await testClient.mine({ blocks: 1 }) - - const price = await getPrice(publicClient, { - nameOrNames: params.name, - duration: params.duration, - }) - const total = price!.base + price!.premium - - const tx = await registerName(walletClient, { - ...params, - account: accounts[1], - value: total, - }) - expect(tx).toBeTruthy() - const receipt = await waitForTransaction(tx) - expect(receipt.status).toBe('success') - - const owner = await getNameWrapperOwner(params.name) - expect(owner).toBe(accounts[1]) - - const unwrapNameTx = await unwrapName(walletClient, { - name: params.name as name, - newOwnerAddress: accounts[1], - newRegistrantAddress: accounts[1], - account: accounts[1], - }) - expect(tx).toBeTruthy() - const unwrapNameTxReceipt = await waitForTransaction(unwrapNameTx) - expect(unwrapNameTxReceipt.status).toBe('success') - - const resolver = await getResolver(publicClient, { name: params.name }) - - const setAddressRecordTx = await setAddressRecord(walletClient, { - name: params.name, - coin: 'eth', - value: accounts[2], - resolverAddress: resolver!, - account: accounts[1], - }) - expect(setAddressRecordTx).toBeTruthy() - const setAddressRecordTxReceipt = await waitForTransaction(setAddressRecordTx) - expect(setAddressRecordTxReceipt.status).toBe('success') - - testClient.mine({ blocks: 1 }) - - const getAddressRecordResult = await getAddressRecord(publicClient, { - name: params.name, - }) - - console.log(getAddressRecordResult) - - const setPrimaryNameTx = await setPrimaryName(walletClient, { - name: params.name, - 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": "${params.name}", - "resolverAddress": "${testClient.chain.contracts.ensPublicResolver.address}", - "reverseResolverAddress": "${testClient.chain.contracts.ensPublicResolver.address}", - } - `) - -}) - -it('Register - Set other manager as primary name', async () => { - const params: RegistrationParameters = { - name: 'other-eth-record-2.eth', - duration: 31536000, - owner: accounts[1], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - } - - const commitTx = await commitName(walletClient, { - ...params, - account: accounts[1], - }) - expect(commitTx).toBeTruthy() - const commitReceipt = await waitForTransaction(commitTx) - - expect(commitReceipt.status).toBe('success') - - await testClient.increaseTime({ seconds: 61 }) - await testClient.mine({ blocks: 1 }) - - const price = await getPrice(publicClient, { - nameOrNames: params.name, - duration: params.duration, - }) - const total = price!.base + price!.premium - - const tx = await registerName(walletClient, { - ...params, - account: accounts[1], - value: total, - }) - expect(tx).toBeTruthy() - const receipt = await waitForTransaction(tx) - expect(receipt.status).toBe('success') - - const owner = await getNameWrapperOwner(params.name) - expect(owner).toBe(accounts[1]) - - const name = 'other-eth-record-2.eth' - const unwrapNameTx = await unwrapName(walletClient, { - name: name, - newOwnerAddress: accounts[1], - account: accounts[1], - newRegistrantAddress: accounts[1], - }) - expect(tx).toBeTruthy() - const unwrapNameTxReceipt = await waitForTransaction(unwrapNameTx) - expect(unwrapNameTxReceipt.status).toBe('success') - - const resolver = await getResolver(publicClient, { name: params.name }) - - const transferNameTx = await transferName(walletClient, { - name: name, - newOwnerAddress: accounts[3], - contract: 'registrar', - account: accounts[1], - }) - expect(transferNameTx).toBeTruthy() - const transferNameTxReceipt = await waitForTransaction(transferNameTx) - expect(transferNameTxReceipt.status).toBe('success') - - const nameDetails = await getOwner(publicClient, { - name: params.name, - contract: 'registrar', - }) - expect(nameDetails!.registrant).toBe(accounts[3]) - - const setAddressRecordTx = await setAddressRecord(walletClient, { - name: params.name, - coin: 'eth', - value: accounts[2], - resolverAddress: resolver!, - account: accounts[1], - }) - expect(setAddressRecordTx).toBeTruthy() - const setAddressRecordTxReceipt = await waitForTransaction(setAddressRecordTx) - expect(setAddressRecordTxReceipt.status).toBe('success') - - testClient.mine({ blocks: 1 }) - - const getAddressRecordResult = await getAddressRecord(publicClient, { - name: params.name, - }) - - console.log(getAddressRecordResult) - - const setPrimaryNameTx = await setPrimaryName(walletClient, { - name: params.name, - account: accounts[3], - }) - 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[3], - }) - - expect(result).toMatchInlineSnapshot(` - { - "match": true, - "name": "${params.name}", - "resolverAddress": "${testClient.chain.contracts.ensPublicResolver.address}", - "reverseResolverAddress": "${testClient.chain.contracts.ensPublicResolver.address}", - } - `) - -}) - -it('Register - Set Subname', async () => { - const params: RegistrationParameters = { - name: 'cool-swag-wrap.eth', - duration: 31536000, - owner: accounts[1], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - } - - const commitTx = await commitName(walletClient, { - ...params, - account: accounts[1], - }) - expect(commitTx).toBeTruthy() - const commitReceipt = await waitForTransaction(commitTx) - - expect(commitReceipt.status).toBe('success') - - await testClient.increaseTime({ seconds: 61 }) - await testClient.mine({ blocks: 1 }) - - const price = await getPrice(publicClient, { - nameOrNames: params.name, - duration: params.duration, - }) - const total = price!.base + price!.premium - - const tx = await registerName(walletClient, { - ...params, - account: accounts[1], - value: total, - }) - expect(tx).toBeTruthy() - const receipt = await waitForTransaction(tx) - expect(receipt.status).toBe('success') - - const subName = 'test.cool-swag-wrap.eth' - 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') - - const owner = await publicClient.readContract({ - abi: nameWrapperOwnerOfSnippet, - functionName: 'ownerOf', - address: getChainContractAddress({ - client: publicClient, - contract: 'ensNameWrapper', - }), - args: [BigInt(namehash(subName))], - }) - 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}", - } - `) -}) - -it('Register - unwrap 2LD - wrap Subname', async () => { - const name = 'cool-swag-wrap.eth' - const params: RegistrationParameters = { - name: name, - duration: 31536000, - owner: accounts[1], - secret, - resolverAddress: testClient.chain.contracts.ensPublicResolver.address, - } - - const commitTx = await commitName(walletClient, { - ...params, - account: accounts[1], - }) - expect(commitTx).toBeTruthy() - const commitReceipt = await waitForTransaction(commitTx) - - expect(commitReceipt.status).toBe('success') - - await testClient.increaseTime({ seconds: 61 }) - await testClient.mine({ blocks: 1 }) - - const price = await getPrice(publicClient, { - nameOrNames: params.name, - duration: params.duration, - }) - const total = price!.base + price!.premium - - const tx = await registerName(walletClient, { - ...params, - account: accounts[1], - value: total, - }) - expect(tx).toBeTruthy() - const receipt = await waitForTransaction(tx) - expect(receipt.status).toBe('success') - - const unwrapNameTx = await unwrapName(walletClient, { - name: name, - newOwnerAddress: accounts[1], - newRegistrantAddress: accounts[1], - account: accounts[1], - }) - expect(tx).toBeTruthy() - const unwrapNameTxReceipt = await waitForTransaction(unwrapNameTx) - expect(unwrapNameTxReceipt.status).toBe('success') - - const nameOwner = await getOwner(publicClient, { - name: name, - }) - expect(nameOwner!.owner).toBe(accounts[1]) - expect(nameOwner!.registrant).toBe(accounts[1]) - expect(nameOwner!.ownershipLevel).toBe('registrar') - - const subName = 'test.cool-swag-wrap.eth' - const createSubnameTx = await createSubname(walletClient, { - name: subName, - contract: 'registry', - owner: accounts[2], - account: accounts[1], - }) - expect(createSubnameTx).toBeTruthy() - const createSubnameTxReceipt = await waitForTransaction(createSubnameTx) - expect(createSubnameTxReceipt.status).toBe('success') - - const subNameOwner = await publicClient.readContract({ - abi: registryOwnerSnippet, - functionName: 'owner', - address: getChainContractAddress({ - client: publicClient, - contract: 'ensRegistry', - }), - args: [namehash(subName)], - }) - expect(subNameOwner).toBe(accounts[2]) - - const resolver = await getResolver(publicClient, { name: subName }) - - console.log(resolver) - - await approve(accounts[2]) - - const wrapNameTx = await wrapName(walletClient, { - name: subName, - newOwnerAddress: accounts[2], - account: accounts[2], - }) - expect(tx).toBeTruthy() - const wrapNameTxReceipt = await waitForTransaction(wrapNameTx) - expect(wrapNameTxReceipt.status).toBe('success') - - const owner = await getOwner(publicClient, { - name: subName, - }) - expect(owner!.owner).toBe(accounts[2]) - expect(owner!.ownershipLevel).toBe('nameWrapper') - - - -}) \ No newline at end of file diff --git a/packages/ensjs/src/functions/wallet/setRecords.test.ts b/packages/ensjs/src/functions/wallet/setRecords.test.ts index d39b3572..fe58ff3a 100644 --- a/packages/ensjs/src/functions/wallet/setRecords.test.ts +++ b/packages/ensjs/src/functions/wallet/setRecords.test.ts @@ -10,6 +10,7 @@ import { encodeAbi } from '../../utils/encoders/encodeAbi.js' import getRecords from '../public/getRecords.js' import getResolver from '../public/getResolver.js' import setRecords from './setRecords.js' +import getSubgraphRecords from '../subgraph/getSubgraphRecords.js' let snapshot: Hex let accounts: Address[] @@ -25,7 +26,7 @@ beforeEach(async () => { afterEach(async () => { await testClient.revert({ id: snapshot }) }) - +jest.setTimeout(15000) const dummyABI = [ { type: 'function', @@ -124,185 +125,4 @@ it('should not wrap with multicall if only setting a single record', async () => }) // 0x8b95dd71 is the function selector for setAddr(bytes32,uint256,bytes) expect(encodedData.data.startsWith('0x8b95dd71')).toBe(true) -}) -it('should return a transaction to the resolver and update successfully', async () => { - const tx = await setRecords(walletClient, { - name: 'test123.eth', - resolverAddress: (await getResolver(publicClient, { - name: 'test123.eth', - }))!, - coins: [ - { - coin: 'etcLegacy', - value: '0x42D63ae25990889E35F215bC95884039Ba354115', - }, - ], - texts: [{ key: 'foo', value: 'bar' }], - abi: await encodeAbi({ encodeAs: 'json', data: dummyABI }), - contentHash: 'ipfs://bafybeico3uuyj3vphxpvbowchdwjlrlrh62awxscrnii7w7flu5z6fk77y', - account: accounts[1], - }) - expect(tx).toBeTruthy() - const receipt = await waitForTransaction(tx) - expect(receipt.status).toBe('success') - await testClient.mine({ blocks: 1 }) - - - const utx = await setRecords(walletClient, { - name: 'test123.eth', - resolverAddress: (await getResolver(publicClient, { - name: 'test123.eth', - }))!, - coins: [ - { - coin: 'etcLegacy', - value: accounts[1], - }, - ], - texts: [{ key: 'foo', value: 'bars' }], - abi: await encodeAbi({ encodeAs: 'json', data: [...dummyABI,{stateMutability: 'readonly',}] }), - contentHash: 'ipns://k51qzi5uqu5dgox2z23r6e99oqency055a6xt92xzmyvpz8mwz5ycjavm0u150', - account: accounts[1], - }) - expect(utx).toBeTruthy() - const ureceipt = await waitForTransaction(utx) - expect(ureceipt.status).toBe('success') - - const records = await getRecords(publicClient, { - name: 'test123.eth', - records: { - coins: ['etcLegacy'], - texts: ['foo'], - contentHash: true, - abi: true, - }, - }) - expect(records.contentHash).toMatchInlineSnapshot(` - { - "decoded": "k51qzi5uqu5dgox2z23r6e99oqency055a6xt92xzmyvpz8mwz5ycjavm0u150", - "protocolType": "ipns", - } -`) - expect(records.abi!.abi).toStrictEqual([...dummyABI,{stateMutability: 'readonly',}]) - expect(records.coins).toMatchInlineSnapshot(` - [ - { - "id": 61, - "name": "etcLegacy", - "value": "${accounts[1]}", - }, - ] - `) - expect(records.texts).toMatchInlineSnapshot(` - [ - { - "key": "foo", - "value": "bars", - }, - ] - `) -}) -it.only('should return a transaction to the resolver and remove successfully', async () => { - const tx = await setRecords(walletClient, { - name: 'test123.eth', - resolverAddress: (await getResolver(publicClient, { - name: 'test123.eth', - }))!, - coins: [ - { - coin: 'etcLegacy', - value: '0x42D63ae25990889E35F215bC95884039Ba354115', - }, - ], - texts: [{ key: 'foo', value: 'bar' }], - abi: await encodeAbi({ encodeAs: 'json', data: dummyABI }), - contentHash: 'ipfs://bafybeico3uuyj3vphxpvbowchdwjlrlrh62awxscrnii7w7flu5z6fk77y', - account: accounts[1], - }) - expect(tx).toBeTruthy() - const receipt = await waitForTransaction(tx) - expect(receipt.status).toBe('success') - await testClient.mine({ blocks: 1 }) - - - const utx = await setRecords(walletClient, { - name: 'test123.eth', - resolverAddress: (await getResolver(publicClient, { - name: 'test123.eth', - }))!, - coins: [], - texts: [], - abi: null, - contentHash: null, - account: accounts[1], - }) - expect(utx).toBeTruthy() - const ureceipt = await waitForTransaction(utx) - expect(ureceipt.status).toBe('success') - - const records = await getRecords(publicClient, { - name: 'test123.eth', - records: { - coins: [], - texts: [], - abi: true, - contentHash: true, - }, - }) - console.log(records) - expect(records.contentHash).toBeNull() - expect(records.abi!.abi).toMatchInlineSnapshot(`abi: { contentType: 1, decoded: true, abi: [ [Object] ] }`) - expect(records.coins).toMatchInlineSnapshot(`[]`) - expect(records.texts).toMatchInlineSnapshot(`[]`) -}) -it('should return a transaction to the resolver and ignore undefined', async () => { - const tx = await setRecords(walletClient, { - name: 'test123.eth', - resolverAddress: (await getResolver(publicClient, { - name: 'test123.eth', - }))!, - coins: [ - { - coin: 'etcLegacy', - value: '0x42D63ae25990889E35F215bC95884039Ba354115', - }, - ], - texts: [{ key: 'foo', value: 'bar' }], - abi: await encodeAbi({ encodeAs: 'json', data: dummyABI }), - contentHash: 'ipfs://bafybeico3uuyj3vphxpvbowchdwjlrlrh62awxscrnii7w7flu5z6fk77y', - account: accounts[1], - }) - expect(tx).toBeTruthy() - const receipt = await waitForTransaction(tx) - expect(receipt.status).toBe('success') - await testClient.mine({ blocks: 1 }) - - - const utx = await setRecords(walletClient, { - name: 'test123.eth', - resolverAddress: (await getResolver(publicClient, { - name: 'test123.eth', - }))!, - coins: [], - texts: [], - abi: undefined, - contentHash: undefined, - account: accounts[1], - }) - expect(utx).toBeTruthy() - const ureceipt = await waitForTransaction(utx) - expect(ureceipt.status).toBe('success') - - const records = await getRecords(publicClient, { - name: 'test123.eth', - records: { - coins: [], - texts: [], - abi: true, - contentHash: true, - }, - }) - expect(records.abi).toMatchInlineSnapshot(`undefined`) - expect(records.coins).toMatchInlineSnapshot(`[]`) - expect(records.texts).toMatchInlineSnapshot(`[]`) }) \ No newline at end of file