const { expect } = require("chai"); const URI = "ipfs://QmTXCPCpdruEQ5HspoTQq6C4uJhP4V66PE89Ja7y8CEJCw"; const URI2 = "ipfs://QmTXCPwpdruEQ5HBpoTQq6C4uJhP4V66PE89Ja7y8CEJC2" describe("YourAppNft", function () { async function deploy() { const [owner, otherAccount] = await ethers.getSigners(); const YourAppNft = await ethers.getContractFactory("YourAppNft"); const appNft = await YourAppNft.deploy(URI); await appNft.deployed(); return appNft; } describe("Deployment", function () { it("Deploy contract and mint", async function () { const appNft = await deploy(); const uri = await appNft.tokenURI(1) expect(uri).to.equal(URI); }); it("The version number", async function () { const appNft = await deploy(); const versions = await appNft.versions() expect(versions).to.equal(1); }) it("Return correct URI", async function() { const appNft = await deploy(); const buildURI = await appNft.getPreviousBuild(1); expect(buildURI).to.equal(URI); }) it("Prohibit the production of new tokens", async function() { const appNft = await deploy(); let err; try { await appNft.mint(URI); } catch (error) { err = error.message; } expect(err).to.equal("appNft.mint is not a function"); }) }); describe("Versions", function () { it("Allow to update versions", async function () { const appNft = await deploy(); const uri = await appNft.tokenURI(1) expect(uri).to.equal(URI); await appNft.updateApp(URI2); const uri2 = await appNft.tokenURI(1) expect(uri2).to.equal(URI2); }); it("Show correct current version", async function () { const appNft = await deploy(); const uri = await appNft.tokenURI(1) expect(uri).to.equal(URI); await appNft.updateApp(URI2); const uri2 = await appNft.tokenURI(1) expect(uri2).to.equal(URI2); }); it("Not permit non-owners of the app to update versions", async function() { const appNft = await deploy(); const uri = await appNft.tokenURI(1) expect(uri).to.equal(URI); const [owner, otherAccount] = await ethers.getSigners(); let err; try { await appNft.connect(otherAccount).updateApp(URI2); const uri2 = await appNft.tokenURI(1) expect(uri2).to.equal(URI2); } catch (error) { err = error.message; } expect(err).to.equal("VM Exception while processing transaction: reverted with reason string 'Only the app owner can make this change'"); }) }); describe("Transfers", function () { it("Not permit transfers from unapproved and non-owner persons", async function() { const appNft = await deploy(); const [owner, otherAccount] = await ethers.getSigners(); let err; try { await appNft.connect(otherAccount).transferFrom(owner.address, otherAccount.address, 1); } catch (error) { err = error.message; } expect(err).to.equal("VM Exception while processing transaction: reverted with reason string 'ERC721: caller is not token owner nor approved'"); }); it("Allow transfers from owner to another address", async function() { const appNft = await deploy(); const [owner, otherAccount] = await ethers.getSigners(); await appNft.transferFrom(owner.address, otherAccount.address, 1); expect(await appNft.appOwner()).to.equal(otherAccount.address); expect(await appNft.ownerOf(1)).to.equal(otherAccount.address); }); it("Allow transfer from non-owner if address is approved", async function() { const appNft = await deploy(); const [owner, otherAccount] = await ethers.getSigners(); await appNft.approve(otherAccount.address, 1); await appNft.connect(otherAccount).transferFrom(owner.address, otherAccount.address, 1); expect(await appNft.appOwner()).to.equal(otherAccount.address); expect(await appNft.ownerOf(1)).to.equal(otherAccount.address); }) }) });