chore: Write encoding rust calldata to file and read in solidity test

This way we can automatically replace the calldata when something changes. We don't need to manually replace the string ourselves.

--- don't change below this line ---
ENG-4453 Took 3 hours 26 minutes
This commit is contained in:
Diana Carvalho
2025-04-29 10:23:47 +01:00
parent b03c58d833
commit 0ff4aef0c7
16 changed files with 277 additions and 153 deletions

View File

@@ -0,0 +1,29 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;
import "forge-std/Test.sol";
contract TestUtils is Test {
constructor() {}
function loadCallDataFromFile(string memory testName)
internal
view
returns (bytes memory)
{
string memory fileContent = vm.readFile("./test/assets/calldata.txt");
string[] memory lines = vm.split(fileContent, "\n");
for (uint256 i = 0; i < lines.length; i++) {
string[] memory parts = vm.split(lines[i], ":");
if (
parts.length >= 2
&& keccak256(bytes(parts[0])) == keccak256(bytes(testName))
) {
return vm.parseBytes(parts[1]);
}
}
revert("Test calldata not found");
}
}