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

Integration Tests Atomic Swap Nominal Use Case (PLT-9263, part of PLT-9226) #171

Merged
merged 1 commit into from
Jan 15, 2024

Conversation

nhenin
Copy link
Collaborator

@nhenin nhenin commented Jan 15, 2024

This PR is part of #147, it covers only the integration tests and not the unit ones.

It fixes also #168

Summary by CodeRabbit

  • New Features

    • Enhanced swap contract states with distinct active and closed states.
    • Improved the clarity of role token minting configurations in user documentation.
    • Added payout ID and additional utility functions to end-to-end swap tests.
  • Bug Fixes

    • Enabled a previously skipped test case for creating Marlowe Contracts.
  • Documentation

    • Updated comments to clarify the behavior of the Withdraw method in the Payouts API.
  • Refactor

    • Streamlined swap contract functions to utilize a new transaction input class.
  • Style

    • Adjusted logging output format for better readability in the testing kit.

@nhenin nhenin self-assigned this Jan 15, 2024
Copy link
Contributor

coderabbitai bot commented Jan 15, 2024

Walkthrough

The recent updates involve tweaks to transaction handling, with a focus on the use of SingleInputTx over Input, and refinements in error class names to reflect active and closed swap contract states. The useMintedRoles function's commentary has been clarified, and the PayoutsAPI interface now specifies non-blocking withdrawal behavior. Testing enhancements include the activation of a previously skipped test and adjustments for better output during wallet synchronization. Additionally, new utility functions and logging have been introduced to the swap test suite.

Changes

File Path Change Summary
.../examples/src/atomicSwap.ts Updated to use SingleInputTx, renamed error classes, and commented out an unused type.
.../client/rest/src/contract/rolesConfigurations.ts Updated a comment for role token minting function.
.../lifecycle/src/api.ts Added a comment about non-blocking behavior for Withdraw method.
.../lifecycle/test/examples/swap.ada.token.e2e.spec.ts Enhanced with new imports, logging, and utility functions.
.../lifecycle/test/generic/contracts.e2e.spec.ts Enabled a previously skipped test case.
.../testing-kit/src/wallet/lucid/index.ts Improved output during runtime syncing and increased sleep duration for better stability.

Poem

In the code's burrow, deep and snug, 🐇💻
A rabbit tweaks with care and hug,
Swaps refined, tests awake,
Synced and minted, no mistake.

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 ba9764e.
Files selected for processing (6)
  • packages/language/examples/src/atomicSwap.ts (12 hunks)
  • packages/runtime/client/rest/src/contract/rolesConfigurations.ts (1 hunks)
  • packages/runtime/lifecycle/src/api.ts (1 hunks)
  • packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (5 hunks)
  • packages/runtime/lifecycle/test/generic/contracts.e2e.spec.ts (1 hunks)
  • packages/testing-kit/src/wallet/lucid/index.ts (2 hunks)
Additional comments: 16
packages/runtime/lifecycle/test/generic/contracts.e2e.spec.ts (1)
  • 22-22: The removal of .skip enables the test case "can create a Marlowe Contract" to be executed, which is a positive change assuming the test is ready to be included in the test suite.
packages/testing-kit/src/wallet/lucid/index.ts (2)
  • 66-67: Adding a newline before returning from the waitRuntimeSyncingTillCurrentWalletTip function improves readability of the output, and increasing the sleep duration from 5 to 15 seconds may help with synchronization issues in tests.
  • 83-83: Using process.stdout.write instead of logWarning for output in the isRuntimeChainMoreAdvancedThan function is a minor change that does not affect functionality but may improve the output formatting.
packages/runtime/client/rest/src/contract/rolesConfigurations.ts (1)
  • 212-212: The comment update in the useMintedRoles function clarifies the minting process for Role Tokens, making it more general and potentially more accurate.
packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (6)
  • 13-13: The addition of payoutId to the imported entities is necessary for the test to use this identifier in payout-related operations.
  • 26-26: The addition of logError to the imported entities allows for better error logging within the test suite.
  • 30-39: Importing additional entities such as onlyByContractIds, RuntimeLifecycle, Action, Closed, Scheme, and mintRole is necessary for the expanded test coverage and utility functions at the end of the file.
  • 75-75: Modifying the seller address assignment within the scheme object to use await seller.wallet.getChangeAddress() ensures that the correct address is used in the test.
  • 96-106: The additional logging and contract manipulation operations within the describe("swap") block provide more detailed output and control over the contract lifecycle in the test.
  • 217-264: The addition of several utility functions at the end of the file, such as getClosedState, getAvailableActions, shouldBeAClosedContract, and getMarloweStatefromAnActiveContract, enhances the test suite's capabilities to interact with and verify the contract's state.
packages/runtime/lifecycle/src/api.ts (1)
  • 285-285: The added comment clarifies the expected behavior of the Withdraw method in the PayoutsAPI interface, which is to not wait for confirmation behind the scenes and to return a TxId.
packages/language/examples/src/atomicSwap.ts (5)
  • 72-72: The addition of the SingleInputTx import is necessary for the updated functions that now use this type instead of Input.
  • 158-168: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [152-165]

Commenting out the RetrieveMinimumLovelaceAdded type indicates that this action is no longer part of the atomic swap contract lifecycle, which could be due to a change in the contract's requirements or behavior.

  • 211-226: Renaming the error handling classes to UnexpectedActiveSwapContractState and UnexpectedClosedSwapContractState provides clearer semantics on the type of error state encountered in the swap contract.
  • 259-263: Commenting out the RetrieveMinimumLovelaceAdded action within the getAvailableActions function aligns with the earlier comment-out of the type, maintaining consistency in the contract's logic.
  • 345-355: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [302-362]

The modifications to the getState, getClosedState, and getActiveState functions to use SingleInputTx instead of Input are consistent with the import change and are necessary for the functions to operate correctly with the updated contract structure.

@nhenin nhenin force-pushed the atomicSwap/nomial-case branch 2 times, most recently from d3dd96c to 8a3b78f Compare January 15, 2024 15:25
@nhenin nhenin marked this pull request as ready for review January 15, 2024 15:27
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 8a3b78f.
Files selected for processing (6)
  • packages/language/examples/src/atomicSwap.ts (12 hunks)
  • packages/runtime/client/rest/src/contract/rolesConfigurations.ts (1 hunks)
  • packages/runtime/lifecycle/src/api.ts (1 hunks)
  • packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (5 hunks)
  • packages/runtime/lifecycle/test/generic/contracts.e2e.spec.ts (1 hunks)
  • packages/testing-kit/src/wallet/lucid/index.ts (2 hunks)
Files skipped from review as they are similar to previous changes (6)
  • packages/language/examples/src/atomicSwap.ts
  • packages/runtime/client/rest/src/contract/rolesConfigurations.ts
  • packages/runtime/lifecycle/src/api.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/wallet/lucid/index.ts

@nhenin nhenin force-pushed the atomicSwap/nomial-case branch from 8a3b78f to 9a5dc22 Compare January 15, 2024 15:35
@nhenin nhenin changed the title Integration Tests Atomic Swap Nominal Use Case (part of PLT-9226) Integration Tests Atomic Swap Nominal Use Case (PLT-9263, part of PLT-9226) Jan 15, 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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between db2f342 and 9a5dc22.
Files selected for processing (6)
  • packages/language/examples/src/atomicSwap.ts (12 hunks)
  • packages/runtime/client/rest/src/contract/rolesConfigurations.ts (1 hunks)
  • packages/runtime/lifecycle/src/api.ts (1 hunks)
  • packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (5 hunks)
  • packages/runtime/lifecycle/test/generic/contracts.e2e.spec.ts (1 hunks)
  • packages/testing-kit/src/wallet/lucid/index.ts (2 hunks)
Files skipped from review as they are similar to previous changes (5)
  • packages/language/examples/src/atomicSwap.ts
  • packages/runtime/client/rest/src/contract/rolesConfigurations.ts
  • packages/runtime/lifecycle/src/api.ts
  • packages/runtime/lifecycle/test/generic/contracts.e2e.spec.ts
  • packages/testing-kit/src/wallet/lucid/index.ts
Additional comments: 7
packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (7)
  • 13-13: The addition of payoutId to the imported entities is noted and appears to be in line with the PR objectives to enhance testing for atomic swaps.
  • 26-26: The addition of logError function to the imported entities is approved as it likely aids in better error logging during the integration tests.
  • 30-35: The addition of new imports such as onlyByContractIds, RuntimeLifecycle, Action, Closed, Scheme, and mintRole is approved, assuming these are necessary for the expanded testing functionality.
  • 71-71: The modification of the seller address assignment within the scheme object to dynamically retrieve the address is approved, as it likely ensures that the correct address is used during tests.
  • 92-101: The addition of logging and contract manipulation operations within the describe("swap") block is approved, assuming these are part of the new integration tests for atomic swaps.
  • 110-206: The extensive changes within the describe("swap") block, including additional logging, contract manipulation operations, and error handling, are approved. These changes seem to align with the PR's objective to enhance the testing framework.
  • 214-261: The addition of several utility functions at the end of the file, such as getClosedState, getAvailableActions, and shouldBeAClosedContract, is approved. These functions likely contribute to the robustness of the integration tests by providing necessary operations for atomic swap testing.

@@ -63,7 +63,8 @@ const waitRuntimeSyncingTillCurrentWalletTip =
await waitForPredicatePromise(
isRuntimeChainMoreAdvancedThan(client, currentLucidSlot)
);
return sleep(5);
process.stdout.write("\n");
return sleep(15);
Copy link
Collaborator

Choose a reason for hiding this comment

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

👁️ ...
what is this sleep 5 turned into 15?
Why are we sleeping on a random number? Could you add a comment to it?

@hrajchert hrajchert merged commit f8121c5 into main Jan 15, 2024
2 checks passed
@hrajchert hrajchert deleted the atomicSwap/nomial-case branch January 15, 2024 16:48
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