From a61794ac4ca2d38e3e2300998d66798433e29a79 Mon Sep 17 00:00:00 2001 From: sugh01 <19183308+sugh01@users.noreply.github.com> Date: Mon, 27 May 2024 07:58:11 +0200 Subject: [PATCH 1/6] update ccip tests with holesky offchain resolver --- .../ensjs/src/functions/public/ccip.test.ts | 148 ++++++++++++------ 1 file changed, 98 insertions(+), 50 deletions(-) diff --git a/packages/ensjs/src/functions/public/ccip.test.ts b/packages/ensjs/src/functions/public/ccip.test.ts index 157ec87b..7a373e22 100644 --- a/packages/ensjs/src/functions/public/ccip.test.ts +++ b/packages/ensjs/src/functions/public/ccip.test.ts @@ -1,12 +1,12 @@ import { createPublicClient, http } from 'viem' -import { mainnet } from 'viem/chains' +import { holesky, mainnet } from 'viem/chains' import { describe, expect, it, vi } from 'vitest' import { addEnsContracts } from '../../contracts/addEnsContracts.js' import { ccipRequest } from '../../utils/ccipRequest.js' import batch from './batch.js' import getAddressRecord from './getAddressRecord.js' import getRecords from './getRecords.js' -// import getText from './getTextRecord.js' +import getText from './getTextRecord.js' vi.setConfig({ testTimeout: 30000, @@ -17,54 +17,100 @@ const mainnetPublicClient = createPublicClient({ transport: http('https://mainnet.gateway.tenderly.co/4imxc4hQfRjxrVB2kWKvTo'), }) -describe('CCIP', () => { +const holeskyPublicClient = createPublicClient({ + chain: addEnsContracts(holesky), + transport: http('https://holesky.gateway.tenderly.co'), +}) + +describe.only('CCIP', () => { describe('getRecords', () => { it('should return records from a ccip-read name', async () => { - const result = await getRecords(mainnetPublicClient, { - name: 'sg.offchaindemo.eth', - // texts: ['email', 'description'], - // contentHash: true, - coins: ['60'], + const result = await getRecords(holeskyPublicClient, { + name: 'offchainexample.eth', + texts: ['email', 'description'], + contentHash: true, + coins: ['btc', '60'], }) expect(result).toMatchInlineSnapshot(` { "coins": [ + { + "id": 0, + "name": "btc", + "value": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", + }, { "id": 60, "name": "eth", - "value": "0x80c5657CEE59A5a193EfDCfDf3D3913Fad977B61", + "value": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", + }, + ], + "contentHash": { + "decoded": "bafybeico3uuyj3vphxpvbowchdwjlrlrh62awxscrnii7w7flu5z6fk77y", + "protocolType": "ipfs", + }, + "resolverAddress": "0x59E16fcCd424Cc24e280Be16E11Bcd56fb0CE547", + "texts": [ + { + "key": "email", + "value": "vitalik@ethereum.org", + }, + { + "key": "description", + "value": "hello offchainresolver record", }, ], - "resolverAddress": "0xDB34Da70Cfd694190742E94B7f17769Bc3d84D27", } `) }) it('should return records from a ccip-read name with custom ccipRequest', async () => { - const goerliWithEns = addEnsContracts(mainnet) - const goerliPublicClientWithCustomCcipRequest = createPublicClient({ - chain: goerliWithEns, - transport: http( - 'https://mainnet.gateway.tenderly.co/4imxc4hQfRjxrVB2kWKvTo', - ), + const holeskyWithEns = addEnsContracts(holesky) + const holeskyPublicClientWithCustomCcipRequest = createPublicClient({ + chain: holeskyWithEns, + transport: http('https://holesky.gateway.tenderly.co'), ccipRead: { - request: ccipRequest(goerliWithEns), + request: ccipRequest(holeskyWithEns), }, }) - const result = await getRecords(goerliPublicClientWithCustomCcipRequest, { - name: 'sg.offchaindemo.eth', - coins: ['60'], - }) - expect(result).toMatchInlineSnapshot(` + const result = await getRecords( + holeskyPublicClientWithCustomCcipRequest, { - "coins": [ - { - "id": 60, - "name": "eth", - "value": "0x80c5657CEE59A5a193EfDCfDf3D3913Fad977B61", - }, - ], - "resolverAddress": "0xDB34Da70Cfd694190742E94B7f17769Bc3d84D27", - } + name: 'offchainexample.eth', + texts: ['email', 'description'], + contentHash: true, + coins: ['btc', '60'], + }, + ) + expect(result).toMatchInlineSnapshot(` + { + "coins": [ + { + "id": 0, + "name": "btc", + "value": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", + }, + { + "id": 60, + "name": "eth", + "value": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", + }, + ], + "contentHash": { + "decoded": "bafybeico3uuyj3vphxpvbowchdwjlrlrh62awxscrnii7w7flu5z6fk77y", + "protocolType": "ipfs", + }, + "resolverAddress": "0x59E16fcCd424Cc24e280Be16E11Bcd56fb0CE547", + "texts": [ + { + "key": "email", + "value": "vitalik@ethereum.org", + }, + { + "key": "description", + "value": "hello offchainresolver record", + }, + ], + } `) }) it('should return records from a ccip-read name with incompliant resolver', async () => { @@ -93,30 +139,32 @@ describe('CCIP', () => { describe('batch', () => { it('allows batch ccip', async () => { const result = await batch( - mainnetPublicClient, - getAddressRecord.batch({ name: 'sg.offchaindemo.eth' }), - getAddressRecord.batch({ name: 'sg.offchaindemo.eth', coin: '60' }), - // getText.batch({ name: '1.offchainexample.eth', key: 'email' }), + holeskyPublicClient, + getAddressRecord.batch({ name: 'offchainexample.eth' }), + getAddressRecord.batch({ name: 'offchainexample.eth', coin: 'btc' }), + getText.batch({ name: 'offchainexample.eth', key: 'email' }), ) + console.log(result) expect(result).toMatchInlineSnapshot(` - [ - { - "id": 60, - "name": "eth", - "value": "0x80c5657CEE59A5a193EfDCfDf3D3913Fad977B61", - }, - { - "id": 60, - "name": "eth", - "value": "0x80c5657CEE59A5a193EfDCfDf3D3913Fad977B61", - }, - ] + [ + { + "id": 60, + "name": "eth", + "value": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", + }, + { + "id": 0, + "name": "btc", + "value": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", + }, + "vitalik@ethereum.org", + ] `) }) it('allows nested batch ccip', async () => { const result = await batch( - mainnetPublicClient, - batch.batch(getAddressRecord.batch({ name: 'sg.offchaindemo.eth' })), + holeskyPublicClient, + batch.batch(getAddressRecord.batch({ name: 'offchainexample.eth' })), ) expect(result).toMatchInlineSnapshot(` [ @@ -124,7 +172,7 @@ describe('CCIP', () => { { "id": 60, "name": "eth", - "value": "0x80c5657CEE59A5a193EfDCfDf3D3913Fad977B61", + "value": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", }, ], ] From c65031508778cde33daa305a2d817391dafebe71 Mon Sep 17 00:00:00 2001 From: sugh01 <19183308+sugh01@users.noreply.github.com> Date: Mon, 27 May 2024 08:02:33 +0200 Subject: [PATCH 2/6] update holesky rpc gateway --- packages/ensjs/src/functions/public/ccip.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ensjs/src/functions/public/ccip.test.ts b/packages/ensjs/src/functions/public/ccip.test.ts index 7a373e22..e1e3fd91 100644 --- a/packages/ensjs/src/functions/public/ccip.test.ts +++ b/packages/ensjs/src/functions/public/ccip.test.ts @@ -19,7 +19,7 @@ const mainnetPublicClient = createPublicClient({ const holeskyPublicClient = createPublicClient({ chain: addEnsContracts(holesky), - transport: http('https://holesky.gateway.tenderly.co'), + transport: http('https://holesky.gateway.tenderly.co/5S00ox7ZN3mdGqaO74UDsg'), }) describe.only('CCIP', () => { From 6895611821bb05feb4fcde6e4edc107671d8d727 Mon Sep 17 00:00:00 2001 From: sugh01 <19183308+sugh01@users.noreply.github.com> Date: Wed, 29 May 2024 07:46:57 +0200 Subject: [PATCH 3/6] fix tests --- packages/ensjs/src/functions/public/ccip.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ensjs/src/functions/public/ccip.test.ts b/packages/ensjs/src/functions/public/ccip.test.ts index e1e3fd91..04641964 100644 --- a/packages/ensjs/src/functions/public/ccip.test.ts +++ b/packages/ensjs/src/functions/public/ccip.test.ts @@ -22,7 +22,7 @@ const holeskyPublicClient = createPublicClient({ transport: http('https://holesky.gateway.tenderly.co/5S00ox7ZN3mdGqaO74UDsg'), }) -describe.only('CCIP', () => { +describe('CCIP', () => { describe('getRecords', () => { it('should return records from a ccip-read name', async () => { const result = await getRecords(holeskyPublicClient, { From 3aa554f935d6eec2bd31f4718e388a00785d42ff Mon Sep 17 00:00:00 2001 From: sugh01 <19183308+sugh01@users.noreply.github.com> Date: Wed, 29 May 2024 08:24:22 +0200 Subject: [PATCH 4/6] fix unit tests --- packages/ensjs/src/functions/public/ccip.test.ts | 3 +-- packages/ensjs/src/utils/ccipBatchRequest.test.ts | 14 +++++++------- packages/ensjs/src/utils/ccipRequest.test.ts | 12 ++++++------ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/ensjs/src/functions/public/ccip.test.ts b/packages/ensjs/src/functions/public/ccip.test.ts index 04641964..f35004ce 100644 --- a/packages/ensjs/src/functions/public/ccip.test.ts +++ b/packages/ensjs/src/functions/public/ccip.test.ts @@ -136,7 +136,7 @@ describe('CCIP', () => { `) }) }) - describe('batch', () => { + describe.only('batch', () => { it('allows batch ccip', async () => { const result = await batch( holeskyPublicClient, @@ -144,7 +144,6 @@ describe('CCIP', () => { getAddressRecord.batch({ name: 'offchainexample.eth', coin: 'btc' }), getText.batch({ name: 'offchainexample.eth', key: 'email' }), ) - console.log(result) expect(result).toMatchInlineSnapshot(` [ { diff --git a/packages/ensjs/src/utils/ccipBatchRequest.test.ts b/packages/ensjs/src/utils/ccipBatchRequest.test.ts index 58c5fb10..f3d93819 100644 --- a/packages/ensjs/src/utils/ccipBatchRequest.test.ts +++ b/packages/ensjs/src/utils/ccipBatchRequest.test.ts @@ -13,7 +13,7 @@ it('returns array of responses', async () => { }) res.end(JSON.stringify({ data: '0xdeadbeef' })) }) - const { close, url } = await createHttpServer(handler) + const { url } = await createHttpServer(handler) const items = [ ['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef01'], ['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef02'], @@ -35,7 +35,7 @@ it('returns array of responses', async () => { ], ] `) - await close() + // await close() }) it('removes duplicate requests', async () => { const handler = vi @@ -47,7 +47,7 @@ it('removes duplicate requests', async () => { }) res.end(JSON.stringify({ data: '0xdeadbeef' })) }) - const { close, url } = await createHttpServer(handler) + const { url } = await createHttpServer(handler) const items = [ ['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef'], ['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef'], @@ -69,7 +69,7 @@ it('removes duplicate requests', async () => { ], ] `) - await close() + // await close() }) it('handles and correctly returns HttpRequestError', async () => { const handler = vi @@ -95,7 +95,7 @@ it('handles and correctly returns HttpRequestError', async () => { `) await close() }) -it('handles and correctly returns misc. error', async () => { +it.only('handles and correctly returns misc. error', async () => { const handler = vi .fn, ReturnType>() .mockImplementation((_, res) => { @@ -105,7 +105,7 @@ it('handles and correctly returns misc. error', async () => { }) res.end('invalid json') }) - const { close, url } = await createHttpServer(handler) + const { url } = await createHttpServer(handler) const items = [ ['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef'], ] as const @@ -120,5 +120,5 @@ it('handles and correctly returns misc. error', async () => { ], ] `) - await close() + // await close() }) diff --git a/packages/ensjs/src/utils/ccipRequest.test.ts b/packages/ensjs/src/utils/ccipRequest.test.ts index fdf978dc..5c26785e 100644 --- a/packages/ensjs/src/utils/ccipRequest.test.ts +++ b/packages/ensjs/src/utils/ccipRequest.test.ts @@ -18,7 +18,7 @@ const handler = vi }) it('uses viemCcipRequest for standard request', async () => { - const { close, url } = await createHttpServer(handler) + const { url } = await createHttpServer(handler) const chain = addEnsContracts(mainnet) const result = await ccipRequest(chain)({ sender: '0x8464135c8F25Da09e49BC8782676a84730C318bC', @@ -27,10 +27,10 @@ it('uses viemCcipRequest for standard request', async () => { }) expect(handler).toHaveBeenCalled() expect(result).toEqual('0xdeadbeef') - await close() + // await close() }) it('uses viemCcipRequest for universalresolver request that is not matching signature', async () => { - const { close, url } = await createHttpServer(handler) + const { url } = await createHttpServer(handler) const chain = addEnsContracts(mainnet) const result = await ccipRequest(chain)({ sender: getChainContractAddress({ @@ -42,13 +42,13 @@ it('uses viemCcipRequest for universalresolver request that is not matching sign }) expect(handler).toHaveBeenCalled() expect(result).toEqual('0xdeadbeef') - await close() + // await close() }) it('uses ccipBatchRequest for universalresolver request that is matching signature', async () => { const abi = parseAbi([ 'function query((address,string[],bytes)[]) returns (bool[],bytes[])', ]) - const { close, url } = await createHttpServer(handler) + const { url } = await createHttpServer(handler) const chain = addEnsContracts(mainnet) const data = encodeFunctionData({ abi, @@ -68,5 +68,5 @@ it('uses ccipBatchRequest for universalresolver request that is matching signatu expect(result).toMatchInlineSnapshot( `"0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000"`, ) - await close() + // await close() }) From c51a147eb6ab7c1181a6d20b6494a504e9841f18 Mon Sep 17 00:00:00 2001 From: sugh01 <19183308+sugh01@users.noreply.github.com> Date: Wed, 29 May 2024 09:01:29 +0200 Subject: [PATCH 5/6] fix tests --- packages/ensjs/src/functions/public/ccip.test.ts | 2 +- packages/ensjs/src/utils/ccipBatchRequest.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ensjs/src/functions/public/ccip.test.ts b/packages/ensjs/src/functions/public/ccip.test.ts index f35004ce..7408cf4d 100644 --- a/packages/ensjs/src/functions/public/ccip.test.ts +++ b/packages/ensjs/src/functions/public/ccip.test.ts @@ -136,7 +136,7 @@ describe('CCIP', () => { `) }) }) - describe.only('batch', () => { + describe('batch', () => { it('allows batch ccip', async () => { const result = await batch( holeskyPublicClient, diff --git a/packages/ensjs/src/utils/ccipBatchRequest.test.ts b/packages/ensjs/src/utils/ccipBatchRequest.test.ts index f3d93819..029e73f8 100644 --- a/packages/ensjs/src/utils/ccipBatchRequest.test.ts +++ b/packages/ensjs/src/utils/ccipBatchRequest.test.ts @@ -93,9 +93,9 @@ it('handles and correctly returns HttpRequestError', async () => { ], ] `) - await close() + // await close() }) -it.only('handles and correctly returns misc. error', async () => { +it('handles and correctly returns misc. error', async () => { const handler = vi .fn, ReturnType>() .mockImplementation((_, res) => { From 5a8f44797ae1d9605c0c043e97b97c7fecac71d3 Mon Sep 17 00:00:00 2001 From: sugh01 <19183308+sugh01@users.noreply.github.com> Date: Wed, 29 May 2024 09:06:09 +0200 Subject: [PATCH 6/6] lint fix --- packages/ensjs/src/utils/ccipBatchRequest.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ensjs/src/utils/ccipBatchRequest.test.ts b/packages/ensjs/src/utils/ccipBatchRequest.test.ts index 029e73f8..712f4de7 100644 --- a/packages/ensjs/src/utils/ccipBatchRequest.test.ts +++ b/packages/ensjs/src/utils/ccipBatchRequest.test.ts @@ -78,7 +78,7 @@ it('handles and correctly returns HttpRequestError', async () => { res.writeHead(404) res.end() }) - const { close, url } = await createHttpServer(handler) + const { url } = await createHttpServer(handler) const items = [ ['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef'], ] as const