Skip to content

Commit

Permalink
chore:delete bridging folder
Browse files Browse the repository at this point in the history
  • Loading branch information
leeftk committed Dec 17, 2024
1 parent a15150f commit c3fbdf8
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 72 deletions.
6 changes: 3 additions & 3 deletions src/modules/paymentProcessor/PP_Connext_Crosschain_v1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
) external {
_validateTransferRequest(client, recipient, pendingIntentId);

bytes32 newIntentId = createCrossChainIntent(order, executionData);
bytes32 newIntentId = _createCrossChainIntent(order, executionData);
if (newIntentId == bytes32(0)) {
revert Module__PP_Crosschain__MessageDeliveryFailed(
8453, 8453, executionData
Expand Down Expand Up @@ -189,7 +189,7 @@ contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
bytes memory executionData,
address client
) internal returns (bytes memory) {
bytes32 _intentId = createCrossChainIntent(order, executionData);
bytes32 _intentId = _createCrossChainIntent(order, executionData);

if (_intentId == bytes32(0)) {
failedTransfers[client][order.recipient][_intentId] = order.amount;
Expand All @@ -208,7 +208,7 @@ contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
* @param executionData Additional execution parameters
* @return The ID of the created intent
*/
function createCrossChainIntent(
function _createCrossChainIntent(
IERC20PaymentClientBase_v1.PaymentOrder memory order,
bytes memory executionData
) internal returns (bytes32) {
Expand Down
3 changes: 1 addition & 2 deletions src/modules/paymentProcessor/abstracts/CrossChainBase_v1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import {ICrossChainBase_v1} from "../interfaces/ICrosschainBase_v1.sol";
* @title Cross-chain Base Contract
* @notice Abstract base contract providing core cross-chain functionality for payment
* processors.
* @dev This contract implements fundamental cross-chain operations and provides:
* @dev This contract exposes fundamental cross-chain operations and provides:
* - Bridge data storage and retrieval functionality
* - Abstract interface for bridge transfer execution
* - Integration with the Module_v1 base contract
* - Implementation of ICrossChainBase_v1 interface
* - ERC165 interface support for cross-chain functionality
* @custom:security-contact [email protected]
* In case of any concerns or findings, please refer to our
* Security Policy at security.inverter.network or email us
Expand Down
175 changes: 125 additions & 50 deletions test/modules/paymentProcessor/abstracts/CrosschainBase_v1.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.0;

//Internal Dependencies
// Internal
import {
ModuleTest,
IModule_v1,
Expand All @@ -10,77 +10,152 @@ import {
import {OZErrors} from "test/utils/errors/OZErrors.sol";
import {ICrossChainBase_v1} from
"src/modules/paymentProcessor/interfaces/ICrosschainBase_v1.sol";
import {CrosschainBase_v1} from
"src/modules/paymentProcessor/abstracts/CrosschainBase_v1.sol";
//External Dependencies
import {Clones} from "@oz/proxy/Clones.sol";

//Tests and Mocks
// import cr
import {CrossChainBase_v1} from
"src/modules/paymentProcessor/abstracts/CrossChainBase_v1.sol";
import {
IERC20PaymentClientBase_v1,
ERC20PaymentClientBaseV1Mock,
ERC20Mock
} from "test/utils/mocks/modules/paymentClient/ERC20PaymentClientBaseV1Mock.sol";
//import exposed
import {CrosschainBase_v1_Exposed} from "./CrosschainBase_v1_Exposed.sol";

//System under test (SuT)
// import {
// IPP_CrossChain_v1,
// PP_CrossChain_v1,
// IPaymentProcessor_v1
// } from "src/templates/modules/PP_Template_v1.sol";
import {CrossChainBase_v1_Exposed} from "./CrossChainBase_v1_Exposed.sol";

import {IPaymentProcessor_v1} from
"src/orchestrator/interfaces/IOrchestrator_v1.sol";
import {ICrossChainBase_v1} from
"src/modules/paymentProcessor/interfaces/ICrosschainBase_v1.sol";
//External Dependencies
import {OZErrors} from "test/utils/errors/OZErrors.sol";
import {Clones} from "@oz/proxy/Clones.sol";

/**
* @title Inverter Template Payment Processor
*
* @notice Basic template payment processor used to showcase the unit testing setup
*
* @dev Not all functions are tested in this template. Placeholders of the functions that are not tested are added
* into the contract. This test showcases the following:
* - Inherit from the ModuleTest contract to enable interaction with the Inverter workflow.
* - Showcases the setup of the workflow, uses in test unit tests.
* - Pre-defined layout for all setup and functions to be tested.
* - Shows the use of Gherkin for documenting the testing. VS Code extension used for formatting is recommended.
* - Shows the use of the modifierInPlace pattern to test the modifier placement.
*
* @custom:security-contact [email protected]
* In case of any concerns or findings, please refer to our Security Policy
* at security.inverter.network or email us directly!
*
* @author Inverter Network
*/
contract CrosschainBase_v1_Test is ModuleTest {
contract CrossChainBase_v1_Test is ModuleTest {
//--------------------------------------------------------------------------
//Constants
//--------------------------------------------------------------------------
//State

//Mocks
ERC20PaymentClientBaseV1Mock paymentClient;

//System under test (SuT)
CrosschainBase_v1 public paymentProcessor;
//PP_CrossChain_v1_Exposed public paymentProcessor;
CrossChainBase_v1_Exposed public crossChainBase;

//--------------------------------------------------------------------------
//Setup
function setUp() public {}
function setUp() public {
//This function is used to setup the unit test
//Deploy the SuT
address impl = address(new CrossChainBase_v1_Exposed(block.chainid));
crossChainBase = CrossChainBase_v1_Exposed(Clones.clone(impl));

//Setup the module to test
_setUpOrchestrator(crossChainBase);

//General setup for other contracts in the workflow
_authorizer.setIsAuthorized(address(this), true);

//Initiate the PP with the medata and config data
crossChainBase.init(_orchestrator, _METADATA, abi.encode(1));

//Setup other modules needed in the unit tests.
//In this case a payment client is needed to test the PP_Template_v1.
impl = address(new ERC20PaymentClientBaseV1Mock());
paymentClient = ERC20PaymentClientBaseV1Mock(Clones.clone(impl));
//Adding the payment client is done through a timelock mechanism
_orchestrator.initiateAddModuleWithTimelock(address(paymentClient));
vm.warp(block.timestamp + _orchestrator.MODULE_UPDATE_TIMELOCK());
_orchestrator.executeAddModule(address(paymentClient));
//Init payment client
paymentClient.init(_orchestrator, _METADATA, bytes(""));
paymentClient.setIsAuthorized(address(crossChainBase), true);
paymentClient.setToken(_token);
}
//--------------------------------------------------------------------------
//Test: Initialization
/*
└── Given the contract is not initialized
└── When initializing the contract
└── Then it should set the correct orchestrator address */

function testInit() public override(ModuleTest) {
assertEq(address(crossChainBase.orchestrator()), address(_orchestrator));
}

//--------------------------------------------------------------------------
//Test: Interface Support
/*
└── Given the contract is initialized
└── When checking for ICrossChainBase_v1 interface support
└── Then it should return true
└── When checking for an unknown interface
└── Then it should return false */
function testSupportsInterface() public {
// Test for ICrossChainBase_v1 interface support
bytes4 interfaceId = type(ICrossChainBase_v1).interfaceId;
assertTrue(crossChainBase.supportsInterface(interfaceId));
}

function testSupportsInterface_revertsGivenUnknownInterface() public {
bytes4 randomInterfaceId = bytes4(keccak256("random()"));
assertFalse(crossChainBase.supportsInterface(randomInterfaceId));
}

//Test if the orchestrator is correctly set
function testInit() public override(ModuleTest) {}
/*
└── Given the contract is already initialized
└── When trying to reinitialize
└── Then it should revert with Initializable__InvalidInitialization */
function testReinitFails() public override(ModuleTest) {
vm.expectRevert(OZErrors.Initializable__InvalidInitialization);
crossChainBase.init(_orchestrator, _METADATA, abi.encode(1));
}
//--------------------------------------------------------------------------
//Test: executeBridgeTransfer

/*
└── Given an empty payment order is created
└── When executeBridgeTransfer is called
└── Then it should return empty bytes */
function testExecuteBridgeTransfer_worksGivenEmptyPaymentOrder() public {
address[] memory setupRecipients = new address[](1);
setupRecipients[0] = address(1);
uint[] memory setupAmounts = new uint[](1);
setupAmounts[0] = 100 ether;

IERC20PaymentClientBase_v1.PaymentOrder[] memory orders =
_createPaymentOrders(1, setupRecipients, setupAmounts);
paymentClient.addPaymentOrders(orders);

//Test the interface support
function testSupportsInterface() public {}
bytes memory executionData = abi.encode(0, 0); //maxFee and ttl setup

bytes memory result = crossChainBase.exposed_executeBridgeTransfer(
orders[0], executionData
);
assertEq(result, bytes(""));
}
//--------------------------------------------------------------------------
//Helper Functions

//Test the reinit function
function testReinitFails() public override(ModuleTest) {}
function _createPaymentOrders(
uint orderCount,
address[] memory recipients,
uint[] memory amounts
)
internal
view
returns (IERC20PaymentClientBase_v1.PaymentOrder[] memory)
{
// Sanity checks for array lengths
require(
recipients.length == orderCount && amounts.length == orderCount,
"Array lengths must match orderCount"
);
IERC20PaymentClientBase_v1.PaymentOrder[] memory orders =
new IERC20PaymentClientBase_v1.PaymentOrder[](orderCount);
for (uint i = 0; i < orderCount; i++) {
orders[i] = IERC20PaymentClientBase_v1.PaymentOrder({
recipient: recipients[i],
paymentToken: address(0xabcd),
amount: amounts[i],
start: block.timestamp,
cliff: 0,
end: block.timestamp + 1 days
});
}
return orders;
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.23;

// Internal Dependencies
//import {PP_CrossChain_v1} from "src/templates/modules/PP_Template_v1.sol";
import {CrosschainBase_v1} from
"src/modules/paymentProcessor/abstracts/CrosschainBase_v1.sol";
import {CrossChainBase_v1} from
"src/modules/paymentProcessor/abstracts/CrossChainBase_v1.sol";
import {IERC20PaymentClientBase_v1} from
"@lm/interfaces/IERC20PaymentClientBase_v1.sol";

contract CrosschainBase_v1_Exposed is CrosschainBase_v1 {
/// @notice Implementation of the bridge transfer logic using EverClear
///// @inheritdoc CrosschainBase_v1
contract CrossChainBase_v1_Exposed is CrossChainBase_v1 {
constructor(uint chainId_) CrossChainBase_v1() {}
///// @inheritdoc CrossChainBase_v1

function exposed_executeBridgeTransfer(
IERC20PaymentClientBase_v1.PaymentOrder memory order,
bytes memory executionData
) external payable returns (bytes memory) {
return _executeBridgeTransfer(order, executionData);
}

function _executeBridgeTransfer(
IERC20PaymentClientBase_v1.PaymentOrder memory order,
bytes memory executionData
) internal override(CrosschainBase_v1) returns (bytes memory) {
// Add default return value here for testing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract PP_Connext_Crosschain_v1_Exposed is PP_Connext_Crosschain_v1 {
IERC20PaymentClientBase_v1.PaymentOrder memory order,
bytes memory executionData
) external returns (bytes32) {
return createCrossChainIntent(order, executionData);
return _createCrossChainIntent(order, executionData);
}

function exposed_setFailedTransfer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import {PP_Connext_Crosschain_v1} from
import {CrossChainBase_v1} from
"src/modules/paymentProcessor/abstracts/CrossChainBase_v1.sol";
import {CrossChainBase_v1_Exposed} from
"test/modules/paymentProcessor/bridging/abstracts/CrossChainBase_v1_Exposed.sol";
"test/modules/paymentProcessor/abstracts/CrossChainBase_v1_Exposed.sol";
import {IERC20PaymentClientBase_v1} from
"@lm/interfaces/IERC20PaymentClientBase_v1.sol";
import {ICrossChainBase_v1} from
"src/modules/paymentProcessor/interfaces/ICrosschainBase_v1.sol";
import {IPaymentProcessor_v1} from
"src/modules/paymentProcessor/IPaymentProcessor_v1.sol";
import {PP_Connext_Crosschain_v1_Exposed} from
"test/modules/paymentProcessor/bridging/abstracts/PP_Connext_Crosschain_v1_Exposed.sol";
"test/modules/paymentProcessor/abstracts/PP_Connext_Crosschain_v1_Exposed.sol";
// Tests and Mocks
import {Mock_EverclearPayment} from
"test/modules/paymentProcessor/bridging/abstracts/mocks/Mock_EverclearPayment.sol";
"test/modules/paymentProcessor/abstracts/mocks/Mock_EverclearPayment.sol";
import {
IERC20PaymentClientBase_v1,
ERC20PaymentClientBaseV1Mock
Expand Down

0 comments on commit c3fbdf8

Please sign in to comment.