Skip to content

Commit

Permalink
test: create unit tests for NFT contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnigos committed Sep 15, 2022
1 parent 3d5a1fd commit 83aeec2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 124 deletions.
124 changes: 0 additions & 124 deletions test/Lock.ts

This file was deleted.

43 changes: 43 additions & 0 deletions test/NFT.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { expect } from 'chai'
import { Contract } from 'ethers'
import { ethers } from 'hardhat'

describe('NFT', () => {
const URI = 'sample URI'

let NFT: Contract
let singers: SignerWithAddress[]

beforeEach(async () => {
const NFTFactory = await ethers.getContractFactory('NFT')
;[, ...singers] = await ethers.getSigners()
NFT = await NFTFactory.deploy()
})

describe('Deployment', () => {
it('Should track name and symbol of the nft collection', async () => {
const nftName = 'DApp NFT'
const nftSymbol = 'DAPP'
expect(await NFT.name()).to.equal(nftName)
expect(await NFT.symbol()).to.equal(nftSymbol)
})
})

describe('Minting', () => {
it('Should track each minted NFT', async function () {
const firstSinger = singers[0]
const secondSinger = singers[1]

await NFT.connect(firstSinger).mint(URI)
expect(await NFT.tokenCount()).to.equal(1)
expect(await NFT.balanceOf(firstSinger.address)).to.equal(1)
expect(await NFT.tokenURI(1)).to.equal(URI)

await NFT.connect(secondSinger).mint(URI)
expect(await NFT.tokenCount()).to.equal(2)
expect(await NFT.balanceOf(secondSinger.address)).to.equal(1)
expect(await NFT.tokenURI(2)).to.equal(URI)
})
})
})

0 comments on commit 83aeec2

Please sign in to comment.