2

I'm writing a contract via Truffle and my understanding is that running truffle test will run my tests in a clean-room environment. E.g. a fresh deployment blockchain run on my local machine

How can I run tests on how my contract interacts with contracts that are on the ethereum mainnet? E.g. lets say that users interacting with my contract need to send specific tokens, e.g. WETH, that I haven't written.

I have a full parity node synced on my machine. Is there a way to test my contract functions and how they interact with the current state of external contracts on the ethereum mainnet?

Thanks!

1

One solution is to add the contracts you want to access to the contracts folder and create references to them

const WETH = artifacts.require("./WETH.sol");

contract("WETH Test", async accounts =>{

    let weth;

    before(async () => {
        weth = await WETH.at("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2");
    });


    it("Checking balances", async() =>{
        const balance = await weth.balanceOf("0x1122334411223344112233441122334411223344");
    });
});
  • Tried this solution but throws Error: Cannot create instance of Whitelist; no code at address 0x6198149b79AFE8114dc07b46A01d94a6af304ED9 – Senju Sep 24 at 11:52
  • @Senju It is better if you ask again as a separate question. Also make sure you are connecting to the right network. – Ismael Sep 24 at 13:47
  • Not sure what the correct setup would be. Maybe you can help me out, ethereum.stackexchange.com/questions/76214/… – Senju Sep 24 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.