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

Add new endpoint to runtime-rest-clime: Get Status Endpoint #150

Merged
merged 1 commit into from
Jan 5, 2024
Merged

Conversation

nhenin
Copy link
Member

@nhenin nhenin commented Dec 27, 2023

As part of resolving issue #145 , the following 2 items were addressed

  • Added Runtime Status Endpoint : In order for the E2E tests to work we need to make sure that the Tip information of the runtime is synchronized with lucid
  • As part of the testing, we noted that the response of getContractById was badly typed.

@nhenin nhenin self-assigned this Dec 27, 2023
Copy link
Contributor

coderabbitai bot commented Dec 27, 2023

Walkthrough

The codebase has been updated to improve the handling of nullable values, with a shift towards using undefined over null. This involves updates to both utility functions and API interactions, with an emphasis on functional programming practices. The changes streamline the process of fetching and asserting contract details, as well as refining the test suite to align with the updated logic.

Changes

Files Summary
packages/adapter/src/io-ts.ts, .../http.ts, .../index.ts Introduced convertNullableToUndefined function using withValidate from "io-ts-types", added getWithHeaders function, and renamed exported namespace.
packages/runtime/client/rest/src/contract/details.ts, .../singleton.ts, .../index.ts Replaced optionFromNullable with fromNullable, integrated convertNullableToUndefined, and updated control flow and error handling.
packages/runtime/client/rest/src/index.ts, .../runtime/index.ts, .../runtime/status.ts Refactored methods, added new functionality for retrieving runtime status, and exported new functionality.
packages/runtime/client/rest/test/endpoints/contracts.spec.e2e.ts, .../payouts.spec.e2e.ts, .../runtime.spec.e2e.ts Updated test descriptions and logic, added new tests, and streamlined imports.
changelog.d/20240103_085440_nicolas.henin_runtimeStatus.md Introduced new file for runtime status endpoint.
packages/runtime/core/src/index.ts, .../network.ts Added exports and introduced functionality for handling network identifiers and types.
packages/runtime/lifecycle/test/context.ts Introduced new imports and modified existing function.
packages/wallet/src/nodejs/index.ts Updated imports and added a new method.

🐇✨
In a burrow, deep and wide,
CodeRabbit hops with pride.
Nulls to undefined, we glide,
Cleaner code on every side. 🌟🌿

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's AI:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d810605 and 2de6c0d.
Files selected for processing (6)
  • packages/adapter/src/io-ts.ts (2 hunks)
  • packages/runtime/client/rest/src/contract/details.ts (3 hunks)
  • packages/runtime/client/rest/src/contract/endpoints/singleton.ts (2 hunks)
  • packages/runtime/client/rest/src/index.ts (2 hunks)
  • packages/runtime/client/rest/test/endpoints/contracts.spec.e2e.ts (2 hunks)
  • packages/runtime/client/rest/test/endpoints/payouts.spec.e2e.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/runtime/client/rest/test/endpoints/payouts.spec.e2e.ts
Additional comments: 5
packages/runtime/client/rest/test/endpoints/contracts.spec.e2e.ts (1)
  • 13-14: The updated test description is more accurate and reflects the test's intent.
packages/adapter/src/io-ts.ts (1)
  • 64-77: The convertNullableToUndefined function is a well-designed utility that enhances the handling of nullable values in codecs.
packages/runtime/client/rest/src/contract/details.ts (1)
  • 99-105: The changes to ContractDetailsGuard use convertNullableToUndefined to handle nullable fields. Ensure that these changes have been tested, or consider updating existing tests to cover the new logic.
packages/runtime/client/rest/src/index.ts (2)
  • 286-290: The refactoring of getContractById to use the new Contract.getContractById method is consistent with the PR objectives and the AI-generated summary. This change should streamline the process of getting contract details by ID and improve error handling with the new method's implementation.

  • 587-590: The update to the contracts.contract.get method in the mkFPTSRestClient function to use TE.fromTask and the new Contract.getContractById method is a good change. It aligns with the PR objectives to handle nullable fields and improve deserialization. This change also encapsulates the asynchronous nature of the operation, which is more idiomatic in functional programming with fp-ts.

@nhenin nhenin changed the title Fixed deserialization issues with fields set to null on getContractById Runtime Status Endpoint Jan 3, 2024
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.

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2de6c0d and 8bc1e12.
Files ignored due to filter (1)
  • packages/runtime/client/rest/typedoc.json
Files selected for processing (12)
  • changelog.d/20240103_085440_nicolas.henin_runtimeStatus.md (1 hunks)
  • packages/adapter/src/http.ts (1 hunks)
  • packages/adapter/src/index.ts (1 hunks)
  • packages/runtime/client/rest/src/guards.ts (1 hunks)
  • packages/runtime/client/rest/src/index.ts (5 hunks)
  • packages/runtime/client/rest/src/runtime/index.ts (1 hunks)
  • packages/runtime/client/rest/src/runtime/status.ts (1 hunks)
  • packages/runtime/client/rest/test/endpoints/runtime.spec.e2e.ts (1 hunks)
  • packages/runtime/core/src/index.ts (1 hunks)
  • packages/runtime/core/src/network.ts (1 hunks)
  • packages/runtime/lifecycle/test/context.ts (1 hunks)
  • packages/wallet/src/nodejs/index.ts (4 hunks)
Files skipped from review due to trivial changes (3)
  • packages/adapter/src/index.ts
  • packages/runtime/client/rest/src/guards.ts
  • packages/runtime/client/rest/src/runtime/index.ts
Additional comments: 7
changelog.d/20240103_085440_nicolas.henin_runtimeStatus.md (1)
  • 1-3: The changelog correctly documents the addition of the GetRuntimeStatus endpoint. Ensure that the format aligns with the project's changelog standards.
packages/runtime/core/src/index.ts (1)
  • 12-12: The export statement for "network.js" is added correctly. Verify that there are no naming conflicts or issues with the exported entities from "network.js".
packages/runtime/client/rest/src/index.ts (5)
  • 43-43: Added import for RuntimeStatus and getRuntimeStatus function.

  • 67-70: Added getRuntimeStatus method to the RestClient interface.

  • 279-280: Implemented getRuntimeStatus in the mkRestClient function.

  • 296-296: Modified implementation of getContractById method.

  • 596-598: Refactored contracts.contract.get method in mkFPTSRestClient to use a new implementation.

@hrajchert hrajchert changed the title Runtime Status Endpoint Add new endpoint to runtime-rest-clime: Get Status Endpoint Jan 3, 2024
Comment on lines +99 to +105
t.partial({
currentContract: convertNullableToUndefined(G.Contract),
state: convertNullableToUndefined(G.MarloweState),
}),
t.partial({ utxo: convertNullableToUndefined(TxOutRef) }),
t.partial({ block: convertNullableToUndefined(BlockHeaderGuard) }),
t.partial({ txBody: convertNullableToUndefined(TextEnvelopeGuard) }),
Copy link
Collaborator

Choose a reason for hiding this comment

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

The guard was failing because it expected an undefined value when the data wasn't present, but the runtime is responding with null instead. This doesn't change the type of the response, it just makes sure that the guard works with the previous type.

@@ -0,0 +1,3 @@
### @marlowe.io/runtime-rest-client

- Added a new endpoint `GetRuntimeStatus` that retrieves informations about the Runtime (version deployed, Network Id of the Node and tips)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add this as part of healthcheck response instead of creating a new endpoint

@nhenin nhenin merged commit 57995e4 into main Jan 5, 2024
6 of 8 checks passed
@nhenin nhenin deleted the fix branch January 5, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants