Environment
Remix
Details
Redeploying the contract with the same address using the CREATE2 in the same transaction, in which it gets selfdestruct() seems to fail.
Tx β selfdestruct() β redeploy using create2 β FAIL
Tx1 β selfdestruct() Tx2 β redeploy using create2 β SUCCESS
Why is it that we cannot selfdestruct and redeploy in the same transaction?
Code to reproduce
pragma solidity ^0.8.0;
contract Test {
function name() public pure returns(string memory) {
return "Testing Redeploy in Same Transaction";
}
function destroy() public {
address _addr = payable(address(this));
assembly {
selfdestruct(_addr)
}
}
}
contract TestCreate2 {
Test public t;
function deploy() public {
t = new Test{salt: bytes32(0)}();
}
function checkName() public view returns(string memory){
return t.name();
}
function destroyTest() public {
t.destroy();
}
// This fails...Why?
function destroyAndRedeploy() public {
t.destroy();
TestCreate2(address(this)).deploy();
}
}