80 lines
3.0 KiB
JavaScript
80 lines
3.0 KiB
JavaScript
const { expect } = require("chai");
|
|
const { ethers } = require("hardhat");
|
|
|
|
describe("EdutHumanMembership", function () {
|
|
async function expectRevertWithCustomError(promise, errorName) {
|
|
try {
|
|
await promise;
|
|
expect.fail(`expected revert ${errorName}`);
|
|
} catch (err) {
|
|
expect(String(err)).to.contain(errorName);
|
|
}
|
|
}
|
|
|
|
async function deployFixture() {
|
|
const [deployer, sponsor, recipient, other] = await ethers.getSigners();
|
|
const factory = await ethers.getContractFactory("EdutHumanMembership", deployer);
|
|
const contract = await factory.deploy();
|
|
await contract.deployed();
|
|
return { contract, deployer, sponsor, recipient, other };
|
|
}
|
|
|
|
it("mints to recipient with gas-only sponsored call", async function () {
|
|
const { contract, sponsor, recipient } = await deployFixture();
|
|
const tx = await contract.connect(sponsor).mintMembership(recipient.address);
|
|
await tx.wait();
|
|
|
|
expect(await contract.name()).to.equal("EDUT ID");
|
|
expect(await contract.symbol()).to.equal("EID");
|
|
expect(await contract.ownerOf(1)).to.equal(recipient.address);
|
|
|
|
const token = await contract.tokenOf(recipient.address);
|
|
expect(token.tokenId.toNumber()).to.equal(1);
|
|
expect(token.status).to.equal(1);
|
|
expect(await contract.hasMembership(recipient.address)).to.equal(true);
|
|
});
|
|
|
|
it("rejects duplicate mint for same human wallet", async function () {
|
|
const { contract, sponsor, recipient } = await deployFixture();
|
|
await (await contract.connect(sponsor).mintMembership(recipient.address)).wait();
|
|
|
|
await expectRevertWithCustomError(
|
|
contract.connect(sponsor).mintMembership(recipient.address),
|
|
"AlreadyMinted"
|
|
);
|
|
});
|
|
|
|
it("always reports zero mint price", async function () {
|
|
const { contract } = await deployFixture();
|
|
const price = await contract.currentMintPrice();
|
|
expect(price.currency).to.equal(ethers.constants.AddressZero);
|
|
expect(price.amountAtomic.toNumber()).to.equal(0);
|
|
});
|
|
|
|
it("rejects accidental ETH value", async function () {
|
|
const { contract, sponsor, recipient } = await deployFixture();
|
|
await expectRevertWithCustomError(
|
|
contract.connect(sponsor).mintMembership(recipient.address, { value: 1 }),
|
|
"UnexpectedEthValue"
|
|
);
|
|
});
|
|
|
|
it("blocks transfer paths (soulbound)", async function () {
|
|
const { contract, sponsor, recipient, other } = await deployFixture();
|
|
await (await contract.connect(sponsor).mintMembership(recipient.address)).wait();
|
|
|
|
await expectRevertWithCustomError(
|
|
contract.connect(recipient).transferFrom(recipient.address, other.address, 1),
|
|
"SoulboundNonTransferable"
|
|
);
|
|
});
|
|
|
|
it("allows owner to update status", async function () {
|
|
const { contract, deployer, sponsor, recipient } = await deployFixture();
|
|
await (await contract.connect(sponsor).mintMembership(recipient.address)).wait();
|
|
await (await contract.connect(deployer).setMembershipStatus(recipient.address, 2)).wait();
|
|
|
|
expect(await contract.membershipStatus(recipient.address)).to.equal(2);
|
|
});
|
|
});
|