Skip to content

Commit

Permalink
docs: improve natspec for constructCreate2Salt
Browse files Browse the repository at this point in the history
chore: remove underscore from function name
test: constructCreate2Salt function
build: set ffi true in test foundry profile
  • Loading branch information
andreivladbrg committed Feb 7, 2024
1 parent 32cbe90 commit 3f3c439
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

# Test the optimized contracts without re-compiling them
[profile.test-optimized]
ffi = true
src = "test"

[doc]
Expand Down
9 changes: 5 additions & 4 deletions script/Base.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -50,9 +50,10 @@ abstract contract BaseScript is Script {
///
/// Notes:
/// - The salt format is "ChainID <chainid>, Version <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";
Expand All @@ -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));
}
}
2 changes: 1 addition & 1 deletion script/DeployDeterministicPeriphery.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }();
}
Expand Down
23 changes: 23 additions & 0 deletions test/utils/BaseScript.t.sol
Original file line number Diff line number Diff line change
@@ -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");
}
}

0 comments on commit 3f3c439

Please sign in to comment.