|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +/// @title PretraceFixture |
| 5 | +/// @notice A simple contract to exercise storage, balance, and nonce changes |
| 6 | +contract PretraceFixture { |
| 7 | + uint256 public value; |
| 8 | + mapping(address => uint256) public balances; |
| 9 | + |
| 10 | + constructor() payable { |
| 11 | + balances[msg.sender] = msg.value; |
| 12 | + value = 42; |
| 13 | + } |
| 14 | + |
| 15 | + function writeStorage(uint256 _value) external { |
| 16 | + value = _value; |
| 17 | + } |
| 18 | + |
| 19 | + function readStorage() external view returns (uint256) { |
| 20 | + return value; |
| 21 | + } |
| 22 | + |
| 23 | + function deposit() external payable { |
| 24 | + balances[msg.sender] += msg.value; |
| 25 | + } |
| 26 | + |
| 27 | + function withdraw(uint256 amount) external { |
| 28 | + require(balances[msg.sender] >= amount, 'Insufficient balance'); |
| 29 | + balances[msg.sender] -= amount; |
| 30 | + (bool sent, ) = msg.sender.call{value: amount}(''); |
| 31 | + require(sent, 'Transfer failed'); |
| 32 | + } |
| 33 | + |
| 34 | + function getContractBalance() external view returns (uint256) { |
| 35 | + return address(this).balance; |
| 36 | + } |
| 37 | + |
| 38 | + function getExternalBalance( |
| 39 | + address account |
| 40 | + ) external view returns (uint256) { |
| 41 | + return account.balance; |
| 42 | + } |
| 43 | + |
| 44 | + function createChild() external returns (address) { |
| 45 | + PretraceFixtureChild c = new PretraceFixtureChild(); |
| 46 | + return address(c); |
| 47 | + } |
| 48 | + |
| 49 | + function callContract(address childAddr) external { |
| 50 | + PretraceFixtureChild(childAddr).increment(); |
| 51 | + } |
| 52 | + |
| 53 | + function delegatecallContract(address childAddr) external { |
| 54 | + (bool success, ) = childAddr.delegatecall( |
| 55 | + abi.encodeWithSelector(PretraceFixtureChild.increment.selector) |
| 56 | + ); |
| 57 | + require(success, "Delegatecall failed"); |
| 58 | + }} |
| 59 | + |
| 60 | +/// @title Child |
| 61 | +/// @notice A disposable child contract used to test contract deployment and calls |
| 62 | +contract PretraceFixtureChild { |
| 63 | + uint256 public value = 1; |
| 64 | + |
| 65 | + function increment() external { |
| 66 | + value += 1; |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments