Skip to content

Commit

Permalink
test: use openeppelin's custom errors in cheatcode
Browse files Browse the repository at this point in the history
  • Loading branch information
andreivladbrg committed Oct 9, 2023
1 parent bd8d4ab commit e5c49d1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract FlashLoanFunction_Integration_Concrete_Test is FlashLoanFunction_Integr
{
uint256 amount = 100e18;
deal({ token: address(dai), to: address(flashLoan), give: amount * 2 });
vm.expectRevert("ERC20: transfer amount exceeds balance");
vm.expectRevert();
flashLoan.flashLoan({
receiver: reentrantFlashLoanReceiver,
asset: address(dai),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19 <0.9.0;

import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { IERC721Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { UD60x18, ud, ZERO } from "@prb/math/src/UD60x18.sol";
import { stdError } from "forge-std/StdError.sol";
Expand Down Expand Up @@ -33,8 +35,8 @@ contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is
}

function test_RevertWhen_RecipientZeroAddress() external whenNotDelegateCalled {
vm.expectRevert("ERC721: mint to the zero address");
address recipient = address(0);
vm.expectRevert(abi.encodeWithSelector(IERC721Errors.ERC721InvalidReceiver.selector, recipient));
createDefaultStreamWithRecipient(recipient);
}

Expand Down Expand Up @@ -295,7 +297,7 @@ contract CreateWithMilestones_LockupDynamic_Integration_Concrete_Test is
changePrank({ msgSender: users.sender });

// Run the test.
vm.expectRevert("Address: call to non-contract");
vm.expectRevert(abi.encodeWithSelector(Address.AddressEmptyCode.selector, nonContract));
createDefaultStreamWithAsset(IERC20(nonContract));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// solhint-disable max-line-length,no-console,quotes
pragma solidity >=0.8.19 <0.9.0;

import { IERC721Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import { console2 } from "forge-std/console2.sol";
import { LibString } from "solady/utils/LibString.sol";
import { StdStyle } from "forge-std/StdStyle.sol";
import { LibString } from "solady/utils/LibString.sol";
import { Base64 } from "solady/utils/Base64.sol";

import { LockupDynamic_Integration_Concrete_Test } from "../LockupDynamic.t.sol";
Expand Down Expand Up @@ -33,7 +34,7 @@ contract TokenURI_LockupDynamic_Integration_Concrete_Test is LockupDynamic_Integ

function test_RevertGiven_NFTDoesNotExist() external {
uint256 nullStreamId = 1729;
vm.expectRevert("ERC721: invalid token ID");
vm.expectRevert(abi.encodeWithSelector(IERC721Errors.ERC721NonexistentToken.selector, nullStreamId));
lockupDynamic.tokenURI({ tokenId: nullStreamId });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19 <0.9.0;

import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { IERC721Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { UD60x18, ud } from "@prb/math/src/UD60x18.sol";

Expand Down Expand Up @@ -31,7 +33,8 @@ contract CreateWithRange_LockupLinear_Integration_Concrete_Test is
}

function test_RevertWhen_RecipientZeroAddress() external whenNotDelegateCalled {
vm.expectRevert("ERC721: mint to the zero address");
address recipient = address(0);
vm.expectRevert(abi.encodeWithSelector(IERC721Errors.ERC721InvalidReceiver.selector, recipient));
createDefaultStreamWithRecipient({ recipient: address(0) });
}

Expand Down Expand Up @@ -142,7 +145,7 @@ contract CreateWithRange_LockupLinear_Integration_Concrete_Test is
whenBrokerFeeNotTooHigh
{
address nonContract = address(8128);
vm.expectRevert("Address: call to non-contract");
vm.expectRevert(abi.encodeWithSelector(Address.AddressEmptyCode.selector, nonContract));
createDefaultStreamWithAsset(IERC20(nonContract));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// solhint-disable max-line-length,no-console,quotes
pragma solidity >=0.8.19 <0.9.0;

import { IERC721Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import { console2 } from "forge-std/console2.sol";
import { LibString } from "solady/utils/LibString.sol";
import { StdStyle } from "forge-std/StdStyle.sol";
import { LibString } from "solady/utils/LibString.sol";
import { Base64 } from "solady/utils/Base64.sol";

import { LockupLinear_Integration_Concrete_Test } from "../LockupLinear.t.sol";
Expand Down Expand Up @@ -33,7 +34,7 @@ contract TokenURI_LockupLinear_Integration_Concrete_Test is LockupLinear_Integra

function test_RevertGiven_NFTDoesNotExist() external {
uint256 nullStreamId = 1729;
vm.expectRevert("ERC721: invalid token ID");
vm.expectRevert(abi.encodeWithSelector(IERC721Errors.ERC721NonexistentToken.selector, nullStreamId));
lockupLinear.tokenURI({ tokenId: nullStreamId });
}

Expand Down
10 changes: 6 additions & 4 deletions test/integration/concrete/lockup/burn/burn.t.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19 <0.9.0;

import { IERC721Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";

import { ISablierV2Lockup } from "src/interfaces/ISablierV2Lockup.sol";
import { Errors } from "src/libraries/Errors.sol";

Expand Down Expand Up @@ -120,7 +122,7 @@ abstract contract Burn_Integration_Concrete_Test is Integration_Test, Lockup_Int
lockup.burn(streamId);

// Run the test.
vm.expectRevert("ERC721: invalid token ID");
vm.expectRevert(abi.encodeWithSelector(IERC721Errors.ERC721NonexistentToken.selector, streamId));
lockup.burn(streamId);
}

Expand All @@ -140,7 +142,7 @@ abstract contract Burn_Integration_Concrete_Test is Integration_Test, Lockup_Int
vm.expectEmit({ emitter: address(lockup) });
emit MetadataUpdate({ _tokenId: notTransferableStreamId });
lockup.burn(notTransferableStreamId);
vm.expectRevert("ERC721: invalid token ID");
vm.expectRevert(abi.encodeWithSelector(IERC721Errors.ERC721NonexistentToken.selector, notTransferableStreamId));
lockup.getRecipient(notTransferableStreamId);
}

Expand Down Expand Up @@ -171,7 +173,7 @@ abstract contract Burn_Integration_Concrete_Test is Integration_Test, Lockup_Int
lockup.burn(streamId);

// Assert that the NFT has been burned.
vm.expectRevert("ERC721: invalid token ID");
vm.expectRevert(abi.encodeWithSelector(IERC721Errors.ERC721NonexistentToken.selector, streamId));
lockup.getRecipient(streamId);
}

Expand All @@ -188,7 +190,7 @@ abstract contract Burn_Integration_Concrete_Test is Integration_Test, Lockup_Int
vm.expectEmit({ emitter: address(lockup) });
emit MetadataUpdate({ _tokenId: streamId });
lockup.burn(streamId);
vm.expectRevert("ERC721: invalid token ID");
vm.expectRevert(abi.encodeWithSelector(IERC721Errors.ERC721NonexistentToken.selector, streamId));
lockup.getRecipient(streamId);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19 <0.9.0;

import { IERC721Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";

import { Lockup_Integration_Shared_Test } from "../../../shared/lockup/Lockup.t.sol";
import { Integration_Test } from "../../../Integration.t.sol";

Expand All @@ -13,7 +15,7 @@ abstract contract GetRecipient_Integration_Concrete_Test is Integration_Test, Lo

function test_RevertGiven_Null() external {
uint256 nullStreamId = 1729;
vm.expectRevert("ERC721: invalid token ID");
vm.expectRevert(abi.encodeWithSelector(IERC721Errors.ERC721NonexistentToken.selector, nullStreamId));
lockup.getRecipient(nullStreamId);
}

Expand All @@ -35,7 +37,7 @@ abstract contract GetRecipient_Integration_Concrete_Test is Integration_Test, Lo
lockup.burn(defaultStreamId);

// Expect the relevant error when retrieving the recipient.
vm.expectRevert("ERC721: invalid token ID");
vm.expectRevert(abi.encodeWithSelector(IERC721Errors.ERC721NonexistentToken.selector, defaultStreamId));
lockup.getRecipient(defaultStreamId);
}

Expand Down

0 comments on commit e5c49d1

Please sign in to comment.