From c6a01c1c93bf37e7d5131b8090f6d2bedcb05dc1 Mon Sep 17 00:00:00 2001 From: Guilherme Dantas Date: Mon, 4 Sep 2023 11:30:27 -0300 Subject: [PATCH] feat: remove extra input JSON files --- .../test/foundry/dapp/CartesiDApp.t.sol | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/onchain/rollups/test/foundry/dapp/CartesiDApp.t.sol b/onchain/rollups/test/foundry/dapp/CartesiDApp.t.sol index 4fd5784c..b1b999c2 100644 --- a/onchain/rollups/test/foundry/dapp/CartesiDApp.t.sol +++ b/onchain/rollups/test/foundry/dapp/CartesiDApp.t.sol @@ -81,6 +81,7 @@ contract CartesiDAppTest is TestBase { deployContracts(); generateOutputs(); writeInputs(); + removeExtraInputs(); readFinishEpochResponse(); } @@ -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, @@ -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();