From fa38a6e92e4491f8142608388af0ef62adafe900 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Wed, 23 Jul 2025 23:50:37 -0700 Subject: [PATCH 1/6] wip --- .github/workflows/ci.yml | 2 +- contracts/test/core/BidderRegistryTest.sol | 72 +++++++++------------- 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b3ffc98b..c273946c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -131,7 +131,7 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 with: - version: nightly-e649e62f125244a3ef116be25dfdc81a2afbaf2a + version: 1.2.3-stable - name: Print Versions run: | diff --git a/contracts/test/core/BidderRegistryTest.sol b/contracts/test/core/BidderRegistryTest.sol index 5fff62a1c..d5a8e8b3f 100644 --- a/contracts/test/core/BidderRegistryTest.sol +++ b/contracts/test/core/BidderRegistryTest.sol @@ -100,25 +100,23 @@ contract BidderRegistryTest is Test { assertEq(bidderStakeStored2, 2 ether); } - function testFail_BidderStakeAndRegisterAlreadyRegistered() public { + function test_TwoDeposits() public { vm.prank(bidder); bidderRegistry.depositForWindow{value: 2e18 wei}(2); - vm.expectRevert(bytes("")); bidderRegistry.depositForWindow{value: 1 wei}(2); } - function testFail_Receive() public { + function test_BidderRegistryReceive() public { vm.prank(bidder); - vm.expectRevert(bytes("")); - (bool success, ) = address(bidderRegistry).call{value: 1 wei}(""); - require(success, "couldn't transfer to bidder"); + vm.expectRevert(); + payable(address(bidderRegistry)).transfer(1 wei); } - function testFail_Fallback() public { + function test_BidderRegistryFallback() public { vm.prank(bidder); - vm.expectRevert(bytes("")); - (bool success, ) = address(bidderRegistry).call{value: 1 wei}(""); - require(success, "couldn't transfer to bidder"); + bytes memory data = abi.encode(1, 2); + (bool success, ) = address(bidderRegistry).call{value: 1 wei}(data); + require(!success, "should revert"); } function test_SetNewProtocolFeeRecipient() public { @@ -131,9 +129,10 @@ contract BidderRegistryTest is Test { assertEq(recipient, newRecipient); } - function testFail_SetNewProtocolFeeRecipient() public { + function test_RevertWhen_SetNewProtocolFeeRecipient() public { address newRecipient = vm.addr(2); - vm.expectRevert(bytes("")); + vm.prank(vm.addr(1)); + vm.expectRevert(); bidderRegistry.setNewProtocolFeeRecipient(newRecipient); } @@ -146,8 +145,9 @@ contract BidderRegistryTest is Test { assertEq(payoutPeriodBlocks, 890); } - function testFail_SetNewFeePayoutPeriodBlocks() public { - vm.expectRevert(bytes("")); + function test_RevertWhen_SetNewFeePayoutPeriodBlocks() public { + vm.prank(vm.addr(1)); + vm.expectRevert(); bidderRegistry.setNewFeePayoutPeriod(83424); } @@ -157,8 +157,9 @@ contract BidderRegistryTest is Test { assertEq(bidderRegistry.feePercent(), uint16(25)); } - function testFail_SetNewFeePercent() public { - vm.expectRevert(bytes("")); + function test_RevertWhen_SetNewFeePercent() public { + vm.prank(vm.addr(1)); + vm.expectRevert(); bidderRegistry.setNewFeePercent(uint16(25)); } @@ -169,10 +170,11 @@ contract BidderRegistryTest is Test { assertEq(bidderRegistry.preconfManager(), newPreConfContract); } - function testFail_SetPreconfManager() public { - vm.prank(address(this)); - vm.expectRevert(bytes("")); - bidderRegistry.setPreconfManager(address(0)); + function test_RevertWhen_SetPreconfManager() public { + vm.prank(vm.addr(1)); + address newPreConfContract = vm.addr(3); + vm.expectRevert(); + bidderRegistry.setPreconfManager(newPreConfContract); } function test_shouldRetrieveFunds() public { @@ -255,35 +257,20 @@ contract BidderRegistryTest is Test { assertEq(bidderRegistry.lockedFunds(bidder, nextWindow), 63 ether); } - function testFail_shouldRetrieveFundsNotPreConf() public { + function test_RevertWhen_RetrieveFundsNotPreConf() public { vm.prank(bidder); uint256 currentWindow = blockTracker.getCurrentWindow(); uint256 nextWindow = currentWindow + 1; uint64 blockNumber = 66; bidderRegistry.depositForWindow{value: 2 ether}(nextWindow); address provider = vm.addr(4); - vm.expectRevert(bytes("")); bytes32 commitmentDigest = keccak256("1234"); + vm.prank(bidderRegistry.preconfManager()); bidderRegistry.openBid(commitmentDigest, 1 ether, bidder, blockNumber); - bidderRegistry.retrieveFunds(nextWindow, commitmentDigest, payable(provider), bidderRegistry.ONE_HUNDRED_PERCENT()); - } - - function testFail_shouldRetrieveFundsGreaterThanStake() public { - vm.prank(address(this)); - bidderRegistry.setPreconfManager(address(this)); - - vm.prank(bidder); - uint256 currentWindow = blockTracker.getCurrentWindow(); - uint256 nextWindow = currentWindow + 1; - uint64 blockNumber = 66; - bidderRegistry.depositForWindow{value: 2 ether}(nextWindow); - - address provider = vm.addr(4); - vm.expectRevert(bytes("")); - vm.prank(address(this)); - bytes32 commitmentDigest = keccak256("1234"); - bidderRegistry.openBid(commitmentDigest, 3 ether, bidder, blockNumber); - bidderRegistry.retrieveFunds(nextWindow, commitmentDigest, payable(provider), bidderRegistry.ONE_HUNDRED_PERCENT()); + vm.prank(vm.addr(1)); + uint256 residualBidAfterDecay = bidderRegistry.ONE_HUNDRED_PERCENT(); + vm.expectRevert(); + bidderRegistry.retrieveFunds(nextWindow, commitmentDigest, payable(provider), residualBidAfterDecay); } function test_withdrawProviderAmount() public { @@ -308,13 +295,14 @@ contract BidderRegistryTest is Test { assertEq(bidderRegistry.providerAmount(provider), 0); } - function testFail_withdrawProviderAmount() public { + function test_RevertWhen_WithdrawProviderAmount() public { bidderRegistry.setPreconfManager(address(this)); uint256 currentWindow = blockTracker.getCurrentWindow(); uint256 nextWindow = currentWindow + 1; vm.prank(bidder); bidderRegistry.depositForWindow{value: 5 ether}(nextWindow); address provider = vm.addr(4); + vm.expectRevert(); bidderRegistry.withdrawProviderAmount(payable(provider)); } From d9b82dc3b1c80015c59a161241d31934980cc688 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Thu, 24 Jul 2025 11:25:09 -0700 Subject: [PATCH 2/6] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c273946c6..c929cbf2c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -131,7 +131,7 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 with: - version: 1.2.3-stable + version: 1.2.3 - name: Print Versions run: | From 300896121c285aaf7ce74cbb718b7103ccd060c6 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Thu, 24 Jul 2025 11:30:12 -0700 Subject: [PATCH 3/6] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c929cbf2c..1450808aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -131,7 +131,7 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 with: - version: 1.2.3 + version: v1.2.3 - name: Print Versions run: | From 3fbf84ee6e0e4d1bd4a384def0975c1a26fdb906 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Thu, 24 Jul 2025 13:54:14 -0700 Subject: [PATCH 4/6] Update ProviderRegistryTest.sol --- contracts/test/core/ProviderRegistryTest.sol | 33 +++++++------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/contracts/test/core/ProviderRegistryTest.sol b/contracts/test/core/ProviderRegistryTest.sol index cb9608fcf..7c4a630d5 100644 --- a/contracts/test/core/ProviderRegistryTest.sol +++ b/contracts/test/core/ProviderRegistryTest.sol @@ -134,19 +134,10 @@ contract ProviderRegistryTest is Test { assertEq(accumulatedAmount, 0); } - function testFail_ProviderStakeAndRegisterMinStake() public { + function test_RevertWhen_ProviderStakeAndRegisterMinStake() public { vm.deal(provider, 3 ether); vm.prank(provider); - vm.expectRevert(bytes("")); - providerRegistry.registerAndStake{value: 1 wei}(); - } - - function testFail_ProviderStakeAndRegisterInvalidBLSKey() public { - vm.deal(provider, 3 ether); - vm.prank(provider); - vm.expectRevert("Invalid BLS public key length"); - bytes[] memory invalidBLSPubkeys = new bytes[](1); - invalidBLSPubkeys[0] = abi.encodePacked(uint256(134)); + vm.expectRevert(); providerRegistry.registerAndStake{value: 1 wei}(); } @@ -196,7 +187,7 @@ contract ProviderRegistryTest is Test { } } - function testFail_ProviderStakeAndRegisterAlreadyRegistered() public { + function test_RevertWhen_ProviderStakeAndRegisterAlreadyRegistered() public { vm.deal(provider, 3 ether); vm.prank(provider); providerRegistry.registerAndStake{value: 2e18 wei}(); @@ -205,7 +196,7 @@ contract ProviderRegistryTest is Test { providerRegistry.registerAndStake{value: 1 wei}(); } - function testFail_Receive() public { + function test_RevertWhen_Receive() public { vm.deal(provider, 3 ether); vm.prank(provider); vm.expectRevert(bytes("")); @@ -213,7 +204,7 @@ contract ProviderRegistryTest is Test { require(success, "Couldn't transfer to provider"); } - function testFail_Fallback() public { + function test_RevertWhen_Fallback() public { vm.deal(provider, 3 ether); vm.prank(provider); vm.expectRevert(bytes("")); @@ -231,7 +222,7 @@ contract ProviderRegistryTest is Test { assertEq(recipient, newRecipient); } - function testFail_SetNewPenaltyFeeRecipient() public { + function test_RevertWhen_SetNewPenaltyFeeRecipient() public { address newRecipient = vm.addr(2); vm.expectRevert(bytes("")); providerRegistry.setNewPenaltyFeeRecipient(newRecipient); @@ -247,7 +238,7 @@ contract ProviderRegistryTest is Test { assertEq(payoutPeriodMs, 890); } - function testFail_SetNewFeePayoutPeriod() public { + function test_RevertWhen_SetNewFeePayoutPeriod() public { vm.expectRevert(bytes("")); providerRegistry.setFeePayoutPeriod(83424); } @@ -259,7 +250,7 @@ contract ProviderRegistryTest is Test { assertEq(providerRegistry.feePercent(), 25); } - function testFail_SetNewFeePercent() public { + function test_RevertWhen_SetNewFeePercent() public { vm.expectRevert(bytes("")); providerRegistry.setNewFeePercent(25); } @@ -272,7 +263,7 @@ contract ProviderRegistryTest is Test { assertEq(providerRegistry.preconfManager(), newPreConfContract); } - function testFail_SetPreConfContract() public { + function test_RevertWhen_SetPreConfContract() public { vm.prank(address(this)); vm.expectRevert(bytes("")); providerRegistry.setPreconfManager(address(0)); @@ -321,7 +312,7 @@ contract ProviderRegistryTest is Test { assertEq(providerRegistry.providerStakes(provider), 0.9 ether); } - function testFail_ShouldRetrieveFundsNotPreConf() public { + function test_RevertWhen_ShouldRetrieveFundsNotPreConf() public { vm.deal(provider, 3 ether); vm.prank(provider); providerRegistry.registerAndStake{value: 2 ether}(); @@ -509,7 +500,7 @@ contract ProviderRegistryTest is Test { ); } - function testFail_WithdrawStakedAmountUnauthorized() public { + function test_RevertWhen_WithdrawStakedAmountUnauthorized() public { address newProvider = vm.addr(8); vm.deal(newProvider, 3 ether); vm.prank(newProvider); @@ -539,7 +530,7 @@ contract ProviderRegistryTest is Test { ); } - function testFail_WithdrawStakedAmountWithoutCommitments() public { + function test_RevertWhen_WithdrawStakedAmountWithoutCommitments() public { address newProvider = vm.addr(8); vm.deal(newProvider, 3 ether); vm.prank(newProvider); From 5579dc0b9d8b0eabccb46e7020e974ebd7257f9d Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Thu, 24 Jul 2025 14:56:48 -0700 Subject: [PATCH 5/6] Update ProviderRegistryTest.sol --- contracts/test/core/ProviderRegistryTest.sol | 48 ++++++++++++-------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/contracts/test/core/ProviderRegistryTest.sol b/contracts/test/core/ProviderRegistryTest.sol index 7c4a630d5..899fad430 100644 --- a/contracts/test/core/ProviderRegistryTest.sol +++ b/contracts/test/core/ProviderRegistryTest.sol @@ -27,6 +27,7 @@ contract ProviderRegistryTest is Test { hex"bbbbbbbbb1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2"; bytes[] public validBLSPubkeys = [validBLSPubkey]; uint256 public penaltyFeePayoutPeriodMs; + mapping(address => uint256) public commitmentsCount; // For use in test_RevertWhen_WithdrawStakedAmountWithoutCommitments event ProviderRegistered(address indexed provider, uint256 stakedAmount); event WithdrawalRequested(address indexed provider, uint256 timestamp); event WithdrawalCompleted(address indexed provider, uint256 amount); @@ -192,24 +193,22 @@ contract ProviderRegistryTest is Test { vm.prank(provider); providerRegistry.registerAndStake{value: 2e18 wei}(); - vm.expectRevert(bytes("")); + vm.expectRevert(); + vm.prank(provider); providerRegistry.registerAndStake{value: 1 wei}(); } function test_RevertWhen_Receive() public { - vm.deal(provider, 3 ether); vm.prank(provider); - vm.expectRevert(bytes("")); - (bool success, ) = address(providerRegistry).call{value: 1 wei}(""); - require(success, "Couldn't transfer to provider"); + vm.expectRevert(); + payable(address(providerRegistry)).transfer(1 wei); } function test_RevertWhen_Fallback() public { - vm.deal(provider, 3 ether); vm.prank(provider); - vm.expectRevert(bytes("")); - (bool success, ) = address(providerRegistry).call{value: 1 wei}(""); - require(success, "Couldn't transfer to provider"); + bytes memory data = abi.encode(1, 2); + (bool success, ) = address(providerRegistry).call{value: 1 wei}(data); + require(!success, "should revert"); } function test_SetNewPenaltyFeeRecipient() public { @@ -224,7 +223,8 @@ contract ProviderRegistryTest is Test { function test_RevertWhen_SetNewPenaltyFeeRecipient() public { address newRecipient = vm.addr(2); - vm.expectRevert(bytes("")); + vm.expectRevert(); + vm.prank(vm.addr(1)); providerRegistry.setNewPenaltyFeeRecipient(newRecipient); } @@ -239,7 +239,8 @@ contract ProviderRegistryTest is Test { } function test_RevertWhen_SetNewFeePayoutPeriod() public { - vm.expectRevert(bytes("")); + vm.expectRevert(); + vm.prank(vm.addr(1)); providerRegistry.setFeePayoutPeriod(83424); } @@ -251,7 +252,8 @@ contract ProviderRegistryTest is Test { } function test_RevertWhen_SetNewFeePercent() public { - vm.expectRevert(bytes("")); + vm.expectRevert(); + vm.prank(vm.addr(1)); providerRegistry.setNewFeePercent(25); } @@ -264,8 +266,8 @@ contract ProviderRegistryTest is Test { } function test_RevertWhen_SetPreConfContract() public { - vm.prank(address(this)); - vm.expectRevert(bytes("")); + vm.prank(vm.addr(1)); + vm.expectRevert(); providerRegistry.setPreconfManager(address(0)); } @@ -318,13 +320,14 @@ contract ProviderRegistryTest is Test { providerRegistry.registerAndStake{value: 2 ether}(); address bidder = vm.addr(4); - vm.expectRevert(bytes("")); + uint256 residualBidPercentAfterDecay = providerRegistry.ONE_HUNDRED_PERCENT(); + vm.expectRevert(); providerRegistry.slash( 1 ether, 0, provider, payable(bidder), - providerRegistry.ONE_HUNDRED_PERCENT() + residualBidPercentAfterDecay ); } @@ -506,9 +509,13 @@ contract ProviderRegistryTest is Test { vm.prank(newProvider); providerRegistry.registerAndStake{value: 2e18 wei}(); - vm.expectRevert(bytes("")); address wrongNewProvider = vm.addr(12); vm.prank(wrongNewProvider); + vm.expectRevert(); + providerRegistry.unstake(); + + vm.prank(wrongNewProvider); + vm.expectRevert(); providerRegistry.withdraw(); } @@ -531,14 +538,19 @@ contract ProviderRegistryTest is Test { } function test_RevertWhen_WithdrawStakedAmountWithoutCommitments() public { + providerRegistry.setPreconfManager(address(this)); + commitmentsCount[vm.addr(8)] = 2; + address newProvider = vm.addr(8); vm.deal(newProvider, 3 ether); vm.prank(newProvider); providerRegistry.registerAndStake{value: 2e18 wei}(); + vm.prank(newProvider); providerRegistry.unstake(); vm.warp(block.timestamp + 24 hours); // Move forward in time - vm.expectRevert("Provider Commitments still pending"); + vm.expectRevert(abi.encodeWithSelector(IProviderRegistry.ProviderCommitmentsPending.selector, newProvider, 2)); + vm.prank(newProvider); providerRegistry.withdraw(); } From 363a4d7c40e469abf287a875f3634a6a31d24383 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Thu, 24 Jul 2025 15:38:43 -0700 Subject: [PATCH 6/6] fixed remaining tests --- contracts/test/standard-bridge/L1GatewayTest.sol | 14 ++++++++------ .../test/standard-bridge/SettlementGatewayTest.sol | 14 ++++++++------ .../validator-registry/VanillaRegistryTest.sol | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/contracts/test/standard-bridge/L1GatewayTest.sol b/contracts/test/standard-bridge/L1GatewayTest.sol index e18f0ed34..2bf8c59b7 100644 --- a/contracts/test/standard-bridge/L1GatewayTest.sol +++ b/contracts/test/standard-bridge/L1GatewayTest.sol @@ -127,13 +127,15 @@ contract L1GatewayTest is Test { assertEq(l1Gateway.transferInitiatedIdx(), 0); assertEq(l1Gateway.transferFinalizedIdx(), 1); - vm.expectRevert(); vm.prank(bridgeUser); - l1Gateway.initiateTransfer{value: 0.9 ether}(bridgeUser, 0.9 ether); - - assertEq(address(bridgeUser).balance, 0.01 ether); - assertEq(l1Gateway.transferInitiatedIdx(), 0); - assertEq(l1Gateway.transferFinalizedIdx(), 1); + // Foundry 1.2.x onward doesn't support vm.expectRevert() for catching EvmError: OutOfFunds. We'll use try/catch instead. + try l1Gateway.initiateTransfer{value: 0.9 ether}(bridgeUser, 0.9 ether) { + fail(); // Call should not succeed + } catch { + assertEq(address(bridgeUser).balance, 0.01 ether); + assertEq(l1Gateway.transferInitiatedIdx(), 0); + assertEq(l1Gateway.transferFinalizedIdx(), 1); + } } function test_InitiateTransferValueMismatch() public { diff --git a/contracts/test/standard-bridge/SettlementGatewayTest.sol b/contracts/test/standard-bridge/SettlementGatewayTest.sol index 32b65a553..4ef7e1a87 100644 --- a/contracts/test/standard-bridge/SettlementGatewayTest.sol +++ b/contracts/test/standard-bridge/SettlementGatewayTest.sol @@ -152,13 +152,15 @@ contract SettlementGatewayTest is Test { assertEq(settlementGateway.transferInitiatedIdx(), 0); assertEq(settlementGateway.transferFinalizedIdx(), 1); - vm.expectRevert(); vm.prank(bridgeUser); - settlementGateway.initiateTransfer{value: 0.9 ether}(bridgeUser, 0.9 ether); - - assertEq(address(bridgeUser).balance, 0.01 ether); - assertEq(settlementGateway.transferInitiatedIdx(), 0); - assertEq(settlementGateway.transferFinalizedIdx(), 1); + // Foundry 1.2.x onward doesn't support vm.expectRevert() for catching EvmError: OutOfFunds. We'll use try/catch instead. + try settlementGateway.initiateTransfer{value: 0.9 ether}(bridgeUser, 0.9 ether) { + fail(); // Call should not succeed + } catch { + assertEq(address(bridgeUser).balance, 0.01 ether); + assertEq(settlementGateway.transferInitiatedIdx(), 0); + assertEq(settlementGateway.transferFinalizedIdx(), 1); + } } function test_InitiateTransferValueMismatch() public { diff --git a/contracts/test/validator-registry/VanillaRegistryTest.sol b/contracts/test/validator-registry/VanillaRegistryTest.sol index 367170772..b8d09c720 100644 --- a/contracts/test/validator-registry/VanillaRegistryTest.sol +++ b/contracts/test/validator-registry/VanillaRegistryTest.sol @@ -889,6 +889,8 @@ contract VanillaRegistryTest is Test { stakers[0] = user1; validatorRegistry.whitelistStakers(stakers); + vm.deal(user1, MIN_STAKE); + bytes[] memory validators = new bytes[](1); validators[0] = user1BLSKey; vm.startPrank(user1); @@ -906,7 +908,6 @@ contract VanillaRegistryTest is Test { vm.stopPrank(); vm.startPrank(user1); - vm.deal(user1, MIN_STAKE); validatorRegistry.stake{value: MIN_STAKE}(validators); vm.stopPrank();