Skip to content

Commit

Permalink
fixed floating promises in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RuslanProgrammer committed Jan 8, 2024
1 parent 0f97c5a commit 582df14
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"extends": [
Expand All @@ -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,
Expand Down
28 changes: 14 additions & 14 deletions test/Distribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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
Expand All @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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]);

Expand Down Expand Up @@ -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) });
Expand All @@ -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));
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion test/L2MessageReceiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('L2MessageReceiver', () => {

await mor.transferOwnership(l2MessageReceiver);

reverter.snapshot();
await reverter.snapshot();
});

beforeEach(async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/L2TokenReceiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('L2TokenReceiver', () => {
sqrtPriceLimitX96: 0,
});

reverter.snapshot();
await reverter.snapshot();
});

beforeEach(async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/MOR.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('MOR', () => {
const MORFactory = await ethers.getContractFactory('MOR');
mor = await MORFactory.deploy(cap);

reverter.snapshot();
await reverter.snapshot();
});

afterEach(async () => {
Expand Down

0 comments on commit 582df14

Please sign in to comment.