From be322d6d7401b6d294123edb08a757e26d8df479 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Thu, 26 Jan 2023 13:50:08 +0000 Subject: [PATCH 01/24] `[ink_e2e]` expose call dry-run method --- crates/e2e/src/client.rs | 145 +++++++++++++++++++++++++++++---------- examples/flipper/lib.rs | 15 ++-- 2 files changed, 113 insertions(+), 47 deletions(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index 5dd976b191..a108b43d5b 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -39,6 +39,7 @@ use sp_runtime::traits::{ use std::{ collections::BTreeMap, fmt::Debug, + marker::PhantomData, path::Path, }; use subxt::{ @@ -120,39 +121,23 @@ where pub struct CallResult { /// The result of the dry run, contains debug messages /// if there were any. - pub dry_run: ContractExecResult, + pub dry_run: CallDryRunResult, /// Events that happened with the contract instantiation. pub events: ExtrinsicEvents, - /// Contains the result of decoding the return value of the called - /// function. - pub value: Result, scale::Error>, - /// Returns the bytes of the encoded dry-run return value. - pub data: Vec, } impl CallResult where C: subxt::Config, E: Environment, + V: scale::Decode, { /// Returns the decoded return value of the message from the dry-run. /// /// Panics if the value could not be decoded. The raw bytes can be accessed /// via [`return_data`]. pub fn return_value(self) -> V { - self.value - .unwrap_or_else(|env_err| { - panic!( - "Decoding dry run result to ink! message return type failed: {}", - env_err - ) - }) - .unwrap_or_else(|lang_err| { - panic!( - "Encountered a `LangError` while decoding dry run result to ink! message: {:?}", - lang_err - ) - }) + self.dry_run.return_value() } /// Returns true if the specified event was triggered by the call. @@ -175,12 +160,74 @@ where { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { f.debug_struct("CallResult") - .field("dry_run", &self.dry_run) + .field("dry_run", &self.dry_run.exec_result) .field("events", &self.events) .finish() } } +/// Result of the dry run of a contract call. +pub struct CallDryRunResult { + /// The result of the dry run, contains debug messages + /// if there were any. + exec_result: ContractExecResult, + _marker: PhantomData, +} + +impl CallDryRunResult +where + E: Environment, + V: scale::Decode, +{ + /// Returns the [`ExecReturnValue`] resulting from the dry-run message call. + /// + /// Panics if the dry-run message call failed to execute. + pub fn exec_return_value(&self) -> &pallet_contracts_primitives::ExecReturnValue { + self.exec_result + .result + .as_ref() + .unwrap_or_else(|call_err| panic!("Call dry-run failed: {:?}", call_err)) + } + + /// Returns the [`MessageResult`] from the execution of the dry-run message + /// call. + /// + /// # Panics + /// - if the dry-run message call failed to execute. + /// - if message result cannot be decoded into the expected return value + /// type. + pub fn message_result(&self) -> MessageResult { + let data = &self.exec_return_value().data; + scale::Decode::decode(&mut data.as_ref()).unwrap_or_else(|env_err| { + panic!( + "Decoding dry run result to ink! message return type failed: {}", + env_err + ) + }) + } + + /// Returns the decoded return value of the message from the dry-run. + /// + /// Panics if the dry-run message call failed to execute. + pub fn return_data(&self) -> &[u8] { + &self.exec_return_value().data + } + + /// Returns the decoded return value of the message from the dry-run. + /// + /// Panics if the value could not be decoded. The raw bytes can be accessed + /// via [`return_data`]. + pub fn return_value(self) -> V { + self.message_result() + .unwrap_or_else(|lang_err| { + panic!( + "Encountered a `LangError` while decoding dry run result to ink! message: {:?}", + lang_err + ) + }) + } +} + /// An error occurred while interacting with the Substrate node. /// /// We only convey errors here that are caused by the contract's @@ -664,17 +711,10 @@ where { log_info(&format!("call: {:02X?}", message.exec_input())); - let dry_run = self - .api - .call_dry_run(signer.account_id().clone(), &message, value, None) - .await; - log_info(&format!("call dry run: {:?}", &dry_run.result)); - log_info(&format!( - "call dry run debug message: {}", - String::from_utf8_lossy(&dry_run.debug_message) - )); - if dry_run.result.is_err() { - return Err(Error::CallDryRun(dry_run)) + let dry_run = self.call_dry_run(signer, &message, value, None).await; + + if dry_run.exec_result.result.is_err() { + return Err(Error::CallDryRun(dry_run.exec_result)) } let tx_events = self @@ -682,7 +722,7 @@ where .call( sp_runtime::MultiAddress::Id(message.account_id().clone()), value, - dry_run.gas_required, + dry_run.exec_result.gas_required, storage_deposit_limit, message.exec_input().to_vec(), signer, @@ -705,18 +745,47 @@ where } } - let bytes = &dry_run.result.as_ref().unwrap().data; - let value: Result, scale::Error> = - scale::Decode::decode(&mut bytes.as_ref()); - Ok(CallResult { - value, - data: bytes.clone(), dry_run, events: tx_events, }) } + /// Executes a dry-run `call`. + /// + /// Returns the result of the dry run, together with the decoded return value of the invoked + /// message. + pub async fn call_dry_run( + &mut self, + signer: &Signer, + message: &Message, + value: E::Balance, + storage_deposit_limit: Option, + ) -> CallDryRunResult + where + RetType: scale::Decode, + { + let exec_result = self + .api + .call_dry_run( + signer.account_id().clone(), + &message, + value, + storage_deposit_limit, + ) + .await; + log_info(&format!("call dry run: {:?}", &exec_result.result)); + log_info(&format!( + "call dry run debug message: {}", + String::from_utf8_lossy(&exec_result.debug_message) + )); + + CallDryRunResult { + exec_result, + _marker: Default::default(), + } + } + /// Returns the balance of `account_id`. pub async fn balance( &self, diff --git a/examples/flipper/lib.rs b/examples/flipper/lib.rs index 3525b8b633..791978ea89 100644 --- a/examples/flipper/lib.rs +++ b/examples/flipper/lib.rs @@ -72,9 +72,8 @@ pub mod flipper { let get = build_message::(contract_acc_id.clone()) .call(|flipper| flipper.get()); let get_res = client - .call(&ink_e2e::bob(), get, 0, None) - .await - .expect("get failed"); + .call_dry_run(&ink_e2e::bob(), &get, 0, None) + .await; assert!(matches!(get_res.return_value(), false)); // when @@ -89,9 +88,8 @@ pub mod flipper { let get = build_message::(contract_acc_id.clone()) .call(|flipper| flipper.get()); let get_res = client - .call(&ink_e2e::bob(), get, 0, None) - .await - .expect("get failed"); + .call_dry_run(&ink_e2e::bob(), &get, 0, None) + .await; assert!(matches!(get_res.return_value(), true)); Ok(()) @@ -113,9 +111,8 @@ pub mod flipper { let get = build_message::(contract_acc_id.clone()) .call(|flipper| flipper.get()); let get_res = client - .call(&ink_e2e::bob(), get, 0, None) - .await - .expect("get failed"); + .call_dry_run(&ink_e2e::bob(), &get, 0, None) + .await; assert!(matches!(get_res.return_value(), false)); Ok(()) From 7e13b7c65ce6ed8d2a25e59e1f2800b0ea5c4ee0 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Thu, 26 Jan 2023 13:56:07 +0000 Subject: [PATCH 02/24] Fix comment --- crates/e2e/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index a108b43d5b..7b6f4e3093 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -206,7 +206,7 @@ where }) } - /// Returns the decoded return value of the message from the dry-run. + /// Returns the return value as raw bytes of the message from the dry-run. /// /// Panics if the dry-run message call failed to execute. pub fn return_data(&self) -> &[u8] { From b674a883202e36235d0059103662827c8fd25b6d Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Thu, 26 Jan 2023 14:39:29 +0000 Subject: [PATCH 03/24] clippy --- crates/e2e/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index 7b6f4e3093..478e2c31df 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -769,7 +769,7 @@ where .api .call_dry_run( signer.account_id().clone(), - &message, + message, value, storage_deposit_limit, ) From 0ad19eb91ed3dfbcd39d5a8b78bb23c8abf2c616 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 27 Jan 2023 15:04:43 +0000 Subject: [PATCH 04/24] Fix up after dry run --- crates/e2e/src/client.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index 34ff655150..ef2f59307b 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -329,8 +329,10 @@ where impl Client where C: subxt::Config, - C::AccountId: serde::de::DeserializeOwned, - C::AccountId: scale::Codec + Debug, + C::AccountId: From + + scale::Codec + + serde::de::DeserializeOwned + + Debug, C::Signature: From, >::OtherParams: Default, @@ -756,7 +758,7 @@ where let exec_result = self .api .call_dry_run( - signer.account_id().clone(), + Signer::account_id(signer).clone(), message, value, storage_deposit_limit, From 9dccf8186ae06ed0e8ca20f7b9f54a4554d1fcb0 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 27 Jan 2023 15:11:57 +0000 Subject: [PATCH 05/24] fmt --- examples/flipper/lib.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/examples/flipper/lib.rs b/examples/flipper/lib.rs index 791978ea89..9efc23bb78 100644 --- a/examples/flipper/lib.rs +++ b/examples/flipper/lib.rs @@ -71,9 +71,7 @@ pub mod flipper { let get = build_message::(contract_acc_id.clone()) .call(|flipper| flipper.get()); - let get_res = client - .call_dry_run(&ink_e2e::bob(), &get, 0, None) - .await; + let get_res = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await; assert!(matches!(get_res.return_value(), false)); // when @@ -87,9 +85,7 @@ pub mod flipper { // then let get = build_message::(contract_acc_id.clone()) .call(|flipper| flipper.get()); - let get_res = client - .call_dry_run(&ink_e2e::bob(), &get, 0, None) - .await; + let get_res = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await; assert!(matches!(get_res.return_value(), true)); Ok(()) @@ -110,9 +106,7 @@ pub mod flipper { // then let get = build_message::(contract_acc_id.clone()) .call(|flipper| flipper.get()); - let get_res = client - .call_dry_run(&ink_e2e::bob(), &get, 0, None) - .await; + let get_res = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await; assert!(matches!(get_res.return_value(), false)); Ok(()) From b6e9ef1d5f7c55e00299455a6e07e36489210095 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 27 Jan 2023 16:26:01 +0000 Subject: [PATCH 06/24] delegator --- examples/delegator/lib.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/delegator/lib.rs b/examples/delegator/lib.rs index 69f5c5ab35..880c3dcbd8 100644 --- a/examples/delegator/lib.rs +++ b/examples/delegator/lib.rs @@ -159,9 +159,8 @@ mod delegator { let get = build_message::(delegator_acc_id.clone()) .call(|contract| contract.get()); let value = client - .call(&ink_e2e::bob(), get, 0, None) + .call_dry_run(&ink_e2e::bob(), &get, 0, None) .await - .expect("calling `get` failed") .return_value(); assert_eq!(value, 1234); let change = build_message::(delegator_acc_id.clone()) @@ -175,9 +174,8 @@ mod delegator { let get = build_message::(delegator_acc_id.clone()) .call(|contract| contract.get()); let value = client - .call(&ink_e2e::bob(), get, 0, None) + .call_dry_run(&ink_e2e::bob(), &get, 0, None) .await - .expect("calling `get` failed") .return_value(); assert_eq!(value, 1234 + 6); @@ -199,9 +197,8 @@ mod delegator { let get = build_message::(delegator_acc_id.clone()) .call(|contract| contract.get()); let value = client - .call(&ink_e2e::bob(), get, 0, None) + .call_dry_run(&ink_e2e::bob(), &get, 0, None) .await - .expect("calling `get` failed") .return_value(); assert_eq!(value, 1234 + 6 - 3); From 685b84ee02cb57e83f92022347b3d0c17cb94699 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 27 Jan 2023 16:32:28 +0000 Subject: [PATCH 07/24] erc20 --- examples/erc20/lib.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/examples/erc20/lib.rs b/examples/erc20/lib.rs index b83da3eff5..c3b78d54c9 100644 --- a/examples/erc20/lib.rs +++ b/examples/erc20/lib.rs @@ -553,9 +553,7 @@ mod erc20 { let total_supply_msg = build_message::(contract_acc_id.clone()) .call(|erc20| erc20.total_supply()); let total_supply_res = client - .call(&ink_e2e::bob(), total_supply_msg, 0, None) - .await - .expect("total_supply failed"); + .call_dry_run(&ink_e2e::bob(), &total_supply_msg, 0, None).await; let bob_account = ink_e2e::account_id(ink_e2e::AccountKeyring::Bob); let transfer_to_bob = 500_000_000u128; @@ -569,9 +567,7 @@ mod erc20 { let balance_of = build_message::(contract_acc_id.clone()) .call(|erc20| erc20.balance_of(bob_account)); let balance_of_res = client - .call(&ink_e2e::alice(), balance_of, 0, None) - .await - .expect("balance_of failed"); + .call_dry_run(&ink_e2e::alice(), &balance_of, 0, None).await; // then assert_eq!( @@ -647,9 +643,7 @@ mod erc20 { let balance_of = build_message::(contract_acc_id.clone()) .call(|erc20| erc20.balance_of(bob_account)); let balance_of_res = client - .call(&ink_e2e::alice(), balance_of, 0, None) - .await - .expect("balance_of failed"); + .call_dry_run(&ink_e2e::alice(), &balance_of, 0, None).await; // `transfer_from` again, this time exceeding the approved amount let transfer_from = From 8fba09754d96e76881a83f8ef7230acfbfb4e26e Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 27 Jan 2023 17:19:36 +0000 Subject: [PATCH 08/24] erc20 --- examples/lang-err-integration-tests/call-builder/lib.rs | 8 ++------ .../constructors-return-value/lib.rs | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/examples/lang-err-integration-tests/call-builder/lib.rs b/examples/lang-err-integration-tests/call-builder/lib.rs index 874138c29e..b6626d57f7 100755 --- a/examples/lang-err-integration-tests/call-builder/lib.rs +++ b/examples/lang-err-integration-tests/call-builder/lib.rs @@ -194,9 +194,7 @@ mod call_builder { let flipper_get = build_message::(flipper_acc_id) .call(|contract| contract.get()); let get_call_result = client - .call(&origin, flipper_get, 0, None) - .await - .expect("Calling `flipper::get` failed"); + .call_dry_run(&origin, &flipper_get, 0, None).await; let initial_value = get_call_result.return_value(); let selector = ink::selector_bytes!("invalid_selector"); @@ -217,9 +215,7 @@ mod call_builder { let flipper_get = build_message::(flipper_acc_id) .call(|contract| contract.get()); let get_call_result = client - .call(&origin, flipper_get, 0, None) - .await - .expect("Calling `flipper::get` failed"); + .call_dry_run(&origin, &flipper_get, 0, None).await; let flipped_value = get_call_result.return_value(); assert!(flipped_value == initial_value); diff --git a/examples/lang-err-integration-tests/constructors-return-value/lib.rs b/examples/lang-err-integration-tests/constructors-return-value/lib.rs index 111b1daa2c..ec1a69d65b 100644 --- a/examples/lang-err-integration-tests/constructors-return-value/lib.rs +++ b/examples/lang-err-integration-tests/constructors-return-value/lib.rs @@ -213,9 +213,7 @@ pub mod constructors_return_value { ink_e2e::build_message::(contract_acc_id) .call(|contract| contract.get_value()); let value = client - .call(&ink_e2e::bob(), get, 0, None) - .await - .expect("Calling `get_value` failed") + .call_dry_run(&ink_e2e::bob(), &get, 0, None).await .return_value(); assert_eq!( From 020e6a44fae4f7e32822030b4cd1938e2b184125 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 30 Jan 2023 15:23:29 +0100 Subject: [PATCH 09/24] fmt --- examples/erc20/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/erc20/lib.rs b/examples/erc20/lib.rs index c3b78d54c9..1e34d09d28 100644 --- a/examples/erc20/lib.rs +++ b/examples/erc20/lib.rs @@ -553,7 +553,8 @@ mod erc20 { let total_supply_msg = build_message::(contract_acc_id.clone()) .call(|erc20| erc20.total_supply()); let total_supply_res = client - .call_dry_run(&ink_e2e::bob(), &total_supply_msg, 0, None).await; + .call_dry_run(&ink_e2e::bob(), &total_supply_msg, 0, None) + .await; let bob_account = ink_e2e::account_id(ink_e2e::AccountKeyring::Bob); let transfer_to_bob = 500_000_000u128; @@ -567,7 +568,8 @@ mod erc20 { let balance_of = build_message::(contract_acc_id.clone()) .call(|erc20| erc20.balance_of(bob_account)); let balance_of_res = client - .call_dry_run(&ink_e2e::alice(), &balance_of, 0, None).await; + .call_dry_run(&ink_e2e::alice(), &balance_of, 0, None) + .await; // then assert_eq!( @@ -643,7 +645,8 @@ mod erc20 { let balance_of = build_message::(contract_acc_id.clone()) .call(|erc20| erc20.balance_of(bob_account)); let balance_of_res = client - .call_dry_run(&ink_e2e::alice(), &balance_of, 0, None).await; + .call_dry_run(&ink_e2e::alice(), &balance_of, 0, None) + .await; // `transfer_from` again, this time exceeding the approved amount let transfer_from = From 49f65c83b0cadca76c386e3a6f3f99dd6eff0faa Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 30 Jan 2023 15:28:52 +0100 Subject: [PATCH 10/24] contract_ref --- .../contract-ref/lib.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/examples/lang-err-integration-tests/contract-ref/lib.rs b/examples/lang-err-integration-tests/contract-ref/lib.rs index 244ba2856e..ee769491d1 100755 --- a/examples/lang-err-integration-tests/contract-ref/lib.rs +++ b/examples/lang-err-integration-tests/contract-ref/lib.rs @@ -92,9 +92,9 @@ mod contract_ref { let get_check = build_message::(contract_acc_id.clone()) .call(|contract| contract.get_check()); let get_call_result = client - .call(&ink_e2e::alice(), get_check, 0, None) - .await - .expect("Calling `get_check` failed"); + .call_dry_run(&ink_e2e::alice(), &get_check, 0, None) + .await; + let initial_value = get_call_result.return_value(); let flip_check = build_message::(contract_acc_id.clone()) @@ -108,12 +108,9 @@ mod contract_ref { "Messages now return a `Result`, which should be `Ok` here." ); - let get_check = build_message::(contract_acc_id.clone()) - .call(|contract| contract.get_check()); let get_call_result = client - .call(&ink_e2e::alice(), get_check, 0, None) - .await - .expect("Calling `get_check` failed"); + .call_dry_run(&ink_e2e::alice(), &get_check, 0, None) + .await; let flipped_value = get_call_result.return_value(); assert!(flipped_value != initial_value); @@ -141,10 +138,10 @@ mod contract_ref { let get_check = build_message::(contract_acc_id.clone()) .call(|contract| contract.get_check()); let get_call_result = client - .call(&ink_e2e::bob(), get_check, 0, None) - .await - .expect("Calling `get_check` failed"); + .call_dry_run(&ink_e2e::bob(), &get_check, 0, None) + .await; let initial_value = get_call_result.return_value(); + assert!(initial_value); Ok(()) From db3aa12b826c48d9927ffe8503a72120c42b8c52 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 30 Jan 2023 15:39:25 +0100 Subject: [PATCH 11/24] contract_ref --- crates/e2e/src/client.rs | 2 +- examples/lang-err-integration-tests/contract-ref/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index ef2f59307b..a85513ba8b 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -163,7 +163,7 @@ where pub struct CallDryRunResult { /// The result of the dry run, contains debug messages /// if there were any. - exec_result: ContractExecResult, + pub exec_result: ContractExecResult, _marker: PhantomData, } diff --git a/examples/lang-err-integration-tests/contract-ref/lib.rs b/examples/lang-err-integration-tests/contract-ref/lib.rs index ee769491d1..61b9c72b1a 100755 --- a/examples/lang-err-integration-tests/contract-ref/lib.rs +++ b/examples/lang-err-integration-tests/contract-ref/lib.rs @@ -104,7 +104,7 @@ mod contract_ref { .await .expect("Calling `flip` failed"); assert!( - flip_call_result.value.is_ok(), + flip_call_result.dry_run.exec_result.result.is_ok(), "Messages now return a `Result`, which should be `Ok` here." ); From 00d269503c2119569b9af5d121591496e37b0b47 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 30 Jan 2023 15:47:10 +0100 Subject: [PATCH 12/24] integration_flipper --- .../integration-flipper/lib.rs | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/examples/lang-err-integration-tests/integration-flipper/lib.rs b/examples/lang-err-integration-tests/integration-flipper/lib.rs index 1a9eeaf70f..0155c1aa4b 100644 --- a/examples/lang-err-integration-tests/integration-flipper/lib.rs +++ b/examples/lang-err-integration-tests/integration-flipper/lib.rs @@ -88,11 +88,10 @@ pub mod integration_flipper { let get = build_message::(contract_acc_id.clone()) .call(|contract| contract.get()); - let get_call_result = client - .call(&ink_e2e::alice(), get, 0, None) + let initial_value = client + .call_dry_run(&ink_e2e::alice(), &get, 0, None) .await - .expect("Calling `get` failed"); - let initial_value = get_call_result.return_value(); + .return_value(); let flip = build_message::(contract_acc_id) .call(|contract| contract.flip()); @@ -105,13 +104,10 @@ pub mod integration_flipper { "Messages now return a `Result`, which should be `Ok` here." ); - let get = build_message::(contract_acc_id.clone()) - .call(|contract| contract.get()); - let get_call_result = client - .call(&ink_e2e::alice(), get, 0, None) + let flipped_value = client + .call_dry_run(&ink_e2e::alice(), &get, 0, None) .await - .expect("Calling `get` failed"); - let flipped_value = get_call_result.return_value(); + .return_value(); assert!(flipped_value != initial_value); Ok(()) @@ -130,11 +126,10 @@ pub mod integration_flipper { let get = build_message::(contract_acc_id.clone()) .call(|contract| contract.get()); - let get_call_result = client - .call(&ink_e2e::bob(), get, 0, None) + let initial_value = client + .call_dry_run(&ink_e2e::bob(), &get, 0, None) .await - .expect("Calling `get` failed"); - let initial_value = get_call_result.return_value(); + .return_value(); let err_flip = build_message::(contract_acc_id) .call(|contract| contract.err_flip()); @@ -146,13 +141,10 @@ pub mod integration_flipper { Err(ink_e2e::Error::CallExtrinsic(_)) )); - let get = build_message::(contract_acc_id.clone()) - .call(|contract| contract.get()); - let get_call_result = client - .call(&ink_e2e::bob(), get, 0, None) + let flipped_value = client + .call(&ink_e2e::bob(), &get, 0, None) .await - .expect("Calling `get` failed"); - let flipped_value = get_call_result.return_value(); + .return_value(); assert!(flipped_value == initial_value); Ok(()) From c8d7bdeb9b2cd362bb9e94d433efe2df9e036f14 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 30 Jan 2023 15:53:29 +0100 Subject: [PATCH 13/24] Expose and use message result --- crates/e2e/src/client.rs | 11 +++++++++++ .../lang-err-integration-tests/contract-ref/lib.rs | 2 +- .../integration-flipper/lib.rs | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index a85513ba8b..e051af6102 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -125,6 +125,17 @@ where E: Environment, V: scale::Decode, { + /// Returns the [`MessageResult`] from the execution of the dry-run message + /// call. + /// + /// # Panics + /// - if the dry-run message call failed to execute. + /// - if message result cannot be decoded into the expected return value + /// type. + pub fn message_result(&self) -> MessageResult { + self.dry_run.message_result() + } + /// Returns the decoded return value of the message from the dry-run. /// /// Panics if the value could not be decoded. The raw bytes can be accessed diff --git a/examples/lang-err-integration-tests/contract-ref/lib.rs b/examples/lang-err-integration-tests/contract-ref/lib.rs index 61b9c72b1a..0f6f8cdc96 100755 --- a/examples/lang-err-integration-tests/contract-ref/lib.rs +++ b/examples/lang-err-integration-tests/contract-ref/lib.rs @@ -104,7 +104,7 @@ mod contract_ref { .await .expect("Calling `flip` failed"); assert!( - flip_call_result.dry_run.exec_result.result.is_ok(), + flip_call_result.message_result().is_ok(), "Messages now return a `Result`, which should be `Ok` here." ); diff --git a/examples/lang-err-integration-tests/integration-flipper/lib.rs b/examples/lang-err-integration-tests/integration-flipper/lib.rs index 0155c1aa4b..2a7b12d7d5 100644 --- a/examples/lang-err-integration-tests/integration-flipper/lib.rs +++ b/examples/lang-err-integration-tests/integration-flipper/lib.rs @@ -100,7 +100,7 @@ pub mod integration_flipper { .await .expect("Calling `flip` failed"); assert!( - flip_call_result.value.is_ok(), + flip_call_result.message_result().is_ok(), "Messages now return a `Result`, which should be `Ok` here." ); @@ -142,7 +142,7 @@ pub mod integration_flipper { )); let flipped_value = client - .call(&ink_e2e::bob(), &get, 0, None) + .call_dry_run(&ink_e2e::bob(), &get, 0, None) .await .return_value(); assert!(flipped_value == initial_value); From 78e85b21df2c42782d5efa3c9f96450d1de9b6dc Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 30 Jan 2023 15:54:41 +0100 Subject: [PATCH 14/24] Fmt --- examples/lang-err-integration-tests/call-builder/lib.rs | 8 ++++---- .../constructors-return-value/lib.rs | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/lang-err-integration-tests/call-builder/lib.rs b/examples/lang-err-integration-tests/call-builder/lib.rs index b6626d57f7..2410ca2c11 100755 --- a/examples/lang-err-integration-tests/call-builder/lib.rs +++ b/examples/lang-err-integration-tests/call-builder/lib.rs @@ -193,8 +193,8 @@ mod call_builder { let flipper_get = build_message::(flipper_acc_id) .call(|contract| contract.get()); - let get_call_result = client - .call_dry_run(&origin, &flipper_get, 0, None).await; + let get_call_result = + client.call_dry_run(&origin, &flipper_get, 0, None).await; let initial_value = get_call_result.return_value(); let selector = ink::selector_bytes!("invalid_selector"); @@ -214,8 +214,8 @@ mod call_builder { let flipper_get = build_message::(flipper_acc_id) .call(|contract| contract.get()); - let get_call_result = client - .call_dry_run(&origin, &flipper_get, 0, None).await; + let get_call_result = + client.call_dry_run(&origin, &flipper_get, 0, None).await; let flipped_value = get_call_result.return_value(); assert!(flipped_value == initial_value); diff --git a/examples/lang-err-integration-tests/constructors-return-value/lib.rs b/examples/lang-err-integration-tests/constructors-return-value/lib.rs index ec1a69d65b..c25fa6e1a5 100644 --- a/examples/lang-err-integration-tests/constructors-return-value/lib.rs +++ b/examples/lang-err-integration-tests/constructors-return-value/lib.rs @@ -213,7 +213,8 @@ pub mod constructors_return_value { ink_e2e::build_message::(contract_acc_id) .call(|contract| contract.get_value()); let value = client - .call_dry_run(&ink_e2e::bob(), &get, 0, None).await + .call_dry_run(&ink_e2e::bob(), &get, 0, None) + .await .return_value(); assert_eq!( From b5552c47cd86ab7c695dbc2ec5336d7f4eae7267 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 30 Jan 2023 16:29:23 +0100 Subject: [PATCH 15/24] Fix contract-terminate example --- crates/e2e/src/client.rs | 7 +++++++ examples/contract-terminate/lib.rs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index e051af6102..7ee5ff12cf 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -136,6 +136,13 @@ where self.dry_run.message_result() } + /// Returns the return value as raw bytes of the message from the dry-run. + /// + /// Panics if the dry-run message call failed to execute. + pub fn return_data(&self) -> &[u8] { + &self.dry_run.exec_return_value().data + } + /// Returns the decoded return value of the message from the dry-run. /// /// Panics if the value could not be decoded. The raw bytes can be accessed diff --git a/examples/contract-terminate/lib.rs b/examples/contract-terminate/lib.rs index 3e2a5dbfe2..3d278127dd 100644 --- a/examples/contract-terminate/lib.rs +++ b/examples/contract-terminate/lib.rs @@ -86,7 +86,7 @@ pub mod just_terminates { .expect("terminate_me messages failed"); assert!( - call_res.data.is_empty(), + call_res.return_data().is_empty(), "Terminated contract never returns" ); From 7916ff533e0d59d38be6658439f4cbc097d1a965 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 30 Jan 2023 16:39:41 +0100 Subject: [PATCH 16/24] Fix up e2e docs --- crates/e2e/src/client.rs | 8 ++++---- crates/e2e/src/lib.rs | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index 7ee5ff12cf..d25832f0a5 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -30,7 +30,7 @@ use super::{ use contract_metadata::ContractMetadata; use ink_env::Environment; use ink_primitives::MessageResult; - +use pallet_contracts_primitives::ExecReturnValue; use sp_core::Pair; use std::{ collections::BTreeMap, @@ -146,7 +146,7 @@ where /// Returns the decoded return value of the message from the dry-run. /// /// Panics if the value could not be decoded. The raw bytes can be accessed - /// via [`return_data`]. + /// via [`CallResult::return_data`]. pub fn return_value(self) -> V { self.dry_run.return_value() } @@ -193,7 +193,7 @@ where /// Returns the [`ExecReturnValue`] resulting from the dry-run message call. /// /// Panics if the dry-run message call failed to execute. - pub fn exec_return_value(&self) -> &pallet_contracts_primitives::ExecReturnValue { + pub fn exec_return_value(&self) -> &ExecReturnValue { self.exec_result .result .as_ref() @@ -227,7 +227,7 @@ where /// Returns the decoded return value of the message from the dry-run. /// /// Panics if the value could not be decoded. The raw bytes can be accessed - /// via [`return_data`]. + /// via [`CallResult::return_data`]. pub fn return_value(self) -> V { self.message_result() .unwrap_or_else(|lang_err| { diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index f03f3f5bfd..a00e599161 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -34,6 +34,10 @@ pub use builders::{ pub use client::{ Client, Error, + CallResult, + CallDryRunResult, + InstantiationResult, + UploadResult, }; pub use default_accounts::*; pub use env_logger; From 8125d59abd3439e5f6d0f76502386c71a6348f21 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 30 Jan 2023 16:40:47 +0100 Subject: [PATCH 17/24] Fmt --- crates/e2e/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index a00e599161..d6a7788dc1 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -32,10 +32,10 @@ pub use builders::{ MessageBuilder, }; pub use client::{ + CallDryRunResult, + CallResult, Client, Error, - CallResult, - CallDryRunResult, InstantiationResult, UploadResult, }; From 5e131165039adbe67c1b8df6d32afb2deb85db10 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 30 Jan 2023 16:46:49 +0100 Subject: [PATCH 18/24] Fix debug impls --- crates/e2e/src/client.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index d25832f0a5..4ecbf48c1b 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -163,21 +163,23 @@ where /// We implement a custom `Debug` here, as to avoid requiring the trait /// bound `Debug` for `E`. // TODO(#xxx) Improve the `Debug` implementation. -impl core::fmt::Debug for CallResult +impl Debug for CallResult where - C: subxt::Config, - E: Environment, - ::Balance: core::fmt::Debug, + C: subxt::Config + Debug, + E: Environment + Debug, + ::Balance: Debug, + V: Debug, { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { f.debug_struct("CallResult") - .field("dry_run", &self.dry_run.exec_result) + .field("dry_run", &self.dry_run) .field("events", &self.events) .finish() } } /// Result of the dry run of a contract call. +#[derive(Debug)] pub struct CallDryRunResult { /// The result of the dry run, contains debug messages /// if there were any. From 4c7d92245b12dd7093ac3942095398f2425a92d9 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 31 Jan 2023 11:24:21 +0000 Subject: [PATCH 19/24] Add debug message method --- crates/e2e/src/client.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index 4ecbf48c1b..ec152738c8 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -151,6 +151,11 @@ where self.dry_run.return_value() } + /// Returns any debug message output by the contract decoded as UTF-8. + pub fn debug_message(&self) -> String { + self.dry_run.debug_message() + } + /// Returns true if the specified event was triggered by the call. pub fn contains_event(&self, pallet_name: &str, variant_name: &str) -> bool { self.events.iter().any(|event| { @@ -239,6 +244,11 @@ where ) }) } + + /// Returns any debug message output by the contract decoded as UTF-8. + pub fn debug_message(&self) -> String { + String::from_utf8_lossy(&self.exec_result.debug_message).into() + } } /// An error occurred while interacting with the Substrate node. From e93d7a29974b6a0dfcf1501061c988f63aa3e774 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 31 Jan 2023 11:28:16 +0000 Subject: [PATCH 20/24] Fix up contract-transfer --- examples/contract-transfer/lib.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/examples/contract-transfer/lib.rs b/examples/contract-transfer/lib.rs index a479f4dae2..f73372f9c9 100644 --- a/examples/contract-transfer/lib.rs +++ b/examples/contract-transfer/lib.rs @@ -210,15 +210,12 @@ pub mod give_me { let call_res = client.call(&ink_e2e::bob(), transfer, 10, None).await; // then - assert!(call_res.is_err()); - let contains_err_msg = match call_res.unwrap_err() { - ink_e2e::Error::CallDryRun(dry_run) => { - String::from_utf8_lossy(&dry_run.debug_message) - .contains("paid an unpayable message") - } - _ => false, - }; - assert!(contains_err_msg); + if let Err(ink_e2e::Error::CallDryRun(dry_run)) = call_res { + let debug_message = String::from_utf8_lossy(&dry_run.debug_message); + assert!(debug_message.contains("paid an unpayable message")) + } else { + panic!("Paying an unpayable message should fail") + } Ok(()) } @@ -254,10 +251,7 @@ pub mod give_me { .expect("call failed"); // then - let contains_debug_println = - String::from_utf8_lossy(&call_res.dry_run.debug_message) - .contains("requested value: 120\n"); - assert!(contains_debug_println); + assert!(call_res.debug_message().contains("requested value: 120\n")); let balance_after: Balance = client .balance(contract_acc_id) From 652beddace78f080dfd557231c64f51b4c9706aa Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 31 Jan 2023 11:29:35 +0000 Subject: [PATCH 21/24] Reorder methods --- crates/e2e/src/client.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index ec152738c8..cf6eb7bc40 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -136,13 +136,6 @@ where self.dry_run.message_result() } - /// Returns the return value as raw bytes of the message from the dry-run. - /// - /// Panics if the dry-run message call failed to execute. - pub fn return_data(&self) -> &[u8] { - &self.dry_run.exec_return_value().data - } - /// Returns the decoded return value of the message from the dry-run. /// /// Panics if the value could not be decoded. The raw bytes can be accessed @@ -151,6 +144,13 @@ where self.dry_run.return_value() } + /// Returns the return value as raw bytes of the message from the dry-run. + /// + /// Panics if the dry-run message call failed to execute. + pub fn return_data(&self) -> &[u8] { + &self.dry_run.exec_return_value().data + } + /// Returns any debug message output by the contract decoded as UTF-8. pub fn debug_message(&self) -> String { self.dry_run.debug_message() @@ -224,13 +224,6 @@ where }) } - /// Returns the return value as raw bytes of the message from the dry-run. - /// - /// Panics if the dry-run message call failed to execute. - pub fn return_data(&self) -> &[u8] { - &self.exec_return_value().data - } - /// Returns the decoded return value of the message from the dry-run. /// /// Panics if the value could not be decoded. The raw bytes can be accessed @@ -245,6 +238,13 @@ where }) } + /// Returns the return value as raw bytes of the message from the dry-run. + /// + /// Panics if the dry-run message call failed to execute. + pub fn return_data(&self) -> &[u8] { + &self.exec_return_value().data + } + /// Returns any debug message output by the contract decoded as UTF-8. pub fn debug_message(&self) -> String { String::from_utf8_lossy(&self.exec_result.debug_message).into() From 9c63bcdb9dd886f4913b1c7c1b4c85a29eac5ed8 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 31 Jan 2023 12:05:18 +0000 Subject: [PATCH 22/24] Fix up mapping integration tests --- examples/mapping_integration_tests/lib.rs | 60 +++++++---------------- 1 file changed, 17 insertions(+), 43 deletions(-) diff --git a/examples/mapping_integration_tests/lib.rs b/examples/mapping_integration_tests/lib.rs index 515bb5cedd..cc2bf52787 100755 --- a/examples/mapping_integration_tests/lib.rs +++ b/examples/mapping_integration_tests/lib.rs @@ -115,20 +115,15 @@ mod mapping_integration_tests { .call(&ink_e2e::alice(), insert, 0, None) .await .expect("Calling `insert_balance` failed") - .value - .expect("Input is valid, call must not fail.") - .expect("Execution should not fail."); + .return_value(); // then let get = ink_e2e::build_message::(contract_id) .call(|contract| contract.get_balance()); let balance = client - .call(&ink_e2e::alice(), get, 0, None) + .call_dry_run(&ink_e2e::alice(), &get, 0, None) .await - .expect("Calling `get_balance` failed") - .value - .expect("Input is valid, call must not fail.") - .expect("Execution should not fail."); + .return_value(); assert!(size.is_none()); assert_eq!(balance, Some(1_000)); @@ -161,19 +156,15 @@ mod mapping_integration_tests { .call(&ink_e2e::bob(), insert, 0, None) .await .expect("Calling `insert_balance` failed") - .value - .expect("Input is valid, call must not fail."); + .return_value(); // then let contains = ink_e2e::build_message::(contract_id) .call(|contract| contract.contains_balance()); let is_there = client - .call(&ink_e2e::bob(), contains, 0, None) + .call_dry_run(&ink_e2e::bob(), &contains, 0, None) .await - .expect("Calling `contains_balance` failed") - .value - .expect("Input is valid, call must not fail.") - .expect("Execution should not fail."); + .return_value(); assert!(is_there); @@ -203,8 +194,7 @@ mod mapping_integration_tests { .call(&ink_e2e::charlie(), first_insert, 0, None) .await .expect("Calling `insert_balance` failed") - .value - .expect("Input is valid, call must not fail."); + .return_value(); let insert = ink_e2e::build_message::(contract_id) .call(|contract| contract.insert_balance(10_000)); @@ -212,9 +202,7 @@ mod mapping_integration_tests { .call(&ink_e2e::charlie(), insert, 0, None) .await .expect("Calling `insert_balance` failed") - .value - .expect("Input is valid, call must not fail.") - .expect("Execution should not fail."); + .return_value(); // then assert!(size.is_some()); @@ -222,12 +210,9 @@ mod mapping_integration_tests { let get = ink_e2e::build_message::(contract_id) .call(|contract| contract.get_balance()); let balance = client - .call(&ink_e2e::charlie(), get, 0, None) + .call_dry_run(&ink_e2e::charlie(), &get, 0, None) .await - .expect("Calling `get_balance` failed") - .value - .expect("Input is valid, call must not fail.") - .expect("Execution should not fail."); + .return_value(); assert_eq!(balance, Some(10_000)); @@ -259,9 +244,7 @@ mod mapping_integration_tests { .call(&ink_e2e::dave(), insert, 0, None) .await .expect("Calling `insert_balance` failed") - .value - .expect("Input is valid, call must not fail.") - .expect("Execution should not fail."); + .return_value(); let remove = ink_e2e::build_message::(contract_id) .call(|contract| contract.remove_balance()); @@ -274,12 +257,9 @@ mod mapping_integration_tests { let get = ink_e2e::build_message::(contract_id) .call(|contract| contract.get_balance()); let balance = client - .call(&ink_e2e::dave(), get, 0, None) + .call_dry_run(&ink_e2e::dave(), &get, 0, None) .await - .expect("Calling `get_balance` failed") - .value - .expect("Input is valid, call must not fail.") - .expect("Execution should not fail."); + .return_value(); assert_eq!(balance, None); @@ -311,8 +291,7 @@ mod mapping_integration_tests { .call(&ink_e2e::eve(), insert, 0, None) .await .expect("Calling `insert_balance` failed") - .value - .expect("Input is valid, call must not fail."); + .return_value(); let take = ink_e2e::build_message::(contract_id) .call(|contract| contract.take_balance()); @@ -320,9 +299,7 @@ mod mapping_integration_tests { .call(&ink_e2e::eve(), take, 0, None) .await .expect("Calling `take_balance` failed") - .value - .expect("Input is valid, call must not fail.") - .expect("Execution should not fail."); + .return_value(); // then assert_eq!(balance, Some(4_000)); @@ -330,12 +307,9 @@ mod mapping_integration_tests { let contains = ink_e2e::build_message::(contract_id) .call(|contract| contract.contains_balance()); let is_there = client - .call(&ink_e2e::eve(), contains, 0, None) + .call_dry_run(&ink_e2e::eve(), &contains, 0, None) .await - .expect("Calling `contains_balance` failed") - .value - .expect("Input is valid, call must not fail.") - .expect("Execution should not fail."); + .return_value(); assert!(!is_there); From c1009b951b48b86ecd408780f8344b04dd426ffd Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 31 Jan 2023 16:58:40 +0000 Subject: [PATCH 23/24] call-builder --- crates/e2e/src/client.rs | 5 +++ .../call-builder/lib.rs | 38 +++++++------------ 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index cf6eb7bc40..d21d178ef4 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -197,6 +197,11 @@ where E: Environment, V: scale::Decode, { + /// Returns true if the dry-run execution resulted in an error. + pub fn is_err(&self) -> bool { + self.exec_result.result.is_err() + } + /// Returns the [`ExecReturnValue`] resulting from the dry-run message call. /// /// Panics if the dry-run message call failed to execute. diff --git a/examples/lang-err-integration-tests/call-builder/lib.rs b/examples/lang-err-integration-tests/call-builder/lib.rs index 2410ca2c11..1d143fadec 100755 --- a/examples/lang-err-integration-tests/call-builder/lib.rs +++ b/examples/lang-err-integration-tests/call-builder/lib.rs @@ -249,17 +249,12 @@ mod call_builder { let invalid_selector = [0x00, 0x00, 0x00, 0x00]; let call = build_message::(contract_acc_id) .call(|contract| contract.invoke(flipper_acc_id, invalid_selector)); - let call_result = client.call(&origin, call, 0, None).await; + let call_result = client.call_dry_run(&origin, &call, 0, None).await; assert!(call_result.is_err()); - let contains_err_msg = match call_result.unwrap_err() { - ink_e2e::Error::CallDryRun(dry_run) => { - String::from_utf8_lossy(&dry_run.debug_message) - .contains("Cross-contract call failed with CouldNotReadInput") - } - _ => false, - }; - assert!(contains_err_msg); + assert!(call_result + .debug_message() + .contains("Cross-contract call failed with CouldNotReadInput")); Ok(()) } @@ -374,18 +369,15 @@ mod call_builder { contract.call_instantiate(code_hash, selector, init_value) }); - let call_result = client.call(&origin, call, 0, None).await; + let call_result = client.call_dry_run(&origin, &call, 0, None).await; assert!( call_result.is_err(), "Call execution should've failed, but didn't." ); - let contains_err_msg = match call_result.unwrap_err() { - ink_e2e::Error::CallDryRun(dry_run) => { - String::from_utf8_lossy(&dry_run.debug_message) - .contains("The callee reverted, but did not encode an error in the output buffer.") - } - _ => false, - }; + let contains_err_msg = call_result.debug_message().contains( + "The callee reverted, but did not encode an error in the output buffer.", + ); + assert!( contains_err_msg, "Call execution failed for an unexpected reason." @@ -510,20 +502,16 @@ mod call_builder { build_message::(contract_acc_id).call(|contract| { contract.call_instantiate_fallible(code_hash, selector, init_value) }); - let call_result = client.call(&origin, call, 0, None).await; + let call_result = client.call_dry_run(&origin, &call, 0, None).await; assert!( call_result.is_err(), "Call execution should've failed, but didn't." ); - let contains_err_msg = match call_result.unwrap_err() { - ink_e2e::Error::CallDryRun(dry_run) => { - String::from_utf8_lossy(&dry_run.debug_message) - .contains("The callee reverted, but did not encode an error in the output buffer.") - } - _ => false, - }; + let contains_err_msg = call_result.debug_message().contains( + "The callee reverted, but did not encode an error in the output buffer.", + ); assert!( contains_err_msg, "Call execution failed for an unexpected reason." From d8161889a57678f5743d3060da8d6aae14b8cb3c Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 31 Jan 2023 17:12:23 +0000 Subject: [PATCH 24/24] clippy --- crates/e2e/src/client.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index d21d178ef4..08984fd097 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -209,7 +209,7 @@ where self.exec_result .result .as_ref() - .unwrap_or_else(|call_err| panic!("Call dry-run failed: {:?}", call_err)) + .unwrap_or_else(|call_err| panic!("Call dry-run failed: {call_err:?}")) } /// Returns the [`MessageResult`] from the execution of the dry-run message @@ -223,8 +223,7 @@ where let data = &self.exec_return_value().data; scale::Decode::decode(&mut data.as_ref()).unwrap_or_else(|env_err| { panic!( - "Decoding dry run result to ink! message return type failed: {}", - env_err + "Decoding dry run result to ink! message return type failed: {env_err}" ) }) } @@ -237,8 +236,7 @@ where self.message_result() .unwrap_or_else(|lang_err| { panic!( - "Encountered a `LangError` while decoding dry run result to ink! message: {:?}", - lang_err + "Encountered a `LangError` while decoding dry run result to ink! message: {lang_err:?}" ) }) }