Skip to content

Commit

Permalink
Merge pull request #57 from axieinfinity/feature/test-integration
Browse files Browse the repository at this point in the history
feat: support default sender for test integration
  • Loading branch information
huyhuynh3103 authored Jan 15, 2024
2 parents 51c6d91 + e9d5127 commit 3f5c3b2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
8 changes: 8 additions & 0 deletions script/BaseGeneralConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,19 @@ contract BaseGeneralConfig is RuntimeConfig, WalletConfig, ContractConfig, Netwo

function _setUpDefaultContracts() private {
_contractNameMap[DefaultContract.ProxyAdmin.key()] = DefaultContract.ProxyAdmin.name();
_contractNameMap[DefaultContract.Multicall3.key()] = DefaultContract.Multicall3.name();
setAddress(
DefaultNetwork.RoninTestnet.key(), DefaultContract.ProxyAdmin.key(), 0x505d91E8fd2091794b45b27f86C045529fa92CD7
);
setAddress(
DefaultNetwork.RoninMainnet.key(), DefaultContract.ProxyAdmin.key(), 0xA3e7d085E65CB0B916f6717da876b7bE5cC92f03
);
setAddress(
DefaultNetwork.RoninMainnet.key(), DefaultContract.Multicall3.key(), 0xcA11bde05977b3631167028862bE2a173976CA11
);
setAddress(
DefaultNetwork.RoninTestnet.key(), DefaultContract.Multicall3.key(), 0xcA11bde05977b3631167028862bE2a173976CA11
);

_setUpContracts();
}
Expand All @@ -92,6 +99,7 @@ contract BaseGeneralConfig is RuntimeConfig, WalletConfig, ContractConfig, Netwo

function getSender() public view virtual override returns (address payable sender) {
sender = _option.trezor ? payable(_trezorSender) : payable(_envSender);
if (sender == address(0x0) && getCurrentNetwork() == DefaultNetwork.Local.key()) sender = payable(DEFAULT_SENDER);
require(sender != address(0x0), "GeneralConfig: Sender is address(0x0)");
}

Expand Down
5 changes: 2 additions & 3 deletions script/BaseMigration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ abstract contract BaseMigration is ScriptExtended {

function setUp() public virtual override {
super.setUp();
vm.label(address(ARTIFACT_FACTORY), "ArtifactFactory");
deploySharedAddress(address(ARTIFACT_FACTORY), type(ArtifactFactory).creationCode);
deploySharedAddress(address(ARTIFACT_FACTORY), type(ArtifactFactory).creationCode, "ArtifactFactory");
_injectDependencies();
_storeRawSharedArguments();
}
Expand Down Expand Up @@ -66,7 +65,7 @@ abstract contract BaseMigration is ScriptExtended {
args = _overriddenArgs.length == 0 ? _defaultArguments() : _overriddenArgs;
}

function _getProxyAdmin() internal view virtual returns (address payable proxyAdmin) {
function _getProxyAdmin() internal virtual returns (address payable proxyAdmin) {
proxyAdmin = loadContract(DefaultContract.ProxyAdmin.key());
}

Expand Down
12 changes: 10 additions & 2 deletions script/configs/WalletConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ abstract contract WalletConfig is CommonBase, IWalletConfig {
public
returns (bytes memory sig)
{
sig = ethSignMessage(by, message, _loadENVPrivateKey(envLabel));
}

function ethSignMessage(address by, string memory message, uint256 privateKey) public returns (bytes memory sig) {
string[] memory commandInput = new string[](8);
commandInput[0] = "cast";
commandInput[1] = "wallet";
commandInput[2] = "sign";
commandInput[3] = "--from";
commandInput[4] = vm.toString(by);
commandInput[5] = "--private-key";
commandInput[6] = LibString.toHexString(_loadENVPrivateKey(envLabel));
commandInput[6] = LibString.toHexString(privateKey);
commandInput[7] = message;

sig = vm.ffi(commandInput);
Expand Down Expand Up @@ -86,14 +90,18 @@ abstract contract WalletConfig is CommonBase, IWalletConfig {
public
returns (bytes memory sig)
{
sig = signTypedDataV4(by, filePath, _loadENVPrivateKey(envLabel));
}

function signTypedDataV4(address by, string memory filePath, uint256 privateKey) public returns (bytes memory sig) {
string[] memory commandInput = new string[](10);
commandInput[0] = "cast";
commandInput[1] = "wallet";
commandInput[2] = "sign";
commandInput[3] = "--from";
commandInput[4] = vm.toString(by);
commandInput[5] = "--private-key";
commandInput[6] = LibString.toHexString(_loadENVPrivateKey(envLabel));
commandInput[6] = LibString.toHexString(privateKey);
commandInput[7] = "--data";
commandInput[8] = "--from-file";
commandInput[9] = filePath;
Expand Down
12 changes: 8 additions & 4 deletions script/extensions/ScriptExtended.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ abstract contract ScriptExtended is Script, StdAssertions, IScriptExtended {
_swichBack(currentNetwork);
}

constructor() {
setUp();
}

function setUp() public virtual {
vm.label(address(CONFIG), "GeneralConfig");
deploySharedAddress(address(CONFIG), _configByteCode());
deploySharedAddress(address(CONFIG), _configByteCode(), "GeneralConfig");
}

function _configByteCode() internal virtual returns (bytes memory);
Expand Down Expand Up @@ -65,17 +68,18 @@ abstract contract ScriptExtended is Script, StdAssertions, IScriptExtended {
revert("ScriptExtended: Got failed assertion");
}

function deploySharedAddress(address where, bytes memory bytecode) public {
function deploySharedAddress(address where, bytes memory bytecode, string memory label) public {
if (where.code.length == 0) {
vm.makePersistent(where);
vm.allowCheatcodes(where);
deployCodeTo(bytecode, where);
if (bytes(label).length != 0) vm.label(where, label);
}
}

function deploySharedMigration(TContract contractType, bytes memory bytecode) public returns (address where) {
where = address(ripemd160(abi.encode(contractType)));
deploySharedAddress(where, bytecode);
deploySharedAddress(where, bytecode, string.concat(contractType.contractName(), "Deploy"));
}

function deployCodeTo(bytes memory creationCode, address where) internal {
Expand Down
4 changes: 4 additions & 0 deletions script/interfaces/configs/IWalletConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ interface IWalletConfig {

function ethSignMessage(string memory message) external returns (bytes memory sig);

function ethSignMessage(address by, string memory message, uint256 privateKey) external returns (bytes memory sig);

function envEthSignMessage(address by, string memory message, string memory envLabel)
external
returns (bytes memory sig);
Expand All @@ -31,6 +33,8 @@ interface IWalletConfig {

function trezorSignTypedDataV4(address by, string memory filePath) external returns (bytes memory sig);

function signTypedDataV4(address by, string memory filePath, uint256 privateKey) external returns (bytes memory sig);

function signTypedDataV4(address by, string memory filePath, WalletOption walletOption)
external
returns (bytes memory sig);
Expand Down
4 changes: 3 additions & 1 deletion script/utils/DefaultContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { LibString } from "../../lib/solady/src/utils/LibString.sol";
import { TContract } from "../types/Types.sol";

enum DefaultContract {
ProxyAdmin
ProxyAdmin,
Multicall3
}

using { key, name } for DefaultContract global;
Expand All @@ -16,5 +17,6 @@ function key(DefaultContract defaultContract) pure returns (TContract) {

function name(DefaultContract defaultContract) pure returns (string memory) {
if (defaultContract == DefaultContract.ProxyAdmin) return "ProxyAdmin";
if (defaultContract == DefaultContract.Multicall3) return "Multicall3";
revert("DefaultContract: Unknown contract");
}

0 comments on commit 3f5c3b2

Please sign in to comment.