Skip to content

Commit 86497ea

Browse files
committed
tests refactor
1 parent efe07cc commit 86497ea

File tree

3 files changed

+62
-44
lines changed

3 files changed

+62
-44
lines changed

src/Client.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,8 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable, Ree
553553
< currentEpoch;
554554

555555
uint64 id = CommonTypes.FilActorId.unwrap(ids[i]);
556-
bool terminated = $._terminatedClaims[id];
557556

558-
if (expired || terminated) {
557+
if (expired || $._terminatedClaims[id]) {
559558
_deleteDealAllocationIdByValue(dealId, deal, id);
560559
continue;
561560
}

test/Client.t.sol

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -496,36 +496,44 @@ contract ClientTest is Test {
496496
}
497497

498498
function testIsDataSizeMatchingHappyPath() public {
499+
ClientContractMock clientMock = ClientContractMock(setupProxy(address(new ClientContractMock())));
500+
499501
transferParams.operator_data = hex"82808183192710011A005034AC";
500502
vm.prank(clientAddress);
501-
client.transfer(transferParams, dealId, false);
503+
clientMock.transfer(transferParams, dealId, false);
502504

503-
CommonTypes.FilActorId[] memory claimIds = client.getClientAllocationIdsPerDeal(dealId);
504-
assertEq(claimIds.length, 1);
505-
assertEq(CommonTypes.FilActorId.unwrap(claimIds[0]), 1);
505+
clientMock.addDealAllocationId(dealId, 1);
506506

507-
bool ok = client.isDataSizeMatching(dealId);
507+
CommonTypes.FilActorId[] memory ids = clientMock.getClientAllocationIdsPerDeal(dealId);
508+
assertEq(ids.length, 1);
509+
assertEq(CommonTypes.FilActorId.unwrap(ids[0]), 1);
510+
511+
bool ok = clientMock.isDataSizeMatching(dealId);
508512
assertTrue(ok);
509513
}
510514

511515
function testIsDataSizeMatchingRemovesTerminatedClaimAndReturnsFalse() public {
516+
ClientContractMock clientMock = ClientContractMock(setupProxy(address(new ClientContractMock())));
517+
512518
transferParams.operator_data = hex"82808183192710011A005034AC";
513519
vm.prank(clientAddress);
514-
client.transfer(transferParams, dealId, false);
520+
clientMock.transfer(transferParams, dealId, false);
521+
522+
clientMock.addDealAllocationId(dealId, 1);
515523

516524
uint64[] memory claims = new uint64[](1);
517525
claims[0] = 1;
518526

519527
vm.prank(terminationOracle);
520-
client.claimsTerminatedEarly(claims);
528+
clientMock.claimsTerminatedEarly(claims);
521529

522-
CommonTypes.FilActorId[] memory beforeIds = client.getClientAllocationIdsPerDeal(dealId);
530+
CommonTypes.FilActorId[] memory beforeIds = clientMock.getClientAllocationIdsPerDeal(dealId);
523531
assertEq(beforeIds.length, 1);
524532

525-
bool ok = client.isDataSizeMatching(dealId);
533+
bool ok = clientMock.isDataSizeMatching(dealId);
526534
assertTrue(!ok);
527535

528-
CommonTypes.FilActorId[] memory afterIds = client.getClientAllocationIdsPerDeal(dealId);
536+
CommonTypes.FilActorId[] memory afterIds = clientMock.getClientAllocationIdsPerDeal(dealId);
529537
assertEq(afterIds.length, 0);
530538
}
531539

@@ -544,21 +552,25 @@ contract ClientTest is Test {
544552
}
545553

546554
function testIsDataSizeMatchingSkipsFailCodes() public {
555+
ClientContractMock clientMock = ClientContractMock(setupProxy(address(new ClientContractMock())));
556+
547557
transferParams.operator_data = hex"82808183192710011A005034AC";
548558
vm.prank(clientAddress);
549-
client.transfer(transferParams, dealId, false);
559+
clientMock.transfer(transferParams, dealId, false);
560+
561+
clientMock.addDealAllocationId(dealId, 1);
550562

551563
actorIdMock.setGetClaimsResult(
552564
hex"8282008182001081881903E81866D82A5828000181E203922020071E414627E89D421B3BAFCCB24CBA13DDE9B6F388706AC8B1D48E58935C76381908001A003815911A005034D60000"
553565
);
554566

555-
CommonTypes.FilActorId[] memory beforeIds = client.getClientAllocationIdsPerDeal(dealId);
567+
CommonTypes.FilActorId[] memory beforeIds = clientMock.getClientAllocationIdsPerDeal(dealId);
556568
assertEq(beforeIds.length, 1);
557569

558-
bool ok = client.isDataSizeMatching(dealId);
570+
bool ok = clientMock.isDataSizeMatching(dealId);
559571
assertTrue(!ok);
560572

561-
CommonTypes.FilActorId[] memory afterIds = client.getClientAllocationIdsPerDeal(dealId);
573+
CommonTypes.FilActorId[] memory afterIds = clientMock.getClientAllocationIdsPerDeal(dealId);
562574
assertEq(afterIds.length, 1);
563575
assertEq(CommonTypes.FilActorId.unwrap(afterIds[0]), 1);
564576
}
@@ -573,28 +585,31 @@ contract ClientTest is Test {
573585
}
574586

575587
function testIsDataSizeMatchingRemovesTerminatedClaimId() public {
588+
ClientContractMock clientMock = ClientContractMock(setupProxy(address(new ClientContractMock())));
589+
576590
actorIdMock.setGetClaimsResult(
577591
hex"8282028082881903E81866D82A5828000181E203922020071E414627E89D421B3BAFCCB24CBA13DDE9B6F388706AC8B1D48E58935C76381908001A003815911A005034D60000881903E81866D82A5828000181E203922020071E414627E89D421B3BAFCCB24CBA13DDE9B6F388706AC8B1D48E58935C76381908001A003815911A005034D60000"
578592
);
579593

580594
transferParams.operator_data = hex"82808283192710011A005034AC83192710021A005034AC";
581595
vm.prank(clientAddress);
582-
client.transfer(transferParams, dealId, false);
596+
clientMock.transfer(transferParams, dealId, false);
583597

584-
CommonTypes.FilActorId[] memory beforeIds = client.getClientAllocationIdsPerDeal(dealId);
598+
clientMock.addDealAllocationId(dealId, 1);
599+
clientMock.addDealAllocationId(dealId, 2);
600+
601+
CommonTypes.FilActorId[] memory beforeIds = clientMock.getClientAllocationIdsPerDeal(dealId);
585602
assertEq(beforeIds.length, 2);
586-
assertEq(CommonTypes.FilActorId.unwrap(beforeIds[0]), 1);
587-
assertEq(CommonTypes.FilActorId.unwrap(beforeIds[1]), 2);
588603

589604
uint64[] memory claims = new uint64[](1);
590605
claims[0] = 1;
591606

592607
vm.prank(terminationOracle);
593-
client.claimsTerminatedEarly(claims);
608+
clientMock.claimsTerminatedEarly(claims);
594609

595-
client.isDataSizeMatching(dealId);
610+
clientMock.isDataSizeMatching(dealId);
596611

597-
CommonTypes.FilActorId[] memory afterIds = client.getClientAllocationIdsPerDeal(dealId);
612+
CommonTypes.FilActorId[] memory afterIds = clientMock.getClientAllocationIdsPerDeal(dealId);
598613
assertEq(afterIds.length, 1);
599614
assertEq(CommonTypes.FilActorId.unwrap(afterIds[0]), 2);
600615
}
@@ -629,28 +644,28 @@ contract ClientTest is Test {
629644
assertTrue(!isFourthClaimTerminated);
630645
}
631646

632-
function testDeleteDealClaimIdByValueRevertsWhenNotFound() public {
647+
function testDeleteDealAllocationIdByValueRevertsWhenNotFound() public {
633648
ClientContractMock mock = ClientContractMock(setupProxy(address(new ClientContractMock())));
634649

635650
uint256 localDealId = 123;
636651

637-
mock.addDealClaimId(localDealId, 1);
638-
mock.addDealClaimId(localDealId, 2);
652+
mock.addDealAllocationId(localDealId, 1);
653+
mock.addDealAllocationId(localDealId, 2);
639654

640655
vm.expectRevert(abi.encodeWithSelector(Client.DealAllocationNotFound.selector, localDealId, uint64(3)));
641-
mock.deleteDealClaimIdByValue(localDealId, uint64(3));
656+
mock.deleteDealAllocationIdByValue(localDealId, uint64(3));
642657
}
643658

644-
function testDeleteDealClaimIdByValue() public {
659+
function testDeleteDealAllocationIdByValue() public {
645660
ClientContractMock mock = ClientContractMock(setupProxy(address(new ClientContractMock())));
646661

647662
uint256 localDealId = 123;
648663

649-
mock.addDealClaimId(localDealId, 1);
650-
mock.addDealClaimId(localDealId, 2);
651-
mock.addDealClaimId(localDealId, 3);
664+
mock.addDealAllocationId(localDealId, 1);
665+
mock.addDealAllocationId(localDealId, 2);
666+
mock.addDealAllocationId(localDealId, 3);
652667

653-
mock.deleteDealClaimIdByValue(localDealId, 2);
668+
mock.deleteDealAllocationIdByValue(localDealId, 2);
654669

655670
CommonTypes.FilActorId[] memory afterIds = mock.getClientAllocationIdsPerDeal(localDealId);
656671

@@ -659,28 +674,32 @@ contract ClientTest is Test {
659674
assertEq(CommonTypes.FilActorId.unwrap(afterIds[1]), 3);
660675
}
661676

662-
function testDeleteDealClaimIdByValueRevertsWhenEmpty() public {
677+
function testDeleteDealAllocationIdByValueRevertsWhenEmpty() public {
663678
ClientContractMock mock = ClientContractMock(setupProxy(address(new ClientContractMock())));
664679

665680
uint256 newDealId = 123;
666-
uint64 missingClaimId = 1;
681+
uint64 missingAllocationId = 1;
667682

668-
vm.expectRevert(abi.encodeWithSelector(Client.DealAllocationNotFound.selector, newDealId, missingClaimId));
669-
mock.deleteDealClaimIdByValue(newDealId, missingClaimId);
683+
vm.expectRevert(abi.encodeWithSelector(Client.DealAllocationNotFound.selector, newDealId, missingAllocationId));
684+
mock.deleteDealAllocationIdByValue(newDealId, missingAllocationId);
670685
}
671686

672687
function testIsDataSizeMatchingRevertsWhenGetClaimsExitCodeNonZero() public {
688+
ClientContractMock clientMock = ClientContractMock(setupProxy(address(new ClientContractMock())));
689+
673690
transferParams.operator_data = hex"82808183192710011A005034AC";
674691
vm.prank(clientAddress);
675-
client.transfer(transferParams, dealId, false);
692+
clientMock.transfer(transferParams, dealId, false);
693+
694+
clientMock.addDealAllocationId(dealId, 1);
676695

677-
CommonTypes.FilActorId[] memory claimIds = client.getClientAllocationIdsPerDeal(dealId);
678-
assertEq(claimIds.length, 1);
696+
CommonTypes.FilActorId[] memory ids = clientMock.getClientAllocationIdsPerDeal(dealId);
697+
assertEq(ids.length, 1);
679698

680699
ActorIdExitCodeErrorFailingMock failing = new ActorIdExitCodeErrorFailingMock();
681700
vm.etch(CALL_ACTOR_ID, address(failing).code);
682701

683702
vm.expectRevert(Client.GetClaimsCallFailed.selector);
684-
client.isDataSizeMatching(dealId);
703+
clientMock.isDataSizeMatching(dealId);
685704
}
686705
}

test/contracts/ClientContractMock.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ contract ClientContractMock is Client {
1010
return s()._deals[dealId];
1111
}
1212

13-
function addDealClaimId(uint256 dealId, uint64 claimId) external {
14-
s()._deals[dealId].allocationIds.push(CommonTypes.FilActorId.wrap(claimId));
13+
function addDealAllocationId(uint256 dealId, uint64 allocationId) external {
14+
s()._deals[dealId].allocationIds.push(CommonTypes.FilActorId.wrap(allocationId));
1515
}
1616

17-
function deleteDealClaimIdByValue(uint256 dealId, uint64 claimId) external {
17+
function deleteDealAllocationIdByValue(uint256 dealId, uint64 allocationId) external {
1818
Deal storage deal = s()._deals[dealId];
19-
_deleteDealAllocationIdByValue(dealId, deal, claimId);
19+
_deleteDealAllocationIdByValue(dealId, deal, allocationId);
2020
}
2121
}

0 commit comments

Comments
 (0)