Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcabot committed Nov 3, 2023
1 parent 94e6195 commit 63a7f0e
Showing 1 changed file with 20 additions and 43 deletions.
63 changes: 20 additions & 43 deletions test/ReferenceStatefulSBTSelfSovereign.test.ts
Expand Up @@ -46,7 +46,7 @@ const signMintSBTToAddress = async (
},
// Types
{
Mint: [
Mint: [
{ name: "to", type: "address" },
{ name: "authorityAddress", type: "address" },
{ name: "signatureDate", type: "uint256" }
Expand Down Expand Up @@ -78,7 +78,9 @@ describe("ReferenceStatefulSBTSelfSovereign", () => {
const env = getEnvParams("hardhat");
const baseUri = `${env.BASE_URI}/green/hardhat/`;

const StatefulSBT = await ethers.getContractFactory('ReferenceStatefulSBTSelfSovereign');
const StatefulSBT = await ethers.getContractFactory(
"ReferenceStatefulSBTSelfSovereign"
);
const statefulSBTDeploy = await StatefulSBT.deploy(
env.ADMIN || owner.address,
env.SOULBOUNDGREEN_NAME,
Expand All @@ -104,7 +106,7 @@ describe("ReferenceStatefulSBTSelfSovereign", () => {
soulboundIdentityAddress,
owner
);

statefulSBT = ReferenceStatefulSBTSelfSovereign__factory.connect(
statefulSBTDeploy.address,
owner
Expand All @@ -121,8 +123,6 @@ describe("ReferenceStatefulSBTSelfSovereign", () => {
// we add authority account
await statefulSBT.addAuthority(authority.address);

await statefulSBT.setMintPrice(0); // 0 USDC

signatureToAddress = await signMintSBTToAddress(
address1.address,
authority
Expand All @@ -131,9 +131,7 @@ describe("ReferenceStatefulSBTSelfSovereign", () => {

describe("owner functions", () => {
it("should set SoulboundIdentity from owner", async () => {
await statefulSBT
.connect(owner)
.setSoulboundIdentity(address1.address);
await statefulSBT.connect(owner).setSoulboundIdentity(address1.address);

expect(await statefulSBT.soulboundIdentity()).to.be.equal(
address1.address
Expand Down Expand Up @@ -170,16 +168,7 @@ describe("ReferenceStatefulSBTSelfSovereign", () => {
).to.be.revertedWith("CallerNotOwner");
});

it("should mint twice", async () => {
await statefulSBT
.connect(address1)
["mint(address,address,address,uint256,bytes)"](
ethers.constants.AddressZero,
address1.address,
authority.address,
signatureDate,
signatureToAddress
);
it("can't mint twice", async () => {
await statefulSBT
.connect(address1)
["mint(address,address,address,uint256,bytes)"](
Expand All @@ -189,10 +178,19 @@ describe("ReferenceStatefulSBTSelfSovereign", () => {
signatureDate,
signatureToAddress
);
await expect(
statefulSBT
.connect(address1)
["mint(address,address,address,uint256,bytes)"](
ethers.constants.AddressZero,
address1.address,
authority.address,
signatureDate,
signatureToAddress
)
).to.be.reverted;

expect(await statefulSBT.totalSupply()).to.equal(2);
expect(await statefulSBT.tokenByIndex(0)).to.equal(0);
expect(await statefulSBT.tokenByIndex(1)).to.equal(1);
expect(await statefulSBT.balanceOf(address1.address)).to.equal(1);
});

it("should mint from final user address", async () => {
Expand Down Expand Up @@ -228,34 +226,13 @@ describe("ReferenceStatefulSBTSelfSovereign", () => {
let mintReceipt = await mintTx.wait();
const tokenId1 = mintReceipt.events![0].args![1].toNumber();

// we mint again
mintTx = await statefulSBT
.connect(address1)
["mint(address,address,address,uint256,bytes)"](
ethers.constants.AddressZero,
address1.address,
authority.address,
signatureDate,
signatureToAddress
);
mintReceipt = await mintTx.wait();
const tokenId2 = mintReceipt.events![0].args![1].toNumber();

expect(await statefulSBT.balanceOf(address1.address)).to.be.equal(2);
expect(await statefulSBT.balanceOf(address1.address)).to.be.equal(2);
expect(await statefulSBT.balanceOf(address1.address)).to.be.equal(1);
expect(await statefulSBT["ownerOf(uint256)"](tokenId1)).to.be.equal(
address1.address
);
expect(await statefulSBT["ownerOf(uint256)"](tokenId2)).to.be.equal(
address1.address
);

await statefulSBT.connect(address1).burn(tokenId1);

expect(await statefulSBT.balanceOf(address1.address)).to.be.equal(1);

await statefulSBT.connect(address1).burn(tokenId2);

expect(await statefulSBT.balanceOf(address1.address)).to.be.equal(0);
});
});
Expand Down

0 comments on commit 63a7f0e

Please sign in to comment.