harb/onchain/analysis/helpers/CSVManager.sol

52 lines
1.4 KiB
Solidity
Raw Normal View History

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "forge-std/Test.sol";
import "./CSVHelper.sol";
/**
* @title CSVManager
* @dev An abstract contract that manages CSV creation, row appending, and writing to file.
* Contracts that inherit this contract can use the CSV functionality without managing the CSV string directly.
*/
abstract contract CSVManager is Test {
using CSVHelper for *;
string internal csv;
/**
* @notice Creates the header for the CSV file.
* This function should be called in the `setUp` function of derived contracts.
*/
function initializePositionsCSV() internal {
csv = CSVHelper.createPositionsHeader();
}
function initializeTimeSeriesCSV() internal {
csv = CSVHelper.createTimeSeriesHeader();
}
/**
* @notice Appends a new row to the CSV string.
* @param newRow The new row to append.
*/
function appendCSVRow(string memory newRow) internal {
csv = CSVHelper.appendRow(csv, newRow);
}
/**
* @notice Writes the CSV string to a file.
* @param filePath The path where the CSV file will be saved.
*/
function writeCSVToFile(string memory filePath) internal {
vm.writeFile(filePath, csv);
}
/**
* @notice Clears the CSV buffer. Should be called between runs to avoid data accumulation.
*/
function clearCSV() internal {
csv = "";
}
}