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

feat: add wrapper for devnet mint endpoint #458

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rukafe0x
Copy link
Contributor

@rukafe0x rukafe0x commented Feb 13, 2025

Add wrapper for devnet mint endpoint as required in issue #447

Also a minor fix in avnu package documentation.

Summary by CodeRabbit

  • Documentation

    • Updated navigation links for clearer package documentation.
    • Simplified testing instructions by removing an unnecessary environment variable requirement.
  • New Features

    • Introduced token minting functionality, enabling users to submit mint requests and receive corresponding responses.
    • Added a new method for processing mint transactions within the provider interface.
  • Tests

    • Added new test cases to validate minting operations across different token units.

Copy link

docs-page bot commented Feb 13, 2025

To view this pull requests documentation preview, visit the following URL:

docs.page/focustree/starknet.dart~458

Documentation is deployed and generated using docs.page.

Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

Walkthrough

The changes update the documentation with improved navigation links and simplified test instructions. An integration tag is added to the test configuration. New data models and serialization code for mint transactions are introduced using the Freezed package. The mintTransaction method is implemented in the provider, and new tests for minting operations with both FRI and WEI units are included.

Changes

File(s) Summary
docs/.../avnu_provider.mdx Updated navigation links to include packages/avnu_provider and simplified test instructions by removing the STARKNET_RPC environment variable requirement.
packages/starknet_provider/dart_test.yaml Added an integration tag in the test configuration.
packages/starknet_provider/lib/src/model/... Added new mint transaction data models (MintRequest, MintResponse, MintResult) in mint_transaction.dart, with corresponding export in index.dart and generated serialization code in mint_transaction.freezed.dart and mint_transaction.g.dart.
packages/starknet_provider/lib/src/provider.dart Introduced the mintTransaction method in the Provider interface and its JsonRpcProvider implementation, calling the devnet_mint RPC endpoint and converting responses to a MintResponse object.
packages/starknet_provider/test/provider_test.dart Added a new test group devnet with tests for minting operations for 'FRI' and 'WEI', asserting that the transaction hash returned is not empty.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Provider as JsonRpcProvider
    participant RPC as RPC Endpoint

    Client->>Provider: mintTransaction(MintRequest)
    Provider->>RPC: callRpcEndpoint('devnet_mint', MintRequest)
    RPC-->>Provider: Response JSON
    Provider->>Provider: Parse JSON to MintResponse
    Provider-->>Client: MintResponse
Loading

Suggested labels

package: starknet_provider

Suggested reviewers

  • ptisserand

Poem

Hop along the code trail, so spry and bright,
Minting tokens in the blockchain night.
Links and tests leaped into place with cheer,
A rabbit’s wink saying "Great job, my dear!"
🐰✨ Let’s celebrate each line and byte!


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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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: 1

🧹 Nitpick comments (1)
packages/starknet_provider/test/provider_test.dart (1)

117-136: Add more comprehensive test cases.

While the basic happy path tests are good, consider adding:

  1. Error cases (invalid address, negative amount)
  2. Validation of response fields (newBalance, unit)
  3. Edge cases (zero amount, very large amounts)
 group('devnet', () {
   test('mint FRI', () async {
     final provider = getJsonRpcProvider(network: 'devnet');
     final request = MintRequest(
         address: account0.accountAddress.toHexString(),
         amount: 1000,
         unit: 'FRI');
     final response = await provider.mintTransaction(request);
     expect(response.result.txHash, isNotEmpty);
+    expect(response.result.unit, equals('FRI'));
+    expect(int.parse(response.result.newBalance), greaterThan(0));
   });
+
+  test('mint with invalid address', () async {
+    final provider = getJsonRpcProvider(network: 'devnet');
+    final request = MintRequest(
+        address: '0xinvalid',
+        amount: 1000,
+        unit: 'FRI');
+    expect(() => provider.mintTransaction(request), throwsException);
+  });
+
+  test('mint with zero amount', () async {
+    final provider = getJsonRpcProvider(network: 'devnet');
+    final request = MintRequest(
+        address: account0.accountAddress.toHexString(),
+        amount: 0,
+        unit: 'FRI');
+    final response = await provider.mintTransaction(request);
+    expect(response.result.txHash, isNotEmpty);
+    expect(response.result.unit, equals('FRI'));
+  });
 });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ecf637 and c1e1ab1.

📒 Files selected for processing (8)
  • docs/packages/avnu_provider.mdx (2 hunks)
  • packages/starknet_provider/dart_test.yaml (1 hunks)
  • packages/starknet_provider/lib/src/model/index.dart (1 hunks)
  • packages/starknet_provider/lib/src/model/mint_transaction.dart (1 hunks)
  • packages/starknet_provider/lib/src/model/mint_transaction.freezed.dart (1 hunks)
  • packages/starknet_provider/lib/src/model/mint_transaction.g.dart (1 hunks)
  • packages/starknet_provider/lib/src/provider.dart (2 hunks)
  • packages/starknet_provider/test/provider_test.dart (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/starknet_provider/dart_test.yaml
  • packages/starknet_provider/lib/src/model/mint_transaction.g.dart
🧰 Additional context used
🧠 Learnings (2)
packages/starknet_provider/lib/src/model/index.dart (2)
Learnt from: rukafe0x
PR: focustree/starknet.dart#417
File: packages/starknet_provider/lib/src/model/invoke_transaction.g.dart:27-27
Timestamp: 2024-11-21T18:02:58.562Z
Learning: In the `packages/starknet_provider` project, it's acceptable to include changes to auto-generated `.g.dart` files like `packages/starknet_provider/lib/src/model/invoke_transaction.g.dart` in commits, as they are necessary for the functionality.
Learnt from: rukafe0x
PR: focustree/starknet.dart#411
File: packages/starknet_provider/lib/src/model/declare_transaction.g.dart:54-54
Timestamp: 2024-11-12T04:15:58.361Z
Learning: Files ending with `.g.dart` are autogenerated and should not be manually modified or reviewed for changes.
packages/starknet_provider/lib/src/model/mint_transaction.freezed.dart (2)
Learnt from: rukafe0x
PR: focustree/starknet.dart#412
File: packages/starknet_provider/lib/src/model/invoke_transaction.freezed.dart:26-31
Timestamp: 2024-11-12T04:15:58.361Z
Learning: In the `starknet_provider/lib/src/model/invoke_transaction.freezed.dart` file and other files with the `.freezed.dart` extension, the code is automatically generated by the `freezed` package and should not be manually modified.
Learnt from: rukafe0x
PR: focustree/starknet.dart#412
File: packages/starknet_provider/lib/src/model/invoke_transaction.freezed.dart:135-139
Timestamp: 2024-11-12T04:15:58.361Z
Learning: Files with the `.freezed.dart` extension are automatically generated by the Freezed package and should not be manually modified.
🔇 Additional comments (6)
packages/starknet_provider/lib/src/model/index.dart (1)

35-35: LGTM!

The new export statement is correctly placed in alphabetical order and properly exposes the mint transaction models.

packages/starknet_provider/lib/src/model/mint_transaction.dart (1)

1-42: LGTM! Well-structured data models.

The implementation uses freezed for immutable data classes with proper JSON serialization. The class structure and field definitions are clear and well-documented.

packages/starknet_provider/lib/src/provider.dart (1)

11-11: LGTM! Clean implementation following established patterns.

The mintTransaction method is well-implemented, following the same pattern as other RPC methods in the provider.

Also applies to: 51-56

packages/starknet_provider/test/provider_test.dart (1)

117-136: LGTM! Basic test coverage is in place.

The integration tests cover the basic functionality for both WEI and FRI units.

packages/starknet_provider/lib/src/model/mint_transaction.freezed.dart (1)

1-572:

❓ Verification inconclusive

LGTM! The generated code looks correct.

The Freezed-generated code implements the data models for mint transactions with proper JSON serialization and immutability.

Please verify that the unit field in MintRequest and MintResult only accepts "WEI" or "FRI" values by checking the implementation in the non-generated file:


🏁 Script executed:

#!/bin/bash
# Description: Check the implementation of MintRequest and MintResult in the non-generated file
# to verify unit field validation

ast-grep --pattern 'class MintRequest {
  $$$
  String get unit;
  $$$
}'

ast-grep --pattern 'class MintResult {
  $$$
  String get unit;
  $$$
}'

Length of output: 150


LGTM – The generated Freezed code appears correct.
The file adheres to standard Freezed patterns and correctly implements JSON serialization and immutability for mint transactions. However, the verification script for checking the unit field constraints in the non-generated file did not yield any output. As a precaution, please manually verify that the non-generated implementation enforces the allowed values ("WEI" or "FRI") for the unit field in both MintRequest and MintResult.

  • Action: Manually check the non-generated file(s) to confirm that the unit field is properly validated.
docs/packages/avnu_provider.mdx (1)

5-8: LGTM! Documentation improvements enhance navigation and simplify setup.

The changes improve the documentation by:

  • Adding full paths to index links for better navigation
  • Simplifying test setup by removing unnecessary environment variable requirement

Also applies to: 263-263

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

🧹 Nitpick comments (3)
packages/starknet_provider/lib/src/model/mint_transaction.dart (3)

13-25: Add validation for the amount field and improve documentation.

While the unit validation is in place, consider these improvements:

  1. Add validation for the amount field to prevent negative values
  2. Enhance documentation with example values and format requirements for the address field
 /// Parameters for minting tokens
+/// 
+/// Example:
+/// ```dart
+/// final request = MintRequest(
+///   address: '0x6e3205f...', // 64-character hex string
+///   amount: 500000,          // must be positive
+///   unit: 'WEI',            // 'WEI' or 'FRI'
+/// );
+/// ```
 @freezed
 class MintRequest with _$MintRequest {
   const factory MintRequest({
     required String address, // "0x6e3205f..."
+    @JsonKey(fromJson: _validateAmount)
     required int amount, // 500000
     /// Can be either "WEI" or "FRI"
     @JsonKey(fromJson: _validateUnit) required String unit, // "WEI" | "FRI"
   }) = _MintRequest;

   factory MintRequest.fromJson(Map<String, dynamic> json) =>
       _$MintRequestFromJson(json);
 }

+int _validateAmount(int amount) {
+  if (amount <= 0) {
+    throw ArgumentError('Amount must be positive');
+  }
+  return amount;
+}

27-36: Add example to the documentation.

Consider adding an example to make the response structure clearer.

 /// Response from minting tokens
+/// 
+/// Example:
+/// ```dart
+/// final response = MintResponse(
+///   result: MintResult(
+///     newBalance: '1000000',
+///     unit: 'WEI',
+///     txHash: '0x123...'
+///   ),
+/// );
+/// ```
 @freezed
 class MintResponse with _$MintResponse {

38-49: Reuse unit validation and improve documentation.

Consider these improvements:

  1. Reuse the unit validation for consistency
  2. Add example to the documentation
 /// Result data from minting tokens
+/// 
+/// Example:
+/// ```dart
+/// final result = MintResult(
+///   newBalance: '1000000',
+///   unit: 'WEI',
+///   txHash: '0x123abc...' // transaction hash
+/// );
+/// ```
 @freezed
 class MintResult with _$MintResult {
   const factory MintResult({
     @JsonKey(name: 'new_balance') required String newBalance,
+    @JsonKey(fromJson: _validateUnit)
     required String unit,
     @JsonKey(name: 'tx_hash') required String txHash,
   }) = _MintResult;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1e1ab1 and 16901aa.

📒 Files selected for processing (3)
  • packages/starknet_provider/lib/src/model/mint_transaction.dart (1 hunks)
  • packages/starknet_provider/lib/src/model/mint_transaction.freezed.dart (1 hunks)
  • packages/starknet_provider/lib/src/model/mint_transaction.g.dart (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/starknet_provider/lib/src/model/mint_transaction.freezed.dart
  • packages/starknet_provider/lib/src/model/mint_transaction.g.dart
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: analyze
  • GitHub Check: test-integration
  • GitHub Check: lint
🔇 Additional comments (2)
packages/starknet_provider/lib/src/model/mint_transaction.dart (2)

1-4: LGTM!

The imports and part declarations are correctly set up for the Freezed package.


6-11: LGTM! Unit validation implemented as requested.

The validation function correctly ensures that only 'WEI' or 'FRI' units are accepted, as previously requested.

@rukafe0x
Copy link
Contributor Author

Hi @ptisserand , could you review this PR?, i think its ready...thanks.

@ptisserand
Copy link
Collaborator

Hi,
thanks for your contribution but I don't think this wrapper should be part of starknet_provider package.
From my point of view starknet_provider should follow as much as possible StarkNet specifications

I think it will be better to move this mint wrapper to starknet package in a utils/devnet directory, this endpoint is quite specific to starknet-devnet.

@rukafe0x what do you think about it ?

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

Successfully merging this pull request may close these issues.

2 participants