Skip to content

Add select token network call tests#1687

Merged
hardyjosh merged 8 commits intomainfrom
2025-04-22-select-token-tests
Apr 29, 2025
Merged

Add select token network call tests#1687
hardyjosh merged 8 commits intomainfrom
2025-04-22-select-token-tests

Conversation

@findolor
Copy link
Copy Markdown
Collaborator

@findolor findolor commented Apr 22, 2025

Caution

Do not merge before #1685

Motivation

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • [ ] included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • Chores

    • Added a new workspace dependency for JavaScript API integration.
    • Updated development dependencies for improved test support in non-WebAssembly environments.
  • Refactor

    • Improved code clarity and efficiency by reducing unnecessary cloning and using more idiomatic assertions and checks.
    • Streamlined key extraction and ownership handling in several functions.
    • Adjusted method signatures and serialization logic for consistent string ownership.
  • New Features

    • Implemented a default configuration for the order GUI.
  • Tests

    • Expanded and reorganized test coverage, including integration tests for token selection and remote contract calls.
    • Enhanced test support for both WebAssembly and non-WebAssembly targets.
  • Style

    • Updated boolean assertions to use more idiomatic patterns for improved readability.

@findolor findolor added test test code rust Related to rust crates labels Apr 22, 2025
@findolor findolor added this to the Test coverage, tech debt milestone Apr 22, 2025
@findolor findolor requested a review from hardyjosh April 22, 2025 12:32
@findolor findolor self-assigned this Apr 22, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2025

## Walkthrough

This set of changes introduces and reorganizes testing for the `rain_orderbook_js_api` crate, particularly focusing on the GUI's token selection functionality. The workspace is updated to include the new crate, and its dependencies are adjusted for conditional compilation. Test assertions are refactored for idiomatic Rust style. The `DotrainOrderGui` struct receives a `Default` implementation, and several internal methods are optimized to reduce unnecessary cloning and improve code clarity. Test modules are reorganized to separate WASM and non-WASM tests, with new integration tests added that utilize HTTP mocking to simulate Ethereum RPC endpoints. The `get_dotrain_hash` method and related calls are updated to use owned `String` types instead of string slices.

## Changes

| File(s)                                                                 | Change Summary                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
|-------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Cargo.toml                                                              | Added new workspace dependency `rain_orderbook_js_api` with path `crates/js_api`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| crates/js_api/Cargo.toml                                                | Added conditional dev-dependency on `httpmock` for non-WASM targets; retains unconditional dev-dependency on `wasm-bindgen-test`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| crates/js_api/src/gui/deposits.rs<br>crates/js_api/src/gui/field_values.rs | Refactored test assertions from `assert_eq!(..., true/false)` to idiomatic `assert!(...)` and `assert!(!...)`. No logic changes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| crates/js_api/src/gui/mod.rs                                            | Added `Default` implementation for `DotrainOrderGui`. Modified `generate_dotrain_text` to use owned `String`. Removed commented TODOs. Introduced non-WASM test module with async integration test using HTTP mock server to test token info retrieval and selection logic.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| crates/js_api/src/gui/order_operations.rs                               | Simplified code by removing unnecessary cloning, improving iteration, and streamlining error handling logic. No changes to public APIs or overall logic.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| crates/js_api/src/gui/select_tokens.rs                                  | Reorganized test modules into WASM and non-WASM submodules. Expanded tests for token selection, including a new async integration test using HTTP mock server to simulate Ethereum RPC and validate token saving logic. No changes to core logic or public API.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| crates/js_api/src/gui/state_management.rs                               | Changed `get_dotrain_hash` and related calls to use owned `String` instead of `&str`. Improved string emptiness check with idiomatic Rust.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| crates/js_api/src/lib.rs                                                | Changed conditional compilation for `gui` module to include both WASM and test builds (`#[cfg(any(target_family = "wasm", test))]`). No changes to public API.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Test as Integration Test (non-WASM)
    participant MockServer as HTTP Mock Server
    participant Gui as DotrainOrderGui
    participant RPC as Simulated Ethereum RPC

    Test->>MockServer: Start mock RPC endpoint
    Test->>Gui: Load YAML configuration
    Test->>Gui: save_select_token(key, address, rpc_url)
    Gui->>RPC: Fetch token metadata (symbol, decimals)
    RPC-->>Gui: Return token metadata
    Gui-->>Test: Return result (token info set or error)
    Test->>Gui: Attempt save_select_token with missing key
    Gui-->>Test: Return TokenNotFound error
    Test->>Gui: Attempt save_select_token with deployment lacking select tokens
    Gui-->>Test: Return SelectTokensNotSet error

Possibly related PRs

Suggested reviewers

  • hardyjosh

<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: ASSERTIVE**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between ff9c8ef68d9dcb8b362915c2c16a588b30f0a0c4 and 58cffbcd1445538ab387d2172b06450dabf26423.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `crates/js_api/src/gui/order_operations.rs` (9 hunks)

</details>

<details>
<summary>🔇 Additional comments (8)</summary><blockquote>

<details>
<summary>crates/js_api/src/gui/order_operations.rs (8)</summary>

`199-199`: **Return value simplified**

The return statement has been simplified to eliminate unnecessary wrapping in `Ok()` since `get_current_deployment()` already returns a `Result`.

---

`262-262`: **Taking ownership instead of cloning**

Moving the token_address value into the struct instead of cloning it improves efficiency since the value isn't needed after this point.

---

`428-428`: **Removed unnecessary clone**

The `.clone()` call has been removed since `Option<U256>` implements `Copy` and can be copied implicitly.

---

`438-438`: **Removed unnecessary clone**

Similar to the input iteration above, the unnecessary `.clone()` call has been removed since `Option<U256>` implements `Copy`.

---

`470-490`: **Simplified pattern matching with if let**

Changed from a match expression to an if-let pattern, which is more concise when you only need to handle one variant.

---

`524-525`: **Improved test assertions**

Using `panic!` with a descriptive message instead of `assert!(false)` provides better error information for failing tests.

---

`539-540`: **Improved test assertions**

Using `panic!` with a descriptive message instead of `assert!(false)` provides better error information for failing tests.

---

`552-553`: **Improved test assertions**

Using `panic!` with a descriptive message instead of `assert!(false)` provides better error information for failing tests.

</details>

</blockquote></details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSHFcLzpIACIAQVp6RBJIsTD8AGsySHJcAHd8CnTGNB8wkMRoyFy0ZAcBZnUaejkw2A9sJL4AM3gMWnwvAvRkW2zHAUpIAEYANgAOAHY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OVTPOVQC4JDtrg+W8JLhMksm0BgzL6QDjuCdYujzEe9BcAcsUAAGoRAEOAHSgGquQGIbQGwHeSABJhKFEFyFweyh+F9PlwDS0QLF1vjYMAYl8Vyl/AGlwUHAaiYgb4Bk+xpVW0aifFfyolUETYiC7ZGC6gpCx4TFdyr4U4Z14ER2AIFC5EVlaCZLHlbLAVco+rDzZMUBJ5P8PnsGHiO+XSExnx44jiytWh76qraFFczc3PIQkvCvAoZvDUDvPc3Gj8hd1PKPNWFdwvG2rd+vPd9vNEM8iEPvMzC8CuXfv7CbP1X0LfOt8IibCilSYCPmCuB4BcI1B3F3Lsn3GQjIU3L1uktqu+dbO6ecj4GFo+69egbdYCBMMuIWPQKHMp81iyP4CJlDJECZ1ivXIQvWD92Cr1GmTs/wHwP4FeIFVVO5WgOWnOvsdyPm/LBZ6+lZ/IrZ03uEbSuL0s6Fa533t1OClE4MzrMMy3kngSz5/5Q50FcL855MyynUuNjCiQJszj/ExrM1Xa3D1t9Frt+Mbiqi1T8d0euD2kj85BoYAYOhFjqomgHgHhMMURMBKROsBRHEfILRGXlQAxEhMxKhBH++OnUGG6W5P4IyFpHQElvPKECxJH1MOKAAJzpx18kAShTAADMy8AALK3x3wsAwB33Xx310HMB33MF0FMHMHX63w+E3wsAsP323yhGhPnx3xKHXzMCoAsB1jMHX03x1hMDMOnAZFMHXwIF0DMAsK33MAfz3+nAILfw37QHMB4K+JH+WnXwwE/2f3MLQHX7QAwAIHMAECt8ZgHWOvlMAlAMAOsDAWYGgAlBzBABrfdOF0HThoBD+HfRfnnwgCQA4Bk8LoAIAYC0ApgHfFfhKEv4qBL+CwWgB1imCb87+MwFfunH6Kn8t+HfDrK3wwGYCoAZWdQEXzMKl81o4qT8PoCAA=== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=rainlanguage/rain.orderbook&utm_content=1687):

- 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 generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

Copy link
Copy Markdown
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.

Actionable comments posted: 14

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 58d4f3b and 1168909.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • Cargo.toml (1 hunks)
  • crates/common/src/erc20.rs (2 hunks)
  • crates/js_api/Cargo.toml (1 hunks)
  • crates/js_api/src/gui/deposits.rs (1 hunks)
  • crates/js_api/src/gui/field_values.rs (2 hunks)
  • crates/js_api/src/gui/mod.rs (3 hunks)
  • crates/js_api/src/gui/order_operations.rs (6 hunks)
  • crates/js_api/src/gui/select_tokens.rs (1 hunks)
  • crates/js_api/src/gui/state_management.rs (4 hunks)
  • crates/js_api/src/lib.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
crates/js_api/src/gui/field_values.rs (1)
crates/js_api/src/gui/state_management.rs (1)
  • is_preset (260-266)
crates/js_api/src/gui/mod.rs (8)
crates/settings/src/yaml/orderbook.rs (1)
  • new (31-59)
crates/settings/src/yaml/dotrain.rs (1)
  • new (26-50)
crates/js_api/src/yaml/mod.rs (2)
  • new (32-34)
  • to_readable_msg (63-70)
crates/settings/src/yaml/context.rs (2)
  • new (192-199)
  • to_readable_msg (38-49)
crates/settings/src/yaml/mod.rs (2)
  • new (26-26)
  • to_readable_msg (254-333)
crates/settings/src/yaml/cache.rs (1)
  • new (10-15)
crates/common/src/dotrain_order/mod.rs (1)
  • new (150-187)
crates/common/src/erc20.rs (4)
  • token_info (105-162)
  • decimals (51-67)
  • name (69-85)
  • symbol (87-103)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: Deploy-Preview
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: git-clean
  • GitHub Check: build-tauri (ubuntu-22.04, true)
🔇 Additional comments (14)
crates/js_api/Cargo.toml (1)

36-38: Good addition of the conditional dev-dependency for HTTP mocking.

Adding the httpmock crate only for non-WASM targets is appropriate since HTTP mocking is typically not compatible with WebAssembly environments. This allows for proper testing of network interactions in native environments while avoiding compilation issues in WASM builds.

Cargo.toml (1)

81-83: Appropriate workspace dependency addition.

Adding the rain_orderbook_js_api as a workspace dependency allows other crates within the workspace to depend on it, which is good for code reuse and integration, especially when implementing token network call tests as mentioned in the PR objectives.

crates/js_api/src/lib.rs (1)

1-1: Broadened compilation scope to include tests.

The conditional compilation has been expanded to include both WebAssembly targets and test builds. This will allow the gui module to be compiled and used during testing, even in non-WASM environments.

This is a good change that facilitates better test coverage, especially for the new integration tests that use HTTP mocking for token selection functionality.

crates/common/src/erc20.rs (2)

16-16: Import reordering.

The FromStr import was moved in the import list.


201-392: Comprehensive test coverage for ERC20 interface.

Great addition of unit tests for the ERC20 contract interface methods, using HTTP mocking to simulate RPC responses.

The tests thoroughly cover:

  • Success and error cases for decimals(), name(), symbol(), and token_info()
  • Proper ABI encoding/decoding
  • Error handling for malformed responses
  • Multicall functionality

This significantly improves reliability and maintainability of the token interface code.

crates/js_api/src/gui/order_operations.rs (5)

199-199: Simplified error handling.

Removed redundant Ok() wrapping since get_current_deployment() already returns a Result.

This improves code readability by avoiding unnecessary nesting of Result types.


262-262: Optimized memory usage by transferring ownership.

The token address is now moved instead of cloned, reducing unnecessary memory allocations.

This is a good optimization as it avoids redundant cloning of immutable data.


296-297: Simplified map iteration.

The code now uses the more idiomatic .keys().map(...) instead of extracting keys from key-value pairs.

This change makes the code more readable and directly expresses the intent to iterate over keys.


428-429: Improved iteration efficiency in get_vault_ids.

The iterators now yield references directly instead of cloning the vault IDs.

This avoids unnecessary cloning of Option<U256> values, which can be expensive.

Also applies to: 438-439


470-490: Refactored pattern matching for clarity and efficiency.

Changed from match statement to if let pattern and improved variable ownership handling to reduce cloning.

The refactoring makes the code more maintainable and slightly more efficient by:

  1. Using a clearer if let pattern for the specific case
  2. Moving token addresses instead of cloning them
  3. Following a more consistent structure for the error handling path
crates/js_api/src/gui/state_management.rs (4)

30-32: Changed parameter type from borrowed to owned String.

The get_dotrain_hash function now takes ownership of the input string rather than borrowing it.

This change is consistent with the actual usage pattern in the codebase, where the function is typically called with owned strings that don't need to be used after the hash calculation.


53-53: More idiomatic string emptiness check.

Changed from string comparison with empty string to the more idiomatic is_empty() method.

This is a minor improvement that makes the code more readable and follows Rust best practices.


149-151: Updated function call to match new signature.

Changed to pass an owned String to get_dotrain_hash instead of a string reference.

This change properly aligns with the updated function signature.


176-176: Updated function call to match new signature.

Changed to pass an owned String to get_dotrain_hash instead of a string reference.

This ensures consistency with the updated function signature.

Comment thread crates/js_api/src/gui/deposits.rs
Comment thread crates/js_api/src/gui/deposits.rs
Comment thread crates/js_api/src/gui/field_values.rs
Comment thread crates/js_api/src/gui/field_values.rs
Comment thread crates/js_api/src/gui/field_values.rs
Comment thread crates/js_api/src/gui/mod.rs
Comment thread crates/js_api/src/gui/mod.rs
Comment thread crates/js_api/src/gui/select_tokens.rs Outdated
Comment thread crates/js_api/src/gui/select_tokens.rs Outdated
Comment thread crates/js_api/src/gui/select_tokens.rs Outdated
Copy link
Copy Markdown
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.

Actionable comments posted: 1

♻️ Duplicate comments (3)
crates/js_api/src/gui/mod.rs (3)

65-69: Derive Default instead of hand‑rolling it
You can save a few lines by adding #[derive(Default)] to the struct and removing this manual impl; it already fulfils the exact same semantics (new() just delegates to the same field defaults).


258-260: Avoid the extra allocation unless Clippy still objects
Calling .to_string() forces an unnecessary heap allocation because RainDocument::create already accepts impl Into<String>. Passing the &str directly (or into()) keeps this zero‑copy.


1367-1370: 🧹 Nitpick (assertive)

Tighten the HTTP‑mock assertions
Consider making the mock fail loudly when the RPC call count changes:

-then.body(...);
+then.body(...)
+    .expect(1); // the code should hit this endpoint exactly once

This guards against silent regressions if the production code stops calling the RPC (or calls it more than once). While it’s “just a test”, catching such drift early is valuable.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1168909 and 4596ab7.

📒 Files selected for processing (1)
  • crates/js_api/src/gui/mod.rs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: Deploy-Preview
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: git-clean

Comment thread crates/js_api/src/gui/mod.rs
let token = output.token.as_ref().unwrap();
let token_info = self.get_token_info(token.key.clone()).await?;
output_token_infos.insert(token.address.clone(), token_info);
if let ApprovalCalldataResult::Calldatas(calldatas) = approval_calldata {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

were these modifications required for this PR? i can't see any tests for this file, it would be better if we are making updates that we have accompanying tests, otherwise i get nervous we're introducing a bug

Comment thread crates/js_api/src/gui/select_tokens.rs
Copy link
Copy Markdown
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.

Actionable comments posted: 4

♻️ Duplicate comments (9)
crates/js_api/src/gui/deposits.rs (2)

289-289: Great improvement to the assertion style

Using assert!(!has_any_deposit) instead of assert_eq!(has_any_deposit, false) is more idiomatic in Rust and makes the test more readable.


294-294: Great improvement to the assertion style

Using assert!(has_any_deposit) instead of assert_eq!(has_any_deposit, true) is more idiomatic in Rust and makes the test more readable.

crates/js_api/src/gui/field_values.rs (4)

198-198: Excellent improvement to boolean assertion style

Using assert!(!field_value.is_preset) instead of assert_eq!(field_value.is_preset, false) is more idiomatic in Rust and improves test readability.


203-203: Excellent improvement to boolean assertion style

Using assert!(field_value.is_preset) instead of assert_eq!(field_value.is_preset, true) is more idiomatic in Rust and improves test readability.


226-226: Excellent improvement to boolean assertion style

Using assert!(!field_values[0].is_preset) instead of assert_eq!(field_values[0].is_preset, false) follows Rust best practices for boolean assertions.


229-229: Excellent improvement to boolean assertion style

Using assert!(field_values[1].is_preset) instead of assert_eq!(field_values[1].is_preset, true) follows Rust best practices for boolean assertions.

crates/js_api/src/gui/mod.rs (1)

65-69: #[derive(Default)] would remove boiler-plate (same remark as before)

The new manual impl Default simply calls new().
A #[derive(Default)] on the struct would achieve the same thing and keeps the code a tad slimmer.

Previous iterations of this PR already discussed this, so feel free to ignore if you still prefer the explicit impl.

crates/js_api/src/gui/select_tokens.rs (2)

170-347: Same earlier feedback: thoughts on adding negative/aggregate assertions

The WASM test suite still omits a quick check for are_all_tokens_selected() after the first successful save. This would harden coverage without much code.

We already discussed this in a previous review, so treat this as a gentle reminder only.


357-524: Mirror the mock-call expectation & extract the YAML fixture

This non-WASM test repeats patterns noted earlier:

  • Add .expect(1) to the RPC mock for stronger guarantees.
  • The standalone YAML fixture duplicates the one in mod.rs. Extracting a single source (e.g. tests/fixtures/select_token.yaml) avoids future drift.

No functional issues – purely maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4596ab7 and ff9c8ef.

📒 Files selected for processing (6)
  • crates/js_api/src/gui/deposits.rs (1 hunks)
  • crates/js_api/src/gui/field_values.rs (2 hunks)
  • crates/js_api/src/gui/mod.rs (3 hunks)
  • crates/js_api/src/gui/order_operations.rs (6 hunks)
  • crates/js_api/src/gui/select_tokens.rs (1 hunks)
  • crates/js_api/src/gui/state_management.rs (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
crates/js_api/src/gui/state_management.rs (1)
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1687
File: crates/js_api/src/gui/mod.rs:258-259
Timestamp: 2025-04-22T12:50:39.581Z
Learning: In `DotrainOrderGui::generate_dotrain_text()`, the call to `.to_string()` on `self.dotrain_order.dotrain()` is necessary because there are two different implementations of the `dotrain()` method - one for WASM targets returning a String and one for non-WASM targets returning a &str. The `.to_string()` ensures type compatibility across different compilation targets.
crates/js_api/src/gui/mod.rs (1)
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1687
File: crates/js_api/src/gui/mod.rs:258-259
Timestamp: 2025-04-22T12:50:39.581Z
Learning: In `DotrainOrderGui::generate_dotrain_text()`, the call to `.to_string()` on `self.dotrain_order.dotrain()` is necessary because there are two different implementations of the `dotrain()` method - one for WASM targets returning a String and one for non-WASM targets returning a &str. The `.to_string()` ensures type compatibility across different compilation targets.
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: test
  • GitHub Check: git-clean
  • GitHub Check: test
  • GitHub Check: Deploy-Preview
🔇 Additional comments (1)
crates/js_api/src/gui/mod.rs (1)

258-259: to_string() call is the correct cross-target compromise

Because dotrain() returns String for WASM and &str for non-WASM, cloning into an owned String here is unavoidable.
Good catch in maintaining compile-time portability. Nothing to change.

Comment thread crates/js_api/src/gui/order_operations.rs
Comment thread crates/js_api/src/gui/order_operations.rs
Comment thread crates/js_api/src/gui/state_management.rs
Comment thread crates/js_api/src/gui/mod.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Related to rust crates test test code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants