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: smart contract klv tx #96

Merged
merged 2 commits into from
Feb 5, 2025
Merged

fix: smart contract klv tx #96

merged 2 commits into from
Feb 5, 2025

Conversation

pedrxlz
Copy link
Contributor

@pedrxlz pedrxlz commented Feb 4, 2025

Summary by CodeRabbit

  • New Features

    • Expanded support for smart contract transactions with an additional contract type.
  • Refactor

    • Improved transaction processing by updating how missing or optional data is handled to ensure consistent default behavior.
  • Tests

    • Added new automated tests for transaction signing and smart contract handling to enhance overall reliability and robustness.

Copy link

coderabbitai bot commented Feb 4, 2025

Walkthrough

This pull request introduces new tests for transaction signing in both the Wallet and KLV modules, verifies the proper functioning of signature generation and transaction hashing, and improves data handling in the models by making the nonce field optional with default fallbacks. In addition, a new smart contract type is added to the protocol definition.

Changes

Files Summary
packages/kos-.../wallet.rs
packages/kos-.../klv/mod.rs
Added new test functions (test_sign_transaction and test_sign_tx_4) to validate transaction signing in the Wallet and KLV modules.
packages/kos-.../klv/models.rs Updated the Raw struct: changed the nonce field from u64 to Option<u64> and modified conversion logic to default to 0 when absent.
packages/kos-.../transaction.proto Extended the ContractType enum by adding a new value SmartContractType = 63 to support smart contracts.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test
    participant W as Wallet Module
    T->>W: Create wallet using mnemonic
    T->>W: Sign transaction with raw JSON
    W-->>T: Return signed transaction (signature & hash)
Loading
sequenceDiagram
    participant T as Test
    participant K as KLV Module
    T->>K: Call sign_tx with smart contract JSON
    K-->>T: Return transaction hash
Loading

Possibly related PRs

  • Feat/transaction from raw #65: Enhances transaction signing functionality in the KOSAccount context with tests similar to the ones introduced here.

Suggested labels

@domain/sdk

Suggested reviewers

  • gustavocbritto
  • klever-patrick

Poem

I’m a bunny with hops so bright,
Testing transactions by day and night.
I wiggle my whiskers with a code-filled glee,
Signing and hashing, happy as can be.
With each new line, I dance in delight!
🐇✨

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e8b3d6a and 18c4d17.

📒 Files selected for processing (1)
  • packages/kos/src/chains/klv/mod.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/kos/src/chains/klv/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: format

🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@github-actions github-actions bot added the rust label Feb 4, 2025
Copy link

@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

🧹 Nitpick comments (1)
packages/kos/src/protos/klever/transaction.proto (1)

37-37: Add documentation for SmartContractType.

While the addition of SmartContractType is good, please add documentation to describe:

  • The purpose and use cases of this contract type
  • Why the value 63 was chosen
  • Any special handling requirements
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a6e05c and e8b3d6a.

⛔ Files ignored due to path filters (1)
  • packages/kos/src/protos/generated/klv/proto.rs is excluded by !**/generated/**
📒 Files selected for processing (4)
  • packages/kos-web/src/wallet.rs (1 hunks)
  • packages/kos/src/chains/klv/mod.rs (1 hunks)
  • packages/kos/src/chains/klv/models.rs (2 hunks)
  • packages/kos/src/protos/klever/transaction.proto (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: format
🔇 Additional comments (4)
packages/kos/src/chains/klv/models.rs (2)

36-36: LGTM! Making nonce optional improves flexibility.

The change to make nonce optional with Option<u64> is a good improvement as it allows for cases where nonce may not be provided.


154-154: LGTM! Proper handling of optional nonce.

The implementation correctly handles the optional nonce by using unwrap_or(0) to provide a default value when nonce is None.

packages/kos/src/chains/klv/mod.rs (1)

288-311: LGTM! Good test coverage for smart contract transactions.

The test case properly validates the transaction signing functionality for smart contracts by:

  • Using a realistic transaction JSON
  • Verifying the transaction hash
  • Following the established test pattern
packages/kos-web/src/wallet.rs (1)

491-506: LGTM! Good integration test for wallet transaction signing.

The test provides good coverage by:

  • Testing the full wallet creation and transaction signing flow
  • Verifying both signature and transaction hash generation
  • Using a realistic smart contract transaction

@pedrxlz pedrxlz merged commit a9c89eb into develop Feb 5, 2025
4 checks passed
@pedrxlz pedrxlz deleted the fix/klv-smart-contract-tx branch February 5, 2025 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants