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

chore: system contract tests #622

Merged
merged 5 commits into from
Sep 24, 2024
Merged

chore: system contract tests #622

merged 5 commits into from
Sep 24, 2024

Conversation

outerlook
Copy link
Contributor

@outerlook outerlook commented Sep 20, 2024

Description

  • adds new tests
  • improve system contract hex handling
  • fix system contract expected foreign calls
  • change test helpers to accommodate requirements

Related Problem

How Has This Been Tested?

  • all tests passing

Summary by CodeRabbit

  • New Features

    • Enhanced validation and handling of Ethereum addresses across multiple procedures.
    • Introduced new procedures for better contract management and address validation.
    • Added a comprehensive suite of unit tests for system contract functionality.
  • Bug Fixes

    • Improved error handling for Ethereum address creation in tests.
  • Refactor

    • Updated function signatures and structures to improve clarity and organization in test setups.
  • Tests

    • Added new test cases to validate the behavior of the system contract and its procedures.

Copy link

coderabbitai bot commented Sep 20, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces significant changes to the handling of system contracts, including modifications to variable types, the addition of new procedures for Ethereum address validation, and the implementation of a comprehensive suite of automated tests for the system contract. The changes encompass updates to existing test files, new test functions, and the restructuring of data handling to improve clarity and organization.

Changes

Files Change Summary
internal/contracts/contracts.go Renamed and modified variables related to system contract content, changing types from string to []byte. Introduced a new variable for the string content and updated tests to reflect these changes.
internal/contracts/system_contract.kf Updated procedures to enhance Ethereum address handling, including visibility changes, parameter additions, and new validation procedures. Enhanced checks for address validity and updated existing procedures to use validated addresses.
internal/contracts/tests/index_change_test.go Restructured test functions to include a setup for Ethereum address deployment. Introduced a new test for division by zero and improved error handling in existing tests.
internal/contracts/tests/primitive_test.go Added Ethereum address creation in the test setup, enhancing the initialization process.
internal/contracts/tests/system_contract_test.go Introduced a new suite of tests for system contract functionality, covering deployment, stream management, and data retrieval. Organized tests into distinct functions for clarity and maintainability.
internal/contracts/tests/utils/setup/common.go Refactored the initializeContract function to accept a structured input, improving parameter handling.
internal/contracts/tests/utils/setup/composed.go Updated the setupComposedAndPrimitives function to utilize a new deployer variable and structured input for contract initialization.
internal/contracts/tests/utils/setup/primitive.go Modified structures to include a new Deployer field, enhancing the handling of the deployer address across various functions.

Assessment against linked issues

Objective Addressed Explanation
Develop automated tests for the system contract ( #585 )

Possibly related PRs

Suggested reviewers

  • MicBun

Poem

In the meadow, contracts bloom,
With bytes and strings, there's plenty of room.
Tests hop along, ensuring all's right,
Validations dance in the soft moonlight.
A rabbit's cheer for the code so fine,
Hopping through changes, all will align! 🐇✨


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

Refactored variable `SystemContractContent` to handle byte content and renamed the string version for clarity. Added comprehensive tests for system contract functionalities, including deployment, stream acceptance and revocation, and methods validation.
Refactored the test setup functions to inject the deployer address, improving consistency and reducing redundancy. This change centralizes the creation of the deployer and ensures it is correctly assigned and used across multiple test setups.
Validate and clean Ethereum addresses in procedures. Refactor tests for better readability and setup initial contract states. Added checks for address length and hex validity.
This commit adds a new test case, `testDivisionByZero`, to ensure that the system correctly handles division by zero errors during index change calculations. The test sets up a primitive stream and verifies that an error is raised when division by zero occurs, aligning with our expected behavior.
@outerlook outerlook force-pushed the chore/sys-contract-tests branch from 01da799 to b714292 Compare September 24, 2024 12:52
@outerlook outerlook marked this pull request as ready for review September 24, 2024 12:53
@outerlook outerlook requested a review from MicBun September 24, 2024 12:53
@outerlook outerlook merged commit 5bbeac1 into main Sep 24, 2024
7 checks passed
@outerlook outerlook deleted the chore/sys-contract-tests branch September 24, 2024 12:57
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.

Problem: System contract automated tests missing
2 participants