diff --git a/test/ActTest.t.sol b/test/ActTest.t.sol index af00c58..a223b89 100644 --- a/test/ActTest.t.sol +++ b/test/ActTest.t.sol @@ -13,20 +13,22 @@ contract ActTest is ReferralSystemTest { function _referralSystem_PrepareOperation( TestPublication memory target, - TestPublication memory referralPub + uint256[] memory referrerProfileIds, + uint256[] memory referrerPubIds ) internal virtual override { actionParams = _getDefaultPublicationActionParams(); actionParams.publicationActedProfileId = target.profileId; actionParams.publicationActedId = target.pubId; actionParams.actorProfileId = actor.profileId; - actionParams.referrerProfileIds = _toUint256Array(referralPub.profileId); - actionParams.referrerPubIds = _toUint256Array(referralPub.pubId); + actionParams.referrerProfileIds = referrerProfileIds; + actionParams.referrerPubIds = referrerPubIds; _refreshCachedNonces(); } function _referralSystem_ExpectRevertsIfNeeded( TestPublication memory target, - TestPublication memory referralPub + uint256[] memory /* referrerProfileIds */, + uint256[] memory /* referrerPubIds */ ) internal virtual override returns (bool) { if (_isV1LegacyPub(hub.getPublication(target.profileId, target.pubId))) { vm.expectRevert(Errors.ActionNotAllowed.selector); @@ -35,15 +37,20 @@ contract ActTest is ReferralSystemTest { return false; } - function _referralSystem_ExecutePreparedOperation( - TestPublication memory target, - TestPublication memory referralPub - ) internal virtual override { - console.log('ACTING on %s, %s', vm.toString(target.profileId), vm.toString(target.pubId)); - console.log(' with referral: %s, %s', vm.toString(referralPub.profileId), vm.toString(referralPub.pubId)); + function _referralSystem_ExecutePreparedOperation() internal virtual override { + _act(actor.ownerPk, actionParams); + } - vm.prank(actor.owner); - hub.act(actionParams); + function _act( + uint256 pk, + Types.PublicationActionParams memory publicationActionParams + ) internal virtual returns (bytes memory) { + vm.prank(vm.addr(pk)); + return hub.act(publicationActionParams); + } + + function _refreshCachedNonces() internal virtual { + // Nothing to do there. } function setUp() public virtual override { @@ -150,18 +157,6 @@ contract ActTest is ReferralSystemTest { testAct(); } - function _act( - uint256 pk, - Types.PublicationActionParams memory publicationActionParams - ) internal virtual returns (bytes memory) { - vm.prank(vm.addr(pk)); - return hub.act(publicationActionParams); - } - - function _refreshCachedNonces() internal virtual { - // Nothing to do there. - } - function testGetActionModuleById(address secondActionModule) public { address firstActionModule = makeAddr('FIRST_ACTION_MODULE'); vm.assume(firstActionModule != secondActionModule); diff --git a/test/ReferralSystem.t.sol b/test/ReferralSystem.t.sol index 4754bd6..c210356 100644 --- a/test/ReferralSystem.t.sol +++ b/test/ReferralSystem.t.sol @@ -37,26 +37,55 @@ abstract contract ReferralSystemTest is BaseTest { function _referralSystem_PrepareOperation( TestPublication memory target, - TestPublication memory referralPub + uint256[] memory referrerProfileIds, + uint256[] memory referrerPubIds ) internal virtual; // Returns true if expectRevert was added, so we avoid a dobule expectRevert scenario. function _referralSystem_ExpectRevertsIfNeeded( TestPublication memory target, - TestPublication memory referralPub + uint256[] memory referrerProfileIds, + uint256[] memory referrerPubIds ) internal virtual returns (bool); - function _referralSystem_ExecutePreparedOperation( + function _referralSystem_ExecutePreparedOperation() internal virtual; + + ///////////////////////////////// + // Internal helpers + ///////////////////////////////// + + function _referralSystem_PrepareOperation( TestPublication memory target, TestPublication memory referralPub - ) internal virtual; + ) private { + _referralSystem_PrepareOperation( + target, + _toUint256Array(referralPub.profileId), + _toUint256Array(referralPub.pubId) + ); + } + + // Returns true if expectRevert was added, so we avoid a dobule expectRevert scenario. + function _referralSystem_ExpectRevertsIfNeeded( + TestPublication memory target, + TestPublication memory referralPub + ) private returns (bool) { + return + _referralSystem_ExpectRevertsIfNeeded( + target, + _toUint256Array(referralPub.profileId), + _toUint256Array(referralPub.pubId) + ); + } function _executeOperation(TestPublication memory target, TestPublication memory referralPub) private { _referralSystem_PrepareOperation(target, referralPub); _referralSystem_ExpectRevertsIfNeeded(target, referralPub); - _referralSystem_ExecutePreparedOperation(target, referralPub); + _referralSystem_ExecutePreparedOperation(); } + ///////////////////////////////// + function setUp() public virtual override { super.setUp(); } @@ -167,7 +196,7 @@ abstract contract ReferralSystemTest is BaseTest { vm.expectRevert(Errors.InvalidReferrer.selector); } - _referralSystem_ExecutePreparedOperation(target, referralPub); + _referralSystem_ExecutePreparedOperation(); } } @@ -201,7 +230,7 @@ abstract contract ReferralSystemTest is BaseTest { vm.expectRevert(Errors.InvalidReferrer.selector); } - _referralSystem_ExecutePreparedOperation(target, referralPub); + _referralSystem_ExecutePreparedOperation(); } } } @@ -236,7 +265,7 @@ abstract contract ReferralSystemTest is BaseTest { vm.expectRevert(Errors.InvalidReferrer.selector); } - _referralSystem_ExecutePreparedOperation(target, referralPub); + _referralSystem_ExecutePreparedOperation(); } } } @@ -446,27 +475,6 @@ abstract contract ReferralSystemTest is BaseTest { return TestPublication(publisher.profileId, pubId); } - ////// setup//// - /// create a big tree with all possible situations (V2 posts) - /// We can use some custom data structure to simplify the tree handling, or just rely on "pointedTo" in pubs. - /// - ////// function replaceV1(depth) /// - /// function that will convert a given depth of the V2 tree into V1 (starting from the root Post) - /// - ////// function testReferralsWorkV2() /// - /// a function that takes each node of the V2 tree as target (except mirrors), and permutates with all possible referrers - /// (or makes an array of all other nodes as referrers and passes then all together). - /// Then it checks that the referral system works as expected (i.e. modules are called with the same array of referrals). - /// - ////// function testReferralsV1() /// - /// a function that takes a V2 tree, and converts it to V1 tree gradually, starting with root Post, then level 1 from it, level 2, etc. - /// At each step, it checks that you can only refer the direct link (pointing to), as this is the only thing possible in V1 - /// It does this by picking a random node from the tree as target, and then picking the rest of the nodes as referrers, - /// and expecting them to be passed or failed, depending if they're direct or complex. - /// - - // Negatives - function testCannotExecuteOperationIf_ReferralProfileIdsPassedQty_DiffersFromPubIdsQty() public { // TODO - Errors.ArrayMismatch(); } @@ -495,8 +503,6 @@ abstract contract ReferralSystemTest is BaseTest { // TODO } - // Scenarios - // This test might fail at some point when we check for duplicates! function testPassingDuplicatedReferralsIsAllowed() public { // TODO diff --git a/test/publications/CommentTest.t.sol b/test/publications/CommentTest.t.sol index 4bb5564..a5a5ef2 100644 --- a/test/publications/CommentTest.t.sol +++ b/test/publications/CommentTest.t.sol @@ -61,10 +61,11 @@ contract CommentTest is ReferencePublicationTest, ActionablePublicationTest, Ref function _referralSystem_PrepareOperation( TestPublication memory target, - TestPublication memory referralPub + uint256[] memory referrerProfileIds, + uint256[] memory referrerPubIds ) internal virtual override { _setPointedPub(target.profileId, target.pubId); - _setReferrers(_toUint256Array(referralPub.profileId), _toUint256Array(referralPub.pubId)); + _setReferrers(referrerProfileIds, referrerPubIds); Types.Publication memory targetPublication = hub.getPublication(target.profileId, target.pubId); if (targetPublication.referenceModule != address(0)) { @@ -75,7 +76,8 @@ contract CommentTest is ReferencePublicationTest, ActionablePublicationTest, Ref function _referralSystem_ExpectRevertsIfNeeded( TestPublication memory target, - TestPublication memory referralPub + uint256[] memory /*referrerProfileIds */, + uint256[] memory /*referrerPubIds */ ) internal virtual override returns (bool) { Types.Publication memory targetPublication = hub.getPublication(target.profileId, target.pubId); @@ -95,12 +97,7 @@ contract CommentTest is ReferencePublicationTest, ActionablePublicationTest, Ref return false; } - function _referralSystem_ExecutePreparedOperation( - TestPublication memory target, - TestPublication memory referralPub - ) internal virtual override { - console.log('COMMENTING on %s, %s', vm.toString(target.profileId), vm.toString(target.pubId)); - console.log(' with referral: %s, %s', vm.toString(referralPub.profileId), vm.toString(referralPub.pubId)); + function _referralSystem_ExecutePreparedOperation() internal virtual override { _publish(publisher.ownerPk, publisher.profileId); } diff --git a/test/publications/MirrorTest.t.sol b/test/publications/MirrorTest.t.sol index 668fc0b..884ff5b 100644 --- a/test/publications/MirrorTest.t.sol +++ b/test/publications/MirrorTest.t.sol @@ -53,10 +53,11 @@ contract MirrorTest is ReferencePublicationTest, ReferralSystemTest { function _referralSystem_PrepareOperation( TestPublication memory target, - TestPublication memory referralPub + uint256[] memory referrerProfileIds, + uint256[] memory referrerPubIds ) internal virtual override { _setPointedPub(target.profileId, target.pubId); - _setReferrers(_toUint256Array(referralPub.profileId), _toUint256Array(referralPub.pubId)); + _setReferrers(referrerProfileIds, referrerPubIds); Types.Publication memory targetPublication = hub.getPublication(target.profileId, target.pubId); if (targetPublication.referenceModule != address(0)) { @@ -67,7 +68,8 @@ contract MirrorTest is ReferencePublicationTest, ReferralSystemTest { function _referralSystem_ExpectRevertsIfNeeded( TestPublication memory target, - TestPublication memory referralPub + uint256[] memory /* referrerProfileIds */, + uint256[] memory /* referrerPubIds */ ) internal virtual override returns (bool) { Types.Publication memory targetPublication = hub.getPublication(target.profileId, target.pubId); @@ -87,12 +89,7 @@ contract MirrorTest is ReferencePublicationTest, ReferralSystemTest { return false; } - function _referralSystem_ExecutePreparedOperation( - TestPublication memory target, - TestPublication memory referralPub - ) internal virtual override { - console.log('MIRRORING on %s, %s', vm.toString(target.profileId), vm.toString(target.pubId)); - console.log(' with referral: %s, %s', vm.toString(referralPub.profileId), vm.toString(referralPub.pubId)); + function _referralSystem_ExecutePreparedOperation() internal virtual override { _publish(publisher.ownerPk, publisher.profileId); } diff --git a/test/publications/QuoteTest.t.sol b/test/publications/QuoteTest.t.sol index f1a5b10..0a28fef 100644 --- a/test/publications/QuoteTest.t.sol +++ b/test/publications/QuoteTest.t.sol @@ -61,10 +61,11 @@ contract QuoteTest is ReferencePublicationTest, ActionablePublicationTest, Refer function _referralSystem_PrepareOperation( TestPublication memory target, - TestPublication memory referralPub + uint256[] memory referrerProfileIds, + uint256[] memory referrerPubIds ) internal virtual override { _setPointedPub(target.profileId, target.pubId); - _setReferrers(_toUint256Array(referralPub.profileId), _toUint256Array(referralPub.pubId)); + _setReferrers(referrerProfileIds, referrerPubIds); Types.Publication memory targetPublication = hub.getPublication(target.profileId, target.pubId); if (targetPublication.referenceModule != address(0)) { @@ -75,7 +76,8 @@ contract QuoteTest is ReferencePublicationTest, ActionablePublicationTest, Refer function _referralSystem_ExpectRevertsIfNeeded( TestPublication memory target, - TestPublication memory referralPub + uint256[] memory /* referrerProfileIds */, + uint256[] memory /* referrerPubIds */ ) internal virtual override returns (bool) { Types.Publication memory targetPublication = hub.getPublication(target.profileId, target.pubId); @@ -95,12 +97,7 @@ contract QuoteTest is ReferencePublicationTest, ActionablePublicationTest, Refer return false; } - function _referralSystem_ExecutePreparedOperation( - TestPublication memory target, - TestPublication memory referralPub - ) internal virtual override { - console.log('QUOTING on %s, %s', vm.toString(target.profileId), vm.toString(target.pubId)); - console.log(' with referral: %s, %s', vm.toString(referralPub.profileId), vm.toString(referralPub.pubId)); + function _referralSystem_ExecutePreparedOperation() internal virtual override { _publish(publisher.ownerPk, publisher.profileId); }