Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda