Skip to content

Commit

Permalink
Merge branch 'main' into mask-address-args-STL
Browse files Browse the repository at this point in the history
  • Loading branch information
transmissions11 committed Jun 13, 2023
2 parents a115360 + 2001af4 commit bceeec7
Show file tree
Hide file tree
Showing 9 changed files with 774 additions and 95 deletions.
246 changes: 164 additions & 82 deletions .gas-snapshot

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*.sol linguist-language=Solidity
.gas-snapshot linguist-language=Julia
2 changes: 1 addition & 1 deletion lib/ds-test
Submodule ds-test updated 1 files
+15 −0 package.json
2 changes: 1 addition & 1 deletion 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
@@ -1,7 +1,7 @@
{
"name": "solmate",
"license": "AGPL-3.0-only",
"version": "6.6.2",
"version": "6.7.0",
"description": "Modern, opinionated and gas optimized building blocks for smart contract development.",
"files": [
"src/**/*.sol"
Expand Down
59 changes: 50 additions & 9 deletions src/test/LibString.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,32 @@ import {LibString} from "../utils/LibString.sol";

contract LibStringTest is DSTestPlus {
function testToString() public {
assertEq(LibString.toString(0), "0");
assertEq(LibString.toString(1), "1");
assertEq(LibString.toString(17), "17");
assertEq(LibString.toString(99999999), "99999999");
assertEq(LibString.toString(99999999999), "99999999999");
assertEq(LibString.toString(2342343923423), "2342343923423");
assertEq(LibString.toString(98765685434567), "98765685434567");
assertEq(LibString.toString(uint256(0)), "0");
assertEq(LibString.toString(uint256(1)), "1");
assertEq(LibString.toString(uint256(17)), "17");
assertEq(LibString.toString(uint256(99999999)), "99999999");
assertEq(LibString.toString(uint256(99999999999)), "99999999999");
assertEq(LibString.toString(uint256(2342343923423)), "2342343923423");
assertEq(LibString.toString(uint256(98765685434567)), "98765685434567");
}

function testToStringIntPositive() public {
assertEq(LibString.toString(int256(0)), "0");
assertEq(LibString.toString(int256(1)), "1");
assertEq(LibString.toString(int256(17)), "17");
assertEq(LibString.toString(int256(99999999)), "99999999");
assertEq(LibString.toString(int256(99999999999)), "99999999999");
assertEq(LibString.toString(int256(2342343923423)), "2342343923423");
assertEq(LibString.toString(int256(98765685434567)), "98765685434567");
}

function testToStringIntNegative() public {
assertEq(LibString.toString(int256(-0)), "0");
assertEq(LibString.toString(int256(-17)), "-17");
assertEq(LibString.toString(int256(-99999999)), "-99999999");
assertEq(LibString.toString(int256(-99999999999)), "-99999999999");
assertEq(LibString.toString(int256(-2342343923423)), "-2342343923423");
assertEq(LibString.toString(int256(-98765685434567)), "-98765685434567");
}

function testDifferentiallyFuzzToString(uint256 value, bytes calldata brutalizeWith)
Expand All @@ -27,8 +46,19 @@ contract LibStringTest is DSTestPlus {
assertEq(libString, oz);
}

function testDifferentiallyFuzzToStringInt(int256 value, bytes calldata brutalizeWith)
public
brutalizeMemory(brutalizeWith)
{
string memory libString = LibString.toString(value);
string memory oz = toStringOZ(value);

assertEq(bytes(libString).length, bytes(oz).length);
assertEq(libString, oz);
}

function testToStringOverwrite() public {
string memory str = LibString.toString(1);
string memory str = LibString.toString(uint256(1));

bytes32 data;
bytes32 expected;
Expand Down Expand Up @@ -62,7 +92,7 @@ contract LibStringTest is DSTestPlus {
mstore(add(freememptr, 96), dirty)
mstore(add(freememptr, 128), dirty)
}
string memory str = LibString.toString(1);
string memory str = LibString.toString(uint256(1));
uint256 len;
bytes32 data;
bytes32 expected;
Expand All @@ -87,6 +117,10 @@ contract LibStringTest is DSTestPlus {
}
}

function toStringOZ(int256 value) pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toStringOZ(absOZ(value))));
}

function toStringOZ(uint256 value) pure returns (string memory) {
if (value == 0) {
return "0";
Expand All @@ -105,3 +139,10 @@ function toStringOZ(uint256 value) pure returns (string memory) {
}
return string(buffer);
}

function absOZ(int256 n) pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
Loading

0 comments on commit bceeec7

Please sign in to comment.