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

PLT-9089: create contract bundle support #167

Merged
merged 5 commits into from
Jan 18, 2024

Conversation

hrajchert
Copy link
Collaborator

@hrajchert hrajchert commented Jan 12, 2024

This PR modifies the runtimeLifecycle.contracts.createContract method to support bundles in a non-breaking way.

Additionaly I also modified the e2e test configuration to be able to debug it.
For the moment to debug e2e tests you need to build (recommended with watch mode) in one terminal

$ tsc --build tsconfig.test.json --watch

Open up a VSCode Debug Terminal and execute

$ node --experimental-vm-modules node_modules/.bin/jest \
 --testRegex ".*e2e.spec.js$" \
 --runInBand \
 --modulePaths $(pwd)/packages/runtime/lifecycle/test-dist

That should attach the debugging session correctly with the source maps. In a future PR I'll modify the launch configuration to simplify this even further.

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration for test environments.
    • Added support for creating contracts from contract bundles.
    • Enhanced contract creation workflow with additional request options.
  • Improvements

    • Streamlined the contract and payout retrieval process with a new REST client.
  • Refactor

    • Reorganized environment configuration to use JSON format.
    • Updated test setup to use new configuration and client creation methods.
  • Documentation

    • Updated development guide to reflect changes in the environment setup process.
  • Bug Fixes

    • Fixed an issue where contract creation was not properly handling different request types.

@hrajchert hrajchert marked this pull request as draft January 12, 2024 16:01
Copy link
Contributor

coderabbitai bot commented Jan 12, 2024

Walkthrough

The updates reflect a shift towards a more modular and testable codebase, with changes to configuration reading and endpoint testing. A new client creation pattern is introduced for REST interactions, and contract creation logic is expanded to handle multiple request types. The testing infrastructure is notably enhanced with better configuration handling and project root detection, streamlining the development and testing workflow.

Changes

File Path Change Summary
.vscode/settings.json Added multiple new paths to the settings for test files.
doc/howToDevelop.md Updated the environment configuration from bash script to JSON format.
.../client/rest/test/endpoints/*.spec.e2e.ts
.../lifecycle/test/.../*.e2e.spec.ts
Replaced readEnvConfigurationFile with readTestConfiguration and updated usage of runtime.client to mkRestClient and mkLifecycle.
.../lifecycle/src/api.ts Introduced new interfaces for contract creation and adjusted CreateContractRequest type.
.../lifecycle/src/generic/contracts.ts Renamed a response to request, added new request options, and updated contract creation logic.
packages/testing-kit/src/environment/configuration.ts Refactored configuration reading using io-ts and added findRootDir function.
packages/testing-kit/src/environment/index.ts Updated imports, parameters, and replaced runtime with mkLifecycle function.

🐇✨
In the code's burrow, deep and wide,
New paths emerge, side by side.
A rabbit's touch, so deft and neat,
Makes the codebase hop to a newer beat. 🎶🌟

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-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 and a 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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between db2f342 and 2193f6e.
Files ignored due to filter (1)
  • tsconfig.test.json
Files selected for processing (11)
  • .vscode/settings.json (1 hunks)
  • doc/howToDevelop.md (1 hunks)
  • examples/nodejs/src/marlowe-object-flow.ts (1 hunks)
  • packages/runtime/client/rest/test/endpoints/contracts.spec.e2e.ts (5 hunks)
  • packages/runtime/client/rest/test/endpoints/payouts.spec.e2e.ts (4 hunks)
  • packages/runtime/lifecycle/src/api.ts (4 hunks)
  • packages/runtime/lifecycle/src/generic/contracts.ts (5 hunks)
  • packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (3 hunks)
  • packages/runtime/lifecycle/test/generic/contracts.e2e.spec.ts (3 hunks)
  • packages/testing-kit/src/environment/configuration.ts (1 hunks)
  • packages/testing-kit/src/environment/index.ts (4 hunks)
Additional comments: 11
.vscode/settings.json (1)
  • 15-20: The updates to include additional paths for test distributions in .vscode/settings.json look good and are consistent with the project structure.
packages/runtime/client/rest/test/endpoints/payouts.spec.e2e.ts (1)
  • 11-12: The refactoring to use readTestConfiguration and mkRestClient in payouts.spec.e2e.ts is correctly implemented.
packages/testing-kit/src/environment/configuration.ts (1)
  • 24-61: The refactoring in configuration.ts to use io-ts for configuration validation and the introduction of readTestConfiguration function are correctly implemented.
packages/runtime/client/rest/test/endpoints/contracts.spec.e2e.ts (1)
  • 13-14: The refactoring to use readTestConfiguration and mkRestClient in contracts.spec.e2e.ts is correctly implemented.
packages/testing-kit/src/environment/index.ts (1)
  • 78-95: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-93]

The updates in index.ts to align with the new testing and configuration approach, including the use of mkRuntimeLifecycle and mkRestClient, are correctly implemented.

packages/runtime/lifecycle/test/generic/contracts.e2e.spec.ts (1)
  • 27-30: The refactoring to use readTestConfiguration and mkLifecycle in contracts.e2e.spec.ts is correctly implemented.
packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (1)
  • 36-37: The refactoring to use readTestConfiguration and mkLifecycle in swap.ada.token.e2e.spec.ts is correctly implemented.
doc/howToDevelop.md (1)
  • 62-76: The documentation in howToDevelop.md has been updated to reflect the new JSON file format for environment configuration, which is correctly detailed.
packages/runtime/lifecycle/src/generic/contracts.ts (1)
  • 104-156: The updates in contracts.ts, including the addition of CreateContractRequestBase, BuildCreateContractTxRequestOptions, and the expanded createContract function, are correctly implemented.
packages/runtime/lifecycle/src/api.ts (1)
  • 82-174: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [24-235]

The updates in api.ts, including the addition of ContractBundle, new interfaces CreateContractRequestFromContract and CreateContractRequestFromBundle, and the union type CreateContractRequest, are correctly implemented.

examples/nodejs/src/marlowe-object-flow.ts (1)
  • 570-573: The createContract function has been updated to include a minimumLovelaceUTxODeposit parameter when calling lifecycle.contracts.createContract. This is likely related to the PR's objective to support contract bundles. Ensure that the value of 3_000_000 lovelaces is appropriate and consistent with the rest of the application's logic and requirements.
Verification successful

The search results confirm that the minimumLovelaceUTxODeposit parameter is consistently used across the application with the value 3_000_000. This consistency is found in test specifications, example code, and within the contract creation logic. There are no indications of inconsistencies or deviations from this value.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the minimumLovelaceUTxODeposit is consistent across the application
rg 'minimumLovelaceUTxODeposit' --type ts

Length of output: 1572

| CreateContractRequestFromBundle;

export interface CreateContractRequestFromContract
extends CreateContractRequestBase {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure, this pattern is better than a ContractOrSourceId parameter, I'd prefer also Composition over Inheritance ... and the doc is probably less readable that way... but ok, we can always change it later when we'll add more functionalities...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

take a look at the generated docs, starting from the function. I think it ended up being readable.

IMO, Composition vs Inheritance does not apply to this. I'm not doing class inheritance

*/
export type TestConfiguration = {
bank: { seedPhrase: SeedPhrase };
lucid: { blockfrost: Blockfrost; node: { network: Lucid.Network } };
Copy link
Collaborator

@nhenin nhenin Jan 15, 2024

Choose a reason for hiding this comment

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

You've re-designed this TestConfiguration type without really using it and discuss with me before... It will impact my current work... Do we proceed anyway or I'll handle the changes myself ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a first attempt to settup debugging in the tests and I managed to do that. I've barely modified the "testing infrastructure". Do any change you want on top, make sure it is debuggable still ;). I have made sure that the e2e tests pass before and after my changes

const status = await runtimeClient.healthcheck();
const runtimeNodeNetwork = getNetwork(status.networkId);

if (!G.CompatibleRuntimeVersion.is(status.version)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where do you provide information on this ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the e2e test I don't

blockfrostProjectId: t.string,
blockfrostUrl: t.string,
}),
network: lucidNetworkGuard,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't want necessary to have a lucid terminology exposed in our config file for the network... and this wasn't done yet , but we should check if the networks are compatible as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is a union type of the words "Preprod", "Preview" and "Mainnet". I don't think it applies to "lucid terminology". And in any case it is used to setup a lucid wallet.

@hrajchert hrajchert marked this pull request as ready for review January 15, 2024 12:10
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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2193f6e and 34ed0f0.
Files selected for processing (1)
  • changelog.d/20240112_130130_hrajchert_plt_9089_createContract_bundle_support.md (1 hunks)
Additional comments: 1
changelog.d/20240112_130130_hrajchert_plt_9089_createContract_bundle_support.md (1)
  • 2-5: The changelog entry is clear and includes a reference to the PR, which is good practice for traceability.

@hrajchert hrajchert force-pushed the hrajchert/plt-9089-createContract-bundle-support branch from 34ed0f0 to f870768 Compare January 15, 2024 17:26
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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between bf47bb0 and f870768.
Files ignored due to path filters (1)
  • tsconfig.test.json is excluded by: !**/*.json
Files selected for processing (12)
  • .vscode/settings.json (1 hunks)
  • changelog.d/20240112_130130_hrajchert_plt_9089_createContract_bundle_support.md (1 hunks)
  • doc/howToDevelop.md (1 hunks)
  • examples/nodejs/src/marlowe-object-flow.ts (1 hunks)
  • packages/runtime/client/rest/test/endpoints/contracts.spec.e2e.ts (5 hunks)
  • packages/runtime/client/rest/test/endpoints/payouts.spec.e2e.ts (4 hunks)
  • packages/runtime/lifecycle/src/api.ts (4 hunks)
  • packages/runtime/lifecycle/src/generic/contracts.ts (5 hunks)
  • packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (9 hunks)
  • packages/runtime/lifecycle/test/generic/contracts.e2e.spec.ts (3 hunks)
  • packages/testing-kit/src/environment/configuration.ts (1 hunks)
  • packages/testing-kit/src/environment/index.ts (4 hunks)
Files skipped from review as they are similar to previous changes (10)
  • .vscode/settings.json
  • changelog.d/20240112_130130_hrajchert_plt_9089_createContract_bundle_support.md
  • doc/howToDevelop.md
  • packages/runtime/client/rest/test/endpoints/contracts.spec.e2e.ts
  • packages/runtime/client/rest/test/endpoints/payouts.spec.e2e.ts
  • packages/runtime/lifecycle/src/api.ts
  • packages/runtime/lifecycle/src/generic/contracts.ts
  • packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts
  • packages/runtime/lifecycle/test/generic/contracts.e2e.spec.ts
  • packages/testing-kit/src/environment/index.ts
Additional comments: 5
packages/testing-kit/src/environment/configuration.ts (4)
  • 5-10: The lucidNetworkGuard union type is correctly defined to include literals for network types.
  • 12-20: The testConfigurationGuard io-ts type is well-defined and matches the expected structure for test configurations.
  • 24-41: The findRootDir function is correctly implemented to recursively find the root directory by checking for the existence of tsconfig-base.json.
  • 44-44: It's important to ensure that the rootDir constant is correctly set in all environments where the tests might run.
Verification successful

The corrected script has successfully located the tsconfig-base.json file within the directory structure of the repository. This confirms that the file exists and suggests that the findRootDir function, which likely relies on the presence of this file to determine the project's root directory, should operate correctly in this environment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that tsconfig-base.json exists in the expected directory structure.
fd --type f --name "tsconfig-base.json"

Length of output: 290



Script:

#!/bin/bash
# Correcting the command to verify that tsconfig-base.json exists in the expected directory structure.
fd --type f "tsconfig-base.json"

Length of output: 51

examples/nodejs/src/marlowe-object-flow.ts (1)
  • 570-573: The refactoring of the createContract function to use lifecycle.contracts.createContract is correctly implemented and simplifies the contract creation process.

Comment on lines +49 to +61
export async function readTestConfiguration(
filepath?: string
): Promise<TestConfiguration> {
if (!filepath) {
filepath = `${rootDir}/env/.test-env.json`;
}
const configStr = await readFile(filepath, { encoding: "utf-8" });
const result = testConfigurationGuard.decode(JSON.parse(configStr));
if (result._tag === "Left") {
throw new Error("Invalid configuration");
}
};
return result.right;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The testConfigurationGuard is implemented using io-ts, which is capable of providing detailed error messages. However, the current error handling in the readTestConfiguration function throws a generic error without these details. To improve debugging, the error message should include the specific validation failures from io-ts.

Analysis chain

The readTestConfiguration function correctly decodes the configuration file using io-ts. However, it's important to verify that the error message for an invalid configuration is informative enough for debugging purposes.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the error message for an invalid configuration is clear and actionable.
# This would involve checking the error handling behavior when an invalid configuration is provided.
# Since this is a hypothetical verification, no actual script is provided.

Length of output: 0



Script:

#!/bin/bash
# Let's find out where the `testConfigurationGuard` is defined and how it's implemented.
# This will help us understand what kind of error messages it produces when decoding fails.

# First, we search for the definition of `testConfigurationGuard`.
rg "const testConfigurationGuard"

Length of output: 136


Script:

#!/bin/bash
# Additionally, we should check if there are any custom error handling or reporting mechanisms
# that are used in conjunction with `testConfigurationGuard.decode`.

# Search for any custom error handling related to `testConfigurationGuard.decode`.
rg "testConfigurationGuard.decode" -A 10

Length of output: 542



Script:

#!/bin/bash
# Now we need to inspect the implementation of `testConfigurationGuard` to see if it provides
# detailed error messages that would be included when the decoding fails.

# Since we know the file where `testConfigurationGuard` is defined, let's look at its implementation.
cat packages/testing-kit/src/environment/configuration.ts | grep -A 20 "const testConfigurationGuard"

Length of output: 746

@hrajchert hrajchert merged commit b6e72d7 into main Jan 18, 2024
2 checks passed
@hrajchert hrajchert deleted the hrajchert/plt-9089-createContract-bundle-support branch January 18, 2024 20:39
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