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-8753 | Atomic Swap Contract in @marlowe.io/language-examples #131

Merged
merged 3 commits into from
Dec 19, 2023

Conversation

nhenin
Copy link
Collaborator

@nhenin nhenin commented Dec 15, 2023

Summary by CodeRabbit

  • New Features

    • Enhanced search functionality with an updated interface.
    • Added new atomic swap contract capabilities, including retract command and open role features.
    • Introduced Survey and AtomicSwap modules with improved functionality and user experience.
  • Documentation

    • Updated file-level documentation comments across several modules.
    • Added package documentation annotations for improved clarity.
  • Refactor

    • Reorganized export statements for better module structure and readability.
    • Updated function calls to align with the new module imports.
  • Tests

    • Modified end-to-end test cases to accommodate new contract creation methods and object structures.
  • Bug Fixes

    • Fixed issues related to the survey module's type accessibility across different modules.

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

coderabbitai bot commented Dec 15, 2023

Walkthrough

The codebase has undergone a refactor, notably transitioning from direct function imports to accessing functions via imported objects. This encapsulation suggests a move towards a more modular and object-oriented approach. Additionally, there's an expansion of functionality and types in the atomic swap feature, enhancing its capabilities and contract logic. The changes streamline imports and exports, suggesting a tidier and more organized code structure.

Changes

File Path Change Summary
.../participant/contract.js
.../src/index.ts
.../src/survey.ts
.../src/vesting.ts
Updated imports and exports, reorganizing and streamlining code structure.
.../src/atomicSwap.ts Added type declarations and functions for atomic swap contract logic.
.../src/contract-one-notify.ts Minor update to function signature and documentation comment.
changelog.d/.../nicolas.henin.md Enhanced swap contract functionality documented.
.../swap.ada.token.e2e.spec.ts
.../payouts.e2e.spec.ts
Refactored contract creation and testing logic, updated imports.

🐇✨
In the land of code where the rabbits hop,
Refactoring's done, and the errors drop.
Modules align with a magical swap,
Neat and tidy, to the top we hop! 🚀🌟

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

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

@nhenin nhenin added this to the Open Roles Support milestone Dec 15, 2023
@nhenin nhenin linked an issue Dec 15, 2023 that may be closed by this pull request
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 b3378c5 and dea416f.
Files ignored due to filter (1)
  • packages/language/examples/typedoc.json
Files selected for processing (4)
  • packages/language/examples/src/atomicSwap.ts (1 hunks)
  • packages/language/examples/src/contract-one-notify.ts (1 hunks)
  • packages/language/examples/src/index.ts (1 hunks)
  • packages/language/examples/src/vesting.ts (1 hunks)
Files skipped from review due to trivial changes (2)
  • packages/language/examples/src/contract-one-notify.ts
  • packages/language/examples/src/vesting.ts
Files skipped from review as they are similar to previous changes (2)
  • packages/language/examples/src/atomicSwap.ts
  • packages/language/examples/src/index.ts

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 b3378c5 and 36f5e64.
Files ignored due to filter (1)
  • packages/language/examples/typedoc.json
Files selected for processing (7)
  • examples/survey-workshop/participant/contract.js (3 hunks)
  • packages/language/examples/src/atomicSwap.ts (1 hunks)
  • packages/language/examples/src/contract-one-notify.ts (1 hunks)
  • packages/language/examples/src/index.ts (1 hunks)
  • packages/language/examples/src/vesting.ts (1 hunks)
  • packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (3 hunks)
  • packages/runtime/lifecycle/test/generic/payouts.e2e.spec.ts (3 hunks)
Files skipped from review due to trivial changes (2)
  • packages/language/examples/src/contract-one-notify.ts
  • packages/language/examples/src/vesting.ts
Files skipped from review as they are similar to previous changes (1)
  • packages/language/examples/src/index.ts
Additional comments: 11
examples/survey-workshop/participant/contract.js (4)
  • 1-1: The import statement has been correctly updated to import Survey from @marlowe.io/language-examples. This aligns with the PR objectives and the AI-generated summary.

  • 48-48: The mkWorkshopSurvey function has been correctly updated to use Survey.survey following the changes in the import statement.

  • 58-58: Verify that the verifySurvey function exists on the Survey object and is correctly referenced here.

  • 57-57: Ensure that the updated call to Survey.verifySurvey within verifySurveyContract maintains the same behavior as the previous direct call to verifySurvey.

packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (4)
  • 18-19: The import of Swap from @marlowe.io/language-examples is correctly used to create a new atomic swap contract with Swap.mkAtomicSwap(scheme). Ensure that the removal of the Examples import does not leave any orphaned references or unused code.
Verification successful

The executed script was intended to search for any remaining references to Examples in the swap.ada.token.e2e.spec.ts file after the import statement for Examples was removed. The absence of output from the rg command indicates that there are no occurrences of Examples in the file, suggesting that the removal of the Examples import did not leave any orphaned references in this specific file.

However, the scope of the search was limited to the swap.ada.token.e2e.spec.ts file. To ensure that the removal of the Examples import does not affect other parts of the codebase, a broader search across the entire codebase would be necessary.

Let's perform a broader search to verify that the removal of Examples does not leave any orphaned references in other files within the codebase.


The search across the entire codebase for references to Examples has produced output indicating that the term Examples appears in various files, but these occurrences are within documentation files (Readme.md and packages/wallet/Readme.md) and an HTML file (examples/vesting-flow/index.html). There are no indications from the search results that the term Examples is used in a way that would suggest orphaned code references due to the removal of the Examples import from the swap.ada.token.e2e.spec.ts file.

Based on this information, it can be concluded that the removal of the Examples import from the swap.ada.token.e2e.spec.ts file has not left any orphaned references to Examples in the codebase that would require attention.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining references to `Examples` that might be orphaned.
rg 'Examples' -- 'packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts'

Length of output: 84



Script:

#!/bin/bash
# Search for any remaining references to `Examples` across the entire codebase.
rg 'Examples'

Length of output: 170

* 43-58: The reorganization of the `scheme` object appears consistent and well-structured. The new properties and their usage in `Swap.mkAtomicSwap(scheme)` align with the expected format for creating an atomic swap contract.
  • 66-69: The update to the roles object to use scheme.participants.buyer.role_token is consistent with the new scheme structure. This change appears to be correctly implemented.

  • 74-74: The update to the waitConfirmation method call to use txCreatedContract is correct and reflects the variable renaming accurately.

packages/runtime/lifecycle/test/generic/payouts.e2e.spec.ts (3)
  • 4-6: The changes in import statements align with the PR's objectives to demonstrate the atomic swap functionality.

  • 38-56: The restructuring of the scheme object and the updated swapContract creation process are consistent with the new atomic swap contract example.

  • 62-62: The update to the roles object in the createContract method correctly reflects the new scheme structure.

@nhenin nhenin changed the title Atomic Swap Example PLT-7831 | Atomic Swap Contract in @marlowe.io/language-examples Dec 15, 2023
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 36f5e64 and 612ff87.
Files selected for processing (1)
  • changelog.d/20231215_173732_nicolas.henin.md (1 hunks)
Additional comments: 1
changelog.d/20231215_173732_nicolas.henin.md (1)
  • 1-3: The changelog entry succinctly describes the enhancements made to the swap contract. It would be beneficial to ensure that all significant changes, especially those related to public or exported entities, are reflected in the changelog for clarity and completeness.

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 21ad5f2 and dadbf25.
Files ignored due to filter (1)
  • packages/language/examples/typedoc.json
Files selected for processing (9)
  • changelog.d/20231215_173732_nicolas.henin.md (1 hunks)
  • examples/survey-workshop/participant/contract.js (3 hunks)
  • packages/language/examples/src/atomicSwap.ts (1 hunks)
  • packages/language/examples/src/contract-one-notify.ts (1 hunks)
  • packages/language/examples/src/index.ts (1 hunks)
  • packages/language/examples/src/survey.ts (2 hunks)
  • packages/language/examples/src/vesting.ts (4 hunks)
  • packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (3 hunks)
  • packages/runtime/lifecycle/test/generic/payouts.e2e.spec.ts (3 hunks)
Files skipped from review due to trivial changes (3)
  • changelog.d/20231215_173732_nicolas.henin.md
  • packages/language/examples/src/contract-one-notify.ts
  • packages/language/examples/src/vesting.ts
Files skipped from review as they are similar to previous changes (3)
  • examples/survey-workshop/participant/contract.js
  • packages/language/examples/src/index.ts
  • packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts
Additional comments: 11
packages/language/examples/src/atomicSwap.ts (6)
  • 1-60: The documentation provided at the beginning of the file is comprehensive and gives a clear overview of the module's purpose and usage. This is good practice for maintainability and clarity for future developers.

  • 63-78: All imports should be used in the file. If any of the imported entities are not used, they should be removed to keep the code clean.

Verification successful

The executed script has verified that all imported entities from the @marlowe.io/language-core-v1 package are indeed used in the atomicSwap.ts file. The script iterated through each imported entity and checked for its presence in the file. Since the output indicates that all entities are used, there are no unused imports to be removed.

Based on this information, the review comment has been addressed, and the imports in atomicSwap.ts are correctly utilized.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that all imported entities are used within the file.
rg --type ts --files-with-matches 'import {.*} from "@marlowe.io/language-core-v1";' | xargs rg --type ts --files-without-match 'Contract|close|TokenValue|Timeout|Party|PayeeParty|Input|MarloweState|IChoice|IDeposit|INotify|Address|datetoTimeout|Role'

Length of output: 2662



Script:

#!/bin/bash
# Verify that all imported entities are used within the atomicSwap.ts file.
unused_imports=()
for entity in Contract close TokenValue Timeout Party PayeeParty Input MarloweState IChoice IDeposit INotify Address datetoTimeout Role; do
  if ! rg --type ts --quiet "$entity" "packages/language/examples/src/atomicSwap.ts"; then
    unused_imports+=("$entity")
  fi
done

if [ ${#unused_imports[@]} -eq 0 ]; then
  echo "All imported entities are used in atomicSwap.ts."
else
  echo "Unused imports in atomicSwap.ts: ${unused_imports[*]}"
fi

Length of output: 3150

* 106-206: The type declarations for `State`, `Action`, and `CloseReason` are comprehensive and seem to cover all necessary scenarios for the atomic swap contract. Ensure that all possible states and actions have been accounted for to prevent any unexpected behavior.
  • 220-375: The getState function's logic appears to correctly interpret the contract's rules based on the input history. However, ensure that the conditions for state transitions are thoroughly tested, especially since this function is central to the contract's operation.

  • 376-444: The mkContract function constructs the contract based on the provided scheme. Ensure that the contract is constructed correctly and that all possible paths are handled, including any error conditions that might not be immediately apparent.

  • 287-318: The handling of timeouts and tokens within the contract logic is critical. Ensure that the logic is secure and robust against potential attacks, such as reentrancy or timing attacks, which are common concerns in smart contract development.

packages/language/examples/src/survey.ts (2)
  • 10-13: The change to export SurveyOptions type is correct and aligns with the PR objectives and AI-generated summary.

  • 19-22: The change to export Question type is correct and aligns with the PR objectives and AI-generated summary.

packages/runtime/lifecycle/test/generic/payouts.e2e.spec.ts (3)
  • 4-6: The import changes are consistent with the PR's focus on atomic swaps and the removal of unused imports is a good practice for code cleanliness.

  • 38-56: The changes to the scheme object and the creation of swapContract using Swap.mkAtomicSwap(scheme) are consistent with the new atomic swap functionality being introduced.

  • 62-62: The update to the roles object in the createContract method to use scheme.participants.buyer.role_token aligns with the new scheme object structure and atomic swap logic.

Copy link
Collaborator

@hrajchert hrajchert left a comment

Choose a reason for hiding this comment

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

I've only did a shallow code review, didn't test if it works correctly or not. In future PR's please provide how to test/what to check for

changelog.d/20231215_173732_nicolas.henin.md Outdated Show resolved Hide resolved
packages/language/examples/src/index.ts Outdated Show resolved Hide resolved
packages/language/examples/src/atomicSwap.ts Outdated Show resolved Hide resolved
packages/language/examples/src/atomicSwap.ts Outdated Show resolved Hide resolved
packages/language/examples/src/atomicSwap.ts Outdated Show resolved Hide resolved
packages/language/examples/src/atomicSwap.ts Outdated Show resolved Hide resolved
packages/language/examples/src/atomicSwap.ts Outdated Show resolved Hide resolved
packages/language/examples/src/atomicSwap.ts Outdated Show resolved Hide resolved
packages/language/examples/src/atomicSwap.ts Outdated Show resolved Hide resolved
packages/language/examples/src/atomicSwap.ts Show resolved Hide resolved
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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between dadbf25 and d6cba83.
Files selected for processing (6)
  • changelog.d/20231215_173732_nicolas.henin.md (1 hunks)
  • packages/language/examples/src/atomicSwap.ts (1 hunks)
  • packages/language/examples/src/index.ts (1 hunks)
  • packages/language/examples/src/vesting.ts (5 hunks)
  • packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (3 hunks)
  • packages/runtime/lifecycle/test/generic/payouts.e2e.spec.ts (3 hunks)
Additional comments: 16
changelog.d/20231215_173732_nicolas.henin.md (1)
  • 1-3: The changelog entry provides a clear description of the new swap contract version and its relevance to the Order Book Swap Prototype. It's good to see that the changelog includes a link to the PR for traceability.
packages/language/examples/src/atomicSwap.ts (9)
  • 1-54: The module description is comprehensive and includes a clear explanation of the contract's functionality, participants, and stages. The example usage is also well-documented, which is beneficial for developers looking to implement or interact with the contract.

  • 57-70: The imports are correctly structured, and it's good to see that only the necessary components are imported, which can help with tree shaking and keeping the bundle size small if used in a frontend application.

  • 80-96: The Scheme type is well-defined and includes comments explaining the purpose of the swapConfirmation phase, which is a good practice for complex types like this one.

  • 98-104: The State type union is clearly defined, with each state representing a distinct phase of the contract. This is a good use of TypeScript's union types to represent a finite state machine.

  • 142-156: The Action type union is well-defined, with each action representing a possible interaction with the contract. The comments provide additional context, which is helpful.

  • 192-198: The CloseReason type union is clearly defined, with each type representing a reason for the contract's closure. This explicitness is good for understanding the contract's possible end states.

  • 210-219: The UnexpectedSwapContractState class is well-defined and extends the native Error class, which is a common pattern for custom error handling in TypeScript.

  • 221-279: The getAvailableActions function is well-structured and uses a switch statement to handle different contract states. This is a clean approach to determining the available actions based on the current state.

  • 364-429: The mkContract function and its helper functions (mkOffer, mkAsk, mkSwapConfirmation) are well-structured and provide a clear way to construct the contract. The use of closures to encapsulate the creation logic for each stage of the contract is a good practice.

packages/language/examples/src/index.ts (1)
  • 1-16: The updated documentation block provides a clear overview of the contract examples contained within the package. The restructuring of exports to directly export Vesting, AtomicSwap, and Survey from their respective modules is a good practice as it simplifies the import paths for these modules.
packages/language/examples/src/vesting.ts (3)
  • 1-7: The module description is clear and concise, explaining the functionality of the vesting contract. It's good to see that the description includes a list of steps that outline the contract's behavior.

  • 20-32: The addition of the "Limitations" section is a good practice as it sets expectations for the contract's deployment capabilities. It's important for users to be aware of any constraints.

  • 43-47: The imports are correctly structured, and it's good to see that only the necessary components are imported. This can help with tree shaking and keeping the bundle size small if used in a frontend application.

packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (1)
  • 40-73: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [18-69]

The test case "can execute the nominal case" has been updated to use the new AtomicSwap contract. The changes reflect the updated import and usage of the AtomicSwap module. It's important to ensure that the test still passes with these changes, as they alter the setup and execution of the swap contract.

packages/runtime/lifecycle/test/generic/payouts.e2e.spec.ts (1)
  • 35-66: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [4-62]

The test case "Payouts can be withdrawn" has been updated to use the new AtomicSwap contract. The changes reflect the updated import and usage of the AtomicSwap module. It's important to ensure that the test still passes with these changes, as they alter the setup and execution of the swap contract.

packages/language/examples/src/atomicSwap.ts Outdated Show resolved Hide resolved
packages/language/examples/src/vesting.ts Show resolved Hide resolved
@nhenin nhenin merged commit 25b9d50 into main Dec 19, 2023
2 checks passed
@nhenin nhenin deleted the atomicSwap branch December 19, 2023 13:31
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: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between dadbf25 and c5795ea.
Files selected for processing (6)
  • changelog.d/20231215_173732_nicolas.henin.md (1 hunks)
  • packages/language/examples/src/atomicSwap.ts (1 hunks)
  • packages/language/examples/src/index.ts (1 hunks)
  • packages/language/examples/src/vesting.ts (5 hunks)
  • packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (3 hunks)
  • packages/runtime/lifecycle/test/generic/payouts.e2e.spec.ts (3 hunks)
Files skipped from review due to trivial changes (2)
  • changelog.d/20231215_173732_nicolas.henin.md
  • packages/language/examples/src/vesting.ts
Files skipped from review as they are similar to previous changes (1)
  • packages/language/examples/src/index.ts
Additional comments: 11
packages/language/examples/src/atomicSwap.ts (5)
  • 1-54: The documentation provided at the beginning of the atomicSwap.ts file is comprehensive and well-structured, offering a clear explanation of the module's purpose and usage. This is good for maintainability and for new developers who may use this module in the future.

  • 143-198: The Action and CloseReason type definitions are comprehensive and cover all expected actions and reasons for closing the contract. It's good practice to keep these definitions close to each other as they are related, which has been done here.

  • 210-219: The UnexpectedSwapContractState class is a good use of custom error handling, providing clear feedback when the contract state is unexpected. Including the scheme and state in the error is helpful for debugging.

  • 282-345: The getState and getClosedState functions are well-implemented, with clear logic for determining the state based on the input history. The use of a switch statement and the length of the input history to determine the state is a good approach.

  • 377-442: The mkContract function and its helper functions (mkOffer, mkAsk, mkSwapConfirmation) are well-structured and provide a clear flow for contract creation. The use of closures to encapsulate the logic for each part of the contract is a good design choice.

packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts (3)
  • 18-19: The addition of the mintRole import and usage is a significant change. It's important to ensure that the mintRole function is properly tested and that its integration into the test does not introduce any side effects or dependencies that could affect the test's reliability.
Verification successful

The initial search for unit tests covering the mintRole function did not yield any results. This could mean that there are no unit tests named with describe blocks that specifically mention mintRole. However, it's possible that the function is tested within a broader context or with a different naming convention in the test descriptions.

To ensure thorough verification, I will perform a broader search for any test files that might contain tests for the mintRole function, without relying on the describe block naming.


The search results indicate that the mintRole function is referenced in two end-to-end test specification files: swap.ada.token.e2e.spec.ts and payouts.e2e.spec.ts. This suggests that the mintRole function is likely exercised as part of the end-to-end testing process in these two test suites.

Given this information, it can be inferred that the mintRole function is indeed covered by tests, specifically within the context of end-to-end tests for the swap and payouts functionality. Therefore, the integration of the mintRole function into the swap.ada.token.e2e.spec.ts test file is supported by existing test coverage.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that mintRole function is covered by unit tests
rg --type ts "describe\(.*mintRole.*\)"

Length of output: 41



Script:

#!/bin/bash
# Search for any test files that might contain tests for the mintRole function
rg --type ts --files-with-matches "mintRole" | grep "\.spec\.ts$"

Length of output: 193

* 43-57: The definition of the `scheme` object within the test is crucial for setting up the atomic swap contract. It's important to verify that the deadlines and asset values are appropriate for the test scenarios and that they align with the expected behavior of the contract.
Verification successful

The search results indicate that the AtomicSwap.Scheme type is used in multiple files within the test suite and examples. To verify the consistency of the scheme object's deadlines and asset values, we should examine the usage of AtomicSwap.Scheme in these files.

Let's write a script to extract the relevant portions of code from the swap.ada.token.e2e.spec.ts, payouts.e2e.spec.ts, and atomicSwap.ts files where AtomicSwap.Scheme is defined. This will allow us to compare the scheme object's structure and values across different test setups.


The regex error occurred because the { character is a special character in regex, used for specifying quantities, and it needs to be escaped to be used as a literal character. Let's correct the script by escaping the { character and rerun the search to extract the relevant portions of code where AtomicSwap.Scheme is defined.


The outputs from the scripts provide the definitions of the scheme object in three different files. Let's analyze the consistency of the scheme object across these files:

  1. In swap.ada.token.e2e.spec.ts, the scheme object is defined with:

    • seller's address from adaProvider.address
    • Deadlines set to one day from the current date for both offer and ask
    • asset for offer set to adaValue(2n)
    • asset for ask set to runtimeTokenToMarloweTokenValue(tokenValueMinted)
  2. In payouts.e2e.spec.ts, the scheme object is similarly defined with:

    • seller's address from adaProvider.address
    • Deadlines set to one day from the current date for both offer and ask
    • asset for offer set to adaValue(2n)
    • asset for ask set to runtimeTokenToMarloweTokenValue(tokenValueMinted)
  3. In atomicSwap.ts, the scheme object is defined within an example in the documentation with:

    • A hardcoded seller's address
    • Deadlines set to one day from the current date for both offer and ask
    • asset for offer set to tokenValue(10n)(tokenA)
    • asset for ask set to tokenValue(10n)(tokenB)

The scheme object's structure is consistent across the test files (swap.ada.token.e2e.spec.ts and payouts.e2e.spec.ts), with the same deadlines and similar asset values, which are appropriate for the test scenarios. The example in atomicSwap.ts is for documentation purposes and uses different token values, but the structure and the approach to setting deadlines are consistent with the test files.

Based on this analysis, the scheme object within the swap.ada.token.e2e.spec.ts file is consistent with other test setups in terms of structure and the approach to defining deadlines and assets.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the scheme deadlines and asset values are consistent with other test setups
rg --type ts "scheme: AtomicSwap.Scheme"

Length of output: 336



Script:

#!/bin/bash
# Extract the relevant portions of code where `AtomicSwap.Scheme` is defined in the mentioned files
rg --type ts --context 10 "const scheme: AtomicSwap.Scheme = {" packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts
rg --type ts --context 10 "const scheme: AtomicSwap.Scheme = {" packages/runtime/lifecycle/test/generic/payouts.e2e.spec.ts
rg --type ts --context 10 "const scheme: AtomicSwap.Scheme = {" packages/language/examples/src/atomicSwap.ts

Length of output: 772



Script:

#!/bin/bash
# Correct the regex by escaping the '{' character and extract the relevant portions of code
rg --type ts --context 10 "const scheme: AtomicSwap.Scheme = \{" packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts
rg --type ts --context 10 "const scheme: AtomicSwap.Scheme = \{" packages/runtime/lifecycle/test/generic/payouts.e2e.spec.ts
rg --type ts --context 10 "const scheme: AtomicSwap.Scheme = \{" packages/language/examples/src/atomicSwap.ts

Length of output: 2721

* 59-69: The creation of the swap contract using the `AtomicSwap.mkContract` function is a key part of the test. It's important to ensure that the contract creation process is robust and that any potential errors are handled appropriately.
packages/runtime/lifecycle/test/generic/payouts.e2e.spec.ts (3)
  • 4-6: The changes in imports, specifically the addition of AtomicSwap and the removal of Next, suggest a significant refactoring. It's important to verify that these changes do not affect other parts of the test suite and that all tests still pass.

  • 38-52: The scheme object is central to the setup of the atomic swap contract in the test. It's important to verify that the scheme's structure and values are consistent with the contract's requirements and that they are used correctly throughout the test.

Verification successful

The search results indicate that the scheme: AtomicSwap.Scheme type declaration is used in multiple test files (payouts.e2e.spec.ts and swap.ada.token.e2e.spec.ts) as well as in the source file atomicSwap.ts. To verify the consistency of the scheme object's structure and values, we should examine its usage in these test files and compare it to the definition in atomicSwap.ts.

To do this, we can look for the definition of the AtomicSwap.Scheme type in atomicSwap.ts and then ensure that the scheme objects in the test files match this structure and use appropriate values.


The output from the scripts indicates that the AtomicSwap.Scheme type is exported from atomicSwap.ts and is used in both payouts.e2e.spec.ts and swap.ada.token.e2e.spec.ts. However, the output does not show the actual structure of the Scheme type or the details of how the scheme object is used in the test files.

To verify the consistency of the scheme object's structure and values, we need to see the full definition of the Scheme type from atomicSwap.ts and the actual usage in the test files. Let's retrieve the full type definition and the complete scheme object declarations from the test files.


The output provides the structure of the AtomicSwap.Scheme type from atomicSwap.ts and the declarations of the scheme object in both payouts.e2e.spec.ts and swap.ada.token.e2e.spec.ts. The Scheme type consists of two main parts: offer and ask, each containing seller or buyer information, an asset, and a deadline.

Comparing this to the scheme object declarations in the test files, we can see that the structure is consistent with the type definition. Both scheme objects in the test files have offer and ask sections with the appropriate fields: seller or buyer, asset, and deadline. The values used in the test files, such as adaProvider.address, pipe(addDays(Date.now(), 1), datetoTimeout), and runtimeTokenToMarloweTokenValue(tokenValueMinted), are specific to the test setup and are not part of the type definition, but they are appropriate for the fields they are assigned to.

Based on the provided output, the scheme object's structure and values in the test files are consistent with the AtomicSwap.Scheme type definition in atomicSwap.ts. Therefore, the usage of the scheme object in the test files appears to be correct.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify consistency of scheme object structure and values in tests
rg --type ts "scheme: AtomicSwap.Scheme"

Length of output: 336



Script:

#!/bin/bash
# Find the definition of AtomicSwap.Scheme in atomicSwap.ts
rg --type ts "export type Scheme =" "packages/language/examples/src/atomicSwap.ts"

# Check the usage of the scheme object in the test files
rg --type ts "const scheme: AtomicSwap.Scheme" "packages/runtime/lifecycle/test/generic/payouts.e2e.spec.ts"
rg --type ts "const scheme: AtomicSwap.Scheme" "packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts"

Length of output: 413



Script:

#!/bin/bash
# Retrieve the full definition of AtomicSwap.Scheme from atomicSwap.ts
rg --type ts -A 10 "export type Scheme =" "packages/language/examples/src/atomicSwap.ts"

# Retrieve the full scheme object declarations from the test files
rg --type ts -A 10 "const scheme: AtomicSwap.Scheme" "packages/runtime/lifecycle/test/generic/payouts.e2e.spec.ts"
rg --type ts -A 10 "const scheme: AtomicSwap.Scheme" "packages/runtime/lifecycle/test/examples/swap.ada.token.e2e.spec.ts"

Length of output: 1325

* 54-63: The contract creation logic has been updated to use the new `scheme` object. It's important to ensure that this logic is consistent with the updated contract implementation and that the contract creation process is tested thoroughly.

@palas palas changed the title PLT-7831 | Atomic Swap Contract in @marlowe.io/language-examples PLT-8753 | Atomic Swap Contract in @marlowe.io/language-examples Dec 22, 2023
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.

Atomic Swap Contract in @marlowe.io/language-examples
2 participants