diff --git a/contracts/CreateTopHat.sol b/contracts/CreateTopHat.sol new file mode 100644 index 00000000..38ed6cad --- /dev/null +++ b/contracts/CreateTopHat.sol @@ -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); + } +} \ No newline at end of file diff --git a/test/CreateTopHat.test.ts b/test/CreateTopHat.test.ts new file mode 100644 index 00000000..41de831a --- /dev/null +++ b/test/CreateTopHat.test.ts @@ -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); + }); +});