Commit a796ae3d authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: upgradable dispute game factory

Alter the dispute game factory such that it used in with
a proxy pattern. The tests are minimally modified in a way
where they now go through the proxy because the constructor
prevents usage of the contract by setting the owner to `address(0)`.
We should strive to follow this sort of pattern, although it makes
testing a bit more difficult, it forces us to test the contracts
behind proxies which is what happens in production plus it also
makes the implementation unusable such that it cannot be mistaken
as the real thing.
parent 8e834128
...@@ -4,7 +4,7 @@ pragma solidity ^0.8.15; ...@@ -4,7 +4,7 @@ pragma solidity ^0.8.15;
import "../libraries/DisputeTypes.sol"; import "../libraries/DisputeTypes.sol";
import "../libraries/DisputeErrors.sol"; import "../libraries/DisputeErrors.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { ClonesWithImmutableArgs } from "@cwia/ClonesWithImmutableArgs.sol"; import { ClonesWithImmutableArgs } from "@cwia/ClonesWithImmutableArgs.sol";
import { IDisputeGame } from "./interfaces/IDisputeGame.sol"; import { IDisputeGame } from "./interfaces/IDisputeGame.sol";
...@@ -14,7 +14,7 @@ import { IDisputeGameFactory } from "./interfaces/IDisputeGameFactory.sol"; ...@@ -14,7 +14,7 @@ import { IDisputeGameFactory } from "./interfaces/IDisputeGameFactory.sol";
* @title DisputeGameFactory * @title DisputeGameFactory
* @notice A factory contract for creating `IDisputeGame` contracts. * @notice A factory contract for creating `IDisputeGame` contracts.
*/ */
contract DisputeGameFactory is Ownable, IDisputeGameFactory { contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory {
/** /**
* @dev Allows for the creation of clone proxies with immutable arguments. * @dev Allows for the creation of clone proxies with immutable arguments.
*/ */
...@@ -40,11 +40,20 @@ contract DisputeGameFactory is Ownable, IDisputeGameFactory { ...@@ -40,11 +40,20 @@ contract DisputeGameFactory is Ownable, IDisputeGameFactory {
IDisputeGame[] public disputeGameList; IDisputeGame[] public disputeGameList;
/** /**
* @notice Constructs a new DisputeGameFactory contract. * @notice Constructs a new DisputeGameFactory contract. Set the owner
* to `address(0)` to prevent accidental usage of the implementation.
*/
constructor() OwnableUpgradeable() {
_transferOwnership(address(0));
}
/**
* @notice Initializes the contract.
* @param _owner The owner of the contract. * @param _owner The owner of the contract.
*/ */
constructor(address _owner) Ownable() { function initialize(address _owner) external initializer {
transferOwnership(_owner); __Ownable_init();
_transferOwnership(_owner);
} }
/** /**
......
...@@ -7,10 +7,10 @@ import "../libraries/DisputeErrors.sol"; ...@@ -7,10 +7,10 @@ import "../libraries/DisputeErrors.sol";
import { Test } from "forge-std/Test.sol"; import { Test } from "forge-std/Test.sol";
import { DisputeGameFactory } from "../dispute/DisputeGameFactory.sol"; import { DisputeGameFactory } from "../dispute/DisputeGameFactory.sol";
import { IDisputeGame } from "../dispute/interfaces/IDisputeGame.sol"; import { IDisputeGame } from "../dispute/interfaces/IDisputeGame.sol";
import { Proxy } from "../universal/Proxy.sol";
contract DisputeGameFactory_Test is Test { contract DisputeGameFactory_Initializer is Test {
DisputeGameFactory factory; DisputeGameFactory factory;
FakeClone fakeClone;
event DisputeGameCreated( event DisputeGameCreated(
address indexed disputeProxy, address indexed disputeProxy,
...@@ -20,8 +20,26 @@ contract DisputeGameFactory_Test is Test { ...@@ -20,8 +20,26 @@ contract DisputeGameFactory_Test is Test {
event ImplementationSet(address indexed impl, GameType indexed gameType); event ImplementationSet(address indexed impl, GameType indexed gameType);
function setUp() public { function setUp() public virtual {
factory = new DisputeGameFactory(address(this)); Proxy proxy = new Proxy(address(this));
DisputeGameFactory impl = new DisputeGameFactory();
proxy.upgradeToAndCall({
_implementation: address(impl),
_data: abi.encodeCall(
impl.initialize,
(address(this))
)
});
factory = DisputeGameFactory(address(proxy));
}
}
contract DisputeGameFactory_Test is DisputeGameFactory_Initializer {
FakeClone fakeClone;
function setUp() public override {
super.setUp();
fakeClone = new FakeClone(); fakeClone = new FakeClone();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment