Skip to content

Commit cbaa5b3

Browse files
authored
[Fil 1296] client sc store allocation id and size per deal for claim extension (#10)
1 parent 3a691a3 commit cbaa5b3

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

src/Client.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable, Ree
469469

470470
for (uint256 i = 0; i < claimsDetails.claims.length; i++) {
471471
VerifRegTypes.Claim memory claim = claimsDetails.claims[i];
472+
deal.allocationIds.push(claimIds[i]);
472473
deal.sizeOfAllocations += claim.size;
473474
}
474475
}

test/Client.t.sol

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ contract ClientTest is Test {
9393
actorIdMock.setGetClaimsResult(
9494
hex"8282018081881903E81866D82A5828000181E203922020071E414627E89D421B3BAFCCB24CBA13DDE9B6F388706AC8B1D48E58935C76381908001A003815911A005034D60000"
9595
);
96+
actorIdMock.setDataCapTransferResult(hex"834100410049838201808200808101");
9697
// --- Dummy transfer params ---
9798
transferParams = DataCapTypes.TransferParams({
9899
to: CommonTypes.FilAddress(transferTo),
@@ -159,13 +160,14 @@ contract ClientTest is Test {
159160
assertEq(clientAllocationIdsBefore.length, 0);
160161

161162
transferParams.operator_data =
162-
hex"828186192710D82A5828000181E203922020F2B9A58BBC9D9856E52EAB85155C1BA298F7E8DF458BD20A3AD767E11572CA221908001A0007E9001A005033401901318183192710011A005034AC";
163+
hex"828186192710D82A5828000181E203922020F2B9A58BBC9D9856E52EAB85155C1BA298F7E8DF458BD20A3AD767E11572CA221908001A0007E9001A005033401901318183192710021A005034AC";
163164
vm.prank(clientAddress);
164165
client.transfer(transferParams, dealId, false);
165166

166167
CommonTypes.FilActorId[] memory clientAllocationIdsAfter = client.getClientAllocationIdsPerDeal(dealId);
167-
assertEq(clientAllocationIdsAfter.length, 1);
168-
assertEq(CommonTypes.FilActorId.unwrap(clientAllocationIdsAfter[0]), 1);
168+
assertEq(clientAllocationIdsAfter.length, 2);
169+
assertEq(CommonTypes.FilActorId.unwrap(clientAllocationIdsAfter[0]), 2);
170+
assertEq(CommonTypes.FilActorId.unwrap(clientAllocationIdsAfter[1]), 1);
169171
}
170172

171173
function testInvalidClaimExtensionRequest() public {
@@ -485,4 +487,42 @@ contract ClientTest is Test {
485487
vm.expectRevert(abi.encodeWithSelector(ReentrancyGuard.ReentrancyGuardReentrantCall.selector));
486488
client.transfer(transferParams, dealId, false);
487489
}
490+
491+
function testShouldAddClaimExtensionIdsAfterTransfer() public {
492+
ClientContractMock clientMock = ClientContractMock(setupProxy(address(new ClientContractMock())));
493+
transferParams.operator_data =
494+
hex"828186192710D82A5828000181E203922020F2B9A58BBC9D9856E52EAB85155C1BA298F7E8DF458BD20A3AD767E11572CA221908001A0007E9001A005033401901318183192710031A005034AC";
495+
496+
vm.prank(clientAddress);
497+
clientMock.transfer(transferParams, dealId, false);
498+
499+
poRepMarketMock.setDealProposal(
500+
dealId,
501+
PoRepMarket.DealProposal({
502+
dealId: 150,
503+
client: clientAddress,
504+
provider: SP1,
505+
requirements: SLIThresholds(80, 500, 200, 90),
506+
validator: address(validatorMock),
507+
state: PoRepMarket.DealState.Accepted,
508+
railId: 0
509+
})
510+
);
511+
// solhint-disable-next-line reentrancy
512+
transferParams.operator_data =
513+
hex"828286192710D82A5828000181E203922020F2B9A58BBC9D9856E52EAB85155C1BA298F7E8DF458BD20A3AD767E11572CA221908001A0007E9001A0050334019013186192710D82A5828000181E203922020F2B9A58BBC9D9856E52EAB85155C1BA298F7E8DF458BD20A3AD767E11572CA221950001A0007E9001A009C7E801901318183192710041A005034AC";
514+
actorIdMock.setDataCapTransferResult(hex"834100410049838201808200808102");
515+
vm.expectEmit(true, true, true, true);
516+
emit Client.ValidatorLockupPeriodUpdated(dealId, address(validatorMock));
517+
518+
vm.prank(clientAddress);
519+
clientMock.transfer(transferParams, dealId, false);
520+
521+
Client.Deal memory deal = clientMock.getDeal(dealId);
522+
assertEq(deal.allocationIds.length, 4);
523+
assertTrue(CommonTypes.FilActorId.unwrap(deal.allocationIds[0]) == 3);
524+
assertTrue(CommonTypes.FilActorId.unwrap(deal.allocationIds[1]) == 1);
525+
assertTrue(CommonTypes.FilActorId.unwrap(deal.allocationIds[2]) == 4);
526+
assertTrue(CommonTypes.FilActorId.unwrap(deal.allocationIds[3]) == 2);
527+
}
488528
}

test/contracts/ActorIdMock.sol

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pragma solidity 0.8.25;
55

66
contract ActorIdMock {
77
bytes internal _getClaimsResult;
8+
bytes internal _dataCapTransferResult;
89
uint256 internal constant VERIFREG_GET_CLAIMS = 2199871187;
910
uint256 internal constant ADD_VERIFIED_CLIENT = 3916220144;
1011
uint256 internal constant IS_CONTROLLING_ADDRESS = 348244887;
@@ -21,6 +22,10 @@ contract ActorIdMock {
2122
_getClaimsResult = d;
2223
}
2324

25+
function setDataCapTransferResult(bytes memory d) public {
26+
_dataCapTransferResult = d;
27+
}
28+
2429
// solhint-disable-next-line no-complex-fallback
2530
fallback(bytes calldata data) external payable returns (bytes memory) {
2631
(uint256 methodNum,,,,, uint64 target) = abi.decode(data, (uint64, uint256, uint64, uint64, bytes, uint64));
@@ -49,8 +54,8 @@ contract ActorIdMock {
4954
return abi.encode(0, 0x51, _getClaimsResult);
5055
}
5156

52-
function _handleDatacapTransfer() internal pure returns (bytes memory) {
53-
return abi.encode(0, 0x51, hex"834100410049838201808200808101");
57+
function _handleDatacapTransfer() internal view returns (bytes memory) {
58+
return abi.encode(0, 0x51, _dataCapTransferResult);
5459
}
5560

5661
function _handleGetOwnerReturn(uint64 target) internal pure returns (bytes memory) {

0 commit comments

Comments
 (0)