-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create CreateTopHat contract to demonstrate like that
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |