Mi dirección constante es:
const addr = '0xcd3b766ccdd6ae721141f452c550ca635964ce71';Y mi contrato de solidez es el siguiente:
function temp(address _myAddress) { // some code }Cómo pasar esta dirección constante a las pruebas JS
Hay tres métodos diferentes para hacer esto en su archivo de prueba:
Método 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) });Método 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); }); Método 3:
Creando directamente una billetera
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); });