Skip to content

Commit

Permalink
fix: propagate httperror on single resolve correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Jan 3, 2024
1 parent 668bfcb commit 00c31e8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
9 changes: 4 additions & 5 deletions contracts/utils/UniversalResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,10 @@ contract UniversalResolver is ERC165, Ownable {
function _checkResolveSingle(Result memory result) internal pure {
if (!result.success) {
if (bytes4(result.returnData) == HttpError.selector) {
(, HttpErrorItem[] memory errors) = abi.decode(
result.returnData,
(bytes4, HttpErrorItem[])
);
revert HttpError(errors);
bytes memory returnData = result.returnData;
assembly {
revert(add(returnData, 32), mload(returnData))
}
}
revert ResolverError(result.returnData);
}
Expand Down
39 changes: 39 additions & 0 deletions test/utils/TestUniversalResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,45 @@ contract('UniversalResolver', function (accounts) {
)
expect(addrRet).to.equal(dummyOffchainResolver.address)
})
it('should propagate HttpError', async () => {
const urWithHttpErrorAbi = new ethers.Contract(
universalResolver.address,
[
...universalResolver.interface.fragments,
'error HttpError((uint16,string)[])',
],
ethers.provider,
)
const errorData = urWithHttpErrorAbi.interface.encodeErrorResult(
'HttpError',
[[[404, 'Not Found']]],
)
const extraData = ethers.utils.defaultAbiCoder.encode(
['bool', 'address', 'string[]', 'bytes', '(bytes4,bytes)[]'],
[
false,
dummyOffchainResolver.address,
['http://universal-offchain-resolver.local/'],
'0x',
[[resolveCallbackSig, errorData]],
],
)
const responses = batchGateway.encodeFunctionResult('query', [
[true],
[errorData],
])

try {
await urWithHttpErrorAbi.callStatic.resolveSingleCallback(
responses,
extraData,
)
expect(false).to.be.true
} catch (e) {
expect(e.errorName).to.equal('HttpError')
expect(e.errorArgs).to.deep.equal([[[404, 'Not Found']]])
}
})
})
describe('resolveCallback', () => {
it('should resolve records via a callback from offchain lookup', async () => {
Expand Down

0 comments on commit 00c31e8

Please sign in to comment.