feat(forge): table tests#10775
Merged
grandizzy merged 2 commits intofoundry-rs:masterfrom Jun 16, 2025
Merged
Conversation
zerosnacks
approved these changes
Jun 13, 2025
Member
zerosnacks
left a comment
There was a problem hiding this comment.
Makes sense 👍
Implementation looks good
Member
|
How does this work for structs if at all? If not good preprocessing feature |
Collaborator
Author
yep, that's possible by defining struct fixtures as samples below, will update docs struct TestCase {
uint256 a;
uint256 b;
uint256 expected;
}
function fixtureSums() public returns (TestCase[] memory) {
TestCase[] memory entries = new TestCase[](2);
entries[0] = TestCase(1, 2, 3);
entries[1] = TestCase(4, 5, 9);
return entries;
}
function tableSumsTest(TestCase memory sums) public pure {
require(sums.a + sums.b == sums.expected, "wrong sum");
}or multiple structs input contract SwapTableTest is Test {
struct Wallet {
address owner;
uint256 amount;
}
struct Swap {
bool swap;
uint256 amount;
}
Wallet[] public fixtureWallet;
Swap[] public fixtureSwap;
function setUp() public {
// first table test input
fixtureWallet.push(Wallet(address(11), 11));
fixtureSwap.push(Swap(true, 11));
// second table test input
fixtureWallet.push(Wallet(address(12), 12));
fixtureSwap.push(Swap(false, 12));
}
function tableSwapTest(Wallet memory wallet, Swap memory swap) public pure {
require(
(wallet.owner == address(11) && swap.swap) || (wallet.owner == address(12) && !swap.swap), "not allowed"
);
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Solution
table*teststable_test(uint256 amount, bool swap)fixtures are defined asuint256[] public fixtureAmount = [2, 5]bool[] public fixtureSwap = [true, false]table_testis then called with the pair of args(2, true)and(5, false).table_test(uint256 amount)will be called with values of 2 and 5PR Checklist