Skip to content

Commit

Permalink
Merge pull request #178 from ensdomains/feat/local-ur-unwrap
Browse files Browse the repository at this point in the history
feat: local ur unwrap
  • Loading branch information
TateB authored Apr 10, 2024
2 parents 1d41e4c + 01ec35c commit 0de940c
Show file tree
Hide file tree
Showing 20 changed files with 409 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/ensjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@
"typedoc": "^0.24.8",
"typedoc-plugin-markdown": "^4.0.0-next.16",
"typescript": "5.3.2",
"viem": "^2.5.0",
"viem": "^2.9.2",
"vitest": "^1.3.1",
"wait-on": "^6.0.1"
},
"peerDependencies": {
"viem": "^2.5.0"
"viem": "^2.9.2"
}
}
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/_getAbi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ it('propagates error when strict is true', async () => {
Params: (uint256, bytes)
Data: 0x1234 (2 bytes)
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/_getAddr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ it('propagates error when strict is true', async () => {
Params: (address)
Data: 0x1234 (2 bytes)
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ it('propagates error when strict is true', async () => {
Params: (bytes)
Data: 0x1234 (2 bytes)
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/_getText.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ it('propagates error when strict is true', async () => {
Params: (string)
Data: 0x1234 (2 bytes)
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})
50 changes: 50 additions & 0 deletions packages/ensjs/src/functions/public/ccip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createPublicClient, http } from 'viem'
import { goerli, 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'
Expand Down Expand Up @@ -62,6 +63,55 @@ describe('CCIP', () => {
}
`)
})
it('should return records from a ccip-read name with custom ccipRequest', async () => {
const goerliWithEns = addEnsContracts(goerli)
const goerliPublicClientWithCustomCcipRequest = createPublicClient({
chain: goerliWithEns,
transport: http(
'https://goerli.gateway.tenderly.co/4imxc4hQfRjxrVB2kWKvTo',
),
ccipRead: {
request: ccipRequest(goerliWithEns),
},
})
const result = await getRecords(goerliPublicClientWithCustomCcipRequest, {
name: '1.offchainexample.eth',
texts: ['email', 'description'],
contentHash: true,
coins: ['ltc', '60'],
})
expect(result).toMatchInlineSnapshot(`
{
"coins": [
{
"id": 2,
"name": "ltc",
"value": "MQMcJhpWHYVeQArcZR3sBgyPZxxRtnH441",
},
{
"id": 60,
"name": "eth",
"value": "0x41563129cDbbD0c5D3e1c86cf9563926b243834d",
},
],
"contentHash": {
"decoded": "bafybeico3uuyj3vphxpvbowchdwjlrlrh62awxscrnii7w7flu5z6fk77y",
"protocolType": "ipfs",
},
"resolverAddress": "0xEE28bdfBB91dE63bfBDA454082Bb1850f7804B09",
"texts": [
{
"key": "email",
"value": "[email protected]",
},
{
"key": "description",
"value": "hello offchainresolver wildcard record",
},
],
}
`)
})
it('should return records from a ccip-read name with incompliant resolver', async () => {
const result = await getRecords(mainnetPublicClient, {
name: 'alisha.beam.eco',
Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/getAbiRecord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('getAbiRecord()', () => {
function: resolve(bytes name, bytes data)
args: (0x, 0x)
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('getAddressRecord()', () => {
function: resolve(bytes name, bytes data)
args: (0x, 0x)
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('getContentHashRecord', () => {
function: resolve(bytes name, bytes data)
args: (0x, 0x)
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})
})
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/getName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('getName', () => {
function: reverse(bytes reverseName)
args: (0x)
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})
it('should not return unnormalised name', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/getRecords.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('getRecords()', () => {
args: (0x04746573740365746800, ["0x5678"])
Docs: https://viem.sh/docs/contract/decodeErrorResult
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})
})
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/getTextRecord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('getTextRecord()', () => {
function: resolve(bytes name, bytes data)
args: (0x, 0x)
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})
})
8 changes: 4 additions & 4 deletions packages/ensjs/src/functions/public/universalWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ it('throws on result decode error when strict is true', async () => {
Params: (bytes data, address resolver)
Data: 0x1234 (2 bytes)
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})

Expand Down Expand Up @@ -116,7 +116,7 @@ it('throws on known contract error when strict is true', async () => {
function: resolve(bytes name, bytes data)
args: (0x, 0x)
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})

Expand Down Expand Up @@ -147,7 +147,7 @@ it('throws on unknown contract error when strict is false', async () => {
args: (0x, 0x)
Docs: https://viem.sh/docs/contract/decodeErrorResult
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})

Expand Down Expand Up @@ -178,6 +178,6 @@ it('throws on unknown contract error when strict is true', async () => {
args: (0x, 0x)
Docs: https://viem.sh/docs/contract/decodeErrorResult
Version: viem@2.5.0]
Version: viem@2.9.2]
`)
})
124 changes: 124 additions & 0 deletions packages/ensjs/src/utils/ccipBatchRequest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import type { RequestListener } from 'http'
import { expect, it, vi } from 'vitest'
import { createHttpServer } from '../test/createHttpServer.js'
import { ccipBatchRequest } from './ccipBatchRequest.js'

it('returns array of responses', async () => {
const handler = vi
.fn<Parameters<RequestListener>, ReturnType<RequestListener>>()
.mockImplementation((_, res) => {
res.writeHead(200, {
// eslint-disable-next-line @typescript-eslint/naming-convention
'Content-Type': 'application/json',
})
res.end(JSON.stringify({ data: '0xdeadbeef' }))
})
const { close, url } = await createHttpServer(handler)
const items = [
['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef01'],
['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef02'],
['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef03'],
] as const
const result = await ccipBatchRequest(items)
expect(handler).toHaveBeenCalledTimes(3)
expect(result).toMatchInlineSnapshot(`
[
[
false,
false,
false,
],
[
"0xdeadbeef",
"0xdeadbeef",
"0xdeadbeef",
],
]
`)
await close()
})
it('removes duplicate requests', async () => {
const handler = vi
.fn<Parameters<RequestListener>, ReturnType<RequestListener>>()
.mockImplementation((_, res) => {
res.writeHead(200, {
// eslint-disable-next-line @typescript-eslint/naming-convention
'Content-Type': 'application/json',
})
res.end(JSON.stringify({ data: '0xdeadbeef' }))
})
const { close, url } = await createHttpServer(handler)
const items = [
['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef'],
['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef'],
['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef'],
] as const
const result = await ccipBatchRequest(items)
expect(handler).toHaveBeenCalledTimes(1)
expect(result).toMatchInlineSnapshot(`
[
[
false,
false,
false,
],
[
"0xdeadbeef",
"0xdeadbeef",
"0xdeadbeef",
],
]
`)
await close()
})
it('handles and correctly returns HttpRequestError', async () => {
const handler = vi
.fn<Parameters<RequestListener>, ReturnType<RequestListener>>()
.mockImplementation((_, res) => {
res.writeHead(404)
res.end()
})
const { close, url } = await createHttpServer(handler)
const items = [
['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef'],
] as const
const result = await ccipBatchRequest(items)
expect(result).toMatchInlineSnapshot(`
[
[
true,
],
[
"0xca7a4e750000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000194000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000094e6f7420466f756e640000000000000000000000000000000000000000000000",
],
]
`)
await close()
})
it('handles and correctly returns misc. error', async () => {
const handler = vi
.fn<Parameters<RequestListener>, ReturnType<RequestListener>>()
.mockImplementation((_, res) => {
res.writeHead(200, {
// eslint-disable-next-line @typescript-eslint/naming-convention
'Content-Type': 'application/json',
})
res.end('invalid json')
})
const { close, url } = await createHttpServer(handler)
const items = [
['0x8464135c8F25Da09e49BC8782676a84730C318bC', [url], '0xdeadbeef'],
] as const
const result = await ccipBatchRequest(items)
expect(result).toMatchInlineSnapshot(`
[
[
true,
],
[
"0xca7a4e7500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001f400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000028556e657870656374656420746f6b656e206920696e204a534f4e20617420706f736974696f6e2030000000000000000000000000000000000000000000000000",
],
]
`)
await close()
})
Loading

0 comments on commit 0de940c

Please sign in to comment.