Skip to content

Commit

Permalink
close #23
Browse files Browse the repository at this point in the history
  • Loading branch information
zuies committed Jun 6, 2024
1 parent 153b6a4 commit 94f74cf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions contracts/Engagement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ contract EngagementContract is IEngagement, ERC1155, AccessControl {
uint tokenId,
uint amount
) external override {
if (account != msg.sender) {
revert NotAllowed(account, tokenId);
}
_burn(account, tokenId, 1);
emit Burn(account, tokenId, 1);
}
Expand Down
1 change: 1 addition & 0 deletions contracts/IEngagement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface IEngagement {

error NotFound(uint tokenId);
error MintLimit(address account, uint tokenId);
error NotAllowed(address account, uint tokenId);

function counter() external view returns (uint);

Expand Down
23 changes: 21 additions & 2 deletions test/engagements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("Engage", function () {
// and reset Hardhat Network to that snapshot in every test.
async function deployFixture() {
// Contracts are deployed using the first signer/account by default
const [deployer, provider, otherAccount] =
const [deployer, provider, otherAccount, otherAccount2] =
await hre.viem.getWalletClients();

const contract = await hre.viem.deployContract("EngagementContract");
Expand All @@ -35,6 +35,7 @@ describe("Engage", function () {
deployer,
provider,
otherAccount,
otherAccount2,
publicClient,
};
}
Expand Down Expand Up @@ -137,11 +138,13 @@ describe("Engage", function () {
let tokenId: any;
let contract: any;
let otherAccount: any;
let otherAccount2: any;

beforeEach(async function () {
const fixture = await loadFixture(deployFixture);
contract = fixture.contract;
otherAccount = fixture.otherAccount;
otherAccount2 = fixture.otherAccount2;

tokenId = await contract.read.counter();
await contract.write.issue([hash]);
Expand Down Expand Up @@ -237,7 +240,7 @@ describe("Engage", function () {
}
);
});
describe("Success", () => {
describe("Success", async function () {
it("Should have an account balance of 0", async function () {
const balance1 = await contract.read.balanceOf([
getAddress(otherAccount.account.address),
Expand Down Expand Up @@ -281,6 +284,22 @@ describe("Engage", function () {
);
});
});
describe("Revert", async function () {
it("Should revert with NotAllowed (msg.sender != account)", async function () {
await expect(
contract.write.burn(
[getAddress(otherAccount.account.address), tokenId, amount],
{
account: otherAccount2.account.address,
}
)
).to.be.rejectedWith(
`NotAllowed("${getAddress(
otherAccount.account.address
)}", ${tokenId})`
);
});
});
});
});
});

0 comments on commit 94f74cf

Please sign in to comment.