-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: main
Are you sure you want to change the base?
Conversation
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. |
WalkthroughThe 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 Changes
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
Suggested labels
Suggested reviewers
Poem
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
CodeRabbit Configuration File (
|
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: 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:
- Error cases (invalid address, negative amount)
- Validation of response fields (newBalance, unit)
- 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
📒 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 inMintRequest
andMintResult
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 theunit
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 theunit
field in bothMintRequest
andMintResult
.
- 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
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: 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:
- Add validation for the amount field to prevent negative values
- 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:
- Reuse the unit validation for consistency
- 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
📒 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.
Hi @ptisserand , could you review this PR?, i think its ready...thanks. |
Hi, I think it will be better to move this mint wrapper to @rukafe0x what do you think about it ? |
Add wrapper for devnet mint endpoint as required in issue #447
Also a minor fix in avnu package documentation.
Summary by CodeRabbit
Documentation
New Features
Tests