-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from ensdomains/feat/local-ur-unwrap
feat: local ur unwrap
- Loading branch information
Showing
20 changed files
with
409 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
|
@@ -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', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) |
Oops, something went wrong.