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

fix(contracts-rfq): gas bench tests for the views [SLT-275] #3217

Merged
merged 2 commits into from
Oct 3, 2024

Conversation

ChiTimesChi
Copy link
Collaborator

@ChiTimesChi ChiTimesChi commented Oct 3, 2024

Description
A clear and concise description of the features you're adding in this pull request.

Additional context
Add any other context about the problem you're solving.

Metadata

  • Fixes #[Link to Issue]

Summary by CodeRabbit

  • New Features

    • Introduced a new contract for gas benchmarking of the FastBridge V2 protocol.
    • Added methods for testing bridge transactions.
  • Bug Fixes

    • Improved transaction ID handling in claim functions for better clarity and redundancy reduction.
    • Enhanced assertions to validate claim processes against expected conditions.

Copy link
Contributor

coderabbitai bot commented Oct 3, 2024

Walkthrough

A new Solidity contract named FastBridgeV2GasBenchmarkSrcProtocolFeesTest has been introduced to facilitate gas benchmarking tests for the FastBridge V2 protocol. This contract includes two public view functions for testing bridge transactions. Additionally, modifications have been made to the FastBridgeV2GasBenchmarkSrcTest contract, particularly in transaction ID handling and assertions related to token and ETH claims, enhancing clarity and validation of the claim process.

Changes

File Path Change Summary
packages/contracts-rfq/test/FastBridgeV2.GasBench.Encoding.t.sol - Added FastBridgeV2GasBenchmarkSrcProtocolFeesTest contract.
- Introduced test_getBridgeTransaction and test_getBridgeTransactionV2 functions.
packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol - Updated test_claim_token and test_claimWithAddress_token to use local txId variable.
- Modified assertions in test_claim_eth and test_claimWithAddress_eth to reference txId.

Possibly related PRs

Suggested labels

size/s, needs-go-generate-services/rfq

Suggested reviewers

  • trajan0x

🐰 In the meadow, we hop and play,
New tests for gas, hip-hip-hooray!
With tokens and ETH, we claim with glee,
FastBridge V2, come dance with me!
As we benchmark and validate,
Our code shines bright, it’s truly great! 🌟


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ChiTimesChi ChiTimesChi changed the title fix(contracts-rfq): gas bench tests for the views fix(contracts-rfq): gas bench tests for the views [SLT-275] Oct 3, 2024
Copy link

github-actions bot commented Oct 3, 2024

Changes to gas cost

Generated at commit: 38e54b8e7c1cce4f4bc74d95934109c2366a37f6, compared to commit: 12668b55c03135b501456689e2d07c9e07aab815

🧾 Summary (50% most significant diffs)

Contract Method Avg (+/-) %

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
FastBridgeV2 2,700,676 (0) grantRole 101,405 (0) 0.00% 114,671 (-31) -0.03% 118,505 (0) 0.00% 118,505 (0) 0.00% 183 (+12)

Copy link

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0145376
Status: ✅  Deploy successful!
Preview URL: https://87568a21.sanguine-fe.pages.dev
Branch Preview URL: https://fix-fast-bridge-gas-bench-vi.sanguine-fe.pages.dev

View logs

Copy link

codecov bot commented Oct 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 28.14426%. Comparing base (ad48cb0) to head (0145376).
Report is 2 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3217         +/-   ##
===================================================
+ Coverage   24.92918%   28.14426%   +3.21508%     
===================================================
  Files            198         184         -14     
  Lines          13061       12006       -1055     
  Branches          82         150         +68     
===================================================
+ Hits            3256        3379        +123     
+ Misses          9523        8346       -1177     
+ Partials         282         281          -1     
Flag Coverage Δ
packages 90.56974% <ø> (ø)
promexporter ?
solidity 89.40678% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
packages/contracts-rfq/test/FastBridgeV2.GasBench.Encoding.t.sol (3)

1-6: LGTM: File structure and imports are well-organized.

The file structure follows Solidity best practices with proper SPDX license identifier and up-to-date pragma version. The import statement is relevant for the test contract.

Consider adding a brief comment explaining why specific solhint rules are disabled for this file.


15-18: LGTM: test_getBridgeTransactionV2 function is well-implemented.

The function is correctly set up for gas benchmarking with the view modifier. It encodes the transaction data directly and calls the V2 method on the fastBridge instance.

Note that this function doesn't use the extractV1 function unlike test_getBridgeTransaction. This difference might be intentional, but it's worth confirming if this is the expected behavior for V2.


8-8: Consider creating a GitHub issue for the TODO item.

The TODO comment indicates a plan for future tests. While it's good to note this, it might be more effective to track such tasks in your issue tracking system.

Would you like me to create a GitHub issue to track the task of adding more tests with variable length requests once arbitrary call functionality is implemented?

packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol (1)

Line range hint 1-268: Summary: Excellent improvements to claim test functions

The changes in this file demonstrate a systematic and consistent approach to improving the test suite for FastBridgeV2 source chain functions. Key improvements include:

  1. Introduction of txId variables to reduce redundant getTxId calls.
  2. Addition of canClaim pre-condition checks to enhance test robustness.
  3. Improved code readability through the use of named transaction ID variables.

These changes were consistently applied across all claim test functions for both token and ETH transactions, resulting in a more efficient, readable, and maintainable test suite.

Suggestion for future improvements:
Consider applying similar optimizations to other test functions in this file, such as the prove, dispute, and refund tests, to maintain consistency and further enhance the overall quality of the test suite.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ad48cb0 and 0145376.

📒 Files selected for processing (2)
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Encoding.t.sol (1 hunks)
  • packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol (2 hunks)
🔇 Additional comments (6)
packages/contracts-rfq/test/FastBridgeV2.GasBench.Encoding.t.sol (2)

7-7: LGTM: Contract declaration and inheritance are appropriate.

The contract name FastBridgeV2GasBenchmarkSrcProtocolFeesTest is descriptive and follows naming conventions. Inheriting from FastBridgeV2SrcBaseTest is a good practice for organizing test contracts.


10-13: LGTM: test_getBridgeTransaction function looks good.

The function is correctly set up for gas benchmarking with the view modifier. It encodes the transaction data and calls the relevant method on the fastBridge instance.

Could you provide more information about the extractV1 function? It would be helpful to understand its purpose and implementation.

packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol (4)

138-142: Excellent improvements to the test_claim_token function!

The changes enhance the code quality by:

  1. Introducing a txId variable, which reduces redundant calls to getTxId.
  2. Adding a pre-condition check with canClaim, improving the test's robustness.
  3. Improving readability by using a named variable for the transaction ID.

These modifications align well with best practices and make the test more efficient and easier to understand.


148-152: Great consistency in improvements for test_claimWithAddress_token!

The changes mirror those made in test_claim_token, bringing the same benefits:

  1. Reduced redundant calls to getTxId by introducing a txId variable.
  2. Added a pre-condition check with canClaim, enhancing test robustness.
  3. Improved readability by using a named variable for the transaction ID.

This consistent approach across similar functions is commendable and improves the overall quality of the test suite.


224-228: Excellent consistency in improvements for ETH claims in test_claim_eth!

The changes are consistent with those made in the token claim functions, demonstrating a systematic approach to improving the test suite:

  1. Introduction of a txId variable to reduce redundant getTxId calls.
  2. Addition of a canClaim pre-condition check, enhancing test robustness.
  3. Improved readability through the use of a named transaction ID variable.

This consistency across different asset types (tokens and ETH) is praiseworthy and contributes to a more maintainable and efficient test suite.


234-238: Commendable consistency maintained in test_claimWithAddress_eth!

The changes in this function complete a consistent pattern of improvements across all claim functions (both token and ETH):

  1. Introduction of a txId variable to eliminate redundant getTxId calls.
  2. Addition of a canClaim pre-condition check, further enhancing test robustness.
  3. Improved code readability through the use of a named transaction ID variable.

This systematic approach to improving all claim functions demonstrates a thorough and well-thought-out refactoring process, contributing to a more efficient, readable, and maintainable test suite.

Copy link

codecov bot commented Oct 3, 2024

Bundle Report

Bundle size has no change ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant