Skip to content

Commit

Permalink
test: polish librariy linkage
Browse files Browse the repository at this point in the history
  • Loading branch information
smol-ninja committed Nov 8, 2024
1 parent 31f544a commit 8f58ce8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 0 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
{ access = "read-write", path = "./script/protocol"}
]
gas_limit = 9223372036854775807
libs = ["src/core/libraries"]
optimizer = true
optimizer_runs = 1000
out = "out"
Expand Down
2 changes: 1 addition & 1 deletion shell/prepare-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
set -euo pipefail

# Generate the artifacts with Forge
FOUNDRY_PROFILE=optimized forge build --lib-paths "src/core/libraries"
FOUNDRY_PROFILE=optimized forge build

# Delete the current artifacts
artifacts=./artifacts
Expand Down
19 changes: 11 additions & 8 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ abstract contract Base_Test is Assertions, Calculations, DeployOptimized, Modifi
return user;
}

/// @dev Deploys the optimized {Helpers} and {VestingMath} libraries and assign them to linked addresses.
function deployOptimizedLibraries() internal {
address helpers = deployCode("out-optimized/Helpers.sol/Helpers.json");
address vestingMath = deployCode("out-optimized/VestingMath.sol/VestingMath.json");
vm.etch(0x7715bE116061E014Bb721b46Dc78Dd57C91FDF9b, helpers.code);
vm.etch(0x26F9d826BDed47Fc472526aE8095B75ac336963C, vestingMath.code);
}

/// @dev Conditionally deploys the protocol normally or from an optimized source compiled with `--via-ir`.
/// We cannot use the {DeployProtocol} script because some tests rely on hard coded addresses for the
/// deployed contracts. Since the script itself would have to be deployed, using it would bump the
Expand All @@ -156,14 +164,9 @@ abstract contract Base_Test is Assertions, Calculations, DeployOptimized, Modifi
lockup = new SablierLockup(users.admin, nftDescriptor, defaults.MAX_COUNT());
merkleFactory = new SablierMerkleFactory(users.admin);
} else {
// Deploy the optimized Helpers and VestingMath libraries and assign them to linked address.
vm.etch(
0x7715bE116061E014Bb721b46Dc78Dd57C91FDF9b, vm.getDeployedCode("out-optimized/Helpers.sol/Helpers.json")
);
vm.etch(
0x26F9d826BDed47Fc472526aE8095B75ac336963C,
vm.getDeployedCode("out-optimized/vestingMath.sol/vestingMath.json")
);
// Deploy the optimized libraries.
deployOptimizedLibraries();

// Deploy the optimized contracts.
(nftDescriptor, lockup, batchLockup, merkleFactory) =
deployOptimizedProtocol(users.admin, defaults.MAX_COUNT());
Expand Down

0 comments on commit 8f58ce8

Please sign in to comment.