Skip to content

Commit

Permalink
feat: add export string value
Browse files Browse the repository at this point in the history
  • Loading branch information
amusingaxl committed Oct 25, 2023
1 parent c8dba04 commit 0dd02b9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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");
}

}

0 comments on commit 0dd02b9

Please sign in to comment.