Skip to content

Commit

Permalink
pass through revert reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Mar 15, 2021
1 parent 8de6ad6 commit 8b4c6bb
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
11 changes: 10 additions & 1 deletion contracts/base/Multicall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ abstract contract Multicall is IMulticall {
results = new bytes[](data.length);
for (uint256 i = 0; i < data.length; i++) {
(bool success, bytes memory result) = address(this).delegatecall(data[i]);
require(success);

if (!success) {
// Next 5 lines from https://ethereum.stackexchange.com/a/83577
if (result.length < 68) revert();
assembly {
result := add(result, 0x04)
}
revert(abi.decode(result, (string)));
}

results[i] = result;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/Multicall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Multicall', async () => {
multicall = (await multicallTestFactory.deploy()) as TestMulticall
})

it.skip('revert messages are returned', async () => {
it('revert messages are returned', async () => {
await expect(
multicall.multicall([multicall.interface.encodeFunctionData('functionThatRevertsWithError', ['abcdef'])])
).to.be.revertedWith('abcdef')
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/Multicall.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Multicall gas cost of pay w/ multicall 1`] = `45094`;
exports[`Multicall gas cost of pay w/ multicall 1`] = `45145`;

exports[`Multicall gas cost of pay w/o multicall 1`] = `42042`;
2 changes: 1 addition & 1 deletion test/__snapshots__/NonfungiblePositionManager.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ exports[`NonfungiblePositionManager #transferFrom gas 1`] = `84209`;

exports[`NonfungiblePositionManager #transferFrom gas comes from approved 1`] = `75409`;

exports[`NonfungiblePositionManager bytecode size 1`] = `23230`;
exports[`NonfungiblePositionManager bytecode size 1`] = `23291`;

exports[`NonfungiblePositionManager multicall exit gas 1`] = `175723`;
16 changes: 8 additions & 8 deletions test/__snapshots__/SwapRouter.gas.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SwapRouter gas tests #exactInput 0 -> 1 -> 2 1`] = `213875`;
exports[`SwapRouter gas tests #exactInput 0 -> 1 -> 2 1`] = `214045`;

exports[`SwapRouter gas tests #exactInput 0 -> 1 1`] = `111436`;
exports[`SwapRouter gas tests #exactInput 0 -> 1 1`] = `111552`;

exports[`SwapRouter gas tests #exactInput 0 -> 1 minimal 1`] = `105152`;

exports[`SwapRouter gas tests #exactInput 0 -> WETH9 1`] = `138263`;
exports[`SwapRouter gas tests #exactInput 0 -> WETH9 1`] = `138469`;

exports[`SwapRouter gas tests #exactInput WETH9 -> 0 1`] = `111342`;
exports[`SwapRouter gas tests #exactInput WETH9 -> 0 1`] = `111458`;

exports[`SwapRouter gas tests #exactOutput 0 -> 1 -> 2 1`] = `178065`;
exports[`SwapRouter gas tests #exactOutput 0 -> 1 -> 2 1`] = `178188`;

exports[`SwapRouter gas tests #exactOutput 0 -> 1 1`] = `115990`;
exports[`SwapRouter gas tests #exactOutput 0 -> 1 1`] = `116083`;

exports[`SwapRouter gas tests #exactOutput 0 -> WETH9 1`] = `139555`;
exports[`SwapRouter gas tests #exactOutput 0 -> WETH9 1`] = `139699`;

exports[`SwapRouter gas tests #exactOutput WETH9 -> 0 1`] = `143637`;
exports[`SwapRouter gas tests #exactOutput WETH9 -> 0 1`] = `143781`;
2 changes: 1 addition & 1 deletion test/__snapshots__/SwapRouter.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SwapRouter bytecode size 1`] = `9239`;
exports[`SwapRouter bytecode size 1`] = `9498`;

0 comments on commit 8b4c6bb

Please sign in to comment.