Skip to content

Commit

Permalink
feat: remove extra input JSON files
Browse files Browse the repository at this point in the history
  • Loading branch information
guidanoli committed Sep 5, 2023
1 parent e1906b0 commit c6a01c1
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions onchain/rollups/test/foundry/dapp/CartesiDApp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ contract CartesiDAppTest is TestBase {
deployContracts();
generateOutputs();
writeInputs();
removeExtraInputs();
readFinishEpochResponse();
}

Expand Down Expand Up @@ -658,6 +659,31 @@ contract CartesiDAppTest is TestBase {
}
}

function getInputPath(
string memory inputIndexStr
) internal view returns (string memory) {
string memory root = vm.projectRoot();
return
string.concat(
root,
"/test",
"/foundry",
"/dapp",
"/helper",
"/input",
"/",
inputIndexStr,
".json"
);
}

function getInputPath(
uint256 inputIndex
) internal view returns (string memory) {
string memory inputIndexStr = vm.toString(inputIndex);
return getInputPath(inputIndexStr);
}

function writeInput(
uint256 inputIndex,
address sender,
Expand All @@ -667,21 +693,19 @@ contract CartesiDAppTest is TestBase {
string memory objectKey = string.concat("input", inputIndexStr);
vm.serializeAddress(objectKey, "sender", sender);
string memory json = vm.serializeBytes(objectKey, "payload", payload);
string memory root = vm.projectRoot();
string memory path = string.concat(
root,
"/test",
"/foundry",
"/dapp",
"/helper",
"/input",
"/",
inputIndexStr,
".json"
);
string memory path = getInputPath(inputIndexStr);
vm.writeJson(json, path);
}

function removeExtraInputs() internal {
uint256 inputIndex = outputEnums.length;
string memory path = getInputPath(inputIndex);
while (vm.isFile(path)) {
vm.removeFile(path);
path = getInputPath(++inputIndex);
}
}

function readFinishEpochResponse() internal {
// Construct path to FinishEpoch response JSON
string memory root = vm.projectRoot();
Expand Down

0 comments on commit c6a01c1

Please sign in to comment.