From 62061c6aeec20ee964e9b8cfc0f7983a0936aefd Mon Sep 17 00:00:00 2001 From: Nenad Date: Mon, 18 Sep 2023 13:42:58 +0200 Subject: [PATCH] Add snapshot tests + refactor to Halo --- test/halo/Halo.ts | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/test/halo/Halo.ts b/test/halo/Halo.ts index c1fbbe3c2..25ba206f1 100644 --- a/test/halo/Halo.ts +++ b/test/halo/Halo.ts @@ -1,3 +1,4 @@ +import {SnapshotRestorer, takeSnapshot} from "@nomicfoundation/hardhat-network-helpers"; import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import {expect} from "chai"; import {BigNumber, Wallet} from "ethers"; @@ -5,28 +6,37 @@ import hre from "hardhat"; import {Halo, Halo__factory} from "typechain-types"; import {getProxyAdminOwner, getSigners} from "utils"; -describe("Halo token", function () { - let Halo: Halo__factory; +describe("Halo", function () { + const INITIALSUPPLY = BigNumber.from(10).pow(27); // 1 billion tokens with 18 decimals let deployer: SignerWithAddress; let proxyAdmin: SignerWithAddress | Wallet; let user: SignerWithAddress; - describe("upon Deployment", async function () { - let halo: Halo; - let INITIALSUPPLY = BigNumber.from(10).pow(27); // 1 billion tokens with 18 decimals - - beforeEach(async function () { - const signers = await getSigners(hre); - deployer = signers.deployer; - proxyAdmin = await getProxyAdminOwner(hre); - user = signers.apTeam1; - - Halo = (await hre.ethers.getContractFactory("Halo", deployer)) as Halo__factory; - halo = await Halo.deploy(); - await halo.deployed(); - }); + let halo: Halo; + + before(async function () { + const signers = await getSigners(hre); + deployer = signers.deployer; + user = signers.apTeam1; + + proxyAdmin = await getProxyAdminOwner(hre); + + const Halo = new Halo__factory(deployer); + halo = await Halo.deploy(); + }); + let snapshot: SnapshotRestorer; + + beforeEach(async () => { + snapshot = await takeSnapshot(); + }); + + afterEach(async () => { + await snapshot.restore(); + }); + + describe("upon Deployment", async function () { it("Sends the specified amount to the specified recipient", async function () { expect(await halo.balanceOf(deployer.address)).to.equal(INITIALSUPPLY); }); @@ -38,7 +48,9 @@ describe("Halo token", function () { }); it("Token holder can burn tokens", async function () { const burnAmount = BigNumber.from(100000); - expect(await halo.burn(burnAmount)).to.emit(halo, "Burn"); + await expect(halo.burn(burnAmount)) + .to.emit(halo, "Transfer") + .withArgs(await halo.signer.getAddress(), hre.ethers.constants.AddressZero, burnAmount); expect(await halo.totalSupply()).to.equal(INITIALSUPPLY.sub(burnAmount)); }); });