Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(migrate-hardhat-test): implement write-integration-test #21

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,5 @@ jobs:

- name: Run Forge tests
run: |
anvil --chain-id 2024 --port 8546 &
anvil --chain-id 2 --port 8547 &
forge test -vvv
id: test
3 changes: 0 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,3 @@ ethereum = "https://eth.llamarpc.com"
goerli = "https://ethereum-goerli.publicnode.com"
ronin-mainnet = "https://api-partner.roninchain.com/rpc"
ronin-testnet = "https://saigon-archive.roninchain.com/rpc"

ronin-local = "http://localhost:8546"
ethereum-local = "http://localhost:8547"
6 changes: 3 additions & 3 deletions logs/contract-code-sizes.log
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
| ERC20PresetMinterPauser | 6.368 | 18.208 |
| EnumerableSet | 0.086 | 24.49 |
| ErrorHandler | 0.086 | 24.49 |
| GeneralConfig | 20.616 | 3.96 |
| GeneralConfig | 20.136 | 4.44 |
| GeneralConfigExtended | 20.35 | 4.226 |
| GlobalProposal | 0.166 | 24.41 |
| HasBridgeDeprecated | 0.063 | 24.513 |
Expand Down Expand Up @@ -44,9 +44,9 @@
| MockRoninBridgeManager | 24.601 | -0.025 |
| MockRoninGatewayV3Extended | 20.048 | 4.528 |
| MockTUint256Slot | 2.73 | 21.846 |
| MockValidatorContract_OnlyTiming_ForHardhatTest | 1.115 | 23.461 |
| MockValidatorContract_OnlyTiming_ForHardhatTest | 1.06 | 23.516 |
| MockValidatorSet_ForFoundryTest | 0.172 | 24.404 |
| MockWrappedToken | 1.978 | 22.598 |
| MockWrappedToken | 2.225 | 22.351 |
| PRBMathUtils | 0.063 | 24.513 |
| PauseEnforcer | 4.548 | 20.028 |
| Proposal | 0.166 | 24.41 |
Expand Down
12 changes: 12 additions & 0 deletions logs/storage/BaseMigrationV2.sol:BaseMigrationV2.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
script/BaseMigrationV2.sol:BaseMigrationV2:stdstore (storage_slot: 0) (offset: 0) (type: struct StdStorage) (numberOfBytes: 224)
script/BaseMigrationV2.sol:BaseMigrationV2:stdChainsInitialized (storage_slot: 7) (offset: 0) (type: bool) (numberOfBytes: 1)
script/BaseMigrationV2.sol:BaseMigrationV2:chains (storage_slot: 8) (offset: 0) (type: mapping(string => struct StdChains.Chain)) (numberOfBytes: 32)
script/BaseMigrationV2.sol:BaseMigrationV2:defaultRpcUrls (storage_slot: 9) (offset: 0) (type: mapping(string => string)) (numberOfBytes: 32)
script/BaseMigrationV2.sol:BaseMigrationV2:idToAlias (storage_slot: 10) (offset: 0) (type: mapping(uint256 => string)) (numberOfBytes: 32)
script/BaseMigrationV2.sol:BaseMigrationV2:fallbackToDefaultRpcUrls (storage_slot: 11) (offset: 0) (type: bool) (numberOfBytes: 1)
script/BaseMigrationV2.sol:BaseMigrationV2:gasMeteringOff (storage_slot: 11) (offset: 1) (type: bool) (numberOfBytes: 1)
script/BaseMigrationV2.sol:BaseMigrationV2:IS_SCRIPT (storage_slot: 11) (offset: 2) (type: bool) (numberOfBytes: 1)
script/BaseMigrationV2.sol:BaseMigrationV2:IS_TEST (storage_slot: 11) (offset: 3) (type: bool) (numberOfBytes: 1)
script/BaseMigrationV2.sol:BaseMigrationV2:_failed (storage_slot: 11) (offset: 4) (type: bool) (numberOfBytes: 1)
script/BaseMigrationV2.sol:BaseMigrationV2:_overriddenArgs (storage_slot: 12) (offset: 0) (type: bytes) (numberOfBytes: 32)
script/BaseMigrationV2.sol:BaseMigrationV2:_deployScript (storage_slot: 13) (offset: 0) (type: mapping(TContract => contract IMigrationScript)) (numberOfBytes: 32)
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ src/mocks/ronin/MockValidatorContract_OnlyTiming_ForHardhatTest.sol:MockValidato
src/mocks/ronin/MockValidatorContract_OnlyTiming_ForHardhatTest.sol:MockValidatorContract_OnlyTiming_ForHardhatTest:_lastUpdatedBlock (storage_slot: 1) (offset: 0) (type: uint256) (numberOfBytes: 32)
src/mocks/ronin/MockValidatorContract_OnlyTiming_ForHardhatTest.sol:MockValidatorContract_OnlyTiming_ForHardhatTest:_lastUpdatedPeriod (storage_slot: 2) (offset: 0) (type: uint256) (numberOfBytes: 32)
src/mocks/ronin/MockValidatorContract_OnlyTiming_ForHardhatTest.sol:MockValidatorContract_OnlyTiming_ForHardhatTest:_currentPeriodStartAtBlock (storage_slot: 3) (offset: 0) (type: uint256) (numberOfBytes: 32)
src/mocks/ronin/MockValidatorContract_OnlyTiming_ForHardhatTest.sol:MockValidatorContract_OnlyTiming_ForHardhatTest:_epochs (storage_slot: 4) (offset: 0) (type: uint256[]) (numberOfBytes: 32)
src/mocks/ronin/MockValidatorContract_OnlyTiming_ForHardhatTest.sol:MockValidatorContract_OnlyTiming_ForHardhatTest:_periodOf (storage_slot: 5) (offset: 0) (type: mapping(uint256 => uint256)) (numberOfBytes: 32)
src/mocks/ronin/MockValidatorContract_OnlyTiming_ForHardhatTest.sol:MockValidatorContract_OnlyTiming_ForHardhatTest:_periodOf (storage_slot: 4) (offset: 0) (type: mapping(uint256 => uint256)) (numberOfBytes: 32)
47 changes: 47 additions & 0 deletions script/BaseMigrationV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "foundry-deployment-kit/BaseMigration.s.sol";

abstract contract BaseMigrationV2 is BaseMigration {
using StdStyle for *;
using LibString for bytes32;
using LibProxy for address payable;

function _deployProxy(TContract contractType, bytes memory args)
internal
virtual
override
logFn(string.concat("_deployProxy ", TContract.unwrap(contractType).unpackOne()))
returns (address payable deployed)
{
string memory contractName = CONFIG.getContractName(contractType);

address logic = _deployLogic(contractType);
string memory proxyAbsolutePath = "TransparentUpgradeableProxyV2.sol:TransparentUpgradeableProxyV2";
uint256 proxyNonce;
address proxyAdmin = _getProxyAdmin();
assertTrue(proxyAdmin != address(0x0), "BaseMigration: Null ProxyAdmin");

(deployed, proxyNonce) = _deployRaw(proxyAbsolutePath, abi.encode(logic, proxyAdmin, args));

// validate proxy admin
address actualProxyAdmin = deployed.getProxyAdmin();
assertEq(
actualProxyAdmin,
proxyAdmin,
string.concat(
"BaseMigration: Invalid proxy admin\n",
"Actual: ",
vm.toString(actualProxyAdmin),
"\nExpected: ",
vm.toString(proxyAdmin)
)
);

CONFIG.setAddress(network(), contractType, deployed);
ARTIFACT_FACTORY.generateArtifact(
sender(), deployed, proxyAbsolutePath, string.concat(contractName, "Proxy"), args, proxyNonce
);
}
}
25 changes: 5 additions & 20 deletions script/GeneralConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,6 @@ contract GeneralConfig is BaseGeneralConfig, Utils {
Network.RoninDevnet.envLabel(),
Network.RoninDevnet.explorer()
);

setNetworkInfo(
Network.RoninLocal.chainId(),
Network.RoninLocal.key(),
Network.RoninLocal.chainAlias(),
Network.RoninLocal.deploymentDir(),
Network.RoninLocal.envLabel(),
Network.RoninLocal.explorer()
);

setNetworkInfo(
Network.EthLocal.chainId(),
Network.EthLocal.key(),
Network.EthLocal.chainAlias(),
Network.EthLocal.deploymentDir(),
Network.EthLocal.envLabel(),
Network.EthLocal.explorer()
);
}

function _setUpContracts() internal virtual override {
Expand All @@ -71,6 +53,9 @@ contract GeneralConfig is BaseGeneralConfig, Utils {
_contractNameMap[Contract.AXS.key()] = "MockERC20";
_contractNameMap[Contract.SLP.key()] = "MockERC20";
_contractNameMap[Contract.USDC.key()] = "MockERC20";

_contractNameMap[Contract.RoninPauseEnforcer.key()] = "PauseEnforcer";
_contractNameMap[Contract.MainchainPauseEnforcer.key()] = "PauseEnforcer";
}

function _mapContractName(Contract contractEnum) internal {
Expand All @@ -79,8 +64,8 @@ contract GeneralConfig is BaseGeneralConfig, Utils {

function getSender() public view virtual override returns (address payable sender) {
sender = _option.trezor ? payable(_trezorSender) : payable(_envSender);
bool isLocalNetwork = getCurrentNetwork() == DefaultNetwork.Local.key()
|| getCurrentNetwork() == Network.RoninLocal.key() || getCurrentNetwork() == Network.EthLocal.key();
bool isLocalNetwork = getCurrentNetwork() == DefaultNetwork.Local.key();

if (sender == address(0x0) && isLocalNetwork) sender = payable(DEFAULT_SENDER);
require(sender != address(0x0), "GeneralConfig: Sender is address(0x0)");
}
Expand Down
111 changes: 59 additions & 52 deletions script/Migration.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { BaseMigration } from "foundry-deployment-kit/BaseMigration.s.sol";
import { BaseMigrationV2 } from "./BaseMigrationV2.sol";
import { DefaultNetwork } from "foundry-deployment-kit/utils/DefaultNetwork.sol";
import { GeneralConfig } from "./GeneralConfig.sol";
import { ISharedArgument } from "./interfaces/ISharedArgument.sol";
Expand All @@ -12,7 +12,7 @@ import { GlobalProposal } from "@ronin/contracts/libraries/GlobalProposal.sol";
import { Token } from "@ronin/contracts/libraries/Token.sol";
import { LibArray } from "./libraries/LibArray.sol";

contract Migration is BaseMigration, Utils {
contract Migration is BaseMigrationV2, Utils {
ISharedArgument public constant config = ISharedArgument(address(CONFIG));

function _configByteCode() internal virtual override returns (bytes memory) {
Expand All @@ -21,54 +21,55 @@ contract Migration is BaseMigration, Utils {

function _sharedArguments() internal virtual override returns (bytes memory rawArgs) {
ISharedArgument.SharedParameter memory param;
param.test.proxyAdmin = makeAddr("proxy-admin");
param.test.dposGA = makeAddr("governance-admin");
param.test.mainchainChainId = Network.EthLocal.chainId();
param.test.roninChainId = Network.RoninLocal.chainId();

// tokens
param.weth.name = "Wrapped WETH";
param.weth.symbol = "WETH";
param.wron.name = "Wrapped RON";
param.wron.symbol = "WRON";
param.axs.name = "Axie Infinity Shard";
param.axs.symbol = "AXS";
param.slp.name = "Smooth Love Potion";
param.slp.symbol = "SLP";
param.usdc.name = "USD Coin";
param.usdc.symbol = "USDC";

uint256 num = 6;
address[] memory operatorAddrs = new address[](num);
address[] memory governorAddrs = new address[](num);
uint256[] memory operatorPKs = new uint256[](num);
uint256[] memory governorPKs = new uint256[](num);
uint96[] memory voteWeights = new uint96[](num);
GlobalProposal.TargetOption[] memory options = new GlobalProposal.TargetOption[](0);
address[] memory targets = new address[](0);

for (uint256 i; i < num; i++) {
(address addrOperator, uint256 pkOperator) = makeAddrAndKey(string.concat("operator-", vm.toString(i + 1)));
(address addrGovernor, uint256 pkGovernor) = makeAddrAndKey(string.concat("governor-", vm.toString(i + 1)));

operatorAddrs[i] = addrOperator;
governorAddrs[i] = addrGovernor;
operatorPKs[i] = pkOperator;
governorPKs[i] = pkGovernor;
voteWeights[i] = 100;
}

LibArray.inlineSortByValue(operatorPKs, LibArray.toUint256s(operatorAddrs));
LibArray.inlineSortByValue(governorPKs, LibArray.toUint256s(governorAddrs));

param.test.operatorPKs = operatorPKs;
param.test.governorPKs = governorPKs;

if (network() == Network.Goerli.key()) {
// Undefined
} else if (network() == DefaultNetwork.RoninTestnet.key()) {
// Undefined
} else if (network() == Network.RoninLocal.key() || network() == Network.EthLocal.key()) {
} else if (network() == DefaultNetwork.Local.key()) {
// test
param.test.numberOfBlocksInEpoch = 200;
param.test.proxyAdmin = makeAddr("proxy-admin");
param.test.dposGA = makeAddr("governance-admin");

// tokens
param.weth.name = "Wrapped WETH";
param.weth.symbol = "WETH";
param.wron.name = "Wrapped RON";
param.wron.symbol = "WRON";
param.axs.name = "Axie Infinity Shard";
param.axs.symbol = "AXS";
param.slp.name = "Smooth Love Potion";
param.slp.symbol = "SLP";
param.usdc.name = "USD Coin";
param.usdc.symbol = "USDC";

uint256 num = 6;
address[] memory operatorAddrs = new address[](num);
address[] memory governorAddrs = new address[](num);
uint256[] memory operatorPKs = new uint256[](num);
uint256[] memory governorPKs = new uint256[](num);
uint96[] memory voteWeights = new uint96[](num);
GlobalProposal.TargetOption[] memory options = new GlobalProposal.TargetOption[](0);
address[] memory targets = new address[](0);

for (uint256 i; i < num; i++) {
(address addrOperator, uint256 pkOperator) = makeAddrAndKey(string.concat("operator-", vm.toString(i + 1)));
(address addrGovernor, uint256 pkGovernor) = makeAddrAndKey(string.concat("governor-", vm.toString(i + 1)));

operatorAddrs[i] = addrOperator;
governorAddrs[i] = addrGovernor;
operatorPKs[i] = pkOperator;
governorPKs[i] = pkGovernor;
voteWeights[i] = 100;
}

LibArray.inlineSortByValue(operatorPKs, LibArray.toUint256s(operatorAddrs));
LibArray.inlineSortByValue(governorPKs, LibArray.toUint256s(governorAddrs));

param.test.operatorPKs = operatorPKs;
param.test.governorPKs = governorPKs;

// Bridge rewards
param.bridgeReward.dposGA = param.test.dposGA;
param.bridgeReward.rewardPerPeriod = 5_000;
Expand All @@ -78,6 +79,10 @@ contract Migration is BaseMigration, Utils {

// Bridge Tracking

// Ronin Gateway Pause Enforcer
param.roninPauseEnforcer.admin = makeAddr("pause-enforcer-admin");
param.roninPauseEnforcer.sentries = wrapAddress(makeAddr("pause-enforcer-sentry"));

// Ronin Gateway V3
param.roninGatewayV3.numerator = 3;
param.roninGatewayV3.denominator = 6;
Expand All @@ -88,15 +93,20 @@ contract Migration is BaseMigration, Utils {
param.roninBridgeManager.num = 2;
param.roninBridgeManager.denom = 4;
param.roninBridgeManager.roninChainId = 0;
param.roninBridgeManager.roninChainId = param.test.roninChainId;
param.roninBridgeManager.roninChainId = block.chainid;
param.roninBridgeManager.expiryDuration = 60 * 60 * 24 * 14; // 14 days
param.roninBridgeManager.bridgeOperators = operatorAddrs;
param.roninBridgeManager.governors = governorAddrs;
param.roninBridgeManager.voteWeights = voteWeights;
param.roninBridgeManager.targetOptions = options;
param.roninBridgeManager.targets = targets;

// Mainchain Gateway Pause Enforcer
param.mainchainPauseEnforcer.admin = makeAddr("pause-enforcer-admin");
param.mainchainPauseEnforcer.sentries = wrapAddress(makeAddr("pause-enforcer-sentry"));

// Mainchain Gateway V3
param.mainchainGatewayV3.roninChainId = param.test.roninChainId;
param.mainchainGatewayV3.roninChainId = block.chainid;
param.mainchainGatewayV3.numerator = 1;
param.mainchainGatewayV3.highTierVWNumerator = 10;
param.mainchainGatewayV3.denominator = 10;
Expand All @@ -105,14 +115,12 @@ contract Migration is BaseMigration, Utils {
param.mainchainBridgeManager.num = 2;
param.mainchainBridgeManager.denom = 4;
param.mainchainBridgeManager.roninChainId = 0;
param.mainchainBridgeManager.roninChainId = param.test.roninChainId;
param.mainchainBridgeManager.roninChainId = block.chainid;
param.mainchainBridgeManager.bridgeOperators = operatorAddrs;
param.mainchainBridgeManager.governors = governorAddrs;
param.mainchainBridgeManager.voteWeights = voteWeights;
param.mainchainBridgeManager.targetOptions = options;
param.mainchainBridgeManager.targets = targets;
} else if (network() == DefaultNetwork.Local.key()) {
// Undefined
} else {
revert("Migration: Network Unknown Shared Parameters Unimplemented!");
}
Expand All @@ -121,8 +129,7 @@ contract Migration is BaseMigration, Utils {
}

function _getProxyAdmin() internal virtual override returns (address payable) {
bool isLocalNetwork = network() == DefaultNetwork.Local.key() || network() == Network.RoninLocal.key()
|| network() == Network.EthLocal.key();
bool isLocalNetwork = network() == DefaultNetwork.Local.key();
return isLocalNetwork ? payable(config.sharedArguments().test.proxyAdmin) : super._getProxyAdmin();
}
}
1 change: 0 additions & 1 deletion script/contracts/MainchainGatewayV3Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.19;

import { MainchainGatewayV3 } from "@ronin/contracts/mainchain/MainchainGatewayV3.sol";
import { IWETH } from "src/interfaces/IWETH.sol";
import { Contract } from "../utils/Contract.sol";
import { ISharedArgument } from "../interfaces/ISharedArgument.sol";
import { Migration } from "../Migration.s.sol";
Expand Down
13 changes: 13 additions & 0 deletions script/contracts/MainchainPauseEnforcerDeploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { PauseEnforcer } from "@ronin/contracts/ronin/gateway/PauseEnforcer.sol";
import { Contract } from "../utils/Contract.sol";
import { ISharedArgument } from "../interfaces/ISharedArgument.sol";
import { Migration } from "../Migration.s.sol";

contract MainchainPauseEnforcerDeploy is Migration {
function run() public virtual returns (PauseEnforcer) {
return PauseEnforcer(_deployProxy(Contract.MainchainPauseEnforcer.key(), EMPTY_ARGS));
}
}
13 changes: 13 additions & 0 deletions script/contracts/RoninPauseEnforcerDeploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { PauseEnforcer } from "@ronin/contracts/ronin/gateway/PauseEnforcer.sol";
import { Contract } from "../utils/Contract.sol";
import { ISharedArgument } from "../interfaces/ISharedArgument.sol";
import { Migration } from "../Migration.s.sol";

contract RoninPauseEnforcerDeploy is Migration {
function run() public virtual returns (PauseEnforcer) {
return PauseEnforcer(_deployProxy(Contract.RoninPauseEnforcer.key(), EMPTY_ARGS));
}
}
Loading
Loading