Skip to content

Commit 7f075c3

Browse files
committed
tests refactor2
1 parent 36d8494 commit 7f075c3

File tree

2 files changed

+30
-36
lines changed

2 files changed

+30
-36
lines changed

test/Client.t.sol

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,16 @@ contract ClientTest is Test {
159159
}
160160

161161
function testShouldAddAllocationsIdsAfterTransfer() public {
162+
ClientContractMock clientMock = ClientContractMock(setupProxy(address(new ClientContractMock())));
162163
CommonTypes.FilActorId[] memory clientAllocationIdsBefore = client.getClientAllocationIdsPerDeal(dealId);
163164
assertEq(clientAllocationIdsBefore.length, 0);
164165

165166
transferParams.operator_data =
166167
hex"828186192710D82A5828000181E203922020F2B9A58BBC9D9856E52EAB85155C1BA298F7E8DF458BD20A3AD767E11572CA221908001A0007E9001A005033401901318183192710021A005034AC";
167168
vm.prank(clientAddress);
168-
client.transfer(transferParams, dealId, false);
169+
clientMock.transfer(transferParams, dealId, false);
169170

170-
CommonTypes.FilActorId[] memory clientAllocationIdsAfter = client.getClientAllocationIdsPerDeal(dealId);
171+
CommonTypes.FilActorId[] memory clientAllocationIdsAfter = clientMock.getClientAllocationIdsPerDeal(dealId);
171172
assertEq(clientAllocationIdsAfter.length, 2);
172173
assertEq(CommonTypes.FilActorId.unwrap(clientAllocationIdsAfter[0]), 2);
173174
assertEq(CommonTypes.FilActorId.unwrap(clientAllocationIdsAfter[1]), 1);
@@ -501,11 +502,10 @@ contract ClientTest is Test {
501502
ClientContractMock clientMock = ClientContractMock(setupProxy(address(new ClientContractMock())));
502503

503504
transferParams.operator_data = hex"82808183192710011A005034AC";
505+
504506
vm.prank(clientAddress);
505507
clientMock.transfer(transferParams, dealId, false);
506508

507-
clientMock.addDealAllocationId(dealId, 1);
508-
509509
CommonTypes.FilActorId[] memory ids = clientMock.getClientAllocationIdsPerDeal(dealId);
510510
assertEq(ids.length, 1);
511511
assertEq(CommonTypes.FilActorId.unwrap(ids[0]), 1);
@@ -521,8 +521,6 @@ contract ClientTest is Test {
521521
vm.prank(clientAddress);
522522
clientMock.transfer(transferParams, dealId, false);
523523

524-
clientMock.addDealAllocationId(dealId, 1);
525-
526524
uint64[] memory claims = new uint64[](1);
527525
claims[0] = 1;
528526

@@ -540,16 +538,18 @@ contract ClientTest is Test {
540538
}
541539

542540
function testIsDataSizeMatchingRemovesExpiredClaimAndReturnsFalse() public {
541+
ClientContractMock clientMock = ClientContractMock(setupProxy(address(new ClientContractMock())));
543542
transferParams.operator_data = hex"82808183192710011A005034AC";
543+
544544
vm.prank(clientAddress);
545-
client.transfer(transferParams, dealId, false);
545+
clientMock.transfer(transferParams, dealId, false);
546546

547547
vm.roll(5256407);
548548

549-
bool ok = client.isDataSizeMatching(dealId);
549+
bool ok = clientMock.isDataSizeMatching(dealId);
550550
assertTrue(!ok);
551551

552-
CommonTypes.FilActorId[] memory afterIds = client.getClientAllocationIdsPerDeal(dealId);
552+
CommonTypes.FilActorId[] memory afterIds = clientMock.getClientAllocationIdsPerDeal(dealId);
553553
assertEq(afterIds.length, 0);
554554
}
555555

@@ -560,8 +560,6 @@ contract ClientTest is Test {
560560
vm.prank(clientAddress);
561561
clientMock.transfer(transferParams, dealId, false);
562562

563-
clientMock.addDealAllocationId(dealId, 1);
564-
565563
actorIdMock.setGetClaimsResult(
566564
hex"8282008182001081881903E81866D82A5828000181E203922020071E414627E89D421B3BAFCCB24CBA13DDE9B6F388706AC8B1D48E58935C76381908001A003815911A005034D60000"
567565
);
@@ -597,9 +595,6 @@ contract ClientTest is Test {
597595
vm.prank(clientAddress);
598596
clientMock.transfer(transferParams, dealId, false);
599597

600-
clientMock.addDealAllocationId(dealId, 1);
601-
clientMock.addDealAllocationId(dealId, 2);
602-
603598
CommonTypes.FilActorId[] memory beforeIds = clientMock.getClientAllocationIdsPerDeal(dealId);
604599
assertEq(beforeIds.length, 2);
605600

@@ -649,31 +644,35 @@ contract ClientTest is Test {
649644
function testDeleteDealAllocationIdByValueRevertsWhenNotFound() public {
650645
ClientContractMock mock = ClientContractMock(setupProxy(address(new ClientContractMock())));
651646

652-
uint256 localDealId = 123;
647+
transferParams.operator_data =
648+
hex"828186192710D82A5828000181E203922020F2B9A58BBC9D9856E52EAB85155C1BA298F7E8DF458BD20A3AD767E11572CA221908001A0007E9001A005033401901318183192710031A005034AC";
653649

654-
mock.addDealAllocationId(localDealId, 1);
655-
mock.addDealAllocationId(localDealId, 2);
650+
vm.prank(clientAddress);
651+
mock.transfer(transferParams, dealId, false);
656652

657-
vm.expectRevert(abi.encodeWithSelector(Client.DealAllocationNotFound.selector, localDealId, uint64(3)));
658-
mock.deleteDealAllocationIdByValue(localDealId, uint64(3));
653+
vm.expectRevert(abi.encodeWithSelector(Client.DealAllocationNotFound.selector, dealId, 999));
654+
mock.deleteDealAllocationIdByValue(dealId, 999);
659655
}
660656

661657
function testDeleteDealAllocationIdByValue() public {
662658
ClientContractMock mock = ClientContractMock(setupProxy(address(new ClientContractMock())));
663659

664-
uint256 localDealId = 123;
660+
transferParams.operator_data =
661+
hex"828186192710D82A5828000181E203922020F2B9A58BBC9D9856E52EAB85155C1BA298F7E8DF458BD20A3AD767E11572CA221908001A0007E9001A005033401901318183192710031A005034AC";
665662

666-
mock.addDealAllocationId(localDealId, 1);
667-
mock.addDealAllocationId(localDealId, 2);
668-
mock.addDealAllocationId(localDealId, 3);
663+
vm.prank(clientAddress);
664+
mock.transfer(transferParams, dealId, false);
669665

670-
mock.deleteDealAllocationIdByValue(localDealId, 2);
666+
CommonTypes.FilActorId[] memory beforeIds = mock.getClientAllocationIdsPerDeal(dealId);
667+
assertEq(beforeIds.length, 2);
668+
assertEq(CommonTypes.FilActorId.unwrap(beforeIds[0]), 3);
669+
assertEq(CommonTypes.FilActorId.unwrap(beforeIds[1]), 1);
671670

672-
CommonTypes.FilActorId[] memory afterIds = mock.getClientAllocationIdsPerDeal(localDealId);
671+
mock.deleteDealAllocationIdByValue(dealId, 3);
673672

674-
assertEq(afterIds.length, 2);
673+
CommonTypes.FilActorId[] memory afterIds = mock.getClientAllocationIdsPerDeal(dealId);
674+
assertEq(afterIds.length, 1);
675675
assertEq(CommonTypes.FilActorId.unwrap(afterIds[0]), 1);
676-
assertEq(CommonTypes.FilActorId.unwrap(afterIds[1]), 3);
677676
}
678677

679678
function testDeleteDealAllocationIdByValueRevertsWhenEmpty() public {
@@ -693,8 +692,6 @@ contract ClientTest is Test {
693692
vm.prank(clientAddress);
694693
clientMock.transfer(transferParams, dealId, false);
695694

696-
clientMock.addDealAllocationId(dealId, 1);
697-
698695
CommonTypes.FilActorId[] memory ids = clientMock.getClientAllocationIdsPerDeal(dealId);
699696
assertEq(ids.length, 1);
700697

@@ -704,7 +701,7 @@ contract ClientTest is Test {
704701
vm.expectRevert(Client.GetClaimsCallFailed.selector);
705702
clientMock.isDataSizeMatching(dealId);
706703
}
707-
704+
708705
function testShouldAddClaimExtensionIdsAfterTransfer() public {
709706
ClientContractMock clientMock = ClientContractMock(setupProxy(address(new ClientContractMock())));
710707
transferParams.operator_data =
@@ -719,7 +716,9 @@ contract ClientTest is Test {
719716
dealId: 150,
720717
client: clientAddress,
721718
provider: SP1,
722-
requirements: SLIThresholds(80, 500, 200, 90),
719+
requirements: SLIThresholds({
720+
retrievabilityPct: 80, bandwidthMbps: 500, latencyMs: 200, indexingPct: 90
721+
}),
723722
validator: address(validatorMock),
724723
state: PoRepMarket.DealState.Accepted,
725724
railId: 0

test/contracts/ClientContractMock.sol

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@
33
pragma solidity ^0.8.24;
44

55
import {Client} from "../../src/Client.sol";
6-
import {CommonTypes} from "filecoin-solidity/v0.8/types/CommonTypes.sol";
76

87
contract ClientContractMock is Client {
98
function getDeal(uint256 dealId) public view returns (Client.Deal memory) {
109
return s()._deals[dealId];
1110
}
1211

13-
function addDealAllocationId(uint256 dealId, uint64 allocationId) external {
14-
s()._deals[dealId].allocationIds.push(CommonTypes.FilActorId.wrap(allocationId));
15-
}
16-
1712
function deleteDealAllocationIdByValue(uint256 dealId, uint64 allocationId) external {
1813
Deal storage deal = s()._deals[dealId];
1914
_deleteDealAllocationIdByValue(dealId, deal, allocationId);

0 commit comments

Comments
 (0)