From e2daef1250e7a1106366d0bee44ab68dc26351c1 Mon Sep 17 00:00:00 2001 From: Peter Michael Date: Wed, 23 Mar 2022 12:33:45 -0400 Subject: [PATCH] test: Added tests for zero treasury fee on referral. --- .solcover.js | 2 + .../collect/fee-collect-module.spec.ts | 68 ++++++++++++++++++- .../limited-fee-collect-module.spec.ts | 67 ++++++++++++++++++ .../limited-timed-fee-collect-module.spec.ts | 67 ++++++++++++++++++ .../collect/timed-fee-collect-module.spec.ts | 67 ++++++++++++++++++ 5 files changed, 270 insertions(+), 1 deletion(-) diff --git a/.solcover.js b/.solcover.js index f1d0907..111825b 100644 --- a/.solcover.js +++ b/.solcover.js @@ -2,6 +2,8 @@ module.exports = { skipFiles: [ '/core/base/ERC721Time.sol', '/core/base/ERC721Enumerable.sol', + '/core/modules/follow/SecretCodeFollowModule.sol', + '/upgradeability', '/interfaces', '/mocks', ], diff --git a/test/modules/collect/fee-collect-module.spec.ts b/test/modules/collect/fee-collect-module.spec.ts index 0216821..524bfef 100644 --- a/test/modules/collect/fee-collect-module.spec.ts +++ b/test/modules/collect/fee-collect-module.spec.ts @@ -164,7 +164,6 @@ makeSuiteCleanRoom('Fee Collect Module', function () { } } expect(currencyEventCount).to.eq(1); - const amount = abiCoder.encode(['uint256'], [DEFAULT_COLLECT_PRICE]); matchEvent( receipt, 'Transfer', @@ -174,6 +173,73 @@ makeSuiteCleanRoom('Fee Collect Module', function () { ); }); + it('UserTwo should mirror the original post, governance should set the treasury fee BPS to zero, userTwo collecting their mirror should not emit a transfer event to the treasury', async function () { + const secondProfileId = FIRST_PROFILE_ID + 1; + await expect( + lensHub.connect(userTwo).createProfile({ + to: userTwoAddress, + handle: 'usertwo', + imageURI: MOCK_PROFILE_URI, + followModule: ZERO_ADDRESS, + followModuleData: [], + followNFTURI: MOCK_FOLLOW_NFT_URI, + }) + ).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).mirror({ + profileId: secondProfileId, + profileIdPointed: FIRST_PROFILE_ID, + pubIdPointed: 1, + referenceModule: ZERO_ADDRESS, + referenceModuleData: [], + }) + ).to.not.be.reverted; + + await expect(moduleGlobals.connect(governance).setTreasuryFee(0)).to.not.be.reverted; + const data = abiCoder.encode( + ['address', 'uint256'], + [currency.address, DEFAULT_COLLECT_PRICE] + ); + await expect(lensHub.connect(userTwo).follow([FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + + await expect(currency.mint(userTwoAddress, MAX_UINT256)).to.not.be.reverted; + await expect( + currency.connect(userTwo).approve(feeCollectModule.address, MAX_UINT256) + ).to.not.be.reverted; + + const tx = lensHub.connect(userTwo).collect(secondProfileId, 1, data); + const receipt = await waitForTx(tx); + + let currencyEventCount = 0; + for (let log of receipt.logs) { + if (log.address == currency.address) { + currencyEventCount++; + } + } + expect(currencyEventCount).to.eq(2); + + const expectedReferralAmount = BigNumber.from(DEFAULT_COLLECT_PRICE) + .mul(REFERRAL_FEE_BPS) + .div(BPS_MAX); + const amount = DEFAULT_COLLECT_PRICE.sub(expectedReferralAmount); + + matchEvent( + receipt, + 'Transfer', + [userTwoAddress, userAddress, amount], + currency, + currency.address + ); + + matchEvent( + receipt, + 'Transfer', + [userTwoAddress, userTwoAddress, expectedReferralAmount], + currency, + currency.address + ); + }); + it('UserTwo should fail to collect without following', async function () { const data = abiCoder.encode( ['address', 'uint256'], diff --git a/test/modules/collect/limited-fee-collect-module.spec.ts b/test/modules/collect/limited-fee-collect-module.spec.ts index dff0673..aa84b3c 100644 --- a/test/modules/collect/limited-fee-collect-module.spec.ts +++ b/test/modules/collect/limited-fee-collect-module.spec.ts @@ -206,6 +206,73 @@ makeSuiteCleanRoom('Limited Fee Collect Module', function () { ); }); + it('UserTwo should mirror the original post, governance should set the treasury fee BPS to zero, userTwo collecting their mirror should not emit a transfer event to the treasury', async function () { + const secondProfileId = FIRST_PROFILE_ID + 1; + await expect( + lensHub.connect(userTwo).createProfile({ + to: userTwoAddress, + handle: 'usertwo', + imageURI: MOCK_PROFILE_URI, + followModule: ZERO_ADDRESS, + followModuleData: [], + followNFTURI: MOCK_FOLLOW_NFT_URI, + }) + ).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).mirror({ + profileId: secondProfileId, + profileIdPointed: FIRST_PROFILE_ID, + pubIdPointed: 1, + referenceModule: ZERO_ADDRESS, + referenceModuleData: [], + }) + ).to.not.be.reverted; + + await expect(moduleGlobals.connect(governance).setTreasuryFee(0)).to.not.be.reverted; + const data = abiCoder.encode( + ['address', 'uint256'], + [currency.address, DEFAULT_COLLECT_PRICE] + ); + await expect(lensHub.connect(userTwo).follow([FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + + await expect(currency.mint(userTwoAddress, MAX_UINT256)).to.not.be.reverted; + await expect( + currency.connect(userTwo).approve(limitedFeeCollectModule.address, MAX_UINT256) + ).to.not.be.reverted; + + const tx = lensHub.connect(userTwo).collect(secondProfileId, 1, data); + const receipt = await waitForTx(tx); + + let currencyEventCount = 0; + for (let log of receipt.logs) { + if (log.address == currency.address) { + currencyEventCount++; + } + } + expect(currencyEventCount).to.eq(2); + + const expectedReferralAmount = BigNumber.from(DEFAULT_COLLECT_PRICE) + .mul(REFERRAL_FEE_BPS) + .div(BPS_MAX); + const amount = DEFAULT_COLLECT_PRICE.sub(expectedReferralAmount); + + matchEvent( + receipt, + 'Transfer', + [userTwoAddress, userAddress, amount], + currency, + currency.address + ); + + matchEvent( + receipt, + 'Transfer', + [userTwoAddress, userTwoAddress, expectedReferralAmount], + currency, + currency.address + ); + }); + it('UserTwo should fail to collect without following', async function () { const data = abiCoder.encode( ['address', 'uint256'], diff --git a/test/modules/collect/limited-timed-fee-collect-module.spec.ts b/test/modules/collect/limited-timed-fee-collect-module.spec.ts index cd59f6e..442fd69 100644 --- a/test/modules/collect/limited-timed-fee-collect-module.spec.ts +++ b/test/modules/collect/limited-timed-fee-collect-module.spec.ts @@ -206,6 +206,73 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { ); }); + it('UserTwo should mirror the original post, governance should set the treasury fee BPS to zero, userTwo collecting their mirror should not emit a transfer event to the treasury', async function () { + const secondProfileId = FIRST_PROFILE_ID + 1; + await expect( + lensHub.connect(userTwo).createProfile({ + to: userTwoAddress, + handle: 'usertwo', + imageURI: MOCK_PROFILE_URI, + followModule: ZERO_ADDRESS, + followModuleData: [], + followNFTURI: MOCK_FOLLOW_NFT_URI, + }) + ).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).mirror({ + profileId: secondProfileId, + profileIdPointed: FIRST_PROFILE_ID, + pubIdPointed: 1, + referenceModule: ZERO_ADDRESS, + referenceModuleData: [], + }) + ).to.not.be.reverted; + + await expect(moduleGlobals.connect(governance).setTreasuryFee(0)).to.not.be.reverted; + const data = abiCoder.encode( + ['address', 'uint256'], + [currency.address, DEFAULT_COLLECT_PRICE] + ); + await expect(lensHub.connect(userTwo).follow([FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + + await expect(currency.mint(userTwoAddress, MAX_UINT256)).to.not.be.reverted; + await expect( + currency.connect(userTwo).approve(limitedTimedFeeCollectModule.address, MAX_UINT256) + ).to.not.be.reverted; + + const tx = lensHub.connect(userTwo).collect(secondProfileId, 1, data); + const receipt = await waitForTx(tx); + + let currencyEventCount = 0; + for (let log of receipt.logs) { + if (log.address == currency.address) { + currencyEventCount++; + } + } + expect(currencyEventCount).to.eq(2); + + const expectedReferralAmount = BigNumber.from(DEFAULT_COLLECT_PRICE) + .mul(REFERRAL_FEE_BPS) + .div(BPS_MAX); + const amount = DEFAULT_COLLECT_PRICE.sub(expectedReferralAmount); + + matchEvent( + receipt, + 'Transfer', + [userTwoAddress, userAddress, amount], + currency, + currency.address + ); + + matchEvent( + receipt, + 'Transfer', + [userTwoAddress, userTwoAddress, expectedReferralAmount], + currency, + currency.address + ); + }); + it('UserTwo should fail to collect without following', async function () { const data = abiCoder.encode( ['address', 'uint256'], diff --git a/test/modules/collect/timed-fee-collect-module.spec.ts b/test/modules/collect/timed-fee-collect-module.spec.ts index 735a31b..cf667b3 100644 --- a/test/modules/collect/timed-fee-collect-module.spec.ts +++ b/test/modules/collect/timed-fee-collect-module.spec.ts @@ -170,6 +170,73 @@ makeSuiteCleanRoom('Timed Fee Collect Module', function () { ); }); + it('UserTwo should mirror the original post, governance should set the treasury fee BPS to zero, userTwo collecting their mirror should not emit a transfer event to the treasury', async function () { + const secondProfileId = FIRST_PROFILE_ID + 1; + await expect( + lensHub.connect(userTwo).createProfile({ + to: userTwoAddress, + handle: 'usertwo', + imageURI: MOCK_PROFILE_URI, + followModule: ZERO_ADDRESS, + followModuleData: [], + followNFTURI: MOCK_FOLLOW_NFT_URI, + }) + ).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).mirror({ + profileId: secondProfileId, + profileIdPointed: FIRST_PROFILE_ID, + pubIdPointed: 1, + referenceModule: ZERO_ADDRESS, + referenceModuleData: [], + }) + ).to.not.be.reverted; + + await expect(moduleGlobals.connect(governance).setTreasuryFee(0)).to.not.be.reverted; + const data = abiCoder.encode( + ['address', 'uint256'], + [currency.address, DEFAULT_COLLECT_PRICE] + ); + await expect(lensHub.connect(userTwo).follow([FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + + await expect(currency.mint(userTwoAddress, MAX_UINT256)).to.not.be.reverted; + await expect( + currency.connect(userTwo).approve(timedFeeCollectModule.address, MAX_UINT256) + ).to.not.be.reverted; + + const tx = lensHub.connect(userTwo).collect(secondProfileId, 1, data); + const receipt = await waitForTx(tx); + + let currencyEventCount = 0; + for (let log of receipt.logs) { + if (log.address == currency.address) { + currencyEventCount++; + } + } + expect(currencyEventCount).to.eq(2); + + const expectedReferralAmount = BigNumber.from(DEFAULT_COLLECT_PRICE) + .mul(REFERRAL_FEE_BPS) + .div(BPS_MAX); + const amount = DEFAULT_COLLECT_PRICE.sub(expectedReferralAmount); + + matchEvent( + receipt, + 'Transfer', + [userTwoAddress, userAddress, amount], + currency, + currency.address + ); + + matchEvent( + receipt, + 'Transfer', + [userTwoAddress, userTwoAddress, expectedReferralAmount], + currency, + currency.address + ); + }); + it('UserTwo should fail to collect without following', async function () { const data = abiCoder.encode( ['address', 'uint256'],