Skip to content

Commit

Permalink
Merge pull request #735 from open-dollar/test-deploy-refactor
Browse files Browse the repository at this point in the history
Refactor Cast-Tokens Function
  • Loading branch information
daopunk authored Jul 11, 2024
2 parents 984c17c + 234e7c3 commit 31c8796
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
39 changes: 27 additions & 12 deletions script/Common.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import '@script/Registry.s.sol';
import {Test} from 'forge-std/Test.sol';
import {VmSafe} from 'forge-std/Script.sol';
import {Params, ParamChecker, OD, ETH_A, ARB, JOB_REWARD} from '@script/Params.s.sol';
import {AuthorizableUpgradeable} from '@contracts/utils/AuthorizableUpgradeable.sol';
import 'forge-std/console.sol';

abstract contract Common is Contracts, Params, Test {
Expand All @@ -18,6 +17,7 @@ abstract contract Common is Contracts, Params, Test {
bytes internal _systemCoinInitCode;
bytes internal _vault721InitCode;
bool internal _isTest;
bool internal _isCastTokens;

function logGovernor() public runIfFork {
emit log_named_address('Governor', tlcGov);
Expand Down Expand Up @@ -210,27 +210,21 @@ abstract contract Common is Contracts, Params, Test {
_contract.addAuthorization(_target);
}

// deploy Tokens
function deployTokenGovernance() public updateParams {
// deploy Tokens

if (!isNetworkAnvil()) {
address systemCoinAddress = create2.create2deploy(_systemCoinSalt, _systemCoinInitCode);
systemCoin = ISystemCoin(systemCoinAddress);
systemCoin.initialize('Open Dollar', 'OD');
} else {
if (_isTest && !isNetworkArbitrumSepolia()) {
systemCoin = OpenDollar(0x221A0f68770658C15B525d0F89F5da2baAB5f321);
vm.stopPrank();
vm.startPrank(AuthorizableUpgradeable(address(systemCoin)).authorizedAccounts()[0]);
AuthorizableUpgradeable(address(systemCoin)).addAuthorization(deployer);
vm.stopPrank();
vm.startPrank(deployer);
if (_isTest && _isCastTokens) {
_castMainnetTokensForTestDeployment();
} else {
systemCoin = new OpenDollar();
systemCoin.initialize('Open Dollar', 'OD');
protocolToken = new OpenDollarGovernance();
protocolToken.initialize('Open Dollar Governance', 'ODG');
}
protocolToken = new OpenDollarGovernance();
protocolToken.initialize('Open Dollar Governance', 'ODG');
}
address[] memory members = new address[](0);

Expand Down Expand Up @@ -310,6 +304,27 @@ abstract contract Common is Contracts, Params, Test {
new SettlementSurplusAuctioneer(address(accountingEngine), address(postSettlementSurplusAuctionHouse));
}

function _castMainnetTokensForTestDeployment() public {
/// @notice cast real systemCoin and protocolToken to test-fork deployment
systemCoin = OpenDollar(MAINNET_SYSTEM_COIN);
protocolToken = OpenDollarGovernance(MAINNET_PROTOCOL_TOKEN);
// pause current prank of test-fork deployment
vm.stopPrank();

// prank with authorized account to add authorization to deployer on systemCoin
vm.startPrank(IAuthorizable(systemCoin).authorizedAccounts()[0]);
IAuthorizable(systemCoin).addAuthorization(deployer);
vm.stopPrank();

// prank with authorized account to add authorization to deployer on protocolToken
vm.startPrank(IAuthorizable(protocolToken).authorizedAccounts()[0]);
IAuthorizable(protocolToken).addAuthorization(deployer);
vm.stopPrank();

// un-pause current prank of test-fork deployment
vm.startPrank(deployer);
}

function _setupGlobalSettlement() internal {
// setup globalSettlement [auth: disableContract]
safeEngine.addAuthorization(address(globalSettlement));
Expand Down
2 changes: 2 additions & 0 deletions script/Registry.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ address constant MAINNET_SYSTEM_COIN_ORACLE = 0x0Cb5313C825d0F00e9708BA54D906E89

// Protocol Token
address constant MAINNET_PROTOCOL_TOKEN = 0x000D636bD52BFc1B3a699165Ef5aa340BEA8939c;
// System Coin
address constant MAINNET_SYSTEM_COIN = 0x221A0f68770658C15B525d0F89F5da2baAB5f321;

// Governance Settings
uint256 constant MAINNET_INIT_VOTING_DELAY = 3600; // 12 hours in blocks
Expand Down
28 changes: 28 additions & 0 deletions test/e2e/E2ETestSpecs.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.20;

import '@script/Registry.s.sol';
import {Common} from '@test/e2e/Common.t.sol';

contract E2ETestSpecsTrue is Common {
function setUp() public virtual override {
_isCastTokens = true;
super.setUp();
}

function testCastTokens() public {
assertEq(address(systemCoin), MAINNET_SYSTEM_COIN);
assertEq(address(protocolToken), MAINNET_PROTOCOL_TOKEN);
}
}

contract E2ETestSpecsFalse is Common {
function setUp() public virtual override {
super.setUp();
}

function testCastTokens() public {
assertNotEq(address(systemCoin), MAINNET_SYSTEM_COIN);
assertNotEq(address(protocolToken), MAINNET_PROTOCOL_TOKEN);
}
}

0 comments on commit 31c8796

Please sign in to comment.