-5

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

  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 09 '22 at 22:40

1 Answers1

-3

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);
    });