diff --git a/contracts/lib/forge-std b/contracts/lib/forge-std index 155d547c4..1d0766bc5 160000 --- a/contracts/lib/forge-std +++ b/contracts/lib/forge-std @@ -1 +1 @@ -Subproject commit 155d547c449afa8715f538d69454b83944117811 +Subproject commit 1d0766bc5d814f117c7b1e643828f7d85024fb51 diff --git a/contracts/lib/openzeppelin-contracts b/contracts/lib/openzeppelin-contracts index 01ef44898..8b4b7b8d0 160000 --- a/contracts/lib/openzeppelin-contracts +++ b/contracts/lib/openzeppelin-contracts @@ -1 +1 @@ -Subproject commit 01ef448981be9d20ca85f2faf6ebdf591ce409f3 +Subproject commit 8b4b7b8d041c62a84e2c23d7f6e1f0d9e0fc1f20 diff --git a/contracts/test/IntegrationTestBase.sol b/contracts/test/IntegrationTestBase.sol index 5a1a3c975..b15e3216d 100644 --- a/contracts/test/IntegrationTestBase.sol +++ b/contracts/test/IntegrationTestBase.sol @@ -40,6 +40,24 @@ import {DiamondCutFacet} from "../src/diamond/DiamondCutFacet.sol"; import {SupplySourceHelper} from "../src/lib/SupplySourceHelper.sol"; import {TestUtils} from "./helpers/TestUtils.sol"; import {SelectorLibrary} from "./helpers/SelectorLibrary.sol"; +import {GatewayFacetsHelper} from "./helpers/GatewayFacetsHelper.sol"; +import {SubnetActorFacetsHelper} from "./helpers/SubnetActorFacetsHelper.sol"; +import {DiamondFacetsHelper} from "./helpers/DiamondFacetsHelper.sol"; + +struct TestSubnetDefinition { + GatewayDiamond gateway; + address gatewayAddr; + SubnetActorDiamond subnetActor; + address subnetActorAddr; + SubnetID id; + address[] path; +} + +struct RootSubnetDefinition { + GatewayDiamond gateway; + address gatewayAddr; + SubnetID id; +} contract TestParams { uint64 constant MAX_NONCE = type(uint64).max; @@ -98,14 +116,6 @@ contract TestGatewayActor is Test, TestParams { bytes4[] gwLoupeSelectors; GatewayDiamond gatewayDiamond; - GatewayManagerFacet gwManager; - GatewayGetterFacet gwGetter; - CheckpointingFacet gwCheckpointingFacet; - XnetMessagingFacet gwXnetMessagingFacet; - TopDownFinalityFacet gwTopDownFinalityFacet; - GatewayMessengerFacet gwMessenger; - DiamondCutFacet gwCutter; - DiamondLoupeFacet gwLouper; constructor() { gwCheckpointingFacetSelectors = SelectorLibrary.resolveSelectors("CheckpointingFacet"); @@ -131,15 +141,7 @@ contract TestSubnetActor is Test, TestParams { bytes4[] saLouperSelectors; SubnetActorDiamond saDiamond; - SubnetActorManagerFacet saManager; SubnetActorMock saMock; - SubnetActorGetterFacet saGetter; - SubnetActorRewardFacet saRewarder; - SubnetActorPauseFacet saPauser; - SubnetActorCheckpointingFacet saCheckpointer; - - DiamondCutFacet saCutter; - DiamondLoupeFacet saLouper; constructor() { saGetterSelectors = SelectorLibrary.resolveSelectors("SubnetActorGetterFacet"); @@ -152,32 +154,18 @@ contract TestSubnetActor is Test, TestParams { saLouperSelectors = SelectorLibrary.resolveSelectors("DiamondLoupeFacet"); } - function subnetActorWithParams( + function defaultSubnetActorParamsWith( address gw, SubnetID memory parentID ) internal pure returns (SubnetActorDiamond.ConstructorParams memory) { SupplySource memory native = SupplySourceHelper.native(); - SubnetActorDiamond.ConstructorParams memory params = SubnetActorDiamond.ConstructorParams({ - parentId: parentID, - ipcGatewayAddr: gw, - consensus: ConsensusType.Fendermint, - minActivationCollateral: DEFAULT_COLLATERAL_AMOUNT, - minValidators: DEFAULT_MIN_VALIDATORS, - bottomUpCheckPeriod: DEFAULT_CHECKPOINT_PERIOD, - majorityPercentage: DEFAULT_MAJORITY_PERCENTAGE, - activeValidatorsLimit: DEFAULT_ACTIVE_VALIDATORS_LIMIT, - powerScale: DEFAULT_POWER_SCALE, - permissionMode: PermissionMode.Collateral, - supplySource: native - }); - - return params; + return defaultSubnetActorParamsWith(gw, parentID, native); } - function subnetActorWithParams( + function defaultSubnetActorParamsWith( address gw, SubnetID memory parentID, - address tokenAddress + SupplySource memory source ) internal pure returns (SubnetActorDiamond.ConstructorParams memory) { SubnetActorDiamond.ConstructorParams memory params = SubnetActorDiamond.ConstructorParams({ parentId: parentID, @@ -190,18 +178,29 @@ contract TestSubnetActor is Test, TestParams { activeValidatorsLimit: DEFAULT_ACTIVE_VALIDATORS_LIMIT, powerScale: DEFAULT_POWER_SCALE, permissionMode: PermissionMode.Collateral, - supplySource: SupplySource({kind: SupplyKind.ERC20, tokenAddress: tokenAddress}) + supplySource: source }); - return params; } - function defaultSubnetActorParamsWithGateway( + function defaultSubnetActorParamsWith( address gw ) internal pure virtual returns (SubnetActorDiamond.ConstructorParams memory) { - SupplySource memory native = SupplySourceHelper.native(); + return + defaultSubnetActorParamsWith( + gw, + SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}), + SupplySourceHelper.native() + ); + } + + function defaultSubnetActorParamsWith( + address gw, + SubnetID memory parentID, + address tokenAddress + ) internal pure returns (SubnetActorDiamond.ConstructorParams memory) { SubnetActorDiamond.ConstructorParams memory params = SubnetActorDiamond.ConstructorParams({ - parentId: SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}), + parentId: parentID, ipcGatewayAddr: gw, consensus: ConsensusType.Fendermint, minActivationCollateral: DEFAULT_COLLATERAL_AMOUNT, @@ -211,9 +210,8 @@ contract TestSubnetActor is Test, TestParams { activeValidatorsLimit: DEFAULT_ACTIVE_VALIDATORS_LIMIT, powerScale: DEFAULT_POWER_SCALE, permissionMode: PermissionMode.Collateral, - supplySource: native + supplySource: SupplySource({kind: SupplyKind.ERC20, tokenAddress: tokenAddress}) }); - return params; } } @@ -223,6 +221,13 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, using SupplySourceHelper for SupplySource; using CrossMsgHelper for IpcEnvelope; using FvmAddressHelper for FvmAddress; + using GatewayFacetsHelper for address; + using GatewayFacetsHelper for GatewayDiamond; + using SubnetActorFacetsHelper for address; + using SubnetActorFacetsHelper for SubnetActorDiamond; + using DiamondFacetsHelper for address; + using DiamondFacetsHelper for GatewayDiamond; + using DiamondFacetsHelper for SubnetActorDiamond; event SubnetRegistryCreated(address indexed subnetRegistryAddress); @@ -236,28 +241,12 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, GatewayDiamond.ConstructorParams memory gwConstructorParams = defaultGatewayParams(); gatewayDiamond = createGatewayDiamond(gwConstructorParams); - gwGetter = GatewayGetterFacet(address(gatewayDiamond)); - gwManager = GatewayManagerFacet(address(gatewayDiamond)); - gwCheckpointingFacet = CheckpointingFacet(address(gatewayDiamond)); - gwXnetMessagingFacet = XnetMessagingFacet(address(gatewayDiamond)); - gwTopDownFinalityFacet = TopDownFinalityFacet(address(gatewayDiamond)); - gwMessenger = GatewayMessengerFacet(address(gatewayDiamond)); - gwLouper = DiamondLoupeFacet(address(gatewayDiamond)); - gwCutter = DiamondCutFacet(address(gatewayDiamond)); - // create a subnet actor in the root network. - SubnetActorDiamond.ConstructorParams memory saConstructorParams = defaultSubnetActorParamsWithGateway( + SubnetActorDiamond.ConstructorParams memory saConstructorParams = defaultSubnetActorParamsWith( address(gatewayDiamond) ); saDiamond = createSubnetActor(saConstructorParams); - saManager = SubnetActorManagerFacet(address(saDiamond)); - saGetter = SubnetActorGetterFacet(address(saDiamond)); - saPauser = SubnetActorPauseFacet(address(saDiamond)); - saRewarder = SubnetActorRewardFacet(address(saDiamond)); - saCheckpointer = SubnetActorCheckpointingFacet(address(saDiamond)); - saLouper = DiamondLoupeFacet(address(saDiamond)); - saCutter = DiamondCutFacet(address(saDiamond)); addValidator(TOPDOWN_VALIDATOR_1, 100); } @@ -270,7 +259,6 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, genesisValidators: new Validator[](0), activeValidatorsLimit: DEFAULT_ACTIVE_VALIDATORS_LIMIT }); - return params; } @@ -282,7 +270,6 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, genesisValidators: new Validator[](0), activeValidatorsLimit: DEFAULT_ACTIVE_VALIDATORS_LIMIT }); - return params; } @@ -290,7 +277,6 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, CheckpointingFacet checkpointingFacet = new CheckpointingFacet(); XnetMessagingFacet xnetMessagingFacet = new XnetMessagingFacet(); TopDownFinalityFacet topDownFinalityFacet = new TopDownFinalityFacet(); - GatewayManagerFacet manager = new GatewayManagerFacet(); GatewayGetterFacet getter = new GatewayGetterFacet(); GatewayMessengerFacet messenger = new GatewayMessengerFacet(); @@ -428,7 +414,6 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, SubnetActorPauseFacet pauser = new SubnetActorPauseFacet(); SubnetActorRewardFacet rewarder = new SubnetActorRewardFacet(); SubnetActorCheckpointingFacet checkpointer = new SubnetActorCheckpointingFacet(); - DiamondLoupeFacet louper = new DiamondLoupeFacet(); DiamondCutFacet cutter = new DiamondCutFacet(); @@ -527,96 +512,20 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, ) public { SubnetID memory _parentId = SubnetID(ROOTNET_CHAINID, new address[](0)); - saManager = new SubnetActorManagerFacet(); - saGetter = new SubnetActorGetterFacet(); - saPauser = new SubnetActorPauseFacet(); - saCheckpointer = new SubnetActorCheckpointingFacet(); - saRewarder = new SubnetActorRewardFacet(); - saCutter = new DiamondCutFacet(); - saLouper = new DiamondLoupeFacet(); - - IDiamond.FacetCut[] memory diamondCut = new IDiamond.FacetCut[](7); - - diamondCut[0] = ( - IDiamond.FacetCut({ - facetAddress: address(saManager), - action: IDiamond.FacetCutAction.Add, - functionSelectors: saManagerSelectors - }) - ); - - diamondCut[1] = ( - IDiamond.FacetCut({ - facetAddress: address(saGetter), - action: IDiamond.FacetCutAction.Add, - functionSelectors: saGetterSelectors - }) - ); - - diamondCut[2] = ( - IDiamond.FacetCut({ - facetAddress: address(saPauser), - action: IDiamond.FacetCutAction.Add, - functionSelectors: saPauserSelectors - }) - ); - - diamondCut[3] = ( - IDiamond.FacetCut({ - facetAddress: address(saRewarder), - action: IDiamond.FacetCutAction.Add, - functionSelectors: saRewarderSelectors - }) - ); - - diamondCut[4] = ( - IDiamond.FacetCut({ - facetAddress: address(saCheckpointer), - action: IDiamond.FacetCutAction.Add, - functionSelectors: saCheckpointerSelectors - }) - ); - - diamondCut[5] = ( - IDiamond.FacetCut({ - facetAddress: address(saCutter), - action: IDiamond.FacetCutAction.Add, - functionSelectors: saCutterSelectors - }) - ); - - diamondCut[6] = ( - IDiamond.FacetCut({ - facetAddress: address(saLouper), - action: IDiamond.FacetCutAction.Add, - functionSelectors: saLouperSelectors - }) - ); - - saDiamond = new SubnetActorDiamond( - diamondCut, - SubnetActorDiamond.ConstructorParams({ - parentId: _parentId, - ipcGatewayAddr: _ipcGatewayAddr, - consensus: _consensus, - minActivationCollateral: _minActivationCollateral, - minValidators: _minValidators, - bottomUpCheckPeriod: _checkPeriod, - majorityPercentage: _majorityPercentage, - activeValidatorsLimit: _activeValidatorsLimit, - powerScale: 12, - permissionMode: _permissionMode, - supplySource: SupplySourceHelper.native() - }) - ); - - saManager = SubnetActorManagerFacet(address(saDiamond)); - saPauser = SubnetActorPauseFacet(address(saDiamond)); - saRewarder = SubnetActorRewardFacet(address(saDiamond)); - saCheckpointer = SubnetActorCheckpointingFacet(address(saDiamond)); - saGetter = SubnetActorGetterFacet(address(saDiamond)); - saCutter = DiamondCutFacet(address(saDiamond)); - saLouper = DiamondLoupeFacet(address(saDiamond)); + SubnetActorDiamond.ConstructorParams memory params = SubnetActorDiamond.ConstructorParams({ + parentId: _parentId, + ipcGatewayAddr: _ipcGatewayAddr, + consensus: _consensus, + minActivationCollateral: _minActivationCollateral, + minValidators: _minValidators, + bottomUpCheckPeriod: _checkPeriod, + majorityPercentage: _majorityPercentage, + activeValidatorsLimit: _activeValidatorsLimit, + powerScale: 12, + permissionMode: _permissionMode, + supplySource: SupplySourceHelper.native() + }); + saDiamond = createSubnetActor(params); } function createMockedSubnetActorWithGateway(address gw) public returns (SubnetActorDiamond) { @@ -641,7 +550,7 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, }) ); - SubnetActorDiamond.ConstructorParams memory params = defaultSubnetActorParamsWithGateway(gw); + SubnetActorDiamond.ConstructorParams memory params = defaultSubnetActorParamsWith(gw); SubnetActorDiamond d = new SubnetActorDiamond(diamondCut, params); @@ -724,7 +633,7 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, ParentFinality memory finality = ParentFinality({height: block.number, blockHash: bytes32(0)}); vm.prank(FilAddress.SYSTEM_ACTOR); - gwTopDownFinalityFacet.commitParentFinality(finality); + gatewayDiamond.topDownFinalizer().commitParentFinality(finality); } function setupWhiteListMethod(address caller, address src) public returns (bytes32) { @@ -733,11 +642,11 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, IpcEnvelope memory crossMsg = IpcEnvelope({ kind: IpcMsgKind.Transfer, from: IPCAddress({ - subnetId: gwGetter.getNetworkName().createSubnetId(caller), + subnetId: gatewayDiamond.getter().getNetworkName().createSubnetId(caller), rawAddress: FvmAddressHelper.from(caller) }), to: IPCAddress({ - subnetId: gwGetter.getNetworkName().createSubnetId(src), + subnetId: gatewayDiamond.getter().getNetworkName().createSubnetId(src), rawAddress: FvmAddressHelper.from(src) }), value: DEFAULT_CROSS_MSG_FEE + 1, @@ -752,7 +661,7 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, // addValidator(caller, 1000); vm.prank(FilAddress.SYSTEM_ACTOR); - gwXnetMessagingFacet.applyCrossMessages(msgs); + gatewayDiamond.xnetMessenger().applyCrossMessages(msgs); return crossMsg.toHash(); } @@ -769,10 +678,10 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, vm.deal(validator, 1); ParentFinality memory finality = ParentFinality({height: block.number, blockHash: bytes32(0)}); - // uint64 n = gwGetter.getLastConfigurationNumber() + 1; + // uint64 n = gatewayDiamond.getter().getLastConfigurationNumber() + 1; vm.startPrank(FilAddress.SYSTEM_ACTOR); - gwTopDownFinalityFacet.commitParentFinality(finality); + gatewayDiamond.topDownFinalizer().commitParentFinality(finality); vm.stopPrank(); } @@ -786,21 +695,24 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, function fund(address funderAddress, uint256 fundAmount, SupplyKind mode) public { // funding subnets is free, we do not need cross msg fee - (SubnetID memory subnetId, , uint256 nonceBefore, , uint256 circSupplyBefore) = getSubnet(address(saManager)); + (SubnetID memory subnetId, , uint256 nonceBefore, , uint256 circSupplyBefore) = getSubnet(address(saDiamond)); - uint256 expectedTopDownMsgsLength = gwGetter.getSubnetTopDownMsgsLength(subnetId) + 1; + uint256 expectedTopDownMsgsLength = gatewayDiamond.getter().getSubnetTopDownMsgsLength(subnetId) + 1; uint256 expectedNonce = nonceBefore + 1; uint256 expectedCircSupply = circSupplyBefore + fundAmount; if (mode == SupplyKind.Native) { - gwManager.fund{value: fundAmount}(subnetId, FvmAddressHelper.from(funderAddress)); + gatewayDiamond.manager().fund{value: fundAmount}(subnetId, FvmAddressHelper.from(funderAddress)); } else if (mode == SupplyKind.ERC20) { - gwManager.fundWithToken(subnetId, FvmAddressHelper.from(funderAddress), fundAmount); + gatewayDiamond.manager().fundWithToken(subnetId, FvmAddressHelper.from(funderAddress), fundAmount); } - (, , uint256 nonce, , uint256 circSupply) = getSubnet(address(saManager)); + (, , uint256 nonce, , uint256 circSupply) = getSubnet(address(saDiamond)); - require(gwGetter.getSubnetTopDownMsgsLength(subnetId) == expectedTopDownMsgsLength, "unexpected lengths"); + require( + gatewayDiamond.getter().getSubnetTopDownMsgsLength(subnetId) == expectedTopDownMsgsLength, + "unexpected lengths" + ); require(nonce == expectedNonce, "unexpected nonce"); require(circSupply == expectedCircSupply, "unexpected circSupply"); @@ -809,7 +721,7 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, function join(address validatorAddress, bytes memory pubkey) public { vm.prank(validatorAddress); vm.deal(validatorAddress, DEFAULT_COLLATERAL_AMOUNT + 1); - saManager.join{value: DEFAULT_COLLATERAL_AMOUNT}(pubkey); + saDiamond.manager().join{value: DEFAULT_COLLATERAL_AMOUNT}(pubkey); } function confirmChange(address validator, uint256 privKey) internal { @@ -860,12 +772,12 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, bytes[] memory signatures = new bytes[](n); - (uint64 nextConfigNum, ) = saGetter.getConfigurationNumbers(); + (uint64 nextConfigNum, ) = saDiamond.getter().getConfigurationNumbers(); - uint256 h = saGetter.lastBottomUpCheckpointHeight() + saGetter.bottomUpCheckPeriod(); + uint256 h = saDiamond.getter().lastBottomUpCheckpointHeight() + saDiamond.getter().bottomUpCheckPeriod(); BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ - subnetID: saGetter.getParent().createSubnetId(address(saDiamond)), + subnetID: saDiamond.getter().getParent().createSubnetId(address(saDiamond)), blockHeight: h, blockHash: keccak256(abi.encode(h)), nextConfigurationNumber: nextConfigNum - 1, @@ -883,14 +795,14 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, for (uint256 i = 0; i < n; i++) { vm.prank(validators[i]); - saCheckpointer.submitCheckpoint(checkpoint, validators, signatures); + saDiamond.checkpointer().submitCheckpoint(checkpoint, validators, signatures); } } function release(uint256 releaseAmount) public { - uint256 expectedNonce = gwGetter.bottomUpNonce() + 1; - gwManager.release{value: releaseAmount}(FvmAddressHelper.from(msg.sender)); - require(gwGetter.bottomUpNonce() == expectedNonce, "gwGetter.bottomUpNonce() == expectedNonce"); + uint256 expectedNonce = gatewayDiamond.getter().bottomUpNonce() + 1; + gatewayDiamond.manager().release{value: releaseAmount}(FvmAddressHelper.from(msg.sender)); + require(gatewayDiamond.getter().bottomUpNonce() == expectedNonce, "unexpected nonce"); } function addStake(uint256 stakeAmount, address subnetAddress) public { @@ -898,7 +810,7 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, (, uint256 stakedBefore, , , ) = getSubnet(subnetAddress); - gwManager.addStake{value: stakeAmount}(); + gatewayDiamond.manager().addStake{value: stakeAmount}(); uint256 balanceAfter = subnetAddress.balance; (, uint256 stakedAfter, , , ) = getSubnet(subnetAddress); @@ -908,8 +820,8 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, } function registerSubnetGW(uint256 collateral, address subnetAddress, GatewayDiamond gw) public { - GatewayManagerFacet manager = GatewayManagerFacet(address(gw)); - GatewayGetterFacet getter = GatewayGetterFacet(address(gw)); + GatewayManagerFacet manager = gw.manager(); + GatewayGetterFacet getter = gw.getter(); manager.register{value: collateral}(0); @@ -937,7 +849,7 @@ contract IntegrationTestBase is Test, TestParams, TestRegistry, TestSubnetActor, address subnetAddress, GatewayDiamond gw ) public view returns (SubnetID memory, uint256, uint256, uint256, uint256) { - GatewayGetterFacet getter = GatewayGetterFacet(address(gw)); + GatewayGetterFacet getter = gw.getter(); SubnetID memory subnetId = getter.getNetworkName().createSubnetId(subnetAddress); diff --git a/contracts/test/IntegrationTestPresets.sol b/contracts/test/IntegrationTestPresets.sol index 27c18d771..051f02918 100644 --- a/contracts/test/IntegrationTestPresets.sol +++ b/contracts/test/IntegrationTestPresets.sol @@ -9,19 +9,17 @@ import {GatewayGetterFacet} from "../src/gateway/GatewayGetterFacet.sol"; import {GatewayManagerFacet} from "../src/gateway/GatewayManagerFacet.sol"; import {GatewayMessengerFacet} from "../src/gateway/GatewayMessengerFacet.sol"; import {XnetMessagingFacet} from "../src/gateway/router/XnetMessagingFacet.sol"; +import {GatewayFacetsHelper} from "./helpers/GatewayFacetsHelper.sol"; +import {DiamondFacetsHelper} from "./helpers/DiamondFacetsHelper.sol"; import {IntegrationTestBase} from "./IntegrationTestBase.sol"; contract L1GatewayActorDiamond is IntegrationTestBase { + using GatewayFacetsHelper for GatewayDiamond; + using DiamondFacetsHelper for GatewayDiamond; + function setUp() public virtual override { GatewayDiamond.ConstructorParams memory gwConstructorParams = defaultGatewayParams(); gatewayDiamond = createGatewayDiamond(gwConstructorParams); - - gwGetter = GatewayGetterFacet(address(gatewayDiamond)); - gwManager = GatewayManagerFacet(address(gatewayDiamond)); - gwXnetMessagingFacet = XnetMessagingFacet(address(gatewayDiamond)); - gwMessenger = GatewayMessengerFacet(address(gatewayDiamond)); - gwLouper = DiamondLoupeFacet(address(gatewayDiamond)); - gwCutter = DiamondCutFacet(address(gatewayDiamond)); } function defaultGatewayParams() internal pure override returns (GatewayDiamond.ConstructorParams memory) { @@ -41,16 +39,12 @@ contract L1GatewayActorDiamond is IntegrationTestBase { } contract L2GatewayActorDiamond is IntegrationTestBase { + using GatewayFacetsHelper for GatewayDiamond; + using DiamondFacetsHelper for GatewayDiamond; + function setUp() public virtual override { GatewayDiamond.ConstructorParams memory gwConstructorParams = defaultGatewayParams(); gatewayDiamond = createGatewayDiamond(gwConstructorParams); - - gwGetter = GatewayGetterFacet(address(gatewayDiamond)); - gwManager = GatewayManagerFacet(address(gatewayDiamond)); - gwXnetMessagingFacet = XnetMessagingFacet(address(gatewayDiamond)); - gwMessenger = GatewayMessengerFacet(address(gatewayDiamond)); - gwLouper = DiamondLoupeFacet(address(gatewayDiamond)); - gwCutter = DiamondCutFacet(address(gatewayDiamond)); } function defaultGatewayParams() internal pure override returns (GatewayDiamond.ConstructorParams memory) { @@ -71,18 +65,14 @@ contract L2GatewayActorDiamond is IntegrationTestBase { } contract L3GatewayActorDiamond is IntegrationTestBase { + using GatewayFacetsHelper for GatewayDiamond; + using DiamondFacetsHelper for GatewayDiamond; + address constant CHILD_NETWORK_ADDRESS_3 = address(31); function setUp() public virtual override { GatewayDiamond.ConstructorParams memory gwConstructorParams = defaultGatewayParams(); gatewayDiamond = createGatewayDiamond(gwConstructorParams); - - gwGetter = GatewayGetterFacet(address(gatewayDiamond)); - gwManager = GatewayManagerFacet(address(gatewayDiamond)); - gwXnetMessagingFacet = XnetMessagingFacet(address(gatewayDiamond)); - gwMessenger = GatewayMessengerFacet(address(gatewayDiamond)); - gwLouper = DiamondLoupeFacet(address(gatewayDiamond)); - gwCutter = DiamondCutFacet(address(gatewayDiamond)); } function defaultGatewayParams() internal pure override returns (GatewayDiamond.ConstructorParams memory) { diff --git a/contracts/test/helpers/DiamondFacetsHelper.sol b/contracts/test/helpers/DiamondFacetsHelper.sol new file mode 100644 index 000000000..3c5ebf710 --- /dev/null +++ b/contracts/test/helpers/DiamondFacetsHelper.sol @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +pragma solidity ^0.8.23; + +import {GatewayDiamond} from "../../src/GatewayDiamond.sol"; +import {DiamondLoupeFacet} from "../../src/diamond/DiamondLoupeFacet.sol"; +import {DiamondCutFacet} from "../../src/diamond/DiamondCutFacet.sol"; +import {SubnetActorDiamond} from "../../src/SubnetActorDiamond.sol"; +import {SubnetRegistryDiamond} from "../../src/SubnetRegistryDiamond.sol"; + +library DiamondFacetsHelper { + function diamondLouper(address a) internal pure returns (DiamondLoupeFacet) { + DiamondLoupeFacet facet = DiamondLoupeFacet(a); + return facet; + } + + function diamondCutter(address a) internal pure returns (DiamondCutFacet) { + DiamondCutFacet facet = DiamondCutFacet(a); + return facet; + } + + // + + function diamondLouper(GatewayDiamond a) internal pure returns (DiamondLoupeFacet) { + DiamondLoupeFacet facet = DiamondLoupeFacet(address(a)); + return facet; + } + + function diamondCutter(GatewayDiamond a) internal pure returns (DiamondCutFacet) { + DiamondCutFacet facet = DiamondCutFacet(address(a)); + return facet; + } + + // + + function diamondLouper(SubnetActorDiamond a) internal pure returns (DiamondLoupeFacet) { + DiamondLoupeFacet facet = DiamondLoupeFacet(address(a)); + return facet; + } + + function diamondCutter(SubnetActorDiamond a) internal pure returns (DiamondCutFacet) { + DiamondCutFacet facet = DiamondCutFacet(address(a)); + return facet; + } + + // + + function diamondLouper(SubnetRegistryDiamond a) internal pure returns (DiamondLoupeFacet) { + DiamondLoupeFacet facet = DiamondLoupeFacet(address(a)); + return facet; + } + + function diamondCutter(SubnetRegistryDiamond a) internal pure returns (DiamondCutFacet) { + DiamondCutFacet facet = DiamondCutFacet(address(a)); + return facet; + } +} diff --git a/contracts/test/helpers/GatewayFacetsHelper.sol b/contracts/test/helpers/GatewayFacetsHelper.sol new file mode 100644 index 000000000..dfb4efd83 --- /dev/null +++ b/contracts/test/helpers/GatewayFacetsHelper.sol @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +pragma solidity ^0.8.23; + +import {GatewayGetterFacet} from "../../src/gateway/GatewayGetterFacet.sol"; +import {GatewayManagerFacet} from "../../src/gateway/GatewayManagerFacet.sol"; +import {GatewayMessengerFacet} from "../../src/gateway/GatewayMessengerFacet.sol"; +import {TopDownFinalityFacet} from "../../src/gateway/router/TopDownFinalityFacet.sol"; +import {CheckpointingFacet} from "../../src/gateway/router/CheckpointingFacet.sol"; +import {XnetMessagingFacet} from "../../src/gateway/router/XnetMessagingFacet.sol"; +import {GatewayDiamond} from "../../src/GatewayDiamond.sol"; +import {DiamondLoupeFacet} from "../../src/diamond/DiamondLoupeFacet.sol"; +import {DiamondCutFacet} from "../../src/diamond/DiamondCutFacet.sol"; + +library GatewayFacetsHelper { + function getter(address gw) internal pure returns (GatewayGetterFacet) { + GatewayGetterFacet facet = GatewayGetterFacet(gw); + return facet; + } + + function manager(address gw) internal pure returns (GatewayManagerFacet) { + GatewayManagerFacet facet = GatewayManagerFacet(gw); + return facet; + } + + function messenger(address gw) internal pure returns (GatewayMessengerFacet) { + GatewayMessengerFacet facet = GatewayMessengerFacet(gw); + return facet; + } + + function topDownFinalizer(address gw) internal pure returns (TopDownFinalityFacet) { + TopDownFinalityFacet facet = TopDownFinalityFacet(gw); + return facet; + } + + function checkpointer(address gw) internal pure returns (CheckpointingFacet) { + CheckpointingFacet facet = CheckpointingFacet(gw); + return facet; + } + + function xnetMessenger(address gw) internal pure returns (XnetMessagingFacet) { + XnetMessagingFacet facet = XnetMessagingFacet(gw); + return facet; + } + + // + + function getter(GatewayDiamond gw) internal pure returns (GatewayGetterFacet) { + GatewayGetterFacet facet = GatewayGetterFacet(address(gw)); + return facet; + } + + function manager(GatewayDiamond gw) internal pure returns (GatewayManagerFacet) { + GatewayManagerFacet facet = GatewayManagerFacet(address(gw)); + return facet; + } + + function messenger(GatewayDiamond gw) internal pure returns (GatewayMessengerFacet) { + GatewayMessengerFacet facet = GatewayMessengerFacet(address(gw)); + return facet; + } + + function topDownFinalizer(GatewayDiamond gw) internal pure returns (TopDownFinalityFacet) { + TopDownFinalityFacet facet = TopDownFinalityFacet(address(gw)); + return facet; + } + + function checkpointer(GatewayDiamond gw) internal pure returns (CheckpointingFacet) { + CheckpointingFacet facet = CheckpointingFacet(address(gw)); + return facet; + } + + function xnetMessenger(GatewayDiamond gw) internal pure returns (XnetMessagingFacet) { + XnetMessagingFacet facet = XnetMessagingFacet(address(gw)); + return facet; + } + + // + + function diamondLouper(GatewayDiamond a) internal pure returns (DiamondLoupeFacet) { + DiamondLoupeFacet facet = DiamondLoupeFacet(address(a)); + return facet; + } + + function diamondCutter(GatewayDiamond a) internal pure returns (DiamondCutFacet) { + DiamondCutFacet facet = DiamondCutFacet(address(a)); + return facet; + } +} diff --git a/contracts/test/helpers/RegistryFacetsHelper.sol b/contracts/test/helpers/RegistryFacetsHelper.sol new file mode 100644 index 000000000..b88a60f31 --- /dev/null +++ b/contracts/test/helpers/RegistryFacetsHelper.sol @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +pragma solidity ^0.8.23; + +import {SubnetRegistryDiamond} from "../../src/SubnetRegistryDiamond.sol"; +import {RegisterSubnetFacet} from "../../src/subnetregistry/RegisterSubnetFacet.sol"; +import {SubnetGetterFacet} from "../../src/subnetregistry/SubnetGetterFacet.sol"; + +library RegistryFacetsHelper { + function register(address a) internal pure returns (RegisterSubnetFacet) { + RegisterSubnetFacet facet = RegisterSubnetFacet(a); + return facet; + } + + function getter(address a) internal pure returns (SubnetGetterFacet) { + SubnetGetterFacet facet = SubnetGetterFacet(a); + return facet; + } + + // + + function register(SubnetRegistryDiamond a) internal pure returns (RegisterSubnetFacet) { + RegisterSubnetFacet facet = RegisterSubnetFacet(address(a)); + return facet; + } + + function getter(SubnetRegistryDiamond a) internal pure returns (SubnetGetterFacet) { + SubnetGetterFacet facet = SubnetGetterFacet(address(a)); + return facet; + } +} diff --git a/contracts/test/helpers/SubnetActorFacetsHelper.sol b/contracts/test/helpers/SubnetActorFacetsHelper.sol new file mode 100644 index 000000000..f465efd40 --- /dev/null +++ b/contracts/test/helpers/SubnetActorFacetsHelper.sol @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +pragma solidity ^0.8.23; + +import {SubnetActorManagerFacet} from "../../src/subnet/SubnetActorManagerFacet.sol"; +import {SubnetActorPauseFacet} from "../../src/subnet/SubnetActorPauseFacet.sol"; +import {SubnetActorCheckpointingFacet} from "../../src/subnet/SubnetActorCheckpointingFacet.sol"; +import {SubnetActorRewardFacet} from "../../src/subnet/SubnetActorRewardFacet.sol"; +import {SubnetActorGetterFacet} from "../../src/subnet/SubnetActorGetterFacet.sol"; +import {SubnetActorDiamond} from "../../src/SubnetActorDiamond.sol"; +import {DiamondLoupeFacet} from "../../src/diamond/DiamondLoupeFacet.sol"; +import {DiamondCutFacet} from "../../src/diamond/DiamondCutFacet.sol"; + +library SubnetActorFacetsHelper { + function manager(address sa) internal pure returns (SubnetActorManagerFacet) { + SubnetActorManagerFacet facet = SubnetActorManagerFacet(sa); + return facet; + } + + function pauser(address sa) internal pure returns (SubnetActorPauseFacet) { + SubnetActorPauseFacet facet = SubnetActorPauseFacet(sa); + return facet; + } + + function checkpointer(address sa) internal pure returns (SubnetActorCheckpointingFacet) { + SubnetActorCheckpointingFacet facet = SubnetActorCheckpointingFacet(sa); + return facet; + } + + function rewarder(address sa) internal pure returns (SubnetActorRewardFacet) { + SubnetActorRewardFacet facet = SubnetActorRewardFacet(sa); + return facet; + } + + function getter(address sa) internal pure returns (SubnetActorGetterFacet) { + SubnetActorGetterFacet facet = SubnetActorGetterFacet(sa); + return facet; + } + + function diamondLouper(SubnetActorDiamond a) internal pure returns (DiamondLoupeFacet) { + DiamondLoupeFacet facet = DiamondLoupeFacet(address(a)); + return facet; + } + + function diamondCutter(SubnetActorDiamond a) internal pure returns (DiamondCutFacet) { + DiamondCutFacet facet = DiamondCutFacet(address(a)); + return facet; + } + + // + + function manager(SubnetActorDiamond sa) internal pure returns (SubnetActorManagerFacet) { + SubnetActorManagerFacet facet = SubnetActorManagerFacet(address(sa)); + return facet; + } + + function pauser(SubnetActorDiamond sa) internal pure returns (SubnetActorPauseFacet) { + SubnetActorPauseFacet facet = SubnetActorPauseFacet(address(sa)); + return facet; + } + + function checkpointer(SubnetActorDiamond sa) internal pure returns (SubnetActorCheckpointingFacet) { + SubnetActorCheckpointingFacet facet = SubnetActorCheckpointingFacet(address(sa)); + return facet; + } + + function rewarder(SubnetActorDiamond sa) internal pure returns (SubnetActorRewardFacet) { + SubnetActorRewardFacet facet = SubnetActorRewardFacet(address(sa)); + return facet; + } + + function getter(SubnetActorDiamond sa) internal pure returns (SubnetActorGetterFacet) { + SubnetActorGetterFacet facet = SubnetActorGetterFacet(address(sa)); + return facet; + } +} diff --git a/contracts/test/integration/GatewayDiamond.t.sol b/contracts/test/integration/GatewayDiamond.t.sol index c81c2101d..e76188aac 100644 --- a/contracts/test/integration/GatewayDiamond.t.sol +++ b/contracts/test/integration/GatewayDiamond.t.sol @@ -34,27 +34,39 @@ import {MerkleTreeHelper} from "../helpers/MerkleTreeHelper.sol"; import {TestUtils, MockIpcContract} from "../helpers/TestUtils.sol"; import {IntegrationTestBase} from "../IntegrationTestBase.sol"; import {SelectorLibrary} from "../helpers/SelectorLibrary.sol"; +import {GatewayFacetsHelper} from "../helpers/GatewayFacetsHelper.sol"; + +import {SubnetActorDiamond} from "../../src/SubnetActorDiamond.sol"; +import {SubnetActorFacetsHelper} from "../helpers/SubnetActorFacetsHelper.sol"; contract GatewayActorDiamondTest is Test, IntegrationTestBase { using SubnetIDHelper for SubnetID; using CrossMsgHelper for IpcEnvelope; using FvmAddressHelper for FvmAddress; + using GatewayFacetsHelper for GatewayDiamond; + using SubnetActorFacetsHelper for SubnetActorDiamond; function setUp() public override { super.setUp(); } function testGatewayDiamond_Constructor() public view { - require(gwGetter.totalSubnets() == 0, "unexpected totalSubnets"); - require(gwGetter.bottomUpNonce() == 0, "unexpected bottomUpNonce"); - require(gwGetter.bottomUpCheckPeriod() == DEFAULT_CHECKPOINT_PERIOD, "unexpected bottomUpCheckPeriod"); + require(gatewayDiamond.getter().totalSubnets() == 0, "unexpected totalSubnets"); + require(gatewayDiamond.getter().bottomUpNonce() == 0, "unexpected bottomUpNonce"); + require( + gatewayDiamond.getter().bottomUpCheckPeriod() == DEFAULT_CHECKPOINT_PERIOD, + "unexpected bottomUpCheckPeriod" + ); require( - gwGetter.getNetworkName().equals(SubnetID({root: ROOTNET_CHAINID, route: new address[](0)})), + gatewayDiamond.getter().getNetworkName().equals(SubnetID({root: ROOTNET_CHAINID, route: new address[](0)})), "unexpected getNetworkName" ); - require(gwGetter.majorityPercentage() == DEFAULT_MAJORITY_PERCENTAGE, "unexpected majorityPercentage"); + require( + gatewayDiamond.getter().majorityPercentage() == DEFAULT_MAJORITY_PERCENTAGE, + "unexpected majorityPercentage" + ); - IpcEnvelope memory storableMsg = gwGetter.postbox(0); + IpcEnvelope memory storableMsg = gatewayDiamond.getter().postbox(0); IpcEnvelope memory msg1; require(msg1.toHash() == storableMsg.toHash(), "unexpected hash"); } @@ -62,15 +74,30 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { function testGatewayDiamond_NewGatewayWithDefaultParams() public view { GatewayDiamond.ConstructorParams memory params = defaultGatewayParams(); - require(gwGetter.bottomUpCheckPeriod() == params.bottomUpCheckPeriod, "unexpected bottom-up period"); - require(gwGetter.majorityPercentage() == params.majorityPercentage, "unexpected majority percentage"); + require( + gatewayDiamond.getter().bottomUpCheckPeriod() == params.bottomUpCheckPeriod, + "unexpected bottom-up period" + ); + require( + gatewayDiamond.getter().majorityPercentage() == params.majorityPercentage, + "unexpected majority percentage" + ); } function testGatewayDiamond_LoupeFunction() public view { - require(gwLouper.facets().length == 8, "unexpected length"); - require(gwLouper.supportsInterface(type(IERC165).interfaceId) == true, "IERC165 not supported"); - require(gwLouper.supportsInterface(type(IDiamondCut).interfaceId) == true, "IDiamondCut not supported"); - require(gwLouper.supportsInterface(type(IDiamondLoupe).interfaceId) == true, "IDiamondLoupe not supported"); + require(gatewayDiamond.diamondLouper().facets().length == 8, "unexpected length"); + require( + gatewayDiamond.diamondLouper().supportsInterface(type(IERC165).interfaceId) == true, + "IERC165 not supported" + ); + require( + gatewayDiamond.diamondLouper().supportsInterface(type(IDiamondCut).interfaceId) == true, + "IDiamondCut not supported" + ); + require( + gatewayDiamond.diamondLouper().supportsInterface(type(IDiamondLoupe).interfaceId) == true, + "IDiamondLoupe not supported" + ); } function testGatewayDiamond_DiamondCut() public { @@ -146,10 +173,6 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { function testGatewayDiamond_Deployment_Works_Root(uint64 checkpointPeriod) public { vm.assume(checkpointPeriod >= DEFAULT_CHECKPOINT_PERIOD); - GatewayDiamond dep; - GatewayManagerFacet depManager = new GatewayManagerFacet(); - GatewayGetterFacet depGetter = new GatewayGetterFacet(); - GatewayDiamond.ConstructorParams memory constructorParams = GatewayDiamond.ConstructorParams({ networkName: SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}), bottomUpCheckPeriod: checkpointPeriod, @@ -158,9 +181,8 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { activeValidatorsLimit: 100 }); - dep = createGatewayDiamond(constructorParams); - depGetter = GatewayGetterFacet(address(dep)); - depManager = GatewayManagerFacet(address(dep)); + GatewayDiamond dep = createGatewayDiamond(constructorParams); + GatewayGetterFacet depGetter = dep.getter(); SubnetID memory networkName = depGetter.getNetworkName(); @@ -179,9 +201,8 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { path[0] = address(0); path[1] = address(1); - GatewayDiamond dep; - GatewayManagerFacet depManager = new GatewayManagerFacet(); GatewayGetterFacet depGetter = new GatewayGetterFacet(); + GatewayManagerFacet depManager = new GatewayManagerFacet(); GatewayDiamond.ConstructorParams memory constructorParams = GatewayDiamond.ConstructorParams({ networkName: SubnetID({root: ROOTNET_CHAINID, route: path}), @@ -209,10 +230,9 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { }) ); - dep = new GatewayDiamond(diamondCut, constructorParams); - - depGetter = GatewayGetterFacet(address(dep)); - depManager = GatewayManagerFacet(address(dep)); + GatewayDiamond dep = new GatewayDiamond(diamondCut, constructorParams); + depGetter = dep.getter(); + depManager = dep.manager(); SubnetID memory networkName = depGetter.getNetworkName(); @@ -228,13 +248,13 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.deal(subnetAddress, subnetCollateral); registerSubnet(subnetCollateral, subnetAddress); - require(gwGetter.totalSubnets() == 1, "unexpected totalSubnets"); - Subnet[] memory subnets = gwGetter.listSubnets(); + require(gatewayDiamond.getter().totalSubnets() == 1, "unexpected totalSubnets"); + Subnet[] memory subnets = gatewayDiamond.getter().listSubnets(); require(subnets.length == 1, "unexpected subnets length"); - SubnetID memory subnetId = gwGetter.getNetworkName().createSubnetId(subnetAddress); + SubnetID memory subnetId = gatewayDiamond.getter().getNetworkName().createSubnetId(subnetAddress); - (bool ok, Subnet memory targetSubnet) = gwGetter.getSubnet(subnetId); + (bool ok, Subnet memory targetSubnet) = gatewayDiamond.getter().getSubnet(subnetId); require(ok, "subnet not found"); @@ -256,8 +276,8 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { registerSubnet(DEFAULT_COLLATERAL_AMOUNT, subnetAddress); } - require(gwGetter.totalSubnets() == numberOfSubnets, "unexpected total subnets"); - Subnet[] memory subnets = gwGetter.listSubnets(); + require(gatewayDiamond.getter().totalSubnets() == numberOfSubnets, "unexpected total subnets"); + Subnet[] memory subnets = gatewayDiamond.getter().listSubnets(); require(subnets.length == numberOfSubnets, "unexpected length"); } @@ -266,7 +286,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.expectRevert(AlreadyRegisteredSubnet.selector); - gwManager.register{value: DEFAULT_COLLATERAL_AMOUNT}(0); + gatewayDiamond.manager().register{value: DEFAULT_COLLATERAL_AMOUNT}(0); } function testGatewayDiamond_AddStake_Works_SingleStaking(uint256 stakeAmount, uint256 registerAmount) public { @@ -296,7 +316,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.deal(subnetAddress, registerAmount); registerSubnet(registerAmount, subnetAddress); - gwManager.releaseStake(registerAmount); + gatewayDiamond.manager().releaseStake(registerAmount); vm.deal(subnetAddress, stakeAmount); addStake(stakeAmount, subnetAddress); @@ -315,7 +335,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.deal(subnetAddress, registerAmount); registerSubnet(registerAmount, subnetAddress); - gwManager.releaseStake(registerAmount); + gatewayDiamond.manager().releaseStake(registerAmount); vm.deal(subnetAddress, stakeAmount); addStake(stakeAmount, subnetAddress); @@ -354,13 +374,13 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.expectRevert(NotEnoughFunds.selector); - gwManager.addStake{value: 0}(); + gatewayDiamond.manager().addStake{value: 0}(); } function testGatewayDiamond_AddStake_Fail_SubnetNotExists() public { vm.expectRevert(NotRegisteredSubnet.selector); - gwManager.addStake{value: 1}(); + gatewayDiamond.manager().addStake{value: 1}(); } function testGatewayDiamond_ReleaseStake_Works_FullAmount(uint256 stakeAmount) public { @@ -377,7 +397,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { registerSubnet(registerAmount, subnetAddress); addStake(stakeAmount, subnetAddress); - gwManager.releaseStake(fullAmount); + gatewayDiamond.manager().releaseStake(fullAmount); (, uint256 stake, , , ) = getSubnet(subnetAddress); @@ -391,7 +411,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.deal(subnetAddress, DEFAULT_COLLATERAL_AMOUNT); registerSubnet(DEFAULT_COLLATERAL_AMOUNT, subnetAddress); - gwManager.releaseStake(DEFAULT_COLLATERAL_AMOUNT / 2); + gatewayDiamond.manager().releaseStake(DEFAULT_COLLATERAL_AMOUNT / 2); (, uint256 stake, , , ) = getSubnet(subnetAddress); require(stake == DEFAULT_COLLATERAL_AMOUNT / 2, "unexpected stake"); @@ -411,7 +431,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { registerSubnet(registerAmount, subnetAddress); addStake(partialAmount, subnetAddress); - gwManager.releaseStake(partialAmount); + gatewayDiamond.manager().releaseStake(partialAmount); (, uint256 stake, , , ) = getSubnet(subnetAddress); @@ -424,7 +444,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.expectRevert(CannotReleaseZero.selector); - gwManager.releaseStake(0); + gatewayDiamond.manager().releaseStake(0); } function testGatewayDiamond_ReleaseStake_Fail_InsufficientSubnetBalance( @@ -442,13 +462,13 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.expectRevert(NotEnoughFundsToRelease.selector); - gwManager.releaseStake(releaseAmount); + gatewayDiamond.manager().releaseStake(releaseAmount); } function testGatewayDiamond_ReleaseStake_Fail_NotRegisteredSubnet() public { vm.expectRevert(NotRegisteredSubnet.selector); - gwManager.releaseStake(1); + gatewayDiamond.manager().releaseStake(1); } function testGatewayDiamond_ReleaseStake_Works_TransitionToInactive() public { @@ -459,7 +479,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { registerSubnet(DEFAULT_COLLATERAL_AMOUNT, subnetAddress); - gwManager.releaseStake(10); + gatewayDiamond.manager().releaseStake(10); (, uint256 stake, , , ) = getSubnet(subnetAddress); @@ -476,7 +496,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { require(subnetAddress.balance == 0, "unexpected balance"); - gwManager.kill(); + gatewayDiamond.manager().kill(); (SubnetID memory id, uint256 stake, uint256 nonce, , uint256 circSupply) = getSubnet(subnetAddress); @@ -484,16 +504,16 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { require(stake == 0, "unexpected stake"); require(nonce == 0, "unexpected nonce"); require(circSupply == 0, "unexpected circSupply"); - require(gwGetter.totalSubnets() == 0, "unexpected total subnets"); + require(gatewayDiamond.getter().totalSubnets() == 0, "unexpected total subnets"); require(subnetAddress.balance == DEFAULT_COLLATERAL_AMOUNT, "unexpected balance"); - require(gwGetter.listSubnets().length == 0, "unexpected number of subnets"); - require(gwGetter.getSubnetKeys().length == 0, "unexpected number of subnet keys"); + require(gatewayDiamond.getter().listSubnets().length == 0, "unexpected number of subnets"); + require(gatewayDiamond.getter().getSubnetKeys().length == 0, "unexpected number of subnet keys"); } function testGatewayDiamond_Kill_Fail_SubnetNotExists() public { vm.expectRevert(NotRegisteredSubnet.selector); - gwManager.kill(); + gatewayDiamond.manager().kill(); } function testGatewayDiamond_SendCrossMessage_Fails_NoFunds() public { @@ -502,10 +522,10 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.deal(caller, DEFAULT_COLLATERAL_AMOUNT + DEFAULT_CROSS_MSG_FEE + 2); registerSubnet(DEFAULT_COLLATERAL_AMOUNT, caller); - SubnetID memory destinationSubnet = gwGetter.getNetworkName().createSubnetId(caller); + SubnetID memory destinationSubnet = gatewayDiamond.getter().getNetworkName().createSubnetId(caller); vm.expectRevert(abi.encodeWithSelector(InvalidXnetMessage.selector, InvalidXnetMessageReason.Value)); - gwMessenger.sendContractXnetMessage{value: DEFAULT_CROSS_MSG_FEE}( + gatewayDiamond.messenger().sendContractXnetMessage{value: DEFAULT_CROSS_MSG_FEE}( TestUtils.newXnetCallMsg( IPCAddress({ subnetId: SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}), @@ -527,7 +547,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { registerSubnet(DEFAULT_COLLATERAL_AMOUNT, caller); vm.expectRevert(); - gwMessenger.sendContractXnetMessage{value: fee - 1}( + gatewayDiamond.messenger().sendContractXnetMessage{value: fee - 1}( TestUtils.newXnetCallMsg( IPCAddress({ subnetId: SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}), @@ -571,9 +591,9 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { fund(funderAddress, fundAmount); vm.stopPrank(); - vm.startPrank(address(saManager)); + vm.startPrank(address(saDiamond)); vm.expectRevert(NotEmptySubnetCircSupply.selector); - gwManager.kill(); + gatewayDiamond.manager().kill(); } function testGatewayDiamond_Fund_Revert_OnZeroValue() public { @@ -582,10 +602,10 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { address funderAddress = address(101); - (SubnetID memory subnetId, , , , ) = getSubnet(address(saManager)); + (SubnetID memory subnetId, , , , ) = getSubnet(address(saDiamond)); vm.expectRevert(abi.encodeWithSelector(InvalidXnetMessage.selector, InvalidXnetMessageReason.Value)); - gwManager.fund{value: 0}(subnetId, FvmAddressHelper.from(funderAddress)); + gatewayDiamond.manager().fund{value: 0}(subnetId, FvmAddressHelper.from(funderAddress)); } function testGatewayDiamond_Fund_Works_MultipleFundings(uint8 numberOfFunds) public { @@ -617,9 +637,9 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.deal(funderAddress, amount); - (SubnetID memory subnetId, , , , ) = getSubnet(address(saManager)); + (SubnetID memory subnetId, , , , ) = getSubnet(address(saDiamond)); vm.prank(funderAddress); - gwManager.fund{value: amount}(subnetId, FvmAddressHelper.from(msg.sender)); + gatewayDiamond.manager().fund{value: amount}(subnetId, FvmAddressHelper.from(msg.sender)); } function testGatewayDiamond_Fund_Fails_NotRegistered() public { @@ -644,10 +664,13 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { SubnetID memory wrongSubnetId = SubnetID({root: ROOTNET_CHAINID, route: wrongSubnetPath}); vm.expectRevert(NotRegisteredSubnet.selector); - gwManager.fund{value: fundAmount}(wrongSubnetId, FvmAddressHelper.from(msg.sender)); + gatewayDiamond.manager().fund{value: fundAmount}(wrongSubnetId, FvmAddressHelper.from(msg.sender)); vm.expectRevert(NotRegisteredSubnet.selector); - gwManager.fund{value: fundAmount}(SubnetID(ROOTNET_CHAINID, wrongPath), FvmAddressHelper.from(msg.sender)); + gatewayDiamond.manager().fund{value: fundAmount}( + SubnetID(ROOTNET_CHAINID, wrongPath), + FvmAddressHelper.from(msg.sender) + ); } function testGatewayDiamond_Fund_Works_BLSAccountSingleFunding() public { @@ -668,7 +691,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { join(validatorAddress, publicKey); vm.prank(validatorAddress); - saManager.leave(); + saDiamond.manager().leave(); join(validatorAddress, publicKey); @@ -692,12 +715,6 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { activeValidatorsLimit: 100 }); gatewayDiamond = createGatewayDiamond(constructorParams); - gwGetter = GatewayGetterFacet(address(gatewayDiamond)); - gwManager = GatewayManagerFacet(address(gatewayDiamond)); - - gwCheckpointingFacet = CheckpointingFacet(address(gatewayDiamond)); - gwXnetMessagingFacet = XnetMessagingFacet(address(gatewayDiamond)); - gwTopDownFinalityFacet = TopDownFinalityFacet(address(gatewayDiamond)); address callerAddress = address(100); @@ -705,7 +722,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.deal(callerAddress, 1 ether); vm.expectRevert(abi.encodeWithSelector(InvalidXnetMessage.selector, InvalidXnetMessageReason.Value)); - gwManager.release{value: 0 ether}(FvmAddressHelper.from(msg.sender)); + gatewayDiamond.manager().release{value: 0 ether}(FvmAddressHelper.from(msg.sender)); } function testGatewayDiamond_Release_Works_BLSAccount(uint256 releaseAmount, uint256 crossMsgFee) public { @@ -724,12 +741,8 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { genesisValidators: new Validator[](0), activeValidatorsLimit: 100 }); + gatewayDiamond = createGatewayDiamond(constructorParams); - gwGetter = GatewayGetterFacet(address(gatewayDiamond)); - gwManager = GatewayManagerFacet(address(gatewayDiamond)); - gwCheckpointingFacet = CheckpointingFacet(address(gatewayDiamond)); - gwXnetMessagingFacet = XnetMessagingFacet(address(gatewayDiamond)); - gwTopDownFinalityFacet = TopDownFinalityFacet(address(gatewayDiamond)); vm.roll(0); vm.warp(0); @@ -754,13 +767,8 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { genesisValidators: new Validator[](0), activeValidatorsLimit: 100 }); - gatewayDiamond = createGatewayDiamond(constructorParams); - gwGetter = GatewayGetterFacet(address(gatewayDiamond)); - gwManager = GatewayManagerFacet(address(gatewayDiamond)); - gwCheckpointingFacet = CheckpointingFacet(address(gatewayDiamond)); - gwXnetMessagingFacet = XnetMessagingFacet(address(gatewayDiamond)); - gwTopDownFinalityFacet = TopDownFinalityFacet(address(gatewayDiamond)); + gatewayDiamond = createGatewayDiamond(constructorParams); address callerAddress = address(100); vm.roll(0); @@ -786,12 +794,8 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { genesisValidators: new Validator[](0), activeValidatorsLimit: 100 }); + gatewayDiamond = createGatewayDiamond(constructorParams); - gwGetter = GatewayGetterFacet(address(gatewayDiamond)); - gwManager = GatewayManagerFacet(address(gatewayDiamond)); - gwCheckpointingFacet = CheckpointingFacet(address(gatewayDiamond)); - gwXnetMessagingFacet = XnetMessagingFacet(address(gatewayDiamond)); - gwTopDownFinalityFacet = TopDownFinalityFacet(address(gatewayDiamond)); address callerAddress = address(100); @@ -811,7 +815,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { registerSubnet(DEFAULT_COLLATERAL_AMOUNT, caller); vm.expectRevert(abi.encodeWithSelector(InvalidXnetMessage.selector, InvalidXnetMessageReason.DstSubnet)); - gwMessenger.sendContractXnetMessage{value: 1}( + gatewayDiamond.messenger().sendContractXnetMessage{value: 1}( TestUtils.newXnetCallMsg( IPCAddress({ subnetId: SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}), @@ -832,10 +836,10 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.startPrank(caller); vm.deal(caller, DEFAULT_COLLATERAL_AMOUNT + DEFAULT_CROSS_MSG_FEE + 2); registerSubnet(DEFAULT_COLLATERAL_AMOUNT, caller); - SubnetID memory destinationSubnet = gwGetter.getNetworkName(); + SubnetID memory destinationSubnet = gatewayDiamond.getter().getNetworkName(); vm.expectRevert(CannotSendCrossMsgToItself.selector); - gwMessenger.sendContractXnetMessage{value: 1}( + gatewayDiamond.messenger().sendContractXnetMessage{value: 1}( TestUtils.newXnetCallMsg( IPCAddress({ subnetId: SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}), @@ -853,10 +857,10 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.startPrank(caller); vm.deal(caller, DEFAULT_COLLATERAL_AMOUNT + DEFAULT_CROSS_MSG_FEE + 2); registerSubnet(DEFAULT_COLLATERAL_AMOUNT, caller); - SubnetID memory destinationSubnet = gwGetter.getNetworkName().createSubnetId(caller); + SubnetID memory destinationSubnet = gatewayDiamond.getter().getNetworkName().createSubnetId(caller); vm.expectRevert(abi.encodeWithSelector(InvalidXnetMessage.selector, InvalidXnetMessageReason.Value)); - gwMessenger.sendContractXnetMessage{value: DEFAULT_CROSS_MSG_FEE}( + gatewayDiamond.messenger().sendContractXnetMessage{value: DEFAULT_CROSS_MSG_FEE}( TestUtils.newXnetCallMsg( IPCAddress({ subnetId: SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}), @@ -879,7 +883,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { SubnetID memory destinationSubnet = SubnetID(0, new address[](0)); vm.expectRevert(abi.encodeWithSelector(InvalidXnetMessage.selector, InvalidXnetMessageReason.Sender)); - gwMessenger.sendContractXnetMessage{value: DEFAULT_CROSS_MSG_FEE}( + gatewayDiamond.messenger().sendContractXnetMessage{value: DEFAULT_CROSS_MSG_FEE}( TestUtils.newXnetCallMsg( IPCAddress({ subnetId: SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}), @@ -904,7 +908,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.expectRevert(abi.encodeWithSelector(InvalidXnetMessage.selector, InvalidXnetMessageReason.DstSubnet)); - gwMessenger.sendContractXnetMessage{value: 1}( + gatewayDiamond.messenger().sendContractXnetMessage{value: 1}( TestUtils.newXnetCallMsg( IPCAddress({ subnetId: SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}), @@ -930,7 +934,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { ParentFinality memory finality = ParentFinality({height: block.number, blockHash: bytes32(0)}); - gwTopDownFinalityFacet.commitParentFinality(finality); + gatewayDiamond.topDownFinalizer().commitParentFinality(finality); } function testGatewayDiamond_applyFinality_works() public { @@ -951,12 +955,15 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.startPrank(FilAddress.SYSTEM_ACTOR); - gwTopDownFinalityFacet.storeValidatorChanges(changes); - uint64 configNumber = gwTopDownFinalityFacet.applyFinalityChanges(); + gatewayDiamond.topDownFinalizer().storeValidatorChanges(changes); + uint64 configNumber = gatewayDiamond.topDownFinalizer().applyFinalityChanges(); require(configNumber == 2, "wrong config number after applying finality"); - require(gwGetter.getCurrentMembership().validators.length == 2, "current membership should be 2"); - require(gwGetter.getCurrentConfigurationNumber() == 2, "unexpected config number"); - require(gwGetter.getLastConfigurationNumber() == 0, "unexpected last config number"); + require( + gatewayDiamond.getter().getCurrentMembership().validators.length == 2, + "current membership should be 2" + ); + require(gatewayDiamond.getter().getCurrentConfigurationNumber() == 2, "unexpected config number"); + require(gatewayDiamond.getter().getLastConfigurationNumber() == 0, "unexpected last config number"); vm.stopPrank(); @@ -970,21 +977,30 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.startPrank(FilAddress.SYSTEM_ACTOR); - gwTopDownFinalityFacet.storeValidatorChanges(changes); - configNumber = gwTopDownFinalityFacet.applyFinalityChanges(); + gatewayDiamond.topDownFinalizer().storeValidatorChanges(changes); + configNumber = gatewayDiamond.topDownFinalizer().applyFinalityChanges(); require(configNumber == 3, "wrong config number after applying finality"); - require(gwGetter.getLastConfigurationNumber() == 2, "apply result: unexpected last config number"); - require(gwGetter.getCurrentConfigurationNumber() == 3, "apply result: unexpected config number"); - require(gwGetter.getCurrentMembership().validators.length == 1, "current membership should be 1"); - require(gwGetter.getLastMembership().validators.length == 2, "last membership should be 2"); + require( + gatewayDiamond.getter().getLastConfigurationNumber() == 2, + "apply result: unexpected last config number" + ); + require(gatewayDiamond.getter().getCurrentConfigurationNumber() == 3, "apply result: unexpected config number"); + require( + gatewayDiamond.getter().getCurrentMembership().validators.length == 1, + "current membership should be 1" + ); + require(gatewayDiamond.getter().getLastMembership().validators.length == 2, "last membership should be 2"); // no changes - configNumber = gwTopDownFinalityFacet.applyFinalityChanges(); + configNumber = gatewayDiamond.topDownFinalizer().applyFinalityChanges(); require(configNumber == 0, "wrong config number after applying finality"); - require(gwGetter.getLastConfigurationNumber() == 2, "no changes: unexpected last config number"); - require(gwGetter.getCurrentConfigurationNumber() == 3, "no changes: unexpected config number"); - require(gwGetter.getCurrentMembership().validators.length == 1, "current membership should be 1"); - require(gwGetter.getLastMembership().validators.length == 2, "last membership should be 2"); + require(gatewayDiamond.getter().getLastConfigurationNumber() == 2, "no changes: unexpected last config number"); + require(gatewayDiamond.getter().getCurrentConfigurationNumber() == 3, "no changes: unexpected config number"); + require( + gatewayDiamond.getter().getCurrentMembership().validators.length == 1, + "current membership should be 1" + ); + require(gatewayDiamond.getter().getLastMembership().validators.length == 2, "last membership should be 2"); vm.stopPrank(); } @@ -1004,12 +1020,12 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { ParentFinality memory finality = ParentFinality({height: block.number, blockHash: bytes32(0)}); - gwTopDownFinalityFacet.commitParentFinality(finality); - ParentFinality memory committedFinality = gwGetter.getParentFinality(block.number); + gatewayDiamond.topDownFinalizer().commitParentFinality(finality); + ParentFinality memory committedFinality = gatewayDiamond.getter().getParentFinality(block.number); require(committedFinality.height == finality.height, "heights are not equal"); require(committedFinality.blockHash == finality.blockHash, "blockHash is not equal"); - require(gwGetter.getLatestParentFinality().height == block.number, "finality height not equal"); + require(gatewayDiamond.getter().getLatestParentFinality().height == block.number, "finality height not equal"); vm.stopPrank(); } @@ -1020,7 +1036,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { (bytes32 membershipRoot, ) = MerkleTreeHelper.createMerkleProofsForValidators(addrs, weights); BottomUpCheckpoint memory old = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), + subnetID: gatewayDiamond.getter().getNetworkName(), blockHeight: 0, blockHash: keccak256("block1"), nextConfigurationNumber: 1, @@ -1028,8 +1044,8 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { }); BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), - blockHeight: gwGetter.bottomUpCheckPeriod(), + subnetID: gatewayDiamond.getter().getNetworkName(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block1"), nextConfigurationNumber: 1, msgs: new IpcEnvelope[](0) @@ -1038,28 +1054,38 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { // failed to create a checkpoint with zero membership weight vm.startPrank(FilAddress.SYSTEM_ACTOR); vm.expectRevert(ZeroMembershipWeight.selector); - gwCheckpointingFacet.createBottomUpCheckpoint(checkpoint, membershipRoot, 0); + gatewayDiamond.checkpointer().createBottomUpCheckpoint(checkpoint, membershipRoot, 0); vm.stopPrank(); // failed create a processed checkpoint vm.startPrank(FilAddress.SYSTEM_ACTOR); vm.expectRevert(QuorumAlreadyProcessed.selector); - gwCheckpointingFacet.createBottomUpCheckpoint(old, membershipRoot, weights[0] + weights[1] + weights[2]); + gatewayDiamond.checkpointer().createBottomUpCheckpoint( + old, + membershipRoot, + weights[0] + weights[1] + weights[2] + ); vm.stopPrank(); // create a checkpoint vm.startPrank(FilAddress.SYSTEM_ACTOR); - gwCheckpointingFacet.createBottomUpCheckpoint(checkpoint, membershipRoot, weights[0] + weights[1] + weights[2]); + gatewayDiamond.checkpointer().createBottomUpCheckpoint( + checkpoint, + membershipRoot, + weights[0] + weights[1] + weights[2] + ); vm.stopPrank(); - BottomUpCheckpoint memory recv = gwGetter.bottomUpCheckpoint(gwGetter.bottomUpCheckPeriod()); + BottomUpCheckpoint memory recv = gatewayDiamond.getter().bottomUpCheckpoint( + gatewayDiamond.getter().bottomUpCheckPeriod() + ); require(recv.nextConfigurationNumber == 1, "nextConfigurationNumber incorrect"); require(recv.blockHash == keccak256("block1"), "block hash incorrect"); - uint256 d = gwGetter.bottomUpCheckPeriod(); + uint256 d = gatewayDiamond.getter().bottomUpCheckPeriod(); // failed to create a checkpoint with the same height checkpoint = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), + subnetID: gatewayDiamond.getter().getNetworkName(), blockHeight: d, blockHash: keccak256("block"), nextConfigurationNumber: 2, @@ -1068,12 +1094,16 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.startPrank(FilAddress.SYSTEM_ACTOR); vm.expectRevert(CheckpointAlreadyExists.selector); - gwCheckpointingFacet.createBottomUpCheckpoint(checkpoint, membershipRoot, weights[0] + weights[1] + weights[2]); + gatewayDiamond.checkpointer().createBottomUpCheckpoint( + checkpoint, + membershipRoot, + weights[0] + weights[1] + weights[2] + ); vm.stopPrank(); // failed to create a checkpoint with the height not multiple to checkpoint period checkpoint = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), + subnetID: gatewayDiamond.getter().getNetworkName(), blockHeight: d + d / 2, blockHash: keccak256("block2"), nextConfigurationNumber: 2, @@ -1082,25 +1112,29 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.startPrank(FilAddress.SYSTEM_ACTOR); vm.expectRevert(InvalidCheckpointEpoch.selector); - gwCheckpointingFacet.createBottomUpCheckpoint(checkpoint, membershipRoot, weights[0] + weights[1] + weights[2]); + gatewayDiamond.checkpointer().createBottomUpCheckpoint( + checkpoint, + membershipRoot, + weights[0] + weights[1] + weights[2] + ); vm.stopPrank(); - (bool ok, uint256 e, ) = gwGetter.getCurrentBottomUpCheckpoint(); + (bool ok, uint256 e, ) = gatewayDiamond.getter().getCurrentBottomUpCheckpoint(); require(ok, "checkpoint not exist"); require(e == d, "out height incorrect"); } function testGatewayDiamond_commitBottomUpCheckpoint_InvalidCheckpointSource() public { BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), - blockHeight: gwGetter.bottomUpCheckPeriod(), + subnetID: gatewayDiamond.getter().getNetworkName(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block1"), nextConfigurationNumber: 1, msgs: new IpcEnvelope[](0) }); vm.expectRevert(InvalidCheckpointSource.selector); - gwCheckpointingFacet.commitCheckpoint(checkpoint); + gatewayDiamond.checkpointer().commitCheckpoint(checkpoint); } function testGatewayDiamond_commitBottomUpCheckpoint_Works_NoMessages() public { @@ -1114,14 +1148,14 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ subnetID: subnetId, - blockHeight: gwGetter.bottomUpCheckPeriod(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block1"), nextConfigurationNumber: 1, msgs: new IpcEnvelope[](0) }); vm.prank(caller); - gwCheckpointingFacet.commitCheckpoint(checkpoint); + gatewayDiamond.checkpointer().commitCheckpoint(checkpoint); } function testGatewayDiamond_commitBottomUpCheckpoint_Works_WithMessages() public { @@ -1134,19 +1168,25 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { uint256 amount = 1; (SubnetID memory subnetId, , , , ) = getSubnet(address(caller)); - (bool exist, Subnet memory subnetInfo) = gwGetter.getSubnet(subnetId); + (bool exist, Subnet memory subnetInfo) = gatewayDiamond.getter().getSubnet(subnetId); require(exist, "subnet does not exist"); require(subnetInfo.circSupply == 0, "unexpected initial circulation supply"); - gwManager.fund{value: DEFAULT_COLLATERAL_AMOUNT}(subnetId, FvmAddressHelper.from(address(caller))); - (, subnetInfo) = gwGetter.getSubnet(subnetId); + gatewayDiamond.manager().fund{value: DEFAULT_COLLATERAL_AMOUNT}( + subnetId, + FvmAddressHelper.from(address(caller)) + ); + (, subnetInfo) = gatewayDiamond.getter().getSubnet(subnetId); require(subnetInfo.circSupply == DEFAULT_COLLATERAL_AMOUNT, "unexpected circulation supply after funding"); IpcEnvelope[] memory msgs = new IpcEnvelope[](10); for (uint64 i = 0; i < 10; i++) { msgs[i] = TestUtils.newXnetCallMsg( IPCAddress({subnetId: subnetId, rawAddress: FvmAddressHelper.from(caller)}), - IPCAddress({subnetId: gwGetter.getNetworkName(), rawAddress: FvmAddressHelper.from(vm.addr(100 + i))}), + IPCAddress({ + subnetId: gatewayDiamond.getter().getNetworkName(), + rawAddress: FvmAddressHelper.from(vm.addr(100 + i)) + }), amount, i ); @@ -1154,16 +1194,16 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ subnetID: subnetId, - blockHeight: gwGetter.bottomUpCheckPeriod(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block1"), nextConfigurationNumber: 1, msgs: msgs }); vm.prank(caller); - gwCheckpointingFacet.commitCheckpoint(checkpoint); + gatewayDiamond.checkpointer().commitCheckpoint(checkpoint); - (, subnetInfo) = gwGetter.getSubnet(subnetId); + (, subnetInfo) = gatewayDiamond.getter().getSubnet(subnetId); require(subnetInfo.circSupply == DEFAULT_COLLATERAL_AMOUNT - 10 * amount, "unexpected circulating supply"); } @@ -1173,16 +1213,16 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { (bytes32 membershipRoot, ) = MerkleTreeHelper.createMerkleProofsForValidators(addrs, weights); BottomUpCheckpoint memory checkpoint1 = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), - blockHeight: gwGetter.bottomUpCheckPeriod(), + subnetID: gatewayDiamond.getter().getNetworkName(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block1"), nextConfigurationNumber: 1, msgs: new IpcEnvelope[](0) }); BottomUpCheckpoint memory checkpoint2 = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), - blockHeight: 2 * gwGetter.bottomUpCheckPeriod(), + subnetID: gatewayDiamond.getter().getNetworkName(), + blockHeight: 2 * gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block2"), nextConfigurationNumber: 1, msgs: new IpcEnvelope[](0) @@ -1190,43 +1230,51 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { // create a checkpoint vm.startPrank(FilAddress.SYSTEM_ACTOR); - gwCheckpointingFacet.createBottomUpCheckpoint( + gatewayDiamond.checkpointer().createBottomUpCheckpoint( checkpoint1, membershipRoot, weights[0] + weights[1] + weights[2] ); - gwCheckpointingFacet.createBottomUpCheckpoint( + gatewayDiamond.checkpointer().createBottomUpCheckpoint( checkpoint2, membershipRoot, weights[0] + weights[1] + weights[2] ); vm.stopPrank(); - uint256[] memory heights = gwGetter.getIncompleteCheckpointHeights(); + uint256[] memory heights = gatewayDiamond.getter().getIncompleteCheckpointHeights(); require(heights.length == 2, "unexpected heights"); - require(heights[0] == gwGetter.bottomUpCheckPeriod(), "heights[0] == period"); - require(heights[1] == 2 * gwGetter.bottomUpCheckPeriod(), "heights[1] == 2*period"); + require(heights[0] == gatewayDiamond.getter().bottomUpCheckPeriod(), "heights[0] == period"); + require(heights[1] == 2 * gatewayDiamond.getter().bottomUpCheckPeriod(), "heights[1] == 2*period"); - QuorumInfo memory info = gwGetter.getCheckpointInfo(gwGetter.bottomUpCheckPeriod()); + QuorumInfo memory info = gatewayDiamond.getter().getCheckpointInfo( + gatewayDiamond.getter().bottomUpCheckPeriod() + ); require(info.rootHash == membershipRoot, "info.rootHash == membershipRoot"); require( - info.threshold == gwGetter.getQuorumThreshold(weights[0] + weights[1] + weights[2]), + info.threshold == gatewayDiamond.getter().getQuorumThreshold(weights[0] + weights[1] + weights[2]), "checkpoint 1 correct threshold" ); - info = gwGetter.getCheckpointInfo(2 * gwGetter.bottomUpCheckPeriod()); + info = gatewayDiamond.getter().getCheckpointInfo(2 * gatewayDiamond.getter().bottomUpCheckPeriod()); require(info.rootHash == membershipRoot, "info.rootHash == membershipRoot"); require( - info.threshold == gwGetter.getQuorumThreshold(weights[0] + weights[1] + weights[2]), + info.threshold == gatewayDiamond.getter().getQuorumThreshold(weights[0] + weights[1] + weights[2]), "checkpoint 2 correct threshold" ); - BottomUpCheckpoint[] memory incomplete = gwGetter.getIncompleteCheckpoints(); + BottomUpCheckpoint[] memory incomplete = gatewayDiamond.getter().getIncompleteCheckpoints(); require(incomplete.length == 2, "incomplete.length == 2"); - require(incomplete[0].blockHeight == gwGetter.bottomUpCheckPeriod(), "incomplete[0].blockHeight"); + require( + incomplete[0].blockHeight == gatewayDiamond.getter().bottomUpCheckPeriod(), + "incomplete[0].blockHeight" + ); require(incomplete[0].blockHash == keccak256("block1"), "incomplete[0].blockHash"); - require(incomplete[1].blockHeight == 2 * gwGetter.bottomUpCheckPeriod(), "incomplete[1].blockHeight"); + require( + incomplete[1].blockHeight == 2 * gatewayDiamond.getter().bottomUpCheckPeriod(), + "incomplete[1].blockHeight" + ); require(incomplete[1].blockHash == keccak256("block2"), "incomplete[1].blockHash"); } @@ -1237,8 +1285,8 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { .createMerkleProofsForValidators(addrs, weights); BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), - blockHeight: gwGetter.bottomUpCheckPeriod(), + subnetID: gatewayDiamond.getter().getNetworkName(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block"), nextConfigurationNumber: 1, msgs: new IpcEnvelope[](0) @@ -1246,7 +1294,11 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { // create a checkpoint vm.startPrank(FilAddress.SYSTEM_ACTOR); - gwCheckpointingFacet.createBottomUpCheckpoint(checkpoint, membershipRoot, weights[0] + weights[1] + weights[2]); + gatewayDiamond.checkpointer().createBottomUpCheckpoint( + checkpoint, + membershipRoot, + weights[0] + weights[1] + weights[2] + ); vm.stopPrank(); // adds signatures @@ -1261,7 +1313,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { signature = abi.encodePacked(r, s, v); vm.startPrank(vm.addr(privKeys[i])); - gwCheckpointingFacet.addCheckpointSignature( + gatewayDiamond.checkpointer().addCheckpointSignature( checkpoint.blockHeight, membershipProofs[i], weights[i], @@ -1271,7 +1323,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { } require( - gwGetter.getCheckpointCurrentWeight(checkpoint.blockHeight) == totalWeight(weights), + gatewayDiamond.getter().getCheckpointCurrentWeight(checkpoint.blockHeight) == totalWeight(weights), "checkpoint weight was not updated" ); @@ -1280,7 +1332,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { QuorumInfo memory info, address[] memory signatories, bytes[] memory signatures - ) = gwGetter.getCheckpointSignatureBundle(gwGetter.bottomUpCheckPeriod()); + ) = gatewayDiamond.getter().getCheckpointSignatureBundle(gatewayDiamond.getter().bottomUpCheckPeriod()); require(ch.blockHash == keccak256("block"), "unexpected block hash"); require(info.hash == keccak256(abi.encode(checkpoint)), "unexpected checkpoint hash"); require(signatories.length == 3, "unexpected signatories length"); @@ -1294,8 +1346,8 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { .createMerkleProofsForValidators(addrs, weights); BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), - blockHeight: gwGetter.bottomUpCheckPeriod(), + subnetID: gatewayDiamond.getter().getNetworkName(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block"), nextConfigurationNumber: 1, msgs: new IpcEnvelope[](0) @@ -1303,7 +1355,11 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { // create a checkpoint vm.startPrank(FilAddress.SYSTEM_ACTOR); - gwCheckpointingFacet.createBottomUpCheckpoint(checkpoint, membershipRoot, weights[0] + weights[1] + weights[2]); + gatewayDiamond.checkpointer().createBottomUpCheckpoint( + checkpoint, + membershipRoot, + weights[0] + weights[1] + weights[2] + ); vm.stopPrank(); // adds signatures @@ -1318,7 +1374,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { signature = abi.encodePacked(r, s, v); vm.startPrank(vm.addr(privKeys[i])); - gwCheckpointingFacet.addCheckpointSignature( + gatewayDiamond.checkpointer().addCheckpointSignature( checkpoint.blockHeight, membershipProofs[i], weights[i], @@ -1327,32 +1383,42 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.stopPrank(); } - QuorumInfo memory info = gwGetter.getCheckpointInfo(1); + QuorumInfo memory info = gatewayDiamond.getter().getCheckpointInfo(1); require(!info.reached, "not reached"); - require(gwGetter.getIncompleteCheckpointHeights().length == 1, "unexpected size"); + require(gatewayDiamond.getter().getIncompleteCheckpointHeights().length == 1, "unexpected size"); - info = gwGetter.getCheckpointInfo(1); + info = gatewayDiamond.getter().getCheckpointInfo(1); (v, r, s) = vm.sign(privKeys[2], keccak256(abi.encode(checkpoint))); signature = abi.encodePacked(r, s, v); vm.startPrank(vm.addr(privKeys[2])); - gwCheckpointingFacet.addCheckpointSignature(checkpoint.blockHeight, membershipProofs[2], weights[2], signature); + gatewayDiamond.checkpointer().addCheckpointSignature( + checkpoint.blockHeight, + membershipProofs[2], + weights[2], + signature + ); vm.stopPrank(); - info = gwGetter.getCheckpointInfo(checkpoint.blockHeight); + info = gatewayDiamond.getter().getCheckpointInfo(checkpoint.blockHeight); require(info.reached, "not reached"); - require(gwGetter.getIncompleteCheckpointHeights().length == 0, "unexpected size"); + require(gatewayDiamond.getter().getIncompleteCheckpointHeights().length == 0, "unexpected size"); require( - gwGetter.getCheckpointCurrentWeight(checkpoint.blockHeight) == totalWeight(weights), + gatewayDiamond.getter().getCheckpointCurrentWeight(checkpoint.blockHeight) == totalWeight(weights), "checkpoint weight was not updated" ); (v, r, s) = vm.sign(privKeys[3], keccak256(abi.encode(checkpoint))); signature = abi.encodePacked(r, s, v); vm.startPrank(vm.addr(privKeys[3])); - gwCheckpointingFacet.addCheckpointSignature(checkpoint.blockHeight, membershipProofs[3], weights[3], signature); + gatewayDiamond.checkpointer().addCheckpointSignature( + checkpoint.blockHeight, + membershipProofs[3], + weights[3], + signature + ); vm.stopPrank(); } @@ -1363,8 +1429,8 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { .createMerkleProofsForValidators(addrs, weights); BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), - blockHeight: gwGetter.bottomUpCheckPeriod(), + subnetID: gatewayDiamond.getter().getNetworkName(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block"), nextConfigurationNumber: 1, msgs: new IpcEnvelope[](0) @@ -1372,7 +1438,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { // create a checkpoint vm.startPrank(FilAddress.SYSTEM_ACTOR); - gwCheckpointingFacet.createBottomUpCheckpoint(checkpoint, membershipRoot, 10); + gatewayDiamond.checkpointer().createBottomUpCheckpoint(checkpoint, membershipRoot, 10); vm.stopPrank(); uint8 v; @@ -1383,10 +1449,10 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { (v, r, s) = vm.sign(privKeys[0], keccak256(abi.encode(checkpoint))); signature = abi.encodePacked(r, s, v); - uint256 h = gwGetter.bottomUpCheckPeriod(); + uint256 h = gatewayDiamond.getter().bottomUpCheckPeriod(); vm.startPrank(vm.addr(privKeys[1])); vm.expectRevert(abi.encodeWithSelector(NotAuthorized.selector, vm.addr(privKeys[0]))); - gwCheckpointingFacet.addCheckpointSignature(h, membershipProofs[2], weights[2], signature); + gatewayDiamond.checkpointer().addCheckpointSignature(h, membershipProofs[2], weights[2], signature); vm.stopPrank(); } @@ -1397,8 +1463,8 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { .createMerkleProofsForValidators(addrs, weights); BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), - blockHeight: gwGetter.bottomUpCheckPeriod(), + subnetID: gatewayDiamond.getter().getNetworkName(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block"), nextConfigurationNumber: 1, msgs: new IpcEnvelope[](0) @@ -1406,7 +1472,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { // create a checkpoint vm.startPrank(FilAddress.SYSTEM_ACTOR); - gwCheckpointingFacet.createBottomUpCheckpoint(checkpoint, membershipRoot, 10); + gatewayDiamond.checkpointer().createBottomUpCheckpoint(checkpoint, membershipRoot, 10); vm.stopPrank(); uint8 v; @@ -1417,19 +1483,19 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { (v, r, s) = vm.sign(privKeys[0], keccak256(abi.encode(checkpoint))); signature = abi.encodePacked(r, s, v); - uint256 h = gwGetter.bottomUpCheckPeriod(); + uint256 h = gatewayDiamond.getter().bottomUpCheckPeriod(); vm.startPrank(vm.addr(privKeys[0])); // send incorrect signature vm.expectRevert(InvalidSignature.selector); - gwCheckpointingFacet.addCheckpointSignature(h, membershipProofs[0], weights[0], new bytes(0)); + gatewayDiamond.checkpointer().addCheckpointSignature(h, membershipProofs[0], weights[0], new bytes(0)); // send correct signature - gwCheckpointingFacet.addCheckpointSignature(h, membershipProofs[0], weights[0], signature); + gatewayDiamond.checkpointer().addCheckpointSignature(h, membershipProofs[0], weights[0], signature); // replay the previous signature vm.expectRevert(SignatureReplay.selector); - gwCheckpointingFacet.addCheckpointSignature(h, membershipProofs[0], weights[0], signature); + gatewayDiamond.checkpointer().addCheckpointSignature(h, membershipProofs[0], weights[0], signature); vm.stopPrank(); } @@ -1441,8 +1507,8 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { .createMerkleProofsForValidators(addrs, weights); BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), - blockHeight: gwGetter.bottomUpCheckPeriod(), + subnetID: gatewayDiamond.getter().getNetworkName(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block"), nextConfigurationNumber: 1, msgs: new IpcEnvelope[](0) @@ -1450,7 +1516,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { // create a checkpoint vm.startPrank(FilAddress.SYSTEM_ACTOR); - gwCheckpointingFacet.createBottomUpCheckpoint(checkpoint, membershipRoot, 10); + gatewayDiamond.checkpointer().createBottomUpCheckpoint(checkpoint, membershipRoot, 10); vm.stopPrank(); uint8 v; @@ -1465,11 +1531,11 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { // send correct signature for incorrect height vm.expectRevert(QuorumAlreadyProcessed.selector); - gwCheckpointingFacet.addCheckpointSignature(0, membershipProofs[0], weights[0], signature); + gatewayDiamond.checkpointer().addCheckpointSignature(0, membershipProofs[0], weights[0], signature); // send correct signature for incorrect height vm.expectRevert(CheckpointNotCreated.selector); - gwCheckpointingFacet.addCheckpointSignature(100, membershipProofs[0], weights[0], signature); + gatewayDiamond.checkpointer().addCheckpointSignature(100, membershipProofs[0], weights[0], signature); vm.stopPrank(); } @@ -1479,7 +1545,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { (bytes32 membershipRoot, ) = MerkleTreeHelper.createMerkleProofsForValidators(addrs, weights); - uint256 index = gwGetter.getCheckpointRetentionHeight(); + uint256 index = gatewayDiamond.getter().getCheckpointRetentionHeight(); require(index == 1, "unexpected height"); BottomUpCheckpoint memory checkpoint; @@ -1489,30 +1555,30 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.startPrank(FilAddress.SYSTEM_ACTOR); for (uint64 i = 1; i <= n; i++) { checkpoint = BottomUpCheckpoint({ - subnetID: gwGetter.getNetworkName(), - blockHeight: i * gwGetter.bottomUpCheckPeriod(), + subnetID: gatewayDiamond.getter().getNetworkName(), + blockHeight: i * gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block"), nextConfigurationNumber: 1, msgs: new IpcEnvelope[](0) }); - gwCheckpointingFacet.createBottomUpCheckpoint(checkpoint, membershipRoot, 10); + gatewayDiamond.checkpointer().createBottomUpCheckpoint(checkpoint, membershipRoot, 10); } vm.stopPrank(); - index = gwGetter.getCheckpointRetentionHeight(); + index = gatewayDiamond.getter().getCheckpointRetentionHeight(); require(index == 1, "retention height is not 1"); - uint256[] memory heights = gwGetter.getIncompleteCheckpointHeights(); + uint256[] memory heights = gatewayDiamond.getter().getIncompleteCheckpointHeights(); require(heights.length == n, "heights.len is not n"); vm.startPrank(FilAddress.SYSTEM_ACTOR); - gwCheckpointingFacet.pruneBottomUpCheckpoints(4); + gatewayDiamond.checkpointer().pruneBottomUpCheckpoints(4); vm.stopPrank(); - index = gwGetter.getCheckpointRetentionHeight(); + index = gatewayDiamond.getter().getCheckpointRetentionHeight(); require(index == 4, "height was not updated"); - heights = gwGetter.getIncompleteCheckpointHeights(); + heights = gatewayDiamond.getter().getIncompleteCheckpointHeights(); require(heights.length == n, "index is not the same"); } @@ -1526,20 +1592,26 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { uint256 amount = 1; (SubnetID memory subnetId, , , , ) = getSubnet(address(caller)); - (bool exist, Subnet memory subnetInfo) = gwGetter.getSubnet(subnetId); + (bool exist, Subnet memory subnetInfo) = gatewayDiamond.getter().getSubnet(subnetId); require(exist, "subnet does not exist"); require(subnetInfo.circSupply == 0, "unexpected initial circulation supply"); - gwManager.fund{value: DEFAULT_COLLATERAL_AMOUNT}(subnetId, FvmAddressHelper.from(address(caller))); - (, subnetInfo) = gwGetter.getSubnet(subnetId); + gatewayDiamond.manager().fund{value: DEFAULT_COLLATERAL_AMOUNT}( + subnetId, + FvmAddressHelper.from(address(caller)) + ); + (, subnetInfo) = gatewayDiamond.getter().getSubnet(subnetId); require(subnetInfo.circSupply == DEFAULT_COLLATERAL_AMOUNT, "unexpected circulation supply after funding"); - uint64 size = gwGetter.maxMsgsPerBottomUpBatch() + 1; + uint64 size = gatewayDiamond.getter().maxMsgsPerBottomUpBatch() + 1; IpcEnvelope[] memory msgs = new IpcEnvelope[](size); for (uint64 i = 0; i < size; i++) { msgs[i] = TestUtils.newXnetCallMsg( IPCAddress({subnetId: subnetId, rawAddress: FvmAddressHelper.from(caller)}), - IPCAddress({subnetId: gwGetter.getNetworkName(), rawAddress: FvmAddressHelper.from(caller)}), + IPCAddress({ + subnetId: gatewayDiamond.getter().getNetworkName(), + rawAddress: FvmAddressHelper.from(caller) + }), amount, i ); @@ -1547,7 +1619,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ subnetID: subnetId, - blockHeight: gwGetter.bottomUpCheckPeriod(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block1"), nextConfigurationNumber: 1, msgs: msgs @@ -1555,7 +1627,7 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { vm.prank(caller); vm.expectRevert(MaxMsgsPerBatchExceeded.selector); - gwCheckpointingFacet.commitCheckpoint(checkpoint); + gatewayDiamond.checkpointer().commitCheckpoint(checkpoint); } function testGatewayDiamond_PopulateBottomUpMsgBatch_Works() public { @@ -1573,14 +1645,9 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { genesisValidators: new Validator[](0), activeValidatorsLimit: 100 }); - gatewayDiamond = createGatewayDiamond(constructorParams); - gwGetter = GatewayGetterFacet(address(gatewayDiamond)); - gwManager = GatewayManagerFacet(address(gatewayDiamond)); - gwCheckpointingFacet = CheckpointingFacet(address(gatewayDiamond)); - gwXnetMessagingFacet = XnetMessagingFacet(address(gatewayDiamond)); - gwTopDownFinalityFacet = TopDownFinalityFacet(address(gatewayDiamond)); - uint256 d = gwGetter.bottomUpCheckPeriod(); + gatewayDiamond = createGatewayDiamond(constructorParams); + uint256 d = gatewayDiamond.getter().bottomUpCheckPeriod(); // a few messags in first batch uint64 numMsgs = 10; @@ -1591,9 +1658,9 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { for (uint64 i = 0; i < numMsgs; i++) { release(releaseAmount); } - require(gwGetter.bottomUpMsgBatch(d).msgs.length == numMsgs, "no messages"); + require(gatewayDiamond.getter().bottomUpMsgBatch(d).msgs.length == numMsgs, "no messages"); - numMsgs = gwGetter.maxMsgsPerBottomUpBatch() + 10; + numMsgs = gatewayDiamond.getter().maxMsgsPerBottomUpBatch() + 10; vm.roll(d + 1); vm.startPrank(from); vm.deal(from, numMsgs * (releaseAmount + DEFAULT_CROSS_MSG_FEE)); @@ -1604,18 +1671,28 @@ contract GatewayActorDiamondTest is Test, IntegrationTestBase { // one batch should be overflow in d+1 and the rest of the messages should have been // added to the next batch require( - gwGetter.bottomUpMsgBatch(d + 1).msgs.length == gwGetter.maxMsgsPerBottomUpBatch(), + gatewayDiamond.getter().bottomUpMsgBatch(d + 1).msgs.length == + gatewayDiamond.getter().maxMsgsPerBottomUpBatch(), "wrong number of messages in full batch" ); - require(gwGetter.bottomUpMsgBatch(2 * d).msgs.length == 10, "wrong number of messages after full batch"); + require( + gatewayDiamond.getter().bottomUpMsgBatch(2 * d).msgs.length == 10, + "wrong number of messages after full batch" + ); } function newListOfMessages(uint64 size) internal view returns (IpcEnvelope[] memory msgs) { msgs = new IpcEnvelope[](size); for (uint64 i = 0; i < size; i++) { msgs[i] = TestUtils.newXnetCallMsg( - IPCAddress({subnetId: gwGetter.getNetworkName(), rawAddress: FvmAddressHelper.from(address(this))}), - IPCAddress({subnetId: gwGetter.getNetworkName(), rawAddress: FvmAddressHelper.from(address(this))}), + IPCAddress({ + subnetId: gatewayDiamond.getter().getNetworkName(), + rawAddress: FvmAddressHelper.from(address(this)) + }), + IPCAddress({ + subnetId: gatewayDiamond.getter().getNetworkName(), + rawAddress: FvmAddressHelper.from(address(this)) + }), 0, i // method: this.callback.selector, diff --git a/contracts/test/integration/GatewayDiamondToken.t.sol b/contracts/test/integration/GatewayDiamondToken.t.sol index 07d06b1d2..fe64ea08d 100644 --- a/contracts/test/integration/GatewayDiamondToken.t.sol +++ b/contracts/test/integration/GatewayDiamondToken.t.sol @@ -31,10 +31,13 @@ import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol"; import {ERC20PresetFixedSupply} from "../helpers/ERC20PresetFixedSupply.sol"; import {IERC20Errors} from "openzeppelin-contracts/interfaces/draft-IERC6093.sol"; +import {GatewayFacetsHelper} from "../helpers/GatewayFacetsHelper.sol"; + contract GatewayDiamondTokenTest is Test, IntegrationTestBase { using SubnetIDHelper for SubnetID; using CrossMsgHelper for IpcEnvelope; using FvmAddressHelper for FvmAddress; + using GatewayFacetsHelper for GatewayDiamond; IERC20 private token; @@ -51,11 +54,11 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { address caller = vm.addr(1); vm.deal(caller, 100); - (SubnetID memory subnetId, , , , ) = getSubnet(address(saManager)); + (SubnetID memory subnetId, , , , ) = getSubnet(address(saDiamond)); vm.prank(caller); vm.expectRevert(SupplySourceHelper.UnexpectedSupplySource.selector); - gwManager.fundWithToken(subnetId, FvmAddressHelper.from(caller), 100); + gatewayDiamond.manager().fundWithToken(subnetId, FvmAddressHelper.from(caller), 100); } function test_fund_TokenSupply_Reverts() public { @@ -66,7 +69,7 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { vm.prank(caller); vm.expectRevert(SupplySourceHelper.UnexpectedSupplySource.selector); - gwManager.fund{value: 100}(subnet.id, FvmAddressHelper.from(caller)); + gatewayDiamond.manager().fund{value: 100}(subnet.id, FvmAddressHelper.from(caller)); } function testFail_InexistentToken() public { @@ -85,7 +88,7 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { vm.expectRevert( abi.encodeWithSelector(IERC20Errors.ERC20InsufficientAllowance.selector, address(gatewayDiamond), 0, 1) ); - gwManager.fundWithToken(subnet.id, FvmAddressHelper.from(caller), 1); + gatewayDiamond.manager().fundWithToken(subnet.id, FvmAddressHelper.from(caller), 1); } function test_fundWithToken() public { @@ -108,28 +111,28 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { ); vm.expectEmit(true, true, true, true, address(gatewayDiamond)); emit LibGateway.NewTopDownMessage(address(saDiamond), expected); - gwManager.fundWithToken(subnet.id, FvmAddressHelper.from(caller), 10); + gatewayDiamond.manager().fundWithToken(subnet.id, FvmAddressHelper.from(caller), 10); // Assert post-conditions. - (, Subnet memory subnetAfter) = gwGetter.getSubnet(subnet.id); + (, Subnet memory subnetAfter) = gatewayDiamond.getter().getSubnet(subnet.id); assertEq(subnetAfter.circSupply, 10); assertEq(subnetAfter.topDownNonce, 1); // A new funding attempt with exhausted token balance should fail. vm.expectRevert(); - gwManager.fundWithToken(subnet.id, FvmAddressHelper.from(caller), 10); + gatewayDiamond.manager().fundWithToken(subnet.id, FvmAddressHelper.from(caller), 10); // And the subnet's state should not have been updated. - (, subnetAfter) = gwGetter.getSubnet(subnet.id); + (, subnetAfter) = gatewayDiamond.getter().getSubnet(subnet.id); assertEq(subnetAfter.circSupply, 10); assertEq(subnetAfter.topDownNonce, 1); // After topping up it succeeds again. token.approve(address(gatewayDiamond), 5); - gwManager.fundWithToken(subnet.id, FvmAddressHelper.from(caller), 5); + gatewayDiamond.manager().fundWithToken(subnet.id, FvmAddressHelper.from(caller), 5); // And the subnet's bookkeeping is correct. - (, subnetAfter) = gwGetter.getSubnet(subnet.id); + (, subnetAfter) = gatewayDiamond.getter().getSubnet(subnet.id); assertEq(subnetAfter.circSupply, 15); assertEq(subnetAfter.topDownNonce, 2); } @@ -145,7 +148,7 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { vm.prank(caller); token.approve(address(gatewayDiamond), 15); vm.prank(caller); - gwManager.fundWithToken(subnet.id, FvmAddressHelper.from(caller), 15); + gatewayDiamond.manager().fundWithToken(subnet.id, FvmAddressHelper.from(caller), 15); // Now create a new recipient on the parent. address recipient = vm.addr(42); @@ -158,7 +161,7 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { BottomUpCheckpoint memory batch = BottomUpCheckpoint({ subnetID: subnet.id, blockHash: blockhash(block.number), - blockHeight: gwGetter.bottomUpCheckPeriod(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), nextConfigurationNumber: 0, msgs: msgs }); @@ -166,10 +169,10 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { vm.prank(address(saDiamond)); vm.expectEmit(true, true, true, true, address(token)); emit Transfer(address(gatewayDiamond), recipient, value); - gwCheckpointingFacet.commitCheckpoint(batch); + gatewayDiamond.checkpointer().commitCheckpoint(batch); // Assert post-conditions. - (, Subnet memory subnetAfter) = gwGetter.getSubnet(subnet.id); + (, Subnet memory subnetAfter) = gatewayDiamond.getter().getSubnet(subnet.id); assertEq(subnetAfter.circSupply, 7); assertEq(subnetAfter.topDownNonce, 2); // 2 because the result msg is also another td message assertEq(subnetAfter.appliedBottomUpNonce, 1); @@ -181,7 +184,7 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { // This reverts. vm.prank(address(saDiamond)); vm.expectRevert(); - gwCheckpointingFacet.commitCheckpoint(batch); + gatewayDiamond.checkpointer().commitCheckpoint(batch); } // Call a smart contract in the parent through a smart contract and with @@ -195,7 +198,7 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { vm.prank(caller); token.approve(address(gatewayDiamond), 15); vm.prank(caller); - gwManager.fundWithToken(subnet.id, FvmAddressHelper.from(caller), 15); + gatewayDiamond.manager().fundWithToken(subnet.id, FvmAddressHelper.from(caller), 15); // Now create a new recipient on the parent. address recipient = address(new MockIpcContract()); @@ -216,7 +219,7 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { BottomUpCheckpoint memory batch = BottomUpCheckpoint({ subnetID: subnet.id, blockHash: blockhash(block.number), - blockHeight: gwGetter.bottomUpCheckPeriod(), + blockHeight: gatewayDiamond.getter().bottomUpCheckPeriod(), nextConfigurationNumber: 0, msgs: msgs }); @@ -224,7 +227,7 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { // Verify that we received the call and that the recipient has the tokens. vm.prank(address(saDiamond)); vm.expectCall(recipient, abi.encodeCall(IpcHandler.handleIpcMessage, (msgs[0])), 1); - gwCheckpointingFacet.commitCheckpoint(batch); + gatewayDiamond.checkpointer().commitCheckpoint(batch); assertEq(token.balanceOf(recipient), 8); } @@ -237,17 +240,13 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { function createTokenSubnet(address tokenAddress) internal returns (Subnet memory) { // Create a subnet actor in the root network, with an ERC20 supply source with the specified token address. - SubnetActorDiamond.ConstructorParams memory saConstructorParams = defaultSubnetActorParamsWithGateway( + SubnetActorDiamond.ConstructorParams memory saConstructorParams = defaultSubnetActorParamsWith( address(gatewayDiamond) ); saConstructorParams.supplySource = SupplySource({kind: SupplyKind.ERC20, tokenAddress: tokenAddress}); // Override the state variables with the new subnet. saDiamond = createSubnetActor(saConstructorParams); - saManager = SubnetActorManagerFacet(address(saDiamond)); - saGetter = SubnetActorGetterFacet(address(saDiamond)); - saLouper = DiamondLoupeFacet(address(saDiamond)); - saCutter = DiamondCutFacet(address(saDiamond)); // increment the block number by 5 (could be other number as well) so that commit // parent finality called down stream will work we need this because in setUp, @@ -260,9 +259,9 @@ contract GatewayDiamondTokenTest is Test, IntegrationTestBase { (address validatorAddress, bytes memory publicKey) = TestUtils.deriveValidatorAddress(100); join(validatorAddress, publicKey); - SubnetID memory subnetId = gwGetter.getNetworkName().createSubnetId(address(saDiamond)); + SubnetID memory subnetId = gatewayDiamond.getter().getNetworkName().createSubnetId(address(saDiamond)); - (bool exists, Subnet memory subnet) = gwGetter.getSubnet(subnetId); + (bool exists, Subnet memory subnet) = gatewayDiamond.getter().getSubnet(subnetId); assert(exists); return subnet; } diff --git a/contracts/test/integration/L2GatewayDiamond.t.sol b/contracts/test/integration/L2GatewayDiamond.t.sol index 9c009d9ff..f230d8725 100644 --- a/contracts/test/integration/L2GatewayDiamond.t.sol +++ b/contracts/test/integration/L2GatewayDiamond.t.sol @@ -23,9 +23,12 @@ import {L2GatewayActorDiamond} from "../IntegrationTestPresets.sol"; import {TestUtils} from "../helpers/TestUtils.sol"; import {FilAddress} from "fevmate/utils/FilAddress.sol"; +import {GatewayFacetsHelper} from "../helpers/GatewayFacetsHelper.sol"; + contract L2GatewayActorDiamondTest is Test, L2GatewayActorDiamond { using SubnetIDHelper for SubnetID; using CrossMsgHelper for IpcEnvelope; + using GatewayFacetsHelper for GatewayDiamond; function testGatewayDiamond_CommitParentFinality_BigNumberOfMessages() public { uint256 n = 2000; @@ -37,14 +40,14 @@ contract L2GatewayActorDiamondTest is Test, L2GatewayActorDiamond { uint256[] memory weights = new uint[](1); weights[0] = 100; - SubnetID memory id = gwGetter.getNetworkName(); + SubnetID memory id = gatewayDiamond.getter().getNetworkName(); IpcEnvelope[] memory topDownMsgs = new IpcEnvelope[](n); for (uint64 i = 0; i < n; i++) { topDownMsgs[i] = TestUtils.newXnetCallMsg( IPCAddress({subnetId: id, rawAddress: FvmAddressHelper.from(address(this))}), IPCAddress({ - subnetId: gwGetter.getNetworkName().getParentSubnet(), + subnetId: gatewayDiamond.getter().getNetworkName().getParentSubnet(), rawAddress: FvmAddressHelper.from(receipient) }), 0, @@ -54,9 +57,9 @@ contract L2GatewayActorDiamondTest is Test, L2GatewayActorDiamond { vm.startPrank(FilAddress.SYSTEM_ACTOR); - gwXnetMessagingFacet.applyCrossMessages(topDownMsgs); - require(gwGetter.getSubnetTopDownMsgsLength(id) == 0, "unexpected top-down message"); - (bool ok, uint64 tdn) = gwGetter.getTopDownNonce(id); + gatewayDiamond.xnetMessenger().applyCrossMessages(topDownMsgs); + require(gatewayDiamond.getter().getSubnetTopDownMsgsLength(id) == 0, "unexpected top-down message"); + (bool ok, uint64 tdn) = gatewayDiamond.getter().getTopDownNonce(id); require(!ok && tdn == 0, "unexpected nonce"); vm.stopPrank(); @@ -76,7 +79,7 @@ contract L2GatewayActorDiamondTest is Test, L2GatewayActorDiamond { vm.expectCall(caller, 1 ether, new bytes(0), 1); vm.prank(caller); - gwMessenger.propagate{value: 1 ether}(postboxId); + gatewayDiamond.messenger().propagate{value: 1 ether}(postboxId); require(caller.balance == 1 ether, "unexpected balance"); } @@ -93,7 +96,7 @@ contract L2GatewayActorDiamondTest is Test, L2GatewayActorDiamond { vm.prank(caller); vm.expectCall(caller, 0, EMPTY_BYTES, 0); - gwMessenger.propagate{value: 0}(postboxId); + gatewayDiamond.messenger().propagate{value: 0}(postboxId); require(caller.balance == 0, "unexpected balance"); } @@ -102,11 +105,11 @@ contract L2GatewayActorDiamondTest is Test, L2GatewayActorDiamond { IpcEnvelope memory crossMsg = TestUtils.newXnetCallMsg( IPCAddress({ - subnetId: gwGetter.getNetworkName().createSubnetId(caller), + subnetId: gatewayDiamond.getter().getNetworkName().createSubnetId(caller), rawAddress: FvmAddressHelper.from(caller) }), IPCAddress({ - subnetId: gwGetter.getNetworkName().createSubnetId(address(this)), + subnetId: gatewayDiamond.getter().getNetworkName().createSubnetId(address(this)), rawAddress: FvmAddressHelper.from(address(this)) }), DEFAULT_CROSS_MSG_FEE + 1, @@ -116,7 +119,7 @@ contract L2GatewayActorDiamondTest is Test, L2GatewayActorDiamond { msgs[0] = crossMsg; vm.prank(FilAddress.SYSTEM_ACTOR); - gwXnetMessagingFacet.applyCrossMessages(msgs); + gatewayDiamond.xnetMessenger().applyCrossMessages(msgs); return crossMsg.toHash(); } diff --git a/contracts/test/integration/MultiSubnet.t.sol b/contracts/test/integration/MultiSubnet.t.sol index 83e1694f7..df710daa0 100644 --- a/contracts/test/integration/MultiSubnet.t.sol +++ b/contracts/test/integration/MultiSubnet.t.sol @@ -25,7 +25,7 @@ import {DiamondCutFacet} from "../../src/diamond/DiamondCutFacet.sol"; import {GatewayMessengerFacet} from "../../src/gateway/GatewayMessengerFacet.sol"; import {DiamondLoupeFacet} from "../../src/diamond/DiamondLoupeFacet.sol"; import {DiamondCutFacet} from "../../src/diamond/DiamondCutFacet.sol"; -import {IntegrationTestBase} from "../IntegrationTestBase.sol"; +import {IntegrationTestBase, RootSubnetDefinition, TestSubnetDefinition} from "../IntegrationTestBase.sol"; import {L2GatewayActorDiamond, L1GatewayActorDiamond} from "../IntegrationTestPresets.sol"; import {TestUtils, MockIpcContract, MockIpcContractPayable, MockIpcContractRevert, MockIpcContractFallback} from "../helpers/TestUtils.sol"; import {FilAddress} from "fevmate/utils/FilAddress.sol"; @@ -35,56 +35,72 @@ import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol"; import {ERC20PresetFixedSupply} from "../helpers/ERC20PresetFixedSupply.sol"; import {IERC20Errors} from "openzeppelin-contracts/interfaces/draft-IERC6093.sol"; +import {GatewayFacetsHelper} from "../helpers/GatewayFacetsHelper.sol"; +import {SubnetActorFacetsHelper} from "../helpers/SubnetActorFacetsHelper.sol"; + import "forge-std/console.sol"; contract MultiSubnetTest is Test, IntegrationTestBase { using SubnetIDHelper for SubnetID; using CrossMsgHelper for IpcEnvelope; + using GatewayFacetsHelper for GatewayDiamond; + using SubnetActorFacetsHelper for SubnetActorDiamond; - GatewayDiamond public rootGateway; - GatewayGetterFacet public rootGatewayGetter; - GatewayManagerFacet public rootGatewayManager; - - SubnetActorDiamond public rootNativeSubnetActor; - SubnetActorDiamond public rootTokenSubnetActor; - - GatewayDiamond public tokenSubnetGateway; - GatewayDiamond public nativeSubnetGateway; - - address[] public nativeSubnetPath; - address[] public tokenSubnetPath; - - SubnetID rootSubnetName; - SubnetID nativeSubnetName; - SubnetID tokenSubnetName; + RootSubnetDefinition public rootSubnet; + TestSubnetDefinition public nativeSubnet; + TestSubnetDefinition public tokenSubnet; IERC20 public token; function setUp() public override { token = new ERC20PresetFixedSupply("TestToken", "TEST", 1_000_000, address(this)); - rootSubnetName = SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}); + SubnetID memory rootSubnetName = SubnetID({root: ROOTNET_CHAINID, route: new address[](0)}); require(rootSubnetName.isRoot(), "not root"); - rootGateway = createGatewayDiamond(gatewayParams(rootSubnetName)); - rootGatewayGetter = GatewayGetterFacet(address(rootGateway)); - rootGatewayManager = GatewayManagerFacet(address(rootGateway)); + GatewayDiamond rootGateway = createGatewayDiamond(gatewayParams(rootSubnetName)); - rootNativeSubnetActor = createSubnetActor(subnetActorWithParams(address(rootGateway), rootSubnetName)); + SubnetActorDiamond rootNativeSubnetActor = createSubnetActor( + defaultSubnetActorParamsWith(address(rootGateway), rootSubnetName) + ); - rootTokenSubnetActor = createSubnetActor( - subnetActorWithParams(address(rootGateway), rootSubnetName, address(token)) + SubnetActorDiamond rootTokenSubnetActor = createSubnetActor( + defaultSubnetActorParamsWith(address(rootGateway), rootSubnetName, address(token)) ); - tokenSubnetPath = new address[](1); + address[] memory tokenSubnetPath = new address[](1); tokenSubnetPath[0] = address(rootTokenSubnetActor); - tokenSubnetName = SubnetID({root: ROOTNET_CHAINID, route: tokenSubnetPath}); - tokenSubnetGateway = createGatewayDiamond(gatewayParams(tokenSubnetName)); + SubnetID memory tokenSubnetName = SubnetID({root: ROOTNET_CHAINID, route: tokenSubnetPath}); + GatewayDiamond tokenSubnetGateway = createGatewayDiamond(gatewayParams(tokenSubnetName)); - nativeSubnetPath = new address[](1); + address[] memory nativeSubnetPath = new address[](1); nativeSubnetPath[0] = address(rootNativeSubnetActor); - nativeSubnetName = SubnetID({root: ROOTNET_CHAINID, route: nativeSubnetPath}); - nativeSubnetGateway = createGatewayDiamond(gatewayParams(nativeSubnetName)); + SubnetID memory nativeSubnetName = SubnetID({root: ROOTNET_CHAINID, route: nativeSubnetPath}); + GatewayDiamond nativeSubnetGateway = createGatewayDiamond(gatewayParams(nativeSubnetName)); + + rootSubnet = RootSubnetDefinition({ + gateway: rootGateway, + gatewayAddr: address(rootGateway), + id: rootSubnetName + }); + + nativeSubnet = TestSubnetDefinition({ + gateway: nativeSubnetGateway, + gatewayAddr: address(nativeSubnetGateway), + id: nativeSubnetName, + subnetActor: rootNativeSubnetActor, + subnetActorAddr: address(rootNativeSubnetActor), + path: nativeSubnetPath + }); + + tokenSubnet = TestSubnetDefinition({ + gateway: tokenSubnetGateway, + gatewayAddr: address(tokenSubnetGateway), + id: tokenSubnetName, + subnetActor: rootTokenSubnetActor, + subnetActorAddr: address(rootTokenSubnetActor), + path: tokenSubnetPath + }); printActors(); } @@ -98,31 +114,31 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContractPayable()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, amount); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); IpcEnvelope memory expected = CrossMsgHelper.createFundMsg( - nativeSubnetName, + nativeSubnet.id, caller, FvmAddressHelper.from(recipient), amount ); vm.prank(caller); - vm.expectEmit(true, true, true, true, address(rootGateway)); - emit LibGateway.NewTopDownMessage(address(rootNativeSubnetActor), expected); - rootGatewayManager.fund{value: amount}(nativeSubnetName, FvmAddressHelper.from(address(recipient))); + vm.expectEmit(true, true, true, true, rootSubnet.gatewayAddr); + emit LibGateway.NewTopDownMessage(nativeSubnet.subnetActorAddr, expected); + rootSubnet.gateway.manager().fund{value: amount}(nativeSubnet.id, FvmAddressHelper.from(address(recipient))); IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = expected; // TODO: commitParentFinality doesn't not affect anything in this test. - commitParentFinality(address(nativeSubnetGateway)); + commitParentFinality(nativeSubnet.gatewayAddr); - executeTopDownMsgs(msgs, nativeSubnetName, address(nativeSubnetGateway)); + executeTopDownMsgs(msgs, nativeSubnet.id, nativeSubnet.gateway); assertEq(recipient.balance, amount); } @@ -135,15 +151,15 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContractPayable()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 0); vm.deal(recipient, 0); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); IpcEnvelope memory crossMsg = CrossMsgHelper.createReleaseMsg( - nativeSubnetName, + nativeSubnet.id, recipient, FvmAddressHelper.from(caller), amount @@ -155,7 +171,7 @@ contract MultiSubnetTest is Test, IntegrationTestBase { IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = resultMsg; - executeTopDownMsgs(msgs, nativeSubnetName, address(nativeSubnetGateway)); + executeTopDownMsgs(msgs, nativeSubnet.id, nativeSubnet.gateway); // works with no state changes assertEq(recipient.balance, 0); @@ -170,13 +186,13 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContractPayable()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); IpcEnvelope memory crossMsg = CrossMsgHelper.createReleaseMsg( - nativeSubnetName, + nativeSubnet.id, caller, FvmAddressHelper.from(recipient), amount @@ -187,7 +203,7 @@ contract MultiSubnetTest is Test, IntegrationTestBase { IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = resultMsg; - executeTopDownMsgs(msgs, nativeSubnetName, address(nativeSubnetGateway)); + executeTopDownMsgs(msgs, nativeSubnet.id, nativeSubnet.gateway); require(caller.balance == amount, "refund not happening"); } @@ -200,13 +216,13 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContractPayable()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); IpcEnvelope memory crossMsg = CrossMsgHelper.createReleaseMsg( - nativeSubnetName, + nativeSubnet.id, caller, FvmAddressHelper.from(recipient), amount @@ -217,7 +233,7 @@ contract MultiSubnetTest is Test, IntegrationTestBase { IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = resultMsg; - executeTopDownMsgs(msgs, nativeSubnetName, address(nativeSubnetGateway)); + executeTopDownMsgs(msgs, nativeSubnet.id, nativeSubnet.gateway); require(caller.balance == amount, "refund not happening"); } @@ -227,32 +243,32 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContractFallback()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, amount); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); IpcEnvelope memory expected = CrossMsgHelper.createFundMsg( - nativeSubnetName, + nativeSubnet.id, caller, FvmAddressHelper.from(recipient), amount ); vm.prank(caller); - vm.expectEmit(true, true, true, true, address(rootGateway)); - emit LibGateway.NewTopDownMessage(address(rootNativeSubnetActor), expected); - rootGatewayManager.fund{value: amount}(nativeSubnetName, FvmAddressHelper.from(address(recipient))); + vm.expectEmit(true, true, true, true, rootSubnet.gatewayAddr); + emit LibGateway.NewTopDownMessage(nativeSubnet.subnetActorAddr, expected); + rootSubnet.gateway.manager().fund{value: amount}(nativeSubnet.id, FvmAddressHelper.from(address(recipient))); IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = expected; // TODO: commitParentFinality doesn't not affect anything in this test. - commitParentFinality(address(nativeSubnetGateway)); + commitParentFinality(nativeSubnet.gatewayAddr); vm.expectRevert(); - executeTopDownMsgsRevert(msgs, tokenSubnetName, address(tokenSubnetGateway)); + executeTopDownMsgsRevert(msgs, nativeSubnet.id, nativeSubnet.gateway); } function testMultiSubnet_Erc20_FundingFromParentToChild() public { @@ -262,32 +278,32 @@ contract MultiSubnetTest is Test, IntegrationTestBase { token.transfer(caller, 100); vm.prank(caller); - token.approve(address(rootGateway), 100); + token.approve(rootSubnet.gatewayAddr, 100); - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, amount); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); IpcEnvelope memory expected = CrossMsgHelper.createFundMsg( - tokenSubnetName, + tokenSubnet.id, caller, FvmAddressHelper.from(recipient), amount ); vm.prank(caller); - vm.expectEmit(true, true, true, true, address(rootGateway)); - emit LibGateway.NewTopDownMessage(address(rootTokenSubnetActor), expected); - rootGatewayManager.fundWithToken(tokenSubnetName, FvmAddressHelper.from(address(recipient)), amount); + vm.expectEmit(true, true, true, true, rootSubnet.gatewayAddr); + emit LibGateway.NewTopDownMessage(tokenSubnet.subnetActorAddr, expected); + rootSubnet.gateway.manager().fundWithToken(tokenSubnet.id, FvmAddressHelper.from(address(recipient)), amount); IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = expected; - commitParentFinality(address(tokenSubnetGateway)); + commitParentFinality(tokenSubnet.gatewayAddr); - executeTopDownMsgs(msgs, tokenSubnetName, address(tokenSubnetGateway)); + executeTopDownMsgs(msgs, tokenSubnet.id, tokenSubnet.gateway); assertEq(recipient.balance, amount); } @@ -299,16 +315,16 @@ contract MultiSubnetTest is Test, IntegrationTestBase { token.transfer(caller, 100); vm.prank(caller); - token.approve(address(rootGateway), 100); + token.approve(rootSubnet.gatewayAddr, 100); - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, amount); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); IpcEnvelope memory crossMsg = CrossMsgHelper.createReleaseMsg( - tokenSubnetName, + tokenSubnet.id, caller, FvmAddressHelper.from(recipient), amount @@ -318,7 +334,7 @@ contract MultiSubnetTest is Test, IntegrationTestBase { IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = resultMsg; - executeTopDownMsgs(msgs, tokenSubnetName, address(tokenSubnetGateway)); + executeTopDownMsgs(msgs, tokenSubnet.id, tokenSubnet.gateway); assertEq(caller.balance, amount); } @@ -330,16 +346,16 @@ contract MultiSubnetTest is Test, IntegrationTestBase { token.transfer(caller, 100); vm.prank(caller); - token.approve(address(rootGateway), 100); + token.approve(rootSubnet.gatewayAddr, 100); - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 0); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); IpcEnvelope memory crossMsg = CrossMsgHelper.createReleaseMsg( - tokenSubnetName, + tokenSubnet.id, caller, FvmAddressHelper.from(recipient), amount @@ -349,7 +365,7 @@ contract MultiSubnetTest is Test, IntegrationTestBase { IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = resultMsg; - executeTopDownMsgs(msgs, tokenSubnetName, address(tokenSubnetGateway)); + executeTopDownMsgs(msgs, tokenSubnet.id, tokenSubnet.gateway); require(caller.balance == amount, "refund should have happened"); } @@ -360,16 +376,16 @@ contract MultiSubnetTest is Test, IntegrationTestBase { token.transfer(caller, 100); vm.prank(caller); - token.approve(address(rootGateway), 100); + token.approve(rootSubnet.gatewayAddr, 100); - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 0); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); IpcEnvelope memory crossMsg = CrossMsgHelper.createReleaseMsg( - tokenSubnetName, + tokenSubnet.id, caller, FvmAddressHelper.from(recipient), amount @@ -379,7 +395,7 @@ contract MultiSubnetTest is Test, IntegrationTestBase { IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = resultMsg; - executeTopDownMsgs(msgs, tokenSubnetName, address(tokenSubnetGateway)); + executeTopDownMsgs(msgs, tokenSubnet.id, tokenSubnet.gateway); require(caller.balance == amount, "refund should have happened"); } @@ -390,33 +406,33 @@ contract MultiSubnetTest is Test, IntegrationTestBase { token.transfer(caller, 100); vm.prank(caller); - token.approve(address(rootGateway), 100); + token.approve(rootSubnet.gatewayAddr, 100); - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, amount); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); IpcEnvelope memory expected = CrossMsgHelper.createFundMsg( - tokenSubnetName, + tokenSubnet.id, caller, FvmAddressHelper.from(recipient), amount ); vm.prank(caller); - vm.expectEmit(true, true, true, true, address(rootGateway)); - emit LibGateway.NewTopDownMessage(address(rootTokenSubnetActor), expected); - rootGatewayManager.fundWithToken(tokenSubnetName, FvmAddressHelper.from(address(recipient)), amount); + vm.expectEmit(true, true, true, true, rootSubnet.gatewayAddr); + emit LibGateway.NewTopDownMessage(tokenSubnet.subnetActorAddr, expected); + rootSubnet.gateway.manager().fundWithToken(tokenSubnet.id, FvmAddressHelper.from(address(recipient)), amount); IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = expected; - commitParentFinality(address(tokenSubnetGateway)); + commitParentFinality(tokenSubnet.gatewayAddr); vm.expectRevert(); - executeTopDownMsgsRevert(msgs, tokenSubnetName, address(tokenSubnetGateway)); + executeTopDownMsgsRevert(msgs, tokenSubnet.id, tokenSubnet.gateway); } //-------------------- @@ -428,26 +444,26 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContractPayable()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); vm.prank(caller); - rootGatewayManager.fund{value: amount}(nativeSubnetName, FvmAddressHelper.from(address(caller))); + rootSubnet.gateway.manager().fund{value: amount}(nativeSubnet.id, FvmAddressHelper.from(address(caller))); - GatewayManagerFacet manager = GatewayManagerFacet(address(nativeSubnetGateway)); + GatewayManagerFacet manager = GatewayManagerFacet(nativeSubnet.gatewayAddr); vm.prank(caller); manager.release{value: amount}(FvmAddressHelper.from(address(recipient))); BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - nativeSubnetName, - address(nativeSubnetGateway) + nativeSubnet.id, + nativeSubnet.gateway ); - submitBottomUpCheckpoint(checkpoint, address(rootNativeSubnetActor)); + submitBottomUpCheckpoint(checkpoint, nativeSubnet.subnetActor); assertEq(recipient.balance, amount); } @@ -459,14 +475,14 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContractPayable()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); IpcEnvelope memory crossMsg = CrossMsgHelper.createFundMsg( - nativeSubnetName, + nativeSubnet.id, caller, FvmAddressHelper.from(recipient), amount @@ -475,15 +491,15 @@ contract MultiSubnetTest is Test, IntegrationTestBase { IpcEnvelope[] memory crossMsgs = new IpcEnvelope[](1); crossMsgs[0] = resultMsg; - GatewayManagerFacet manager = GatewayManagerFacet(address(nativeSubnetGateway)); + GatewayManagerFacet manager = GatewayManagerFacet(nativeSubnet.gatewayAddr); BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - nativeSubnetName, - address(nativeSubnetGateway), + nativeSubnet.id, + nativeSubnet.gateway, crossMsgs ); - submitBottomUpCheckpoint(checkpoint, address(rootNativeSubnetActor)); + submitBottomUpCheckpoint(checkpoint, nativeSubnet.subnetActor); // no change to caller's balance assertEq(caller.balance, 1 ether); @@ -497,19 +513,19 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContractPayable()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); // fund first to provide circulation vm.prank(caller); - rootGatewayManager.fund{value: amount}(nativeSubnetName, FvmAddressHelper.from(address(caller))); + rootSubnet.gateway.manager().fund{value: amount}(nativeSubnet.id, FvmAddressHelper.from(address(caller))); assertEq(caller.balance, 1 ether - amount); IpcEnvelope memory crossMsg = CrossMsgHelper.createFundMsg( - nativeSubnetName, + nativeSubnet.id, caller, FvmAddressHelper.from(recipient), amount @@ -518,15 +534,15 @@ contract MultiSubnetTest is Test, IntegrationTestBase { IpcEnvelope[] memory crossMsgs = new IpcEnvelope[](1); crossMsgs[0] = resultMsg; - GatewayManagerFacet manager = GatewayManagerFacet(address(nativeSubnetGateway)); + GatewayManagerFacet manager = GatewayManagerFacet(nativeSubnet.gatewayAddr); BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - nativeSubnetName, - address(nativeSubnetGateway), + nativeSubnet.id, + nativeSubnet.gateway, crossMsgs ); - submitBottomUpCheckpoint(checkpoint, address(rootNativeSubnetActor)); + submitBottomUpCheckpoint(checkpoint, nativeSubnet.subnetActor); // caller's balance should receive the refund assertEq(caller.balance, 1 ether); @@ -540,15 +556,15 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContractPayable()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); // fund first to provide circulation vm.prank(caller); - rootGatewayManager.fund{value: amount}(nativeSubnetName, FvmAddressHelper.from(address(caller))); + rootSubnet.gateway.manager().fund{value: amount}(nativeSubnet.id, FvmAddressHelper.from(address(caller))); assertEq(caller.balance, 1 ether - amount); // now the fund propagated to the child and execution is Ok @@ -556,7 +572,7 @@ contract MultiSubnetTest is Test, IntegrationTestBase { // and relayer pushed to the parent IpcEnvelope memory crossMsg = CrossMsgHelper.createFundMsg( - nativeSubnetName, + nativeSubnet.id, caller, FvmAddressHelper.from(recipient), amount @@ -565,15 +581,15 @@ contract MultiSubnetTest is Test, IntegrationTestBase { IpcEnvelope[] memory crossMsgs = new IpcEnvelope[](1); crossMsgs[0] = resultMsg; - GatewayManagerFacet manager = GatewayManagerFacet(address(nativeSubnetGateway)); + GatewayManagerFacet manager = GatewayManagerFacet(nativeSubnet.gatewayAddr); BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - nativeSubnetName, - address(nativeSubnetGateway), + nativeSubnet.id, + nativeSubnet.gateway, crossMsgs ); - submitBottomUpCheckpoint(checkpoint, address(rootNativeSubnetActor)); + submitBottomUpCheckpoint(checkpoint, nativeSubnet.subnetActor); // caller's balance should receive the refund assertEq(caller.balance, 1 ether); @@ -584,26 +600,26 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContractFallback()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 6); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); vm.prank(caller); - rootGatewayManager.fund{value: amount}(nativeSubnetName, FvmAddressHelper.from(address(caller))); + rootSubnet.gateway.manager().fund{value: amount}(nativeSubnet.id, FvmAddressHelper.from(address(caller))); - GatewayManagerFacet manager = GatewayManagerFacet(address(nativeSubnetGateway)); + GatewayManagerFacet manager = GatewayManagerFacet(nativeSubnet.gatewayAddr); vm.prank(caller); manager.release{value: amount}(FvmAddressHelper.from(address(recipient))); BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - nativeSubnetName, - address(nativeSubnetGateway) + nativeSubnet.id, + nativeSubnet.gateway ); vm.expectRevert(); - submitBottomUpCheckpointRevert(checkpoint, address(rootNativeSubnetActor)); + submitBottomUpCheckpointRevert(checkpoint, nativeSubnet.subnetActor); } function testMultiSubnet_Native_ReleaseFromChildToParent_DifferentFunderAndSenderInParent() public { @@ -611,25 +627,25 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContractPayable()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 6); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); vm.prank(caller); - rootGatewayManager.fund{value: amount}(nativeSubnetName, FvmAddressHelper.from(address(caller))); + rootSubnet.gateway.manager().fund{value: amount}(nativeSubnet.id, FvmAddressHelper.from(address(caller))); - GatewayManagerFacet manager = GatewayManagerFacet(address(nativeSubnetGateway)); + GatewayManagerFacet manager = GatewayManagerFacet(nativeSubnet.gatewayAddr); vm.prank(caller); manager.release{value: amount}(FvmAddressHelper.from(address(recipient))); BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - nativeSubnetName, - address(nativeSubnetGateway) + nativeSubnet.id, + nativeSubnet.gateway ); - submitBottomUpCheckpoint(checkpoint, address(rootNativeSubnetActor)); + submitBottomUpCheckpoint(checkpoint, nativeSubnet.subnetActor); assertEq(recipient.balance, amount); } @@ -641,16 +657,16 @@ contract MultiSubnetTest is Test, IntegrationTestBase { token.transfer(caller, amount); vm.prank(caller); - token.approve(address(rootGateway), amount); + token.approve(rootSubnet.gatewayAddr, amount); - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); vm.prank(caller); - rootGatewayManager.fundWithToken(tokenSubnetName, FvmAddressHelper.from(address(caller)), amount); + rootSubnet.gateway.manager().fundWithToken(tokenSubnet.id, FvmAddressHelper.from(address(caller)), amount); assertEq(token.balanceOf(caller), 0); // now the fund propagated to the child and execution is Ok @@ -659,7 +675,7 @@ contract MultiSubnetTest is Test, IntegrationTestBase { // simulating the checkpoint pushed from relayer IpcEnvelope memory crossMsg = CrossMsgHelper.createFundMsg( - tokenSubnetName, + tokenSubnet.id, caller, FvmAddressHelper.from(caller), amount @@ -669,12 +685,12 @@ contract MultiSubnetTest is Test, IntegrationTestBase { crossMsgs[0] = resultMsg; BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - tokenSubnetName, - address(tokenSubnetGateway), + tokenSubnet.id, + tokenSubnet.gateway, crossMsgs ); - submitBottomUpCheckpoint(checkpoint, address(rootTokenSubnetActor)); + submitBottomUpCheckpoint(checkpoint, tokenSubnet.subnetActor); // fund works, so fund is still locked, balance is 0 assertEq(token.balanceOf(caller), 0); @@ -687,16 +703,16 @@ contract MultiSubnetTest is Test, IntegrationTestBase { token.transfer(caller, amount); vm.prank(caller); - token.approve(address(rootGateway), amount); + token.approve(rootSubnet.gatewayAddr, amount); - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); vm.prank(caller); - rootGatewayManager.fundWithToken(tokenSubnetName, FvmAddressHelper.from(address(caller)), amount); + rootSubnet.gateway.manager().fundWithToken(tokenSubnet.id, FvmAddressHelper.from(address(caller)), amount); assertEq(token.balanceOf(caller), 0); // now the fund propagated to the child and execution is Ok @@ -705,7 +721,7 @@ contract MultiSubnetTest is Test, IntegrationTestBase { // simulating the checkpoint pushed from relayer IpcEnvelope memory crossMsg = CrossMsgHelper.createFundMsg( - tokenSubnetName, + tokenSubnet.id, caller, FvmAddressHelper.from(caller), amount @@ -715,12 +731,12 @@ contract MultiSubnetTest is Test, IntegrationTestBase { crossMsgs[0] = resultMsg; BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - tokenSubnetName, - address(tokenSubnetGateway), + tokenSubnet.id, + tokenSubnet.gateway, crossMsgs ); - submitBottomUpCheckpoint(checkpoint, address(rootTokenSubnetActor)); + submitBottomUpCheckpoint(checkpoint, tokenSubnet.subnetActor); // fund rejected, so fund should be unlocked assertEq(token.balanceOf(caller), amount); @@ -733,16 +749,16 @@ contract MultiSubnetTest is Test, IntegrationTestBase { token.transfer(caller, amount); vm.prank(caller); - token.approve(address(rootGateway), amount); + token.approve(rootSubnet.gatewayAddr, amount); - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); vm.prank(caller); - rootGatewayManager.fundWithToken(tokenSubnetName, FvmAddressHelper.from(address(caller)), amount); + rootSubnet.gateway.manager().fundWithToken(tokenSubnet.id, FvmAddressHelper.from(address(caller)), amount); assertEq(token.balanceOf(caller), 0); // now the fund propagated to the child and execution is Ok @@ -751,7 +767,7 @@ contract MultiSubnetTest is Test, IntegrationTestBase { // simulating the checkpoint pushed from relayer IpcEnvelope memory crossMsg = CrossMsgHelper.createFundMsg( - tokenSubnetName, + tokenSubnet.id, caller, FvmAddressHelper.from(caller), amount @@ -761,12 +777,12 @@ contract MultiSubnetTest is Test, IntegrationTestBase { crossMsgs[0] = resultMsg; BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - tokenSubnetName, - address(tokenSubnetGateway), + tokenSubnet.id, + tokenSubnet.gateway, crossMsgs ); - submitBottomUpCheckpoint(checkpoint, address(rootTokenSubnetActor)); + submitBottomUpCheckpoint(checkpoint, tokenSubnet.subnetActor); // fund rejected, so fund should be unlocked assertEq(token.balanceOf(caller), amount); @@ -779,27 +795,27 @@ contract MultiSubnetTest is Test, IntegrationTestBase { token.transfer(caller, amount); vm.prank(caller); - token.approve(address(rootGateway), amount); + token.approve(rootSubnet.gatewayAddr, amount); - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); vm.prank(caller); - rootGatewayManager.fundWithToken(tokenSubnetName, FvmAddressHelper.from(address(caller)), amount); + rootSubnet.gateway.manager().fundWithToken(tokenSubnet.id, FvmAddressHelper.from(address(caller)), amount); - GatewayManagerFacet manager = GatewayManagerFacet(address(tokenSubnetGateway)); + GatewayManagerFacet manager = tokenSubnet.gateway.manager(); vm.prank(caller); manager.release{value: amount}(FvmAddressHelper.from(address(recipient))); BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - tokenSubnetName, - address(tokenSubnetGateway) + tokenSubnet.id, + tokenSubnet.gateway ); - submitBottomUpCheckpoint(checkpoint, address(rootTokenSubnetActor)); + submitBottomUpCheckpoint(checkpoint, tokenSubnet.subnetActor); assertEq(token.balanceOf(recipient), amount); } @@ -811,27 +827,27 @@ contract MultiSubnetTest is Test, IntegrationTestBase { token.transfer(caller, amount); vm.prank(caller); - token.approve(address(rootGateway), amount); + token.approve(rootSubnet.gatewayAddr, amount); - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); vm.prank(caller); - rootGatewayManager.fundWithToken(tokenSubnetName, FvmAddressHelper.from(address(caller)), amount); + rootSubnet.gateway.manager().fundWithToken(tokenSubnet.id, FvmAddressHelper.from(address(caller)), amount); - GatewayManagerFacet manager = GatewayManagerFacet(address(tokenSubnetGateway)); + GatewayManagerFacet manager = tokenSubnet.gateway.manager(); vm.prank(caller); manager.release{value: amount}(FvmAddressHelper.from(address(recipient))); BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - tokenSubnetName, - address(tokenSubnetGateway) + tokenSubnet.id, + tokenSubnet.gateway ); - submitBottomUpCheckpoint(checkpoint, address(rootTokenSubnetActor)); + submitBottomUpCheckpoint(checkpoint, tokenSubnet.subnetActor); assertEq(token.balanceOf(recipient), amount); assertEq(recipient.balance, 0); } @@ -847,25 +863,28 @@ contract MultiSubnetTest is Test, IntegrationTestBase { uint256 initialBalance = 1 ether; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, initialBalance); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); - require(address(rootGatewayManager).balance == initialBalance, "initial balance not correct"); + require(rootSubnet.gatewayAddr.balance == initialBalance, "initial balance not correct"); uint256 fundToSend = 100000; vm.prank(caller); - rootGatewayManager.fund{value: fundToSend}(nativeSubnetName, FvmAddressHelper.from(address(caller))); + rootSubnet.gateway.manager().fund{value: fundToSend}(nativeSubnet.id, FvmAddressHelper.from(address(caller))); - require(address(rootGatewayManager).balance == initialBalance + fundToSend, "fund not locked in gateway"); + require( + address(rootSubnet.gateway.manager()).balance == initialBalance + fundToSend, + "fund not locked in gateway" + ); // a cross network message from parent caller to child recipient IpcEnvelope memory crossMsg = TestUtils.newXnetCallMsg( - IPCAddress({subnetId: rootSubnetName, rawAddress: FvmAddressHelper.from(caller)}), - IPCAddress({subnetId: nativeSubnetName, rawAddress: FvmAddressHelper.from(recipient)}), + IPCAddress({subnetId: rootSubnet.id, rawAddress: FvmAddressHelper.from(caller)}), + IPCAddress({subnetId: nativeSubnet.id, rawAddress: FvmAddressHelper.from(recipient)}), amount, 0 ); @@ -876,8 +895,8 @@ contract MultiSubnetTest is Test, IntegrationTestBase { crossMsgs[0] = resultMsg; BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - nativeSubnetName, - address(nativeSubnetGateway), + nativeSubnet.id, + nativeSubnet.gateway, crossMsgs ); @@ -887,10 +906,10 @@ contract MultiSubnetTest is Test, IntegrationTestBase { // call made to `handleIpcMessage`, we should make sure: // 1. The submission of checkpoint is never blocked // 2. The fund is locked in the gateway as execution is rejected - submitBottomUpCheckpoint(checkpoint, address(rootNativeSubnetActor)); + submitBottomUpCheckpoint(checkpoint, nativeSubnet.subnetActor); require( - address(rootGatewayManager).balance == initialBalance + fundToSend, + address(rootSubnet.gateway.manager()).balance == initialBalance + fundToSend, "fund should still be locked in gateway" ); require(caller.balance == initialBalance - fundToSend, "fund should still be locked in gateway"); @@ -901,32 +920,32 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContract()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); vm.prank(caller); - rootGatewayManager.fund{value: 100000}(nativeSubnetName, FvmAddressHelper.from(address(caller))); + rootSubnet.gateway.manager().fund{value: 100000}(nativeSubnet.id, FvmAddressHelper.from(address(caller))); - GatewayMessengerFacet messenger = GatewayMessengerFacet(address(nativeSubnetGateway)); + GatewayMessengerFacet messenger = nativeSubnet.gateway.messenger(); vm.prank(address(caller)); messenger.sendContractXnetMessage{value: amount}( TestUtils.newXnetCallMsg( - IPCAddress({subnetId: nativeSubnetName, rawAddress: FvmAddressHelper.from(caller)}), - IPCAddress({subnetId: rootSubnetName, rawAddress: FvmAddressHelper.from(recipient)}), + IPCAddress({subnetId: nativeSubnet.id, rawAddress: FvmAddressHelper.from(caller)}), + IPCAddress({subnetId: rootSubnet.id, rawAddress: FvmAddressHelper.from(recipient)}), amount, 0 ) ); BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - nativeSubnetName, - address(nativeSubnetGateway) + nativeSubnet.id, + nativeSubnet.gateway ); - submitBottomUpCheckpoint(checkpoint, address(rootNativeSubnetActor)); + submitBottomUpCheckpoint(checkpoint, nativeSubnet.subnetActor); assertEq(recipient.balance, amount); } @@ -936,42 +955,41 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContract()); uint256 amount = 3; - vm.deal(address(rootNativeSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(nativeSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); - vm.prank(address(rootNativeSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootNativeSubnetActor), rootGateway); + vm.prank(nativeSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, nativeSubnet.subnetActorAddr, rootSubnet.gateway); vm.prank(caller); - rootGatewayManager.fund{value: 100000}(nativeSubnetName, FvmAddressHelper.from(address(caller))); + rootSubnet.gateway.manager().fund{value: 100000}(nativeSubnet.id, FvmAddressHelper.from(address(caller))); IpcEnvelope memory xnetCallMsg = TestUtils.newXnetCallMsg( - IPCAddress({subnetId: rootSubnetName, rawAddress: FvmAddressHelper.from(caller)}), - IPCAddress({subnetId: nativeSubnetName, rawAddress: FvmAddressHelper.from(recipient)}), + IPCAddress({subnetId: rootSubnet.id, rawAddress: FvmAddressHelper.from(caller)}), + IPCAddress({subnetId: nativeSubnet.id, rawAddress: FvmAddressHelper.from(recipient)}), amount, 0 ); IpcEnvelope memory committedEvent = IpcEnvelope({ kind: IpcMsgKind.Call, - from: IPCAddress({subnetId: rootSubnetName, rawAddress: FvmAddressHelper.from(caller)}), + from: IPCAddress({subnetId: rootSubnet.id, rawAddress: FvmAddressHelper.from(caller)}), to: xnetCallMsg.to, value: xnetCallMsg.value, message: xnetCallMsg.message, nonce: 1 }); - GatewayMessengerFacet rootGatewayMessenger = GatewayMessengerFacet(address(rootGateway)); vm.prank(address(caller)); - vm.expectEmit(true, true, true, true, address(rootGateway)); - emit LibGateway.NewTopDownMessage({subnet: address(rootNativeSubnetActor), message: committedEvent}); - rootGatewayMessenger.sendContractXnetMessage{value: amount}(xnetCallMsg); + vm.expectEmit(true, true, true, true, rootSubnet.gatewayAddr); + emit LibGateway.NewTopDownMessage({subnet: nativeSubnet.subnetActorAddr, message: committedEvent}); + rootSubnet.gateway.messenger().sendContractXnetMessage{value: amount}(xnetCallMsg); IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = xnetCallMsg; - commitParentFinality(address(nativeSubnetGateway)); - executeTopDownMsgs(msgs, nativeSubnetName, address(nativeSubnetGateway)); + commitParentFinality(nativeSubnet.gatewayAddr); + executeTopDownMsgs(msgs, nativeSubnet.id, nativeSubnet.gateway); assertEq(address(recipient).balance, amount); } @@ -981,7 +999,7 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContractRevert()); uint256 amount = 3; - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); uint256 balance = 100; @@ -989,22 +1007,22 @@ contract MultiSubnetTest is Test, IntegrationTestBase { // Fund an account in the subnet. token.transfer(caller, balance); vm.prank(caller); - token.approve(address(rootGateway), balance); + token.approve(rootSubnet.gatewayAddr, balance); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); uint256 fundToSend = 10; vm.prank(caller); - rootGatewayManager.fundWithToken(tokenSubnetName, FvmAddressHelper.from(address(caller)), fundToSend); + rootSubnet.gateway.manager().fundWithToken(tokenSubnet.id, FvmAddressHelper.from(address(caller)), fundToSend); - require(token.balanceOf(address(rootGatewayManager)) == fundToSend, "initial balance not correct"); + require(token.balanceOf(address(rootSubnet.gateway.manager())) == fundToSend, "initial balance not correct"); // a cross network message from parent caller to child recipient IpcEnvelope memory crossMsg = TestUtils.newXnetCallMsg( - IPCAddress({subnetId: rootSubnetName, rawAddress: FvmAddressHelper.from(caller)}), - IPCAddress({subnetId: tokenSubnetName, rawAddress: FvmAddressHelper.from(recipient)}), + IPCAddress({subnetId: rootSubnet.id, rawAddress: FvmAddressHelper.from(caller)}), + IPCAddress({subnetId: tokenSubnet.id, rawAddress: FvmAddressHelper.from(recipient)}), amount, 0 ); @@ -1016,8 +1034,8 @@ contract MultiSubnetTest is Test, IntegrationTestBase { crossMsgs[0] = resultMsg; BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - tokenSubnetName, - address(tokenSubnetGateway), + tokenSubnet.id, + tokenSubnet.gateway, crossMsgs ); @@ -1027,9 +1045,12 @@ contract MultiSubnetTest is Test, IntegrationTestBase { // call made to `handleIpcMessage`, we should make sure: // 1. The submission of checkpoint is never blocked // 2. The fund is locked in the gateway as execution is rejected - submitBottomUpCheckpoint(checkpoint, address(rootTokenSubnetActor)); + submitBottomUpCheckpoint(checkpoint, tokenSubnet.subnetActor); - require(token.balanceOf(address(rootGatewayManager)) == fundToSend, "fund should still be locked in gateway"); + require( + token.balanceOf(address(rootSubnet.gateway.manager())) == fundToSend, + "fund should still be locked in gateway" + ); require(token.balanceOf(caller) == balance - fundToSend, "fund should still be locked in gateway"); } @@ -1038,37 +1059,37 @@ contract MultiSubnetTest is Test, IntegrationTestBase { address recipient = address(new MockIpcContract()); uint256 amount = 3; - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(address(token), DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 1 ether); // Fund an account in the subnet. token.transfer(caller, 100); vm.prank(caller); - token.approve(address(rootGateway), 100); + token.approve(rootSubnet.gatewayAddr, 100); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); vm.prank(caller); - rootGatewayManager.fundWithToken(tokenSubnetName, FvmAddressHelper.from(address(caller)), 15); + rootSubnet.gateway.manager().fundWithToken(tokenSubnet.id, FvmAddressHelper.from(address(caller)), 15); - IPCAddress memory from = IPCAddress({subnetId: tokenSubnetName, rawAddress: FvmAddressHelper.from(caller)}); - IPCAddress memory to = IPCAddress({subnetId: rootSubnetName, rawAddress: FvmAddressHelper.from(recipient)}); + IPCAddress memory from = IPCAddress({subnetId: tokenSubnet.id, rawAddress: FvmAddressHelper.from(caller)}); + IPCAddress memory to = IPCAddress({subnetId: rootSubnet.id, rawAddress: FvmAddressHelper.from(recipient)}); bytes4 method = bytes4(0x11223344); bytes memory params = bytes("hello"); IpcEnvelope memory envelope = CrossMsgHelper.createCallMsg(from, to, amount, method, params); - GatewayMessengerFacet messenger = GatewayMessengerFacet(address(tokenSubnetGateway)); + GatewayMessengerFacet messenger = tokenSubnet.gateway.messenger(); vm.prank(address(caller)); messenger.sendContractXnetMessage{value: amount}(envelope); BottomUpCheckpoint memory checkpoint = callCreateBottomUpCheckpointFromChildSubnet( - tokenSubnetName, - address(tokenSubnetGateway) + tokenSubnet.id, + tokenSubnet.gateway ); - submitBottomUpCheckpoint(checkpoint, address(rootTokenSubnetActor)); + submitBottomUpCheckpoint(checkpoint, tokenSubnet.subnetActor); assertEq(token.balanceOf(recipient), amount); } @@ -1080,44 +1101,43 @@ contract MultiSubnetTest is Test, IntegrationTestBase { token.transfer(caller, 100); vm.prank(caller); - token.approve(address(rootGateway), 100); + token.approve(rootSubnet.gatewayAddr, 100); - vm.deal(address(rootTokenSubnetActor), DEFAULT_COLLATERAL_AMOUNT); + vm.deal(tokenSubnet.subnetActorAddr, DEFAULT_COLLATERAL_AMOUNT); vm.deal(caller, 3); - vm.prank(address(rootTokenSubnetActor)); - registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, address(rootTokenSubnetActor), rootGateway); + vm.prank(tokenSubnet.subnetActorAddr); + registerSubnetGW(DEFAULT_COLLATERAL_AMOUNT, tokenSubnet.subnetActorAddr, rootSubnet.gateway); vm.prank(caller); - rootGatewayManager.fundWithToken(tokenSubnetName, FvmAddressHelper.from(address(caller)), 15); + rootSubnet.gateway.manager().fundWithToken(tokenSubnet.id, FvmAddressHelper.from(address(caller)), 15); IpcEnvelope memory xnetCallMsg = TestUtils.newXnetCallMsg( - IPCAddress({subnetId: rootSubnetName, rawAddress: FvmAddressHelper.from(caller)}), - IPCAddress({subnetId: tokenSubnetName, rawAddress: FvmAddressHelper.from(recipient)}), + IPCAddress({subnetId: rootSubnet.id, rawAddress: FvmAddressHelper.from(caller)}), + IPCAddress({subnetId: tokenSubnet.id, rawAddress: FvmAddressHelper.from(recipient)}), amount, 0 ); IpcEnvelope memory committedEvent = IpcEnvelope({ kind: IpcMsgKind.Call, - from: IPCAddress({subnetId: rootSubnetName, rawAddress: FvmAddressHelper.from(caller)}), + from: IPCAddress({subnetId: rootSubnet.id, rawAddress: FvmAddressHelper.from(caller)}), to: xnetCallMsg.to, value: xnetCallMsg.value, message: xnetCallMsg.message, nonce: 1 }); - GatewayMessengerFacet rootGatewayMessenger = GatewayMessengerFacet(address(rootGateway)); vm.prank(address(caller)); - vm.expectEmit(true, true, true, true, address(rootGateway)); - emit LibGateway.NewTopDownMessage({subnet: address(rootTokenSubnetActor), message: committedEvent}); - rootGatewayMessenger.sendContractXnetMessage{value: amount}(xnetCallMsg); + vm.expectEmit(true, true, true, true, rootSubnet.gatewayAddr); + emit LibGateway.NewTopDownMessage({subnet: tokenSubnet.subnetActorAddr, message: committedEvent}); + rootSubnet.gateway.messenger().sendContractXnetMessage{value: amount}(xnetCallMsg); IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = xnetCallMsg; - commitParentFinality(address(tokenSubnetGateway)); - executeTopDownMsgs(msgs, tokenSubnetName, address(tokenSubnetGateway)); + commitParentFinality(tokenSubnet.gatewayAddr); + executeTopDownMsgs(msgs, tokenSubnet.id, tokenSubnet.gateway); assertEq(address(recipient).balance, amount); } @@ -1132,8 +1152,8 @@ contract MultiSubnetTest is Test, IntegrationTestBase { gwTopDownFinalityFacet.commitParentFinality(finality); } - function executeTopDownMsgs(IpcEnvelope[] memory msgs, SubnetID memory subnet, address gateway) internal { - XnetMessagingFacet xnet = XnetMessagingFacet(address(gateway)); + function executeTopDownMsgs(IpcEnvelope[] memory msgs, SubnetID memory subnet, GatewayDiamond gw) internal { + XnetMessagingFacet messenger = gw.xnetMessenger(); uint256 minted_tokens; @@ -1149,27 +1169,27 @@ contract MultiSubnetTest is Test, IntegrationTestBase { // https://github.com/consensus-shipyard/ipc/blob/main/fendermint/vm/interpreter/src/fvm/topdown.rs#L43 // This emulates minting tokens. - vm.deal(address(gateway), minted_tokens); + vm.deal(address(gw), minted_tokens); // TODO: how to emulate increase of circulation supply? vm.prank(FilAddress.SYSTEM_ACTOR); - xnet.applyCrossMessages(msgs); + messenger.applyCrossMessages(msgs); } - function executeTopDownMsgsRevert(IpcEnvelope[] memory msgs, SubnetID memory subnet, address gateway) internal { + function executeTopDownMsgsRevert(IpcEnvelope[] memory msgs, SubnetID memory subnet, GatewayDiamond gw) internal { vm.expectRevert(); - executeTopDownMsgs(msgs, subnet, gateway); + executeTopDownMsgs(msgs, subnet, gw); } function callCreateBottomUpCheckpointFromChildSubnet( SubnetID memory subnet, - address gateway + GatewayDiamond gw ) internal returns (BottomUpCheckpoint memory checkpoint) { uint256 e = getNextEpoch(block.number, DEFAULT_CHECKPOINT_PERIOD); - GatewayGetterFacet getter = GatewayGetterFacet(address(gateway)); - CheckpointingFacet checkpointer = CheckpointingFacet(address(gateway)); + GatewayGetterFacet getter = gw.getter(); + CheckpointingFacet checkpointer = gw.checkpointer(); BottomUpMsgBatch memory batch = getter.bottomUpMsgBatch(e); require(batch.msgs.length == 1, "batch length incorrect"); @@ -1195,13 +1215,13 @@ contract MultiSubnetTest is Test, IntegrationTestBase { function callCreateBottomUpCheckpointFromChildSubnet( SubnetID memory subnet, - address gateway, + GatewayDiamond gw, IpcEnvelope[] memory msgs ) internal returns (BottomUpCheckpoint memory checkpoint) { uint256 e = getNextEpoch(block.number, DEFAULT_CHECKPOINT_PERIOD); - GatewayGetterFacet getter = GatewayGetterFacet(address(gateway)); - CheckpointingFacet checkpointer = CheckpointingFacet(address(gateway)); + GatewayGetterFacet getter = gw.getter(); + CheckpointingFacet checkpointer = gw.checkpointer(); (, address[] memory addrs, uint256[] memory weights) = TestUtils.getFourValidators(vm); @@ -1222,12 +1242,12 @@ contract MultiSubnetTest is Test, IntegrationTestBase { return checkpoint; } - function submitBottomUpCheckpoint(BottomUpCheckpoint memory checkpoint, address subnetActor) internal { + function submitBottomUpCheckpoint(BottomUpCheckpoint memory checkpoint, SubnetActorDiamond sa) internal { (uint256[] memory parentKeys, address[] memory parentValidators, ) = TestUtils.getThreeValidators(vm); bytes[] memory parentPubKeys = new bytes[](3); bytes[] memory parentSignatures = new bytes[](3); - SubnetActorManagerFacet manager = SubnetActorManagerFacet(subnetActor); + SubnetActorManagerFacet manager = sa.manager(); for (uint256 i = 0; i < 3; i++) { vm.deal(parentValidators[i], 10 gwei); @@ -1243,16 +1263,16 @@ contract MultiSubnetTest is Test, IntegrationTestBase { parentSignatures[i] = abi.encodePacked(r, s, v); } - SubnetActorCheckpointingFacet checkpointer = SubnetActorCheckpointingFacet(subnetActor); + SubnetActorCheckpointingFacet checkpointer = sa.checkpointer(); - vm.startPrank(subnetActor); + vm.startPrank(address(sa)); checkpointer.submitCheckpoint(checkpoint, parentValidators, parentSignatures); vm.stopPrank(); } - function submitBottomUpCheckpointRevert(BottomUpCheckpoint memory checkpoint, address subnetActor) internal { + function submitBottomUpCheckpointRevert(BottomUpCheckpoint memory checkpoint, SubnetActorDiamond sa) internal { vm.expectRevert(); - submitBottomUpCheckpoint(checkpoint, subnetActor); + submitBottomUpCheckpoint(checkpoint, sa); } function getNextEpoch(uint256 blockNumber, uint256 checkPeriod) internal pure returns (uint256) { @@ -1260,18 +1280,18 @@ contract MultiSubnetTest is Test, IntegrationTestBase { } function printActors() internal view { - console.log("root gateway: %s", address(rootGateway)); - console.log("root actor: %s", rootSubnetName.getActor()); - console.log("root native subnet actor: %s", (address(rootNativeSubnetActor))); - console.log("root token subnet actor: %s", (address(rootTokenSubnetActor))); - console.log("root name: %s", rootSubnetName.toString()); - console.log("native subnet name: %s", nativeSubnetName.toString()); - console.log("token subnet name: %s", tokenSubnetName.toString()); - console.log("native subnet getActor(): %s", address(nativeSubnetName.getActor())); - console.log("native subnet gateway(): %s", address(nativeSubnetGateway)); + console.log("root gateway: %s", rootSubnet.gatewayAddr); + console.log("root actor: %s", rootSubnet.id.getActor()); + console.log("root native subnet actor: %s", (nativeSubnet.subnetActorAddr)); + console.log("root token subnet actor: %s", (tokenSubnet.subnetActorAddr)); + console.log("root name: %s", rootSubnet.id.toString()); + console.log("native subnet name: %s", nativeSubnet.id.toString()); + console.log("token subnet name: %s", tokenSubnet.id.toString()); + console.log("native subnet getActor(): %s", address(nativeSubnet.id.getActor())); + console.log("native subnet gateway(): %s", nativeSubnet.gatewayAddr); } - function printEnvelope(IpcEnvelope memory envelope) internal { + function printEnvelope(IpcEnvelope memory envelope) internal view { console.log("from %s:", envelope.from.subnetId.toString()); console.log("to %s:", envelope.to.subnetId.toString()); } diff --git a/contracts/test/integration/SubnetActorDiamond.t.sol b/contracts/test/integration/SubnetActorDiamond.t.sol index adbe8403d..e74f2e5b4 100644 --- a/contracts/test/integration/SubnetActorDiamond.t.sol +++ b/contracts/test/integration/SubnetActorDiamond.t.sol @@ -21,6 +21,7 @@ import {IDiamondLoupe} from "../../src/interfaces/IDiamondLoupe.sol"; import {FvmAddressHelper} from "../../src/lib/FvmAddressHelper.sol"; import {MultisignatureChecker} from "../../src/lib/LibMultisignatureChecker.sol"; import {SubnetIDHelper} from "../../src/lib/SubnetIDHelper.sol"; +import {GatewayDiamond} from "../../src/GatewayDiamond.sol"; import {SubnetActorDiamond, FunctionNotFound} from "../../src/SubnetActorDiamond.sol"; import {SubnetActorManagerFacet} from "../../src/subnet/SubnetActorManagerFacet.sol"; import {SubnetActorGetterFacet} from "../../src/subnet/SubnetActorGetterFacet.sol"; @@ -36,10 +37,15 @@ import {SupplySourceHelper} from "../../src/lib/SupplySourceHelper.sol"; import {IntegrationTestBase} from "../IntegrationTestBase.sol"; +import {SubnetActorFacetsHelper} from "../helpers/SubnetActorFacetsHelper.sol"; +import {GatewayFacetsHelper} from "../helpers/GatewayFacetsHelper.sol"; + contract SubnetActorDiamondTest is Test, IntegrationTestBase { using SubnetIDHelper for SubnetID; using FilAddress for address; using FvmAddressHelper for FvmAddress; + using SubnetActorFacetsHelper for SubnetActorDiamond; + using GatewayFacetsHelper for GatewayDiamond; address gatewayAddress; @@ -51,27 +57,37 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { function testSubnetActorDiamond_NewSubnetActorWithDefaultParams() public view { SubnetID memory _parentId = SubnetID(ROOTNET_CHAINID, new address[](0)); - SubnetActorDiamond.ConstructorParams memory params = defaultSubnetActorParamsWithGateway( - address(gatewayDiamond) - ); + SubnetActorDiamond.ConstructorParams memory params = defaultSubnetActorParamsWith(address(gatewayDiamond)); - require(saGetter.ipcGatewayAddr() == params.ipcGatewayAddr, "unexpected gateway"); - require(saGetter.minActivationCollateral() == params.minActivationCollateral, "unexpected collateral"); - require(saGetter.minValidators() == params.minValidators, "unexpected minValidators"); - require(saGetter.consensus() == params.consensus, "unexpected consensus"); - require(saGetter.getParent().equals(_parentId), "unexpected parent"); - require(saGetter.activeValidatorsLimit() == 100, "unexpected activeValidatorsLimit"); - require(saGetter.powerScale() == params.powerScale, "unexpected powerscale"); - require(saGetter.bottomUpCheckPeriod() == params.bottomUpCheckPeriod, "unexpected bottom-up period"); - require(saGetter.majorityPercentage() == params.majorityPercentage, "unexpected majority percentage"); - require(saGetter.getParent().toHash() == _parentId.toHash(), "unexpected parent subnetID hash"); + require(saDiamond.getter().ipcGatewayAddr() == params.ipcGatewayAddr, "unexpected gateway"); + require( + saDiamond.getter().minActivationCollateral() == params.minActivationCollateral, + "unexpected collateral" + ); + require(saDiamond.getter().minValidators() == params.minValidators, "unexpected minValidators"); + require(saDiamond.getter().consensus() == params.consensus, "unexpected consensus"); + require(saDiamond.getter().getParent().equals(_parentId), "unexpected parent"); + require(saDiamond.getter().activeValidatorsLimit() == 100, "unexpected activeValidatorsLimit"); + require(saDiamond.getter().powerScale() == params.powerScale, "unexpected powerscale"); + require(saDiamond.getter().bottomUpCheckPeriod() == params.bottomUpCheckPeriod, "unexpected bottom-up period"); + require(saDiamond.getter().majorityPercentage() == params.majorityPercentage, "unexpected majority percentage"); + require(saDiamond.getter().getParent().toHash() == _parentId.toHash(), "unexpected parent subnetID hash"); } function testSubnetActorDiamondReal_LoupeFunction() public view { - require(saLouper.facets().length == 7, "unexpected length"); - require(saLouper.supportsInterface(type(IERC165).interfaceId) == true, "IERC165 not supported"); - require(saLouper.supportsInterface(type(IDiamondCut).interfaceId) == true, "IDiamondCut not supported"); - require(saLouper.supportsInterface(type(IDiamondLoupe).interfaceId) == true, "IDiamondLoupe not supported"); + require(saDiamond.diamondLouper().facets().length == 7, "unexpected length"); + require( + saDiamond.diamondLouper().supportsInterface(type(IERC165).interfaceId) == true, + "IERC165 not supported" + ); + require( + saDiamond.diamondLouper().supportsInterface(type(IDiamondCut).interfaceId) == true, + "IDiamondCut not supported" + ); + require( + saDiamond.diamondLouper().supportsInterface(type(IDiamondLoupe).interfaceId) == true, + "IDiamondLoupe not supported" + ); } /// @notice Testing the basic join, stake, leave lifecycle of validators @@ -84,11 +100,11 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { uint256 stake = 10; uint256 validator1Stake = 10 * DEFAULT_MIN_VALIDATOR_STAKE; - require(!saGetter.isActiveValidator(validator1), "active validator1"); - require(!saGetter.isWaitingValidator(validator1), "waiting validator1"); + require(!saDiamond.getter().isActiveValidator(validator1), "active validator1"); + require(!saDiamond.getter().isWaitingValidator(validator1), "waiting validator1"); - require(!saGetter.isActiveValidator(validator2), "active validator2"); - require(!saGetter.isWaitingValidator(validator2), "waiting validator2"); + require(!saDiamond.getter().isActiveValidator(validator2), "active validator2"); + require(!saDiamond.getter().isWaitingValidator(validator2), "waiting validator2"); // ======== Step. Join ====== // initial validator joins @@ -96,25 +112,25 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.deal(validator2, DEFAULT_MIN_VALIDATOR_STAKE); vm.startPrank(validator1); - saManager.join{value: validator1Stake}(publicKey1); + saDiamond.manager().join{value: validator1Stake}(publicKey1); collateral = validator1Stake; require(gatewayAddress.balance == collateral, "gw balance is incorrect after validator1 joining"); // collateral confirmed immediately and network boostrapped - ValidatorInfo memory v = saGetter.getValidator(validator1); + ValidatorInfo memory v = saDiamond.getter().getValidator(validator1); require(v.totalCollateral == collateral, "total collateral not expected"); require(v.confirmedCollateral == collateral, "confirmed collateral not equal to collateral"); - require(saGetter.isActiveValidator(validator1), "not active validator 1"); - require(!saGetter.isWaitingValidator(validator1), "waiting validator 1"); - require(!saGetter.isActiveValidator(validator2), "active validator2"); - require(!saGetter.isWaitingValidator(validator2), "waiting validator2"); + require(saDiamond.getter().isActiveValidator(validator1), "not active validator 1"); + require(!saDiamond.getter().isWaitingValidator(validator1), "waiting validator 1"); + require(!saDiamond.getter().isActiveValidator(validator2), "active validator2"); + require(!saDiamond.getter().isWaitingValidator(validator2), "waiting validator2"); TestUtils.ensureBytesEqual(v.metadata, publicKey1); - require(saGetter.bootstrapped(), "subnet not bootstrapped"); - require(!saGetter.killed(), "subnet killed"); - require(saGetter.genesisValidators().length == 1, "not one validator in genesis"); + require(saDiamond.getter().bootstrapped(), "subnet not bootstrapped"); + require(!saDiamond.getter().killed(), "subnet killed"); + require(saDiamond.getter().genesisValidators().length == 1, "not one validator in genesis"); - (uint64 nextConfigNum, uint64 startConfigNum) = saGetter.getConfigurationNumbers(); + (uint64 nextConfigNum, uint64 startConfigNum) = saDiamond.getter().getConfigurationNumbers(); require(nextConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER, "next config num not 1"); require(startConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER, "start config num not 1"); @@ -123,20 +139,20 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { // subnet bootstrapped and should go through queue // second and third validators join vm.startPrank(validator2); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey2); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey2); // collateral not confirmed yet - v = saGetter.getValidator(validator2); + v = saDiamond.getter().getValidator(validator2); require(gatewayAddress.balance == collateral, "gw balance is incorrect after validator2 joining"); require(v.totalCollateral == DEFAULT_MIN_VALIDATOR_STAKE, "total collateral not expected"); require(v.confirmedCollateral == 0, "confirmed collateral not equal to collateral"); - require(saGetter.isActiveValidator(validator1), "not active validator 1"); - require(!saGetter.isWaitingValidator(validator1), "waiting validator 1"); - require(!saGetter.isActiveValidator(validator2), "active validator2"); - require(!saGetter.isWaitingValidator(validator2), "waiting validator2"); + require(saDiamond.getter().isActiveValidator(validator1), "not active validator 1"); + require(!saDiamond.getter().isWaitingValidator(validator1), "waiting validator 1"); + require(!saDiamond.getter().isActiveValidator(validator2), "active validator2"); + require(!saDiamond.getter().isWaitingValidator(validator2), "waiting validator2"); TestUtils.ensureBytesEqual(v.metadata, new bytes(0)); - (nextConfigNum, startConfigNum) = saGetter.getConfigurationNumbers(); + (nextConfigNum, startConfigNum) = saDiamond.getter().getConfigurationNumbers(); // join will update the metadata, incr by 1 // join will call deposit, incr by 1 require(nextConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER + 2, "next config num not 3"); @@ -148,18 +164,18 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { confirmChange(validator1, privKey1); require(gatewayAddress.balance == collateral, "gw balance is incorrect after validator2 joining"); - v = saGetter.getValidator(validator2); + v = saDiamond.getter().getValidator(validator2); require(v.totalCollateral == DEFAULT_MIN_VALIDATOR_STAKE, "unexpected total collateral after confirm join"); require( v.confirmedCollateral == DEFAULT_MIN_VALIDATOR_STAKE, "unexpected confirmed collateral after confirm join" ); - require(saGetter.isActiveValidator(validator1), "not active validator1"); - require(!saGetter.isWaitingValidator(validator1), "waiting validator1"); - require(saGetter.isActiveValidator(validator2), "not active validator2"); - require(!saGetter.isWaitingValidator(validator2), "waiting validator2"); + require(saDiamond.getter().isActiveValidator(validator1), "not active validator1"); + require(!saDiamond.getter().isWaitingValidator(validator1), "waiting validator1"); + require(saDiamond.getter().isActiveValidator(validator2), "not active validator2"); + require(!saDiamond.getter().isWaitingValidator(validator2), "waiting validator2"); - (nextConfigNum, startConfigNum) = saGetter.getConfigurationNumbers(); + (nextConfigNum, startConfigNum) = saDiamond.getter().getConfigurationNumbers(); require( nextConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER + 2, "next config num not 3 after confirm join" @@ -173,14 +189,14 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.startPrank(validator1); vm.deal(validator1, stake); - saManager.stake{value: stake}(); + saDiamond.manager().stake{value: stake}(); - v = saGetter.getValidator(validator1); + v = saDiamond.getter().getValidator(validator1); require(v.totalCollateral == validator1Stake + stake, "unexpected total collateral after stake"); require(v.confirmedCollateral == validator1Stake, "unexpected confirmed collateral after stake"); require(gatewayAddress.balance == collateral, "gw balance is incorrect after validator1 stakes more"); - (nextConfigNum, startConfigNum) = saGetter.getConfigurationNumbers(); + (nextConfigNum, startConfigNum) = saDiamond.getter().getConfigurationNumbers(); require(nextConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER + 3, "next config num not 4 after stake"); require(startConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER + 2, "start config num not 3 after stake"); @@ -191,21 +207,21 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { confirmChange(validator1, privKey1, validator2, privKey2); require(gatewayAddress.balance == collateral, "gw balance is incorrect after confirm stake"); - v = saGetter.getValidator(validator1); + v = saDiamond.getter().getValidator(validator1); require(v.totalCollateral == validator1Stake + stake, "unexpected total collateral after confirm stake"); require( v.confirmedCollateral == validator1Stake + stake, "unexpected confirmed collateral after confirm stake" ); - v = saGetter.getValidator(validator2); + v = saDiamond.getter().getValidator(validator2); require(v.totalCollateral == DEFAULT_MIN_VALIDATOR_STAKE, "unexpected total collateral after confirm stake"); require( v.confirmedCollateral == DEFAULT_MIN_VALIDATOR_STAKE, "unexpected confirmed collateral after confirm stake" ); - (nextConfigNum, startConfigNum) = saGetter.getConfigurationNumbers(); + (nextConfigNum, startConfigNum) = saDiamond.getter().getConfigurationNumbers(); require( nextConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER + 3, "next config num not 4 after confirm stake" @@ -214,18 +230,18 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { startConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER + 3, "start config num not 4 after confirm stake" ); - require(saGetter.genesisValidators().length == 1, "genesis validators still 1"); + require(saDiamond.getter().genesisValidators().length == 1, "genesis validators still 1"); // ======== Step. Leave ====== vm.startPrank(validator1); - saManager.leave(); + saDiamond.manager().leave(); - v = saGetter.getValidator(validator1); + v = saDiamond.getter().getValidator(validator1); require(v.totalCollateral == 0, "total collateral not 0 after confirm leave"); require(v.confirmedCollateral == validator1Stake + stake, "confirmed collateral incorrect after confirm leave"); require(gatewayAddress.balance == collateral, "gw balance is incorrect after validator 1 leaving"); - (nextConfigNum, startConfigNum) = saGetter.getConfigurationNumbers(); + (nextConfigNum, startConfigNum) = saDiamond.getter().getConfigurationNumbers(); require( nextConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER + 4, "next config num not 5 after confirm leave" @@ -234,8 +250,8 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { startConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER + 3, "start config num not 4 after confirm leave" ); - require(saGetter.isActiveValidator(validator1), "not active validator 1"); - require(saGetter.isActiveValidator(validator2), "not active validator 2"); + require(saDiamond.getter().isActiveValidator(validator1), "not active validator 1"); + require(saDiamond.getter().isActiveValidator(validator2), "not active validator 2"); vm.stopPrank(); @@ -244,11 +260,11 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { collateral -= (validator1Stake + stake); require(gatewayAddress.balance == collateral, "gw balance is incorrect after confirming validator 1 leaving"); - v = saGetter.getValidator(validator1); + v = saDiamond.getter().getValidator(validator1); require(v.totalCollateral == 0, "total collateral not 0 after confirm leave"); require(v.confirmedCollateral == 0, "confirmed collateral not 0 after confirm leave"); - (nextConfigNum, startConfigNum) = saGetter.getConfigurationNumbers(); + (nextConfigNum, startConfigNum) = saDiamond.getter().getConfigurationNumbers(); require( nextConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER + 4, "next config num not 5 after confirm leave" @@ -257,13 +273,13 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { startConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER + 4, "start config num not 5 after confirm leave" ); - require(!saGetter.isActiveValidator(validator1), "active validator 1"); - require(saGetter.isActiveValidator(validator2), "not active validator 2"); + require(!saDiamond.getter().isActiveValidator(validator1), "active validator 1"); + require(saDiamond.getter().isActiveValidator(validator2), "not active validator 2"); // ======== Step. Claim collateral ====== uint256 b1 = validator1.balance; vm.prank(validator1); - saRewarder.claim(); + saDiamond.rewarder().claim(); uint256 b2 = validator1.balance; require(b2 - b1 == validator1Stake + stake, "collateral not received"); } @@ -290,10 +306,10 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { _majorityPercentage ); - SubnetID memory parent = saGetter.getParent(); + SubnetID memory parent = saDiamond.getter().getParent(); require(parent.isRoot(), "parent.isRoot()"); - require(saGetter.bottomUpCheckPeriod() == _checkPeriod, "bottomUpCheckPeriod"); + require(saDiamond.getter().bottomUpCheckPeriod() == _checkPeriod, "bottomUpCheckPeriod"); } function testSubnetActorDiamond_Deployments_Fail_GatewayCannotBeZero() public { @@ -335,7 +351,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.prank(validator); vm.expectRevert(NotOwnerOfPublicKey.selector); - saManager.join{value: 10}(new bytes(65)); + saDiamond.manager().join{value: 10}(new bytes(65)); } function testSubnetActorDiamond_Join_Fail_InvalidPublicKeyLength() public { @@ -345,7 +361,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.prank(validator); vm.expectRevert(InvalidPublicKeyLength.selector); - saManager.join{value: 10}(new bytes(64)); + saDiamond.manager().join{value: 10}(new bytes(64)); } function testSubnetActorDiamond_Join_Fail_ZeroColalteral() public { @@ -355,7 +371,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.prank(validator); vm.expectRevert(CollateralIsZero.selector); - saManager.join(publicKey); + saDiamond.manager().join(publicKey); } function testSubnetActorDiamond_Bootstrap_Node() public { @@ -363,23 +379,23 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.deal(validator, DEFAULT_MIN_VALIDATOR_STAKE); vm.prank(validator); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey); // validator adds empty node vm.prank(validator); vm.expectRevert(EmptyAddress.selector); - saManager.addBootstrapNode(""); + saDiamond.manager().addBootstrapNode(""); // validator adds a node vm.prank(validator); - saManager.addBootstrapNode("1.2.3.4"); + saDiamond.manager().addBootstrapNode("1.2.3.4"); // not-validator adds a node vm.prank(vm.addr(200)); vm.expectRevert(abi.encodeWithSelector(NotValidator.selector, vm.addr(200))); - saManager.addBootstrapNode("3.4.5.6"); + saDiamond.manager().addBootstrapNode("3.4.5.6"); - string[] memory nodes = saGetter.getBootstrapNodes(); + string[] memory nodes = saDiamond.getter().getBootstrapNodes(); require(nodes.length == 1, "it returns one node"); require( keccak256(abi.encodePacked((nodes[0]))) == keccak256(abi.encodePacked(("1.2.3.4"))), @@ -387,10 +403,10 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { ); vm.prank(validator); - saManager.leave(); + saDiamond.manager().leave(); confirmChange(validator, privKey); - nodes = saGetter.getBootstrapNodes(); + nodes = saDiamond.getter().getBootstrapNodes(); require(nodes.length == 0, "no nodes"); } @@ -400,7 +416,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { // non-empty subnet can't be killed vm.prank(validator); vm.expectRevert(abi.encodeWithSelector(NotValidator.selector, validator)); - saManager.leave(); + saDiamond.manager().leave(); } function testSubnetActorDiamond_Leave_Subnet() public { @@ -413,35 +429,35 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.deal(validator3, DEFAULT_MIN_VALIDATOR_STAKE); vm.prank(validator1); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey1); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey1); vm.prank(validator2); - saManager.join{value: 3 * DEFAULT_MIN_VALIDATOR_STAKE}(publicKey2); + saDiamond.manager().join{value: 3 * DEFAULT_MIN_VALIDATOR_STAKE}(publicKey2); vm.prank(validator3); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey3); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey3); confirmChange(validator1, privKey1); - require(saGetter.isActiveValidator(validator1), "validator 1 is not active"); - require(saGetter.isActiveValidator(validator2), "validator 2 is not active"); - require(saGetter.isActiveValidator(validator3), "validator 3 is not active"); + require(saDiamond.getter().isActiveValidator(validator1), "validator 1 is not active"); + require(saDiamond.getter().isActiveValidator(validator2), "validator 2 is not active"); + require(saDiamond.getter().isActiveValidator(validator3), "validator 3 is not active"); // non-empty subnet can't be killed vm.expectRevert(NotAllValidatorsHaveLeft.selector); vm.prank(validator1); - saManager.kill(); + saDiamond.manager().kill(); // validator1 is leaving the subnet vm.startPrank(validator1); - saManager.leave(); + saDiamond.manager().leave(); vm.stopPrank(); confirmChange(validator2, privKey2, validator3, privKey3); - require(!saGetter.isActiveValidator(validator1), "validator 1 is active"); - require(saGetter.isActiveValidator(validator2), "validator 2 is not active"); - require(saGetter.isActiveValidator(validator3), "validator 3 is not active"); + require(!saDiamond.getter().isActiveValidator(validator1), "validator 1 is active"); + require(saDiamond.getter().isActiveValidator(validator2), "validator 2 is not active"); + require(saDiamond.getter().isActiveValidator(validator3), "validator 3 is not active"); } function testSubnetActorDiamond_Kill_NotBootstrappedSubnet() public { @@ -450,7 +466,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { // not bootstrapped subnet can't be killed vm.expectRevert(SubnetNotBootstrapped.selector); vm.prank(validator1); - saManager.kill(); + saDiamond.manager().kill(); } function testSubnetActorDiamond_Stake() public { @@ -459,28 +475,28 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.prank(validator); vm.expectRevert(CollateralIsZero.selector); - saManager.stake(); + saDiamond.manager().stake(); vm.prank(validator); vm.expectRevert((abi.encodeWithSelector(MethodNotAllowed.selector, ERR_VALIDATOR_NOT_JOINED))); - saManager.stake{value: 10}(); + saDiamond.manager().stake{value: 10}(); vm.prank(validator); - saManager.join{value: 3}(publicKey); + saDiamond.manager().join{value: 3}(publicKey); - ValidatorInfo memory info = saGetter.getValidator(validator); + ValidatorInfo memory info = saDiamond.getter().getValidator(validator); require(info.totalCollateral == 3); } function testSubnetActorDiamond_crossMsgGetter() public view { IpcEnvelope[] memory msgs = new IpcEnvelope[](1); msgs[0] = TestUtils.newXnetCallMsg( - IPCAddress({subnetId: saGetter.getParent(), rawAddress: FvmAddressHelper.from(address(this))}), - IPCAddress({subnetId: saGetter.getParent(), rawAddress: FvmAddressHelper.from(address(this))}), + IPCAddress({subnetId: saDiamond.getter().getParent(), rawAddress: FvmAddressHelper.from(address(this))}), + IPCAddress({subnetId: saDiamond.getter().getParent(), rawAddress: FvmAddressHelper.from(address(this))}), DEFAULT_CROSS_MSG_FEE + 1, 0 ); - require(saGetter.crossMsgsHash(msgs) == keccak256(abi.encode(msgs))); + require(saDiamond.getter().crossMsgsHash(msgs) == keccak256(abi.encode(msgs))); } function testSubnetActorDiamond_validateActiveQuorumSignatures() public { @@ -497,10 +513,10 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { pubKeys[i] = TestUtils.deriveValidatorPubKeyBytes(keys[i]); vm.deal(validators[i], 10 gwei); vm.prank(validators[i]); - saManager.join{value: 10}(pubKeys[i]); + saDiamond.manager().join{value: 10}(pubKeys[i]); } - saCheckpointer.validateActiveQuorumSignatures(validators, hash, signatures); + saDiamond.checkpointer().validateActiveQuorumSignatures(validators, hash, signatures); } function testSubnetActorDiamond_validateActiveQuorumSignatures_InvalidWeightSum() public { @@ -516,7 +532,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { pubKeys[i] = TestUtils.deriveValidatorPubKeyBytes(keys[i]); vm.deal(validators[i], 10 gwei); vm.prank(validators[i]); - saManager.join{value: 10}(pubKeys[i]); + saDiamond.manager().join{value: 10}(pubKeys[i]); } // this should trigger `WeightsSumLessThanThreshold` error since the signature weight will be just 100. @@ -530,7 +546,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { MultisignatureChecker.Error.WeightsSumLessThanThreshold ) ); - saCheckpointer.validateActiveQuorumSignatures(subValidators, hash, signatures); + saDiamond.checkpointer().validateActiveQuorumSignatures(subValidators, hash, signatures); } function testSubnetActorDiamond_validateActiveQuorumSignatures_InvalidSignature() public { @@ -551,13 +567,13 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { pubKeys[i] = TestUtils.deriveValidatorPubKeyBytes(keys[i]); vm.deal(validators[i], 10 gwei); vm.prank(validators[i]); - saManager.join{value: 10}(pubKeys[i]); + saDiamond.manager().join{value: 10}(pubKeys[i]); } vm.expectRevert( abi.encodeWithSelector(InvalidSignatureErr.selector, MultisignatureChecker.Error.InvalidSignature) ); - saCheckpointer.validateActiveQuorumSignatures(validators, hash, signatures); + saDiamond.checkpointer().validateActiveQuorumSignatures(validators, hash, signatures); } function testSubnetActorDiamond_validateActiveQuorumSignatures_EmptySignatures() public { @@ -571,14 +587,14 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { pubKeys[i] = TestUtils.deriveValidatorPubKeyBytes(keys[i]); vm.deal(validators[i], 10 gwei); vm.prank(validators[i]); - saManager.join{value: 10}(pubKeys[i]); + saDiamond.manager().join{value: 10}(pubKeys[i]); } require(signatures.length == 0, "signatures are not empty"); vm.expectRevert( abi.encodeWithSelector(InvalidSignatureErr.selector, MultisignatureChecker.Error.EmptySignatures) ); - saCheckpointer.validateActiveQuorumSignatures(validators, hash, signatures); + saDiamond.checkpointer().validateActiveQuorumSignatures(validators, hash, signatures); } function testSubnetActorDiamond_validateActiveQuorumSignatures_InvalidArrayLength() public { @@ -592,14 +608,14 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { pubKeys[i] = TestUtils.deriveValidatorPubKeyBytes(keys[i]); vm.deal(validators[i], 10 gwei); vm.prank(validators[i]); - saManager.join{value: 10}(pubKeys[i]); + saDiamond.manager().join{value: 10}(pubKeys[i]); } require(signatures.length == 1, "signatures are not empty"); vm.expectRevert( abi.encodeWithSelector(InvalidSignatureErr.selector, MultisignatureChecker.Error.InvalidArrayLength) ); - saCheckpointer.validateActiveQuorumSignatures(validators, hash, signatures); + saDiamond.checkpointer().validateActiveQuorumSignatures(validators, hash, signatures); } function testSubnetActorDiamond_validateActiveQuorumSignatures_InvalidSignatory() public { @@ -619,7 +635,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { pubKeys[i] = TestUtils.deriveValidatorPubKeyBytes(keys[i]); vm.deal(validators[i], 10 gwei); vm.prank(validators[i]); - saManager.join{value: 10}(pubKeys[i]); + saDiamond.manager().join{value: 10}(pubKeys[i]); } // swap validators to trigger `InvalidSignatory` error; @@ -631,7 +647,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.expectRevert( abi.encodeWithSelector(InvalidSignatureErr.selector, MultisignatureChecker.Error.InvalidSignatory) ); - saCheckpointer.validateActiveQuorumSignatures(validators, hash0, signatures); + saDiamond.checkpointer().validateActiveQuorumSignatures(validators, hash0, signatures); } function testSubnetActorDiamond_submitCheckpoint_basic() public { @@ -643,14 +659,17 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.deal(validators[i], 10 gwei); pubKeys[i] = TestUtils.deriveValidatorPubKeyBytes(keys[i]); vm.prank(validators[i]); - saManager.join{value: 10}(pubKeys[i]); + saDiamond.manager().join{value: 10}(pubKeys[i]); } - SubnetID memory localSubnetID = saGetter.getParent().createSubnetId(address(saDiamond)); + SubnetID memory localSubnetID = saDiamond.getter().getParent().createSubnetId(address(saDiamond)); IpcEnvelope memory crossMsg = TestUtils.newXnetCallMsg( IPCAddress({subnetId: localSubnetID, rawAddress: FvmAddressHelper.from(address(saDiamond))}), - IPCAddress({subnetId: saGetter.getParent(), rawAddress: FvmAddressHelper.from(address(saDiamond))}), + IPCAddress({ + subnetId: saDiamond.getter().getParent(), + rawAddress: FvmAddressHelper.from(address(saDiamond)) + }), DEFAULT_CROSS_MSG_FEE + 1, 0 ); @@ -659,14 +678,14 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ subnetID: localSubnetID, - blockHeight: saGetter.bottomUpCheckPeriod(), + blockHeight: saDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block1"), nextConfigurationNumber: 0, msgs: msgs }); BottomUpCheckpoint memory checkpointWithIncorrectHeight = BottomUpCheckpoint({ - subnetID: saGetter.getParent(), + subnetID: saDiamond.getter().getParent(), blockHeight: 1, blockHash: keccak256("block1"), nextConfigurationNumber: 0, @@ -675,7 +694,9 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.deal(address(saDiamond), 100 ether); vm.prank(address(saDiamond)); - gwManager.register{value: DEFAULT_MIN_VALIDATOR_STAKE + 3 * DEFAULT_CROSS_MSG_FEE}(3 * DEFAULT_CROSS_MSG_FEE); + gatewayDiamond.manager().register{value: DEFAULT_MIN_VALIDATOR_STAKE + 3 * DEFAULT_CROSS_MSG_FEE}( + 3 * DEFAULT_CROSS_MSG_FEE + ); bytes32 hash = keccak256(abi.encode(checkpoint)); @@ -686,39 +707,39 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.expectRevert(InvalidCheckpointEpoch.selector); vm.prank(validators[0]); - saCheckpointer.submitCheckpoint(checkpointWithIncorrectHeight, validators, signatures); + saDiamond.checkpointer().submitCheckpoint(checkpointWithIncorrectHeight, validators, signatures); vm.expectCall(gatewayAddress, abi.encodeCall(IGateway.commitCheckpoint, (checkpoint)), 1); vm.prank(validators[0]); - saCheckpointer.submitCheckpoint(checkpoint, validators, signatures); + saDiamond.checkpointer().submitCheckpoint(checkpoint, validators, signatures); require( - saGetter.lastBottomUpCheckpointHeight() == saGetter.bottomUpCheckPeriod(), + saDiamond.getter().lastBottomUpCheckpointHeight() == saDiamond.getter().bottomUpCheckPeriod(), " checkpoint height correct" ); vm.prank(validators[0]); - saCheckpointer.submitCheckpoint(checkpoint, validators, signatures); + saDiamond.checkpointer().submitCheckpoint(checkpoint, validators, signatures); require( - saGetter.lastBottomUpCheckpointHeight() == saGetter.bottomUpCheckPeriod(), + saDiamond.getter().lastBottomUpCheckpointHeight() == saDiamond.getter().bottomUpCheckPeriod(), " checkpoint height correct" ); - (bool exists, BottomUpCheckpoint memory recvCheckpoint) = saGetter.bottomUpCheckpointAtEpoch( - saGetter.bottomUpCheckPeriod() + (bool exists, BottomUpCheckpoint memory recvCheckpoint) = saDiamond.getter().bottomUpCheckpointAtEpoch( + saDiamond.getter().bottomUpCheckPeriod() ); require(exists, "checkpoint does not exist"); require(hash == keccak256(abi.encode(recvCheckpoint)), "checkpoint hashes are not the same"); bytes32 recvHash; - (exists, recvHash) = saGetter.bottomUpCheckpointHashAtEpoch(saGetter.bottomUpCheckPeriod()); + (exists, recvHash) = saDiamond.getter().bottomUpCheckpointHashAtEpoch(saDiamond.getter().bottomUpCheckPeriod()); require(exists, "checkpoint does not exist"); require(hash == recvHash, "hashes are not the same"); - saPauser.pause(); + saDiamond.pauser().pause(); vm.prank(validators[0]); vm.expectRevert(Pausable.EnforcedPause.selector); - saCheckpointer.submitCheckpoint(checkpoint, validators, signatures); + saDiamond.checkpointer().submitCheckpoint(checkpoint, validators, signatures); } function testSubnetActorDiamond_submitCheckpointWithReward() public { @@ -730,15 +751,18 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.deal(validators[i], 10 gwei); pubKeys[i] = TestUtils.deriveValidatorPubKeyBytes(keys[i]); vm.prank(validators[i]); - saManager.join{value: 10}(pubKeys[i]); + saDiamond.manager().join{value: 10}(pubKeys[i]); } - SubnetID memory localSubnetID = saGetter.getParent().createSubnetId(address(saDiamond)); + SubnetID memory localSubnetID = saDiamond.getter().getParent().createSubnetId(address(saDiamond)); // send the first checkpoint IpcEnvelope memory crossMsg = TestUtils.newXnetCallMsg( IPCAddress({subnetId: localSubnetID, rawAddress: FvmAddressHelper.from(address(saDiamond))}), - IPCAddress({subnetId: saGetter.getParent(), rawAddress: FvmAddressHelper.from(address(saDiamond))}), + IPCAddress({ + subnetId: saDiamond.getter().getParent(), + rawAddress: FvmAddressHelper.from(address(saDiamond)) + }), DEFAULT_CROSS_MSG_FEE + 1, 0 ); @@ -747,7 +771,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { BottomUpCheckpoint memory checkpoint = BottomUpCheckpoint({ subnetID: localSubnetID, - blockHeight: saGetter.bottomUpCheckPeriod(), + blockHeight: saDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block1"), nextConfigurationNumber: 0, msgs: msgs @@ -755,7 +779,9 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.deal(address(saDiamond), 100 ether); vm.prank(address(saDiamond)); - gwManager.register{value: DEFAULT_MIN_VALIDATOR_STAKE + 6 * DEFAULT_CROSS_MSG_FEE}(6 * DEFAULT_CROSS_MSG_FEE); + gatewayDiamond.manager().register{value: DEFAULT_MIN_VALIDATOR_STAKE + 6 * DEFAULT_CROSS_MSG_FEE}( + 6 * DEFAULT_CROSS_MSG_FEE + ); bytes32 hash = keccak256(abi.encode(checkpoint)); @@ -766,17 +792,20 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.expectCall(gatewayAddress, abi.encodeCall(IGateway.commitCheckpoint, (checkpoint)), 1); vm.prank(validators[0]); - saCheckpointer.submitCheckpoint(checkpoint, validators, signatures); + saDiamond.checkpointer().submitCheckpoint(checkpoint, validators, signatures); require( - saGetter.lastBottomUpCheckpointHeight() == saGetter.bottomUpCheckPeriod(), + saDiamond.getter().lastBottomUpCheckpointHeight() == saDiamond.getter().bottomUpCheckPeriod(), " checkpoint height correct" ); // send the second checkpoint crossMsg = TestUtils.newXnetCallMsg( IPCAddress({subnetId: localSubnetID, rawAddress: FvmAddressHelper.from(address(saDiamond))}), - IPCAddress({subnetId: saGetter.getParent(), rawAddress: FvmAddressHelper.from(address(saDiamond))}), + IPCAddress({ + subnetId: saDiamond.getter().getParent(), + rawAddress: FvmAddressHelper.from(address(saDiamond)) + }), DEFAULT_CROSS_MSG_FEE + 1, 1 ); @@ -784,7 +813,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { checkpoint = BottomUpCheckpoint({ subnetID: localSubnetID, - blockHeight: 2 * saGetter.bottomUpCheckPeriod(), + blockHeight: 2 * saDiamond.getter().bottomUpCheckPeriod(), blockHash: keccak256("block2"), nextConfigurationNumber: 0, msgs: msgs @@ -798,7 +827,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { } vm.prank(validators[0]); - saCheckpointer.submitCheckpoint(checkpoint, validators, signatures); + saDiamond.checkpointer().submitCheckpoint(checkpoint, validators, signatures); } function testSubnetActorDiamond_DiamondCut() public { @@ -875,32 +904,32 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.expectRevert(CannotReleaseZero.selector); vm.prank(validator); - saManager.unstake(0); + saDiamond.manager().unstake(0); vm.expectRevert(abi.encodeWithSelector(NotValidator.selector, validator)); vm.prank(validator); - saManager.unstake(10); + saDiamond.manager().unstake(10); vm.deal(validator, DEFAULT_MIN_VALIDATOR_STAKE); vm.prank(validator); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey); require( - saGetter.getValidator(validator).totalCollateral == DEFAULT_MIN_VALIDATOR_STAKE, + saDiamond.getter().getValidator(validator).totalCollateral == DEFAULT_MIN_VALIDATOR_STAKE, "initial collateral correct" ); vm.expectRevert(NotEnoughCollateral.selector); vm.prank(validator); - saManager.unstake(DEFAULT_MIN_VALIDATOR_STAKE + 100); + saDiamond.manager().unstake(DEFAULT_MIN_VALIDATOR_STAKE + 100); vm.expectRevert(NotEnoughCollateral.selector); vm.prank(validator); - saManager.unstake(DEFAULT_MIN_VALIDATOR_STAKE); + saDiamond.manager().unstake(DEFAULT_MIN_VALIDATOR_STAKE); vm.prank(validator); - saManager.unstake(5); + saDiamond.manager().unstake(5); require( - saGetter.getValidator(validator).totalCollateral == DEFAULT_MIN_VALIDATOR_STAKE - 5, + saDiamond.getter().getValidator(validator).totalCollateral == DEFAULT_MIN_VALIDATOR_STAKE - 5, "collateral correct after unstaking" ); } @@ -914,46 +943,46 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { uint256 collateral = 0; uint256 fundAmount = 100; - require(!saGetter.isActiveValidator(validator1), "active validator1"); - require(!saGetter.isWaitingValidator(validator1), "waiting validator1"); + require(!saDiamond.getter().isActiveValidator(validator1), "active validator1"); + require(!saDiamond.getter().isWaitingValidator(validator1), "waiting validator1"); // ======== Step. Join ====== // pre-fund and pre-release from same address vm.startPrank(preReleaser); vm.deal(preReleaser, 2 * fundAmount); - saManager.preFund{value: 2 * fundAmount}(); - require(saGetter.genesisCircSupply() == 2 * fundAmount, "genesis circ supply not correct"); - saManager.preRelease(fundAmount); - require(saGetter.genesisCircSupply() == fundAmount, "genesis circ supply not correct"); - (address[] memory genesisAddrs, ) = saGetter.genesisBalances(); + saDiamond.manager().preFund{value: 2 * fundAmount}(); + require(saDiamond.getter().genesisCircSupply() == 2 * fundAmount, "genesis circ supply not correct"); + saDiamond.manager().preRelease(fundAmount); + require(saDiamond.getter().genesisCircSupply() == fundAmount, "genesis circ supply not correct"); + (address[] memory genesisAddrs, ) = saDiamond.getter().genesisBalances(); require(genesisAddrs.length == 1, "not one genesis addresses"); // cannot release more than the initial balance of the address vm.expectRevert(NotEnoughBalance.selector); - saManager.preRelease(2 * fundAmount); + saDiamond.manager().preRelease(2 * fundAmount); // release all - saManager.preRelease(fundAmount); - (genesisAddrs, ) = saGetter.genesisBalances(); - require(saGetter.genesisCircSupply() == 0, "genesis circ supply not correct"); + saDiamond.manager().preRelease(fundAmount); + (genesisAddrs, ) = saDiamond.getter().genesisBalances(); + require(saDiamond.getter().genesisCircSupply() == 0, "genesis circ supply not correct"); require(genesisAddrs.length == 0, "not zero genesis addresses"); vm.stopPrank(); // pre-fund from validator and from pre-funder vm.startPrank(validator1); vm.deal(validator1, fundAmount); - saManager.preFund{value: fundAmount}(); + saDiamond.manager().preFund{value: fundAmount}(); vm.stopPrank(); vm.startPrank(preFunder); vm.deal(preFunder, fundAmount); - saManager.preFund{value: fundAmount}(); + saDiamond.manager().preFund{value: fundAmount}(); vm.stopPrank(); // initial validator joins vm.deal(validator1, DEFAULT_MIN_VALIDATOR_STAKE); vm.startPrank(validator1); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey1); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey1); vm.stopPrank(); collateral = DEFAULT_MIN_VALIDATOR_STAKE; @@ -962,22 +991,22 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { "gw balance is incorrect after validator1 joining" ); - require(saGetter.genesisCircSupply() == 2 * fundAmount, "genesis circ supply not correct"); - (genesisAddrs, ) = saGetter.genesisBalances(); + require(saDiamond.getter().genesisCircSupply() == 2 * fundAmount, "genesis circ supply not correct"); + (genesisAddrs, ) = saDiamond.getter().genesisBalances(); require(genesisAddrs.length == 2, "not two genesis addresses"); // collateral confirmed immediately and network boostrapped - ValidatorInfo memory v = saGetter.getValidator(validator1); + ValidatorInfo memory v = saDiamond.getter().getValidator(validator1); require(v.totalCollateral == DEFAULT_MIN_VALIDATOR_STAKE, "total collateral not expected"); require(v.confirmedCollateral == DEFAULT_MIN_VALIDATOR_STAKE, "confirmed collateral not equal to collateral"); - require(saGetter.isActiveValidator(validator1), "not active validator 1"); - require(!saGetter.isWaitingValidator(validator1), "waiting validator 1"); + require(saDiamond.getter().isActiveValidator(validator1), "not active validator 1"); + require(!saDiamond.getter().isWaitingValidator(validator1), "waiting validator 1"); TestUtils.ensureBytesEqual(v.metadata, publicKey1); - require(saGetter.bootstrapped(), "subnet not bootstrapped"); - require(!saGetter.killed(), "subnet killed"); - require(saGetter.genesisValidators().length == 1, "not one validator in genesis"); + require(saDiamond.getter().bootstrapped(), "subnet not bootstrapped"); + require(!saDiamond.getter().killed(), "subnet killed"); + require(saDiamond.getter().genesisValidators().length == 1, "not one validator in genesis"); - (uint64 nextConfigNum, uint64 startConfigNum) = saGetter.getConfigurationNumbers(); + (uint64 nextConfigNum, uint64 startConfigNum) = saDiamond.getter().getConfigurationNumbers(); require(nextConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER, "next config num not 1"); require(startConfigNum == LibStaking.INITIAL_CONFIGURATION_NUMBER, "start config num not 1"); @@ -985,7 +1014,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.startPrank(preFunder); vm.expectRevert(SubnetAlreadyBootstrapped.selector); vm.deal(preFunder, fundAmount); - saManager.preFund{value: fundAmount}(); + saDiamond.manager().preFund{value: fundAmount}(); vm.stopPrank(); } @@ -999,26 +1028,26 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { // pre-fund from validator vm.startPrank(validator1); vm.deal(validator1, fundAmount); - saManager.preFund{value: fundAmount}(); + saDiamond.manager().preFund{value: fundAmount}(); vm.stopPrank(); // initial validator joins but doesn't bootstrap the subnet vm.deal(validator1, collateral); vm.startPrank(validator1); - saManager.join{value: collateral}(publicKey1); + saDiamond.manager().join{value: collateral}(publicKey1); require( address(saDiamond).balance == collateral + fundAmount, "subnet balance is incorrect after validator1 joining" ); - require(saGetter.genesisCircSupply() == fundAmount, "genesis circ supply not correct"); - (address[] memory genesisAddrs, ) = saGetter.genesisBalances(); + require(saDiamond.getter().genesisCircSupply() == fundAmount, "genesis circ supply not correct"); + (address[] memory genesisAddrs, ) = saDiamond.getter().genesisBalances(); require(genesisAddrs.length == 1, "not one genesis addresses"); // Leave should return the collateral and the initial balance - saManager.leave(); + saDiamond.manager().leave(); require(address(saDiamond).balance == 0, "subnet balance is incorrect after validator1 leaving"); - require(saGetter.genesisCircSupply() == 0, "genesis circ supply not zero"); - (genesisAddrs, ) = saGetter.genesisBalances(); + require(saDiamond.getter().genesisCircSupply() == 0, "genesis circ supply not zero"); + (genesisAddrs, ) = saDiamond.getter().genesisBalances(); require(genesisAddrs.length == 0, "not zero genesis addresses"); vm.stopPrank(); @@ -1026,13 +1055,13 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.deal(validator1, DEFAULT_MIN_VALIDATOR_STAKE); vm.startPrank(validator1); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey1); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey1); vm.stopPrank(); // pre-release not allowed with bootstrapped subnet vm.startPrank(validator1); vm.expectRevert(SubnetAlreadyBootstrapped.selector); - saManager.preRelease(fundAmount); + saDiamond.manager().preRelease(fundAmount); vm.stopPrank(); } @@ -1048,17 +1077,17 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { } vm.prank(validators[0]); - saManager.join{value: 100 * DEFAULT_MIN_VALIDATOR_STAKE}(publicKeys[0]); + saDiamond.manager().join{value: 100 * DEFAULT_MIN_VALIDATOR_STAKE}(publicKeys[0]); for (uint i = 1; i < n; i++) { vm.prank(validators[i]); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKeys[i]); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKeys[i]); } confirmChange(validators[0], privKeys[0]); for (uint i = 0; i < n; i++) { - require(saGetter.isActiveValidator(validators[i]), "not active validator"); + require(saDiamond.getter().isActiveValidator(validators[i]), "not active validator"); } } @@ -1075,17 +1104,17 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { } vm.prank(validators[0]); - saManager.join{value: 100 * DEFAULT_MIN_VALIDATOR_STAKE}(publicKeys[0]); + saDiamond.manager().join{value: 100 * DEFAULT_MIN_VALIDATOR_STAKE}(publicKeys[0]); for (uint i = 1; i < n; i++) { vm.prank(validators[i]); - saManager.join{value: 1}(publicKeys[i]); + saDiamond.manager().join{value: 1}(publicKeys[i]); } confirmChange(validators[0], privKeys[0]); for (uint i = 0; i < n; i++) { - require(saGetter.isActiveValidator(validators[i]), "not active validator"); + require(saDiamond.getter().isActiveValidator(validators[i]), "not active validator"); } } @@ -1097,10 +1126,10 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { for (uint i = 0; i < n; i++) { vm.deal(validators[i], 1); vm.prank(validators[i]); - saManager.join{value: 1}(publicKeys[i]); + saDiamond.manager().join{value: 1}(publicKeys[i]); } - require(!saGetter.bootstrapped()); + require(!saDiamond.getter().bootstrapped()); } function test_second_validator_can_join() public { @@ -1109,13 +1138,13 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { join(validatorAddress1, publicKey1); - require(saGetter.bootstrapped(), "subnet not bootstrapped"); - require(saGetter.isActiveValidator(validatorAddress1), "validator 1 is not active"); - require(!saGetter.isActiveValidator(validatorAddress2), "validator 2 is active"); + require(saDiamond.getter().bootstrapped(), "subnet not bootstrapped"); + require(saDiamond.getter().isActiveValidator(validatorAddress1), "validator 1 is not active"); + require(!saDiamond.getter().isActiveValidator(validatorAddress2), "validator 2 is active"); join(validatorAddress2, publicKey2); confirmChange(validatorAddress1, privKey1); - require(saGetter.isActiveValidator(validatorAddress2), "validator 2 is not active"); + require(saDiamond.getter().isActiveValidator(validatorAddress2), "validator 2 is not active"); } function callback() public view { @@ -1139,21 +1168,21 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { (address validator1, bytes memory publicKey1) = TestUtils.deriveValidatorAddress(100); vm.deal(validator1, DEFAULT_MIN_VALIDATOR_STAKE * 2); vm.prank(validator1); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(publicKey1); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(publicKey1); (address validator2, bytes memory publicKey2) = TestUtils.deriveValidatorAddress(101); vm.deal(validator2, DEFAULT_MIN_VALIDATOR_STAKE * 2); vm.prank(validator2); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(publicKey2); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(publicKey2); - require(saGetter.isActiveValidator(validator1), "not active validator 1"); - require(saGetter.isActiveValidator(validator2), "not active validator 2"); + require(saDiamond.getter().isActiveValidator(validator1), "not active validator 1"); + require(saDiamond.getter().isActiveValidator(validator2), "not active validator 2"); // cannot join after bootstrap vm.expectRevert(abi.encodeWithSelector(MethodNotAllowed.selector, ERR_PERMISSIONED_AND_BOOTSTRAPPED)); vm.prank(validator1); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey1); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKey1); vm.expectRevert(abi.encodeWithSelector(MethodNotAllowed.selector, ERR_PERMISSIONED_AND_BOOTSTRAPPED)); (address[] memory validators, , bytes[] memory publicKeys) = TestUtils.newValidators(3); @@ -1161,7 +1190,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { powers[0] = 10000; powers[1] = 20000; powers[2] = 5000; // we only have 2 active validators, validator 2 does not have enough power - saManager.setFederatedPower(validators, publicKeys, powers); + saDiamond.manager().setFederatedPower(validators, publicKeys, powers); } function testSubnetActorDiamond_registration_policy() public { @@ -1170,30 +1199,30 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.expectRevert(abi.encodeWithSelector(MethodNotAllowed.selector, ERR_VALIDATOR_NOT_JOINED)); vm.prank(validator1); - saManager.stake{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(); + saDiamond.manager().stake{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(); vm.prank(validator1); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(publicKey1); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(publicKey1); - require(saGetter.isActiveValidator(validator1), "active validator 1"); - require(!saGetter.bootstrapped(), "subnet bootstrapped"); + require(saDiamond.getter().isActiveValidator(validator1), "active validator 1"); + require(!saDiamond.getter().bootstrapped(), "subnet bootstrapped"); vm.expectRevert(abi.encodeWithSelector(MethodNotAllowed.selector, ERR_VALIDATOR_JOINED)); vm.prank(validator1); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(publicKey1); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(publicKey1); vm.prank(validator1); - saManager.stake{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(); + saDiamond.manager().stake{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(); - require(saGetter.isActiveValidator(validator1), "active validator 1"); + require(saDiamond.getter().isActiveValidator(validator1), "active validator 1"); (address validator2, bytes memory publicKey2) = TestUtils.deriveValidatorAddress(101); vm.deal(validator2, DEFAULT_MIN_VALIDATOR_STAKE * 2); vm.prank(validator2); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(publicKey2); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE / 2}(publicKey2); - require(saGetter.isActiveValidator(validator1), "not active validator 1"); - require(saGetter.bootstrapped(), "subnet not bootstrapped"); + require(saDiamond.getter().isActiveValidator(validator1), "not active validator 1"); + require(saDiamond.getter().bootstrapped(), "subnet not bootstrapped"); } function testSubnetActorDiamond_FederatedValidation_bootstrapWorks() public { @@ -1216,9 +1245,9 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { powers[0] = 10000; powers[1] = 20000; - saManager.setFederatedPower(validators, publicKeys, powers); - require(saGetter.isActiveValidator(validators[0]), "not active validator 1"); - require(saGetter.isActiveValidator(validators[1]), "not active validator 2"); + saDiamond.manager().setFederatedPower(validators, publicKeys, powers); + require(saDiamond.getter().isActiveValidator(validators[0]), "not active validator 1"); + require(saDiamond.getter().isActiveValidator(validators[1]), "not active validator 2"); } function testSubnetActorDiamond_FederatedValidation_bootstrapNotOwnerOfPublicKeys() public { @@ -1243,7 +1272,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { powers[1] = 20000; vm.expectRevert(abi.encodeWithSelector(NotOwnerOfPublicKey.selector)); - saManager.setFederatedPower(validators, publicKeys, powers); + saDiamond.manager().setFederatedPower(validators, publicKeys, powers); } function testSubnetActorDiamond_FederatedValidation_bootstrapNotEnoughValidators() public { @@ -1266,7 +1295,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { powers[0] = 10000; vm.expectRevert(abi.encodeWithSelector(NotEnoughGenesisValidators.selector)); - saManager.setFederatedPower(validators, publicKeys, powers); + saDiamond.manager().setFederatedPower(validators, publicKeys, powers); } function testSubnetActorDiamond_FederatedValidation_bootstrapDuplicates() public { @@ -1292,7 +1321,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { powers[1] = 20000; vm.expectRevert(abi.encodeWithSelector(DuplicatedGenesisValidator.selector)); - saManager.setFederatedPower(validators, publicKeys, powers); + saDiamond.manager().setFederatedPower(validators, publicKeys, powers); } function testSubnetActorDiamond_FederatedValidation_cannotJoin() public { @@ -1314,12 +1343,12 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { powers[0] = 10000; powers[1] = 20000; - saManager.setFederatedPower(validators, publicKeys, powers); + saDiamond.manager().setFederatedPower(validators, publicKeys, powers); vm.deal(validators[0], DEFAULT_MIN_VALIDATOR_STAKE * 2); vm.startPrank(validators[0]); vm.expectRevert(abi.encodeWithSelector(MethodNotAllowed.selector, ERR_PERMISSIONED_AND_BOOTSTRAPPED)); - saManager.join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKeys[0]); + saDiamond.manager().join{value: DEFAULT_MIN_VALIDATOR_STAKE}(publicKeys[0]); } function testSubnetActorDiamond_FederatedValidation_works() public { @@ -1344,33 +1373,33 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { powers[1] = 20000; powers[2] = 5000; // we only have 2 active validators, validator 2 does not have enough power - saManager.setFederatedPower(validators, publicKeys, powers); + saDiamond.manager().setFederatedPower(validators, publicKeys, powers); - require(saGetter.isActiveValidator(validators[0]), "not active validator 0"); - require(saGetter.isActiveValidator(validators[1]), "not active validator 1"); - require(!saGetter.isActiveValidator(validators[2]), "2 should not be active validator"); + require(saDiamond.getter().isActiveValidator(validators[0]), "not active validator 0"); + require(saDiamond.getter().isActiveValidator(validators[1]), "not active validator 1"); + require(!saDiamond.getter().isActiveValidator(validators[2]), "2 should not be active validator"); // change in validator power powers[2] = 10001; - saManager.setFederatedPower(validators, publicKeys, powers); + saDiamond.manager().setFederatedPower(validators, publicKeys, powers); confirmChange(validators[0], privKeys[0], validators[1], privKeys[1]); - require(!saGetter.isActiveValidator(validators[0]), "0 should not be active validator"); - require(saGetter.isActiveValidator(validators[1]), "not active validator 1"); - require(saGetter.isActiveValidator(validators[2]), "not active validator 2"); + require(!saDiamond.getter().isActiveValidator(validators[0]), "0 should not be active validator"); + require(saDiamond.getter().isActiveValidator(validators[1]), "not active validator 1"); + require(saDiamond.getter().isActiveValidator(validators[2]), "not active validator 2"); /// reduce validator 2 power powers[2] = 5000; - saManager.setFederatedPower(validators, publicKeys, powers); + saDiamond.manager().setFederatedPower(validators, publicKeys, powers); confirmChange(validators[2], privKeys[2], validators[1], privKeys[1]); - require(saGetter.isActiveValidator(validators[0]), "not active validator 0"); - require(saGetter.isActiveValidator(validators[1]), "not active validator 1"); - require(!saGetter.isActiveValidator(validators[2]), "2 should not be active validator"); + require(saDiamond.getter().isActiveValidator(validators[0]), "not active validator 0"); + require(saDiamond.getter().isActiveValidator(validators[1]), "not active validator 1"); + require(!saDiamond.getter().isActiveValidator(validators[2]), "2 should not be active validator"); } function testSubnetActorDiamond_FederatedValidation_worksWithDuplicates() public { @@ -1395,11 +1424,11 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { powers[1] = 20000; powers[2] = 5000; // we only have 2 active validators, validator 2 does not have enough power - saManager.setFederatedPower(validators, publicKeys, powers); + saDiamond.manager().setFederatedPower(validators, publicKeys, powers); - require(saGetter.isActiveValidator(validators[0]), "not active validator 0"); - require(saGetter.isActiveValidator(validators[1]), "not active validator 1"); - require(!saGetter.isActiveValidator(validators[2]), "2 should not be active validator"); + require(saDiamond.getter().isActiveValidator(validators[0]), "not active validator 0"); + require(saDiamond.getter().isActiveValidator(validators[1]), "not active validator 1"); + require(!saDiamond.getter().isActiveValidator(validators[2]), "2 should not be active validator"); // change in validator power, changing validator 2's power to 10001. @@ -1415,14 +1444,14 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { powers[0] = 9999; // lower than validator 0's power, will not kick validator 1 off powers[2] = 10001; // higher than validator 0's power, will kick validator 1 off - saManager.setFederatedPower(validators, publicKeys, powers); + saDiamond.manager().setFederatedPower(validators, publicKeys, powers); confirmChange(prevV, prevPrivateKey, validators[1], privKeys[1]); // we should see validator 0 kicked off - require(!saGetter.isActiveValidator(prevV), "0 should not be active validator"); - require(saGetter.isActiveValidator(validators[1]), "not active validator 1"); - require(saGetter.isActiveValidator(validators[2]), "not active validator 2"); + require(!saDiamond.getter().isActiveValidator(prevV), "0 should not be active validator"); + require(saDiamond.getter().isActiveValidator(validators[1]), "not active validator 1"); + require(saDiamond.getter().isActiveValidator(validators[2]), "not active validator 2"); } // ----------------------------------------------------------------------------------------------------------------- @@ -1430,18 +1459,18 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { // ----------------------------------------------------------------------------------------------------------------- function testSubnetActorDiamond_Pausable_PauseUnpause() public { - require(!saPauser.paused(), "paused"); + require(!saDiamond.pauser().paused(), "paused"); - saPauser.pause(); - require(saPauser.paused(), "not paused"); + saDiamond.pauser().pause(); + require(saDiamond.pauser().paused(), "not paused"); - saPauser.unpause(); - require(!saPauser.paused(), "paused"); + saDiamond.pauser().unpause(); + require(!saDiamond.pauser().paused(), "paused"); } function testSubnetActorDiamond_Pausable_EnforcedPause() public { - saPauser.pause(); - require(saPauser.paused(), "not paused"); + saDiamond.pauser().pause(); + require(saDiamond.pauser().paused(), "not paused"); uint256 n = 1; (address[] memory validators, , bytes[] memory publicKeys) = TestUtils.newValidators(n); @@ -1449,23 +1478,23 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { vm.prank(validators[0]); vm.expectRevert(Pausable.EnforcedPause.selector); - saManager.join{value: 10}(publicKeys[0]); + saDiamond.manager().join{value: 10}(publicKeys[0]); vm.prank(validators[0]); vm.expectRevert(Pausable.EnforcedPause.selector); - saManager.stake{value: 10}(); + saDiamond.manager().stake{value: 10}(); vm.prank(validators[0]); vm.expectRevert(Pausable.EnforcedPause.selector); - saManager.unstake(1); + saDiamond.manager().unstake(1); vm.prank(validators[0]); vm.expectRevert(Pausable.EnforcedPause.selector); - saManager.leave(); + saDiamond.manager().leave(); vm.prank(validators[0]); vm.expectRevert(Pausable.EnforcedPause.selector); - saManager.addBootstrapNode("1.1.1.1"); + saDiamond.manager().addBootstrapNode("1.1.1.1"); // Test on submitCheckpoint() reverts if the contract is paused // is in testSubnetActorDiamond_submitCheckpoint_basic. @@ -1474,30 +1503,30 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { function testSubnetActorDiamond_PauseUnpause_NotOwner() public { vm.prank(vm.addr(1)); vm.expectRevert(LibDiamond.NotOwner.selector); - saPauser.pause(); + saDiamond.pauser().pause(); - saPauser.pause(); - require(saPauser.paused(), "not paused"); + saDiamond.pauser().pause(); + require(saDiamond.pauser().paused(), "not paused"); vm.prank(vm.addr(1)); vm.expectRevert(LibDiamond.NotOwner.selector); - saPauser.unpause(); + saDiamond.pauser().unpause(); - saPauser.unpause(); - require(!saPauser.paused(), "not paused"); + saDiamond.pauser().unpause(); + require(!saDiamond.pauser().paused(), "not paused"); } function testSubnetActorDiamond_Pausable_CannotPauseAgain() public { - saPauser.pause(); - require(saPauser.paused(), "not paused"); + saDiamond.pauser().pause(); + require(saDiamond.pauser().paused(), "not paused"); vm.expectRevert(Pausable.EnforcedPause.selector); - saPauser.pause(); + saDiamond.pauser().pause(); } function testSubnetActorDiamond_Pausable_CannotUnpauseAgain() public { vm.expectRevert(Pausable.ExpectedPause.selector); - saPauser.unpause(); - require(!saPauser.paused(), "paused"); + saDiamond.pauser().unpause(); + require(!saDiamond.pauser().paused(), "paused"); } } diff --git a/contracts/test/integration/SubnetRegistry.t.sol b/contracts/test/integration/SubnetRegistry.t.sol index bc1b1422d..56076e56d 100644 --- a/contracts/test/integration/SubnetRegistry.t.sol +++ b/contracts/test/integration/SubnetRegistry.t.sol @@ -26,10 +26,15 @@ import {SubnetGetterFacet} from "../../src/subnetregistry/SubnetGetterFacet.sol" import {DiamondLoupeFacet} from "../../src/diamond/DiamondLoupeFacet.sol"; import {DiamondCutFacet} from "../../src/diamond/DiamondCutFacet.sol"; import {SupplySourceHelper} from "../../src/lib/SupplySourceHelper.sol"; +import {RegistryFacetsHelper} from "../helpers/RegistryFacetsHelper.sol"; +import {DiamondFacetsHelper} from "../helpers/DiamondFacetsHelper.sol"; import {IntegrationTestBase, TestRegistry} from "../IntegrationTestBase.sol"; contract SubnetRegistryTest is Test, TestRegistry, IntegrationTestBase { + using RegistryFacetsHelper for SubnetRegistryDiamond; + using DiamondFacetsHelper for SubnetRegistryDiamond; + bytes4[] empty; function setUp() public virtual override { @@ -64,10 +69,10 @@ contract SubnetRegistryTest is Test, TestRegistry, IntegrationTestBase { params.subnetActorPauserSelectors = mockedSelectors5; registryDiamond = createSubnetRegistry(params); - registryLouper = DiamondLoupeFacet(address(registryDiamond)); - registryCutter = DiamondCutFacet(address(registryDiamond)); - registrySubnetFacet = RegisterSubnetFacet(address(registryDiamond)); - registrySubnetGetterFacet = SubnetGetterFacet(address(registryDiamond)); + registryLouper = registryDiamond.diamondLouper(); + registryCutter = registryDiamond.diamondCutter(); + registrySubnetFacet = registryDiamond.register(); + registrySubnetGetterFacet = registryDiamond.getter(); } function test_Registry_FacetFunctionSelectors() public view { @@ -137,7 +142,7 @@ contract SubnetRegistryTest is Test, TestRegistry, IntegrationTestBase { } function test_Registry_Deployment_DifferentGateway() public { - SubnetActorDiamond.ConstructorParams memory params = defaultSubnetActorParamsWithGateway(address(1)); + SubnetActorDiamond.ConstructorParams memory params = defaultSubnetActorParamsWith(address(1)); params.permissionMode = PermissionMode.Collateral; vm.expectRevert(WrongGateway.selector); @@ -147,9 +152,7 @@ contract SubnetRegistryTest is Test, TestRegistry, IntegrationTestBase { function test_Registry_LatestSubnetDeploy_Revert() public { vm.startPrank(DEFAULT_SENDER); - SubnetActorDiamond.ConstructorParams memory params = defaultSubnetActorParamsWithGateway( - DEFAULT_IPC_GATEWAY_ADDR - ); + SubnetActorDiamond.ConstructorParams memory params = defaultSubnetActorParamsWith(DEFAULT_IPC_GATEWAY_ADDR); params.permissionMode = PermissionMode.Collateral; registrySubnetFacet.newSubnetActor(params); @@ -160,9 +163,7 @@ contract SubnetRegistryTest is Test, TestRegistry, IntegrationTestBase { function test_Registry_GetSubnetDeployedByNonce_Revert() public { vm.startPrank(DEFAULT_SENDER); - SubnetActorDiamond.ConstructorParams memory params = defaultSubnetActorParamsWithGateway( - DEFAULT_IPC_GATEWAY_ADDR - ); + SubnetActorDiamond.ConstructorParams memory params = defaultSubnetActorParamsWith(DEFAULT_IPC_GATEWAY_ADDR); params.permissionMode = PermissionMode.Collateral; registrySubnetFacet.newSubnetActor(params); @@ -173,9 +174,7 @@ contract SubnetRegistryTest is Test, TestRegistry, IntegrationTestBase { function test_Registry_Deployment_Works() public { vm.startPrank(DEFAULT_SENDER); - SubnetActorDiamond.ConstructorParams memory params = defaultSubnetActorParamsWithGateway( - DEFAULT_IPC_GATEWAY_ADDR - ); + SubnetActorDiamond.ConstructorParams memory params = defaultSubnetActorParamsWith(DEFAULT_IPC_GATEWAY_ADDR); registrySubnetFacet.newSubnetActor(params); require(registrySubnetGetterFacet.latestSubnetDeployed(DEFAULT_SENDER) != address(0)); } diff --git a/contracts/test/invariants/GatewayActorInvariantTests.t.sol b/contracts/test/invariants/GatewayActorInvariantTests.t.sol index 077659e7f..c4a00820f 100644 --- a/contracts/test/invariants/GatewayActorInvariantTests.t.sol +++ b/contracts/test/invariants/GatewayActorInvariantTests.t.sol @@ -6,8 +6,11 @@ import {GatewayDiamond} from "../../src/GatewayDiamond.sol"; import {L1GatewayActorDiamond, L2GatewayActorDiamond, L3GatewayActorDiamond} from "../IntegrationTestPresets.sol"; import {GatewayActorHandler} from "./handlers/GatewayActorHandler.sol"; import {GatewayActorBasicProperties} from "./GatewayActorProperties.sol"; +import {GatewayFacetsHelper} from "../helpers/GatewayFacetsHelper.sol"; contract GatewayActorInvariantTests is StdInvariant, L1GatewayActorDiamond, GatewayActorBasicProperties { + using GatewayFacetsHelper for GatewayDiamond; + GatewayActorHandler private gatewayActorHandler; function setUp() public override { @@ -16,11 +19,13 @@ contract GatewayActorInvariantTests is StdInvariant, L1GatewayActorDiamond, Gate targetContract(address(gatewayActorHandler)); // assert specific properties of the infrastructure. - assertEq(gwGetter.getNetworkName().route.length, 1); + assertEq(gatewayDiamond.getter().getNetworkName().route.length, 1); } } contract L2GatewayActorInvariantTests is L2GatewayActorDiamond, GatewayActorBasicProperties { + using GatewayFacetsHelper for GatewayDiamond; + GatewayActorHandler private gatewayActorHandler; function setUp() public override { @@ -29,11 +34,13 @@ contract L2GatewayActorInvariantTests is L2GatewayActorDiamond, GatewayActorBasi targetContract(address(gatewayActorHandler)); // assert specific properties of the infrastructure. - assertEq(gwGetter.getNetworkName().route.length, 2); + assertEq(gatewayDiamond.getter().getNetworkName().route.length, 2); } } contract L3GatewayActorInvariantTests is L3GatewayActorDiamond, GatewayActorBasicProperties { + using GatewayFacetsHelper for GatewayDiamond; + GatewayActorHandler private gatewayActorHandler; function setUp() public override { @@ -42,6 +49,6 @@ contract L3GatewayActorInvariantTests is L3GatewayActorDiamond, GatewayActorBasi targetContract(address(gatewayActorHandler)); // assert specific properties of the infrastructure. - assertEq(gwGetter.getNetworkName().route.length, 3); + assertEq(gatewayDiamond.getter().getNetworkName().route.length, 3); } } diff --git a/contracts/test/invariants/GatewayActorProperties.sol b/contracts/test/invariants/GatewayActorProperties.sol index a199cf968..6adfe9a5e 100644 --- a/contracts/test/invariants/GatewayActorProperties.sol +++ b/contracts/test/invariants/GatewayActorProperties.sol @@ -2,16 +2,23 @@ pragma solidity ^0.8.23; import {StdAssertions} from "forge-std/StdAssertions.sol"; -import {GatewayGetterFacet} from "../../src/gateway/GatewayGetterFacet.sol"; +import {GatewayDiamond} from "../../src/GatewayDiamond.sol"; import {IntegrationTestBase, TestGatewayActor} from "../IntegrationTestBase.sol"; +import {GatewayFacetsHelper} from "../helpers/GatewayFacetsHelper.sol"; /// @title GatewayActor properties. /// @dev It is suggested that all properties are defined here. /// To check that a concrete GatewayActor instance holds the properties that target contract should inherit from this contract. /// This contract must be abstract. abstract contract GatewayActorBasicProperties is StdAssertions, TestGatewayActor { + using GatewayFacetsHelper for GatewayDiamond; + /// @notice The number of subnets is consistent within GatewayActor mechanisms. function invariant_GA_01_consistent_subnet_number() public virtual { - assertEq(gwGetter.totalSubnets(), gwGetter.listSubnets().length, "the number of subnets is not consistent"); + assertEq( + gatewayDiamond.getter().totalSubnets(), + gatewayDiamond.getter().listSubnets().length, + "the number of subnets is not consistent" + ); } } diff --git a/contracts/test/invariants/SubnetActorInvariants.t.sol b/contracts/test/invariants/SubnetActorInvariants.t.sol index 614c4f22f..6977b1322 100644 --- a/contracts/test/invariants/SubnetActorInvariants.t.sol +++ b/contracts/test/invariants/SubnetActorInvariants.t.sol @@ -6,6 +6,8 @@ import {StdInvariant} from "forge-std/Test.sol"; import {SubnetID, Subnet} from "../../src/structs/Subnet.sol"; import {SubnetIDHelper} from "../../src/lib/SubnetIDHelper.sol"; import {GatewayDiamond} from "../../src/GatewayDiamond.sol"; +import {SubnetActorDiamond} from "../../src/SubnetActorDiamond.sol"; +import {GatewayDiamond} from "../../src/GatewayDiamond.sol"; import {GatewayGetterFacet} from "../../src/gateway/GatewayGetterFacet.sol"; import {GatewayMessengerFacet} from "../../src/gateway/GatewayMessengerFacet.sol"; import {GatewayManagerFacet} from "../../src/gateway/GatewayManagerFacet.sol"; @@ -14,9 +16,14 @@ import {SubnetActorMock} from "../mocks/SubnetActorMock.sol"; import {SubnetActorGetterFacet} from "../../src/subnet/SubnetActorGetterFacet.sol"; import {IntegrationTestBase} from "../IntegrationTestBase.sol"; import {SupplySourceHelper} from "../../src/lib/SupplySourceHelper.sol"; +import {GatewayFacetsHelper} from "../helpers/GatewayFacetsHelper.sol"; +import {SubnetActorFacetsHelper} from "../helpers/SubnetActorFacetsHelper.sol"; +import {GatewayFacetsHelper} from "../helpers/GatewayFacetsHelper.sol"; contract SubnetActorInvariants is StdInvariant, IntegrationTestBase { using SubnetIDHelper for SubnetID; + using GatewayFacetsHelper for GatewayDiamond; + using SubnetActorFacetsHelper for SubnetActorDiamond; SubnetActorHandler private subnetActorHandler; @@ -27,15 +34,11 @@ contract SubnetActorInvariants is StdInvariant, IntegrationTestBase { gatewayDiamond = createGatewayDiamond(gwConstructorParams); - gwGetter = GatewayGetterFacet(address(gatewayDiamond)); - gwManager = GatewayManagerFacet(address(gatewayDiamond)); - gwMessenger = GatewayMessengerFacet(address(gatewayDiamond)); gatewayAddress = address(gatewayDiamond); saDiamond = createMockedSubnetActorWithGateway(gatewayAddress); saMock = SubnetActorMock(address(saDiamond)); - saGetter = SubnetActorGetterFacet(address(saDiamond)); subnetActorHandler = new SubnetActorHandler(saDiamond); bytes4[] memory fuzzSelectors = new bytes4[](4); @@ -52,7 +55,7 @@ contract SubnetActorInvariants is StdInvariant, IntegrationTestBase { /// if confirmations are executed immediately. function invariant_SA_01_total_validators_number_is_correct() public { assertEq( - saGetter.getTotalValidatorsNumber(), + saDiamond.getter().getTotalValidatorsNumber(), subnetActorHandler.joinedValidatorsNumber(), "unexpected total validators number" ); @@ -72,21 +75,21 @@ contract SubnetActorInvariants is StdInvariant, IntegrationTestBase { assertEq( ETH_SUPPLY, address(subnetActorHandler).balance + - saGetter.getTotalCollateral() + + saDiamond.getter().getTotalCollateral() + subnetActorHandler.ghost_unstakedSum(), "subnet actor: unexpected stake" ); assertEq( ETH_SUPPLY, address(subnetActorHandler).balance + - saGetter.getTotalConfirmedCollateral() + + saDiamond.getter().getTotalConfirmedCollateral() + subnetActorHandler.ghost_unstakedSum(), "subnet actor: unexpected stake" ); - if (saGetter.bootstrapped()) { - SubnetID memory subnetId = gwGetter.getNetworkName().createSubnetId(address(saDiamond)); - Subnet memory subnet = gwGetter.subnets(subnetId.toHash()); + if (saDiamond.getter().bootstrapped()) { + SubnetID memory subnetId = gatewayDiamond.getter().getNetworkName().createSubnetId(address(saDiamond)); + Subnet memory subnet = gatewayDiamond.getter().subnets(subnetId.toHash()); assertEq( subnetActorHandler.ghost_stakedSum() - subnetActorHandler.ghost_unstakedSum(), @@ -99,7 +102,7 @@ contract SubnetActorInvariants is StdInvariant, IntegrationTestBase { /// @notice The value resulting from all stake and unstake operations is equal to the total confirmed collateral. function invariant_SA_03_sum_of_stake_equals_collateral() public { assertEq( - saGetter.getTotalConfirmedCollateral(), + saDiamond.getter().getTotalConfirmedCollateral(), subnetActorHandler.ghost_stakedSum() - subnetActorHandler.ghost_unstakedSum() ); } @@ -112,7 +115,7 @@ contract SubnetActorInvariants is StdInvariant, IntegrationTestBase { if (validator == address(0)) { return; } - if (!saGetter.bootstrapped()) { + if (!saDiamond.getter().bootstrapped()) { return; } @@ -135,10 +138,10 @@ contract SubnetActorInvariants is StdInvariant, IntegrationTestBase { address[] memory validators = subnetActorHandler.joinedValidators(); uint256 n = validators.length; for (uint256 i; i < n; ++i) { - sumOfCollaterals += saGetter.getTotalValidatorCollateral(validators[i]); + sumOfCollaterals += saDiamond.getter().getTotalValidatorCollateral(validators[i]); } - uint256 totalCollateral = saGetter.getTotalConfirmedCollateral(); + uint256 totalCollateral = saDiamond.getter().getTotalConfirmedCollateral(); assertEq(sumOfCollaterals, totalCollateral, "unexpected sum of validators collateral"); } diff --git a/contracts/test/invariants/handlers/GatewayActorHandler.sol b/contracts/test/invariants/handlers/GatewayActorHandler.sol index 0e1943d59..12d015ce2 100644 --- a/contracts/test/invariants/handlers/GatewayActorHandler.sol +++ b/contracts/test/invariants/handlers/GatewayActorHandler.sol @@ -6,18 +6,19 @@ import "forge-std/StdCheats.sol"; import {CommonBase} from "forge-std/Base.sol"; import {GatewayDiamond} from "../../../src/GatewayDiamond.sol"; import {GatewayManagerFacet} from "../../../src/gateway/GatewayManagerFacet.sol"; +import {GatewayFacetsHelper} from "../../helpers/GatewayFacetsHelper.sol"; import {EnumerableSet} from "openzeppelin-contracts/utils/structs/EnumerableSet.sol"; uint256 constant ETH_SUPPLY = 129_590_000 ether; contract GatewayActorHandler is CommonBase, StdCheats, StdUtils { + using GatewayFacetsHelper for GatewayDiamond; GatewayManagerFacet managerFacet; uint256 private constant DEFAULT_MIN_VALIDATOR_STAKE = 10 ether; constructor(GatewayDiamond _gw) { - managerFacet = GatewayManagerFacet(address(_gw)); - + managerFacet = _gw.manager(); deal(address(this), ETH_SUPPLY); } diff --git a/contracts/test/invariants/handlers/SubnetRegistryHandler.sol b/contracts/test/invariants/handlers/SubnetRegistryHandler.sol index f8b8f168f..4b9e67d6a 100644 --- a/contracts/test/invariants/handlers/SubnetRegistryHandler.sol +++ b/contracts/test/invariants/handlers/SubnetRegistryHandler.sol @@ -12,9 +12,11 @@ import {ConsensusType} from "../../../src/enums/ConsensusType.sol"; import {SubnetID, PermissionMode} from "../../../src/structs/Subnet.sol"; import {SupplySourceHelper} from "../../../src/lib/SupplySourceHelper.sol"; import {EnumerableSet} from "openzeppelin-contracts/utils/structs/EnumerableSet.sol"; +import {RegistryFacetsHelper} from "../../helpers/RegistryFacetsHelper.sol"; contract SubnetRegistryHandler is CommonBase, StdCheats, StdUtils { using EnumerableSet for EnumerableSet.AddressSet; + using RegistryFacetsHelper for SubnetRegistryDiamond; address private constant DEFAULT_IPC_GATEWAY_ADDR = address(1024); uint64 constant DEFAULT_CHECKPOINT_PERIOD = 10; @@ -34,8 +36,8 @@ contract SubnetRegistryHandler is CommonBase, StdCheats, StdUtils { address private subnetGetterFacetAddr; constructor(SubnetRegistryDiamond _registry) { - registerSubnetFacet = RegisterSubnetFacet(address(_registry)); - registerGetterFacet = SubnetGetterFacet(address(_registry)); + registerSubnetFacet = _registry.register(); + registerGetterFacet = _registry.getter(); } function getSubnetDeployedBy(address owner) external view returns (address subnet) {