Skip to content

Conversation

@kubaplas
Copy link
Contributor

@kubaplas kubaplas commented Nov 7, 2025

Closes #614

Summary by CodeRabbit

  • Style

    • Adjusted trailing whitespace in template file.
  • Tests

    • Updated test deployment reference in template.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 7, 2025

Walkthrough

Two template files were updated to fix code generation issues. The flipper template now generates deployment calls using the module name instead of the HostRef variant, resolving trait bound errors in generated tests. The CEP18 template had a trailing newline adjusted.

Changes

Cohort / File(s) Change Summary
Template Deployment Reference Fix
templates/flipper.rs.template
Updated generated test deployment call to use #module_name::deploy() instead of #module_nameHostRef::deploy(), resolving trait bound satisfaction issue for OdraContract
Template Whitespace Adjustment
templates/cep18.rs.template
Adjusted trailing newline at end-of-file

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

  • The CEP18 change is a whitespace-only edit with no functional impact
  • The flipper template change is a straightforward single-line variable reference update that directly addresses the documented issue #614

Suggested reviewers

  • zie1ony

Poem

🐰 A rabbit hops through template land,
Where deploy calls need a helping hand,
No HostRef tricks, just names that's right,
Tests compile now—what a delight!

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly refers to fixing issue #614 regarding incorrect contract template generation, which matches the main objective of the changeset.
Linked Issues check ✅ Passed The changes fix the template deployment call from HostRef::deploy to ::deploy, which directly addresses the trait bounds error in issue #614, allowing generated tests to compile.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the contract template generation issue; trailing newline adjustment and deployment reference fix are both within scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/contract-template

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e37308 and 534fce0.

📒 Files selected for processing (2)
  • templates/cep18.rs.template (1 hunks)
  • templates/flipper.rs.template (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Test
  • GitHub Check: Calculate test coverage
  • GitHub Check: Test templates
  • GitHub Check: Evaluate benchmark
  • GitHub Check: Benchmark
🔇 Additional comments (2)
templates/cep18.rs.template (1)

88-88: Trailing whitespace adjustment—no functional changes.

This is a minor formatting fix with no impact on generated code or logic.

templates/flipper.rs.template (1)

44-44: Deployment fix addresses issue #614 correctly.

Changed the deployment invocation from #module_nameHostRef::deploy() to #module_name::deploy(), which directly fixes the E0599 compilation error. The module type (generated by #[odra::module]) implements the Deployer trait, while HostRef does not. This aligns with the Deployer import at line 39 and matches the corrected pattern already present in the CEP-18 template.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

Benchmark report

Action Details Gas diff
Wasm Deploy Filename: Benchmark.wasm 🔴 +0.004470348 CSPR (0.00%)

Copy link

@llamapreview llamapreview bot left a comment

Choose a reason for hiding this comment

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

AI Code Review by LlamaPReview

🎯 TL;DR & Recommendation

Recommendation: Request Changes

This PR fixes a critical compilation error in contract tests by correcting the deploy method call, ensuring generated code compiles successfully, alongside a minor style improvement.

🌟 Strengths

  • Accurately resolves the reported issue #614 with a minimal and correct change.

⚡ Key Risks & Improvements (P1)

  • templates/flipper.rs.template: Corrects the deploy method call to prevent build failures in generated contracts.

💡 Suggestions (P2)

  • templates/cep18.rs.template: Removes trailing whitespace to improve code style consistency and reduce diff noise.
⚠️ **Unanchored Suggestions (Manual Review Recommended)**

The following suggestions could not be precisely anchored to a specific line in the diff. This can happen if the code is outside the changed lines, has been significantly refactored, or if the suggestion is a general observation. Please review them carefully in the context of the full file.


📁 File: templates/cep18.rs.template

The change removes trailing whitespace at the end of the file, improving code style consistency. While this doesn't affect functionality, maintaining consistent formatting across templates reduces noise in diffs and follows Rust style conventions.

Related Code:

mod tests {
    use super::*;
    use odra::host::{Deployer, NoArgs};

    #[test]
    fn it_works() {
        let env = odra_test::env();
        let init_args = #init_args_struct_name {
            #(#init_args_members),*
        };
        assert!(#module_name::try_deploy(&env, init_args).is_ok());
    }
}


💡 Have feedback? We'd love to hear it in our GitHub Discussions.
✨ This review was generated by LlamaPReview Advanced, which is free for all open-source projects. Learn more.

use super::*;
use odra::host::{Deployer, NoArgs};

#[test]
Copy link

Choose a reason for hiding this comment

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

P1 | Confidence: High

The change fixes a critical compilation error in generated contract tests by replacing #module_nameHostRef::deploy with #module_name::deploy. The original code attempted to call deploy on a type that doesn't implement the required OdraContract trait, causing immediate build failures in projects using the template. This directly addresses issue #614 where cargo odra test would fail with trait bound errors after generating new contracts.

@kubaplas kubaplas merged commit 5b2b8bd into release/2.4.1 Nov 7, 2025
5 checks passed
@kubaplas kubaplas deleted the bugfix/contract-template branch November 7, 2025 11:37
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.

"cargo odra generate" generates wrong test code

3 participants