github.com/codingfuture/orig-energi3@v0.8.4/energi/contracts/src/GovernedProxyTest.sol (about) 1 // Copyright 2019 The Energi Core Authors 2 // This file is part of Energi Core. 3 // 4 // Energi Core is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Energi Core is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Energi Core. If not, see <http://www.gnu.org/licenses/>. 16 17 // Energi Governance system is the fundamental part of Energi Core. 18 19 // NOTE: It's not allowed to change the compiler due to byte-to-byte 20 // match requirement. 21 pragma solidity 0.5.16; 22 //pragma experimental SMTChecker; 23 24 // solium-disable no-empty-blocks 25 26 import { IGovernedContract, GovernedContract } from "./GovernedContract.sol"; 27 import { IUpgradeProposal } from "./IUpgradeProposal.sol"; 28 import { ISporkRegistry } from "./ISporkRegistry.sol"; 29 import { IGovernedProxy, GovernedProxy } from "./GovernedProxy.sol"; 30 import { StorageBase } from "./StorageBase.sol"; 31 32 contract MockContract is GovernedContract 33 { 34 constructor(address _proxy) public GovernedContract(_proxy) {} 35 function migrate(IGovernedContract) external {} 36 function destroy(IGovernedContract new_impl) external { 37 selfdestruct(address(new_impl)); 38 } 39 function getAddress() external view returns (address) { 40 return address(this); 41 } 42 function killStorage(StorageBase _storage) external { 43 _storage.kill(); 44 } 45 function testDrain() external { 46 selfdestruct(msg.sender); 47 } 48 function testDrain(uint amount) external { 49 msg.sender.transfer(amount); 50 } 51 function callProxy() external payable { 52 address payable p = address(uint160(proxy)); 53 p.transfer(msg.value); 54 } 55 function () external payable {} 56 } 57 58 contract MockProxy is GovernedProxy 59 { 60 constructor() public GovernedProxy( 61 IGovernedContract(address(0)), 62 new GovernedProxy( 63 new MockSporkRegistry(address(0)), 64 IGovernedProxy(address(0)) 65 ) 66 ) {} 67 68 function setImpl(IGovernedContract _impl) external { 69 impl = _impl; 70 } 71 72 function setSporkProxy(IGovernedProxy _proxy) external { 73 spork_proxy = _proxy; 74 } 75 } 76 77 contract MockSporkRegistry is MockContract, ISporkRegistry { 78 constructor(address _proxy) public MockContract(_proxy) {} 79 80 function createUpgradeProposal(IGovernedContract impl, uint, address payable) 81 external payable 82 returns (IUpgradeProposal) 83 { 84 return new MockProposal(msg.sender, impl); 85 } 86 87 function consensusGasLimits() 88 external view 89 returns(uint callGas, uint xferGas) 90 {} 91 } 92 93 contract MockProposal is IUpgradeProposal { 94 bool accepted; 95 address public parent; 96 IGovernedContract public impl; 97 98 constructor(address _parent, IGovernedContract _impl) public { 99 parent = _parent; 100 impl = _impl; 101 } 102 103 function isAccepted() external view returns(bool) { 104 return accepted; 105 } 106 function setAccepted() external { 107 accepted = true; 108 } 109 function () external payable {} 110 function created_block() external view returns(uint) { 111 return 0; 112 } 113 function deadline() external view returns(uint) { 114 return 0; 115 } 116 function fee_payer() external view returns(address payable) { 117 return address(0); 118 } 119 function fee_amount() external view returns(uint) { 120 return 0; 121 } 122 function accepted_weight() external view returns(uint) { 123 return 0; 124 } 125 function rejected_weight() external view returns(uint) { 126 return 0; 127 } 128 function total_weight() external view returns(uint) { 129 return 0; 130 } 131 function quorum_weight() external view returns(uint) { 132 return 0; 133 } 134 function isFinished() external view returns(bool) { 135 return false; 136 } 137 function withdraw() external {} 138 function destroy() external { 139 require(msg.sender == parent, "Not Owner"); 140 } 141 function collect() external {} 142 function canVote(address) external view returns(bool) { 143 return true; 144 } 145 function voteAccept() external {} 146 function voteReject() external {} 147 function setFee() external payable {} 148 } 149