-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
139 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
@@ -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; | ||
} | ||
} |
19 changes: 6 additions & 13 deletions
19
test/modules/paymentProcessor/abstracts/CrosschainBase_v1_Exposed.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.