-
Notifications
You must be signed in to change notification settings - Fork 4
Add missing args in factory contract ref #626
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| use odra::{casper_types::U256, prelude::*}; | ||
| use odra::{casper_types::U256, prelude::*, ContractRef}; | ||
| use odra_modules::{access::Ownable, cep18_token::Cep18}; | ||
|
|
||
| #[odra::module(factory=on)] | ||
|
|
@@ -32,17 +32,44 @@ impl FToken { | |
| } | ||
| } | ||
|
|
||
| #[odra::module] | ||
| pub struct FactoryProxy { | ||
| factory_address: Var<Address> | ||
| } | ||
|
|
||
| #[odra::module] | ||
| impl FactoryProxy { | ||
| pub fn init(&mut self, address: Address) { | ||
| self.factory_address.set(address); | ||
| } | ||
|
|
||
| pub fn deploy_new_contract(&self) -> Address { | ||
| let factory_address = self.factory_address.get().unwrap_or_revert(self); | ||
|
|
||
| let mut factory = FTokenFactoryContractRef::new(self.env(), factory_address); | ||
| let (addr, _uref) = factory.new_contract( | ||
| "TokenContract".to_string(), | ||
| "Token".to_string(), | ||
| "TTK".to_string(), | ||
| 18, | ||
| U256::from(1000u64) | ||
| ); | ||
| addr | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use alloc::string::ToString; | ||
| use odra::{ | ||
| casper_types::U256, | ||
| host::{Deployer, HostRef, NoArgs} | ||
| host::{Deployer, HostRef, NoArgs}, | ||
| prelude::Addressable | ||
| }; | ||
|
|
||
| use crate::factory::token::{ | ||
| FToken as Token, FTokenFactory as TokenFactory, FTokenHostRef, | ||
| FTokenInitArgs as TokenInitArgs | ||
| FTokenInitArgs as TokenInitArgs, FactoryProxy, FactoryProxyInitArgs | ||
| }; | ||
|
|
||
| #[test] | ||
|
|
@@ -84,4 +111,24 @@ mod tests { | |
| assert_eq!(token.symbol(), "TTK".to_string()); | ||
| assert_eq!(token.total_supply(), U256::from(500u64)); | ||
| } | ||
|
|
||
| #[test] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 | Confidence: High A new test has been added but immediately ignored with a VM-specific reason. While this documents known limitations, ignored tests can become stale and mask real issues. The test should either be fixed to work in all environments or have a clear plan for when it will be enabled. Code Suggestion: Consider adding a conditional compilation attribute or environment-specific test configuration instead of blanket ignoring. |
||
| #[ignore = "This test does not work on odra vm"] | ||
| fn test_proxy() { | ||
| let env = odra_test::env(); | ||
| let factory = TokenFactory::deploy(&env, NoArgs); | ||
| let proxy = FactoryProxy::deploy( | ||
| &env, | ||
| FactoryProxyInitArgs { | ||
| address: factory.address() | ||
| } | ||
| ); | ||
|
|
||
| let addr = proxy.deploy_new_contract(); | ||
| let token = FTokenHostRef::new(addr, env); | ||
| assert_eq!(token.get_owner(), proxy.address()); | ||
| assert_eq!(token.name(), "Token".to_string()); | ||
| assert_eq!(token.symbol(), "TTK".to_string()); | ||
| assert_eq!(token.total_supply(), U256::from(1000u64)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ impl TryFrom<&'_ ModuleImplIR> for ContractRefImplItem { | |
| let fns = vec![module.factory_fn(), module.factory_upgrade_fn(), module.factory_batch_upgrade_fn()]; | ||
| Ok(Self { | ||
| ref_ident: module.contract_ref_ident()?, | ||
| factory_fns: fns.iter().map(|fun| ref_utils::contract_function_item(fun, false)).collect() | ||
| factory_fns: fns.iter().map(|fun| ref_utils::factory_contract_function_item(fun, false)).collect() | ||
| }) | ||
|
Comment on lines
32
to
35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 | Confidence: High The change introduces a new function Code Suggestion: Add comments explaining the distinction between regular and factory contract reference generation. |
||
| } | ||
| } | ||
|
|
@@ -96,15 +96,15 @@ mod test { | |
| true, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Contextual Comment] P1 | Confidence: High The factory contract reference methods (new_contract, upgrade_child_contract, batch_upgrade_child_contract) have been modified to remove the attached value (amount) from the call definitions. This is a breaking change for any existing code that relies on sending tokens with factory deployments. The related context shows that the VM's Code Suggestion: Either preserve the attached value mechanism or provide a clear migration path and documentation for alternative token transfer methods.Evidence: path:odra-vm/src/vm/odra_vm.rs |
||
| { | ||
| let mut named_args = odra::casper_types::RuntimeArgs::new(); | ||
| if self.attached_value > odra::casper_types::U512::zero() { | ||
| let _ = named_args.insert("amount", self.attached_value); | ||
| } | ||
| odra::args::EntrypointArgument::insert_runtime_arg(true, "odra_cfg_is_upgradable", &mut named_args); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(false, "odra_cfg_is_upgrade", &mut named_args); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(true, "odra_cfg_allow_key_override", &mut named_args); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(contract_name.clone(), "odra_cfg_package_hash_key_name", &mut named_args); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(contract_name, "contract_name", &mut named_args); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(value, "value", &mut named_args); | ||
| named_args | ||
| } | ||
| ) | ||
| .with_amount(self.attached_value), | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -120,18 +120,13 @@ mod test { | |
| true, | ||
| { | ||
| let mut named_args = odra::casper_types::RuntimeArgs::new(); | ||
| if self.attached_value > odra::casper_types::U512::zero() { | ||
| let _ = named_args.insert("amount", self.attached_value); | ||
| } | ||
| odra::args::EntrypointArgument::insert_runtime_arg( | ||
| contract_name, | ||
| "contract_name", | ||
| &mut named_args, | ||
| ); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(contract_name, "contract_name", &mut named_args); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(true, "odra_cfg_is_factory_upgrade", &mut named_args); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(true, "odra_cfg_allow_key_override", &mut named_args); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(false, "odra_cfg_create_upgrade_group", &mut named_args); | ||
| named_args | ||
| }, | ||
| ) | ||
| .with_amount(self.attached_value), | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -151,18 +146,13 @@ mod test { | |
| true, | ||
| { | ||
| let mut named_args = odra::casper_types::RuntimeArgs::new(); | ||
| if self.attached_value > odra::casper_types::U512::zero() { | ||
| let _ = named_args.insert("amount", self.attached_value); | ||
| } | ||
| odra::args::EntrypointArgument::insert_runtime_arg( | ||
| odra::args::BatchUpgradeArgs::from(args), | ||
| "args", | ||
| &mut named_args, | ||
| ); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(odra::args::BatchUpgradeArgs::from(args), "args", &mut named_args); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(true, "odra_cfg_is_factory_upgrade", &mut named_args); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(true, "odra_cfg_allow_key_override", &mut named_args); | ||
| odra::args::EntrypointArgument::insert_runtime_arg(false, "odra_cfg_create_upgrade_group", &mut named_args); | ||
| named_args | ||
| }, | ||
| ) | ||
| .with_amount(self.attached_value), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,18 @@ pub fn contract_function_item(fun: &FnIR, is_trait_impl: bool) -> syn::ItemFn { | |
| env_call(signature, call_def_expr, attrs, vis) | ||
| } | ||
|
|
||
| pub fn factory_contract_function_item(fun: &FnIR, is_trait_impl: bool) -> syn::ItemFn { | ||
| let vis = match is_trait_impl { | ||
| true => visibility_default(), | ||
| false => visibility_pub() | ||
| }; | ||
| let signature = function_signature(fun); | ||
| let call_def_expr = factory_call_def_with_amount(fun); | ||
| let attrs = function_filtered_attrs(fun); | ||
|
|
||
| env_call(signature, call_def_expr, attrs, vis) | ||
|
Comment on lines
+60
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 | Confidence: Medium The new |
||
| } | ||
|
|
||
| fn env_call( | ||
| sig: syn::Signature, | ||
| call_def_expr: syn::Expr, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2 | Confidence: Medium
The FactoryProxy example demonstrates the new factory contract reference usage but doesn't handle potential errors from the factory call. In a production scenario, factory deployments might fail due to various reasons (insufficient balance, invalid parameters), and the proxy should handle these gracefully rather than relying on the environment to revert.
Code Suggestion: