generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"; | ||
import { expect } from "chai"; | ||
import { ethers } from "hardhat"; | ||
|
||
import { deployTokenFixture } from "./token.fixture"; | ||
import { Signers } from "./types"; | ||
|
||
describe("Minting", function () { | ||
before(async function () { | ||
this.signers = {} as Signers; | ||
const signers = await ethers.getSigners(); | ||
this.signers.admin = signers[0]; | ||
this.loadFixture = loadFixture; | ||
}); | ||
|
||
describe("Initial State", function () { | ||
beforeEach(async function () { | ||
const { token, token_address } = await this.loadFixture(deployTokenFixture); | ||
this.token = token; | ||
this.token_address = token_address; | ||
}); | ||
|
||
it("owner is the community steward"); | ||
|
||
it("should allow the community steward to mint to themselves", async function () { | ||
const initialSupply = await this.token.totalSupply(); | ||
await this.token.mint(this.signers.admin.address, 100); | ||
expect(await this.token.totalSupply()).to.equal(initialSupply + 100n); | ||
}); | ||
|
||
it("should allow the community steward to mint to others", async function () { | ||
const [_, newOwner] = await ethers.getSigners(); | ||
const initialSupply = await this.token.totalSupply(); | ||
await this.token.mint(newOwner.address, 100); | ||
expect(await this.token.totalSupply()).to.equal(initialSupply + 100n); | ||
}); | ||
|
||
it("should not allow non-comunity stewards to mint", async function () { | ||
const [_, nonOwner] = await ethers.getSigners(); | ||
await expect(this.token.connect(nonOwner).mint(nonOwner.address, 100)).to.be.reverted; | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"; | ||
import { expect } from "chai"; | ||
import { ethers } from "hardhat"; | ||
|
||
import { deployTokenFixture } from "./token.fixture"; | ||
import { Signers } from "./types"; | ||
|
||
describe("Ownership", () => { | ||
before(async function () { | ||
this.signers = {} as Signers; | ||
const signers = await ethers.getSigners(); | ||
this.signers.admin = signers[0]; | ||
this.loadFixture = loadFixture; | ||
}); | ||
|
||
describe("Initial State", () => { | ||
beforeEach(async function () { | ||
const { token, token_address } = await this.loadFixture(deployTokenFixture); | ||
this.token = token; | ||
this.token_address = token_address; | ||
}); | ||
|
||
it("should be owned by the community steward", async function () { | ||
expect(await this.token.owner()).to.equal(this.signers.admin.address); | ||
}); | ||
|
||
it("should be able to transfer ownership", async function () { | ||
const [_, newOwner] = await ethers.getSigners(); | ||
await this.token.transferOwnership(newOwner.address); | ||
expect(await this.token.owner()).to.equal(newOwner.address); | ||
}); | ||
|
||
it("only community steward can pause transfers"); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ethers } from "hardhat"; | ||
|
||
import { KolektivoTTD, KolektivoTTD__factory } from "../types"; | ||
|
||
export async function deployTokenFixture() { | ||
// Contracts are deployed using the first signer/account by default | ||
const [_] = await ethers.getSigners(); | ||
const Token = (await ethers.getContractFactory("KolektivoTTD")) as KolektivoTTD__factory; | ||
const token = (await Token.deploy()) as KolektivoTTD; | ||
const token_address = await token.getAddress(); | ||
|
||
return { token, token_address }; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"; | ||
import { expect } from "chai"; | ||
import { ethers } from "hardhat"; | ||
|
||
import { deployTokenFixture } from "./token.fixture"; | ||
import { Signers } from "./types"; | ||
|
||
describe("Transfering", function () { | ||
before(async function () { | ||
this.signers = {} as Signers; | ||
const signers = await ethers.getSigners(); | ||
this.signers.admin = signers[0]; | ||
this.loadFixture = loadFixture; | ||
}); | ||
|
||
describe("Initial State", function () { | ||
beforeEach(async function () { | ||
const { token, token_address } = await this.loadFixture(deployTokenFixture); | ||
this.token = token; | ||
this.token_address = token_address; | ||
const [alice, ..._] = await ethers.getSigners(); | ||
const transferAmount = 100n; | ||
await token.connect(this.signers.admin).mint(alice.address, transferAmount); | ||
}); | ||
|
||
it("comunity members can transfer to each other", async function () { | ||
const { token } = this; | ||
const transferAmount = 100n; | ||
const [alice, bob] = await ethers.getSigners(); | ||
await token.connect(alice).transfer(bob.address, transferAmount); | ||
expect(await token.balanceOf(alice.address)).to.equal(0n); | ||
expect(await token.balanceOf(bob.address)).to.equal(transferAmount); | ||
}); | ||
}); | ||
|
||
describe("Paying @ Impact Partner", function () { | ||
beforeEach(async function () { | ||
const { token, token_address } = await this.loadFixture(deployTokenFixture); | ||
this.token = token; | ||
this.token_address = token_address; | ||
}); | ||
|
||
it("can check if a partner is valid", async function () { | ||
const { token } = this; | ||
const [_, partner, customer] = await ethers.getSigners(); | ||
await token.connect(this.signers.admin).addPartner(partner.address); | ||
expect(await token.isPartner(partner.address)).to.be.true; | ||
expect(await token.isPartner(customer.address)).to.be.false; | ||
}); | ||
|
||
it("emits event for partner transfers", async function () { | ||
const { token } = this; | ||
const [_, partner, customer] = await ethers.getSigners(); | ||
const transferAmount = 100n; | ||
await token.connect(this.signers.admin).addPartner(partner.address); | ||
await token.connect(this.signers.admin).mint(customer.address, transferAmount); | ||
await expect(token.connect(customer).transfer(partner.address, transferAmount)) | ||
.to.emit(token, "ImpactPartnerTransfer") | ||
.withArgs(customer.address, partner.address, transferAmount); | ||
expect(await token.balanceOf(partner.address)).to.equal(transferAmount); | ||
expect(await token.balanceOf(customer.address)).to.equal(0n); | ||
}); | ||
}); | ||
}); |