Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: export string value #37

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/ScriptTools.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,31 @@ library ScriptTools {
_doExport(name, json);
}

/**
* @notice Used to export important values to higher level deploy scripts.
* Note waiting on Foundry to have better primitives, but roll our own for now.
* @dev Requires FOUNDRY_EXPORTS_NAME to be set.
* @param label The label of the address.
* @param val The value to export.
*/
function exportValue(string memory label, string memory val) internal {
exportValue(vm.envString("FOUNDRY_EXPORTS_NAME"), label, val);
}

/**
* @notice Used to export important values to higher level deploy scripts.
* Note waiting on Foundry to have better primitives, but roll our own for now.
* @dev Set FOUNDRY_EXPORTS_NAME to override the name of the json file.
* @param name The name to give the json file.
* @param label The label of the address.
* @param val The value to export.
*/
function exportValue(string memory name, string memory label, string memory val) internal {
name = vm.envOr("FOUNDRY_EXPORTS_NAME", name);
string memory json = vm.serializeString(EXPORT_JSON_KEY, label, val);
_doExport(name, json);
}

/**
* @dev Common logic to export JSON files.
* @param name The name to give the json file
Expand Down
9 changes: 9 additions & 0 deletions src/tests/ScriptToolsTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ contract ScriptToolTest is DssTest {
loadedExports = ScriptTools.readOutput("myExports", 1);
assertEq(stdJson.readUint(loadedExports, ".label1"), 1);
assertEq(stdJson.readUint(loadedExports, ".label2"), 2);

// Export some values and write to output
ScriptTools.exportValue("myExports", "str-label1", "str1");
ScriptTools.exportValue("myExports", "str-label2", "str2");

// Simulate a subsequent run loading a previously written file (use latest deploy)
loadedExports = ScriptTools.readOutput("myExports", 1);
assertEq(stdJson.readString(loadedExports, ".str-label1"), "str1");
assertEq(stdJson.readString(loadedExports, ".str-label2"), "str2");
}

}