Skip to content

Commit

Permalink
Cleanup and fix flaky tests (#43)
Browse files Browse the repository at this point in the history
* use hh helpers to fix flakiness

* skip coverage for testers
  • Loading branch information
arjun-io authored Jul 22, 2023
1 parent feef088 commit 8df48d1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/common/testutil/time.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '@nomiclabs/hardhat-ethers'
import { mine, mineUpTo, time } from '@nomicfoundation/hardhat-network-helpers'
import HRE from 'hardhat'
import { HardhatConfig } from 'hardhat/types'
const { ethers } = HRE
Expand All @@ -10,24 +11,25 @@ export async function currentBlockTimestamp(): Promise<number> {
}

export async function advanceBlock(): Promise<void> {
await ethers.provider.send('evm_mine', [])
await mine()
}

export async function advanceBlockTo(block: number): Promise<void> {
while ((await ethers.provider.getBlockNumber()) < block) {
await ethers.provider.send('evm_mine', [])
}
await mineUpTo(block)
}

export async function increase(duration: number): Promise<void> {
await ethers.provider.send('evm_increaseTime', [duration])
await advanceBlock()
await time.increase(duration)
}

export async function increaseTo(timestamp: number): Promise<void> {
const currentTimestamp = await currentBlockTimestamp()
await ethers.provider.send('evm_increaseTime', [timestamp - currentTimestamp])
await advanceBlock()
if (timestamp < currentTimestamp) {
await ethers.provider.send('evm_increaseTime', [timestamp - currentTimestamp])
await advanceBlock()
} else {
await time.increaseTo(timestamp)
}
const newTimestamp = await currentBlockTimestamp()
if (timestamp != newTimestamp)
console.log('[WARNING] increaseTo failed to reach timestamp (%s vs %s)', timestamp, newTimestamp)
Expand Down
3 changes: 3 additions & 0 deletions packages/perennial-extensions/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
skipFiles: ['test'],
}
3 changes: 3 additions & 0 deletions packages/perennial-oracle/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
skipFiles: ['test'],
}
3 changes: 3 additions & 0 deletions packages/perennial-payoff/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
skipFiles: ['test'],
}
3 changes: 3 additions & 0 deletions packages/perennial-vault/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
skipFiles: ['test'],
}
3 changes: 3 additions & 0 deletions packages/perennial/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
skipFiles: ['test'],
}

0 comments on commit 8df48d1

Please sign in to comment.