-
Notifications
You must be signed in to change notification settings - Fork 57
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 #162 from 1inch/feature/increase-coverage
[SC-1321] Increase coverage
- Loading branch information
Showing
11 changed files
with
265 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
// solhint-disable one-contract-per-file | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "../../libraries/RevertReasonForwarder.sol"; | ||
|
||
contract RevertReasonForwarderHelper { | ||
error RevertReason(); | ||
|
||
function revertWithReason() external pure { | ||
revert RevertReason(); | ||
} | ||
} | ||
|
||
contract RevertReasonForwarderMock { | ||
address payable private _helper; | ||
|
||
constructor(address helper) { | ||
_helper = payable(helper); | ||
} | ||
|
||
function reRevert() external payable { | ||
// solhint-disable-next-line avoid-low-level-calls | ||
(bool success, ) = _helper.call{value: msg.value}( | ||
abi.encodeWithSignature("revertWithReason()") | ||
); | ||
if (!success) { | ||
RevertReasonForwarder.reRevert(); | ||
} | ||
} | ||
|
||
function reReason() external payable returns (bytes memory) { | ||
// solhint-disable-next-line avoid-low-level-calls | ||
(bool success, ) = _helper.call{value: msg.value}( | ||
abi.encodeWithSignature("revertWithReason()") | ||
); | ||
if (!success) { | ||
return RevertReasonForwarder.reReason(); | ||
} | ||
return ""; | ||
} | ||
} |
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,30 @@ | ||
import { expect } from '../../src/expect'; | ||
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; | ||
import { ethers } from 'hardhat'; | ||
import { | ||
RevertReasonForwarderHelper__factory as RevertReasonForwarderHelper, | ||
RevertReasonForwarderMock__factory as RevertReasonForwarderMock, | ||
} from '../../typechain-types'; | ||
|
||
describe('RevertReasonForwarder', function () { | ||
let Helper: RevertReasonForwarderHelper; | ||
let RevertReasonForwarderMock: RevertReasonForwarderMock; | ||
|
||
async function deployRevertReasonForwarderMock() { | ||
RevertReasonForwarderMock = await ethers.getContractFactory('RevertReasonForwarderMock'); | ||
Helper = await ethers.getContractFactory('RevertReasonForwarderHelper'); | ||
const helper = await Helper.deploy(); | ||
const mock = await RevertReasonForwarderMock.deploy(helper); | ||
return { helper, mock }; | ||
} | ||
|
||
it('should forward custom error from the helper contract using reRevert', async function () { | ||
const { helper, mock } = await loadFixture(deployRevertReasonForwarderMock); | ||
await expect(mock.reRevert()).to.be.revertedWithCustomError(helper, 'RevertReason'); | ||
}); | ||
|
||
it('should return custom error from the helper contract using reReason', async function () { | ||
const { mock } = await loadFixture(deployRevertReasonForwarderMock); | ||
expect(await mock.reReason.staticCall()).to.be.equal(ethers.id('RevertReason()').substring(0, 10)); | ||
}); | ||
}); |
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