-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
114 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { createPublicClient, http } from 'viem' | ||
import { RawContractError, createPublicClient, http } from 'viem' | ||
import { mainnet } from 'viem/chains' | ||
import { addEnsContracts } from '../../index.js' | ||
import { | ||
|
@@ -98,4 +98,50 @@ describe('getRecords()', () => { | |
} | ||
`) | ||
}) | ||
|
||
it('returns null results when known resolver error', async () => { | ||
await expect( | ||
getRecords.decode( | ||
publicClient, | ||
new RawContractError({ | ||
data: '0x7199966d', // ResolverNotFound() | ||
}), | ||
[{ type: 'coin', key: 60, call: { to: '0x1234', data: '0x5678' } }], | ||
{ name: 'test.eth' }, | ||
), | ||
).resolves.toMatchInlineSnapshot(` | ||
{ | ||
"coins": [], | ||
"resolverAddress": "0x0000000000000000000000000000000000000000", | ||
} | ||
`) | ||
}) | ||
|
||
it('throws when unknown resolver error', async () => { | ||
await expect( | ||
getRecords.decode( | ||
publicClient, | ||
new RawContractError({ | ||
data: '0x4ced43fb', // SwagError() | ||
}), | ||
[{ type: 'coin', key: 60, call: { to: '0x1234', data: '0x5678' } }], | ||
{ name: 'test.eth' }, | ||
), | ||
).rejects.toThrowErrorMatchingInlineSnapshot(` | ||
"The contract function "resolve" reverted with the following signature: | ||
0x4ced43fb | ||
Unable to decode signature "0x4ced43fb" as it was not found on the provided ABI. | ||
Make sure you are using the correct ABI and that the error exists on it. | ||
You can look up the decoded signature here: https://openchain.xyz/signatures?query=0x4ced43fb. | ||
Contract Call: | ||
address: ${deploymentAddresses.UniversalResolver} | ||
function: resolve(bytes name, bytes[] data) | ||
args: (0x04746573740365746800, ["0x5678"]) | ||
Docs: https://viem.sh/docs/contract/decodeErrorResult.html | ||
Version: [email protected]" | ||
`) | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -72,6 +72,34 @@ describe('checkSafeUniversalResolverData', () => { | |
`) | ||
}) | ||
|
||
it('throws error with args as a function', () => { | ||
expect(() => { | ||
checkSafeUniversalResolverData( | ||
new RawContractError({ | ||
data: '0x7199966d', // ResolverNotFound() | ||
}), | ||
{ | ||
strict: true, | ||
abi: universalResolverResolveSnippet, | ||
args: () => ['ab', 'cd'], | ||
functionName: 'resolve', | ||
address: '0x1234567890abcdef', | ||
}, | ||
) | ||
}).toThrowErrorMatchingInlineSnapshot(` | ||
"The contract function "resolve" reverted. | ||
Error: ResolverNotFound() | ||
Contract Call: | ||
address: 0x1234567890abcdef | ||
function: resolve(bytes name, bytes data) | ||
args: (ab, cd) | ||
Version: [email protected]" | ||
`) | ||
}) | ||
|
||
it('throws error when the data is an unknown error and strict is false', () => { | ||
expect(() => { | ||
checkSafeUniversalResolverData( | ||
|
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