|
| 1 | +import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"; |
| 2 | +import { expect } from "chai"; |
| 3 | +import { ethers } from "hardhat"; |
| 4 | + |
| 5 | +import { deployTokenFixture } from "./token.fixture"; |
| 6 | +import { Signers } from "./types"; |
| 7 | + |
| 8 | +describe("Transfering", function () { |
| 9 | + before(async function () { |
| 10 | + this.signers = {} as Signers; |
| 11 | + const signers = await ethers.getSigners(); |
| 12 | + this.signers.admin = signers[0]; |
| 13 | + this.loadFixture = loadFixture; |
| 14 | + }); |
| 15 | + |
| 16 | + describe("Initial State", function () { |
| 17 | + beforeEach(async function () { |
| 18 | + const { token, token_address } = await this.loadFixture(deployTokenFixture); |
| 19 | + this.token = token; |
| 20 | + this.token_address = token_address; |
| 21 | + const [alice, ..._] = await ethers.getSigners(); |
| 22 | + const transferAmount = 100n; |
| 23 | + await token.connect(this.signers.admin).mint(alice.address, transferAmount); |
| 24 | + }); |
| 25 | + |
| 26 | + it("comunity members can transfer to each other", async function () { |
| 27 | + const { token } = this; |
| 28 | + const transferAmount = 100n; |
| 29 | + const [alice, bob] = await ethers.getSigners(); |
| 30 | + await token.connect(alice).transfer(bob.address, transferAmount); |
| 31 | + expect(await token.balanceOf(alice.address)).to.equal(0n); |
| 32 | + expect(await token.balanceOf(bob.address)).to.equal(transferAmount); |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + describe("Paying @ Impact Partner", function () { |
| 37 | + beforeEach(async function () { |
| 38 | + const { token, token_address } = await this.loadFixture(deployTokenFixture); |
| 39 | + this.token = token; |
| 40 | + this.token_address = token_address; |
| 41 | + }); |
| 42 | + |
| 43 | + it("can check if a partner is valid", async function () { |
| 44 | + const { token } = this; |
| 45 | + const [_, partner, customer] = await ethers.getSigners(); |
| 46 | + await token.connect(this.signers.admin).addPartner(partner.address); |
| 47 | + expect(await token.isPartner(partner.address)).to.be.true; |
| 48 | + expect(await token.isPartner(customer.address)).to.be.false; |
| 49 | + }); |
| 50 | + |
| 51 | + it("emits event for partner transfers", async function () { |
| 52 | + const { token } = this; |
| 53 | + const [_, partner, customer] = await ethers.getSigners(); |
| 54 | + const transferAmount = 100n; |
| 55 | + await token.connect(this.signers.admin).addPartner(partner.address); |
| 56 | + await token.connect(this.signers.admin).mint(customer.address, transferAmount); |
| 57 | + await expect(token.connect(customer).transfer(partner.address, transferAmount)) |
| 58 | + .to.emit(token, "ImpactPartnerTransfer") |
| 59 | + .withArgs(customer.address, partner.address, transferAmount); |
| 60 | + expect(await token.balanceOf(partner.address)).to.equal(transferAmount); |
| 61 | + expect(await token.balanceOf(customer.address)).to.equal(0n); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
0 commit comments