Skip to content

Commit

Permalink
Merge pull request #97 from ethstorage/init-test
Browse files Browse the repository at this point in the history
Fix ./test/vendor/Initializable.t.sol test
  • Loading branch information
qzhodl authored Dec 5, 2024
2 parents 3834224 + 08e27d1 commit 1768ebc
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/deploy-config/hardhat.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"daResolveWindow": 100,
"daBondSize": 1000,
"daResolverRefundPercentage": 50
}
}
2 changes: 2 additions & 0 deletions packages/contracts-bedrock/scripts/Artifacts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ abstract contract Artifacts {
bytes32 digest = keccak256(bytes(_name));
if (digest == keccak256(bytes("L2CrossDomainMessenger"))) {
return payable(Predeploys.L2_CROSS_DOMAIN_MESSENGER);
} else if (digest == keccak256(bytes("SoulGasToken"))) {
return payable(Predeploys.SOUL_GAS_TOKEN);
} else if (digest == keccak256(bytes("L2ToL1MessagePasser"))) {
return payable(Predeploys.L2_TO_L1_MESSAGE_PASSER);
} else if (digest == keccak256(bytes("L2StandardBridge"))) {
Expand Down
10 changes: 10 additions & 0 deletions packages/contracts-bedrock/scripts/deploy/DeployConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ contract DeployConfig is Script {
useInterop = _useInterop;
}

/// @notice Allow the `useSoulGasToken` config to be overridden in testing environments
function setUseSoulGasToken(bool _useSoulGasToken) public {
useSoulGasToken = _useSoulGasToken;
}

/// @notice Allow the `isSoulBackedByNative` config to be overridden in testing environments
function setIsSoulBackedByNative(bool _isSoulBackedByNative) public {
isSoulBackedByNative = _isSoulBackedByNative;
}

/// @notice Allow the `fundDevAccounts` config to be overridden.
function setFundDevAccounts(bool _fundDevAccounts) public {
fundDevAccounts = _fundDevAccounts;
Expand Down
1 change: 1 addition & 0 deletions packages/contracts-bedrock/src/L2/SoulGasToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ contract SoulGasToken is ERC20Upgradeable, OwnableUpgradeable {

constructor(bool isBackedByNative_) {
IS_BACKED_BY_NATIVE = isBackedByNative_;
initialize("", "", msg.sender);
}

/// @notice Initializer.
Expand Down
10 changes: 10 additions & 0 deletions packages/contracts-bedrock/src/L2/interfaces/ISoulGasToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title ISoulGasToken
/// @notice The interface for the SoulGasToken.
interface ISoulGasToken {
function initialize(string memory _name, string memory _symbol, address _owner) external;

function __constructor__() external;
}
19 changes: 19 additions & 0 deletions packages/contracts-bedrock/test/setup/CommonTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ contract CommonTest is Test, Setup, Events {
bool useLegacyContracts;
address customGasToken;
bool useInteropOverride;
bool useSoulGasToken;
bool isSoulBackedByNative;

ERC20 L1Token;
ERC20 BadL1Token;
Expand Down Expand Up @@ -55,6 +57,12 @@ contract CommonTest is Test, Setup, Events {
if (useInteropOverride) {
deploy.cfg().setUseInterop(true);
}
if (useSoulGasToken) {
deploy.cfg().setUseSoulGasToken(true);
if (isSoulBackedByNative) {
deploy.cfg().setIsSoulBackedByNative(true);
}
}

vm.etch(address(ffi), vm.getDeployedCode("FFIInterface.sol:FFIInterface"));
vm.label(address(ffi), "FFIInterface");
Expand Down Expand Up @@ -210,4 +218,15 @@ contract CommonTest is Test, Setup, Events {

useInteropOverride = true;
}

function enableSoulGasToken() public {
// Check if the system has already been deployed, based off of the heuristic that alice and bob have not been
// set by the `setUp` function yet.
if (!(alice == address(0) && bob == address(0))) {
revert("CommonTest: Cannot enable interop after deployment. Consider overriding `setUp`.");
}

useSoulGasToken = true;
isSoulBackedByNative = true;
}
}
3 changes: 3 additions & 0 deletions packages/contracts-bedrock/test/setup/Setup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { IDisputeGameFactory } from "src/dispute/interfaces/IDisputeGameFactory.
import { IDelayedWETH } from "src/dispute/interfaces/IDelayedWETH.sol";
import { IAnchorStateRegistry } from "src/dispute/interfaces/IAnchorStateRegistry.sol";
import { IL2CrossDomainMessenger } from "src/L2/interfaces/IL2CrossDomainMessenger.sol";
import { ISoulGasToken } from "src/L2/interfaces/ISoulGasToken.sol";
import { IL2StandardBridgeInterop } from "src/L2/interfaces/IL2StandardBridgeInterop.sol";
import { IL2ToL1MessagePasser } from "src/L2/interfaces/IL2ToL1MessagePasser.sol";
import { IL2ERC721Bridge } from "src/L2/interfaces/IL2ERC721Bridge.sol";
Expand Down Expand Up @@ -111,6 +112,7 @@ contract Setup {
ISuperchainTokenBridge superchainTokenBridge = ISuperchainTokenBridge(Predeploys.SUPERCHAIN_TOKEN_BRIDGE);
IOptimismSuperchainERC20Factory l2OptimismSuperchainERC20Factory =
IOptimismSuperchainERC20Factory(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_FACTORY);
ISoulGasToken soulGasToken = ISoulGasToken(Predeploys.SOUL_GAS_TOKEN);

/// @dev Deploys the Deploy contract without including its bytecode in the bytecode
/// of this contract by fetching the bytecode dynamically using `vm.getCode()`.
Expand Down Expand Up @@ -237,6 +239,7 @@ contract Setup {
labelPredeploy(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_FACTORY);
labelPredeploy(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_BEACON);
labelPredeploy(Predeploys.SUPERCHAIN_TOKEN_BRIDGE);
labelPredeploy(Predeploys.SOUL_GAS_TOKEN);

// L2 Preinstalls
labelPreinstall(Preinstalls.MultiCall3);
Expand Down
9 changes: 9 additions & 0 deletions packages/contracts-bedrock/test/vendor/Initializable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ contract Initializer_Test is CommonTest {
function setUp() public override {
super.enableAltDA();
super.enableLegacyContracts();
super.enableSoulGasToken();
super.setUp();

// Initialize the `contracts` array with the addresses of the contracts to test, the
Expand Down Expand Up @@ -266,6 +267,14 @@ contract Initializer_Test is CommonTest {
initCalldata: abi.encodeCall(l2CrossDomainMessenger.initialize, (l1CrossDomainMessenger))
})
);
// SoulGasToken
contracts.push(
InitializeableContract({
name: "SoulGasToken",
target: address(soulGasToken),
initCalldata: abi.encodeCall(soulGasToken.initialize, ("SoulGasToken", "SGT", address(0)))
})
);
// L1StandardBridgeImpl
contracts.push(
InitializeableContract({
Expand Down

0 comments on commit 1768ebc

Please sign in to comment.