From c924c4986ac6516acdfcb195eed7c18e70490d5f Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Wed, 27 Mar 2024 18:58:21 +0100 Subject: [PATCH 1/3] encode error from basic features migration to new proxy and unified syntax --- .../basic-features/src/basic_features_main.rs | 1 + .../basic-features/src/codec_err_test.rs | 30 ++---- .../basic-features/src/encode_error_proxy.rs | 100 ++++++++++++++++++ 3 files changed, 109 insertions(+), 22 deletions(-) create mode 100644 contracts/feature-tests/basic-features/src/encode_error_proxy.rs diff --git a/contracts/feature-tests/basic-features/src/basic_features_main.rs b/contracts/feature-tests/basic-features/src/basic_features_main.rs index 2be5e1a535..1d3485b3f1 100644 --- a/contracts/feature-tests/basic-features/src/basic_features_main.rs +++ b/contracts/feature-tests/basic-features/src/basic_features_main.rs @@ -12,6 +12,7 @@ pub mod crypto_features; pub mod echo; pub mod echo_managed; pub mod elliptic_curve_features; +pub mod encode_error_proxy; pub mod event_features; pub mod macro_features; pub mod managed_address_features; diff --git a/contracts/feature-tests/basic-features/src/codec_err_test.rs b/contracts/feature-tests/basic-features/src/codec_err_test.rs index 4fa4da2258..e72f71b44b 100644 --- a/contracts/feature-tests/basic-features/src/codec_err_test.rs +++ b/contracts/feature-tests/basic-features/src/codec_err_test.rs @@ -1,19 +1,5 @@ multiversx_sc::imports!(); -use crate::types::CodecErrorTestType; - -mod encode_err_proxy { - multiversx_sc::imports!(); - use crate::types::CodecErrorTestType; - - #[multiversx_sc::proxy] - pub trait EncodeErrorProxy { - #[init] - fn init(&self, error_arg: CodecErrorTestType); - - #[endpoint] - fn encode_error_method(&self, error_arg: CodecErrorTestType); - } -} +use crate::{encode_error_proxy, types::CodecErrorTestType}; /// Test various serialization errors. #[multiversx_sc::module] @@ -62,15 +48,14 @@ pub trait CodecErrorTest { fn codec_err_event_data(&self) { self.event_err_data(CodecErrorTestType); } - - #[proxy] - fn encode_err_proxy(&self) -> encode_err_proxy::Proxy; - /// Never actually calls any deploy/upgrade, so it is appropriate in this contract. /// It just covers contract init serialization errors. #[endpoint] fn codec_err_contract_init(&self) { - let _ = self.encode_err_proxy().init(CodecErrorTestType); + let _ = self + .tx() + .typed(encode_error_proxy::EncodeErrorProxy) + .init(CodecErrorTestType); } /// Never actually calls any async/sync call, so it is appropriate in this contract. @@ -78,8 +63,9 @@ pub trait CodecErrorTest { #[endpoint] fn codec_err_contract_call(&self) { let _ = self - .encode_err_proxy() - .contract(ManagedAddress::zero()) + .tx() + .to(&ManagedAddress::zero()) + .typed(encode_error_proxy::EncodeErrorProxy) .encode_error_method(CodecErrorTestType); } } diff --git a/contracts/feature-tests/basic-features/src/encode_error_proxy.rs b/contracts/feature-tests/basic-features/src/encode_error_proxy.rs new file mode 100644 index 0000000000..eee70b6ae2 --- /dev/null +++ b/contracts/feature-tests/basic-features/src/encode_error_proxy.rs @@ -0,0 +1,100 @@ +// Code generated by the multiversx-sc proxy generator. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +#![allow(dead_code)] +#![allow(clippy::all)] + +use multiversx_sc::proxy_imports::*; + +use crate::types::CodecErrorTestType; + +pub struct EncodeErrorProxy; + +impl TxProxyTrait for EncodeErrorProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = EncodeErrorProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + EncodeErrorProxyMethods { wrapped_tx: tx } + } +} + +pub struct EncodeErrorProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +#[rustfmt::skip] +impl EncodeErrorProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + Gas: TxGas, +{ + pub fn init< + Arg0: CodecInto, + >( + self, + error_arg: Arg0, + ) -> TxProxyDeploy { + self.wrapped_tx + .raw_deploy() + .argument(&error_arg) + .original_result() + } +} + +#[rustfmt::skip] +impl EncodeErrorProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn upgrade( + self, + ) -> TxProxyUpgrade { + self.wrapped_tx + .raw_upgrade() + .original_result() + } +} + +#[rustfmt::skip] +impl EncodeErrorProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn encode_error_method< + Arg0: CodecInto, + >( + self, + error_arg: Arg0, + ) -> TxProxyCall { + self.wrapped_tx + .raw_call() + .function_name("encode_error_method") + .argument(&error_arg) + .original_result() + } +} From 25fd2ae97196b84305a870b1ff38738df3decb61 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Thu, 28 Mar 2024 17:12:37 +0100 Subject: [PATCH 2/3] removed encode error proxy --- .../basic-features/src/basic_features_main.rs | 1 - .../basic-features/src/codec_err_test.rs | 13 +-- .../basic-features/src/encode_error_proxy.rs | 100 ------------------ 3 files changed, 3 insertions(+), 111 deletions(-) delete mode 100644 contracts/feature-tests/basic-features/src/encode_error_proxy.rs diff --git a/contracts/feature-tests/basic-features/src/basic_features_main.rs b/contracts/feature-tests/basic-features/src/basic_features_main.rs index 1d3485b3f1..2be5e1a535 100644 --- a/contracts/feature-tests/basic-features/src/basic_features_main.rs +++ b/contracts/feature-tests/basic-features/src/basic_features_main.rs @@ -12,7 +12,6 @@ pub mod crypto_features; pub mod echo; pub mod echo_managed; pub mod elliptic_curve_features; -pub mod encode_error_proxy; pub mod event_features; pub mod macro_features; pub mod managed_address_features; diff --git a/contracts/feature-tests/basic-features/src/codec_err_test.rs b/contracts/feature-tests/basic-features/src/codec_err_test.rs index e72f71b44b..1e2a2d4719 100644 --- a/contracts/feature-tests/basic-features/src/codec_err_test.rs +++ b/contracts/feature-tests/basic-features/src/codec_err_test.rs @@ -1,5 +1,5 @@ multiversx_sc::imports!(); -use crate::{encode_error_proxy, types::CodecErrorTestType}; +use crate::types::CodecErrorTestType; /// Test various serialization errors. #[multiversx_sc::module] @@ -52,20 +52,13 @@ pub trait CodecErrorTest { /// It just covers contract init serialization errors. #[endpoint] fn codec_err_contract_init(&self) { - let _ = self - .tx() - .typed(encode_error_proxy::EncodeErrorProxy) - .init(CodecErrorTestType); + let _ = self.tx().raw_call().argument(&CodecErrorTestType); } /// Never actually calls any async/sync call, so it is appropriate in this contract. /// It just covers contract call serialization errors. #[endpoint] fn codec_err_contract_call(&self) { - let _ = self - .tx() - .to(&ManagedAddress::zero()) - .typed(encode_error_proxy::EncodeErrorProxy) - .encode_error_method(CodecErrorTestType); + let _ = self.tx().raw_call().argument(&CodecErrorTestType); } } diff --git a/contracts/feature-tests/basic-features/src/encode_error_proxy.rs b/contracts/feature-tests/basic-features/src/encode_error_proxy.rs deleted file mode 100644 index eee70b6ae2..0000000000 --- a/contracts/feature-tests/basic-features/src/encode_error_proxy.rs +++ /dev/null @@ -1,100 +0,0 @@ -// Code generated by the multiversx-sc proxy generator. DO NOT EDIT. - -//////////////////////////////////////////////////// -////////////////// AUTO-GENERATED ////////////////// -//////////////////////////////////////////////////// - -#![allow(dead_code)] -#![allow(clippy::all)] - -use multiversx_sc::proxy_imports::*; - -use crate::types::CodecErrorTestType; - -pub struct EncodeErrorProxy; - -impl TxProxyTrait for EncodeErrorProxy -where - Env: TxEnv, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - type TxProxyMethods = EncodeErrorProxyMethods; - - fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { - EncodeErrorProxyMethods { wrapped_tx: tx } - } -} - -pub struct EncodeErrorProxyMethods -where - Env: TxEnv, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - wrapped_tx: Tx, -} - -#[rustfmt::skip] -impl EncodeErrorProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - Gas: TxGas, -{ - pub fn init< - Arg0: CodecInto, - >( - self, - error_arg: Arg0, - ) -> TxProxyDeploy { - self.wrapped_tx - .raw_deploy() - .argument(&error_arg) - .original_result() - } -} - -#[rustfmt::skip] -impl EncodeErrorProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - pub fn upgrade( - self, - ) -> TxProxyUpgrade { - self.wrapped_tx - .raw_upgrade() - .original_result() - } -} - -#[rustfmt::skip] -impl EncodeErrorProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - pub fn encode_error_method< - Arg0: CodecInto, - >( - self, - error_arg: Arg0, - ) -> TxProxyCall { - self.wrapped_tx - .raw_call() - .function_name("encode_error_method") - .argument(&error_arg) - .original_result() - } -} From a320dca1e2345f1d90d2f92b4f870c2916c6b23a Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Thu, 28 Mar 2024 18:50:53 +0100 Subject: [PATCH 3/3] fix after review --- contracts/feature-tests/basic-features/src/codec_err_test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/feature-tests/basic-features/src/codec_err_test.rs b/contracts/feature-tests/basic-features/src/codec_err_test.rs index 1e2a2d4719..cbe8f470b5 100644 --- a/contracts/feature-tests/basic-features/src/codec_err_test.rs +++ b/contracts/feature-tests/basic-features/src/codec_err_test.rs @@ -52,7 +52,7 @@ pub trait CodecErrorTest { /// It just covers contract init serialization errors. #[endpoint] fn codec_err_contract_init(&self) { - let _ = self.tx().raw_call().argument(&CodecErrorTestType); + let _ = self.tx().raw_deploy().argument(&CodecErrorTestType); } /// Never actually calls any async/sync call, so it is appropriate in this contract.