Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tests for Crosschain_Base and PP_Connext_Crosschain - DRAFT #694

Draft
wants to merge 108 commits into
base: feature/crosschain-paymentProcessor
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
dc03239
add cross-chain module, contracts compile
leeftk Oct 30, 2024
b4b0c1f
refactor tempalte module
leeftk Nov 1, 2024
7041fa4
fix compile issues
zzzuhaibmohd Nov 4, 2024
6cd983c
add todo's for implementation contract
leeftk Nov 5, 2024
07e9b81
added notes handoff
leeftk Nov 5, 2024
a12749e
fix compile issues before everclear impl
zzzuhaibmohd Nov 5, 2024
793d8a7
add everclear poc impl
zzzuhaibmohd Nov 5, 2024
af340d1
add everclear logic impl
zzzuhaibmohd Nov 7, 2024
b565de2
remove old templates
leeftk Nov 7, 2024
7da377d
code compile issue solved
zzzuhaibmohd Nov 7, 2024
865e268
fix minor dependency
zzzuhaibmohd Nov 7, 2024
960fcd2
remove file
zzzuhaibmohd Nov 7, 2024
fc33b2e
added contract for bridge testing
leeftk Nov 8, 2024
7584abb
add tests for base contracts
leeftk Nov 8, 2024
7f20d42
fix file structure
leeftk Nov 8, 2024
5ff8e1c
uncomment bridge return value and run fmt
leeftk Nov 9, 2024
dfdb828
change contract to abstract
leeftk Nov 12, 2024
0fa97c5
add logic to PP_Connext_Crosschain
leeftk Nov 13, 2024
c06d6ec
fix inheritance chain
leeftk Nov 14, 2024
802f3b5
remove function impl
leeftk Nov 15, 2024
e0608ea
seperate interfaces
leeftk Nov 15, 2024
6909a38
remove unecessary state variables
leeftk Nov 18, 2024
54f1eea
remove unecessary state variables
leeftk Nov 18, 2024
09047da
add unit tests for Connext
zzzuhaibmohd Nov 8, 2024
d8f88b9
unit test processPayments & xcall
zzzuhaibmohd Nov 8, 2024
46df46a
fix directory structure
leeftk Nov 12, 2024
a5a10bf
unit test chainid test
zzzuhaibmohd Nov 11, 2024
5a78d5f
unit test processpayments test
zzzuhaibmohd Nov 11, 2024
ac662d5
unit test paymentId check and test
zzzuhaibmohd Nov 11, 2024
4b74169
unit test chainId and ProcessPayment
zzzuhaibmohd Nov 12, 2024
32b2c05
unit test paymentId check and test
zzzuhaibmohd Nov 12, 2024
567815e
resolve conflicts
zzzuhaibmohd Nov 13, 2024
af9df30
add unit test verify bridgeData
zzzuhaibmohd Nov 13, 2024
2c96138
add unit test process payments insufficient balance
zzzuhaibmohd Nov 13, 2024
330cbc2
add feedback comment
leeftk Nov 18, 2024
be2fc27
fixed unit tests after rebase
zzzuhaibmohd Nov 19, 2024
6928ec0
add comments and fuzz tests
leeftk Nov 20, 2024
ca1b6a8
refrator test file and add unit tests
zzzuhaibmohd Nov 20, 2024
3468df9
verify executionData & add unit tests
zzzuhaibmohd Nov 20, 2024
293db4f
add ttl validation
leeftk Nov 21, 2024
e96b3fb
refractor unit tests
zzzuhaibmohd Nov 22, 2024
45816bf
add unit tests CrosschainBase_v1
zzzuhaibmohd Nov 22, 2024
f460be3
singlePayment fuzz tests added
zzzuhaibmohd Nov 25, 2024
c251997
move balance setup internal function
zzzuhaibmohd Nov 25, 2024
01f5ff8
multiplePayment fuzz tests added
zzzuhaibmohd Nov 25, 2024
8e0b414
camelcase changes for CrossChainBase contract
zzzuhaibmohd Nov 26, 2024
6300df5
add gherking comments
leeftk Nov 27, 2024
084e594
remove unecessary variables and add comments
leeftk Nov 27, 2024
3fff1b7
add more gherkin to each test
leeftk Nov 27, 2024
8fc2cd8
add validation of ttl
leeftk Nov 27, 2024
d3d0af3
add getbridgedata and natspec
leeftk Nov 27, 2024
24ba1ce
chore: cleaned code changed event name
leeftk Nov 27, 2024
eb14eeb
add templates folder
leeftk Nov 28, 2024
167f624
emit PaymentProcessed via Interface
zzzuhaibmohd Nov 28, 2024
66f5208
chore: use exposed payment processor
zzzuhaibmohd Nov 28, 2024
bdb3c65
update gherkin for tests
leeftk Dec 9, 2024
ee1e448
add assertions to payment processor test
leeftk Dec 9, 2024
918b836
update gherkin and remove vs code settings
leeftk Dec 9, 2024
3c98fa7
feat: add cancel payments
leeftk Dec 11, 2024
855f6f2
feat:add cancel payment & test
leeftk Dec 12, 2024
d64d977
feat:add retry payments & test
leeftk Dec 12, 2024
cedbb59
fix:retry payments test
leeftk Dec 12, 2024
f1e0e69
fix:format
leeftk Dec 12, 2024
a15150f
fix:fmt and standard updates
leeftk Dec 12, 2024
c3fbdf8
chore:delete bridging folder
leeftk Dec 13, 2024
197a65a
fix:rebase onto feature
leeftk Dec 17, 2024
90615c2
chore:remove redundant files
leeftk Dec 17, 2024
8f34e00
fix:add standard to test file
leeftk Dec 17, 2024
18aa1f4
chore:remove redundant files
leeftk Dec 17, 2024
102cbd4
fix:update crosschain base format
leeftk Dec 17, 2024
b93500c
fix:delete console import
leeftk Dec 17, 2024
9bdbf8a
fix:move files to proper directories
leeftk Dec 17, 2024
d6bdba6
fix:remove impl for functions
leeftk Jan 6, 2025
bd55516
fix: fix retry failed payments
leeftk Jan 6, 2025
ed26634
chore:add comments for clarity
leeftk Jan 6, 2025
81e4275
fix:remove files
leeftk Jan 7, 2025
54e595f
add tests for unhappy paths
leeftk Jan 7, 2025
a22d76b
chore:change mapping name
leeftk Jan 7, 2025
d986ff1
remove redundant file
leeftk Jan 7, 2025
c9a9d9a
chore:rename file
leeftk Jan 7, 2025
e17ae52
add base test file
leeftk Jan 7, 2025
a3d5311
fix: remove chainid impl
zzzuhaibmohd Jan 13, 2025
6d0378c
chore: add unit tests
zzzuhaibmohd Jan 13, 2025
f4164af
chore: add unit tests
zzzuhaibmohd Jan 16, 2025
89184cd
fix: make unit tests generic input
zzzuhaibmohd Jan 16, 2025
3e76524
fix: process payment if else
zzzuhaibmohd Jan 17, 2025
3a753d4
chore: add unit tests for PP_Crosschain_v1
zzzuhaibmohd Jan 20, 2025
7adcca7
fix: add auth checks and retrypayment issue and format unit tests
zzzuhaibmohd Jan 23, 2025
238254c
fix: change test to fuzz tests, fix minor bugs
zzzuhaibmohd Jan 24, 2025
e7d0660
fix: code format invertor standard
zzzuhaibmohd Jan 24, 2025
002b3f6
fix: change the _validateTransferRequest msg.sender to client
zzzuhaibmohd Jan 27, 2025
4e5b488
fix: refractor the unit tests
zzzuhaibmohd Jan 29, 2025
d400668
chore: add unit tests for client.amountPaid functionality
zzzuhaibmohd Feb 7, 2025
a3564ea
fix: track processedIntentId fix
zzzuhaibmohd Feb 12, 2025
b4d9f77
feat: add unclaimed amount impl
zzzuhaibmohd Feb 13, 2025
85ca775
fix: format code
zzzuhaibmohd Feb 13, 2025
8a406cd
fix: follow invertor standard
zzzuhaibmohd Feb 17, 2025
baf13d7
Merge remote-tracking branch 'upstream/feature/crosschain-paymentProc…
Zitzak Feb 19, 2025
289221e
Merge remote-tracking branch 'upstream/feature/crosschain-paymentProc…
Zitzak Feb 19, 2025
377f888
refactor: Rename ERC20PaymentClientBase_v1 to v2
Zitzak Feb 19, 2025
6c351c8
refactor: adapt implementation and tests to new Payment order struct
Zitzak Feb 19, 2025
27dd77c
feat(IERC20PaymentClientBase_v2): add maxFee and TTL to payment order…
Zitzak Feb 19, 2025
e53ebb5
refactor: CrossChainBase_v1 & ICrossChainBase_v1
Zitzak Feb 19, 2025
7dfb039
refactor: PP_Crosschain_v1 & IPP_Crosschain_v1
Zitzak Feb 19, 2025
b9e7168
refactor: PP_Connext_Crosschain_v1 & IPP_Connext_Crosschain_v1
Zitzak Feb 19, 2025
a3534bb
test: WIP
Zitzak Feb 19, 2025
db1ec3e
fix: code refactor & fix unit tests
zzzuhaibmohd Feb 24, 2025
34961e1
fix: code refactor & fix unit tests
zzzuhaibmohd Feb 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: fix retry failed payments
leeftk committed Jan 6, 2025
commit bd555168c6827eb7a45ab665a5b231f7254bc03b
106 changes: 51 additions & 55 deletions src/modules/paymentProcessor/PP_Connext_Crosschain_v1.sol
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
mapping(
address paymentClient
=> mapping(
address recipient => mapping(bytes32 intentId => uint amount)
address recipient => mapping(bytes intentId => uint amount)
)
) public failedTransfers;

@@ -88,76 +88,88 @@ contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
) external {
IERC20PaymentClientBase_v1.PaymentOrder[] memory orders;
(orders,,) = client.collectPaymentOrders();

address clientAddress = address(client);
for (uint i = 0; i < orders.length; i++) {
bytes memory bridgeData = _executeBridgeTransfer(
orders[i], executionData, address(client)
);

_bridgeData[i] = bridgeData;
emit PaymentOrderProcessed(
address(client),
orders[i].recipient,
orders[i].paymentToken,
orders[i].amount,
orders[i].start,
orders[i].cliff,
orders[i].end
);
_paymentId++;
intentId[address(client)][orders[i].recipient] = bytes32(bridgeData);
client.amountPaid(orders[i].paymentToken, orders[i].amount);
bytes memory bridgeData =
_executeBridgeTransfer(orders[i], executionData);

if (bytes32(bridgeData) == bytes32(0)) {
// Handle failed transfer
failedTransfers[clientAddress][orders[i].recipient][executionData]
= orders[i].amount;
emit TransferFailed(
clientAddress,
orders[i].recipient,
executionData,
orders[i].amount
);
} else {
// Handle successful transfer
_bridgeData[i] = bridgeData;
emit PaymentOrderProcessed(
address(client),
orders[i].recipient,
orders[i].paymentToken,
orders[i].amount,
orders[i].start,
orders[i].cliff,
orders[i].end
);
_paymentId++;
intentId[address(client)][orders[i].recipient] =
bytes32(bridgeData);
client.amountPaid(orders[i].paymentToken, orders[i].amount);
}
}
}

/**
* @notice Cancels a pending transfer and returns funds to the client
* @param client The payment client address
* @param recipient The recipient address
* @param pendingIntentId The intentId to cancel
* @param executionData The execution data to cancel
* @param order The payment order details
*/
function cancelTransfer(
address client,
address recipient,
bytes32 pendingIntentId,
bytes memory executionData,
IERC20PaymentClientBase_v1.PaymentOrder memory order
) external {
_validateTransferRequest(client, recipient, pendingIntentId);
_cleanupFailedTransfer(client, recipient, pendingIntentId);
_validateTransferRequest(client, recipient, executionData);
_cleanupFailedTransfer(client, recipient, executionData);

if (!IERC20(order.paymentToken).transfer(recipient, order.amount)) {
revert FailedTransfer();
}

emit TransferCancelled(client, recipient, pendingIntentId, order.amount);
emit TransferCancelled(client, recipient, executionData, order.amount);
}

/**
* @notice Retries a previously failed transfer
* @param client The payment client address
* @param recipient The recipient address
* @param pendingIntentId The failed intent ID
* @param order The payment order details
* @param executionData New execution data for retry
*/
function retryFailedTransfer(
address client,
address recipient,
bytes32 pendingIntentId,
IERC20PaymentClientBase_v1.PaymentOrder memory order,
bytes memory executionData
bytes memory executionData,
bytes memory newExecutionData,
IERC20PaymentClientBase_v1.PaymentOrder memory order
) external {
_validateTransferRequest(client, recipient, pendingIntentId);
_validateTransferRequest(client, recipient, executionData);

bytes32 newIntentId = _createCrossChainIntent(order, executionData);
bytes32 newIntentId = _createCrossChainIntent(order, newExecutionData);
if (newIntentId == bytes32(0)) {
revert Module__PP_Crosschain__MessageDeliveryFailed(
8453, 8453, executionData
);
}

_cleanupFailedTransfer(client, recipient, pendingIntentId);
_cleanupFailedTransfer(client, recipient, executionData);
intentId[client][recipient] = newIntentId;
}

@@ -181,24 +193,13 @@ contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
* @dev Execute the cross-chain bridge transfer
* @param order The payment order containing transfer details
* @param executionData Additional execution parameters
* @param client The client address
* @return bridgeData Data returned by the bridge implementation
*/
function _executeBridgeTransfer(
IERC20PaymentClientBase_v1.PaymentOrder memory order,
bytes memory executionData,
address client
) internal returns (bytes memory) {
bytes memory executionData
) internal override returns (bytes memory) {
bytes32 _intentId = _createCrossChainIntent(order, executionData);

if (_intentId == bytes32(0)) {
failedTransfers[client][order.recipient][_intentId] = order.amount;
intentId[client][order.recipient] = _intentId;
emit TransferFailed(
client, order.recipient, _intentId, order.amount
);
}

return abi.encode(_intentId);
}

@@ -252,23 +253,18 @@ contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
* @dev Validates a transfer request
* @param client The payment client address
* @param recipient The recipient address
* @param pendingIntentId The intent ID to validate
* @return The amount of the failed transfer
* @param executionData The execution data
*/
function _validateTransferRequest(
address client,
address recipient,
bytes32 pendingIntentId
bytes memory executionData
) internal view returns (uint) {
if (msg.sender != client) {
revert Module__InvalidAddress();
}

if (intentId[client][recipient] != pendingIntentId) {
revert Module__PP_Crosschain__InvalidIntentId();
}

uint failedAmount = failedTransfers[client][recipient][pendingIntentId];
uint failedAmount = failedTransfers[client][recipient][executionData];
if (failedAmount == 0) {
revert Module__CrossChainBase__InvalidAmount();
}
@@ -280,15 +276,15 @@ contract PP_Connext_Crosschain_v1 is PP_Crosschain_v1 {
* @dev Cleans up storage after handling a failed transfer
* @param client The payment client address
* @param recipient The recipient address
* @param pendingIntentId The intent ID to clean up
* @param executionData The execution data
*/
function _cleanupFailedTransfer(
address client,
address recipient,
bytes32 pendingIntentId
bytes memory executionData
) internal {
delete intentId[client][recipient];
delete failedTransfers[client][recipient][pendingIntentId];
delete failedTransfers[client][recipient][executionData];
}

/**
Original file line number Diff line number Diff line change
@@ -68,5 +68,5 @@ abstract contract CrossChainBase_v1 is ICrossChainBase_v1, Module_v1 {
function _executeBridgeTransfer(
IERC20PaymentClientBase_v1.PaymentOrder memory order,
bytes memory executionData
) internal virtual returns (bytes memory)
) internal virtual returns (bytes memory);
}
6 changes: 3 additions & 3 deletions src/modules/paymentProcessor/interfaces/IPP_Crosschain_v1.sol
Original file line number Diff line number Diff line change
@@ -13,12 +13,12 @@ interface IPP_Crosschain_v1 is IPaymentProcessor_v1 {
/// @notice Emitted when a cross-chain transfer fails to complete
/// @param client The address initiating the transfer
/// @param recipient The intended recipient of the transfer
/// @param intentId The unique identifier for this transfer attempt
/// @param executionData The unique identifier for this transfer attempt
/// @param amount The amount that failed to transfer
event TransferFailed(
address indexed client,
address indexed recipient,
bytes32 indexed intentId,
bytes indexed executionData,
uint amount
);

@@ -42,7 +42,7 @@ interface IPP_Crosschain_v1 is IPaymentProcessor_v1 {
event TransferCancelled(
address indexed client,
address indexed recipient,
bytes32 indexed intentId,
bytes indexed intentId,
uint amount
);

35 changes: 20 additions & 15 deletions test/modules/paymentProcessor/PP_Connext_Crosschain_v1_Test.t.sol
Original file line number Diff line number Diff line change
@@ -508,16 +508,21 @@ contract PP_Connext_Crosschain_v1_Test is ModuleTest {
IERC20PaymentClientBase_v1.PaymentOrder[] memory orders =
_setupSinglePayment(recipient, amount);

// Store the initial execution data that will fail
bytes memory failingExecutionData = abi.encode(333, 1); // maxFee of 333 will cause failure

// First attempt with high maxFee to force failure
paymentProcessor.processPayments(
IERC20PaymentClientBase_v1(address(paymentClient)),
abi.encode(333, 1) // maxFee of 333 will cause failure
failingExecutionData
);

// Verify failed transfer was recorded
// Verify failed transfer was recorded with the failing execution data
assertEq(
paymentProcessor.failedTransfers(
address(paymentClient), recipient, bytes32(0)
address(paymentClient),
recipient,
failingExecutionData // Use the same execution data that was used in processPayments
),
orders[0].amount
);
@@ -527,16 +532,18 @@ contract PP_Connext_Crosschain_v1_Test is ModuleTest {
paymentProcessor.retryFailedTransfer(
address(paymentClient),
recipient,
bytes32(0),
orders[0],
abi.encode(0, 1) // proper maxFee and ttl
failingExecutionData, // Old execution data that failed
executionData, // New execution data for retry
orders[0]
);

// Verify:
// 1. Failed transfer record was cleared
assertEq(
paymentProcessor.failedTransfers(
address(paymentClient), recipient, bytes32(0)
address(paymentClient),
recipient,
failingExecutionData // Check using the original failing execution data
),
0
);
@@ -564,30 +571,28 @@ contract PP_Connext_Crosschain_v1_Test is ModuleTest {
IERC20PaymentClientBase_v1.PaymentOrder[] memory orders =
_setupSinglePayment(recipient, amount);
paymentClient.addPaymentOrder(orders[0]);
bytes memory executionData = abi.encode(333, 1);
//call processPayments with maxFee = 333
paymentProcessor.processPayments(
IERC20PaymentClientBase_v1(address(paymentClient)),
abi.encode(333, 1)
IERC20PaymentClientBase_v1(address(paymentClient)), executionData
);
console2.log("Fucker who seneeed", address(this));
// see if failed failedTransfers updates
assertEq(
paymentProcessor.failedTransfers(
address(paymentClient), recipient, bytes32(0)
address(paymentClient), recipient, executionData
),
orders[0].amount
);

uint failedIntentId = paymentProcessor.failedTransfers(
address(paymentClient), recipient, bytes32(0)
address(paymentClient), recipient, executionData
);
console2.log("AMOUNT", failedIntentId);
assertEq(failedIntentId, orders[0].amount);

// Cancel as recipient
vm.prank(address(paymentClient));
paymentProcessor.cancelTransfer(
address(paymentClient), recipient, bytes32(0), orders[0]
address(paymentClient), recipient, executionData, orders[0]
);

// Verify intentId was cleared
@@ -637,7 +642,7 @@ contract PP_Connext_Crosschain_v1_Test is ModuleTest {

vm.expectRevert(IModule_v1.Module__InvalidAddress.selector);
paymentProcessor.cancelTransfer(
address(paymentClient), testRecipient, pendingIntentId, order
address(paymentClient), testRecipient, executionData, order
);
}

Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ contract CrossChainBase_v1_Test is ModuleTest {
function setUp() public {
//This function is used to setup the unit test
//Deploy the SuT
address impl = address(new CrossChainBase_v1_Exposed(block.chainid));
address impl = address(new CrossChainBase_v1_Exposed());
crossChainBase = CrossChainBase_v1_Exposed(Clones.clone(impl));

//Setup the module to test
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ contract CrossChainBase_v1_Test is ModuleTest {
function setUp() public {
//This function is used to setup the unit test
//Deploy the SuT
address impl = address(new CrossChainBase_v1_Exposed(block.chainid));
address impl = address(new CrossChainBase_v1_Exposed());
crossChainBase = CrossChainBase_v1_Exposed(Clones.clone(impl));

//Setup the module to test
Original file line number Diff line number Diff line change
@@ -8,9 +8,29 @@ import {IERC20PaymentClientBase_v1} from
"@lm/interfaces/IERC20PaymentClientBase_v1.sol";

contract CrossChainBase_v1_Exposed is CrossChainBase_v1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contract can be moved to the testing file folder, see code of conduct Folder Structure -> bullet point test

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the other exposed mock

constructor(uint chainId_) CrossChainBase_v1() {}
///// @inheritdoc CrossChainBase_v1

function _executeBridgeTransfer(
IERC20PaymentClientBase_v1.PaymentOrder memory order,
bytes memory executionData
) internal pure override returns (bytes memory) {
return "";
}

function getBridgeData(uint paymentId)
public
pure
override
returns (bytes memory)
{
return "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can return the values from the _bridgedata mapping, which then can be tested

}

function processPayments(IERC20PaymentClientBase_v1 client)
external
override
{}

function exposed_executeBridgeTransfer(
IERC20PaymentClientBase_v1.PaymentOrder memory order,
bytes memory executionData
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ contract PP_Connext_Crosschain_v1_Exposed is PP_Connext_Crosschain_v1 {
function exposed_setFailedTransfer(
address client,
address recipient,
bytes32 intentId,
bytes memory intentId,
uint amount
) external {
failedTransfers[client][recipient][intentId] = amount;