From 3f3c43955ee5aa6976385d343bb94750d266be40 Mon Sep 17 00:00:00 2001 From: andreivladbrg Date: Tue, 6 Feb 2024 13:36:59 +0200 Subject: [PATCH] docs: improve natspec for constructCreate2Salt chore: remove underscore from function name test: constructCreate2Salt function build: set ffi true in test foundry profile --- foundry.toml | 1 + script/Base.s.sol | 9 +++++---- script/DeployDeterministicPeriphery.s.sol | 2 +- test/utils/BaseScript.t.sol | 23 +++++++++++++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 test/utils/BaseScript.t.sol diff --git a/foundry.toml b/foundry.toml index 8e8d78d9..fcacb1ff 100644 --- a/foundry.toml +++ b/foundry.toml @@ -34,6 +34,7 @@ # Test the optimized contracts without re-compiling them [profile.test-optimized] + ffi = true src = "test" [doc] diff --git a/script/Base.s.sol b/script/Base.s.sol index 37ecdda4..8e710a6a 100644 --- a/script/Base.s.sol +++ b/script/Base.s.sol @@ -7,7 +7,7 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; import { console2 } from "forge-std/src/console2.sol"; import { Script } from "forge-std/src/Script.sol"; -abstract contract BaseScript is Script { +contract BaseScript is Script { using Strings for uint256; /// @dev Included to enable compilation of the script without a $MNEMONIC environment variable. @@ -50,9 +50,10 @@ abstract contract BaseScript is Script { /// /// Notes: /// - The salt format is "ChainID , Version ". - /// - The version is obtained from the `package.json` file via --ffi cheatcode: + /// - The version is obtained from `package.json` using the `ffi` cheatcode: /// https://book.getfoundry.sh/cheatcodes/ffi - function _constructCreate2Salt() internal returns (bytes32) { + /// - Requires `jq` CLI tool installed: https://jqlang.github.io/jq/ + function constructCreate2Salt() public returns (bytes32) { string memory chainId = block.chainid.toString(); string[] memory inputs = new string[](4); inputs[0] = "jq"; @@ -62,7 +63,7 @@ abstract contract BaseScript is Script { bytes memory result = vm.ffi(inputs); string memory version = string(result); string memory create2Salt = string.concat("ChainID ", chainId, ", Version ", version); - console2.log(create2Salt); + console2.log("The CREATE2 salt is \"%s\"", create2Salt); return bytes32(abi.encodePacked(create2Salt)); } } diff --git a/script/DeployDeterministicPeriphery.s.sol b/script/DeployDeterministicPeriphery.s.sol index e3bb0a5e..d196d534 100644 --- a/script/DeployDeterministicPeriphery.s.sol +++ b/script/DeployDeterministicPeriphery.s.sol @@ -19,7 +19,7 @@ contract DeployDeterministicPeriphery is BaseScript { broadcast returns (SablierV2Batch batch, SablierV2MerkleStreamerFactory merkleStreamerFactory) { - bytes32 salt = _constructCreate2Salt(); + bytes32 salt = constructCreate2Salt(); batch = new SablierV2Batch{ salt: salt }(); merkleStreamerFactory = new SablierV2MerkleStreamerFactory{ salt: bytes32(abi.encodePacked(create2Salt)) }(); } diff --git a/test/utils/BaseScript.t.sol b/test/utils/BaseScript.t.sol new file mode 100644 index 00000000..28c15073 --- /dev/null +++ b/test/utils/BaseScript.t.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +pragma solidity >=0.8.19 <0.9.0; + +import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; +import { PRBTest } from "@prb/test/src/PRBTest.sol"; + +import { BaseScript } from "script/Base.s.sol"; + +contract BaseScript_Test is PRBTest { + using Strings for uint256; + + BaseScript internal baseScript = new BaseScript(); + + function test_ConstructCreate2Salt() public { + string memory chainId = block.chainid.toString(); + string memory version = "1.1.1"; + string memory salt = string.concat("ChainID ", chainId, ", Version ", version); + + bytes32 actualSalt = baseScript.constructCreate2Salt(); + bytes32 expectedSalt = bytes32(abi.encodePacked(salt)); + assertEq(actualSalt, expectedSalt, "CREATE2 salt mismatch"); + } +}