Skip to content

Commit

Permalink
Refactor tests (#679)
Browse files Browse the repository at this point in the history
Co-authored-by: raulk <[email protected]>
  • Loading branch information
dnkolegov and raulk authored Feb 27, 2024
1 parent d0d8b0c commit 3bcef48
Show file tree
Hide file tree
Showing 19 changed files with 1,332 additions and 1,034 deletions.
2 changes: 1 addition & 1 deletion contracts/lib/openzeppelin-contracts
266 changes: 89 additions & 177 deletions contracts/test/IntegrationTestBase.sol

Large diffs are not rendered by default.

32 changes: 11 additions & 21 deletions contracts/test/IntegrationTestPresets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
56 changes: 56 additions & 0 deletions contracts/test/helpers/DiamondFacetsHelper.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
88 changes: 88 additions & 0 deletions contracts/test/helpers/GatewayFacetsHelper.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
30 changes: 30 additions & 0 deletions contracts/test/helpers/RegistryFacetsHelper.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
75 changes: 75 additions & 0 deletions contracts/test/helpers/SubnetActorFacetsHelper.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit 3bcef48

Please sign in to comment.