test: Referral System - Unverified referrals tests added

Co-authored-by: Victor Naumik <vicnaum@gmail.com>
This commit is contained in:
donosonaumczuk
2023-06-26 17:40:57 +01:00
parent 359ccc3ce3
commit 54124d00d0
2 changed files with 154 additions and 0 deletions

View File

@@ -49,6 +49,31 @@ contract LegacyCollectTest is BaseTest, ReferralSystemTest {
});
}
function testV2UnverifiedReferrals() public virtual override {
// ReferralSystem inherited test that does not apply to this file.
// This case is tested at `testCannot_PassV2UnverifiedReferrals`.
}
function testCannot_PassV2UnverifiedReferral_SameAsTargetAuthor() public virtual 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(0));
vm.expectRevert(Errors.InvalidReferrer.selector);
_referralSystem_ExecutePreparedOperation();
}
function testCannot_PassV2UnverifiedReferrals(address referrerProfileOwner) public {
uint256 referrerProfileId = _createProfile(referrerProfileOwner);
// Set unverified referral
defaultCollectParams.referrerProfileId = referrerProfileId;
defaultCollectParams.referrerPubId = 0;
vm.expectRevert(Errors.InvalidReferrer.selector);
_collect(defaultAccount.ownerPk, defaultCollectParams);
}
function testCannotCollectIfPaused() public {
vm.prank(governance);
hub.setState(Types.ProtocolState.Paused);
@@ -143,6 +168,51 @@ contract LegacyCollectTest is BaseTest, ReferralSystemTest {
_referralSystem_ExecutePreparedOperation();
}
function testCannotPass_UnexistentProfile_AsUnverifiedReferrer(uint256 unexistentProfileId) public override {
// Note: The following publication is converted to Legacy V1 in this test's setUp.
TestPublication memory targetPub = TestPublication(defaultAccount.profileId, pubId);
// We need unexistentProfileId to be non-zero, otherwise referral = (0, 0) means no referrals were passed.
vm.assume(unexistentProfileId != 0);
vm.assume(!hub.exists(unexistentProfileId));
_referralSystem_PrepareOperation(targetPub, _toUint256Array(unexistentProfileId), _toUint256Array(0));
vm.expectRevert(Errors.InvalidReferrer.selector);
_referralSystem_ExecutePreparedOperation();
}
function testCannotPass_BurntProfile_AsReferrer() public {
// Note: The following publication is converted to Legacy V1 in this test's setUp.
TestPublication memory targetPub = TestPublication(defaultAccount.profileId, pubId);
TestPublication memory referrerMirrorPub = _mirror(targetPub);
address referrerMirrorOwner = hub.ownerOf(referrerMirrorPub.profileId);
vm.prank(referrerMirrorOwner);
hub.burn(referrerMirrorPub.profileId);
_referralSystem_PrepareOperation(
targetPub,
_toUint256Array(referrerMirrorPub.profileId),
_toUint256Array(referrerMirrorPub.pubId)
);
vm.expectRevert(Errors.InvalidReferrer.selector);
_referralSystem_ExecutePreparedOperation();
}
function testCannotPass_BurntProfile_AsUnverifiedReferrer() 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 referralPub = _mirror(targetPub);
address referralOwner = hub.ownerOf(referralPub.profileId);
vm.prank(referralOwner);
hub.burn(referralPub.profileId);
_referralSystem_PrepareOperation(targetPub, _toUint256Array(referralPub.profileId), _toUint256Array(0));
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));

View File

@@ -96,6 +96,59 @@ abstract contract ReferralSystemTest is BaseTest {
TestPublication[] mirrors;
}
function testV2UnverifiedReferrals() public virtual {
TestAccount memory profileReferral = _loadAccountAs('PROFILE_REFERRAL');
TestPublication memory referralPub = TestPublication(profileReferral.profileId, 0);
for (uint256 commentQuoteFuzzBitmap = 0; commentQuoteFuzzBitmap < 32; commentQuoteFuzzBitmap++) {
Tree memory treeV2 = _createV2Tree(commentQuoteFuzzBitmap);
{
TestPublication memory target = treeV2.post;
_executeOperation(target, referralPub);
}
{
for (uint256 i = 0; i < treeV2.references.length; i++) {
TestPublication memory target = treeV2.references[i];
_executeOperation(target, referralPub);
}
}
}
}
function testCannot_PassV2UnverifiedReferral_SameAsTargetAuthor() public virtual {
for (uint256 commentQuoteFuzzBitmap = 0; commentQuoteFuzzBitmap < 32; commentQuoteFuzzBitmap++) {
Tree memory treeV2 = _createV2Tree(commentQuoteFuzzBitmap);
{
TestPublication memory target = treeV2.post;
TestPublication memory referralPub = TestPublication(target.profileId, 0);
_referralSystem_PrepareOperation(target, referralPub);
if (!_referralSystem_ExpectRevertsIfNeeded(target, referralPub)) {
vm.expectRevert(Errors.InvalidReferrer.selector);
}
_referralSystem_ExecutePreparedOperation();
}
{
for (uint256 i = 0; i < treeV2.references.length; i++) {
TestPublication memory target = treeV2.references[i];
TestPublication memory referralPub = TestPublication(target.profileId, 0);
_referralSystem_PrepareOperation(target, referralPub);
if (!_referralSystem_ExpectRevertsIfNeeded(target, referralPub)) {
vm.expectRevert(Errors.InvalidReferrer.selector);
}
_referralSystem_ExecutePreparedOperation();
}
}
}
}
function testV2Referrals() public virtual {
for (uint256 commentQuoteFuzzBitmap = 0; commentQuoteFuzzBitmap < 32; commentQuoteFuzzBitmap++) {
Tree memory treeV2 = _createV2Tree(commentQuoteFuzzBitmap);
@@ -535,6 +588,37 @@ abstract contract ReferralSystemTest is BaseTest {
_referralSystem_ExecutePreparedOperation();
}
function testCannotPass_UnexistentProfile_AsUnverifiedReferrer(uint256 unexistentProfileId) public virtual {
Types.PostParams memory postParams = _getDefaultPostParams();
postParams.referenceModule = address(mockReferenceModule);
postParams.referenceModuleInitData = abi.encode(true);
vm.prank(defaultAccount.owner);
TestPublication memory targetPub = TestPublication(defaultAccount.profileId, hub.post(postParams));
vm.assume(!hub.exists(unexistentProfileId));
_referralSystem_PrepareOperation(targetPub, _toUint256Array(unexistentProfileId), _toUint256Array(0));
vm.expectRevert(Errors.InvalidReferrer.selector);
_referralSystem_ExecutePreparedOperation();
}
function testCannotPass_BurntProfile_AsUnverifiedReferrer() public virtual {
Types.PostParams memory postParams = _getDefaultPostParams();
postParams.referenceModule = address(mockReferenceModule);
postParams.referenceModuleInitData = abi.encode(true);
vm.prank(defaultAccount.owner);
TestPublication memory targetPub = TestPublication(defaultAccount.profileId, hub.post(postParams));
TestPublication memory referralPub = _comment(targetPub);
address referralOwner = hub.ownerOf(referralPub.profileId);
vm.prank(referralOwner);
hub.burn(referralPub.profileId);
_referralSystem_PrepareOperation(targetPub, _toUint256Array(referralPub.profileId), _toUint256Array(0));
vm.expectRevert(Errors.InvalidReferrer.selector);
_referralSystem_ExecutePreparedOperation();
}
// This test might fail at some point when we check for duplicates!
function testPassingDuplicatedReferralsIsAllowed() public {
Types.PostParams memory postParams = _getDefaultPostParams();