From 582df14dec236d63aed221d9d96c154a0331bf07 Mon Sep 17 00:00:00 2001 From: RuslanProgrammer Date: Mon, 8 Jan 2024 09:59:33 +0100 Subject: [PATCH] fixed floating promises in tests --- .eslintrc.json | 6 ++++-- test/Distribution.test.ts | 28 ++++++++++++++-------------- test/L2MessageReceiver.test.ts | 2 +- test/L2TokenReceiver.test.ts | 2 +- test/MOR.test.ts | 2 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 446ede9..402a5fb 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,7 +2,8 @@ "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 12, - "sourceType": "module" + "sourceType": "module", + "project": "./tsconfig.json" }, "plugins": ["@typescript-eslint"], "extends": [ @@ -11,7 +12,8 @@ "plugin:prettier/recommended" ], "rules": { - "@typescript-eslint/no-unused-vars": "error" + "@typescript-eslint/no-unused-vars": "error", + "@typescript-eslint/no-floating-promises": "error" }, "env": { "browser": true, diff --git a/test/Distribution.test.ts b/test/Distribution.test.ts index 160cc75..ce8fc31 100644 --- a/test/Distribution.test.ts +++ b/test/Distribution.test.ts @@ -131,7 +131,7 @@ describe('Distribution', () => { const l2MessageReceiverProxy = await ERC1967ProxyFactory.deploy(l2MessageReceiverImplementation, '0x'); l2MessageReceiver = L2MessageReceiver.attach(l2MessageReceiverProxy) as L2MessageReceiver; - l2MessageReceiver.L2MessageReceiver__init(); + await l2MessageReceiver.L2MessageReceiver__init(); const l2TokenReceiverProxy = await ERC1967ProxyFactory.deploy(l2TokenReceiverImplementation, '0x'); l2TokenReceiver = L2TokenReceiver.attach(l2TokenReceiverProxy) as L2TokenReceiver; @@ -164,7 +164,7 @@ describe('Distribution', () => { // Deploy reward token rewardToken = await MORFactory.deploy(wei(1000000000)); - rewardToken.transferOwnership(l2MessageReceiver); + await rewardToken.transferOwnership(l2MessageReceiver); await l2MessageReceiver.setParams(rewardToken, { gateway: lZEndpointMockReceiver, @@ -364,7 +364,7 @@ describe('Distribution', () => { it('should correctly imitate stake and withdraw process', async () => { let userData; - setNextTime(oneHour * 2); + await setNextTime(oneHour * 2); let tx = await distribution.manageUsersInPrivatePool(poolId, [secondAddress, ownerAddress], [wei(1), wei(4)]); await expect(tx).to.emit(distribution, 'UserStaked').withArgs(poolId, secondAddress, wei(1)); await expect(tx).to.emit(distribution, 'UserStaked').withArgs(poolId, ownerAddress, wei(4)); @@ -381,7 +381,7 @@ describe('Distribution', () => { expect(userData.deposited).to.eq(wei(4)); expect(userData.pendingRewards).to.eq(0); - setNextTime(oneHour * 3); + await setNextTime(oneHour * 3); tx = await distribution.manageUsersInPrivatePool(poolId, [secondAddress, ownerAddress], [wei(10), wei(1)]); await expect(tx).to.emit(distribution, 'UserStaked').withArgs(poolId, secondAddress, wei(9)); await expect(tx).to.emit(distribution, 'UserWithdrawn').withArgs(poolId, ownerAddress, wei(3)); @@ -401,7 +401,7 @@ describe('Distribution', () => { it('should correctly calculate and withdraw rewards', async () => { let userData; - setNextTime(oneHour * 2); + await setNextTime(oneHour * 2); await distribution.manageUsersInPrivatePool(poolId, [secondAddress, ownerAddress], [wei(1), wei(4)]); // Claim after 1 day @@ -422,7 +422,7 @@ describe('Distribution', () => { expect(userData.pendingRewards).to.eq(0); // Withdraw after 2 days - setNextTime(oneDay + oneDay * 2); + await setNextTime(oneDay + oneDay * 2); await distribution.manageUsersInPrivatePool(poolId, [secondAddress, ownerAddress], [wei(0), wei(0)]); expect(await depositToken.balanceOf(secondAddress)).to.eq(wei(1000)); @@ -442,11 +442,11 @@ describe('Distribution', () => { it('should correctly calculate rewards after partial stake', async () => { let userData; - setNextTime(oneHour * 2); + await setNextTime(oneHour * 2); await distribution.manageUsersInPrivatePool(poolId, [secondAddress, ownerAddress], [wei(1), wei(4)]); // Stake after 1 day - setNextTime(oneDay + oneDay * 1); + await setNextTime(oneDay + oneDay * 1); await distribution.manageUsersInPrivatePool(poolId, [secondAddress, ownerAddress], [wei(5), wei(5)]); expect(await depositToken.balanceOf(secondAddress)).to.eq(wei(1000)); @@ -502,7 +502,7 @@ describe('Distribution', () => { it('should correctly calculate rewards if change before distribution end and claim after', async () => { let userData; - setNextTime(oneDay + oneDay * 25); + await setNextTime(oneDay + oneDay * 25); await distribution.manageUsersInPrivatePool(poolId, [secondAddress, ownerAddress], [wei(1), wei(4)]); await setNextTime(oneDay * 20000); @@ -541,7 +541,7 @@ describe('Distribution', () => { it('should correctly calculate rewards if change both at and distribution end', async () => { let userData; - setNextTime(oneDay + oneDay * 25); + await setNextTime(oneDay + oneDay * 25); await distribution.manageUsersInPrivatePool(poolId, [secondAddress, ownerAddress], [wei(1), wei(4)]); await setNextTime(oneDay * 20000); @@ -562,7 +562,7 @@ describe('Distribution', () => { it('should correctly work if multiple changes in one block', async () => { let userData; - setNextTime(oneHour * 2); + await setNextTime(oneHour * 2); await ethers.provider.send('evm_setAutomine', [false]); @@ -597,7 +597,7 @@ describe('Distribution', () => { expect(userData.pendingRewards).to.eq(0); // Withdraw after 2 days - setNextTime(oneDay + oneDay * 2); + await setNextTime(oneDay + oneDay * 2); await distribution.manageUsersInPrivatePool(poolId, [secondAddress, ownerAddress], [wei(0), wei(0)]); await distribution.claim(poolId, SECOND, { value: wei(0.5) }); await distribution.claim(poolId, OWNER, { value: wei(0.5) }); @@ -617,7 +617,7 @@ describe('Distribution', () => { it('should do nothing id deposited amount is the same', async () => { let userData; - setNextTime(oneHour * 2); + await setNextTime(oneHour * 2); await distribution.manageUsersInPrivatePool(poolId, [secondAddress, ownerAddress], [wei(1), wei(4)]); expect(await depositToken.balanceOf(secondAddress)).to.eq(wei(1000)); @@ -632,7 +632,7 @@ describe('Distribution', () => { expect(userData.deposited).to.eq(wei(4)); expect(userData.pendingRewards).to.eq(0); - setNextTime(oneHour * 3); + await setNextTime(oneHour * 3); await distribution.manageUsersInPrivatePool(poolId, [secondAddress, ownerAddress], [wei(1), wei(4)]); expect(await depositToken.balanceOf(secondAddress)).to.eq(wei(1000)); diff --git a/test/L2MessageReceiver.test.ts b/test/L2MessageReceiver.test.ts index 524a381..08832dc 100644 --- a/test/L2MessageReceiver.test.ts +++ b/test/L2MessageReceiver.test.ts @@ -40,7 +40,7 @@ describe('L2MessageReceiver', () => { await mor.transferOwnership(l2MessageReceiver); - reverter.snapshot(); + await reverter.snapshot(); }); beforeEach(async () => { diff --git a/test/L2TokenReceiver.test.ts b/test/L2TokenReceiver.test.ts index b7fe7d3..aa49583 100644 --- a/test/L2TokenReceiver.test.ts +++ b/test/L2TokenReceiver.test.ts @@ -63,7 +63,7 @@ describe('L2TokenReceiver', () => { sqrtPriceLimitX96: 0, }); - reverter.snapshot(); + await reverter.snapshot(); }); beforeEach(async () => { diff --git a/test/MOR.test.ts b/test/MOR.test.ts index 8393b99..f3ec9a1 100644 --- a/test/MOR.test.ts +++ b/test/MOR.test.ts @@ -21,7 +21,7 @@ describe('MOR', () => { const MORFactory = await ethers.getContractFactory('MOR'); mor = await MORFactory.deploy(cap); - reverter.snapshot(); + await reverter.snapshot(); }); afterEach(async () => {