Closed Skelectric closed 1 year ago
Here's a simpler example. When i run this script it deploys SomeLibrary - why?
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.17;
import "forge-std/Script.sol";
contract ExtraBroadcastTest is Script {
function run() external {
SomeLibrary.reflect(5);
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
(bool success,) = address(0).call{value: 0 ether}("");
vm.stopBroadcast();
require(success, "Call failed.");
}
}
library SomeLibrary {
function reflect(uint number) external pure returns (uint) {
return number;
}
}
If i change SomeLibrary into an abstract contract and make the script inherit from it, this doesn't happen.
So libraries and forge script don't mix?
This is unfortunate as there are things I can't do with abstract contracts that I can do with libraries. For example, the try-catch pattern.
I am getting the same issue! Thanks for reporting this.
I have also gotten this issue recently. It looks like it only affects external libraries, as internal libraries are inlined.
Ref #5194
Closing—fixed with several linker fixes
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
No response
What command(s) is the bug in?
forge script
Operating System
Windows
Describe the bug
I have some libraries with convenience functions that I like to use in my scripts.
For example, a
readableNum
library that lets me log numbers in decimal format (for easier debugging), or astdJsonDB
library that lets me serialize/write data to a file in a single call. Despite me using these utilities outside the the bounds ofvm.startBroadcast(privKey)
andvm.stopBroadcast()
, forge script still manages to include their deployments among the broadcasted transactions.For an example:
I expect this script to broadcast only the operations I marked but forge script also cues up and deploys the
stdJsonDB
library.