sanity.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const { ethers } = require('hardhat');
  2. const { expect } = require('chai');
  3. const { loadFixture, mine } = require('@nomicfoundation/hardhat-network-helpers');
  4. async function fixture() {
  5. const signers = await ethers.getSigners();
  6. const addresses = await Promise.all(signers.map(s => s.getAddress()));
  7. return { signers, addresses };
  8. }
  9. contract('Environment sanity', function (accounts) {
  10. beforeEach(async function () {
  11. Object.assign(this, await loadFixture(fixture));
  12. });
  13. describe('[skip-on-coverage] signers', function () {
  14. it('match accounts', async function () {
  15. expect(this.addresses).to.deep.equal(accounts);
  16. });
  17. it('signer #0 is skipped', async function () {
  18. const signer = await ethers.provider.getSigner(0);
  19. expect(this.addresses).to.not.include(await signer.getAddress());
  20. });
  21. });
  22. describe('snapshot', function () {
  23. let blockNumberBefore;
  24. it('cache and mine', async function () {
  25. blockNumberBefore = await ethers.provider.getBlockNumber();
  26. await mine();
  27. expect(await ethers.provider.getBlockNumber()).to.be.equal(blockNumberBefore + 1);
  28. });
  29. it('check snapshot', async function () {
  30. expect(await ethers.provider.getBlockNumber()).to.be.equal(blockNumberBefore);
  31. });
  32. });
  33. });