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?



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

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.