Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda