Skip to content

Commit

Permalink
comment update
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Oct 11, 2024
1 parent 43f0dc1 commit 7b7c1fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
22 changes: 9 additions & 13 deletions contracts/utils/Strings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ library Strings {
/**
* @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.
*
* Requirements:
* - The result must fit into an `uint256` type.
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {
return tryParseUint(input, 0, bytes(input).length);
Expand All @@ -168,8 +167,7 @@ library Strings {
* @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character.
*
* Requirements:
* - The result must fit into an `uint256` type.
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(
string memory input,
Expand Down Expand Up @@ -214,10 +212,10 @@ library Strings {
}

/**
* @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character.
* @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if
* the result does not fit in a `int256`.
*
* Requirements:
* - The result must fit into an `int256` type.
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {
return tryParseInt(input, 0, bytes(input).length);
Expand All @@ -227,9 +225,9 @@ library Strings {

/**
* @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character.
* character or if the result does not fit in a `int256`.
*
* This function will still revert if the result does not fit in a `int256`
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(
string memory input,
Expand Down Expand Up @@ -280,8 +278,7 @@ library Strings {
/**
* @dev Variant of {parseHex-string} that returns false if the parsing fails because of an invalid character.
*
* Requirements:
* - The result must fit into an `uint256` type.
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHex(string memory input) internal pure returns (bool success, uint256 value) {
return tryParseHex(input, 0, bytes(input).length);
Expand All @@ -291,8 +288,7 @@ library Strings {
* @dev Variant of {parseHex-string-uint256-uint256} that returns false if the parsing fails because of an
* invalid character.
*
* Requirements:
* - The result must fit into an `uint256` type.
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHex(
string memory input,
Expand Down
10 changes: 8 additions & 2 deletions test/utils/Strings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,14 @@ describe('Strings', function () {
await expect(this.mock.$tryParseInt((-ethers.MaxUint256 - 1n).toString(10))).to.be.revertedWithPanic(
PANIC_CODES.ARITHMETIC_OVERFLOW,
);
await expect(this.mock.$parseInt((ethers.MaxInt256 + 1n).toString(10))).to.be.revertedWithCustomError(this.mock, 'StringsInvalidChar');
await expect(this.mock.$parseInt((ethers.MinInt256 - 1n).toString(10))).to.be.revertedWithCustomError(this.mock, 'StringsInvalidChar');
await expect(this.mock.$parseInt((ethers.MaxInt256 + 1n).toString(10))).to.be.revertedWithCustomError(
this.mock,
'StringsInvalidChar',
);
await expect(this.mock.$parseInt((ethers.MinInt256 - 1n).toString(10))).to.be.revertedWithCustomError(
this.mock,
'StringsInvalidChar',
);
expect(await this.mock.$tryParseInt((ethers.MaxInt256 + 1n).toString(10))).to.deep.equal([false, 0n]);
expect(await this.mock.$tryParseInt((ethers.MinInt256 - 1n).toString(10))).to.deep.equal([false, 0n]);
});
Expand Down

0 comments on commit 7b7c1fd

Please sign in to comment.