Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-torabiv committed Nov 25, 2024
1 parent 40374d0 commit c640c07
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
6 changes: 3 additions & 3 deletions ignition/modules/Engagement.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";

const EngagementModule = buildModule("EngagementModule", (m) => {
const uri = m.getParameter("uri");
const uri = m.getParameter("uri");

const engagement = m.contract("Engagement", [uri], {});

return { engagement };
});

export default EngagementModule;
export default EngagementModule;
57 changes: 31 additions & 26 deletions test/Engagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,27 @@ describe("Engagement", () => {
describe("Success", () => {
it("Shuld have counter equal 0", async () => {
const { contract } = await loadFixture(deployFixture);

expect(await contract.read.counter()).to.be.equal(parseUnits("0", 0));
});

it("Should have deployer as an Admin", async () => {
const { contract, deployer } = await loadFixture(deployFixture);

const adminRole = await contract.read.DEFAULT_ADMIN_ROLE();

expect(await contract.read.hasRole([adminRole, deployer.account.address]))
.to.be.true;

expect(
await contract.read.hasRole([adminRole, deployer.account.address]),
).to.be.true;
});
})
});
describe("Revert", () => {
it("Should revert deployment if URI is empty", async () => {
await expect(
hre.viem.deployContract("Engagement", [""])
).to.be.rejectedWith("URIEmpty(\"URI cannot be empty\")");
hre.viem.deployContract("Engagement", [""]),
).to.be.rejectedWith('URIEmpty("URI cannot be empty")');
});
})
});
});

describe("Issue", () => {
Expand Down Expand Up @@ -107,48 +108,52 @@ describe("Engagement", () => {
it("Should allow admin to update base URI", async () => {
const { contract, deployer } = await loadFixture(deployFixture);
const newURI = "https://new-api.example.com";

await contract.write.issue({ account: deployer.account.address });

await contract.write.updateBaseURI([newURI], { account: deployer.account.address });

expect(await contract.read.uri([parseUnits("0", 0)])).to.be.equal(`${newURI}/0.json`);

await contract.write.updateBaseURI([newURI], {
account: deployer.account.address,
});

expect(await contract.read.uri([parseUnits("0", 0)])).to.be.equal(
`${newURI}/0.json`,
);
});

it("Should emit BaseURIUpdated event on URI change", async () => {
const { contract, deployer } = await loadFixture(deployFixture);
const newURI = "https://new-api.example.com";

const updateTx = await contract.write.updateBaseURI([newURI], {
account: deployer.account.address,
});

const baseURIEvents = await contract.getEvents.BaseURIUpdated();

expect(baseURIEvents.length).to.be.equal(1);

const event = baseURIEvents[0];
expect(event.eventName).to.be.equal("BaseURIUpdated");
expect(event.args.oldURI).to.be.equal(DEFAULT_URI);
expect(event.args.newURI).to.be.equal(newURI);
});
})
});

describe("Revert", () => {
it("Should revert if non-admin tries to update URI", async () => {
const { contract, otherAccount } = await loadFixture(deployFixture);

await expect(
contract.write.updateBaseURI(["https://new-api.example.com"], {
account: otherAccount.account.address,
})
}),
).to.be.rejectedWith(
`AccessControlUnauthorizedAccount("${getAddress(
otherAccount.account.address
)}", "0x0000000000000000000000000000000000000000000000000000000000000000")`
otherAccount.account.address,
)}", "0x0000000000000000000000000000000000000000000000000000000000000000")`,
);
});
})
});
});

describe("Uri", () => {
Expand Down

0 comments on commit c640c07

Please sign in to comment.