diff --git a/foundry/foundry.toml b/foundry/foundry.toml index 9acffad..e5183c8 100644 --- a/foundry/foundry.toml +++ b/foundry/foundry.toml @@ -7,7 +7,7 @@ evm_version = 'cancun' optimizer = true optimizer_runs = 200 via_ir = true -fs_permissions = [{ access = "read", path = "./test/assets" }] +fs_permissions = [{ access = "read", path = "./test/assets" }, { access = "write", path = "./test" }] [profile.production] src = 'src' diff --git a/foundry/test/TestUtils.sol b/foundry/test/TestUtils.sol index 3399c9f..c062cf8 100644 --- a/foundry/test/TestUtils.sol +++ b/foundry/test/TestUtils.sol @@ -26,4 +26,26 @@ contract TestUtils is Test { revert("Test calldata not found"); } + + /// @notice Export the runtime bytecode of a deployed contract to a JSON file. + /// @dev + /// This function captures the runtime bytecode (including immutables) of the deployed + /// contract at `contractAddr` and writes it to a JSON file under `test/.runtime.json`. + /// The resulting file is intended to be used for SDK testing in another repository and + /// should be copied there. It **should not** be committed in this repository. + /// @param contractAddr The address of the deployed contract to extract runtime bytecode from. + /// @param contractName The base filename for the exported JSON file. + function exportRuntimeBytecode( + address contractAddr, + string memory contractName + ) internal { + bytes memory runtime = contractAddr.code; + string memory hexCode = vm.toString(runtime); + string memory json = + string.concat('{"runtimeBytecode":"', hexCode, '"}'); + + string memory path = + string.concat("test/", contractName, ".runtime.json"); + vm.writeFile(path, json); + } } diff --git a/foundry/test/protocols/BalancerV2.t.sol b/foundry/test/protocols/BalancerV2.t.sol index 6c832d6..1540ce1 100644 --- a/foundry/test/protocols/BalancerV2.t.sol +++ b/foundry/test/protocols/BalancerV2.t.sol @@ -134,4 +134,9 @@ contract BalancerV2ExecutorTest is Constants, TestUtils { assertGt(balanceAfter, balanceBefore); assertEq(balanceAfter - balanceBefore, amountOut); } + + function testExportContract() public { + vm.skip(true); + exportRuntimeBytecode(address(balancerV2Exposed), "BalancerV2"); + } }