From 2e78193c10f7c5e54ee473f86aa61e142076cd8f Mon Sep 17 00:00:00 2001 From: zer0dot Date: Mon, 3 Oct 2022 15:32:04 -0400 Subject: [PATCH] test: Fixed limited timed fee collect module Hardhat tests. --- .../limited-timed-fee-collect-module.spec.ts | 148 ++++++++++++------ 1 file changed, 97 insertions(+), 51 deletions(-) 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 d23054c..e59f6eb 100644 --- a/test/modules/collect/limited-timed-fee-collect-module.spec.ts +++ b/test/modules/collect/limited-timed-fee-collect-module.spec.ts @@ -50,7 +50,7 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { ).to.not.be.reverted; }); - context('Negatives', function () { + context.only('Negatives', function () { context('Publication Creation', function () { it('user should fail to post with limited timed fee collect module using zero collect limit', async function () { const collectModuleInitData = abiCoder.encode( @@ -181,7 +181,7 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { await expect( limitedTimedFeeCollectModule .connect(userTwo) - .processCollect(0, userTwoAddress, userTwoAddress, FIRST_PROFILE_ID, 1, []) + .processCollect(0, 0, userTwoAddress, userTwoAddress, FIRST_PROFILE_ID, 1, []) ).to.be.revertedWith(ERRORS.NOT_HUB); }); @@ -191,14 +191,16 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE] ); - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [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(userTwoAddress,FIRST_PROFILE_ID, 1, data); + const tx = lensHub.connect(userTwo).collect(userTwoAddress, FIRST_PROFILE_ID, 1, data); const receipt = await waitForTx(tx); let currencyEventCount = 0; @@ -245,14 +247,16 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE] ); - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [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(userTwoAddress,secondProfileId, 1, data); + const tx = lensHub.connect(userTwo).collect(userTwoAddress, secondProfileId, 1, data); const receipt = await waitForTx(tx); let currencyEventCount = 0; @@ -291,12 +295,14 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { [currency.address, DEFAULT_COLLECT_PRICE] ); await expect( - lensHub.connect(userTwo).collect(userTwoAddress,FIRST_PROFILE_ID, 1, data) + lensHub.connect(userTwo).collect(userTwoAddress, FIRST_PROFILE_ID, 1, data) ).to.be.revertedWith(ERRORS.FOLLOW_INVALID); }); it('UserTwo should fail to collect after the collect end timestmap', async function () { - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]]) + ).to.not.be.reverted; const currentTimestamp = await getTimestamp(); await setNextBlockTimestamp(Number(currentTimestamp) + 24 * 60 * 60); @@ -306,42 +312,48 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { [currency.address, DEFAULT_COLLECT_PRICE] ); await expect( - lensHub.connect(userTwo).collect(userTwoAddress,FIRST_PROFILE_ID, 1, data) + lensHub.connect(userTwo).collect(userTwoAddress, FIRST_PROFILE_ID, 1, data) ).to.be.revertedWith(ERRORS.COLLECT_EXPIRED); }); it('UserTwo should fail to collect passing a different expected price in data', async function () { - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]]) + ).to.not.be.reverted; const data = abiCoder.encode( ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE.div(2)] ); await expect( - lensHub.connect(userTwo).collect(userTwoAddress,FIRST_PROFILE_ID, 1, data) + lensHub.connect(userTwo).collect(userTwoAddress, FIRST_PROFILE_ID, 1, data) ).to.be.revertedWith(ERRORS.MODULE_DATA_MISMATCH); }); it('UserTwo should fail to collect passing a different expected currency in data', async function () { - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]]) + ).to.not.be.reverted; const data = abiCoder.encode(['address', 'uint256'], [userAddress, DEFAULT_COLLECT_PRICE]); await expect( - lensHub.connect(userTwo).collect(userTwoAddress,FIRST_PROFILE_ID, 1, data) + lensHub.connect(userTwo).collect(userTwoAddress, FIRST_PROFILE_ID, 1, data) ).to.be.revertedWith(ERRORS.MODULE_DATA_MISMATCH); }); it('UserTwo should fail to collect without first approving module with currency', async function () { await expect(currency.mint(userTwoAddress, MAX_UINT256)).to.not.be.reverted; - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]]) + ).to.not.be.reverted; const data = abiCoder.encode( ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE] ); await expect( - lensHub.connect(userTwo).collect(userTwoAddress,FIRST_PROFILE_ID, 1, data) + lensHub.connect(userTwo).collect(userTwoAddress, FIRST_PROFILE_ID, 1, data) ).to.be.revertedWith(ERRORS.ERC20_INSUFFICIENT_ALLOWANCE); }); @@ -372,9 +384,9 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE] ); - await expect(lensHub.connect(userTwo).collect(userTwoAddress,secondProfileId, 1, data)).to.be.revertedWith( - ERRORS.FOLLOW_INVALID - ); + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, secondProfileId, 1, data) + ).to.be.revertedWith(ERRORS.FOLLOW_INVALID); }); it('UserTwo should mirror the original post, fail to collect from their mirror after the collect end timestamp', async function () { @@ -400,7 +412,9 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { }) ).to.not.be.reverted; - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]]) + ).to.not.be.reverted; const currentTimestamp = await getTimestamp(); await setNextBlockTimestamp(Number(currentTimestamp) + 24 * 60 * 60); @@ -409,9 +423,9 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE] ); - await expect(lensHub.connect(userTwo).collect(userTwoAddress,secondProfileId, 1, data)).to.be.revertedWith( - ERRORS.COLLECT_EXPIRED - ); + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, secondProfileId, 1, data) + ).to.be.revertedWith(ERRORS.COLLECT_EXPIRED); }); it('UserTwo should mirror the original post, fail to collect from their mirror passing a different expected price in data', async function () { @@ -437,15 +451,17 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { }) ).to.not.be.reverted; - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]]) + ).to.not.be.reverted; const data = abiCoder.encode( ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE.div(2)] ); - await expect(lensHub.connect(userTwo).collect(userTwoAddress,secondProfileId, 1, data)).to.be.revertedWith( - ERRORS.MODULE_DATA_MISMATCH - ); + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, secondProfileId, 1, data) + ).to.be.revertedWith(ERRORS.MODULE_DATA_MISMATCH); }); it('UserTwo should mirror the original post, fail to collect from their mirror passing a different expected currency in data', async function () { @@ -471,17 +487,19 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { }) ).to.not.be.reverted; - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]]) + ).to.not.be.reverted; const data = abiCoder.encode(['address', 'uint256'], [userAddress, DEFAULT_COLLECT_PRICE]); - await expect(lensHub.connect(userTwo).collect(userTwoAddress,secondProfileId, 1, data)).to.be.revertedWith( - ERRORS.MODULE_DATA_MISMATCH - ); + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, secondProfileId, 1, data) + ).to.be.revertedWith(ERRORS.MODULE_DATA_MISMATCH); }); }); }); - context('Scenarios', function () { + context.only('Scenarios', function () { it('User should post with limited timed fee collect module as the collect module and data, correct events should be emitted', async function () { const collectModuleInitData = abiCoder.encode( ['uint256', 'uint256', 'address', 'address', 'uint16', 'bool'], @@ -601,7 +619,9 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE] ); - await expect(lensHub.connect(userTwo).collect(userTwoAddress,FIRST_PROFILE_ID, 1, data)).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, FIRST_PROFILE_ID, 1, data) + ).to.not.be.reverted; const expectedTreasuryAmount = BigNumber.from(DEFAULT_COLLECT_PRICE) .mul(TREASURY_FEE_BPS) @@ -643,12 +663,16 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { await expect( currency.connect(userTwo).approve(limitedTimedFeeCollectModule.address, MAX_UINT256) ).to.not.be.reverted; - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]]) + ).to.not.be.reverted; const data = abiCoder.encode( ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE] ); - await expect(lensHub.connect(userTwo).collect(userTwoAddress,FIRST_PROFILE_ID, 1, data)).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, FIRST_PROFILE_ID, 1, data) + ).to.not.be.reverted; const expectedTreasuryAmount = BigNumber.from(DEFAULT_COLLECT_PRICE) .mul(TREASURY_FEE_BPS) @@ -690,13 +714,19 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { await expect( currency.connect(userTwo).approve(limitedTimedFeeCollectModule.address, MAX_UINT256) ).to.not.be.reverted; - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]]) + ).to.not.be.reverted; const data = abiCoder.encode( ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE] ); - await expect(lensHub.connect(userTwo).collect(userTwoAddress,FIRST_PROFILE_ID, 1, data)).to.not.be.reverted; - await expect(lensHub.connect(userTwo).collect(userTwoAddress,FIRST_PROFILE_ID, 1, data)).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, FIRST_PROFILE_ID, 1, data) + ).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, FIRST_PROFILE_ID, 1, data) + ).to.not.be.reverted; const expectedTreasuryAmount = BigNumber.from(DEFAULT_COLLECT_PRICE) .mul(TREASURY_FEE_BPS) @@ -760,12 +790,16 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { await expect( currency.connect(userTwo).approve(limitedTimedFeeCollectModule.address, MAX_UINT256) ).to.not.be.reverted; - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]]) + ).to.not.be.reverted; const data = abiCoder.encode( ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE] ); - await expect(lensHub.connect(userTwo).collect(userTwoAddress,secondProfileId, 1, data)).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, secondProfileId, 1, data) + ).to.not.be.reverted; const expectedTreasuryAmount = BigNumber.from(DEFAULT_COLLECT_PRICE) .mul(TREASURY_FEE_BPS) @@ -828,12 +862,16 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { await expect( currency.connect(userTwo).approve(limitedTimedFeeCollectModule.address, MAX_UINT256) ).to.not.be.reverted; - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]]) + ).to.not.be.reverted; const data = abiCoder.encode( ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE] ); - await expect(lensHub.connect(userTwo).collect(userTwoAddress,secondProfileId, 1, data)).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, secondProfileId, 1, data) + ).to.not.be.reverted; const expectedTreasuryAmount = BigNumber.from(DEFAULT_COLLECT_PRICE) .mul(TREASURY_FEE_BPS) @@ -897,21 +935,29 @@ makeSuiteCleanRoom('Limited Timed Fee Collect Module', function () { await expect( currency.connect(userTwo).approve(limitedTimedFeeCollectModule.address, MAX_UINT256) ).to.not.be.reverted; - await expect(lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]])).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).follow(userTwoAddress, [FIRST_PROFILE_ID], [[]]) + ).to.not.be.reverted; const data = abiCoder.encode( ['address', 'uint256'], [currency.address, DEFAULT_COLLECT_PRICE] ); - await expect(lensHub.connect(userTwo).collect(userTwoAddress,FIRST_PROFILE_ID, 1, data)).to.not.be.reverted; - await expect(lensHub.connect(userTwo).collect(userTwoAddress,secondProfileId, 1, data)).to.not.be.reverted; - await expect(lensHub.connect(userTwo).collect(userTwoAddress,secondProfileId, 1, data)).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, FIRST_PROFILE_ID, 1, data) + ).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, secondProfileId, 1, data) + ).to.not.be.reverted; + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, secondProfileId, 1, data) + ).to.not.be.reverted; - await expect(lensHub.connect(userTwo).collect(userTwoAddress,FIRST_PROFILE_ID, 1, data)).to.be.revertedWith( - ERRORS.MINT_LIMIT_EXCEEDED - ); - await expect(lensHub.connect(userTwo).collect(userTwoAddress,secondProfileId, 1, data)).to.be.revertedWith( - ERRORS.MINT_LIMIT_EXCEEDED - ); + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, FIRST_PROFILE_ID, 1, data) + ).to.be.revertedWith(ERRORS.MINT_LIMIT_EXCEEDED); + await expect( + lensHub.connect(userTwo).collect(userTwoAddress, secondProfileId, 1, data) + ).to.be.revertedWith(ERRORS.MINT_LIMIT_EXCEEDED); }); }); });