Add SynthProxy.sol to test_upgradeability_util.py test

pull/1757/head
webthethird 2 years ago
parent 9192fef4a7
commit 72c6d78130
  1. 5
      tests/test_upgradeability_util.py
  2. 1
      tests/upgradeability-util/TestUpgrades-0.5.0.sol
  3. 58
      tests/upgradeability-util/src/SynthProxy.sol

@ -58,6 +58,7 @@ def test_upgrades_implementation_var() -> None:
eip_1822_proxy = sl.get_contract_from_name("EIP1822Proxy")[0]
# zos_proxy = sl.get_contract_from_name("ZosProxy")[0]
master_copy_proxy = sl.get_contract_from_name("MasterCopyProxy")[0]
synth_proxy = sl.get_contract_from_name("SynthProxy")[0]
target = get_proxy_implementation_var(eip_1822_proxy)
slot = get_proxy_implementation_slot(eip_1822_proxy)
@ -77,3 +78,7 @@ def test_upgrades_implementation_var() -> None:
slot = get_proxy_implementation_slot(master_copy_proxy)
assert target == master_copy_proxy.get_state_variable_from_name("masterCopy")
assert slot.slot == 0
target = get_proxy_implementation_var(synth_proxy)
slot = get_proxy_implementation_slot(synth_proxy)
assert target == synth_proxy.get_state_variable_from_name("target")
assert slot.slot == 1

@ -3,3 +3,4 @@ pragma solidity ^0.5.0;
import "./src/EIP1822Proxy.sol";
import "./src/ZosProxy.sol";
import "./src/MasterCopyProxy.sol";
import "./src/SynthProxy.sol";

@ -0,0 +1,58 @@
pragma solidity ^0.5.0;
contract Owned {
address public owner;
constructor(address _owner) public {
require(_owner != address(0), "Owner address cannot be 0");
owner = _owner;
}
modifier onlyOwner {
require(msg.sender == owner, "Only the contract owner may perform this action");
_;
}
}
contract Proxyable is Owned {
/* The proxy this contract exists behind. */
SynthProxy public proxy;
constructor(address payable _proxy) internal {
// This contract is abstract, and thus cannot be instantiated directly
require(owner != address(0), "Owner must be set");
proxy = SynthProxy(_proxy);
}
function setProxy(address payable _proxy) external onlyOwner {
proxy = SynthProxy(_proxy);
}
}
contract SynthProxy is Owned {
Proxyable public target;
constructor(address _owner) public Owned(_owner) {}
function setTarget(Proxyable _target) external onlyOwner {
target = _target;
}
// solhint-disable no-complex-fallback
function() external payable {
assembly {
calldatacopy(0, 0, calldatasize)
/* We must explicitly forward ether to the underlying contract as well. */
let result := delegatecall(gas, sload(target_slot), 0, calldatasize, 0, 0)
returndatacopy(0, 0, returndatasize)
if iszero(result) {
revert(0, returndatasize)
}
return(0, returndatasize)
}
}
}
Loading…
Cancel
Save