From efbe1ff6dd862f51d98217e77eca2f70525cf396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Pobiar=C5=BCyn?= Date: Tue, 6 Aug 2024 10:00:23 +0200 Subject: [PATCH] Group all derived module structs into single trait (#509) * Add OdraContract trait grouping module-related structs * Change `Deploy` definition to take advantage of `OdraContract` * Update `deploy` calls in modules and examples --- CHANGELOG.md | 6 + Cargo.toml | 16 +- benchmark/bin/benchmark.rs | 4 +- core/src/contract.rs | 13 ++ core/src/error.rs | 1 + core/src/host.rs | 140 +++++++++--------- core/src/lib.rs | 3 + examples/Cargo.toml | 2 +- examples/bin/cep18_on_livenet.rs | 6 +- examples/bin/cep78_on_livenet.rs | 13 +- examples/bin/erc20_on_livenet.rs | 6 +- examples/bin/livenet_tests.rs | 14 +- examples/bin/tlw_on_livenet.rs | 4 +- examples/ourcoin/bin/our_token_livenet.rs | 2 +- examples/ourcoin/src/token.rs | 2 +- examples/src/contracts/balance_checker.rs | 2 +- examples/src/contracts/owned_token.rs | 2 +- examples/src/contracts/tlw.rs | 2 +- examples/src/contracts/token_manager.rs | 6 +- examples/src/features/access_control.rs | 8 +- examples/src/features/cross_calls.rs | 6 +- examples/src/features/custom_types.rs | 2 +- examples/src/features/events.rs | 4 +- examples/src/features/handling_errors.rs | 6 +- examples/src/features/host_functions.rs | 4 +- examples/src/features/module_nesting.rs | 2 +- examples/src/features/modules.rs | 4 +- examples/src/features/native_token.rs | 6 +- examples/src/features/optional_args.rs | 4 +- examples/src/features/pauseable.rs | 10 +- examples/src/features/reentrancy_guard.rs | 8 +- examples/src/features/signature_verifier.rs | 6 +- examples/src/features/storage/list.rs | 4 +- examples/src/features/storage/mapping.rs | 4 +- examples/src/features/storage/variable.rs | 4 +- examples/src/features/testing.rs | 6 +- modules/Cargo.toml | 10 +- modules/src/access/ownable.rs | 15 +- modules/src/cep18/tests/allowance.rs | 6 +- modules/src/cep18/tests/transfer.rs | 6 +- modules/src/cep18_token.rs | 6 +- modules/src/cep78/tests/acl.rs | 48 +++--- modules/src/cep78/tests/burn.rs | 28 ++-- modules/src/cep78/tests/costs.rs | 10 +- modules/src/cep78/tests/events.rs | 4 +- modules/src/cep78/tests/installer.rs | 26 ++-- modules/src/cep78/tests/metadata.rs | 40 ++--- modules/src/cep78/tests/mint.rs | 48 +++--- modules/src/cep78/tests/set_variables.rs | 6 +- modules/src/cep78/tests/transfer.rs | 68 ++++----- modules/src/cep78/tests/utils.rs | 8 +- modules/src/cep78/utils.rs | 4 +- modules/src/erc1155_token.rs | 20 +-- modules/src/erc20.rs | 4 +- modules/src/erc721_token.rs | 14 +- modules/src/wrapped_native.rs | 4 +- odra-casper/proxy-caller/Cargo.toml | 2 +- .../rpc-client/src/casper_client/error.rs | 7 +- odra-macros/src/ast/contract_item.rs | 65 ++++++++ odra-macros/src/ast/deployer_item.rs | 27 +--- odra-macros/src/ast/mod.rs | 1 + odra-macros/src/ast/module_impl_item.rs | 4 + odra-macros/src/ast/test_parts.rs | 3 - odra-macros/src/utils/ident.rs | 8 - odra-macros/src/utils/ty.rs | 4 - odra/src/lib.rs | 4 +- templates/cep18.rs.template | 4 +- templates/cep18/src/token.rs | 4 +- templates/cep78.rs.template | 4 +- templates/cep78/src/token.rs | 6 +- templates/full/src/flipper.rs | 8 +- templates/workspace/flapper/src/flapper.rs | 8 +- templates/workspace/flipper/src/flipper.rs | 8 +- 73 files changed, 472 insertions(+), 402 deletions(-) create mode 100644 core/src/contract.rs create mode 100644 odra-macros/src/ast/contract_item.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 94b59815..0757a011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ Changelog for `odra`. +## [1.3.0] - 2024-08-xx +### Added +- `OdraContract` trait grouping module-related structures. +### Changed +- `Deployer` is no longer implemented for `HostRef` but for `OdraContract`. + ## [1.2.0] - 2024-07-30 ### Added - `Extern` type for simple external calls. diff --git a/Cargo.toml b/Cargo.toml index 69c66509..b7997c9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,20 +16,20 @@ exclude = [ "examples", "modules", "benchmark", "odra-casper/proxy-caller", "tem resolver = "2" [workspace.package] -version = "1.2.0" +version = "1.3.0" authors = ["Jakub Płaskonka ", "Krzysztof Pobiarżyn ", "Maciej Zieliński "] license = "MIT" homepage = "https://odra.dev/docs" repository = "https://github.com/odradev/odra" [workspace.dependencies] -odra-core = { path = "core", version = "1.2.0" } -odra-macros = { path = "odra-macros", version = "1.2.0" } -odra-casper-test-vm = { path = "odra-casper/test-vm", version = "1.2.0" } -odra-casper-rpc-client = { path = "odra-casper/rpc-client", version = "1.2.0" } -odra-vm = { path = "odra-vm", version = "1.2.0" } -odra-casper-wasm-env = { path = "odra-casper/wasm-env", version = "1.2.0"} -odra-schema = { path = "odra-schema", version = "1.2.0" } +odra-core = { path = "core", version = "1.3.0" } +odra-macros = { path = "odra-macros", version = "1.3.0" } +odra-casper-test-vm = { path = "odra-casper/test-vm", version = "1.3.0" } +odra-casper-rpc-client = { path = "odra-casper/rpc-client", version = "1.3.0" } +odra-vm = { path = "odra-vm", version = "1.3.0" } +odra-casper-wasm-env = { path = "odra-casper/wasm-env", version = "1.3.0"} +odra-schema = { path = "odra-schema", version = "1.3.0" } casper-contract = { version = "4.0.0", default-features = false } casper-types = { version = "4.0.1", default-features = false } casper-execution-engine = "7.0.1" diff --git a/benchmark/bin/benchmark.rs b/benchmark/bin/benchmark.rs index 196b2a9e..7e97501d 100644 --- a/benchmark/bin/benchmark.rs +++ b/benchmark/bin/benchmark.rs @@ -1,4 +1,4 @@ -use benchmark::benchmark::{BenchmarkHostRef, StructVariable}; +use benchmark::benchmark::{Benchmark, StructVariable}; use odra::host::{Deployer, HostRef, NoArgs}; use odra_test::env; use std::fs; @@ -8,7 +8,7 @@ pub fn main() { println!("Running benchmark..."); let env = env(); - let mut contract = BenchmarkHostRef::deploy(&env, NoArgs); + let mut contract = Benchmark::deploy(&env, NoArgs); // Var contract.set_variable(true); assert!(contract.get_variable()); diff --git a/core/src/contract.rs b/core/src/contract.rs new file mode 100644 index 00000000..3446022d --- /dev/null +++ b/core/src/contract.rs @@ -0,0 +1,13 @@ +/// The contract trait. +pub trait OdraContract { + /// The host reference type. + #[cfg(not(target_arch = "wasm32"))] + type HostRef: crate::host::HostRef + + crate::host::EntryPointsCallerProvider + + crate::contract_def::HasIdent; + /// The contract reference type. + type ContractRef: crate::ContractRef; + /// The init args type. + #[cfg(not(target_arch = "wasm32"))] + type InitArgs: crate::host::InitArgs; +} diff --git a/core/src/error.rs b/core/src/error.rs index 6ce1555a..205e747f 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -151,6 +151,7 @@ impl ExecutionError { unsafe { match self { ExecutionError::User(code) => *code, + ExecutionError::MaxUserError => 64535, ExecutionError::UserErrorTooHigh => 64536, _ => ExecutionError::UserErrorTooHigh.code() + *(self as *const Self as *const u16) } diff --git a/core/src/host.rs b/core/src/host.rs index 2efb6c57..a1cc3c0b 100644 --- a/core/src/host.rs +++ b/core/src/host.rs @@ -3,10 +3,12 @@ use crate::address::Addressable; use crate::gas_report::GasReport; use crate::{ - call_result::CallResult, contract_def::HasIdent, entry_point_callback::EntryPointsCaller, - Address, CallDef, ContractCallResult, ContractEnv, EventError, OdraError, OdraResult, VmError + call_result::CallResult, entry_point_callback::EntryPointsCaller, Address, CallDef, + ContractCallResult, ContractEnv, EventError, OdraError, OdraResult, VmError }; use crate::{consts, prelude::*, utils, ExecutionError}; +#[cfg(not(target_arch = "wasm32"))] +use crate::{contract::OdraContract, contract_def::HasIdent}; use casper_event_standard::EventInstance; use casper_types::{ bytesrepr::{Bytes, FromBytes, ToBytes}, @@ -45,9 +47,9 @@ impl Addressable for T { /// Trait for loading a contract from the host environment. /// /// Similar to [Deployer], but does not deploy a new contract, but loads an existing one. -pub trait HostRefLoader { +pub trait HostRefLoader { /// Loads an existing contract from the host environment. - fn load(env: &HostEnv, address: Address) -> Self; + fn load(env: &HostEnv, address: Address) -> T; } /// A type which can provide an [EntryPointsCaller]. @@ -62,7 +64,8 @@ pub trait EntryPointsCallerProvider { /// on a virtual machine or on a real blockchain. /// /// The `Deployer` trait provides a simple way to deploy a contract. -pub trait Deployer: Sized { +#[cfg(not(target_arch = "wasm32"))] +pub trait Deployer: Sized { /// Deploys a contract with given init args. /// /// If the init args are provided, the contract is deployed and initialized @@ -70,21 +73,16 @@ pub trait Deployer: Sized { /// is deployed without initialization. /// /// Returns a host reference to the deployed contract. - fn deploy(env: &HostEnv, init_args: T) -> Self; + fn deploy(env: &HostEnv, init_args: R::InitArgs) -> R::HostRef; /// Tries to deploy a contract with given init args. /// /// Similar to `deploy`, but returns a result instead of panicking. - fn try_deploy(env: &HostEnv, init_args: T) -> OdraResult; + fn try_deploy(env: &HostEnv, init_args: R::InitArgs) -> OdraResult; } /// A type which can be used as initialization arguments for a contract. -pub trait InitArgs: Into { - /// Validates the args are used to initialized the right contact. - /// - /// If the `expected_ident` does not match the contract ident, the method returns `false`. - fn validate(expected_ident: &str) -> bool; -} +pub trait InitArgs: Into {} /// Default implementation of [InitArgs]. Should be used when the contract /// does not require initialization arguments. @@ -93,11 +91,7 @@ pub trait InitArgs: Into { /// or does not require any arguments. pub struct NoArgs; -impl InitArgs for NoArgs { - fn validate(_expected_ident: &str) -> bool { - true - } -} +impl InitArgs for NoArgs {} impl From for RuntimeArgs { fn from(_: NoArgs) -> Self { @@ -105,9 +99,13 @@ impl From for RuntimeArgs { } } -impl Deployer for R { - fn deploy(env: &HostEnv, init_args: T) -> Self { - let contract_ident = R::ident(); +#[cfg(not(target_arch = "wasm32"))] +impl Deployer for R { + fn deploy( + env: &HostEnv, + init_args: ::InitArgs + ) -> ::HostRef { + let contract_ident = R::HostRef::ident(); match Self::try_deploy(env, init_args) { Ok(contract) => contract, Err(OdraError::ExecutionError(ExecutionError::MissingArg)) => { @@ -117,24 +115,25 @@ impl Deployer for R { } } - fn try_deploy(env: &HostEnv, init_args: T) -> OdraResult { - let contract_ident = R::ident(); - if !T::validate(&contract_ident) { - return Err(OdraError::ExecutionError(ExecutionError::MissingArg)); - } + fn try_deploy( + env: &HostEnv, + init_args: ::InitArgs + ) -> OdraResult<::HostRef> { + let contract_ident = R::HostRef::ident(); - let caller = R::entry_points_caller(env); + let caller = R::HostRef::entry_points_caller(env); let address = env.new_contract(&contract_ident, init_args.into(), caller)?; - Ok(R::new(address, env.clone())) + Ok(R::HostRef::new(address, env.clone())) } } -impl HostRefLoader for T { - fn load(env: &HostEnv, address: Address) -> Self { - let caller = T::entry_points_caller(env); - let contract_name = T::ident(); +#[cfg(not(target_arch = "wasm32"))] +impl HostRefLoader for T { + fn load(env: &HostEnv, address: Address) -> T::HostRef { + let caller = T::HostRef::entry_points_caller(env); + let contract_name = T::HostRef::ident(); env.register_contract(address, contract_name, caller); - T::new(address, env.clone()) + T::HostRef::new(address, env.clone()) } } @@ -311,8 +310,24 @@ impl HostEnv { address: Address, call_def: CallDef ) -> OdraResult { - let backend = self.backend.borrow(); let use_proxy = T::cl_type() != <()>::cl_type() || !call_def.amount().is_zero(); + let call_result = self.raw_call_contract(address, call_def, use_proxy); + call_result.map(|bytes| { + T::from_bytes(&bytes) + .map(|(obj, _)| obj) + .map_err(|_| OdraError::VmError(VmError::Deserialization)) + })? + } + + /// Calls a contract at the specified address with the given call definition. Returns raw, + /// not serialized bytes. + pub fn raw_call_contract( + &self, + address: Address, + call_def: CallDef, + use_proxy: bool + ) -> OdraResult { + let backend = self.backend.borrow(); let call_result = backend.call_contract(&address, call_def, use_proxy); let mut events_map: BTreeMap> = BTreeMap::new(); @@ -347,11 +362,7 @@ impl HostEnv { events_map ))); - call_result.map(|bytes| { - T::from_bytes(&bytes) - .map(|(obj, _)| obj) - .map_err(|_| OdraError::VmError(VmError::Deserialization)) - })? + call_result } /// Returns the gas cost of the last contract call. @@ -553,7 +564,6 @@ mod test { static IDENT_MTX: Mutex<()> = Mutex::new(()); static EPC_MTX: Mutex<()> = Mutex::new(()); - static VALIDATE_MTX: Mutex<()> = Mutex::new(()); #[derive(Debug, Event, PartialEq)] struct TestEv {} @@ -576,11 +586,25 @@ mod test { } } + impl ContractRef for MockTestRef { + fn new(_env: Rc, _address: Address) -> Self { + unimplemented!() + } + fn address(&self) -> &Address { + unimplemented!() + } + } + + impl OdraContract for MockTestRef { + type HostRef = MockTestRef; + + type ContractRef = MockTestRef; + + type InitArgs = NoArgs; + } + mock! { Ev {} - impl InitArgs for Ev { - fn validate(expected_ident: &str) -> bool; - } impl Into for Ev { fn into(self) -> RuntimeArgs; } @@ -615,43 +639,19 @@ mod test { ctx.expect_new_contract() .returning(|_, _, _| Ok(Address::Account(AccountHash::new([0; 32])))); let env = HostEnv::new(Rc::new(RefCell::new(ctx))); - ::deploy(&env, NoArgs); - } - - #[test] - #[should_panic(expected = "Invalid init args for contract TestRef.")] - fn test_deploy_with_invalid_args() { - // MockTestRef::ident() and MockEv::validate() are static and can't be safely used - // from multiple tests at the same time. Should be to protected with a Mutex. Each function has - // a separate Mutex. - // https://github.com/asomers/mockall/blob/master/mockall/tests/mock_struct_with_static_method.rs - let _i = IDENT_MTX.lock(); - let _v = VALIDATE_MTX.lock(); - - // stubs - let args_ctx = MockEv::validate_context(); - args_ctx.expect().returning(|_| false); - let indent_ctx = MockTestRef::ident_context(); - indent_ctx.expect().returning(|| "TestRef".to_string()); - - let env = HostEnv::new(Rc::new(RefCell::new(MockHostContext::new()))); - let args = MockEv::new(); - MockTestRef::deploy(&env, args); + MockTestRef::deploy(&env, NoArgs); } #[test] fn test_load_ref() { - // MockTestRef::ident(), MockEv::validate(), MockTestRef::entry_points_caller() are static and can't be safely used + // MockTestRef::ident() and MockTestRef::entry_points_caller() are static and can't be safely used // from multiple tests at the same time. Should be to protected with a Mutex. Each function has // a separate Mutex. // https://github.com/asomers/mockall/blob/master/mockall/tests/mock_struct_with_static_method.rs let _e = EPC_MTX.lock(); let _i = IDENT_MTX.lock(); - let _v = VALIDATE_MTX.lock(); // stubs - let args_ctx = MockEv::validate_context(); - args_ctx.expect().returning(|_| true); let epc_ctx = MockTestRef::entry_points_caller_context(); epc_ctx .expect() @@ -672,7 +672,7 @@ mod test { let env = HostEnv::new(Rc::new(RefCell::new(ctx))); let address = Address::Account(AccountHash::new([0; 32])); - ::load(&env, address); + MockTestRef::load(&env, address); } #[test] diff --git a/core/src/lib.rs b/core/src/lib.rs index 7177ea0b..714e98d0 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -12,6 +12,7 @@ mod call_result; pub mod callstack; #[doc(hidden)] pub mod consts; +mod contract; mod contract_container; mod contract_context; pub mod contract_def; @@ -22,6 +23,7 @@ pub mod entry_point_callback; mod error; mod external; mod gas_report; +// TODO: consider making this not wasm32 pub mod host; mod list; mod mapping; @@ -47,6 +49,7 @@ pub use error::{ }; pub use unwrap_or_revert::UnwrapOrRevert; +pub use contract::OdraContract; pub use external::External; pub use gas_report::*; pub use list::{List, ListIter}; diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 4a23c3b3..782a42df 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "odra-examples" -version = "1.2.0" +version = "1.3.0" edition = "2021" [dependencies] diff --git a/examples/bin/cep18_on_livenet.rs b/examples/bin/cep18_on_livenet.rs index 9fa83c1b..603d1c37 100644 --- a/examples/bin/cep18_on_livenet.rs +++ b/examples/bin/cep18_on_livenet.rs @@ -3,7 +3,7 @@ use odra::casper_types::U256; use odra::host::{Deployer, HostEnv, HostRefLoader}; use odra::Address; use odra_modules::cep18::utils::Cep18Modality; -use odra_modules::cep18_token::{Cep18HostRef, Cep18InitArgs}; +use odra_modules::cep18_token::{Cep18, Cep18HostRef, Cep18InitArgs}; fn main() { let env = odra_casper_livenet_env::env(); @@ -40,7 +40,7 @@ fn _load_cep18(env: &HostEnv) -> Cep18HostRef { let address = Address::new("hash-568fd396922fbbc8f8499f9b888795b2155aa60a68ef9cc38752b2771693a9ce") .unwrap(); - Cep18HostRef::load(env, address) + Cep18::load(env, address) } /// Deploys a CEP-18 contract. @@ -61,5 +61,5 @@ pub fn deploy_cep18(env: &HostEnv) -> Cep18HostRef { }; env.set_gas(300_000_000_000u64); - Cep18HostRef::deploy(env, init_args) + Cep18::deploy(env, init_args) } diff --git a/examples/bin/cep78_on_livenet.rs b/examples/bin/cep78_on_livenet.rs index e85b0ceb..cc86067d 100644 --- a/examples/bin/cep78_on_livenet.rs +++ b/examples/bin/cep78_on_livenet.rs @@ -6,7 +6,7 @@ use odra::Address; use odra_modules::cep78::modalities::{ EventsMode, MetadataMutability, NFTIdentifierMode, NFTKind, NFTMetadataKind, OwnershipMode }; -use odra_modules::cep78::token::{TestCep78HostRef, TestCep78InitArgs}; +use odra_modules::cep78::token::{TestCep78, TestCep78HostRef, TestCep78InitArgs}; use odra_modules::cep78::utils::InitArgsBuilder; const CEP78_METADATA: &str = r#"{ @@ -47,9 +47,12 @@ fn main() { } /// Loads a Cep78 contract. -pub fn load_contract(env: &HostEnv, address: &str) -> TestCep78HostRef { - let address = Address::new(address).expect("Should be a valid contract address"); - TestCep78HostRef::load(env, address) +pub fn load_contract(env: &HostEnv, address: &'static str) -> TestCep78HostRef { + let address = Address::new(address).expect("Should be a valid address"); + if !address.is_contract() { + panic!("Address is not a contract"); + } + TestCep78::load(env, address) } /// Deploys a Cep78 contract. @@ -72,5 +75,5 @@ pub fn deploy_contract(env: &HostEnv) -> TestCep78HostRef { .build(); env.set_gas(430_000_000_000u64); - TestCep78HostRef::deploy(env, init_args) + TestCep78::deploy(env, init_args) } diff --git a/examples/bin/erc20_on_livenet.rs b/examples/bin/erc20_on_livenet.rs index 9537ad8b..0dbda54c 100644 --- a/examples/bin/erc20_on_livenet.rs +++ b/examples/bin/erc20_on_livenet.rs @@ -2,7 +2,7 @@ use odra::casper_types::U256; use odra::host::{Deployer, HostEnv, HostRef, HostRefLoader}; use odra::Address; -use odra_modules::erc20::{Erc20HostRef, Erc20InitArgs}; +use odra_modules::erc20::{Erc20, Erc20HostRef, Erc20InitArgs}; use std::str::FromStr; fn main() { @@ -32,7 +32,7 @@ fn main() { fn _load_erc20(env: &HostEnv) -> Erc20HostRef { let address = "hash-d26fcbd2106e37be975d2045c580334a6d7b9d0a241c2358a4db970dfd516945"; let address = Address::from_str(address).unwrap(); - Erc20HostRef::load(env, address) + Erc20::load(env, address) } /// Deploys an ERC20 contract. @@ -50,5 +50,5 @@ pub fn deploy_erc20(env: &HostEnv) -> Erc20HostRef { }; env.set_gas(100_000_000_000u64); - Erc20HostRef::deploy(env, init_args) + Erc20::deploy(env, init_args) } diff --git a/examples/bin/livenet_tests.rs b/examples/bin/livenet_tests.rs index d42ba469..87b7e12b 100644 --- a/examples/bin/livenet_tests.rs +++ b/examples/bin/livenet_tests.rs @@ -3,9 +3,11 @@ use odra::casper_types::U256; use odra::host::{Deployer, HostEnv, HostRef, HostRefLoader}; use odra::Address; use odra::ExecutionError; -use odra_examples::features::livenet::{LivenetContractHostRef, LivenetContractInitArgs}; +use odra_examples::features::livenet::{ + LivenetContract, LivenetContractHostRef, LivenetContractInitArgs +}; use odra_modules::access::events::OwnershipTransferred; -use odra_modules::erc20::{Erc20HostRef, Erc20InitArgs}; +use odra_modules::erc20::{Erc20, Erc20HostRef, Erc20InitArgs}; fn main() { let env = odra_casper_livenet_env::env(); @@ -68,7 +70,7 @@ fn deploy_new(env: &HostEnv) -> (LivenetContractHostRef, Erc20HostRef) { let init_args = LivenetContractInitArgs { erc20_address: *erc20_contract.address() }; - let livenet_contract = LivenetContractHostRef::deploy(env, init_args); + let livenet_contract = LivenetContract::deploy(env, init_args); erc20_contract.transfer(livenet_contract.address(), &1000.into()); (livenet_contract, erc20_contract) } @@ -79,8 +81,8 @@ fn load( erc20_address: Address ) -> (LivenetContractHostRef, Erc20HostRef) { ( - LivenetContractHostRef::load(env, contract_address), - Erc20HostRef::load(env, erc20_address) + LivenetContract::load(env, contract_address), + Erc20::load(env, erc20_address) ) } @@ -99,5 +101,5 @@ pub fn deploy_erc20(env: &HostEnv) -> Erc20HostRef { }; env.set_gas(100_000_000_000u64); - Erc20HostRef::deploy(env, init_args) + Erc20::deploy(env, init_args) } diff --git a/examples/bin/tlw_on_livenet.rs b/examples/bin/tlw_on_livenet.rs index 243c24c6..75040d74 100644 --- a/examples/bin/tlw_on_livenet.rs +++ b/examples/bin/tlw_on_livenet.rs @@ -2,7 +2,7 @@ use odra::casper_types::{AsymmetricType, PublicKey, U512}; use odra::host::{Deployer, HostRef}; use odra::Address; -use odra_examples::contracts::tlw::{TimeLockWalletHostRef, TimeLockWalletInitArgs}; +use odra_examples::contracts::tlw::{TimeLockWallet, TimeLockWalletInitArgs}; const DEPOSIT: u64 = 100; const WITHDRAWAL: u64 = 99; @@ -15,7 +15,7 @@ fn main() { env.set_caller(caller); env.set_gas(GAS); - let mut contract = TimeLockWalletHostRef::deploy( + let mut contract = TimeLockWallet::deploy( &env, TimeLockWalletInitArgs { lock_duration: 60 * 60 diff --git a/examples/ourcoin/bin/our_token_livenet.rs b/examples/ourcoin/bin/our_token_livenet.rs index b0716857..1897729f 100644 --- a/examples/ourcoin/bin/our_token_livenet.rs +++ b/examples/ourcoin/bin/our_token_livenet.rs @@ -69,5 +69,5 @@ pub fn deploy_our_token(env: &HostEnv) -> OurTokenHostRef { }; env.set_gas(300_000_000_000u64); - OurTokenHostRef::deploy(env, init_args) + OurToken::deploy(env, init_args) } diff --git a/examples/ourcoin/src/token.rs b/examples/ourcoin/src/token.rs index cc73732d..4be2bade 100644 --- a/examples/ourcoin/src/token.rs +++ b/examples/ourcoin/src/token.rs @@ -225,7 +225,7 @@ mod tests { initial_supply: U256::from(1_000u64) }; - let mut token = OurTokenHostRef::deploy(&env, init_args); + let mut token = OurToken::deploy(&env, init_args); // The deployer, as the only token holder, // starts a new voting to mint 1000 tokens to account 1. diff --git a/examples/src/contracts/balance_checker.rs b/examples/src/contracts/balance_checker.rs index 70da146f..bc42bbc7 100644 --- a/examples/src/contracts/balance_checker.rs +++ b/examples/src/contracts/balance_checker.rs @@ -41,7 +41,7 @@ mod tests { let token = setup(); let env = token.env(); let (owner, second_account) = (env.get_account(0), env.get_account(1)); - let balance_checker = BalanceCheckerHostRef::deploy( + let balance_checker = BalanceChecker::deploy( env, BalanceCheckerInitArgs { address: *token.address() diff --git a/examples/src/contracts/owned_token.rs b/examples/src/contracts/owned_token.rs index 2ad018e8..e87ceda1 100644 --- a/examples/src/contracts/owned_token.rs +++ b/examples/src/contracts/owned_token.rs @@ -66,7 +66,7 @@ pub mod tests { decimals: DECIMALS, initial_supply: INITIAL_SUPPLY.into() }; - OwnedTokenHostRef::deploy(&odra_test::env(), init_args) + OwnedToken::deploy(&odra_test::env(), init_args) } #[test] diff --git a/examples/src/contracts/tlw.rs b/examples/src/contracts/tlw.rs index a9202e49..6efca0ad 100644 --- a/examples/src/contracts/tlw.rs +++ b/examples/src/contracts/tlw.rs @@ -121,7 +121,7 @@ mod test { fn setup() -> (TimeLockWalletHostRef, Address, Address) { let test_env = odra_test::env(); ( - TimeLockWalletHostRef::deploy( + TimeLockWallet::deploy( &test_env, TimeLockWalletInitArgs { lock_duration: ONE_DAY_IN_SECONDS diff --git a/examples/src/contracts/token_manager.rs b/examples/src/contracts/token_manager.rs index c9408320..950806f2 100644 --- a/examples/src/contracts/token_manager.rs +++ b/examples/src/contracts/token_manager.rs @@ -55,7 +55,7 @@ impl TokenManager { #[cfg(test)] mod test { - use super::TokenManagerHostRef; + use super::{TokenManager, TokenManagerHostRef}; use odra::casper_types::U256; use odra::{ host::{Deployer, HostRef, NoArgs}, @@ -70,7 +70,7 @@ mod test { fn setup() -> TokenManagerHostRef { let test_env = odra_test::env(); - let mut contract = TokenManagerHostRef::deploy(&test_env, NoArgs); + let mut contract = TokenManager::deploy(&test_env, NoArgs); contract.add_token(String::from(PLASCOIN), DECIMALS, String::from(PLS)); contract.add_token(String::from(MY_COIN), DECIMALS, String::from(MCN)); @@ -137,7 +137,7 @@ mod test { #[test] fn many_tokens_works() { let test_env = odra_test::env(); - let mut contract = TokenManagerHostRef::deploy(&test_env, NoArgs); + let mut contract = TokenManager::deploy(&test_env, NoArgs); let (user, balance) = (test_env.get_account(0), U256::from(111)); for i in 0..20 { contract.add_token(i.to_string(), DECIMALS, i.to_string()); diff --git a/examples/src/features/access_control.rs b/examples/src/features/access_control.rs index f3ebe66e..3e818c09 100644 --- a/examples/src/features/access_control.rs +++ b/examples/src/features/access_control.rs @@ -87,7 +87,9 @@ pub fn keccak_256(input: &str) -> Role { #[cfg(test)] pub mod test { - use super::{keccak_256, MockModeratedHostRef, ROLE_MODERATOR, ROLE_MODERATOR_ADMIN}; + use super::{ + keccak_256, MockModerated, MockModeratedHostRef, ROLE_MODERATOR, ROLE_MODERATOR_ADMIN + }; use odra::{ host::{Deployer, HostRef, NoArgs}, Address @@ -100,7 +102,7 @@ pub mod test { #[test] fn deploy_works() { let env = odra_test::env(); - let contract = MockModeratedHostRef::deploy(&env, NoArgs); + let contract = MockModerated::deploy(&env, NoArgs); let admin = env.get_account(0); assert!(contract.is_moderator(&admin)); @@ -268,7 +270,7 @@ pub mod test { fn setup(add_moderator: bool) -> (MockModeratedHostRef, Address, Address, Address) { let env = odra_test::env(); - let mut contract = MockModeratedHostRef::deploy(&env, NoArgs); + let mut contract = MockModerated::deploy(&env, NoArgs); // given admin who is a moderator and two users that are not moderators. let (admin, user1, user2) = (env.get_account(0), env.get_account(1), env.get_account(2)); if add_moderator { diff --git a/examples/src/features/cross_calls.rs b/examples/src/features/cross_calls.rs index 095f5401..81a76da9 100644 --- a/examples/src/features/cross_calls.rs +++ b/examples/src/features/cross_calls.rs @@ -37,14 +37,14 @@ impl MathEngine { #[cfg(test)] mod tests { - use super::{CrossContractHostRef, CrossContractInitArgs, MathEngineHostRef}; + use super::{CrossContract, CrossContractInitArgs, MathEngine}; use odra::host::{Deployer, HostRef, NoArgs}; #[test] fn test_cross_calls() { let test_env = odra_test::env(); - let math_engine_contract = MathEngineHostRef::deploy(&test_env, NoArgs); - let cross_contract = CrossContractHostRef::deploy( + let math_engine_contract = MathEngine::deploy(&test_env, NoArgs); + let cross_contract = CrossContract::deploy( &test_env, CrossContractInitArgs { math_engine_address: *math_engine_contract.address() diff --git a/examples/src/features/custom_types.rs b/examples/src/features/custom_types.rs index f0e473b6..8338f5f8 100644 --- a/examples/src/features/custom_types.rs +++ b/examples/src/features/custom_types.rs @@ -105,7 +105,7 @@ mod tests { unit: Unit::C, my_struct: MyStruct { a: 10, b: 20 } }; - let contract = MyContractHostRef::deploy(&test_env, init_args); + let contract = MyContract::deploy(&test_env, init_args); assert_eq!(contract.get_ip(), IP::IPv4([192, 168, 0, 1])); assert_eq!(contract.get_fieldless(), Fieldless::Tuple()); diff --git a/examples/src/features/events.rs b/examples/src/features/events.rs index a775ba5e..4b36d039 100644 --- a/examples/src/features/events.rs +++ b/examples/src/features/events.rs @@ -28,13 +28,13 @@ impl PartyContract { #[cfg(test)] mod tests { - use super::{PartyContractHostRef, PartyStarted}; + use super::{PartyContract, PartyStarted}; use odra::host::{Deployer, NoArgs}; #[test] fn test_party() { let test_env = odra_test::env(); - let party_contract = PartyContractHostRef::deploy(&test_env, NoArgs); + let party_contract = PartyContract::deploy(&test_env, NoArgs); test_env.emitted_event( &party_contract, &PartyStarted { diff --git a/examples/src/features/handling_errors.rs b/examples/src/features/handling_errors.rs index 181c4679..f2f2608f 100644 --- a/examples/src/features/handling_errors.rs +++ b/examples/src/features/handling_errors.rs @@ -49,7 +49,7 @@ impl OwnedContract { #[cfg(test)] mod tests { - use super::{Error, OwnedContractHostRef, OwnedContractInitArgs}; + use super::{Error, OwnedContract, OwnedContractInitArgs}; use odra::{host::Deployer, prelude::*}; #[test] @@ -59,7 +59,7 @@ mod tests { let not_an_owner = test_env.get_account(1); test_env.set_caller(owner); - let mut owned_contract = OwnedContractHostRef::deploy( + let mut owned_contract = OwnedContract::deploy( &test_env, OwnedContractInitArgs { name: "OwnedContract".to_string() @@ -83,7 +83,7 @@ mod tests { let not_an_owner = test_env.get_account(1); test_env.set_caller(owner); - let mut owned_contract = OwnedContractHostRef::deploy( + let mut owned_contract = OwnedContract::deploy( &test_env, OwnedContractInitArgs { name: "OwnedContract".to_string() diff --git a/examples/src/features/host_functions.rs b/examples/src/features/host_functions.rs index 31a2076f..24fbf10b 100644 --- a/examples/src/features/host_functions.rs +++ b/examples/src/features/host_functions.rs @@ -29,12 +29,12 @@ impl HostContract { mod tests { use odra::{host::Deployer, prelude::string::ToString}; - use crate::features::host_functions::{HostContractHostRef, HostContractInitArgs}; + use crate::features::host_functions::{HostContract, HostContractInitArgs}; #[test] fn host_test() { let test_env = odra_test::env(); - let host_contract = HostContractHostRef::deploy( + let host_contract = HostContract::deploy( &test_env, HostContractInitArgs { name: "HostContract".to_string() diff --git a/examples/src/features/module_nesting.rs b/examples/src/features/module_nesting.rs index e3f96041..08c53074 100644 --- a/examples/src/features/module_nesting.rs +++ b/examples/src/features/module_nesting.rs @@ -150,7 +150,7 @@ mod tests { #[test] fn nested_odra_types() { let test_env = odra_test::env(); - let mut nested_odra_types = NestedOdraTypesContractHostRef::deploy(&test_env, NoArgs); + let mut nested_odra_types = NestedOdraTypesContract::deploy(&test_env, NoArgs); // Storage is not set assert_eq!(nested_odra_types.latest_result(), None); diff --git a/examples/src/features/modules.rs b/examples/src/features/modules.rs index 61dae7e2..56fe0517 100644 --- a/examples/src/features/modules.rs +++ b/examples/src/features/modules.rs @@ -20,13 +20,13 @@ impl ModulesContract { #[cfg(test)] mod tests { - use super::ModulesContractHostRef; + use super::ModulesContract; use odra::host::{Deployer, NoArgs}; #[test] fn test_modules() { let test_env = odra_test::env(); - let modules_contract = ModulesContractHostRef::deploy(&test_env, NoArgs); + let modules_contract = ModulesContract::deploy(&test_env, NoArgs); assert_eq!(modules_contract.add_using_module(), 8); } } diff --git a/examples/src/features/native_token.rs b/examples/src/features/native_token.rs index 8570bde5..68f1f8bf 100644 --- a/examples/src/features/native_token.rs +++ b/examples/src/features/native_token.rs @@ -25,7 +25,7 @@ impl PublicWallet { #[cfg(test)] mod tests { - use super::PublicWalletHostRef; + use super::PublicWallet; use odra::{ casper_types::U512, host::{Deployer, HostRef, NoArgs} @@ -34,7 +34,7 @@ mod tests { #[test] fn test_modules() { let test_env = odra_test::env(); - let mut my_contract = PublicWalletHostRef::deploy(&test_env, NoArgs); + let mut my_contract = PublicWallet::deploy(&test_env, NoArgs); let original_contract_balance = test_env.balance_of(&my_contract); assert_eq!(test_env.balance_of(&my_contract), U512::zero()); @@ -51,7 +51,7 @@ mod tests { #[test] fn test_call_non_payable_function_with_tokens() { let test_env = odra_test::env(); - let contract = PublicWalletHostRef::deploy(&test_env, NoArgs); + let contract = PublicWallet::deploy(&test_env, NoArgs); let caller_address = test_env.get_account(0); let original_caller_balance = test_env.balance_of(&caller_address); diff --git a/examples/src/features/optional_args.rs b/examples/src/features/optional_args.rs index 6aa3e295..10859a61 100644 --- a/examples/src/features/optional_args.rs +++ b/examples/src/features/optional_args.rs @@ -40,7 +40,7 @@ mod test { name: String::from("MyToken"), metadata: Maybe::None }; - let my_contract = TokenHostRef::deploy(&test_env, init_args); + let my_contract = Token::deploy(&test_env, init_args); assert_eq!(my_contract.metadata(), String::from("")); } @@ -51,7 +51,7 @@ mod test { name: String::from("MyToken"), metadata: Maybe::Some(String::from("MyMetadata")) }; - let my_contract = TokenHostRef::deploy(&test_env, init_args); + let my_contract = Token::deploy(&test_env, init_args); assert_eq!(my_contract.metadata(), String::from("MyMetadata")); } } diff --git a/examples/src/features/pauseable.rs b/examples/src/features/pauseable.rs index ab331625..d3bee5d0 100644 --- a/examples/src/features/pauseable.rs +++ b/examples/src/features/pauseable.rs @@ -48,7 +48,7 @@ impl PauseableCounter { #[cfg(test)] mod test { - use super::PauseableCounterHostRef; + use super::PauseableCounter; use odra::host::{Deployer, HostRef, NoArgs}; use odra_modules::security::errors::Error::{PausedRequired, UnpausedRequired}; use odra_modules::security::events::{Paused, Unpaused}; @@ -56,7 +56,7 @@ mod test { #[test] fn pause_works() { let test_env = odra_test::env(); - let mut contract = PauseableCounterHostRef::deploy(&test_env, NoArgs); + let mut contract = PauseableCounter::deploy(&test_env, NoArgs); let caller = test_env.get_account(0); assert!(!contract.is_paused()); @@ -76,7 +76,7 @@ mod test { #[test] fn increment_only_if_unpaused() { let test_env = odra_test::env(); - let mut contract = PauseableCounterHostRef::deploy(&test_env, NoArgs); + let mut contract = PauseableCounter::deploy(&test_env, NoArgs); contract.increment(); contract.pause(); @@ -90,7 +90,7 @@ mod test { #[test] fn cannot_unpause_unpaused() { let test_env = odra_test::env(); - let mut contract = PauseableCounterHostRef::deploy(&test_env, NoArgs); + let mut contract = PauseableCounter::deploy(&test_env, NoArgs); assert_eq!(contract.try_unpause().unwrap_err(), PausedRequired.into()); } @@ -98,7 +98,7 @@ mod test { #[test] fn cannot_pause_paused() { let test_env = odra_test::env(); - let mut contract = PauseableCounterHostRef::deploy(&test_env, NoArgs); + let mut contract = PauseableCounter::deploy(&test_env, NoArgs); contract.pause(); assert_eq!(contract.try_pause().unwrap_err(), UnpausedRequired.into()); } diff --git a/examples/src/features/reentrancy_guard.rs b/examples/src/features/reentrancy_guard.rs index f7b0d724..b6dbe8bd 100644 --- a/examples/src/features/reentrancy_guard.rs +++ b/examples/src/features/reentrancy_guard.rs @@ -50,12 +50,12 @@ impl ReentrancyMock { #[cfg(test)] mod test { - use super::ReentrancyMockHostRef; + use super::ReentrancyMock; use odra::host::{Deployer, NoArgs}; #[test] fn non_reentrant_function_can_be_called() { - let mut contract = ReentrancyMockHostRef::deploy(&odra_test::env(), NoArgs); + let mut contract = ReentrancyMock::deploy(&odra_test::env(), NoArgs); assert_eq!(contract.get_value(), 0); contract.non_reentrant_count(); assert_eq!(contract.get_value(), 1); @@ -63,7 +63,7 @@ mod test { #[test] fn ref_recursion_not_allowed() { - let mut contract = ReentrancyMockHostRef::deploy(&odra_test::env(), NoArgs); + let mut contract = ReentrancyMock::deploy(&odra_test::env(), NoArgs); assert_eq!( contract.try_count_ref_recursive(11).unwrap_err(), odra::ExecutionError::ReentrantCall.into() @@ -72,7 +72,7 @@ mod test { #[test] fn local_recursion_allowed() { - let mut contract = ReentrancyMockHostRef::deploy(&odra_test::env(), NoArgs); + let mut contract = ReentrancyMock::deploy(&odra_test::env(), NoArgs); contract.count_local_recursive(11); assert_eq!(contract.get_value(), 11); } diff --git a/examples/src/features/signature_verifier.rs b/examples/src/features/signature_verifier.rs index 3e3542fb..7edc7d53 100644 --- a/examples/src/features/signature_verifier.rs +++ b/examples/src/features/signature_verifier.rs @@ -21,7 +21,7 @@ impl SignatureVerifier { #[cfg(test)] mod test { - use super::SignatureVerifierHostRef; + use super::SignatureVerifier; use odra::{ casper_types::{ bytesrepr::{Bytes, FromBytes}, @@ -41,7 +41,7 @@ mod test { let public_key = test_env.public_key(&account); - let signature_verifier = SignatureVerifierHostRef::deploy(&test_env, NoArgs); + let signature_verifier = SignatureVerifier::deploy(&test_env, NoArgs); assert!(signature_verifier.verify_signature(&message_bytes, &signature, &public_key)); } @@ -68,7 +68,7 @@ mod test { let public_key_decoded = hex::decode(public_key_hex).unwrap(); let (public_key, _) = PublicKey::from_bytes(public_key_decoded.as_slice()).unwrap(); - let signature_verifier = SignatureVerifierHostRef::deploy(&odra_test::env(), NoArgs); + let signature_verifier = SignatureVerifier::deploy(&odra_test::env(), NoArgs); assert!(signature_verifier.verify_signature(&message_bytes, &signature_bytes, &public_key)); } } diff --git a/examples/src/features/storage/list.rs b/examples/src/features/storage/list.rs index 37159331..142f97f9 100644 --- a/examples/src/features/storage/list.rs +++ b/examples/src/features/storage/list.rs @@ -38,13 +38,13 @@ impl DogContract3 { #[cfg(test)] mod tests { - use super::{DogContract3HostRef, DogContract3InitArgs}; + use super::{DogContract3, DogContract3InitArgs}; use odra::{host::Deployer, prelude::string::ToString}; #[test] fn init_test() { let test_env = odra_test::env(); - let mut dog_contract = DogContract3HostRef::deploy( + let mut dog_contract = DogContract3::deploy( &test_env, DogContract3InitArgs { name: "DogContract".to_string() diff --git a/examples/src/features/storage/mapping.rs b/examples/src/features/storage/mapping.rs index 60598b3a..9c0fcf5d 100644 --- a/examples/src/features/storage/mapping.rs +++ b/examples/src/features/storage/mapping.rs @@ -38,13 +38,13 @@ impl DogContract2 { #[cfg(test)] mod tests { - use super::{DogContract2HostRef, DogContract2InitArgs}; + use super::{DogContract2, DogContract2InitArgs}; use odra::{host::Deployer, prelude::string::ToString}; #[test] fn visit_test() { let test_env = odra_test::env(); - let mut dog_contract = DogContract2HostRef::deploy( + let mut dog_contract = DogContract2::deploy( &test_env, DogContract2InitArgs { name: "Mantus".to_string() diff --git a/examples/src/features/storage/variable.rs b/examples/src/features/storage/variable.rs index cb6bf915..b340e548 100644 --- a/examples/src/features/storage/variable.rs +++ b/examples/src/features/storage/variable.rs @@ -51,7 +51,7 @@ impl DogContract { #[cfg(test)] mod tests { - use super::{DogContractHostRef, DogContractInitArgs}; + use super::{DogContract, DogContractInitArgs}; use odra::{host::Deployer, prelude::string::ToString}; #[test] @@ -62,7 +62,7 @@ mod tests { weight: 10, name: "Mantus".to_string() }; - let dog_contract = DogContractHostRef::deploy(&test_env, init_args); + let dog_contract = DogContract::deploy(&test_env, init_args); assert!(dog_contract.barks()); assert_eq!(dog_contract.weight(), 10); assert_eq!(dog_contract.name(), "Mantus".to_string()); diff --git a/examples/src/features/testing.rs b/examples/src/features/testing.rs index 2b579660..5ccf38cd 100644 --- a/examples/src/features/testing.rs +++ b/examples/src/features/testing.rs @@ -40,13 +40,13 @@ impl TestingContract { mod tests { use odra::{host::Deployer, prelude::*}; - use crate::features::testing::{TestingContractHostRef, TestingContractInitArgs}; + use crate::features::testing::{TestingContract, TestingContractInitArgs}; #[test] fn env() { let test_env = odra_test::env(); test_env.set_caller(test_env.get_account(0)); - let testing_contract = TestingContractHostRef::deploy( + let testing_contract = TestingContract::deploy( &test_env, TestingContractInitArgs { name: "MyContract".to_string() @@ -54,7 +54,7 @@ mod tests { ); let creator = testing_contract.created_by(); test_env.set_caller(test_env.get_account(1)); - let testing_contract2 = TestingContractHostRef::deploy( + let testing_contract2 = TestingContract::deploy( &test_env, TestingContractInitArgs { name: "MyContract2".to_string() diff --git a/modules/Cargo.toml b/modules/Cargo.toml index ac093bb2..8eac1c98 100644 --- a/modules/Cargo.toml +++ b/modules/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "odra-modules" -version = "1.2.0" +version = "1.3.0" edition = "2021" authors = ["Jakub Płaskonka ", "Krzysztof Pobiarżyn ", "Maciej Zieliński "] license = "MIT" @@ -9,7 +9,7 @@ description = "Collection of reusable Odra modules." keywords = ["wasm", "webassembly", "blockchain"] [dependencies] -odra = { path = "../odra", version = "1.2.0", default-features = false } +odra = { path = "../odra", version = "1.3.0", default-features = false } serde = { version = "1.0.80", default-features = false } serde_json = { version = "1.0.59", default-features = false } serde-json-wasm = { version = "1.0.1", default-features = false } @@ -17,15 +17,15 @@ base16 = { version = "0.2.1", default-features = false } base64 = { version = "0.22.0", default-features = false, features = ["alloc"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -odra-build = { path = "../odra-build", version = "1.2.0" } +odra-build = { path = "../odra-build", version = "1.3.0" } [dev-dependencies] -odra-test = { path = "../odra-test", version = "1.2.0" } +odra-test = { path = "../odra-test", version = "1.3.0" } once_cell = "1" blake2 = "0.10.6" [build-dependencies] -odra-build = { path = "../odra-build", version = "1.2.0" } +odra-build = { path = "../odra-build", version = "1.3.0" } [features] default = [] diff --git a/modules/src/access/ownable.rs b/modules/src/access/ownable.rs index 7ad415bd..b67fa7bf 100644 --- a/modules/src/access/ownable.rs +++ b/modules/src/access/ownable.rs @@ -338,21 +338,18 @@ mod test { fn setup_ownable() -> (OwnableHostRef, Address) { let env = odra_test::env(); - (OwnableHostRef::deploy(&env, NoArgs), env.get_account(0)) + (Ownable::deploy(&env, NoArgs), env.get_account(0)) } fn setup_ownable_2_step() -> (Ownable2StepHostRef, Address) { let env = odra_test::env(); - ( - Ownable2StepHostRef::deploy(&env, NoArgs), - env.get_account(0) - ) + (Ownable2Step::deploy(&env, NoArgs), env.get_account(0)) } fn setup_renounceable() -> (Vec, Address) { let env = odra_test::env(); - let ownable = OwnableHostRef::deploy(&env, NoArgs); - let ownable_2_step = Ownable2StepHostRef::deploy(&env, NoArgs); + let ownable = Ownable::deploy(&env, NoArgs); + let ownable_2_step = Ownable2Step::deploy(&env, NoArgs); let renouncable_ref = RenounceableHostRef::new(*ownable.address(), env.clone()); let renouncable_2_step_ref = RenounceableHostRef::new(*ownable_2_step.address(), env.clone()); @@ -364,8 +361,8 @@ mod test { fn setup_owned() -> (HostEnv, OwnableHostRef, Ownable2StepHostRef, Address) { let env = odra_test::env(); - let ownable = OwnableHostRef::deploy(&env, NoArgs); - let ownable_2_step = Ownable2StepHostRef::deploy(&env, NoArgs); + let ownable = Ownable::deploy(&env, NoArgs); + let ownable_2_step = Ownable2Step::deploy(&env, NoArgs); (env.clone(), ownable, ownable_2_step, env.get_account(0)) } } diff --git a/modules/src/cep18/tests/allowance.rs b/modules/src/cep18/tests/allowance.rs index 34872379..95144f9c 100644 --- a/modules/src/cep18/tests/allowance.rs +++ b/modules/src/cep18/tests/allowance.rs @@ -6,7 +6,7 @@ mod allowance_tests { use odra::host::{Deployer, HostRef, NoArgs}; use odra::Address; - use crate::cep18::cep18_client_contract::Cep18ClientContractHostRef; + use crate::cep18::cep18_client_contract::Cep18ClientContract; use crate::cep18::errors::Error::InsufficientAllowance; use crate::cep18_token::tests::{ invert_address, setup, ALLOWANCE_AMOUNT_1, ALLOWANCE_AMOUNT_2, TRANSFER_AMOUNT_1 @@ -56,8 +56,8 @@ mod allowance_tests { let owner = cep18_token.env().get_account(0); let alice = cep18_token.env().get_account(1); let token_address = *cep18_token.address(); - let client_contract = Cep18ClientContractHostRef::deploy(cep18_token.env(), NoArgs); - let another_client_contract = Cep18ClientContractHostRef::deploy(cep18_token.env(), NoArgs); + let client_contract = Cep18ClientContract::deploy(cep18_token.env(), NoArgs); + let another_client_contract = Cep18ClientContract::deploy(cep18_token.env(), NoArgs); let client_contract_address = client_contract.address(); let another_client_contract_address = another_client_contract.address(); diff --git a/modules/src/cep18/tests/transfer.rs b/modules/src/cep18/tests/transfer.rs index fa5534a4..66b416aa 100644 --- a/modules/src/cep18/tests/transfer.rs +++ b/modules/src/cep18/tests/transfer.rs @@ -3,7 +3,7 @@ mod transfer_tests { use odra::casper_types::U256; use odra::host::{Deployer, HostRef, NoArgs}; - use crate::cep18::cep18_client_contract::Cep18ClientContractHostRef; + use crate::cep18::cep18_client_contract::Cep18ClientContract; use crate::cep18::errors::Error::{CannotTargetSelfUser, InsufficientBalance}; use crate::cep18_token::tests::{ setup, ALLOWANCE_AMOUNT_1, TOKEN_TOTAL_SUPPLY, TRANSFER_AMOUNT_1 @@ -86,7 +86,7 @@ mod transfer_tests { #[test] fn should_transfer_from_account_by_contract() { let mut cep18_token = setup(false); - let client_contract = Cep18ClientContractHostRef::deploy(cep18_token.env(), NoArgs); + let client_contract = Cep18ClientContract::deploy(cep18_token.env(), NoArgs); let spender = cep18_token.env().get_account(1); let owner = cep18_token.env().get_account(0); @@ -200,7 +200,7 @@ mod transfer_tests { // given a token let mut cep18_token = setup(false); let owner = cep18_token.env().get_account(0); - let client_contract = Cep18ClientContractHostRef::deploy(cep18_token.env(), NoArgs); + let client_contract = Cep18ClientContract::deploy(cep18_token.env(), NoArgs); // when the owner transfers tokens to another contract cep18_token.transfer(client_contract.address(), &TRANSFER_AMOUNT_1.into()); diff --git a/modules/src/cep18_token.rs b/modules/src/cep18_token.rs index 7db8a3f0..ae039846 100644 --- a/modules/src/cep18_token.rs +++ b/modules/src/cep18_token.rs @@ -369,7 +369,9 @@ pub(crate) mod tests { use odra::host::{Deployer, HostEnv, HostRef}; use odra::Address; - use crate::cep18_token::{Cep18HostRef, Cep18InitArgs}; + use crate::cep18_token::{Cep18, Cep18InitArgs}; + + use super::Cep18HostRef; pub const TOKEN_NAME: &str = "Plascoin"; pub const TOKEN_SYMBOL: &str = "PLS"; @@ -401,7 +403,7 @@ pub(crate) mod tests { } pub fn setup_with_args(env: &HostEnv, args: Cep18InitArgs) -> Cep18HostRef { - Cep18HostRef::deploy(env, args) + Cep18::deploy(env, args) } pub fn invert_address(address: Address) -> Address { diff --git a/modules/src/cep78/tests/acl.rs b/modules/src/cep78/tests/acl.rs index dd5e6988..998a87a6 100644 --- a/modules/src/cep78/tests/acl.rs +++ b/modules/src/cep78/tests/acl.rs @@ -8,8 +8,8 @@ use crate::cep78::{ error::CEP78Error, modalities::{MintingMode, NFTHolderMode, OwnershipMode, WhitelistMode}, tests::utils::TEST_PRETTY_721_META_DATA, - token::TestCep78HostRef, - utils::{MockCep78OperatorHostRef, MockDummyContractHostRef} + token::TestCep78, + utils::{MockCep78Operator, MockDummyContract} }; use super::default_args_builder; @@ -17,7 +17,7 @@ use super::default_args_builder; #[test] fn should_install_with_acl_whitelist() { let env = odra_test::env(); - let test_contract_address = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let test_contract_address = MockCep78Operator::deploy(&env, NoArgs); let contract_whitelist = vec![*test_contract_address.address()]; let args = default_args_builder() .holder_mode(NFTHolderMode::Contracts) @@ -25,7 +25,7 @@ fn should_install_with_acl_whitelist() { .minting_mode(MintingMode::Acl) .acl_white_list(contract_whitelist) .build(); - let contract = TestCep78HostRef::deploy(&env, args); + let contract = TestCep78::deploy(&env, args); assert_eq!(WhitelistMode::Locked, contract.get_whitelist_mode()); let is_whitelisted_contract = contract.is_whitelisted(test_contract_address.address()); @@ -46,7 +46,7 @@ fn should_not_install_with_minting_mode_not_acl_if_acl_whitelist_provided() { .acl_white_list(contract_whitelist) .build(); - let init_result = TestCep78HostRef::try_deploy(&env, args); + let init_result = TestCep78::try_deploy(&env, args); assert_eq!( init_result.err(), Some(CEP78Error::InvalidMintingMode.into()), @@ -64,7 +64,7 @@ fn should_allow_installation_of_contract_with_empty_locked_whitelist_in_public_m .minting_mode(MintingMode::Public) .build(); - assert!(TestCep78HostRef::try_deploy(env, args).is_ok()); + assert!(TestCep78::try_deploy(env, args).is_ok()); } #[test] @@ -98,7 +98,7 @@ fn should_disallow_installation_with_contract_holder_mode_and_installer_mode() { .build(); assert_eq!( - TestCep78HostRef::try_deploy(&env, args).err(), + TestCep78::try_deploy(&env, args).err(), Some(CEP78Error::InvalidMintingMode.into()) ); } @@ -117,7 +117,7 @@ fn should_allow_whitelisted_account_to_mint() { .minting_mode(MintingMode::Acl) .acl_white_list(account_whitelist) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); assert!( contract.is_whitelisted(&account_user_1), @@ -150,7 +150,7 @@ fn should_disallow_unlisted_account_from_minting() { .minting_mode(MintingMode::Acl) .acl_white_list(account_whitelist) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); assert!( contract.is_whitelisted(&account), @@ -174,7 +174,7 @@ fn should_disallow_unlisted_account_from_minting() { fn should_allow_whitelisted_contract_to_mint() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let contract_whitelist = vec![*minting_contract.address()]; let args = default_args_builder() @@ -184,7 +184,7 @@ fn should_allow_whitelisted_contract_to_mint() { .minting_mode(MintingMode::Acl) .acl_white_list(contract_whitelist) .build(); - let contract = TestCep78HostRef::deploy(&env, args); + let contract = TestCep78::deploy(&env, args); assert!( contract.is_whitelisted(minting_contract.address()), "acl whitelist is incorrectly set" @@ -201,7 +201,7 @@ fn should_allow_whitelisted_contract_to_mint() { fn should_disallow_unlisted_contract_from_minting() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let contract_whitelist = vec![env.get_account(1), env.get_account(2), env.get_account(3)]; let args = default_args_builder() @@ -211,7 +211,7 @@ fn should_disallow_unlisted_contract_from_minting() { .minting_mode(MintingMode::Acl) .acl_white_list(contract_whitelist) .build(); - let contract = TestCep78HostRef::deploy(&env, args); + let contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); assert_eq!( @@ -225,7 +225,7 @@ fn should_disallow_unlisted_contract_from_minting() { fn should_allow_mixed_account_contract_to_mint() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let account_user_1 = env.get_account(1); let mixed_whitelist = vec![*minting_contract.address(), account_user_1]; @@ -236,7 +236,7 @@ fn should_allow_mixed_account_contract_to_mint() { .minting_mode(MintingMode::Acl) .acl_white_list(mixed_whitelist) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); assert!( @@ -270,10 +270,10 @@ fn should_allow_mixed_account_contract_to_mint() { fn should_disallow_unlisted_contract_from_minting_with_mixed_account_contract() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let account_user_1 = env.get_account(1); let mixed_whitelist = vec![ - *MockDummyContractHostRef::deploy(&env, NoArgs).address(), + *MockDummyContract::deploy(&env, NoArgs).address(), account_user_1, ]; @@ -284,7 +284,7 @@ fn should_disallow_unlisted_contract_from_minting_with_mixed_account_contract() .minting_mode(MintingMode::Acl) .acl_white_list(mixed_whitelist) .build(); - let contract = TestCep78HostRef::deploy(&env, args); + let contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); assert_eq!( @@ -298,7 +298,7 @@ fn should_disallow_unlisted_contract_from_minting_with_mixed_account_contract() fn should_disallow_unlisted_account_from_minting_with_mixed_account_contract() { let env = odra_test::env(); - let minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let minting_contract = MockCep78Operator::deploy(&env, NoArgs); let listed_account = env.get_account(0); let unlisted_account = env.get_account(1); let mixed_whitelist = vec![*minting_contract.address(), listed_account]; @@ -310,7 +310,7 @@ fn should_disallow_unlisted_account_from_minting_with_mixed_account_contract() { .minting_mode(MintingMode::Acl) .acl_white_list(mixed_whitelist) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); env.set_caller(unlisted_account); assert_eq!( contract.try_mint( @@ -327,7 +327,7 @@ fn should_disallow_unlisted_account_from_minting_with_mixed_account_contract() { fn should_disallow_listed_account_from_minting_with_nftholder_contract() { let env = odra_test::env(); - let minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let minting_contract = MockCep78Operator::deploy(&env, NoArgs); let listed_account = env.get_account(0); let mixed_whitelist = vec![*minting_contract.address(), listed_account]; @@ -339,7 +339,7 @@ fn should_disallow_listed_account_from_minting_with_nftholder_contract() { .minting_mode(MintingMode::Acl) .acl_white_list(mixed_whitelist) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); assert!( contract.is_whitelisted(&listed_account), @@ -363,7 +363,7 @@ fn should_disallow_listed_account_from_minting_with_nftholder_contract() { fn should_be_able_to_update_whitelist_for_minting() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let contract_whitelist = vec![]; let args = default_args_builder() @@ -373,7 +373,7 @@ fn should_be_able_to_update_whitelist_for_minting() { .minting_mode(MintingMode::Acl) .acl_white_list(contract_whitelist) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); assert!( diff --git a/modules/src/cep78/tests/burn.rs b/modules/src/cep78/tests/burn.rs index 5523152c..302375e0 100644 --- a/modules/src/cep78/tests/burn.rs +++ b/modules/src/cep78/tests/burn.rs @@ -12,8 +12,8 @@ use crate::cep78::{ OwnerReverseLookupMode, OwnershipMode, TokenIdentifier }, tests::{default_args_builder, utils}, - token::TestCep78HostRef, - utils::MockCep78OperatorHostRef + token::{TestCep78, TestCep78HostRef}, + utils::MockCep78Operator }; use super::utils::TEST_PRETTY_721_META_DATA; @@ -25,7 +25,7 @@ fn should_burn_minted_token(reporting: OwnerReverseLookupMode) { .ownership_mode(OwnershipMode::Transferable) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); let token_id = 0u64; @@ -96,7 +96,7 @@ fn should_not_burn_previously_burnt_token() { .ownership_mode(OwnershipMode::Transferable) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); mint(&mut contract, true, token_owner); @@ -118,7 +118,7 @@ fn should_return_expected_error_when_burning_non_existing_token() { let args = default_args_builder() .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_id = 0u64; assert_eq!( @@ -135,7 +135,7 @@ fn should_return_expected_error_burning_of_others_users_token() { .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); let account_1 = env.get_account(1); @@ -152,7 +152,7 @@ fn should_return_expected_error_burning_of_others_users_token() { #[test] fn should_allow_contract_to_burn_token() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let contract_whitelist = vec![*minting_contract.address()]; let args = default_args_builder() .holder_mode(NFTHolderMode::Contracts) @@ -161,7 +161,7 @@ fn should_allow_contract_to_burn_token() { .ownership_mode(OwnershipMode::Transferable) .acl_white_list(contract_whitelist) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); let token_owner = env.get_account(0); minting_contract.mint_for(token_owner, TEST_PRETTY_721_META_DATA.to_string()); @@ -183,7 +183,7 @@ fn should_not_burn_in_non_burn_mode() { .burn_mode(BurnMode::NonBurnable) .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); mint(&mut contract, true, token_owner); @@ -203,7 +203,7 @@ fn should_let_account_operator_burn_tokens_with_operator_burn_mode() { .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); mint(&mut contract, true, token_owner); @@ -248,12 +248,12 @@ fn should_let_contract_operator_burn_tokens_with_operator_burn_mode() { .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); mint(&mut contract, true, token_owner); let token_id = 0u64; - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); minting_contract.set_address(contract.address()); let operator = *minting_contract.address(); let account_1 = env.get_account(1); @@ -295,7 +295,7 @@ fn should_burn_token_in_hash_identifier_mode() { .metadata_mutability(MetadataMutability::Immutable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); mint(&mut contract, true, token_owner); @@ -316,7 +316,7 @@ fn should_allow_to_remint_with_reverse_lookup() { .events_mode(EventsMode::CES) .identifier_mode(NFTIdentifierMode::Hash) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_hash = "token_hash".to_string(); let token_owner = env.get_account(0); diff --git a/modules/src/cep78/tests/costs.rs b/modules/src/cep78/tests/costs.rs index 494e300c..21da10b7 100644 --- a/modules/src/cep78/tests/costs.rs +++ b/modules/src/cep78/tests/costs.rs @@ -3,7 +3,7 @@ use odra::{args::Maybe, host::Deployer}; use crate::cep78::{ modalities::{NFTMetadataKind, OwnerReverseLookupMode, OwnershipMode}, tests::{default_args_builder, utils}, - token::TestCep78HostRef + token::TestCep78 }; #[test] @@ -15,7 +15,7 @@ fn mint_cost_should_remain_stable() { .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint(token_owner, "".to_string(), Maybe::None); @@ -34,7 +34,7 @@ fn transfer_costs_should_remain_stable() { .nft_metadata_kind(NFTMetadataKind::Raw) .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract: TestCep78HostRef = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); let receiver = env.get_account(1); @@ -63,14 +63,14 @@ fn should_cost_less_when_installing_without_reverse_lookup(reporting: OwnerRever .nft_metadata_kind(NFTMetadataKind::Raw) .ownership_mode(OwnershipMode::Transferable) .build(); - TestCep78HostRef::deploy(&env, args); + TestCep78::deploy(&env, args); let args = default_args_builder() .owner_reverse_lookup_mode(reporting) .nft_metadata_kind(NFTMetadataKind::Raw) .ownership_mode(OwnershipMode::Transferable) .build(); - TestCep78HostRef::deploy(&env, args); + TestCep78::deploy(&env, args); let costs = utils::get_deploy_gas_cost(&env); if let Some(no_lookup_gas_cost) = costs.first() { diff --git a/modules/src/cep78/tests/events.rs b/modules/src/cep78/tests/events.rs index fe2e6bdb..15c9477c 100644 --- a/modules/src/cep78/tests/events.rs +++ b/modules/src/cep78/tests/events.rs @@ -6,7 +6,7 @@ use odra::{ use crate::cep78::{ modalities::{EventsMode, OwnerReverseLookupMode, OwnershipMode}, tests::{default_args_builder, utils::TEST_PRETTY_721_META_DATA}, - token::TestCep78HostRef + token::TestCep78 }; #[test] @@ -21,7 +21,7 @@ fn should_not_record_events_in_no_events_mode() { .ownership_mode(OwnershipMode::Transferable) .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint( diff --git a/modules/src/cep78/tests/installer.rs b/modules/src/cep78/tests/installer.rs index 8272a2b3..6f315cb3 100644 --- a/modules/src/cep78/tests/installer.rs +++ b/modules/src/cep78/tests/installer.rs @@ -6,8 +6,8 @@ use crate::cep78::{ MintingMode, NFTHolderMode, OwnerReverseLookupMode, OwnershipMode, WhitelistMode }, tests::{default_args_builder, COLLECTION_NAME, COLLECTION_SYMBOL}, - token::TestCep78HostRef, - utils::MockDummyContractHostRef + token::TestCep78, + utils::MockDummyContract }; #[test] @@ -20,7 +20,7 @@ fn should_install_contract() { .total_token_supply(1u64) .allow_minting(true) .build(); - let contract = TestCep78HostRef::deploy(&env, args); + let contract = TestCep78::deploy(&env, args); assert_eq!(&contract.get_collection_name(), COLLECTION_NAME); assert_eq!(&contract.get_collection_symbol(), COLLECTION_SYMBOL); @@ -39,7 +39,7 @@ fn should_install_with_allow_minting_set_to_false() { let env = odra_test::env(); let args = default_args_builder().allow_minting(false).build(); - let contract = TestCep78HostRef::deploy(&env, args); + let contract = TestCep78::deploy(&env, args); assert!(!contract.is_minting_allowed()); } @@ -58,7 +58,7 @@ fn should_reject_non_numerical_total_token_supply_value() {} #[test] fn should_install_with_contract_holder_mode() { let env = odra_test::env(); - let whitelisted_contract = MockDummyContractHostRef::deploy(&env, NoArgs); + let whitelisted_contract = MockDummyContract::deploy(&env, NoArgs); let contract_whitelist = vec![*whitelisted_contract.address()]; let args = default_args_builder() .holder_mode(NFTHolderMode::Contracts) @@ -67,7 +67,7 @@ fn should_install_with_contract_holder_mode() { .minting_mode(MintingMode::Acl) .acl_white_list(contract_whitelist) .build(); - let contract = TestCep78HostRef::deploy(&env, args); + let contract = TestCep78::deploy(&env, args); assert_eq!( contract.get_holder_mode(), @@ -97,7 +97,7 @@ fn should_disallow_installation_of_contract_with_empty_locked_whitelist_with_hol .build(); assert_eq!( - TestCep78HostRef::try_deploy(&env, args).err(), + TestCep78::try_deploy(&env, args).err(), Some(CEP78Error::EmptyACLWhitelist.into()), "should fail execution since whitelist mode is locked and the provided whitelist is empty", ); @@ -121,7 +121,7 @@ fn should_disallow_installation_with_zero_issuance() { let env = odra_test::env(); let args = default_args_builder().total_token_supply(0).build(); assert_eq!( - TestCep78HostRef::try_deploy(&env, args).err(), + TestCep78::try_deploy(&env, args).err(), Some(CEP78Error::CannotInstallWithZeroSupply.into()), "cannot install when issuance is equal 0", ); @@ -134,7 +134,7 @@ fn should_disallow_installation_with_supply_exceeding_hard_cap() { .total_token_supply(1_000_001u64) .build(); assert_eq!( - TestCep78HostRef::try_deploy(&env, args).err(), + TestCep78::try_deploy(&env, args).err(), Some(CEP78Error::ExceededMaxTotalSupply.into()), "cannot install when issuance is more than 1_000_000", ); @@ -149,7 +149,7 @@ fn should_prevent_installation_with_ownership_and_minting_modality_conflict() { .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .build(); assert_eq!( - TestCep78HostRef::try_deploy(&env, args).err(), + TestCep78::try_deploy(&env, args).err(), Some(CEP78Error::InvalidReportingMode.into()), "cannot install when Ownership::Minter and MintingMode::Installer", ); @@ -164,7 +164,7 @@ fn should_prevent_installation_with_ownership_minter_and_owner_reverse_lookup_mo .owner_reverse_lookup_mode(OwnerReverseLookupMode::TransfersOnly) .build(); assert_eq!( - TestCep78HostRef::try_deploy(&env, args).err(), + TestCep78::try_deploy(&env, args).err(), Some(CEP78Error::OwnerReverseLookupModeNotTransferable.into()), "cannot install when Ownership::Minter and OwnerReverseLookupMode::TransfersOnly", ); @@ -180,7 +180,7 @@ fn should_prevent_installation_with_ownership_assigned_and_owner_reverse_lookup_ .owner_reverse_lookup_mode(OwnerReverseLookupMode::TransfersOnly) .build(); assert_eq!( - TestCep78HostRef::try_deploy(&env, args).err(), + TestCep78::try_deploy(&env, args).err(), Some(CEP78Error::OwnerReverseLookupModeNotTransferable.into()), "cannot install when Ownership::Minter and OwnerReverseLookupMode::TransfersOnly", ); @@ -195,5 +195,5 @@ fn should_allow_installation_with_ownership_transferable_and_owner_reverse_looku .ownership_mode(OwnershipMode::Transferable) .owner_reverse_lookup_mode(OwnerReverseLookupMode::TransfersOnly) .build(); - assert_eq!(TestCep78HostRef::try_deploy(&env, args).err(), None); + assert_eq!(TestCep78::try_deploy(&env, args).err(), None); } diff --git a/modules/src/cep78/tests/metadata.rs b/modules/src/cep78/tests/metadata.rs index 21710ba4..bdc24da6 100644 --- a/modules/src/cep78/tests/metadata.rs +++ b/modules/src/cep78/tests/metadata.rs @@ -17,8 +17,8 @@ use crate::cep78::{ TEST_CUSTOM_METADATA, TEST_CUSTOM_METADATA_SCHEMA, TEST_CUSTOM_UPDATED_METADATA, TOKEN_HASH }, - token::TestCep78HostRef, - utils::MockCep78OperatorHostRef + token::TestCep78, + utils::MockCep78Operator }; use super::{ @@ -35,7 +35,7 @@ fn should_prevent_update_in_immutable_mode() { .metadata_mutability(MetadataMutability::Immutable) .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); contract.mint( env.get_account(0), TEST_PRETTY_721_META_DATA.to_string(), @@ -63,7 +63,7 @@ fn should_allow_install_with_hash_identifier_in_mutable_mode() { .identifier_mode(NFTIdentifierMode::Hash) .metadata_mutability(MetadataMutability::Mutable) .build(); - assert!(TestCep78HostRef::try_deploy(&env, args).is_ok()); + assert!(TestCep78::try_deploy(&env, args).is_ok()); } #[test] @@ -75,7 +75,7 @@ fn should_prevent_update_for_invalid_metadata() { .metadata_mutability(MetadataMutability::Mutable) .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); contract.mint( env.get_account(0), TEST_PRETTY_721_META_DATA.to_string(), @@ -105,7 +105,7 @@ fn should_prevent_metadata_update_by_non_owner_key() { .metadata_mutability(MetadataMutability::Mutable) .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = *contract.address(); contract.mint( token_owner, @@ -145,7 +145,7 @@ fn should_allow_update_for_valid_metadata_based_on_kind( .json_schema(json_schema) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); let custom_metadata = serde_json::to_string_pretty(&*TEST_CUSTOM_METADATA) @@ -256,7 +256,7 @@ fn should_update_metadata_for_custom_validated_using_token_id() { #[test] fn should_get_metadata_using_token_id() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let contract_whitelist = vec![*minting_contract.address()]; let args = default_args_builder() .holder_mode(NFTHolderMode::Contracts) @@ -265,7 +265,7 @@ fn should_get_metadata_using_token_id() { .minting_mode(MintingMode::Acl) .acl_white_list(contract_whitelist) .build(); - let contract = TestCep78HostRef::deploy(&env, args); + let contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); let token_id = 0u64; @@ -283,7 +283,7 @@ fn should_get_metadata_using_token_id() { #[test] fn should_get_metadata_using_token_metadata_hash() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let contract_whitelist = vec![*minting_contract.address()]; let args = default_args_builder() .identifier_mode(NFTIdentifierMode::Hash) @@ -294,7 +294,7 @@ fn should_get_metadata_using_token_metadata_hash() { .minting_mode(MintingMode::Acl) .acl_white_list(contract_whitelist) .build(); - let contract = TestCep78HostRef::deploy(&env, args); + let contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); assert!( @@ -314,7 +314,7 @@ fn should_get_metadata_using_token_metadata_hash() { #[test] fn should_revert_minting_token_metadata_hash_twice() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let contract_whitelist = vec![*minting_contract.address()]; let args = default_args_builder() .identifier_mode(NFTIdentifierMode::Hash) @@ -325,7 +325,7 @@ fn should_revert_minting_token_metadata_hash_twice() { .minting_mode(MintingMode::Acl) .acl_white_list(contract_whitelist) .build(); - let contract = TestCep78HostRef::deploy(&env, args); + let contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); assert!( contract.is_whitelisted(minting_contract.address()), @@ -348,7 +348,7 @@ fn should_revert_minting_token_metadata_hash_twice() { #[test] fn should_get_metadata_using_custom_token_hash() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let contract_whitelist = vec![*minting_contract.address()]; let args = default_args_builder() .identifier_mode(NFTIdentifierMode::Hash) @@ -359,7 +359,7 @@ fn should_get_metadata_using_custom_token_hash() { .minting_mode(MintingMode::Acl) .acl_white_list(contract_whitelist) .build(); - let contract = TestCep78HostRef::deploy(&env, args); + let contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); assert!( @@ -379,7 +379,7 @@ fn should_get_metadata_using_custom_token_hash() { #[test] fn should_revert_minting_custom_token_hash_identifier_twice() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let contract_whitelist = vec![*minting_contract.address()]; let args = default_args_builder() .identifier_mode(NFTIdentifierMode::Hash) @@ -390,7 +390,7 @@ fn should_revert_minting_custom_token_hash_identifier_twice() { .minting_mode(MintingMode::Acl) .acl_white_list(contract_whitelist) .build(); - let contract = TestCep78HostRef::deploy(&env, args); + let contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); assert!( @@ -426,7 +426,7 @@ fn should_require_valid_json_schema_when_kind_is_custom_validated() { .json_schema("test".to_string()) .build(); assert_eq!( - TestCep78HostRef::try_deploy(&env, args).err(), + TestCep78::try_deploy(&env, args).err(), Some(CEP78Error::InvalidJsonSchema.into()), "should fail execution since json_schema is required" ); @@ -446,7 +446,7 @@ fn should_require_json_schema_when_kind_is_custom_validated() { .build(); assert_eq!( - TestCep78HostRef::try_deploy(&env, args).err(), + TestCep78::try_deploy(&env, args).err(), Some(CEP78Error::MissingJsonSchema.into()), "should fail execution since json_schema is required" ); @@ -461,7 +461,7 @@ fn should_not_require_json_schema_when_kind_is(nft_metadata_kind: NFTMetadataKin .nft_metadata_kind(nft_metadata_kind.clone()) .json_schema("".to_string()) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let original_metadata = match &nft_metadata_kind { NFTMetadataKind::CEP78 => TEST_PRETTY_CEP78_METADATA, diff --git a/modules/src/cep78/tests/mint.rs b/modules/src/cep78/tests/mint.rs index cc711e77..217db5f0 100644 --- a/modules/src/cep78/tests/mint.rs +++ b/modules/src/cep78/tests/mint.rs @@ -19,7 +19,7 @@ use crate::cep78::{ }, TEST_CUSTOM_METADATA, TEST_CUSTOM_METADATA_SCHEMA }, - token::TestCep78HostRef + token::{TestCep78, TestCep78HostRef} }; use super::{default_args_builder, utils::TEST_PRETTY_721_META_DATA}; @@ -38,7 +38,7 @@ fn default_token() -> (TestCep78HostRef, HostEnv) { .ownership_mode(OwnershipMode::Transferable) .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .build(); - (TestCep78HostRef::deploy(&env, args), env) + (TestCep78::deploy(&env, args), env) } #[test] @@ -48,7 +48,7 @@ fn should_disallow_minting_when_allow_minting_is_set_to_false() { .nft_metadata_kind(NFTMetadataKind::NFT721) .allow_minting(false) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); assert_eq!( contract.try_mint( @@ -72,7 +72,7 @@ fn should_mint() { .nft_metadata_kind(NFTMetadataKind::CEP78) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); assert!(contract @@ -222,7 +222,7 @@ fn should_allow_public_minting_with_flag_set_to_true() { let args = default_args_builder() .minting_mode(MintingMode::Public) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let account_1 = env.get_account(1); let minting_mode = contract.get_minting_mode(); @@ -248,7 +248,7 @@ fn should_disallow_public_minting_with_flag_set_to_false() { let args = default_args_builder() .minting_mode(MintingMode::Installer) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let account_1 = env.get_account(1); let metadata = TEST_PRETTY_721_META_DATA.to_string(); @@ -274,7 +274,7 @@ fn should_allow_minting_for_different_public_key_with_minting_mode_set_to_public let args = default_args_builder() .minting_mode(MintingMode::Public) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let account_1 = env.get_account(1); let account_2 = env.get_account(2); @@ -300,7 +300,7 @@ fn should_set_approval_for_all() { .ownership_mode(OwnershipMode::Transferable) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let owner = env.get_account(0); contract.mint(owner, TEST_PRETTY_721_META_DATA.to_string(), Maybe::None); @@ -346,7 +346,7 @@ fn should_revoke_approval_for_all() { .ownership_mode(OwnershipMode::Transferable) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let owner = env.get_account(0); contract.mint(owner, TEST_PRETTY_721_META_DATA.to_string(), Maybe::None); @@ -407,7 +407,7 @@ fn should_mint_with_valid_cep78_metadata() { let args = default_args_builder() .nft_metadata_kind(NFTMetadataKind::CEP78) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); contract.mint( env.get_account(0), @@ -430,7 +430,7 @@ fn should_mint_with_custom_metadata_validation() { .nft_metadata_kind(NFTMetadataKind::CustomValidated) .json_schema(custom_json_schema) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let metadata = serde_json::to_string(&*TEST_CUSTOM_METADATA).expect("must convert to json metadata"); @@ -453,7 +453,7 @@ fn should_mint_with_raw_metadata() { let args = default_args_builder() .nft_metadata_kind(NFTMetadataKind::Raw) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); contract.mint(env.get_account(0), "raw_string".to_string(), Maybe::None); let token_id = 0u64; @@ -470,7 +470,7 @@ fn should_mint_with_hash_identifier_mode() { .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint( @@ -492,7 +492,7 @@ fn should_fail_to_mint_when_immediate_caller_is_account_in_contract_mode() { .holder_mode(NFTHolderMode::Contracts) .whitelist_mode(WhitelistMode::Unlocked) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); assert_eq!( contract.try_mint( @@ -512,7 +512,7 @@ fn should_approve_in_hash_identifier_mode() { .metadata_mutability(MetadataMutability::Immutable) .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); contract.mint( env.get_account(0), TEST_PRETTY_721_META_DATA.to_string(), @@ -535,7 +535,7 @@ fn should_mint_without_returning_receipts_and_flat_gas_cost() { .nft_metadata_kind(NFTMetadataKind::Raw) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); contract.mint(env.get_account(0), "".to_string(), Maybe::None); contract.mint(env.get_account(1), "".to_string(), Maybe::None); contract.mint(env.get_account(2), "".to_string(), Maybe::None); @@ -560,7 +560,7 @@ fn should_maintain_page_table_despite_invoking_register_owner() { .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint(token_owner, "".to_string(), Maybe::None); @@ -585,7 +585,7 @@ fn should_prevent_mint_to_unregistered_owner() { .ownership_mode(OwnershipMode::Transferable) .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); assert_eq!( contract.try_mint(env.get_account(0), "".to_string(), Maybe::None), Err(CEP78Error::UnregisteredOwnerInMint.into()) @@ -602,7 +602,7 @@ fn should_mint_with_two_required_metadata_kind() { .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .additional_required_metadata(vec![NFTMetadataKind::Raw]) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint( @@ -631,7 +631,7 @@ fn should_mint_with_one_required_one_optional_metadata_kind_without_optional() { .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .optional_metadata(vec![NFTMetadataKind::Raw]) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint( @@ -673,7 +673,7 @@ fn should_not_mint_with_missing_required_metadata() { .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .additional_required_metadata(vec![NFTMetadataKind::NFT721]) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); @@ -695,7 +695,7 @@ fn should_mint_with_transfer_only_reporting() { .nft_metadata_kind(NFTMetadataKind::CEP78) .owner_reverse_lookup_mode(OwnerReverseLookupMode::TransfersOnly) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.mint( token_owner, @@ -717,7 +717,7 @@ fn should_approve_all_in_hash_identifier_mode() { .nft_metadata_kind(NFTMetadataKind::CEP78) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); let operator = env.get_account(1); contract.mint( @@ -751,7 +751,7 @@ fn should_approve_all_with_flat_gas_cost() { .ownership_mode(OwnershipMode::Transferable) .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); let operator = env.get_account(1); let operator1 = env.get_account(2); diff --git a/modules/src/cep78/tests/set_variables.rs b/modules/src/cep78/tests/set_variables.rs index bccb03c3..827448e1 100644 --- a/modules/src/cep78/tests/set_variables.rs +++ b/modules/src/cep78/tests/set_variables.rs @@ -5,7 +5,7 @@ use odra::{ use crate::cep78::{ error::CEP78Error, events::VariablesSet, modalities::EventsMode, tests::default_args_builder, - token::TestCep78HostRef + token::TestCep78 }; #[test] @@ -16,7 +16,7 @@ fn only_installer_should_be_able_to_toggle_allow_minting() { .allow_minting(false) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = >::deploy(&env, args); // Account other than installer account should not be able to change allow_minting env.set_caller(other_user); @@ -50,7 +50,7 @@ fn installer_should_be_able_to_toggle_package_operator_mode() {} fn installer_should_be_able_to_toggle_operator_burn_mode() { let env = odra_test::env(); let args = default_args_builder().events_mode(EventsMode::CES).build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = >::deploy(&env, args); // Installer account should be able to change allow_minting assert_eq!( diff --git a/modules/src/cep78/tests/transfer.rs b/modules/src/cep78/tests/transfer.rs index f02e221c..1ee1df95 100644 --- a/modules/src/cep78/tests/transfer.rs +++ b/modules/src/cep78/tests/transfer.rs @@ -13,8 +13,8 @@ use crate::cep78::{ TransferFilterContractResult, WhitelistMode }, tests::{default_args_builder, utils::TEST_PRETTY_721_META_DATA}, - token::TestCep78HostRef, - utils::{MockCep78OperatorHostRef, MockCep78TransferFilterHostRef} + token::TestCep78, + utils::{MockCep78Operator, MockCep78TransferFilter} }; use super::utils; @@ -27,7 +27,7 @@ fn should_disallow_transfer_with_minter_or_assigned_ownership_mode() { .minting_mode(MintingMode::Installer) .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); @@ -64,7 +64,7 @@ fn should_transfer_token_from_sender_to_receiver() { .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); @@ -123,7 +123,7 @@ fn approve_token_for_transfer_should_add_entry_to_approved_dictionary( .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); @@ -183,7 +183,7 @@ fn revoke_token_for_transfer_should_remove_entry_to_approved_dictionary( .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); @@ -242,7 +242,7 @@ fn should_disallow_approving_when_ownership_mode_is_minter_or_assigned() { .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint( @@ -266,7 +266,7 @@ fn should_be_able_to_transfer_token(env: HostEnv, operator: Option
) { .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint( @@ -325,7 +325,7 @@ fn should_disallow_same_approved_account_to_transfer_token_twice() { .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .events_mode(EventsMode::CES) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); @@ -381,7 +381,7 @@ fn should_disallow_to_transfer_token_using_revoked_hash(env: HostEnv, operator: .ownership_mode(OwnershipMode::Transferable) .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); @@ -456,7 +456,7 @@ fn should_be_able_to_approve_with_deprecated_operator_argument() {} #[test] fn should_transfer_between_contract_to_account() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let contract_whitelist = vec![*minting_contract.address()]; let args = default_args_builder() .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) @@ -467,7 +467,7 @@ fn should_transfer_between_contract_to_account() { .minting_mode(MintingMode::Acl) .acl_white_list(contract_whitelist) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); assert!( @@ -499,7 +499,7 @@ fn should_prevent_transfer_when_caller_is_not_owner() { .ownership_mode(OwnershipMode::Transferable) .holder_mode(NFTHolderMode::Accounts) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); let unauthorized_user = env.get_account(10); @@ -534,7 +534,7 @@ fn should_transfer_token_in_hash_identifier_mode() { .ownership_mode(OwnershipMode::Transferable) .metadata_mutability(MetadataMutability::Immutable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); let new_owner = env.get_account(1); @@ -556,13 +556,13 @@ fn should_transfer_token_in_hash_identifier_mode() { #[test] fn should_not_allow_non_approved_contract_to_transfer() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let args = default_args_builder() .owner_reverse_lookup_mode(OwnerReverseLookupMode::Complete) .holder_mode(NFTHolderMode::Mixed) .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); @@ -599,7 +599,7 @@ fn transfer_should_correctly_track_page_table_entries() { .nft_metadata_kind(NFTMetadataKind::Raw) .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); let new_owner = env.get_account(1); @@ -627,7 +627,7 @@ fn should_prevent_transfer_to_unregistered_owner() { .identifier_mode(NFTIdentifierMode::Ordinal) .metadata_mutability(MetadataMutability::Immutable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint(token_owner, "".to_string(), Maybe::None); @@ -652,7 +652,7 @@ fn should_transfer_token_from_sender_to_receiver_with_transfer_only_reporting() .owner_reverse_lookup_mode(OwnerReverseLookupMode::TransfersOnly) .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); env.set_caller(token_owner); @@ -693,7 +693,7 @@ fn disallow_owner_to_approve_itself() { let args = default_args_builder() .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint( @@ -714,7 +714,7 @@ fn disallow_operator_to_approve_itself() { let args = default_args_builder() .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint( @@ -740,7 +740,7 @@ fn disallow_owner_to_approve_for_all_itself() { let args = default_args_builder() .ownership_mode(OwnershipMode::Transferable) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint( @@ -759,13 +759,13 @@ fn disallow_owner_to_approve_for_all_itself() { fn check_transfers_with_transfer_filter_contract_modes() { let env = odra_test::env(); - let mut transfer_filter_contract = MockCep78TransferFilterHostRef::deploy(&env, NoArgs); + let mut transfer_filter_contract = MockCep78TransferFilter::deploy(&env, NoArgs); transfer_filter_contract.set_return_value(TransferFilterContractResult::DenyTransfer as u8); let args = default_args_builder() .ownership_mode(OwnershipMode::Transferable) .transfer_filter_contract_contract_key(*transfer_filter_contract.address()) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint( @@ -832,12 +832,12 @@ fn check_transfers_with_transfer_filter_contract_modes() { #[test] fn should_disallow_transfer_from_contract_with_package_operator_mode_without_operator() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let args = default_args_builder() .ownership_mode(OwnershipMode::Transferable) .holder_mode(NFTHolderMode::Mixed) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); @@ -865,12 +865,12 @@ fn should_disallow_transfer_from_contract_without_package_operator_mode_with_pac #[test] fn should_allow_transfer_from_contract_with_package_operator_mode_with_operator() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let args = default_args_builder() .ownership_mode(OwnershipMode::Transferable) .holder_mode(NFTHolderMode::Mixed) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); @@ -900,12 +900,12 @@ fn should_disallow_package_operator_to_approve_without_package_operator_mode() { #[test] fn should_allow_package_operator_to_approve_with_package_operator_mode() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let args = default_args_builder() .ownership_mode(OwnershipMode::Transferable) .holder_mode(NFTHolderMode::Mixed) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); @@ -938,12 +938,12 @@ fn should_allow_package_operator_to_approve_with_package_operator_mode() { #[test] fn should_allow_account_to_approve_spender_with_package_operator() { let env = odra_test::env(); - let minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let minting_contract = MockCep78Operator::deploy(&env, NoArgs); let args = default_args_builder() .ownership_mode(OwnershipMode::Transferable) .holder_mode(NFTHolderMode::Mixed) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); contract.mint( @@ -975,12 +975,12 @@ fn should_allow_account_to_approve_spender_with_package_operator() { #[test] fn should_allow_package_operator_to_revoke_with_package_operator_mode() { let env = odra_test::env(); - let mut minting_contract = MockCep78OperatorHostRef::deploy(&env, NoArgs); + let mut minting_contract = MockCep78Operator::deploy(&env, NoArgs); let args = default_args_builder() .ownership_mode(OwnershipMode::Transferable) .holder_mode(NFTHolderMode::Mixed) .build(); - let mut contract = TestCep78HostRef::deploy(&env, args); + let mut contract = TestCep78::deploy(&env, args); minting_contract.set_address(contract.address()); let token_owner = env.get_account(0); contract.register_owner(Maybe::Some(token_owner)); diff --git a/modules/src/cep78/tests/utils.rs b/modules/src/cep78/tests/utils.rs index f9a8c319..c88991e7 100644 --- a/modules/src/cep78/tests/utils.rs +++ b/modules/src/cep78/tests/utils.rs @@ -48,12 +48,12 @@ pub(crate) fn create_blake2b_hash>(data: T) -> [u8; BLAKE2B_DIGES pub(crate) fn get_gas_cost_of(env: &HostEnv, entry_point: &str) -> Vec { let gas_report = env.gas_report(); gas_report - .into_iter() + .iter() .filter_map(|r| match r { DeployReport::WasmDeploy { .. } => None, DeployReport::ContractCall { gas, call_def, .. } => { if call_def.entry_point() == entry_point { - Some(gas) + Some(*gas) } else { None } @@ -65,9 +65,9 @@ pub(crate) fn get_gas_cost_of(env: &HostEnv, entry_point: &str) -> Vec { pub(crate) fn get_deploy_gas_cost(env: &HostEnv) -> Vec { let gas_report = env.gas_report(); gas_report - .into_iter() + .iter() .filter_map(|r| match r { - DeployReport::WasmDeploy { gas, .. } => Some(gas), + DeployReport::WasmDeploy { gas, .. } => Some(*gas), DeployReport::ContractCall { .. } => None }) .collect::>() diff --git a/modules/src/cep78/utils.rs b/modules/src/cep78/utils.rs index eaf44dee..2c941d7a 100644 --- a/modules/src/cep78/utils.rs +++ b/modules/src/cep78/utils.rs @@ -33,7 +33,7 @@ pub fn max_number_of_pages(total_token_supply: u64) -> u64 { } #[odra::module] -struct MockDummyContract; +pub struct MockDummyContract; #[odra::module] impl MockDummyContract {} @@ -55,7 +55,7 @@ impl MockCep78TransferFilter { } #[odra::module] -struct MockCep78Operator { +pub struct MockCep78Operator { nft_contract: External } diff --git a/modules/src/erc1155_token.rs b/modules/src/erc1155_token.rs index 72351be1..97efd609 100644 --- a/modules/src/erc1155_token.rs +++ b/modules/src/erc1155_token.rs @@ -186,9 +186,9 @@ mod tests { use crate::erc1155::events::{ApprovalForAll, TransferBatch, TransferSingle}; use crate::erc1155::owned_erc1155::OwnedErc1155; use crate::erc1155_receiver::events::{BatchReceived, SingleReceived}; - use crate::erc1155_receiver::Erc1155ReceiverHostRef; + use crate::erc1155_receiver::Erc1155Receiver; use crate::erc1155_token::Erc1155TokenHostRef; - use crate::wrapped_native::WrappedNativeTokenHostRef; + use crate::wrapped_native::WrappedNativeToken; use odra::host::{Deployer, HostEnv, HostRef, NoArgs}; use odra::prelude::*; use odra::{ @@ -196,6 +196,8 @@ mod tests { Address, OdraError, VmError }; + use super::Erc1155Token; + struct TokenEnv { env: HostEnv, token: Erc1155TokenHostRef, @@ -209,7 +211,7 @@ mod tests { TokenEnv { env: env.clone(), - token: Erc1155TokenHostRef::deploy(&env, NoArgs), + token: Erc1155Token::deploy(&env, NoArgs), alice: env.get_account(1), bob: env.get_account(2), owner: env.get_account(0) @@ -824,7 +826,7 @@ mod tests { let mut env = setup(); // And a valid receiver - let receiver = Erc1155ReceiverHostRef::deploy(&env.env, NoArgs); + let receiver = Erc1155Receiver::deploy(&env.env, NoArgs); // And some tokens minted env.token.mint(&env.alice, &U256::one(), &100.into(), &None); @@ -863,7 +865,7 @@ mod tests { // Given a deployed contract let mut env = setup(); // And a valid receiver - let receiver = Erc1155ReceiverHostRef::deploy(&env.env, NoArgs); + let receiver = Erc1155Receiver::deploy(&env.env, NoArgs); // And some tokens minted env.token.mint(&env.alice, &U256::one(), &100.into(), &None); @@ -902,7 +904,7 @@ mod tests { // Given a deployed contract let mut env = setup(); // And an invalid receiver - let receiver = WrappedNativeTokenHostRef::deploy(&env.env, NoArgs); + let receiver = WrappedNativeToken::deploy(&env.env, NoArgs); // And some tokens minted env.token.mint(&env.alice, &U256::one(), &100.into(), &None); @@ -929,7 +931,7 @@ mod tests { // Given a deployed contract let mut env = setup(); // And a valid receiver - let receiver = Erc1155ReceiverHostRef::deploy(&env.env, NoArgs); + let receiver = Erc1155Receiver::deploy(&env.env, NoArgs); // And some tokens minted env.token.mint(&env.alice, &U256::one(), &100.into(), &None); env.token @@ -975,7 +977,7 @@ mod tests { // Given a deployed contract let mut env = setup(); // And a valid receiver - let receiver = Erc1155ReceiverHostRef::deploy(&env.env, NoArgs); + let receiver = Erc1155Receiver::deploy(&env.env, NoArgs); // And some tokens minted env.token.mint(&env.alice, &U256::one(), &100.into(), &None); env.token @@ -1021,7 +1023,7 @@ mod tests { // Given a deployed contract let mut env = setup(); // And an invalid receiver - let receiver = WrappedNativeTokenHostRef::deploy(&env.env, NoArgs); + let receiver = WrappedNativeToken::deploy(&env.env, NoArgs); // And some tokens minted env.token.mint(&env.alice, &U256::one(), &100.into(), &None); env.token diff --git a/modules/src/erc20.rs b/modules/src/erc20.rs index 3f942925..b000ec77 100644 --- a/modules/src/erc20.rs +++ b/modules/src/erc20.rs @@ -210,7 +210,7 @@ mod tests { use super::{ errors::Error, events::{Approval, Transfer}, - Erc20HostRef, Erc20InitArgs + Erc20, Erc20HostRef, Erc20InitArgs }; use odra::{ casper_types::U256, @@ -227,7 +227,7 @@ mod tests { let env = odra_test::env(); ( env.clone(), - Erc20HostRef::deploy( + Erc20::deploy( &env, Erc20InitArgs { symbol: SYMBOL.to_string(), diff --git a/modules/src/erc721_token.rs b/modules/src/erc721_token.rs index 577677d0..60a8eaa1 100644 --- a/modules/src/erc721_token.rs +++ b/modules/src/erc721_token.rs @@ -139,13 +139,13 @@ pub mod errors { #[cfg(test)] mod tests { - use super::{Erc721TokenHostRef, Erc721TokenInitArgs}; + use super::{Erc721Token, Erc721TokenHostRef, Erc721TokenInitArgs}; use crate::access::errors::Error as AccessError; - use crate::erc20::{Erc20HostRef, Erc20InitArgs}; + use crate::erc20::{Erc20, Erc20InitArgs}; use crate::erc721::errors::Error::{InvalidTokenId, NotAnOwnerOrApproved}; use crate::erc721::owned_erc721_with_metadata::OwnedErc721WithMetadata; use crate::erc721_receiver::events::Received; - use crate::erc721_receiver::Erc721ReceiverHostRef; + use crate::erc721_receiver::Erc721Receiver; use crate::erc721_token::errors::Error::TokenAlreadyExists; use odra::host::{Deployer, HostEnv, HostRef, NoArgs}; use odra::prelude::*; @@ -166,7 +166,7 @@ mod tests { let env = odra_test::env(); TokenEnv { env: env.clone(), - token: Erc721TokenHostRef::deploy( + token: Erc721Token::deploy( &env, Erc721TokenInitArgs { name: NAME.to_string(), @@ -501,7 +501,7 @@ mod tests { // When deploy a contract with the initial supply let mut erc721_env = setup(); // And another contract which does not support nfts - let erc20 = Erc20HostRef::deploy( + let erc20 = Erc20::deploy( &erc721_env.env, Erc20InitArgs { name: "PLASCOIN".to_string(), @@ -534,7 +534,7 @@ mod tests { // When deploy a contract with the initial supply let mut erc721_env = setup(); // And another contract which does not support nfts - let receiver = Erc721ReceiverHostRef::deploy(&erc721_env.env, NoArgs); + let receiver = Erc721Receiver::deploy(&erc721_env.env, NoArgs); // And mint a token to Alice. erc721_env.token.mint(&erc721_env.alice, &U256::from(1)); @@ -567,7 +567,7 @@ mod tests { // When deploy a contract with the initial supply let mut erc721_env = setup(); // And another contract which does not support nfts - let receiver = Erc721ReceiverHostRef::deploy(&erc721_env.env, NoArgs); + let receiver = Erc721Receiver::deploy(&erc721_env.env, NoArgs); // And mint a token to Alice. erc721_env.token.mint(&erc721_env.alice, &U256::from(1)); diff --git a/modules/src/wrapped_native.rs b/modules/src/wrapped_native.rs index 0ae0d838..1e8d1600 100644 --- a/modules/src/wrapped_native.rs +++ b/modules/src/wrapped_native.rs @@ -136,6 +136,8 @@ mod tests { Address, OdraError }; + use super::WrappedNativeToken; + fn setup() -> ( HostEnv, WrappedNativeTokenHostRef, @@ -145,7 +147,7 @@ mod tests { U512 ) { let env = odra_test::env(); - let token = WrappedNativeTokenHostRef::deploy(&env, NoArgs); + let token = WrappedNativeToken::deploy(&env, NoArgs); let account_1 = env.get_account(0); let account_1_balance = env.balance_of(&account_1); let account_2 = env.get_account(1); diff --git a/odra-casper/proxy-caller/Cargo.toml b/odra-casper/proxy-caller/Cargo.toml index 9952dedb..368bf597 100644 --- a/odra-casper/proxy-caller/Cargo.toml +++ b/odra-casper/proxy-caller/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "odra-casper-proxy-caller" edition = "2021" -version = "1.2.0" +version = "1.3.0" authors = ["Jakub Płaskonka ", "Krzysztof Pobiarżyn ", "Maciej Zieliński "] license = "MIT" homepage = "https://odra.dev/docs" diff --git a/odra-casper/rpc-client/src/casper_client/error.rs b/odra-casper/rpc-client/src/casper_client/error.rs index 3d0d708e..84f4a5a2 100644 --- a/odra-casper/rpc-client/src/casper_client/error.rs +++ b/odra-casper/rpc-client/src/casper_client/error.rs @@ -97,6 +97,7 @@ fn get_internal_error_name(error_num: u16) -> (String, OdraError) { ExecutionError::CouldNotSignMessage, ExecutionError::EmptyDictionaryName, ExecutionError::MissingArg, + ExecutionError::MissingAddress, ExecutionError::OutOfGas, ExecutionError::MaxUserError, ExecutionError::UserErrorTooHigh @@ -128,10 +129,10 @@ mod test { )) ); assert_eq!( - call("User error: 64657").ok(), + call("User error: 64659").ok(), Some(( - "ExecutionError::EmptyDictionaryName".to_string(), - ExecutionError::EmptyDictionaryName.into() + "ExecutionError::MissingAddress".to_string(), + ExecutionError::MissingAddress.into() )) ); // Unknown user error diff --git a/odra-macros/src/ast/contract_item.rs b/odra-macros/src/ast/contract_item.rs new file mode 100644 index 00000000..5a7207f6 --- /dev/null +++ b/odra-macros/src/ast/contract_item.rs @@ -0,0 +1,65 @@ +use proc_macro2::TokenStream; +use syn::parse_quote; +use crate::ModuleImplIR; + +#[derive(syn_derive::ToTokens)] +pub struct ContractItem { + code: TokenStream +} + +impl TryFrom<&'_ ModuleImplIR> for ContractItem { + type Error = syn::Error; + + fn try_from(module: &'_ ModuleImplIR) -> Result { + let module_ident = module.module_ident()?; + let host_ref = module.host_ref_ident()?; + + let contract_ref = module.contract_ref_ident()?; + let has_constructor_args = module.constructor().map(|c| c.has_args()).unwrap_or_default(); + let init_args: syn::Path = match has_constructor_args { + true => module.init_args_ident()?.into(), + false => parse_quote!(odra::host::NoArgs) + }; + + Ok(Self { + code: quote::quote! { + impl odra::OdraContract for #module_ident { + #[cfg(not(target_arch = "wasm32"))] + type HostRef = #host_ref; + + type ContractRef = #contract_ref; + + #[cfg(not(target_arch = "wasm32"))] + type InitArgs = #init_args; + } + } + }) + } +} + + +#[cfg(test)] +mod test { + use super::*; + use crate::test_utils; + + #[test] + fn test_contract_item() { + let module = test_utils::mock::module_impl(); + + let item = ContractItem::try_from(&module).unwrap(); + + let expected = quote::quote! { + impl odra::OdraContract for Erc20 { + #[cfg(not(target_arch = "wasm32"))] + type HostRef = Erc20HostRef; + + type ContractRef = Erc20ContractRef; + + #[cfg(not(target_arch = "wasm32"))] + type InitArgs = Erc20InitArgs; + } + }; + test_utils::assert_eq(item, expected); + } +} \ No newline at end of file diff --git a/odra-macros/src/ast/deployer_item.rs b/odra-macros/src/ast/deployer_item.rs index 3ebd1792..dca359b2 100644 --- a/odra-macros/src/ast/deployer_item.rs +++ b/odra-macros/src/ast/deployer_item.rs @@ -1,14 +1,12 @@ +#![allow(unused_variables)] + use crate::{ ir::ModuleImplIR, - utils::{self, misc::AsBlock} + utils }; use derive_try_from_ref::TryFromRef; -use syn::parse_quote; -use super::{ - deployer_utils::{EntrypointCallerExpr, EntrypointsInitExpr, EpcSignature}, - fn_utils::FnItem -}; +use super::deployer_utils::{EntrypointCallerExpr, EntrypointsInitExpr, EpcSignature}; #[derive(syn_derive::ToTokens)] struct DeployImplItem { @@ -124,32 +122,18 @@ struct InitArgsImplItem { ident: syn::Ident, #[syn(braced)] brace_token: syn::token::Brace, - #[syn(in = brace_token)] - validate_fn: FnItem } impl TryFrom<&'_ ModuleImplIR> for InitArgsImplItem { type Error = syn::Error; fn try_from(module: &'_ ModuleImplIR) -> Result { - let module_str = module.module_str()?; - let ident_validate = utils::ident::validate(); - let ident_expected_ident = utils::ident::expected_ident(); - let ty_string = utils::ty::string_ref(); - let validate_expr: syn::Expr = parse_quote!(#module_str == expected_ident); - Ok(Self { impl_token: Default::default(), trait_ty: utils::ty::init_args(), for_token: Default::default(), ident: module.init_args_ident()?, brace_token: Default::default(), - validate_fn: FnItem::new( - &ident_validate, - vec![parse_quote!(#ident_expected_ident: #ty_string)], - parse_quote!(-> bool), - validate_expr.as_block() - ) }) } } @@ -199,9 +183,6 @@ mod deployer_impl { } impl odra::host::InitArgs for Erc20InitArgs { - fn validate(expected_ident: &str) -> bool { - "Erc20" == expected_ident - } } impl odra::host::EntryPointsCallerProvider for Erc20HostRef { diff --git a/odra-macros/src/ast/mod.rs b/odra-macros/src/ast/mod.rs index 491f4bfd..ec7862ec 100644 --- a/odra-macros/src/ast/mod.rs +++ b/odra-macros/src/ast/mod.rs @@ -23,6 +23,7 @@ mod test_parts; mod utils; mod wasm_parts; mod wasm_parts_utils; +mod contract_item; pub(crate) use error_item::OdraErrorAttrItem; pub(crate) use external_contract_item::ExternalContractImpl; diff --git a/odra-macros/src/ast/module_impl_item.rs b/odra-macros/src/ast/module_impl_item.rs index 1418d0e2..ffbedf43 100644 --- a/odra-macros/src/ast/module_impl_item.rs +++ b/odra-macros/src/ast/module_impl_item.rs @@ -1,5 +1,6 @@ use crate::ast::blueprint::BlueprintItem; use crate::ast::contract_ref_item::RefItem; +use crate::ast::contract_item::ContractItem; use crate::ast::entrypoints_item::HasEntrypointsImplItem; use crate::ast::exec_parts::ExecPartsItem; use crate::ast::schema::{SchemaCustomTypesItem, SchemaEntrypointsItem}; @@ -8,6 +9,7 @@ use crate::ast::wasm_parts::WasmPartsModuleItem; use crate::ir::ModuleImplIR; use derive_try_from_ref::TryFromRef; + #[derive(syn_derive::ToTokens, TryFromRef)] #[source(ModuleImplIR)] #[err(syn::Error)] @@ -20,7 +22,9 @@ pub struct ModuleImplItem { test_parts_reexport: TestPartsReexportItem, exec_parts: ExecPartsItem, wasm_parts: WasmPartsModuleItem, + contract_item: ContractItem, blueprint: BlueprintItem, schema_entrypoints: SchemaEntrypointsItem, schema_custom_types: SchemaCustomTypesItem } + diff --git a/odra-macros/src/ast/test_parts.rs b/odra-macros/src/ast/test_parts.rs index 91038bbb..2b57928e 100644 --- a/odra-macros/src/ast/test_parts.rs +++ b/odra-macros/src/ast/test_parts.rs @@ -280,9 +280,6 @@ mod test { } impl odra::host::InitArgs for Erc20InitArgs { - fn validate(expected_ident: &str) -> bool { - "Erc20" == expected_ident - } } impl odra::host::EntryPointsCallerProvider for Erc20HostRef { diff --git a/odra-macros/src/utils/ident.rs b/odra-macros/src/utils/ident.rs index 504845c3..5616dc71 100644 --- a/odra-macros/src/utils/ident.rs +++ b/odra-macros/src/utils/ident.rs @@ -110,11 +110,3 @@ pub fn from() -> syn::Ident { pub fn error() -> syn::Ident { format_ident!("error") } - -pub fn expected_ident() -> syn::Ident { - format_ident!("expected_ident") -} - -pub fn validate() -> syn::Ident { - format_ident!("validate") -} diff --git a/odra-macros/src/utils/ty.rs b/odra-macros/src/utils/ty.rs index 46f2d2ae..8d5a6e7f 100644 --- a/odra-macros/src/utils/ty.rs +++ b/odra-macros/src/utils/ty.rs @@ -168,10 +168,6 @@ pub fn string() -> syn::Type { parse_quote!(odra::prelude::string::String) } -pub fn string_ref() -> syn::Type { - parse_quote!(&str) -} - pub fn result(ty: &syn::Type, err_ty: &syn::Type) -> syn::Type { parse_quote!(Result<#ty, #err_ty>) } diff --git a/odra/src/lib.rs b/odra/src/lib.rs index da4c4004..13effed3 100644 --- a/odra/src/lib.rs +++ b/odra/src/lib.rs @@ -51,8 +51,8 @@ pub use odra_core::{casper_event_standard, casper_event_standard::Event, casper_ pub use odra_core::{ Address, AddressError, Addressable, CallDef, CollectionError, ContractCallResult, ContractContext, ContractEnv, ContractRef, DeployReport, EventError, ExecutionEnv, - ExecutionError, External, GasReport, List, ListIter, Mapping, OdraError, OdraResult, Sequence, - SubModule, UnwrapOrRevert, Var, VmError + ExecutionError, External, GasReport, List, ListIter, Mapping, OdraContract, OdraError, + OdraResult, Sequence, SubModule, UnwrapOrRevert, Var, VmError }; pub use odra_macros::*; diff --git a/templates/cep18.rs.template b/templates/cep18.rs.template index 83b94b58..6f6bf893 100644 --- a/templates/cep18.rs.template +++ b/templates/cep18.rs.template @@ -88,7 +88,7 @@ mod tests { fn it_works() { let env = odra_test::env(); // To test a module we need to deploy it. Autogenerated Autogenerated `#module_nameInitArgs` - // implements `InitArgs` trait and `#module_nameHostRef` implements `Deployer` trait, + // implements `InitArgs` trait and `#module_name` implements `Deployer` trait, // so we can use it to deploy the module. let init_args = #module_nameInitArgs { name: "#module_name".to_string(), @@ -96,6 +96,6 @@ mod tests { decimals: 10, initial_supply: U256::from(1_000_000_000_000u64), }; - assert!(#module_nameHostRef::try_deploy(&env, init_args).is_ok()); + assert!(#module_name::try_deploy(&env, init_args).is_ok()); } } diff --git a/templates/cep18/src/token.rs b/templates/cep18/src/token.rs index 75876fae..a967c843 100644 --- a/templates/cep18/src/token.rs +++ b/templates/cep18/src/token.rs @@ -89,7 +89,7 @@ mod tests { let env = odra_test::env(); // To test a module, we need to deploy it. // Autogenerated `MyTokenInitArgs` implements `InitArgs` trait - // and `MyTokenHostRef` implements `Deployer` trait, + // and `MyToken` implements `Deployer` trait, // so we can use it to deploy the module. let init_args = MyTokenInitArgs { name: "MyToken".to_string(), @@ -97,6 +97,6 @@ mod tests { decimals: 10, initial_supply: U256::from(1_000_000_000_000u64), }; - assert!(MyTokenHostRef::try_deploy(&env, init_args).is_ok()); + assert!(MyToken::try_deploy(&env, init_args).is_ok()); } } diff --git a/templates/cep78.rs.template b/templates/cep78.rs.template index a250cff2..3c568734 100644 --- a/templates/cep78.rs.template +++ b/templates/cep78.rs.template @@ -162,13 +162,13 @@ mod tests { fn it_works() { let env = odra_test::env(); // To test a module we need to deploy it. Autogenerated Autogenerated `#module_nameInitArgs` - // implements `InitArgs` trait and `#module_nameHostRef` implements `Deployer` trait, + // implements `InitArgs` trait and `#module_name` implements `Deployer` trait, // so we can use it to deploy the module. let init_args = #module_nameInitArgs { collection_name: "#module_name".to_string(), collection_symbol: "MT".to_string(), total_supply: 100, }; - assert!(#module_nameHostRef::try_deploy(&env, init_args).is_ok()); + assert!(#module_name::try_deploy(&env, init_args).is_ok()); } } diff --git a/templates/cep78/src/token.rs b/templates/cep78/src/token.rs index c03dab0c..7082aa62 100644 --- a/templates/cep78/src/token.rs +++ b/templates/cep78/src/token.rs @@ -161,14 +161,14 @@ mod tests { #[test] fn it_works() { let env = odra_test::env(); - // To test a module we need to deploy it. Autogenerated Autogenerated `MyTokenInitArgs` - // implements `InitArgs` trait and `MyTokenHostRef` implements `Deployer` trait, + // To test a module we need to deploy it. Autogenerated `MyTokenInitArgs` + // implements `InitArgs` trait and `MyToken` implements `Deployer` trait, // so we can use it to deploy the module. let init_args = MyTokenInitArgs { collection_name: "MyToken".to_string(), collection_symbol: "MT".to_string(), total_supply: 100, }; - assert!(MyTokenHostRef::try_deploy(&env, init_args).is_ok()); + assert!(MyToken::try_deploy(&env, init_args).is_ok()); } } diff --git a/templates/full/src/flipper.rs b/templates/full/src/flipper.rs index f97d875f..14af80c6 100644 --- a/templates/full/src/flipper.rs +++ b/templates/full/src/flipper.rs @@ -42,15 +42,15 @@ impl Flipper { #[cfg(test)] mod tests { - use crate::flipper::FlipperHostRef; + use crate::flipper::Flipper; use odra::host::{Deployer, NoArgs}; #[test] fn flipping() { let env = odra_test::env(); - // To test a module we need to deploy it. Autogenerated `FlipperHostRef` - // implements `Deployer` trait, so we can use it to deploy the module. - let mut contract = FlipperHostRef::deploy(&env, NoArgs); + // To test a module we need to deploy it. `Flipper` implements `Deployer` trait, + // so we can use it to deploy the module. + let mut contract = Flipper::deploy(&env, NoArgs); assert!(!contract.get()); contract.flip(); assert!(contract.get()); diff --git a/templates/workspace/flapper/src/flapper.rs b/templates/workspace/flapper/src/flapper.rs index ab029a5c..674cbd5a 100644 --- a/templates/workspace/flapper/src/flapper.rs +++ b/templates/workspace/flapper/src/flapper.rs @@ -42,15 +42,15 @@ impl Flapper { #[cfg(test)] mod tests { - use crate::flapper::FlapperHostRef; + use crate::flapper::Flapper; use odra::host::{Deployer, NoArgs}; #[test] fn flapping() { let env = odra_test::env(); - // To test a module we need to deploy it. Autogenerated `FlapperHostRef` - // implements `Deployer` trait, so we can use it to deploy the module. - let mut contract = FlapperHostRef::deploy(&env, NoArgs); + // To test a module we need to deploy it. `Flapper` implements `Deployer` trait, + // so we can use it to deploy the module. + let mut contract = Flapper::deploy(&env, NoArgs); assert!(!contract.get()); contract.flap(); assert!(contract.get()); diff --git a/templates/workspace/flipper/src/flipper.rs b/templates/workspace/flipper/src/flipper.rs index f97d875f..14af80c6 100644 --- a/templates/workspace/flipper/src/flipper.rs +++ b/templates/workspace/flipper/src/flipper.rs @@ -42,15 +42,15 @@ impl Flipper { #[cfg(test)] mod tests { - use crate::flipper::FlipperHostRef; + use crate::flipper::Flipper; use odra::host::{Deployer, NoArgs}; #[test] fn flipping() { let env = odra_test::env(); - // To test a module we need to deploy it. Autogenerated `FlipperHostRef` - // implements `Deployer` trait, so we can use it to deploy the module. - let mut contract = FlipperHostRef::deploy(&env, NoArgs); + // To test a module we need to deploy it. `Flipper` implements `Deployer` trait, + // so we can use it to deploy the module. + let mut contract = Flipper::deploy(&env, NoArgs); assert!(!contract.get()); contract.flip(); assert!(contract.get());