Skip to content

Commit

Permalink
Fix flaky lockup test (#524)
Browse files Browse the repository at this point in the history
Fix flaky test
  • Loading branch information
vtleonardo committed Nov 28, 2022
1 parent e24e680 commit 154f52d
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions bridge/test/lockup/unlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,6 @@ describe("Testing Unlock", async () => {
expectedState.users[user].alca += BigNumber.from(
example3[user].totalEarnedALCA
).toBigInt();
// workaround to discount integer division errors.
expectedState.users[user].eth =
(expectedState.users[user].eth / 100n) * 100n;
expectedState.users[user].alca =
(expectedState.users[user].alca / 100n) * 100n;
expectedState.users[user].tokenId = ethers.constants.Zero.toBigInt();
expectedState.users[user].tokenOwner = ethers.constants.AddressZero;
expectedState.users[user].rewardEth = 0n;
Expand Down Expand Up @@ -292,10 +287,20 @@ describe("Testing Unlock", async () => {
// workaround to discount integer division errors.
for (let i = 1; i <= numberOfLockingUsers - 2; i++) {
const user = "user" + i;
currentState.users[user].eth =
(currentState.users[user].eth / 100n) * 100n;
currentState.users[user].alca =
(currentState.users[user].alca / 100n) * 100n;
// extra check to check if the error is less than an allowed threshold
if (currentState.users[user].eth >= expectedState.users[user].eth) {
expect(
currentState.users[user].eth - expectedState.users[user].eth
).to.be.lessThan(10);
} else {
expect(
expectedState.users[user].eth - currentState.users[user].eth
).to.be.lessThan(10);
}
// after we have checked the threshold that accounts for integer division errors, we put the expect
// and current values to be same to check the rest of the state
expectedState.users[user].eth = currentState.users[user].eth;
expectedState.users[user].alca = currentState.users[user].alca;
}
assert.deepEqual(currentState, expectedState);
});
Expand Down Expand Up @@ -387,17 +392,10 @@ describe("Testing Unlock", async () => {
expectedState.users[user].eth - currentState.users[user].eth
).to.be.lessThan(10);
}
// workaround to discount integer division errors. The error range is less than 10, usually 1
// or 2. However, to avoid values ...39 and ...40 resulting in failed tests, we divide by 100
// instead of 10
expectedState.users[user].eth =
(expectedState.users[user].eth / 100n) * 100n;
expectedState.users[user].alca =
(expectedState.users[user].alca / 100n) * 100n;
currentState.users[user].eth =
(currentState.users[user].eth / 100n) * 100n;
currentState.users[user].alca =
(currentState.users[user].alca / 100n) * 100n;
// after we have checked the threshold that accounts for integer division errors, we put the
// expect and current values to be same to check the rest of the state
expectedState.users[user].eth = currentState.users[user].eth;
expectedState.users[user].alca = currentState.users[user].alca;
}
assert.deepEqual(currentState, expectedState);
});
Expand Down

0 comments on commit 154f52d

Please sign in to comment.