-
Notifications
You must be signed in to change notification settings - Fork 30
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
Parod/fb v2 multicall add test #3335
Conversation
WalkthroughThe changes in this pull request enhance the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (2)
packages/contracts-rfq/test/integration/MulticallTarget.t.sol (2)
266-267
: Define a constant for the repeatedhex"02"
parameter.The value
hex"02"
is used multiple times in the code for theprove
action. Defining it as a constant improves readability and maintainability.Apply this diff to define the constant:
+bytes constant PROVE_DATA = hex"02"; function getDataMany( TestBridgeTransactionWithMetadata[] memory testBridgeTxns, TestAction action ) public view returns (bytes[] memory data) { data = new bytes[](testBridgeTxns.length); for (uint256 i = 0; i < testBridgeTxns.length; i++) { if (action == TestAction.prove) { - data[i] = abi.encodeCall(IFastBridge.prove, (testBridgeTxns[i].encodedData, hex"02")); + data[i] = abi.encodeCall(IFastBridge.prove, (testBridgeTxns[i].encodedData, PROVE_DATA)); } // ... } } function executeSequentialTransactions( TestBridgeTransactionWithMetadata[] memory transactions, TestAction action, address pranker ) internal { for (uint256 i = 0; i < transactions.length; i++) { if (action == TestAction.prove) { vm.prank(pranker); - IFastBridge(fastBridge).prove(transactions[i].encodedData, hex"02"); + IFastBridge(fastBridge).prove(transactions[i].encodedData, PROVE_DATA); } // ... } }Also applies to: 337-337
298-298
: Consider defining the magic number15
as a constant.The number
15
is used in bothtest_manyActions_sequentialNonMulticall
andtest_manyActions_multicall
. Defining it as a constant improves code readability and makes future adjustments easier.Apply this diff to introduce a constant:
+uint8 constant NUM_TRANSACTIONS = 15; function test_manyActions_sequentialNonMulticall() public { // send X contiguous bridges, proofs, and claims -- and X non-contiguous relays to the same bridger - manyActions_flow(15, TestExecutionMode.Sequential_NonMulticall); + manyActions_flow(NUM_TRANSACTIONS, TestExecutionMode.Sequential_NonMulticall); } function test_manyActions_multicall() public { // send X contiguous bridges, proofs, and claims -- and X non-contiguous relays to the same bridger - manyActions_flow(15, TestExecutionMode.Multicall); + manyActions_flow(NUM_TRANSACTIONS, TestExecutionMode.Multicall); }Also applies to: 303-303
for (uint8 i = 0; i < transactions.length; i++) { | ||
if (action == TestAction.bridge) { | ||
// bridge already pranks as user, no need to prank | ||
bridge(transactions[i].transaction, user); | ||
} else if (action == TestAction.prove) { | ||
vm.prank(pranker); | ||
IFastBridge(fastBridge).prove(transactions[i].encodedData, hex"02"); | ||
} else if (action == TestAction.claim) { | ||
vm.prank(pranker); | ||
IFastBridge(fastBridge).claim(transactions[i].encodedData, claimTo); | ||
} else if (action == TestAction.relay) { | ||
vm.prank(pranker); | ||
IFastBridge(fastBridge).relay(transactions[i].encodedData); | ||
} | ||
// Check status after each action | ||
manyActions_checkStatusAfter(transactions[i].txId, action); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use uint256
for loop index to prevent overflow in executeSequentialTransactions
.
In the executeSequentialTransactions
function, the loop variable i
is declared as uint8
. If transactions.length
exceeds 255, the uint8
index may overflow, causing unexpected behavior. Changing i
to uint256
ensures correct operation with larger arrays.
Apply this diff to fix the issue:
function executeSequentialTransactions(
TestBridgeTransactionWithMetadata[] memory transactions,
TestAction action,
address pranker
)
internal
{
- for (uint8 i = 0; i < transactions.length; i++) {
+ for (uint256 i = 0; i < transactions.length; i++) {
if (action == TestAction.bridge) {
// bridge already pranks as user, no need to prank
bridge(transactions[i].transaction, user);
} else if (action == TestAction.prove) {
vm.prank(pranker);
IFastBridge(fastBridge).prove(transactions[i].encodedData, hex"02");
} else if (action == TestAction.claim) {
vm.prank(pranker);
IFastBridge(fastBridge).claim(transactions[i].encodedData, claimTo);
} else if (action == TestAction.relay) {
vm.prank(pranker);
IFastBridge(fastBridge).relay(transactions[i].encodedData);
}
// Check status after each action
manyActions_checkStatusAfter(transactions[i].txId, action);
}
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
for (uint8 i = 0; i < transactions.length; i++) { | |
if (action == TestAction.bridge) { | |
// bridge already pranks as user, no need to prank | |
bridge(transactions[i].transaction, user); | |
} else if (action == TestAction.prove) { | |
vm.prank(pranker); | |
IFastBridge(fastBridge).prove(transactions[i].encodedData, hex"02"); | |
} else if (action == TestAction.claim) { | |
vm.prank(pranker); | |
IFastBridge(fastBridge).claim(transactions[i].encodedData, claimTo); | |
} else if (action == TestAction.relay) { | |
vm.prank(pranker); | |
IFastBridge(fastBridge).relay(transactions[i].encodedData); | |
} | |
// Check status after each action | |
manyActions_checkStatusAfter(transactions[i].txId, action); | |
} | |
} | |
for (uint256 i = 0; i < transactions.length; i++) { | |
if (action == TestAction.bridge) { | |
// bridge already pranks as user, no need to prank | |
bridge(transactions[i].transaction, user); | |
} else if (action == TestAction.prove) { | |
vm.prank(pranker); | |
IFastBridge(fastBridge).prove(transactions[i].encodedData, hex"02"); | |
} else if (action == TestAction.claim) { | |
vm.prank(pranker); | |
IFastBridge(fastBridge).claim(transactions[i].encodedData, claimTo); | |
} else if (action == TestAction.relay) { | |
vm.prank(pranker); | |
IFastBridge(fastBridge).relay(transactions[i].encodedData); | |
} | |
// Check status after each action | |
manyActions_checkStatusAfter(transactions[i].txId, action); | |
} | |
} |
for (uint8 i = 0; i < testBridgeTxns.length; i++) { | ||
if (action == TestAction.bridge) { | ||
data[i] = abi.encodeCall( | ||
IFastBridge.bridge, | ||
( | ||
IFastBridge.BridgeParams({ | ||
dstChainId: testBridgeTxns[i].transaction.destChainId, | ||
sender: testBridgeTxns[i].transaction.originSender, | ||
to: testBridgeTxns[i].transaction.destRecipient, | ||
originToken: testBridgeTxns[i].transaction.originToken, | ||
destToken: testBridgeTxns[i].transaction.destToken, | ||
originAmount: testBridgeTxns[i].transaction.originAmount, | ||
destAmount: testBridgeTxns[i].transaction.destAmount, | ||
sendChainGas: testBridgeTxns[i].transaction.sendChainGas, | ||
deadline: testBridgeTxns[i].transaction.deadline | ||
}) | ||
) | ||
); | ||
} | ||
if (action == TestAction.prove) { | ||
data[i] = abi.encodeCall(IFastBridge.prove, (testBridgeTxns[i].encodedData, hex"02")); | ||
} | ||
if (action == TestAction.claim) { | ||
data[i] = abi.encodeCall(IFastBridge.claim, (testBridgeTxns[i].encodedData, claimTo)); | ||
} | ||
if (action == TestAction.relay) { | ||
data[i] = abi.encodeCall(IFastBridge.relay, (testBridgeTxns[i].encodedData)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use uint256
for loop index to prevent overflow in getDataMany
.
In the getDataMany
function, the loop variable i
is declared as uint8
. If testBridgeTxns.length
exceeds 255, uint8
will overflow, leading to incorrect indexing. Consider changing i
to uint256
to accommodate larger arrays.
Apply this diff to fix the issue:
function getDataMany(
TestBridgeTransactionWithMetadata[] memory testBridgeTxns,
TestAction action
)
public
view
returns (bytes[] memory data)
{
data = new bytes[](testBridgeTxns.length);
- for (uint8 i = 0; i < testBridgeTxns.length; i++) {
+ for (uint256 i = 0; i < testBridgeTxns.length; i++) {
if (action == TestAction.bridge) {
data[i] = abi.encodeCall(
IFastBridge.bridge,
(
IFastBridge.BridgeParams({
dstChainId: testBridgeTxns[i].transaction.destChainId,
sender: testBridgeTxns[i].transaction.originSender,
to: testBridgeTxns[i].transaction.destRecipient,
originToken: testBridgeTxns[i].transaction.originToken,
destToken: testBridgeTxns[i].transaction.destToken,
originAmount: testBridgeTxns[i].transaction.originAmount,
destAmount: testBridgeTxns[i].transaction.destAmount,
sendChainGas: testBridgeTxns[i].transaction.sendChainGas,
deadline: testBridgeTxns[i].transaction.deadline
})
)
);
}
if (action == TestAction.prove) {
data[i] = abi.encodeCall(IFastBridge.prove, (testBridgeTxns[i].encodedData, hex"02"));
}
if (action == TestAction.claim) {
data[i] = abi.encodeCall(IFastBridge.claim, (testBridgeTxns[i].encodedData, claimTo));
}
if (action == TestAction.relay) {
data[i] = abi.encodeCall(IFastBridge.relay, (testBridgeTxns[i].encodedData));
}
}
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
for (uint8 i = 0; i < testBridgeTxns.length; i++) { | |
if (action == TestAction.bridge) { | |
data[i] = abi.encodeCall( | |
IFastBridge.bridge, | |
( | |
IFastBridge.BridgeParams({ | |
dstChainId: testBridgeTxns[i].transaction.destChainId, | |
sender: testBridgeTxns[i].transaction.originSender, | |
to: testBridgeTxns[i].transaction.destRecipient, | |
originToken: testBridgeTxns[i].transaction.originToken, | |
destToken: testBridgeTxns[i].transaction.destToken, | |
originAmount: testBridgeTxns[i].transaction.originAmount, | |
destAmount: testBridgeTxns[i].transaction.destAmount, | |
sendChainGas: testBridgeTxns[i].transaction.sendChainGas, | |
deadline: testBridgeTxns[i].transaction.deadline | |
}) | |
) | |
); | |
} | |
if (action == TestAction.prove) { | |
data[i] = abi.encodeCall(IFastBridge.prove, (testBridgeTxns[i].encodedData, hex"02")); | |
} | |
if (action == TestAction.claim) { | |
data[i] = abi.encodeCall(IFastBridge.claim, (testBridgeTxns[i].encodedData, claimTo)); | |
} | |
if (action == TestAction.relay) { | |
data[i] = abi.encodeCall(IFastBridge.relay, (testBridgeTxns[i].encodedData)); | |
} | |
} | |
} | |
for (uint256 i = 0; i < testBridgeTxns.length; i++) { | |
if (action == TestAction.bridge) { | |
data[i] = abi.encodeCall( | |
IFastBridge.bridge, | |
( | |
IFastBridge.BridgeParams({ | |
dstChainId: testBridgeTxns[i].transaction.destChainId, | |
sender: testBridgeTxns[i].transaction.originSender, | |
to: testBridgeTxns[i].transaction.destRecipient, | |
originToken: testBridgeTxns[i].transaction.originToken, | |
destToken: testBridgeTxns[i].transaction.destToken, | |
originAmount: testBridgeTxns[i].transaction.originAmount, | |
destAmount: testBridgeTxns[i].transaction.destAmount, | |
sendChainGas: testBridgeTxns[i].transaction.sendChainGas, | |
deadline: testBridgeTxns[i].transaction.deadline | |
}) | |
) | |
); | |
} | |
if (action == TestAction.prove) { | |
data[i] = abi.encodeCall(IFastBridge.prove, (testBridgeTxns[i].encodedData, hex"02")); | |
} | |
if (action == TestAction.claim) { | |
data[i] = abi.encodeCall(IFastBridge.claim, (testBridgeTxns[i].encodedData, claimTo)); | |
} | |
if (action == TestAction.relay) { | |
data[i] = abi.encodeCall(IFastBridge.relay, (testBridgeTxns[i].encodedData)); | |
} | |
} |
for (uint8 i = 0; i < countOfTxnsToCreate; i++) { | ||
// prepare relays for execution later | ||
IFastBridge.BridgeTransaction memory toRelayTx = IFastBridge.BridgeTransaction({ | ||
originChainId: REMOTE_CHAIN_ID, | ||
destChainId: LOCAL_CHAIN_ID, | ||
originSender: userRemote, | ||
destRecipient: user, | ||
originToken: remoteToken, | ||
destToken: address(token), | ||
originAmount: 1.01 ether, | ||
destAmount: 1 ether, | ||
originFeeAmount: 0, | ||
sendChainGas: false, | ||
deadline: block.timestamp + SKIP_PERIOD, | ||
nonce: remoteTokenTx.nonce + i | ||
}); | ||
|
||
bytes memory encoded = getEncodedBridgeTx(toRelayTx); | ||
bytes32 txId = keccak256(encoded); | ||
|
||
toRelay[i] = TestBridgeTransactionWithMetadata({transaction: toRelayTx, encodedData: encoded, txId: txId}); | ||
|
||
// prepare *and* execute bridges, to be subsequently proven & claimed | ||
IFastBridge.BridgeTransaction memory toBridgeProveClaimTx = IFastBridge.BridgeTransaction({ | ||
originChainId: LOCAL_CHAIN_ID, | ||
destChainId: REMOTE_CHAIN_ID, | ||
originSender: user, | ||
destRecipient: userRemote, | ||
originToken: address(token), | ||
destToken: remoteToken, | ||
originAmount: 1 ether, | ||
destAmount: 0.98 ether, | ||
originFeeAmount: 0, | ||
sendChainGas: false, | ||
deadline: block.timestamp + DEADLINE_PERIOD, | ||
nonce: 2 + i | ||
}); | ||
|
||
encoded = getEncodedBridgeTx(toBridgeProveClaimTx); | ||
txId = keccak256(encoded); | ||
|
||
toBridgeProveClaimData[i] = | ||
// solhint-disable-next-line max-line-length | ||
TestBridgeTransactionWithMetadata({transaction: toBridgeProveClaimTx, encodedData: encoded, txId: txId}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use uint256
for loop index to prevent overflow in createMany
.
In the createMany
function, the loop variable i
is declared as uint8
. If countOfTxnsToCreate
exceeds 255, uint8
will overflow, potentially causing incorrect behavior. It's safer to use uint256
for loop indices to handle larger values.
Apply this diff to fix the issue:
-function createMany(uint8 countOfTxnsToCreate)
+function createMany(uint256 countOfTxnsToCreate)
public
returns (
TestBridgeTransactionWithMetadata[] memory toRelay,
TestBridgeTransactionWithMetadata[] memory toBridgeProveClaimData
)
{
toRelay = new TestBridgeTransactionWithMetadata[](countOfTxnsToCreate);
toBridgeProveClaimData = new TestBridgeTransactionWithMetadata[](countOfTxnsToCreate);
// fund user & relayer
dealTokens(user, countOfTxnsToCreate);
dealTokens(relayer, countOfTxnsToCreate);
- for (uint8 i = 0; i < countOfTxnsToCreate; i++) {
+ for (uint256 i = 0; i < countOfTxnsToCreate; i++) {
// prepare relays for execution later
IFastBridge.BridgeTransaction memory toRelayTx = IFastBridge.BridgeTransaction({
originChainId: REMOTE_CHAIN_ID,
destChainId: LOCAL_CHAIN_ID,
originSender: userRemote,
destRecipient: user,
originToken: remoteToken,
destToken: address(token),
originAmount: 1.01 ether,
destAmount: 1 ether,
originFeeAmount: 0,
sendChainGas: false,
deadline: block.timestamp + SKIP_PERIOD,
nonce: remoteTokenTx.nonce + i
});
bytes memory encoded = getEncodedBridgeTx(toRelayTx);
bytes32 txId = keccak256(encoded);
toRelay[i] = TestBridgeTransactionWithMetadata({transaction: toRelayTx, encodedData: encoded, txId: txId});
// prepare *and* execute bridges, to be subsequently proven & claimed
IFastBridge.BridgeTransaction memory toBridgeProveClaimTx = IFastBridge.BridgeTransaction({
originChainId: LOCAL_CHAIN_ID,
destChainId: REMOTE_CHAIN_ID,
originSender: user,
destRecipient: userRemote,
originToken: address(token),
destToken: remoteToken,
originAmount: 1 ether,
destAmount: 0.98 ether,
originFeeAmount: 0,
sendChainGas: false,
deadline: block.timestamp + DEADLINE_PERIOD,
nonce: 2 + i
});
encoded = getEncodedBridgeTx(toBridgeProveClaimTx);
txId = keccak256(encoded);
toBridgeProveClaimData[i] = TestBridgeTransactionWithMetadata({
transaction: toBridgeProveClaimTx,
encodedData: encoded,
txId: txId
});
}
}
Committable suggestion was skipped due to low confidence.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## feat/FbV2-multicall #3335 +/- ##
=======================================================
Coverage 28.74454% 28.74454%
=======================================================
Files 184 184
Lines 12131 12131
Branches 82 82
=======================================================
Hits 3487 3487
Misses 8361 8361
Partials 283 283
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solid work, LGTM!
Deploying sanguine-fe with Cloudflare Pages
|
* refactor: dedupe integration test template * test: V2 multicall integration * feat: add multicall features to FastBridgeV2 * Parod/fb v2 multicall add test (#3335) * add manyActions multicall test * increase manyAction count * comment cleanup --------- Co-authored-by: parodime <jordan@protochainresearch.com>
In addition to previous tests, addtl tests added for calling large batches of Bridges, Relays, Proofs, and Claims via multicall and also via non-multicall sequentially
Summary by CodeRabbit
New Features
dealTokens
function.createMany
, for generating multiple bridge transactions.Bug Fixes
Tests