Skip to content

Commit

Permalink
Create CreateTopHat contract to demonstrate like that
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgall committed Jun 21, 2024
1 parent 19992b6 commit 6e99a2b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
19 changes: 19 additions & 0 deletions contracts/CreateTopHat.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

import { IHats } from "./interfaces/hats/IHats.sol";

contract CreateTopHat {
IHats hats;

event DeclareTopHatId(address indexed declarer, uint256 topHatId);

constructor(IHats _hats) {
hats = _hats;
}

function createTopHat(string memory _details, string memory _imageURI) public {
uint256 topHatId = hats.mintTopHat(msg.sender, _details, _imageURI);
emit DeclareTopHatId(msg.sender, topHatId);
}
}
49 changes: 49 additions & 0 deletions test/CreateTopHat.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
CreateTopHat,
CreateTopHat__factory,
MockHats,
MockHats__factory,
} from "../typechain-types";
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { expect } from "chai";
import hre from "hardhat";

describe.only("CreateTopHat", () => {
let createTopHat: CreateTopHat;
let hats: MockHats;

let deployer: SignerWithAddress;
let dao1: SignerWithAddress;
let dao2: SignerWithAddress;

beforeEach(async () => {
[deployer, dao1, dao2] = await hre.ethers.getSigners();

hats = await new MockHats__factory(deployer).deploy();
createTopHat = await new CreateTopHat__factory(deployer).deploy(
await hats.getAddress()
);
});

it("Creates a new Top Hat with expected ID", async () => {
await expect(createTopHat.connect(dao1).createTopHat("", ""))
.to.emit(createTopHat, "DeclareTopHatId")
.withArgs(dao1.address, 0);
});

it("Creates a Top Hat from the expected address", async () => {
await expect(createTopHat.connect(dao2).createTopHat("", ""))
.to.emit(createTopHat, "DeclareTopHatId")
.withArgs(dao2.address, 0);
});

it("Creates Top Hats with sequential IDs", async () => {
await expect(createTopHat.connect(dao1).createTopHat("", ""))
.to.emit(createTopHat, "DeclareTopHatId")
.withArgs(dao1.address, 0);

await expect(createTopHat.connect(dao2).createTopHat("", ""))
.to.emit(createTopHat, "DeclareTopHatId")
.withArgs(dao2.address, 1);
});
});

0 comments on commit 6e99a2b

Please sign in to comment.