Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
Add snapshot tests + refactor to Halo
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNeshi committed Sep 18, 2023
1 parent 00875bd commit 62061c6
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions test/halo/Halo.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
import {SnapshotRestorer, takeSnapshot} from "@nomicfoundation/hardhat-network-helpers";
import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers";
import {expect} from "chai";
import {BigNumber, Wallet} from "ethers";
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);
});
Expand All @@ -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));
});
});
Expand Down

0 comments on commit 62061c6

Please sign in to comment.