Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removal of contract code (selfdestruct) was not reflected in hardhat 2.2.0 #1415

Closed
NIC619 opened this issue Apr 21, 2021 · 2 comments · Fixed by #1419
Closed

Removal of contract code (selfdestruct) was not reflected in hardhat 2.2.0 #1415

NIC619 opened this issue Apr 21, 2021 · 2 comments · Fixed by #1419

Comments

@NIC619
Copy link

NIC619 commented Apr 21, 2021

I upgraded hardhat from 2.0.6 to 2.2.0 and ran into a problem where transaction that triggers a contract to selfdestruct succeeded (receipt.status == 1) but querying the dead contract's code still shows that the contract contains code (ethers.provider.getCode(CONTRACT_ADDRESS)).
Contract balance can be correctly updated however, but not the contract code.

To reproduce:

  • contract code (modified from Greeter example)
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.7.0;

contract Greeter {

  constructor() payable {}

  function kill() public {
    selfdestruct(msg.sender);
  }

}
  • test
const { expect } = require("chai");

describe("Greeter", function() {
  it("Should successfully update contract state after selfdestruct", async function() {
    const Greeter = await ethers.getContractFactory("Greeter");
    const greeter = await Greeter.deploy({value: 1000});
    await greeter.deployed();

    expect(await ethers.provider.getBalance(greeter.address)).to.equal(1000)
    expect(await ethers.provider.getCode(greeter.address)).to.not.equal("0x")
    await greeter.kill();
    expect(await ethers.provider.getBalance(greeter.address)).to.equal(0)
    expect(await ethers.provider.getCode(greeter.address)).to.equal("0x")
  });
});

Then install different versions of hardhat and run the test. So far I've tried 2.0.6, 2.0.10, 2.1.0, 2.1.2 and they all work fine. Only 2.2.0 fail.

@alcuadrado
Copy link
Member

Hey @NIC619, thanks for reporting this bug and trying it with different versions! It was really helpful to understand what's going on. We are now working on a fix.

@fvictorio
Copy link
Member

Thanks @NIC619, this should be fixed in hardhat@2.2.1.

pdyraga added a commit to keep-network/coverage-pools that referenced this issue Aug 24, 2021
Update hardhat version and fix unit tests

Due to an error in Hardhat 2.2.0 (NomicFoundation/hardhat#1415)
we decided to update Hardhat version and fix errors in unit and system tests.

The errors in tests were caused by functions like isOpen, takeOffer, earlyClose
being called on auctions that self destructed (the previously used version of Hardhat
seemed to tolerate such calls).
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants