tests: port existing JS tests to foundry tests (#9)

This commit is contained in:
r4bbit
2023-09-12 17:08:59 +02:00
committed by GitHub
parent 2a8505f3b2
commit 5386b09f55
8 changed files with 489 additions and 265 deletions

View File

@@ -4,8 +4,36 @@ pragma solidity >=0.8.19 <=0.9.0;
import { BaseScript } from "./Base.s.sol";
import { DeploymentConfig } from "./DeploymentConfig.s.sol";
import { MiniMeToken } from "../contracts/MiniMeToken.sol";
import { MiniMeTokenFactory } from "../contracts/MiniMeToken.sol";
contract Deploy is BaseScript {
function run() public returns (DeploymentConfig deploymentConfig) {
function run()
public
returns (DeploymentConfig deploymentConfig, MiniMeTokenFactory minimeFactory, MiniMeToken minimeToken)
{
deploymentConfig = new DeploymentConfig(broadcaster);
(
,
address parentToken,
uint256 parentSnapShotBlock,
string memory name,
uint8 decimals,
string memory symbol,
bool transferEnabled
) = deploymentConfig.activeNetworkConfig();
vm.startBroadcast(broadcaster);
minimeFactory = new MiniMeTokenFactory();
minimeToken = new MiniMeToken(
minimeFactory,
MiniMeToken(payable(parentToken)),
parentSnapShotBlock,
name,
decimals,
symbol,
transferEnabled
);
vm.stopBroadcast();
}
}

View File

@@ -10,6 +10,12 @@ contract DeploymentConfig is Script {
struct NetworkConfig {
address deployer;
address parentToken;
uint256 parentSnapShotBlock;
string name;
uint8 decimals;
string symbol;
bool transferEnabled;
}
NetworkConfig public activeNetworkConfig;
@@ -17,17 +23,25 @@ contract DeploymentConfig is Script {
address private deployer;
constructor(address _broadcaster) {
deployer = _broadcaster;
if (block.chainid == 31_337) {
activeNetworkConfig = getOrCreateAnvilEthConfig();
} else {
revert DeploymentConfig_NoConfigForChain(block.chainid);
}
if (_broadcaster == address(0)) revert DeploymentConfig_InvalidDeployerAddress();
deployer = _broadcaster;
}
function getOrCreateAnvilEthConfig() public view returns (NetworkConfig memory) {
return NetworkConfig({ deployer: deployer });
return NetworkConfig({
deployer: deployer,
parentToken: address(0),
parentSnapShotBlock: 0,
name: "MiniMe Test Token",
decimals: 18,
symbol: "MMT",
transferEnabled: true
});
}
// This function is a hack to have it excluded by `forge coverage` until