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:
29
foundry/test/TestUtils.sol
Normal file
29
foundry/test/TestUtils.sol
Normal 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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user