Skip to content

Commit af5142e

Browse files
committed
cr fixes
1 parent b0caed0 commit af5142e

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/PoRepMarket.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ contract PoRepMarket is Initializable, AccessControlUpgradeable, UUPSUpgradeable
146146
error ValidatorAlreadySet(uint256 dealId);
147147
error InvalidRetrievabilityPct(uint8 value);
148148
error InvalidIndexingPct(uint8 value);
149+
error InvalidRailId();
150+
error RailIdAlreadySet();
149151

150152
/**
151153
* @notice Constructor
@@ -251,6 +253,14 @@ contract PoRepMarket is Initializable, AccessControlUpgradeable, UUPSUpgradeable
251253
_ensureDealExists(dp);
252254
_ensureDealCorrectState(dp, DealState.Accepted);
253255

256+
if (dp.railId != 0) {
257+
revert RailIdAlreadySet();
258+
}
259+
260+
if (railId == 0) {
261+
revert InvalidRailId();
262+
}
263+
254264
if (dp.validator != msg.sender) {
255265
revert NotTheRegisteredValidator(dealId, msg.sender);
256266
}

test/PoRepMarket.t.sol

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,34 @@ contract PoRepMarketTest is Test {
239239
poRepMarket.updateRailId(dealId, railId);
240240
}
241241

242+
function testUpdateRailIdRevertsWhenRailIdIsAlreadySet() public {
243+
vm.prank(clientAddress);
244+
poRepMarket.proposeDeal(defaultRequirements, defaultTerms);
245+
vm.prank(providerOwnerAddress);
246+
poRepMarket.acceptDeal(dealId);
247+
vm.prank(validatorAddress);
248+
poRepMarket.updateValidator(dealId);
249+
vm.prank(validatorAddress);
250+
poRepMarket.updateRailId(dealId, railId);
251+
252+
vm.expectRevert(abi.encodeWithSelector(PoRepMarket.RailIdAlreadySet.selector));
253+
vm.prank(validatorAddress);
254+
poRepMarket.updateRailId(dealId, railId);
255+
}
256+
257+
function testUpdateRailIdRevertsWhenRailIdIsInvalid() public {
258+
vm.prank(clientAddress);
259+
poRepMarket.proposeDeal(defaultRequirements, defaultTerms);
260+
vm.prank(providerOwnerAddress);
261+
poRepMarket.acceptDeal(dealId);
262+
vm.prank(validatorAddress);
263+
poRepMarket.updateValidator(dealId);
264+
265+
vm.expectRevert(abi.encodeWithSelector(PoRepMarket.InvalidRailId.selector));
266+
vm.prank(validatorAddress);
267+
poRepMarket.updateRailId(dealId, 0);
268+
}
269+
242270
function testAcceptDealEmitsDealAcceptedEvent() public {
243271
vm.prank(clientAddress);
244272
poRepMarket.proposeDeal(defaultRequirements, defaultTerms);

0 commit comments

Comments
 (0)