Last active
August 18, 2022 18:55
-
-
Save polluterofminds/63be26b7fc838eb721bf63ccf3561332 to your computer and use it in GitHub Desktop.
App NFT test
This file contains hidden or 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
const { expect } = require("chai"); | |
const URI = "ipfs://QmTXCPCpdruEQ5HspoTQq6C4uJhP4V66PE89Ja7y8CEJCw"; | |
const URI2 = "ipfs://QmTXCPwpdruEQ5HBpoTQq6C4uJhP4V66PE89Ja7y8CEJC2" | |
describe("AppNFT", function () { | |
async function deploy() { | |
const [owner, otherAccount] = await ethers.getSigners(); | |
const AppNFT = await ethers.getContractFactory("AppNFT"); | |
const appNft = await AppNFT.deploy(URI); | |
await appNft.deployed(); | |
return appNft; | |
} | |
describe("Deployment", function () { | |
it("Should deploy contract and mint", async function () { | |
const appNft = await deploy(); | |
const uri = await appNft.tokenURI(1) | |
expect(uri).to.equal(URI); | |
}); | |
it("Should set the right version number", async function () { | |
const appNft = await deploy(); | |
const versions = await appNft.versions() | |
expect(versions).to.equal(1); | |
}) | |
it("Should return correct URI based on version", async function() { | |
const appNft = await deploy(); | |
const buildURI = await appNft.getPreviousBuild(1); | |
expect(buildURI).to.equal(URI); | |
}) | |
it("Should not allow minting additional 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("Should allow the app owner 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("Should 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("Should not allow someone who is not the app owner 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("Should not allow transfers from non owner and non approved", 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("Should 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("Should 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); | |
}) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment