Created
May 30, 2023 13:32
-
-
Save cleanunicorn/b0a108a38c8bf0c9542e0c76e0e8342c to your computer and use it in GitHub Desktop.
Test contracts for EIP-6780 code removal implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
// This contract destroys itself right away, when it is created. | |
contract ShouldSelfDestruct1 { | |
constructor() { | |
// Selfdestruct right away | |
selfdestruct(payable(msg.sender)); | |
} | |
} | |
// Creates an instance of ShouldSelfDestruct1 and | |
// checks whether there's any code left after deploy. | |
contract CreateAndDestroy1 { | |
function deploy() public { | |
ShouldSelfDestruct1 ssd1 = new ShouldSelfDestruct1(); | |
// We shouldn't see any code at this address | |
require(address(ssd1).codehash == keccak256(abi.encodePacked(hex''))); | |
} | |
} | |
// This contract does not selfdestruct on deploy, | |
// but has a method which executes selfdestruct, | |
// which can be called at any time (in the same tx or not). | |
contract ShouldSelfDestruct2 { | |
constructor() { | |
// We don't selfdestruct here | |
} | |
function destroy() public { | |
// Should selfdestruct if the contract was created in the same tx | |
selfdestruct(payable(msg.sender)); | |
} | |
} | |
// Creates an instance of ShouldSelfDestruct2, | |
// and calls .destroy(). | |
contract CreateAndDestroy2 { | |
event ContractAddress(address _a); | |
event ContractCode(bytes _b); | |
event ContractCodeHash(bytes32 _c); | |
function deploy() public { | |
// Create the contract | |
ShouldSelfDestruct2 ssd2 = new ShouldSelfDestruct2{ | |
salt: 0x0000000000000000000000000000000000000000000000000000000000000000 | |
}(); | |
// Call destroy in the same tx, but not in the constructor | |
ssd2.destroy(); | |
// We shouldn't see any code at this address | |
require(address(ssd2).codehash == keccak256(abi.encodePacked(hex''))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment