Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Flaky Test #89

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions contracts/payments.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"leaves": [
"0x29036a1d92861ffd464a1e285030fad3978a36f953ae33c160e606d2ac746c42",
"0x29036a1d92861ffd464a1e285030fad3978a36f953ae33c160e606d2ac746c42",
"0x29036a1d92861ffd464a1e285030fad3978a36f953ae33c160e606d2ac746c42",
"0x29036a1d92861ffd464a1e285030fad3978a36f953ae33c160e606d2ac746c42"
"0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000000000000000000000000000002"
],
"tokenLeaves": [
"0xf5d87050cb923194fe63c7ed2c45cbc913fa6ecf322f3631149c36d9460b3ad6"
"0x0000000000000000000000000000000000000000000000000000000000000003",
"0x0000000000000000000000000000000000000000000000000000000000000004"
]
}
8 changes: 5 additions & 3 deletions contracts/script/SetupPayments.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract SetupPayments is Script {
address private deployer;
CoreDeploymentLib.DeploymentData coreDeployment;
HelloWorldDeploymentLib.DeploymentData helloWorldDeployment;
string private filePath;
string internal constant filePath = "test/mockData/scratch/payments.json";

uint256 constant NUM_TOKEN_EARNINGS = 1;
uint256 constant DURATION = 1 weeks;
Expand All @@ -50,7 +50,8 @@ contract SetupPayments is Script {
earner: info.earners[info.indexToProve],
earnerTokenRoot: info.earnerTokenRoots[info.indexToProve]
});
processClaim(SetupPaymentsLib.getFilePath(), info.indexToProve, info.recipient, earnerLeaf);

processClaim(filePath, info.indexToProve, info.recipient, earnerLeaf);

vm.stopBroadcast();
}
Expand Down Expand Up @@ -95,7 +96,8 @@ contract SetupPayments is Script {
helloWorldDeployment.strategy,
endTimestamp,
numPayments,
NUM_TOKEN_EARNINGS
NUM_TOKEN_EARNINGS,
filePath
);
}
}
18 changes: 8 additions & 10 deletions contracts/script/utils/SetupPaymentsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {Vm} from "forge-std/Vm.sol";
library SetupPaymentsLib {

Vm internal constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
string internal constant filePath = "test/mockData/scratch/payments.json";

struct PaymentLeaves {
bytes32[] leaves;
Expand Down Expand Up @@ -87,9 +86,10 @@ library SetupPaymentsLib {
address strategy,
uint32 rewardsCalculationEndTimestamp,
uint256 NUM_PAYMENTS,
uint256 NUM_TOKEN_EARNINGS
uint256 NUM_TOKEN_EARNINGS,
string memory filePath
) internal {
bytes32 paymentRoot = createPaymentRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, NUM_PAYMENTS, NUM_TOKEN_EARNINGS, strategy);
bytes32 paymentRoot = createPaymentRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, NUM_PAYMENTS, NUM_TOKEN_EARNINGS, strategy, filePath);
rewardsCoordinator.submitRoot(paymentRoot, rewardsCalculationEndTimestamp);
}

Expand All @@ -99,7 +99,8 @@ library SetupPaymentsLib {
IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves,
uint256 NUM_PAYMENTS,
uint256 NUM_TOKEN_EARNINGS,
address strategy
address strategy,
string memory filePath
) internal returns (bytes32) {
require(earnerLeaves.length == NUM_PAYMENTS, "Number of earners must match number of payments");
bytes32[] memory leaves = new bytes32[](NUM_PAYMENTS);
Expand All @@ -109,7 +110,7 @@ library SetupPaymentsLib {
leaves[i] = rewardsCoordinator.calculateEarnerLeafHash(earnerLeaves[i]);
}

writeLeavesToJson(leaves, tokenLeaves);
writeLeavesToJson(leaves, tokenLeaves, filePath);
return (merkleizeKeccak(leaves));
}

Expand Down Expand Up @@ -158,7 +159,8 @@ library SetupPaymentsLib {

function writeLeavesToJson(
bytes32[] memory leaves,
bytes32[] memory tokenLeaves
bytes32[] memory tokenLeaves,
string memory filePath
) internal {
string memory parent_object = "parent_object";
vm.serializeBytes32(parent_object, "leaves", leaves);
Expand Down Expand Up @@ -264,8 +266,4 @@ library SetupPaymentsLib {
}
return paddedLeaves;
}

function getFilePath() public pure returns (string memory) {
return filePath;
}
}
10 changes: 7 additions & 3 deletions contracts/test/SetupPaymentsLib.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup
IStrategy public strategy;
address proxyAdmin;

string internal constant filePath = "test/mockData/scratch/payments.json";


function setUp() public override virtual {
proxyAdmin = UpgradeableProxyLib.deployProxyAdmin();
Expand Down Expand Up @@ -73,7 +75,7 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup
IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves =SetupPaymentsLib.createEarnerLeaves(earners, tokenLeaves);

cheats.startPrank(address(0), address(0));
SetupPaymentsLib.submitRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, address(strategy), endTimestamp, NUM_EARNERS, 1);
SetupPaymentsLib.submitRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, address(strategy), endTimestamp, NUM_EARNERS, 1, filePath);
cheats.stopPrank();
}

Expand All @@ -86,7 +88,9 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup
tokenLeaves[0] = bytes32(uint256(3));
tokenLeaves[1] = bytes32(uint256(4));

SetupPaymentsLib.writeLeavesToJson(leaves, tokenLeaves);
string memory filePath = ("payments.json");

SetupPaymentsLib.writeLeavesToJson(leaves, tokenLeaves, filePath);

assertTrue(vm.exists("payments.json"), "JSON file should be created");
}
Expand Down Expand Up @@ -146,7 +150,7 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup
IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves =SetupPaymentsLib.createEarnerLeaves(earners, tokenLeaves);

cheats.startPrank(address(0));
SetupPaymentsLib.submitRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, address(strategy), endTimestamp, NUM_EARNERS, 1);
SetupPaymentsLib.submitRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, address(strategy), endTimestamp, NUM_EARNERS, 1, filePath);
cheats.stopPrank();


Expand Down