Skip to content

Commit

Permalink
Update scripts and tests for new deployer template
Browse files Browse the repository at this point in the history
  • Loading branch information
gretzke committed Dec 2, 2023
1 parent 40c6b99 commit cd9fb2f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 77 deletions.
20 changes: 0 additions & 20 deletions script/1.0.0/Deploy.s.sol

This file was deleted.

26 changes: 0 additions & 26 deletions script/1.0.0/Inputs.sol

This file was deleted.

17 changes: 17 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;

import "forge-std/Script.sol";
import "script/util/ScriptHelpers.sol";

import "script/deployers/CounterDeployer.s.sol";

contract Deploy is Script, ScriptHelpers, CounterDeployer {
using stdJson for string;

function run() public {
address proxyAdmin = address(0);
uint256 initialNumber = 5;
deployCounterTransparent(proxyAdmin, initialNumber);
}
}
7 changes: 0 additions & 7 deletions script/config.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
pragma solidity ^0.8.0;

////////////////////////////////////////////////////
// AUTOGENERATED - DO NOT EDIT THIS FILE DIRECTLY //
////////////////////////////////////////////////////

import "forge-std/Script.sol";

import "src/Counter.sol";
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import {TransparentUpgradeableProxy, ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

struct CounterInput {
uint256 number;
}

abstract contract CounterDeployer is Script {
Counter internal counter;
ProxyAdmin internal counterProxyAdmin;
address internal counterLogic;

function deployCounter(address proxyAdminOwner, CounterInput memory input) internal {
bytes memory initData = abi.encodeCall(Counter.initialize, (input.number));

_deployCounter(proxyAdminOwner, initData);
}
address internal counterImplementation;

function deployCounter_NoInit(address proxyAdminOwner) internal {
_deployCounter(proxyAdminOwner, "");
}
function deployCounterTransparent(address proxyAdminOwner, uint256 initialNumber)
internal
returns (address implementation, address proxyAdmin, address proxy)
{
bytes memory initData = abi.encodeCall(Counter.initialize, (initialNumber));

function _deployCounter(address proxyAdminOwner, bytes memory initData) private {
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));

counterLogic = address(new Counter());
counter = Counter(address(new TransparentUpgradeableProxy(counterLogic, proxyAdminOwner, initData)));
counterImplementation = address(new Counter());
counter = Counter(address(new TransparentUpgradeableProxy(counterImplementation, proxyAdminOwner, initData)));

vm.stopBroadcast();

counterProxyAdmin =
ProxyAdmin(address(uint160(uint256(vm.load(address(counter), hex"b53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103")))));

return (counterImplementation, address(counterProxyAdmin), address(counter));
}

function deployCounterImplementation() internal returns (address implementation) {
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
implementation = address(new Counter());
vm.stopBroadcast();
}
}
18 changes: 12 additions & 6 deletions test/1.0.0/Counter.t.sol → test/Counter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@ pragma solidity 0.8.22;
import "forge-std/Test.sol";
import "test/util/TestHelpers.sol";

import "script/1.0.0/Deploy.s.sol";
import "script/deployers/CounterDeployer.s.sol";

abstract contract BeforeScript is Test, TestHelpers, CounterDeployer {
function setUp() public virtual {
deployCounter_NoInit(makeAddr(""));
counter = Counter(deployCounterImplementation());
}
}

contract CounterTest_Zero is BeforeScript {
function test_Initializes(uint256 number) public {
function test_InitialState() public {
assertEq(counter.number(), 0);
}

function test_RevertsOnInitialization(uint256 number) public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
counter.initialize(number);
assertEq(counter.number(), number);
}
}

abstract contract AfterScript is Test, TestHelpers, Deploy {
abstract contract AfterScript is Test, TestHelpers, CounterDeployer {
function setUp() public virtual {
_run_All();
address proxyAdmin = makeAddr("alice");
uint256 initialNumber = 10;
deployCounterTransparent(proxyAdmin, initialNumber);
}
}

Expand Down

0 comments on commit cd9fb2f

Please sign in to comment.