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

Refactor testent and previewnet integration tests #65

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

Conversation

illia-malachyn
Copy link
Contributor

@illia-malachyn illia-malachyn commented Sep 5, 2024

Merge testnet and integration test into one file

Summary by CodeRabbit

  • New Features

    • Introduced utility functions for managing Flow accounts and transactions, enhancing the testing framework.
    • Added comprehensive integration tests for blockchain interactions using the Rosetta API.
    • Created structured JSON configurations for account signers in both testnet and previewnet environments.
  • Bug Fixes

    • Updated file paths and activated previously commented-out functions in integration tests for improved functionality.
  • Documentation

    • Enhanced clarity and organization of the testing framework through updates to configuration files and command structures.

Merge testent and integration test into one file
Copy link

coderabbitai bot commented Sep 5, 2024

Warning

Rate limit exceeded

@illia-malachyn has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 8 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 0d168ff and 75e85f5.

Walkthrough

The changes encompass modifications to the Makefile for better organization of integration tests and cleanup processes, the introduction of utility functions in tests/helpers.py, and the creation of integration tests in tests/integration_test.py. Additionally, file paths were updated in tests/localnet_integration_test.py, and several configuration files were adjusted to reflect new blockchain parameters. New JSON files were added for account signer configurations, enhancing the overall structure and functionality of the testing framework.

Changes

Files Change Summary
Makefile Renamed targets for integration tests and cleanup, updated file paths, and specified network options.
tests/helpers.py Introduced utility functions for account management and contract deployment.
tests/integration_test.py Implemented integration tests for blockchain operations using the Rosetta API.
tests/localnet_integration_test.py Updated file paths and activated previously commented-out functions for account creation and transfers.
tests/previewnet.json Modified contract identifiers and network settings.
tests/previewnet_account_signer.json Defined a JSON structure for account signer configuration.
tests/rosetta.py Implemented functions for managing accounts and transactions via the Rosetta API.
tests/testnet.json Updated spork version and root block values.
tests/testnet_account_signer.json Introduced structured representation of a test account signer configuration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant RosettaAPI
    participant FlowAccount

    User->>CLI: Start integration test
    CLI->>FlowAccount: Create originator account
    FlowAccount-->>CLI: Return account details
    CLI->>RosettaAPI: Setup Rosetta server
    CLI->>FlowAccount: Create accounts for Alice and Bob
    FlowAccount-->>CLI: Return account details
    CLI->>FlowAccount: Transfer assets between accounts
    FlowAccount-->>CLI: Confirm transfer
    CLI->>User: Display transfer status
Loading

🐰 "In the garden where changes bloom,
New paths for tests, dispelling gloom.
With helpers to guide and scripts that play,
The blockchain hops in a brighter way!
Let's dance in the fields, all frolic and cheer,
For every new feature, we hold dear!" 🐇


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

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

@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: 24

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 41d1988 and 0d168ff.

Files selected for processing (9)
  • Makefile (1 hunks)
  • tests/helpers.py (1 hunks)
  • tests/integration_test.py (1 hunks)
  • tests/localnet_integration_test.py (9 hunks)
  • tests/previewnet.json (3 hunks)
  • tests/previewnet_account_signer.json (1 hunks)
  • tests/rosetta.py (1 hunks)
  • tests/testnet.json (1 hunks)
  • tests/testnet_account_signer.json (1 hunks)
Additional context used
Gitleaks
tests/previewnet_account_signer.json

8-8: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

tests/testnet_account_signer.json

8-8: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

tests/helpers.py

18-18: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


125-125: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Ruff
tests/integration_test.py

3-3: from rosetta import * used; unable to detect undefined names

(F403)


4-4: from helpers import * used; unable to detect undefined names

(F403)


9-9: sys may be undefined, or defined from star imports

(F405)


16-16: read_account may be undefined, or defined from star imports

(F405)


18-18: rosetta_create_account_transaction may be undefined, or defined from star imports

(F405)


24-24: rosetta_create_account_transaction may be undefined, or defined from star imports

(F405)


30-30: rosetta_transfer may be undefined, or defined from star imports

(F405)


39-39: rosetta_transfer may be undefined, or defined from star imports

(F405)


49-49: read_account may be undefined, or defined from star imports

(F405)


50-50: rosetta_proxy_transfer may be undefined, or defined from star imports

(F405)


70-70: sys may be undefined, or defined from star imports

(F405)


72-72: sys may be undefined, or defined from star imports

(F405)


72-72: sys may be undefined, or defined from star imports

(F405)


103-103: subprocess may be undefined, or defined from star imports

(F405)


103-103: subprocess may be undefined, or defined from star imports

(F405)


109-109: read_account_signer may be undefined, or defined from star imports

(F405)


110-110: save_account_to_flow_json may be undefined, or defined from star imports

(F405)


121-121: create_flow_account may be undefined, or defined from star imports

(F405)


134-134: save_account_to_flow_json may be undefined, or defined from star imports

(F405)


136-136: deploy_contract may be undefined, or defined from star imports

(F405)


140-140: json may be undefined, or defined from star imports

(F405)


144-144: json may be undefined, or defined from star imports

(F405)


148-148: convert_to_rosetta_address may be undefined, or defined from star imports

(F405)


152-152: json may be undefined, or defined from star imports

(F405)


163-163: create_flow_account may be undefined, or defined from star imports

(F405)


164-164: convert_to_rosetta_address may be undefined, or defined from star imports

(F405)


166-166: save_account may be undefined, or defined from star imports

(F405)


175-175: subprocess may be undefined, or defined from star imports

(F405)


175-175: subprocess may be undefined, or defined from star imports

(F405)

tests/localnet_integration_test.py

42-42: Use context handler for opening files

(SIM115)

tests/rosetta.py

1-1: from helpers import * used; unable to detect undefined names

(F403)


29-29: generate_keys may be undefined, or defined from star imports

(F405)


47-47: f-string without any placeholders

Remove extraneous f prefix

(F541)


52-52: f-string without any placeholders

Remove extraneous f prefix

(F541)


58-58: f-string without any placeholders

Remove extraneous f prefix

(F541)


64-64: subprocess may be undefined, or defined from star imports

(F405)


64-64: subprocess may be undefined, or defined from star imports

(F405)


93-93: save_account may be undefined, or defined from star imports

(F405)


146-146: read_account_keys may be undefined, or defined from star imports

(F405)


152-152: subprocess may be undefined, or defined from star imports

(F405)


152-152: subprocess may be undefined, or defined from star imports

(F405)


247-247: read_account may be undefined, or defined from star imports

(F405)


250-250: subprocess may be undefined, or defined from star imports

(F405)


250-250: subprocess may be undefined, or defined from star imports

(F405)


276-276: read_account may be undefined, or defined from star imports

(F405)


279-279: subprocess may be undefined, or defined from star imports

(F405)


279-279: subprocess may be undefined, or defined from star imports

(F405)


332-332: request_router may be undefined, or defined from star imports

(F405)


357-357: request_router may be undefined, or defined from star imports

(F405)


386-386: request_router may be undefined, or defined from star imports

(F405)


434-434: request_router may be undefined, or defined from star imports

(F405)


459-459: request_router may be undefined, or defined from star imports

(F405)

Additional comments not posted (14)
Makefile (1)

30-31: Review of testnet-integration-test and previewnet-integration-test targets

The integration test targets have been renamed and updated to execute a specific Python script with network parameters. Here are the key points:

  1. Script Execution: Both targets now explicitly call python3 tests/integration_test.py with a network-specific parameter (--network testnet for testnet-integration-test and --network previewnet for previewnet-integration-test). This is a clear and straightforward way to specify the test environment.
  2. Consistency and Clarity: The update enhances clarity by specifying the network context directly in the make target, which helps in understanding and running the correct tests for the desired network.

These changes are well-aligned with the PR's objectives to streamline and clarify the testing process. No issues are observed with the current implementation.

Also applies to: 34-34

tests/testnet.json (2)

23-23: Updated spork version to "51".

The change in spork version from "50" to "51" is noted. This update is crucial as it likely corresponds to a new set of operational parameters for the blockchain. Ensure that this version update is consistent with the intended upgrades or changes in the blockchain configuration.


29-29: Updated root_block value to 211176670.

The root_block value has been updated from 185185854 to 211176670. This change is significant as it adjusts the starting point for the blockchain's operations under the new spork. It's important to verify that this new root_block value is correct and aligns with the blockchain's historical data and planned operations.

tests/previewnet.json (3)

9-9: Verify the new contract address for flow_cold_storage_proxy.

The contract address has been updated to 0x05f842cd1b178690. It is crucial to verify that this address is correct and corresponds to an active contract on the network.

Run the following script to verify the contract address:


31-31: Verify the new root_block value.

The root_block value has been updated to 29859120. It is important to verify that this value is correct and reflects the current state of the network, especially in terms of synchronization and accessing historical data.

Run the following script to verify the root_block value:


19-19: Verify the new address in the originators array.

The originators array now includes the address 0x05f842cd1b178690. Ensure that this address is correctly included and has the appropriate permissions or roles within the network.

Run the following script to verify the address in the originators array:

tests/localnet_integration_test.py (8)

72-72: Approved path update in init_flow_json.

The update to use a relative path for flow.json is consistent with the PR's objectives to improve path management.


115-115: Approved path updates in gen_contract_account.

The updates to use relative paths for flow.json and account-keys.csv are consistent with the PR's objectives to improve path management.

Also applies to: 125-125


130-130: Approved path update in deploy_contracts.

The update to use a relative path for the contract file is consistent with the PR's objectives to improve path management.


143-143: Approved path update in seed_contract_accounts.

The update to use a relative path for account-keys.csv is consistent with the PR's objectives to improve path management.


167-167: Approved path update in get_account_keys.

The update to use a relative path for account-keys.csv is consistent with the PR's objectives to improve path management.


211-211: Approved path update in rosetta_create_account.

The update to use a relative path for account-keys.csv is consistent with the PR's objectives to improve path management.


243-243: Approved path update in rosetta_create_proxy_account.

The update to use a relative path for account-keys.csv is consistent with the PR's objectives to improve path management.


479-487: Approved activation of previously commented-out functions in the main script.

The activation of these functions enhances the script's functionality by ensuring that account creation and transfers are executed as part of the main flow.

Comment on lines +1 to +10
{
"address": "941840a945dddfd0",
"key": {
"type": "hex",
"index": 0,
"signatureAlgorithm": "ECDSA_secp256k1",
"hashAlgorithm": "SHA3_256",
"privateKey": "573e4f583fa08997e3ca91a4adcbcd5831ccb0b4d8e47476bec0b305c3e5b79a"
}
}
Copy link

Choose a reason for hiding this comment

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

Critical Security Issue: Exposed Private Key

The inclusion of a private key directly in the JSON configuration file poses a significant security risk. This could potentially expose sensitive operations and access to various services.

To mitigate this risk, consider the following actions:

  • Remove the private key from the file.
  • Use environment variables or a secure vault solution to handle sensitive data securely.

Would you like assistance in implementing these changes?

Tools
Gitleaks

8-8: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

"index": 0,
"signatureAlgorithm": "ECDSA_secp256k1",
"hashAlgorithm": "SHA3_256",
"privateKey": "8ad6b3c4ab1cb753139285870c9361590269ed633356f7349067c74b8080e834"
Copy link

Choose a reason for hiding this comment

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

Critical Security Issue: Exposed Private Key

The inclusion of a private key directly in the JSON file poses a significant security risk. This can lead to unauthorized access and should be avoided.

Consider the following alternatives to enhance security:

  • Remove the private key from the file and instead load it from environment variables or a secure vault solution.
  • If the key must remain in the file for local or testing purposes, ensure this file is never included in version control or accessible in production environments.
-    "privateKey": "8ad6b3c4ab1cb753139285870c9361590269ed633356f7349067c74b8080e834"
+    "privateKey": "<REDACTED>"
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"privateKey": "8ad6b3c4ab1cb753139285870c9361590269ed633356f7349067c74b8080e834"
"privateKey": "<REDACTED>"
Tools
Gitleaks

8-8: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Makefile Outdated Show resolved Hide resolved
receiver_address=alice_account_rosetta["address"],
amount=50,
i=0)
time.sleep(20) # Hacky fix to not check nonce
Copy link

Choose a reason for hiding this comment

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

Consider alternatives to using time.sleep for handling nonces.

Using time.sleep as a hacky fix to avoid nonce issues is not reliable and can lead to unpredictable behavior in automated tests.

Explore more robust methods for handling nonces, such as checking transaction status or implementing a retry mechanism with backoff until the nonce is updated.

Also applies to: 46-46

i=0)
time.sleep(20)

# TODO: Proxy transfer doesn't work for now. Make it work
Copy link

Choose a reason for hiding this comment

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

Address the TODO comment regarding proxy transfers.

The TODO comment indicates that proxy transfers do not work currently. This should be addressed to ensure the functionality is complete.

Would you like assistance in debugging and implementing the proxy transfer functionality? I can help by looking into the issue or opening a GitHub issue to track this task.

tests/rosetta.py Outdated Show resolved Hide resolved
tests/rosetta.py Outdated Show resolved Hide resolved
tests/rosetta.py Outdated Show resolved Hide resolved
tests/rosetta.py Outdated Show resolved Hide resolved
tests/rosetta.py Outdated Show resolved Hide resolved
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.

1 participant