Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Unit testing Solidity JS

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;
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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);
    }
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!