Add toUint, toInt and hexToUint to Strings (#5166)

Co-authored-by: cairo <cairoeth@protonmail.com>
Co-authored-by: Ernesto García <ernestognw@gmail.com>
This commit is contained in:
Hadrien Croubois
2024-10-14 17:13:33 +02:00
committed by GitHub
parent 72c152dc1c
commit bd588959ad
6 changed files with 503 additions and 68 deletions

27
test/utils/Strings.t.sol Normal file
View File

@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Test} from "forge-std/Test.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
contract StringsTest is Test {
using Strings for *;
function testParse(uint256 value) external {
assertEq(value, value.toString().parseUint());
}
function testParseSigned(int256 value) external {
assertEq(value, value.toStringSigned().parseInt());
}
function testParseHex(uint256 value) external {
assertEq(value, value.toHexString().parseHexUint());
}
function testParseChecksumHex(address value) external {
assertEq(value, value.toChecksumHexString().parseAddress());
}
}