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

159
Vistas
How to pass constant solidity address variable to tests in JS

My constant address is:

const addr = '0xcd3b766ccdd6ae721141f452c550ca635964ce71';

And my solidity contract is as follows -

function temp(address _myAddress) {
    // some code
}

How to pass this constant address to JS tests

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are three different methods to do this in your test file-

Method 1 :

it ("Method1", async () => {
        const addr = '0xcd3b766ccdd6ae721141f452c550ca635964ce71';
        console.log(addr);
        await contract.temp(addr);
        const userAddress = await contract.getTempAddr(); // say this function exists
        expect(userAddressList).to.equal(addr);
        // Successfully passes address to solidity but gives assertion error (due to checksum error)
    });

Method 2:

it ("Method2", async () => {
        const Web3 = require('web3');
        const web3 = new Web3(Web3.givenProvider);
        const addr = Web3.utils.toChecksumAddress('0xcd3b766ccdd6ae721141f452c550ca635964ce71');
        await contract.temp(addr);
        const userAddress = await contract.getTempAddr();
        expect(userAddressList).to.equal(addr);
    });

Method 3:
Creating directly a wallet

it ("Method3", async () => {
        const addrWallet = new ethers.Wallet('0xcd3b766ccdd6ae721141f452c550ca635964ce71');
        await contract.temp(addrWallet.address);
        const userAddressList = await contract.getTempAddr();
        expect(userAddressList[0]).to.equal(addrWallet.address);
    });
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