Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update chai matchers #4899

Merged
merged 8 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions contracts/utils/Panic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ library Panic {
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
ernestognw marked this conversation as resolved.
Show resolved Hide resolved
uint256 internal constant UNDER_OVERFLOW = 0x11;
uint256 internal constant OVERFLOW = 0x11;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that overflow is a better name, and hardhat was right to change it, but this file is supposed to follow https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h

/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
Expand All @@ -47,9 +47,9 @@ library Panic {
function panic(uint256 code) internal pure {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, shl(0xe0, 0x4e487b71))
mstore(0x04, code)
revert(0x00, 0x24)
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
Comment on lines -50 to +52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool

}
}
}
2 changes: 1 addition & 1 deletion contracts/utils/math/Math.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ library Math {

// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
Panic.panic(denominator == 0 ? Panic.DIVISION_BY_ZERO : Panic.UNDER_OVERFLOW);
Panic.panic(denominator == 0 ? Panic.DIVISION_BY_ZERO : Panic.OVERFLOW);
}

///////////////////////////////////////////////
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@changesets/cli": "^2.26.0",
"@changesets/pre": "^2.0.0",
"@changesets/read": "^0.6.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.3",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.6",
"@nomicfoundation/hardhat-ethers": "^3.0.4",
"@nomicfoundation/hardhat-network-helpers": "^1.0.3",
"@openzeppelin/docs-utils": "^0.1.5",
Expand Down
2 changes: 1 addition & 1 deletion test/utils/Panic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Panic', function () {
for (const [name, code] of Object.entries({
GENERIC: 0x0,
ASSERT: PANIC_CODES.ASSERTION_ERROR,
UNDER_OVERFLOW: PANIC_CODES.ARITHMETIC_UNDER_OR_OVERFLOW,
OVERFLOW: PANIC_CODES.ARITHMETIC_OVERFLOW,
DIVISION_BY_ZERO: PANIC_CODES.DIVISION_BY_ZERO,
ENUM_CONVERSION_ERROR: PANIC_CODES.ENUM_CONVERSION_OUT_OF_BOUNDS,
STORAGE_ENCODING_ERROR: PANIC_CODES.INCORRECTLY_ENCODED_STORAGE_BYTE_ARRAY,
Expand Down
Loading