From 7b7c1fd4a6681dc0072a222d33d7514dc505c61b Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Fri, 11 Oct 2024 22:45:38 +0200 Subject: [PATCH] comment update --- contracts/utils/Strings.sol | 22 +++++++++------------- test/utils/Strings.test.js | 10 ++++++++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/contracts/utils/Strings.sol b/contracts/utils/Strings.sol index a53c24dc570..ae2b7a6a8a0 100644 --- a/contracts/utils/Strings.sol +++ b/contracts/utils/Strings.sol @@ -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); @@ -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, @@ -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); @@ -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, @@ -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); @@ -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, diff --git a/test/utils/Strings.test.js b/test/utils/Strings.test.js index 35b5e842fca..b5d8acc93e4 100644 --- a/test/utils/Strings.test.js +++ b/test/utils/Strings.test.js @@ -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]); });