-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNftStore.js
75 lines (54 loc) · 2.33 KB
/
NftStore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("NftStore", function() {
const minterRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes("MINTER_ROLE"));
let storeInstance;
beforeEach(async function() {
const NftStore = await ethers.getContractFactory("NftStore");
storeInstance = await NftStore.deploy();
await storeInstance.deployed();
});
it("Contract should have symbol NFT", async function() {
expect(await storeInstance.symbol()).to.equal("NFT");
});
it("Contract should set MINTER_ROLE role for contract owner", async function() {
const [owner] = await ethers.getSigners();
const hasMinterRole = await storeInstance.hasRole(minterRole, owner.address);
expect(hasMinterRole).to.be.true;
});
it('MINTER_ROLE cannot be assigned after deployment', async function() {
const [owner, acct1] = await ethers.getSigners();
await expect(storeInstance.grantRole(minterRole, acct1)).to.be.reverted;
const actualMinterCount = await storeInstance.getRoleMemberCount(minterRole);
expect(actualMinterCount).to.equal(ethers.BigNumber.from(1));
});
it("Minting always assigns token to contract owner", async function() {
const [owner] = await ethers.getSigners();
const receipt = await storeInstance.mint("some-token-uri");
const ownerBalance = await storeInstance.balanceOf(owner.address);
expect(ownerBalance).to.equal(1);
});
it('Minting emits an event with tokenId, tokenUri', async function() {
const tokenId = 1;
await expect(storeInstance.mint("some-token-uri"))
.to
.emit(storeInstance, 'Mint')
.withArgs(ethers.BigNumber.from(tokenId), 'some-token-uri');
});
it("Only contract owner can mint", async function() {
const [owner, acct1] = await ethers.getSigners();
await expect(
storeInstance
.connect(acct1)
.mint("some-token-uri")
).to.be.revertedWith('Must have MINTER role to mint');
});
it("Token can be burned", async function() {
const receipt = await storeInstance.mint("some-token-uri");
const [owner] = await ethers.getSigners();
const [event] = await storeInstance.queryFilter('Mint');
await storeInstance.burn(event.args.tokenId);
ownerBalance = await storeInstance.balanceOf(owner.address);
expect(ownerBalance).to.equal(0);
});
});