From fbc9df7315bc2f18d0ee028ff404dc3fcd7b0e66 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Tue, 5 Mar 2024 16:06:12 -0500 Subject: [PATCH] Adds more testing. --- contracts/Oracle.sol | 2 +- test/PreConfirmationConfTest.sol | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/contracts/Oracle.sol b/contracts/Oracle.sol index 2d295ed..66f68b6 100644 --- a/contracts/Oracle.sol +++ b/contracts/Oracle.sol @@ -100,7 +100,7 @@ contract Oracle is Ownable { ) external onlyOwner { // Check graffiti against registered builder IDs address builder = blockBuilderNameToAddress[blockBuilderName]; - + require(residualBidAfterDecay <= 100, "Residual bid after decay cannot be greater than 100 percent"); IPreConfCommitmentStore.PreConfCommitment memory commitment = preConfContract.getCommitment(commitmentIndex); if (commitment.commiter == builder && commitment.blockNumber == blockNumber) { processCommitment(commitmentIndex, isSlash, residualBidAfterDecay); diff --git a/test/PreConfirmationConfTest.sol b/test/PreConfirmationConfTest.sol index a5584e5..34ffc8e 100644 --- a/test/PreConfirmationConfTest.sol +++ b/test/PreConfirmationConfTest.sol @@ -502,6 +502,65 @@ contract TestPreConfCommitmentStore is Test { } } + + function test_InitiateRewardFullyDecayed() public { + // Assuming you have a stored commitment + { + (address bidder, ) = makeAddrAndKey("alice"); + vm.deal(bidder, 5 ether); + vm.prank(bidder); + bidderRegistry.prepay{value: 2 ether}(); + + // Step 1: Verify that the commitment has not been used before + bytes32 bidHash = verifyCommitmentNotUsed( + _testCommitmentAliceBob.txnHash, + _testCommitmentAliceBob.bid, + _testCommitmentAliceBob.blockNumber, + _testCommitmentAliceBob.decayStartTimestamp, + _testCommitmentAliceBob.decayEndTimestamp, + _testCommitmentAliceBob.bidSignature + ); + bytes32 preConfHash = preConfCommitmentStore.getPreConfHash( + _testCommitmentAliceBob.txnHash, + _testCommitmentAliceBob.bid, + _testCommitmentAliceBob.blockNumber, + _testCommitmentAliceBob.decayStartTimestamp, + _testCommitmentAliceBob.decayEndTimestamp, + bidHash, + _bytesToHexString(_testCommitmentAliceBob.bidSignature) + ); + + // Verify that the commitment has not been used before + (bool commitmentUsed, , , , , , , , , , , , ) = preConfCommitmentStore + .commitments(preConfHash); + assert(commitmentUsed == false); + bytes32 index = preConfCommitmentStore.storeCommitment( + _testCommitmentAliceBob.bid, + _testCommitmentAliceBob.blockNumber, + _testCommitmentAliceBob.txnHash, + _testCommitmentAliceBob.decayStartTimestamp, + _testCommitmentAliceBob.decayEndTimestamp, + _testCommitmentAliceBob.bidSignature, + _testCommitmentAliceBob.commitmentSignature + ); + (address commiter, ) = makeAddrAndKey("bob"); + vm.deal(commiter, 5 ether); + vm.prank(commiter); + providerRegistry.registerAndStake{value: 4 ether}(); + vm.prank(feeRecipient); + preConfCommitmentStore.initiateReward(index, 0); + + (commitmentUsed, , , , , , , , , , , , ) = preConfCommitmentStore + .commitments(index); + // Verify that the commitment has been marked as used + assert(commitmentUsed == true); + // commitmentHash value is internal to contract and not asserted + + assert(bidderRegistry.bidderPrepaidBalances(bidder) == 2 ether); + assert(bidderRegistry.providerAmount(commiter) == 0 ether); + } + + } function _bytesToHexString( bytes memory _bytes ) public pure returns (string memory) {