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

Examples use-cases - get blocks #80

Merged
merged 33 commits into from
Aug 20, 2024
Merged

Examples use-cases - get blocks #80

merged 33 commits into from
Aug 20, 2024

Conversation

lealobanov
Copy link
Collaborator

@lealobanov lealobanov commented Aug 15, 2024

Description

Get blocks
-Get the latest sealed block
-Get the block by ID
-Get the block by height

To-do: refactor get_blocks package name to not use underscores


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Updated Maven Central and Sonatype OSS badges in the documentation for improved accuracy.
    • Introduced the GetBlockAccessAPIConnector class to interact with the blockchain access API, enabling methods to retrieve block information.
    • Added the sendSampleTransaction function to the AccessAPIConnector class for creating and sending transactions on the Flow blockchain.
  • Bug Fixes

    • Removed unnecessary debug print statement in the utility code to streamline performance and reduce log clutter.
  • Tests

    • Added unit tests for GetBlockAccessAPIConnector to ensure functionality for retrieving the latest sealed block, fetching blocks by ID, and fetching blocks by height.

Copy link
Contributor

coderabbitai bot commented Aug 15, 2024

Warning

Rate limit exceeded

@lealobanov has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 42 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 8ebb852 and 2c0710a.

Walkthrough

The recent changes enhance the Flow JVM SDK's usability and documentation. Key updates include correcting badge URLs in the README.md, streamlining the FlowTestUtil for improved performance, and introducing the GetBlockAccessAPIConnector class along with its unit tests to facilitate robust interaction with the blockchain's access API. Additional features and tests in both Kotlin and Java ensure a clearer and more effective development experience.

Changes

File(s) Change Summary
README.md Updated Maven Central and Sonatype OSS badge URLs to reflect the correct group ID.
common/src/testFixtures/kotlin/... Removed unnecessary debug print statement in FlowTestUtil.kt to reduce log clutter.
kotlin-example/src/main/kotlin/..., java-example/src/main/java/... Introduced GetBlockAccessAPIConnector classes for interacting with blockchain access API, with methods for fetching block data.
kotlin-example/src/test/kotlin/..., java-example/src/test/java/... Added unit tests for the new connector classes, validating core functionalities in both Kotlin and Java.
java-example/src/main/java/... Refactored AccessAPIConnector for improved transaction handling and introduced new methods.
kotlin-example/src/main/kotlin/... Added sendSampleTransaction function to facilitate transaction sending on the Flow blockchain.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GetBlockAccessAPIConnector
    participant FlowAccessApi

    User->>GetBlockAccessAPIConnector: Request latest sealed block
    GetBlockAccessAPIConnector->>FlowAccessApi: Call getLatestBlock(isSealed=true)
    FlowAccessApi-->>GetBlockAccessAPIConnector: Return latest block data
    GetBlockAccessAPIConnector-->>User: Provide latest sealed block
Loading

🐇 In the code, I hop and play,
Debug lines now tucked away!
With blocks to fetch, the API sings,
Updates here, oh what joy it brings!
Flow's path is clear as a sunny day! 🌼


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

github-actions bot commented Aug 15, 2024

Unit Test Results

  53 files  ±0    53 suites  ±0   23s ⏱️ ±0s
310 tests ±0  310 ✔️ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 2c0710a. ± Comparison against base commit f785a05.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Aug 15, 2024

SDK Examples Unit Test Results

12 files  12 suites   2m 51s ⏱️
33 tests 33 ✔️ 0 💤 0 ❌

Results for commit 2c0710a.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Aug 15, 2024

Integration Test Results

  5 files  ±0    5 suites  ±0   2m 29s ⏱️ ±0s
29 tests ±0  29 ✔️ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 2c0710a. ± Comparison against base commit f785a05.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Aug 15, 2024

Common Integration Test Results

1 files  1 suites   7s ⏱️
1 tests 1 ✔️ 0 💤 0 ❌

Results for commit 2c0710a.

♻️ This comment has been updated with latest results.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d857ae6 and 799fa4d.

Files selected for processing (4)
  • README.md (1 hunks)
  • common/src/testFixtures/kotlin/org/onflow/flow/common/test/FlowTestUtil.kt (1 hunks)
  • kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/get_block/GetBlockAccessAPIConnector.kt (1 hunks)
  • kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/get_block/GetBlockAccessAPIConnectorTest.kt (1 hunks)
Files skipped from review due to trivial changes (2)
  • README.md
  • common/src/testFixtures/kotlin/org/onflow/flow/common/test/FlowTestUtil.kt
Additional comments not posted (6)
kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/get_block/GetBlockAccessAPIConnector.kt (3)

9-15: LGTM!

The method correctly retrieves the latest sealed block and handles API responses effectively.


17-22: LGTM!

The method correctly fetches a block by ID and handles API responses appropriately.


24-29: LGTM!

The method correctly retrieves a block by height and handles API responses effectively.

kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/get_block/GetBlockAccessAPIConnectorTest.kt (3)

25-32: Test is well-structured!

The test effectively verifies that the latest sealed block can be fetched and checks its properties.


34-43: Test is well-structured!

The test correctly verifies that a block can be fetched by ID and compares its properties to the latest block.


45-53: Test is well-structured!

The test effectively verifies that a block can be fetched by height and checks its properties against the latest block.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 799fa4d and fe68568.

Files selected for processing (2)
  • java-example/src/main/java/org/onflow/examples/java/get_block/GetBlockAccessAPIConnector.java (1 hunks)
  • java-example/src/test/java/org/onflow/examples/java/get_block/GetBlockAccessAPIConnectorTest.java (1 hunks)
Additional comments not posted (6)
java-example/src/main/java/org/onflow/examples/java/get_block/GetBlockAccessAPIConnector.java (3)

13-23: LGTM: Correctly retrieves the latest sealed block.

The method effectively retrieves the latest sealed block and handles potential errors by throwing a runtime exception with a detailed message.


25-34: LGTM: Correctly retrieves a block by ID.

The method effectively retrieves a block by its ID and handles potential errors by throwing a runtime exception with a detailed message.


36-45: LGTM: Correctly retrieves a block by height.

The method effectively retrieves a block by its height and handles potential errors by throwing a runtime exception with a detailed message.

java-example/src/test/java/org/onflow/examples/java/get_block/GetBlockAccessAPIConnectorTest.java (3)

26-33: LGTM: Validates fetching the latest sealed block.

The test correctly verifies that the latest sealed block is fetched and checks essential properties like ID, height, and timestamp.


35-44: LGTM: Validates fetching a block by ID.

The test ensures that a block can be fetched by its ID and verifies that its properties match those of the latest block.


46-54: LGTM: Validates fetching a block by height.

The test correctly verifies that a block can be fetched by its height and checks that its properties match those of the latest block.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fe68568 and 1ae92e5.

Files selected for processing (4)
  • java-example/src/main/java/org/onflow/examples/java/getBlock/GetBlockAccessAPIConnector.java (1 hunks)
  • java-example/src/test/java/org/onflow/examples/java/getBlock/GetBlockAccessAPIConnectorTest.java (1 hunks)
  • kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getBlock/GetBlockAccessAPIConnector.kt (1 hunks)
  • kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getBlock/GetBlockAccessAPIConnectorTest.kt (1 hunks)
Additional comments not posted (15)
kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getBlock/GetBlockAccessAPIConnector.kt (3)

8-14: LGTM!

The getLatestSealedBlock method is well-implemented, using a when expression to handle success and error responses appropriately.


16-21: LGTM!

The getBlockByID method correctly handles API responses with a when expression, ensuring consistent error handling.


23-28: LGTM!

The getBlockByHeight method is consistent with the other methods, using a when expression for response handling.

java-example/src/main/java/org/onflow/examples/java/getBlock/GetBlockAccessAPIConnector.java (3)

13-23: LGTM!

The getLatestSealedBlock method is well-implemented, using an if statement to handle success and error responses appropriately.


25-34: LGTM!

The getBlockByID method correctly handles API responses with an if statement, ensuring consistent error handling.


36-45: LGTM!

The getBlockByHeight method is consistent with the other methods, using an if statement for response handling.

kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getBlock/GetBlockAccessAPIConnectorTest.kt (3)

23-30: LGTM!

The test method Can fetch the latest sealed block provides adequate coverage and assertions for the block's properties.


32-41: LGTM!

The test method Can fetch a block by ID ensures the correctness of fetching a block by ID, with appropriate assertions.


43-51: LGTM!

The test method Can fetch a block by height ensures the correctness of fetching a block by height, with appropriate assertions.

java-example/src/test/java/org/onflow/examples/java/getBlock/GetBlockAccessAPIConnectorTest.java (6)

3-11: Imports are appropriate.

All imports are necessary for the functionality of the test class.


13-14: Class declaration and annotations are appropriate.

The use of @FlowEmulatorProjectTest and @FlowTestClient is suitable for this test setup.


21-24: Setup method is correctly implemented.

The setup method properly initializes GetBlockAccessAPIConnector with accessAPI.


26-33: Test for fetching the latest sealed block is well-implemented.

The test checks essential properties of the latest sealed block, ensuring its validity.


35-44: Test for fetching block by ID is comprehensive.

The test ensures that the block fetched by ID matches the latest block in all key properties.


46-54: Test for fetching block by height is well-structured.

The test ensures that the block fetched by height matches the latest block in all key properties.

Examples use-cases - get network parameters
Examples use-cases - get event
Examples use-cases - get transaction
Examples use-cases  - get account
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: 12

Outside diff range, codebase verification and nitpick comments (11)
kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt (1)

11-12: Consider using a more descriptive class name.

The class name GetNetworkParametersAccessAPIConnectorTest could be more descriptive to reflect the specific functionality being tested, such as NetworkParametersAccessAPIConnectorTest.

java-example/src/test/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.java (1)

12-13: Consider using a more descriptive class name.

The class name GetNetworkParametersAccessAPIConnectorTest could be more descriptive to reflect the specific functionality being tested, such as NetworkParametersAccessAPIConnectorTest.

java-example/src/main/java/org/onflow/examples/java/getAccount/GetAccountAccessAPIConnector.java (1)

14-22: Consider using a more specific exception type.

Currently, the method throws a RuntimeException for error responses. Consider defining and using a more specific exception type to provide better context for error handling.

// Example: Define a custom exception
public class FlowAccessApiException extends Exception {
    public FlowAccessApiException(String message, Throwable cause) {
        super(message, cause);
    }
}

// Use the custom exception
throw new FlowAccessApiException(errorResponse.getMessage(), errorResponse.getThrowable());
java-example/src/test/java/org/onflow/examples/java/getAccount/GetAccountAccessAPIConnectorTest.java (2)

31-39: Ensure comprehensive test coverage.

The test cases for fetching accounts from the latest block and by block height are well-structured. However, consider adding tests for edge cases, such as handling non-existent accounts or invalid block heights, to ensure robustness.


52-58: Consider testing edge cases for account balance retrieval.

The test for fetching account balance checks for non-null and non-negative values. Consider adding tests for scenarios where the account might not exist or the balance retrieval fails.

kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getEvent/GetEventAccessAPIConnectorTest.kt (3)

41-47: Add edge case tests for event retrieval by height range.

The test for getEventsForHeightRange is well-structured. Consider adding edge cases, such as invalid height ranges or non-existent event types, to ensure comprehensive coverage.


49-62: Consider adding tests for empty block IDs.

The test for getEventsForBlockIds is comprehensive, but consider adding scenarios where the block ID list is empty or contains invalid IDs to ensure robustness.


76-88: Ensure expected event types are comprehensive.

The test for transaction result events checks for expected event types. Verify that all possible event types are covered, and consider adding a test for unexpected event types.

java-example/src/test/java/org/onflow/examples/java/getEvent/GetEventAccessAPIConnectorTest.java (3)

44-50: Add edge case tests for event retrieval by height range.

The test for getEventsForHeightRange is well-structured. Consider adding edge cases, such as invalid height ranges or non-existent event types, to ensure comprehensive coverage.


52-74: Consider adding tests for empty or invalid block IDs.

The test for getEventsForBlockIds is comprehensive, but consider adding scenarios where the block ID list is empty or contains invalid IDs to ensure robustness.


88-100: Ensure comprehensive coverage of expected event types.

The test for transaction result events checks for expected event types. Verify that all possible event types are covered, and consider adding a test for unexpected event types.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1ae92e5 and 6ef59c3.

Files selected for processing (20)
  • java-example/src/main/java/org/onflow/examples/java/AccessAPIConnector.java (3 hunks)
  • java-example/src/main/java/org/onflow/examples/java/getAccount/GetAccountAccessAPIConnector.java (1 hunks)
  • java-example/src/main/java/org/onflow/examples/java/getEvent/GetEventAccessAPIConnector.java (1 hunks)
  • java-example/src/main/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnector.java (1 hunks)
  • java-example/src/main/java/org/onflow/examples/java/getTransaction/GetTransactionAccessAPIConnector.java (1 hunks)
  • java-example/src/test/java/org/onflow/examples/java/getAccount/GetAccountAccessAPIConnectorTest.java (1 hunks)
  • java-example/src/test/java/org/onflow/examples/java/getEvent/GetEventAccessAPIConnectorTest.java (1 hunks)
  • java-example/src/test/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.java (1 hunks)
  • java-example/src/test/java/org/onflow/examples/java/getTransaction/GetTransactionAccessAPIConnectorTest.java (1 hunks)
  • kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/AccessAPIConnector.kt (1 hunks)
  • kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getAccount/GetAccountAccessAPIConnector.kt (1 hunks)
  • kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getEvent/GetEventAccessAPIConnector.kt (1 hunks)
  • kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt (1 hunks)
  • kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getTransaction/GetTransactionAccessAPIConnector.kt (1 hunks)
  • kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getAccount/GetAccountAccessAPIConnectorTest.kt (1 hunks)
  • kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getEvent/GetEventAccessAPIConnectorTest.kt (1 hunks)
  • kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt (1 hunks)
  • kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getTransaction/GetTransactionAccessAPIConnectorTest.kt (1 hunks)
  • sdk/src/intTest/org/onflow/flow/sdk/transaction/TransactionIntegrationTest.kt (1 hunks)
  • sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt (1 hunks)
Files skipped from review due to trivial changes (1)
  • sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt
Additional context used
Learnings (3)
kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getAccount/GetAccountAccessAPIConnectorTest.kt (1)
Learnt from: franklywatson
PR: onflow/flow-jvm-sdk#55
File: src/intTest/org/onflow/flow/sdk/ExposeAccountKeyIssueTest.kt:151-152
Timestamp: 2024-07-04T05:15:46.310Z
Learning: When reviewing test code, avoid recommending additional exception handling if it might obscure the actual failure points and over-sensitize the process.
sdk/src/intTest/org/onflow/flow/sdk/transaction/TransactionIntegrationTest.kt (1)
Learnt from: lealobanov
PR: onflow/flow-jvm-sdk#55
File: src/intTest/org/onflow/flow/sdk/transaction/TransactionIntegrationTest.kt:95-106
Timestamp: 2024-07-03T12:30:04.496Z
Learning: In the `TransactionIntegrationTest` class, exception handling is implemented using `IntegrationTestUtils.handleResult`.
java-example/src/main/java/org/onflow/examples/java/AccessAPIConnector.java (1)
Learnt from: lealobanov
PR: onflow/flow-jvm-sdk#67
File: java-example/src/main/java/org/onflow/examples/java/AccessAPIConnector.java:103-103
Timestamp: 2024-08-02T18:59:04.927Z
Learning: Logging public keys during debugging can aid in troubleshooting but should be removed or secured before moving to production environments to avoid potential security risks.
Additional comments not posted (21)
kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getAccount/GetAccountAccessAPIConnector.kt (1)

23-26: Ensure account balance retrieval handles null values.

The method getAccountBalance retrieves the balance from the account object. Ensure that the account object and its balance property are not null to prevent potential NullPointerException.

kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt (1)

23-30: Test assertions look good.

The test method Can fetch network parameters correctly checks for non-nullity, valid ID, and expected values of network parameters. The assertions are clear and appropriate.

java-example/src/test/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.java (1)

25-32: Test assertions look good.

The test method canFetchNetworkParameters correctly checks for non-nullity, valid ID, and expected values of network parameters. The assertions are clear and appropriate.

java-example/src/main/java/org/onflow/examples/java/getTransaction/GetTransactionAccessAPIConnector.java (1)

8-14: Constructor initialization looks good.

The constructor correctly initializes the accessAPI field, ensuring that the API connector is ready for use.

kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getEvent/GetEventAccessAPIConnector.kt (1)

5-7: Constructor initialization looks good.

The primary constructor correctly initializes the accessAPI field, ensuring that the API connector is ready for use.

java-example/src/main/java/org/onflow/examples/java/getAccount/GetAccountAccessAPIConnector.java (2)

24-32: Consider using a more specific exception type.

Currently, the method throws a RuntimeException for error responses. Consider defining and using a more specific exception type to provide better context for error handling.


34-37: LGTM!

The method correctly retrieves the account balance. No issues found.

kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getAccount/GetAccountAccessAPIConnectorTest.kt (3)

25-33: LGTM!

The test effectively verifies fetching an account from the latest block with appropriate assertions.


35-43: LGTM!

The test effectively verifies fetching an account from a block by height with appropriate assertions.


45-52: LGTM!

The test correctly verifies fetching the account balance with appropriate assertions.

kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getTransaction/GetTransactionAccessAPIConnectorTest.kt (2)

40-46: LGTM!

The test effectively verifies fetching a transaction with appropriate assertions.


48-54: LGTM!

The test correctly verifies fetching a transaction result with appropriate assertions.

java-example/src/test/java/org/onflow/examples/java/getTransaction/GetTransactionAccessAPIConnectorTest.java (2)

47-53: LGTM!

The test effectively verifies fetching a transaction with appropriate assertions.


55-61: LGTM!

The test correctly verifies fetching a transaction result with appropriate assertions.

kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/AccessAPIConnector.kt (2)

104-137: LGTM!

The sendSampleTransaction function is well-structured and correctly handles transaction creation and sending.


145-145: LGTM!

The removal of the unnecessary variable assignment in transferTokens simplifies the code without affecting functionality.

sdk/src/intTest/org/onflow/flow/sdk/transaction/TransactionIntegrationTest.kt (1)

27-27: LGTM!

Updating the error message to specify a failure to ping the emulator aligns with the test's context and improves clarity.

java-example/src/main/java/org/onflow/examples/java/AccessAPIConnector.java (4)

85-92: LGTM!

The addition of an assertion to ensure the address is not null improves the robustness of the getAccountCreatedAddress method.


Line range hint 107-123: LGTM!

The createTransaction method improves modularity and reduces code duplication by centralizing transaction creation logic.


125-129: LGTM!

The signAndSendTransaction method effectively consolidates signing and sending logic, improving readability and maintainability.


131-153: LGTM!

The refactoring of createAccount and the introduction of sendSampleTransaction enhance code clarity and reduce duplication by leveraging new helper methods.

Comment on lines +29 to +39
public List<FlowEventResult> getEventsForBlockIds(String eventType, List<FlowId> blockIds) {
Set<FlowId> blockIdSet = new HashSet<>(blockIds);
FlowAccessApi.AccessApiCallResponse<List<FlowEventResult>> response = accessAPI.getEventsForBlockIds(eventType, blockIdSet);
if (response instanceof FlowAccessApi.AccessApiCallResponse.Success) {
return ((FlowAccessApi.AccessApiCallResponse.Success<List<FlowEventResult>>) response).getData();
} else if (response instanceof FlowAccessApi.AccessApiCallResponse.Error errorResponse) {
throw new RuntimeException(errorResponse.getMessage(), errorResponse.getThrowable());
} else {
throw new RuntimeException("Unknown response type");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Enhance type safety with Java Generics.

In getEventsForBlockIds, consider using Java Generics to improve type safety and reduce casting.

// Current casting
return ((FlowAccessApi.AccessApiCallResponse.Success<List<FlowEventResult>>) response).getData();

// Suggested use of generics
if (response instanceof FlowAccessApi.AccessApiCallResponse.Success<List<FlowEventResult>> successResponse) {
    return successResponse.getData();
}

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6ef59c3 and 8ebb852.

Files selected for processing (2)
  • java-example/src/main/java/org/onflow/examples/java/AccessAPIConnector.java (3 hunks)
  • kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/AccessAPIConnector.kt (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/AccessAPIConnector.kt
Additional context used
Learnings (1)
java-example/src/main/java/org/onflow/examples/java/AccessAPIConnector.java (1)
Learnt from: lealobanov
PR: onflow/flow-jvm-sdk#67
File: java-example/src/main/java/org/onflow/examples/java/AccessAPIConnector.java:103-103
Timestamp: 2024-08-02T18:59:04.927Z
Learning: Logging public keys during debugging can aid in troubleshooting but should be removed or secured before moving to production environments to avoid potential security risks.
Additional comments not posted (4)
java-example/src/main/java/org/onflow/examples/java/AccessAPIConnector.java (4)

Line range hint 107-123: Good encapsulation of transaction creation logic.

The createTransaction method effectively encapsulates the logic for creating a FlowTransaction object, enhancing modularity and readability.


131-139: Refactored createAccount for improved modularity.

The createAccount method now uses createTransaction and signAndSendTransaction, reducing duplication and enhancing modularity.

Verify that the script cadence/create_account.cdc is correctly located and accessible.

Run the following script to verify the script's accessibility:

Verification successful

Script create_account.cdc is accessible and correctly located.

The script create_account.cdc is found at common/src/main/resources/cadence/create_account.cdc, confirming its accessibility for use in the createAccount method.

  • Location: common/src/main/resources/cadence/create_account.cdc
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the accessibility of `cadence/create_account.cdc`.

# Test: Check if the script file exists. Expect: File should be found.
fd 'create_account.cdc' --type f

Length of output: 149


144-152: Well-structured sendSampleTransaction method.

The sendSampleTransaction method is similar to createAccount but returns the transaction ID, serving a different use case.

Ensure that the script cadence/create_account.cdc is consistently used and accessible.

Run the following script to verify the script's consistency:


125-129: Simplified transaction signing and sending.

The signAndSendTransaction method effectively consolidates the signing and sending process, improving code clarity.

Ensure that the sendTransaction method handles errors appropriately.

Run the following script to verify error handling in sendTransaction:

Verification successful

Error handling in sendTransaction is appropriate.

The sendTransaction method checks for success and throws a RuntimeException with detailed error information if the transaction fails. This ensures that errors are properly managed and communicated.

  • Lines 173-179 in AccessAPIConnector.java confirm the presence of error handling.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify error handling in `sendTransaction`.

# Test: Search for error handling in `sendTransaction`. Expect: Proper handling of error responses.
rg --type java 'private FlowId sendTransaction'

Length of output: 182


Script:

#!/bin/bash
# Extract the full implementation of the `sendTransaction` method to review error handling.
ast-grep --lang java --pattern $'private FlowId sendTransaction(FlowTransaction tx) {
  $$$
}'

Length of output: 1273

@lealobanov lealobanov merged commit 0bc8410 into main Aug 20, 2024
6 checks passed
@lealobanov lealobanov deleted the get-blocks-example branch September 5, 2024 15:01
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