Skip to content

Commit

Permalink
Merge pull request #183 from ensdomains/holeskyOffchainResolver
Browse files Browse the repository at this point in the history
update ccip tests with holesky offchain resolver
  • Loading branch information
LeonmanRolls authored May 29, 2024
2 parents f928da9 + 5a8f447 commit c42dc04
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 63 deletions.
145 changes: 96 additions & 49 deletions packages/ensjs/src/functions/public/ccip.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,54 +17,100 @@ const mainnetPublicClient = createPublicClient({
transport: http('https://mainnet.gateway.tenderly.co/4imxc4hQfRjxrVB2kWKvTo'),
})

const holeskyPublicClient = createPublicClient({
chain: addEnsContracts(holesky),
transport: http('https://holesky.gateway.tenderly.co/5S00ox7ZN3mdGqaO74UDsg'),
})

describe('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": "[email protected]",
},
{
"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": "[email protected]",
},
{
"key": "description",
"value": "hello offchainresolver record",
},
],
}
`)
})
it('should return records from a ccip-read name with incompliant resolver', async () => {
Expand Down Expand Up @@ -93,38 +139,39 @@ 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' }),
)
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",
},
"[email protected]",
]
`)
})
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(`
[
[
{
"id": 60,
"name": "eth",
"value": "0x80c5657CEE59A5a193EfDCfDf3D3913Fad977B61",
"value": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
},
],
]
Expand Down
16 changes: 8 additions & 8 deletions packages/ensjs/src/utils/ccipBatchRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -35,7 +35,7 @@ it('returns array of responses', async () => {
],
]
`)
await close()
// await close()
})
it('removes duplicate requests', async () => {
const handler = vi
Expand All @@ -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'],
Expand All @@ -69,7 +69,7 @@ it('removes duplicate requests', async () => {
],
]
`)
await close()
// await close()
})
it('handles and correctly returns HttpRequestError', async () => {
const handler = vi
Expand All @@ -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
Expand All @@ -93,7 +93,7 @@ it('handles and correctly returns HttpRequestError', async () => {
],
]
`)
await close()
// await close()
})
it('handles and correctly returns misc. error', async () => {
const handler = vi
Expand All @@ -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
Expand All @@ -120,5 +120,5 @@ it('handles and correctly returns misc. error', async () => {
],
]
`)
await close()
// await close()
})
12 changes: 6 additions & 6 deletions packages/ensjs/src/utils/ccipRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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({
Expand All @@ -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,
Expand All @@ -68,5 +68,5 @@ it('uses ccipBatchRequest for universalresolver request that is matching signatu
expect(result).toMatchInlineSnapshot(
`"0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000"`,
)
await close()
// await close()
})

0 comments on commit c42dc04

Please sign in to comment.