feat: Add BytecodeExporter to TestUtils

Add example usage for BalancerV2

Took 2 hours 27 minutes


Took 10 seconds
This commit is contained in:
Diana Carvalho
2025-08-21 16:59:26 +01:00
parent cc9801ff91
commit cea964e0a5
3 changed files with 28 additions and 1 deletions

View File

@@ -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/<name>.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);
}
}