BacktestingUtils
Title: BacktestingUtils
Author: Phylax Systems
Utility functions for the backtesting framework
Provides parsing, string manipulation, and error decoding utilities used internally by CredibleTestWithBacktesting
Functions
extractDataLine
Extract transaction data from fetcher output
function extractDataLine(string memory output) internal pure returns (string memory);
_isWhitespace
Check if a character is whitespace
function _isWhitespace(bytes1 char) private pure returns (bool);
splitString
Simple pipe-delimited string splitter
function splitString(string memory str, string memory) internal pure returns (string[] memory);
stringToUint
Parse hex or decimal string to uint256
function stringToUint(string memory str) internal pure returns (uint256);
stringToAddress
Parse hex address string to address
function stringToAddress(string memory str) internal pure returns (address);
stringToBytes32
Parse hex string to bytes32
function stringToBytes32(string memory str) internal pure returns (bytes32);
hexStringToBytes
Parse hex string to bytes
function hexStringToBytes(string memory str) internal pure returns (bytes memory);
bytes32ToHex
Convert bytes32 to hex string
function bytes32ToHex(bytes32 data) internal pure returns (string memory);
extractFunctionSelector
Extract function selector from calldata
function extractFunctionSelector(bytes memory data) internal pure returns (string memory);
parseMultipleTransactions
Parse multiple transactions from a single data line
function parseMultipleTransactions(string memory txDataString)
internal
pure
returns (BacktestingTypes.TransactionData[] memory transactions);
_hexCharToUint8
Convert hex character to uint8
function _hexCharToUint8(bytes1 char) private pure returns (uint8);
substring
Helper to get substring for debugging
function substring(string memory str, uint256 start, uint256 len) private pure returns (string memory);
decodeRevertReason
Decode revert reason from error data
function decodeRevertReason(bytes memory data) internal pure returns (string memory);
Parameters
| Name | Type | Description |
|---|---|---|
data | bytes | The error data from a failed call |
Returns
| Name | Type | Description |
|---|---|---|
<none> | string | The decoded revert reason string |
_panicCodeToString
Convert panic code to human-readable string
function _panicCodeToString(uint256 code) private pure returns (string memory);
bytesToHex
Convert bytes to hex string
function bytesToHex(bytes memory data) internal pure returns (bytes memory);
Parameters
| Name | Type | Description |
|---|---|---|
data | bytes | The bytes to convert |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bytes | The hex string representation |
getErrorTypeString
Get human-readable error type string from validation result
function getErrorTypeString(BacktestingTypes.ValidationResult result) internal pure returns (string memory);
Parameters
| Name | Type | Description |
|---|---|---|
result | BacktestingTypes.ValidationResult | The validation result enum |
Returns
| Name | Type | Description |
|---|---|---|
<none> | string | The human-readable string representation |
startsWith
Check if a string starts with a prefix
function startsWith(string memory str, string memory prefix) internal pure returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
str | string | The string to check |
prefix | string | The prefix to look for |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | True if str starts with prefix |
getDefaultScriptSearchPaths
Get the standard search paths for transaction_fetcher.sh
function getDefaultScriptSearchPaths() internal pure returns (string[] memory);
Returns
| Name | Type | Description |
|---|---|---|
<none> | string[] | Array of paths to check, in order of preference |