Created
April 20, 2021 17:13
-
-
Save ylv-io/795ac8c5234d858b564a72039ad26647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { expect } = require('chai'); | |
const { ethers } = require('hardhat'); | |
const { ONE_DAY_IN_SECONDS } = require('../../utils/constants'); | |
const { increaseTime, getTimestamp, mineInBlock } = require('./test-helpers'); | |
describe('Test Helpers', function () { | |
beforeEach(async () => {}); | |
it.only('can mine multiple transactions within the same block', async function () { | |
const [signer] = await ethers.getSigners(); | |
let onePromise, twoPromise; | |
await mineInBlock(async () => { | |
onePromise = signer.sendTransaction({ | |
to: signer.address, | |
value: 1, | |
}); | |
twoPromise = signer.sendTransaction({ | |
to: signer.address, | |
value: 1, | |
}); | |
}); | |
const [receiptOne, receiptTwo] = await Promise.all([(await onePromise).wait(), (await twoPromise).wait()]); | |
expect(receiptOne.blockNumber).to.be.gt(0); | |
expect(receiptTwo.blockNumber).to.be.gt(0); | |
expect(receiptOne.blockNumber).to.be.eq(receiptTwo.blockNumber); | |
}); | |
it('can increase time', async function () { | |
const timestampBefore = await getTimestamp(); | |
const beforeBlock = await ethers.provider.getBlock(); | |
await increaseTime(ONE_DAY_IN_SECONDS); | |
const timestampAfter = await getTimestamp(); | |
const afterBlock = await ethers.provider.getBlock(); | |
expect(beforeBlock.number + 1).to.be.eq(afterBlock.number); | |
expect(timestampBefore).to.be.closeTo(timestampAfter - ONE_DAY_IN_SECONDS.toNumber(), 1); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment