0

I have forked polygon mumbai network in my local project so that I can solve the Ethernaut challenges by writing tests (to improve my understanding of ethers.js, testing, and solving the problems etc)

I thought that forking the network would create a clone with exactly the same state etc as that of the original, but I can't seem to confirm this...

I do this with hardhat.config.js:

networks: {
    hardhat: {
      accounts,
      forking: {
        url: "https://polygon-mumbai.g.alchemy.com/v2/<key>",
        blockNumber: 0,
      },
    },
}

And I run the fork locally by running:

npx hardhat node --fork https://polygon-mumbai.g.alchemy.com/v2/<key> --port 7545 --verbose

I have the ethernaut ABI, followed by the ethernaut address, and then my before hook:


const ETHERNAUT_ABI = [
  {
    anonymous: false,
    inputs: [
      {
        indexed: true,
        internalType: "address",
        name: "player",
        type: "address",
      },
      {
        indexed: false,
        internalType: "contract Level",
        name: "level",
        type: "address",
      },
    ],
    name: "LevelCompletedLog",
    type: "event",
    signature:
      "0x9dfdf7e3e630f506a3dfe38cdbe34e196353364235df33e5a3b588488d9a1e78",
  },
  {
    anonymous: false,
    inputs: [
      {
        indexed: true,
        internalType: "address",
        name: "player",
        type: "address",
      },
      {
        indexed: false,
        internalType: "address",
        name: "instance",
        type: "address",
      },
    ],
    name: "LevelInstanceCreatedLog",
    type: "event",
    signature:
      "0x7bf7f1ed7f75e83b76de0ff139966989aff81cb85aac26469c18978d86aac1c2",
  },
  {
    anonymous: false,
    inputs: [
      {
        indexed: true,
        internalType: "address",
        name: "previousOwner",
        type: "address",
      },
      {
        indexed: true,
        internalType: "address",
        name: "newOwner",
        type: "address",
      },
    ],
    name: "OwnershipTransferred",
    type: "event",
    signature:
      "0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0",
  },
  {
    inputs: [
      {
        internalType: "contract Level",
        name: "_level",
        type: "address",
      },
    ],
    name: "createLevelInstance",
    outputs: [],
    stateMutability: "payable",
    type: "function",
    payable: true,
    signature: "0xdfc86b17",
  },
  {
    inputs: [],
    name: "owner",
    outputs: [
      {
        internalType: "address",
        name: "",
        type: "address",
      },
    ],
    stateMutability: "view",
    type: "function",
    constant: true,
    signature: "0x8da5cb5b",
  },
  {
    inputs: [
      {
        internalType: "contract Level",
        name: "_level",
        type: "address",
      },
    ],
    name: "registerLevel",
    outputs: [],
    stateMutability: "nonpayable",
    type: "function",
    signature: "0x202023d4",
  },
  {
    inputs: [],
    name: "renounceOwnership",
    outputs: [],
    stateMutability: "nonpayable",
    type: "function",
    signature: "0x715018a6",
  },
  {
    inputs: [
      {
        internalType: "address payable",
        name: "_instance",
        type: "address",
      },
    ],
    name: "submitLevelInstance",
    outputs: [],
    stateMutability: "nonpayable",
    type: "function",
    signature: "0xc882d7c2",
  },
  {
    inputs: [
      {
        internalType: "address",
        name: "newOwner",
        type: "address",
      },
    ],
    name: "transferOwnership",
    outputs: [],
    stateMutability: "nonpayable",
    type: "function",
    signature: "0xf2fde38b",
  },
];

ETHERNAUT_ADDRESS = `0xe04f955e4Cf9858F8f8d60C09aBf16DF23D4672b`;

before(async () => {
  const ethernaut = await ethers.getContractAt(
    ETHERNAUT_ABI,
    ETHERNAUT_ADDRESS
  );
}

However, I get the error:

0xe04f955e4Cf9858F8f8d60C09aBf16DF23D4672b is not a contract account.

This address most certainly is a contract account, as it is the Ethernaut contract on Mumbai, seen here:

https://mumbai.polygonscan.com/address/0xe04f955e4Cf9858F8f8d60C09aBf16DF23D4672b

Clearly this is a contract account on Mumbai testnet, so why isn't it on my fork of Mumbai testnet?

1 Answer 1

0

When you write:

      forking: {
        url: "https://polygon-mumbai.g.alchemy.com/v2/<key>",
        blockNumber: 0,
      },

blockNumber: 0 means you're forking at block number 0 (docs), so of course the contract isn't deployed yet.

I believe removing it should fix your problem:

      forking: {
        url: "https://polygon-mumbai.g.alchemy.com/v2/<key>",
      },
5
  • Thanks for getting back to me, I removed this and started my node with: npx hardhat node --fork https://polygon-mumbai.g.alchemy.com/v2/<key> --port 7545 --verbose --fork-block-number 28885869 Unfortunately it is still not working... same error as above
    – pho_pho
    Commented Oct 30, 2022 at 18:08
  • I am starting my test with: hh test ./test/1-fallback.js Should i be passing in any flags with that command?
    – pho_pho
    Commented Oct 30, 2022 at 18:21
  • If I run the command hh test ./test/1-fallback.js without starting my node using the above command, i get the same errors as above, so maybe i am missing a flag when i run my test command?
    – pho_pho
    Commented Oct 30, 2022 at 18:33
  • I got it working - I had two forking: {...} entries in my hardhat.config.js and removed the blocknumber as suggested. Thank!
    – pho_pho
    Commented Oct 30, 2022 at 18:50
  • Nice, glad it worked!
    – 0xSanson
    Commented Oct 30, 2022 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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