diff --git a/test/LegacyCollectTest.t.sol b/test/LegacyCollectTest.t.sol index 961656b..37824db 100644 --- a/test/LegacyCollectTest.t.sol +++ b/test/LegacyCollectTest.t.sol @@ -98,6 +98,51 @@ contract LegacyCollectTest is BaseTest, ReferralSystemTest { _collect(defaultAccount.ownerPk, defaultCollectParams); } + function testCannotExecuteOperationIf_ReferralProfileIdsPassedQty_DiffersFromPubIdsQty() public override { + // ReferralSystem inherited test that does not apply to this file. + } + + function testCannotPass_TargetedPublication_AsReferrer() public override { + // Note: The following publication is converted to Legacy V1 in this test's setUp. + TestPublication memory targetPub = TestPublication(defaultAccount.profileId, pubId); + + _referralSystem_PrepareOperation( + targetPub, + _toUint256Array(targetPub.profileId), + _toUint256Array(targetPub.pubId) + ); + vm.expectRevert(Errors.InvalidReferrer.selector); + _referralSystem_ExecutePreparedOperation(); + } + + function testCannotPass_UnexistentProfile_AsReferrer(uint256 unexistentProfileId, uint8 anyPubId) public override { + // Note: The following publication is converted to Legacy V1 in this test's setUp. + TestPublication memory targetPub = TestPublication(defaultAccount.profileId, pubId); + + vm.assume(!hub.exists(unexistentProfileId)); + vm.assume(anyPubId != 0); + _referralSystem_PrepareOperation(targetPub, _toUint256Array(unexistentProfileId), _toUint256Array(anyPubId)); + vm.expectRevert(Errors.InvalidReferrer.selector); + _referralSystem_ExecutePreparedOperation(); + } + + function testCannotPass_UnexistentPublication_AsReferrer(uint256 unexistentPubId) public override { + // Note: The following publication is converted to Legacy V1 in this test's setUp. + TestPublication memory targetPub = TestPublication(defaultAccount.profileId, pubId); + + TestPublication memory pub = _comment(targetPub); + uint256 existentProfileId = pub.profileId; + vm.assume(unexistentPubId > pub.pubId); + + _referralSystem_PrepareOperation( + targetPub, + _toUint256Array(existentProfileId), + _toUint256Array(unexistentPubId) + ); + vm.expectRevert(Errors.InvalidReferrer.selector); + _referralSystem_ExecutePreparedOperation(); + } + function testCollect() public { Types.Publication memory pub = hub.getPublication(defaultAccount.profileId, pubId); assertTrue(pub.__DEPRECATED__collectNFT == address(0)); @@ -218,8 +263,8 @@ contract LegacyCollectTest is BaseTest, ReferralSystemTest { function _referralSystem_ExpectRevertsIfNeeded( TestPublication memory target, - uint256[] memory referrerProfileIds, - uint256[] memory referrerPubIds + uint256[] memory /* referrerProfileIds */, + uint256[] memory /* referrerPubIds */ ) internal virtual override returns (bool) { if (skipTest) { return true; @@ -267,16 +312,16 @@ contract LegacyCollectTest is BaseTest, ReferralSystemTest { } function _referralSystem_ExecutePreparedOperation() internal virtual override { - console.log( - 'LEGACY COLLECTING: (%s, %s)', - defaultCollectParams.publicationCollectedProfileId, - defaultCollectParams.publicationCollectedId - ); - console.log( - ' with referrer: (%s, %s)', - defaultCollectParams.referrerProfileId, - defaultCollectParams.referrerPubId - ); + // console.log( + // 'LEGACY COLLECTING: (%s, %s)', + // defaultCollectParams.publicationCollectedProfileId, + // defaultCollectParams.publicationCollectedId + // ); + // console.log( + // ' with referrer: (%s, %s)', + // defaultCollectParams.referrerProfileId, + // defaultCollectParams.referrerPubId + // ); if (skipTest) { console.log(' ^^^ SKIPPED ^^^'); return; diff --git a/test/ReferralSystem.t.sol b/test/ReferralSystem.t.sol index 3d5f35c..be9baba 100644 --- a/test/ReferralSystem.t.sol +++ b/test/ReferralSystem.t.sol @@ -122,11 +122,11 @@ abstract contract ReferralSystemTest is BaseTest { for (uint256 i = 0; i < treeV2.references.length; i++) { TestPublication memory target = treeV2.references[i]; for (uint256 j = 0; j < treeV2.references.length; j++) { - TestPublication memory referralPub = treeV2.references[j]; + TestPublication memory quoteOrCommentAsReferralPub = treeV2.references[j]; if (i == j) continue; // skip self // vm.expectCall /* */(); - _executeOperation(target, referralPub); + _executeOperation(target, quoteOrCommentAsReferralPub); } // One special case is a post as referal for reference node @@ -166,7 +166,6 @@ abstract contract ReferralSystemTest is BaseTest { function testV1_TargetPost_ReferralMirror(uint256 v1FuzzBitmap) public virtual { vm.assume(v1FuzzBitmap < 2 ** 11); - uint256 commentQuoteFuzzBitmap = 0; Tree memory treeV1 = _createV1Tree(v1FuzzBitmap); // Target a post with mirrors as referrals @@ -186,9 +185,6 @@ abstract contract ReferralSystemTest is BaseTest { for (uint256 i = 0; i < treeV1.references.length; i++) { TestPublication memory target = treeV1.references[i]; - // check if target is V2 or V1 - Types.Publication memory targetPublication = hub.getPublication(target.profileId, target.pubId); - _referralSystem_PrepareOperation(target, referralPub); // Shoule revert as V1-contaminated trees don't have a root and only allow downwards referrals @@ -475,7 +471,7 @@ abstract contract ReferralSystemTest is BaseTest { return TestPublication(publisher.profileId, pubId); } - function testCannotExecuteOperationIf_ReferralProfileIdsPassedQty_DiffersFromPubIdsQty() public { + function testCannotExecuteOperationIf_ReferralProfileIdsPassedQty_DiffersFromPubIdsQty() public virtual { Types.PostParams memory postParams = _getDefaultPostParams(); postParams.referenceModule = address(mockReferenceModule); postParams.referenceModuleInitData = abi.encode(true); @@ -493,7 +489,7 @@ abstract contract ReferralSystemTest is BaseTest { _referralSystem_ExecutePreparedOperation(); } - function testCannotPass_TargetedPublication_AsReferrer() public { + function testCannotPass_TargetedPublication_AsReferrer() public virtual { Types.PostParams memory postParams = _getDefaultPostParams(); postParams.referenceModule = address(mockReferenceModule); postParams.referenceModuleInitData = abi.encode(true); @@ -505,7 +501,7 @@ abstract contract ReferralSystemTest is BaseTest { _referralSystem_ExecutePreparedOperation(); } - function testCannotPass_UnexistentProfile_AsReferrer(uint256 unexistentProfileId, uint8 pubId) public { + function testCannotPass_UnexistentProfile_AsReferrer(uint256 unexistentProfileId, uint8 pubId) public virtual { Types.PostParams memory postParams = _getDefaultPostParams(); postParams.referenceModule = address(mockReferenceModule); postParams.referenceModuleInitData = abi.encode(true); @@ -519,7 +515,7 @@ abstract contract ReferralSystemTest is BaseTest { _referralSystem_ExecutePreparedOperation(); } - function testCannotPass_UnexistentPublication_AsReferrer(uint256 unexistentPubId) public { + function testCannotPass_UnexistentPublication_AsReferrer(uint256 unexistentPubId) public virtual { Types.PostParams memory postParams = _getDefaultPostParams(); postParams.referenceModule = address(mockReferenceModule); postParams.referenceModuleInitData = abi.encode(true);