I want to test these 3 different require in my mint function with Javascript.
function mint(uint256 _mintAmount) public payable {
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
I'm really new to testing so I tried something like this. obviously its wrong but how can I test that _mintAmount <= maxMintAmount in a function like this
it('mint amount', async () =>{
_mintAmount > 0;
_mintAmount <= maxMintAmount;
supply + _mintAmount <= maxSupply;
})
ended up doing this,
since all the checks were already in my mint function. mint(0) would return "need to mint at least 1 NFT" so I used assert.equal() for that. By using try/catch to get the revert error message I check for the expected output for any input that I want.
it('mint amount', async function () {
try {
await NFT.mint.sendTransaction(0);
}
catch (err) {
assert.equal("need to mint at least 1 NFT", err.reason);
}
});
it('mint amount2', async function () {
try {
await NFT.mint.sendTransaction(1);
}
catch (err) {
assert.equal("max mint amount per session exceeded", err.reason);
}
});
it('mint amount3', async function () {
try {
await NFT.mint.sendTransaction(2);
}
catch (err) {
assert.equal("max NFT limit exceeded", err.reason);
}
});