hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

Cannot upgrade a contract from an impersonated account using ethers with Forking on chain

Open nhynhyiddy opened this issue 2 years ago • 2 comments

Contract: `

contract Testing {
  function initialize() public initializer {}
  function add( uint256 a, uint256 b) public pure returns(uint256) { return a+b;}
}

`

Reproduce: scripts/testing.ts `

const [_, alice,] = await ethers.getSigners();
const aliceAddress = await alice.getAddress()
console.log("aliceAddress", aliceAddress)
const factory = await ethers.getContractFactory('Foo', alice)
const contract = await upgrades.deployProxy(factory,[])

const impersonate = await ethers.getImpersonatedSigner(aliceAddress)
console.log("impersonate address", await impersonate.getAddress())
const factory1 = await ethers.getContractFactory("Foo", impersonate)
await upgrades.upgradeProxy(contract.address, factory1)  

`

hardhat.config.ts inside networks: `hardhat: { chainId:25,

  forking: {
    url:"https://rpc.vvs.finance",
  },

  accounts: [
    {
      privateKey: <some private key1>',
      balance: "10000000000000000000000",
    },
    {
      privateKey: <some private key2>,
      balance: "10000000000000000000000",
    },
  ]
}

` Error:

Error: VM Exception while processing transaction: reverted with reason string 'Ownable: caller is not the owner'

Scripts: npx hardhat run scripts/testing.ts

If I do not fork on hardhat, contract can be upgraded. but it cannot upgrade with forking.

nhynhyiddy avatar Jul 20 '22 03:07 nhynhyiddy

This issue is also being tracked on Linear.

We use Linear to manage our development process, but we keep the conversations on Github.

LINEAR-ID: bc7d9f58-38e2-4eac-b9ce-c8c413e6c623

github-actions[bot] avatar Jul 20 '22 03:07 github-actions[bot]

Thank you for using Hardhat.

In general, if there is a problem in Hardhat, we will need a minimal reproducible example in order to investigate it. See https://stackoverflow.com/help/minimal-reproducible-example

You have provide some examples here, but they do not correlate well enough to make them reproducible. For example, contract Testing vs Foo; what is upgrades?; etc.

Can you provide us with a minimal reproducible example?

feuGeneA avatar Aug 08 '22 13:08 feuGeneA

Closing for lack of reproduction steps.

fvictorio avatar Oct 03 '22 13:10 fvictorio