From fc543da276dabf24f3d2a18c31c7b332c5670c28 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 30 Nov 2022 14:20:13 +0000 Subject: [PATCH] `[ink_e2e]` housekeeping (#1524) * Remove unused stuff * Remove redundant mutable from signer arg * Fmt examples --- crates/e2e/src/client.rs | 32 +++---------------- crates/e2e/src/lib.rs | 21 ------------ examples/contract-transfer/lib.rs | 8 ++--- examples/delegator/lib.rs | 20 ++++++------ .../call-builder/lib.rs | 28 +++++++--------- .../constructors-return-value/lib.rs | 8 ++--- .../contract-ref/lib.rs | 10 +++--- .../integration-flipper/lib.rs | 22 +++++-------- 8 files changed, 47 insertions(+), 102 deletions(-) diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index 26f34ce7965..7da76b5dab7 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -35,7 +35,6 @@ use super::{ ContractExecResult, ContractInstantiateResult, ContractsApi, - InkMessage, Signer, }; use contract_metadata::ContractMetadata; @@ -62,27 +61,6 @@ use subxt::{ tx::ExtrinsicParams, }; -/// An encoded `#[ink(message)]`. -#[derive(Clone)] -pub struct EncodedMessage(Vec); - -impl EncodedMessage { - fn new(call: &M) -> Self { - let mut call_data = M::SELECTOR.to_vec(); - ::encode_to(call, &mut call_data); - Self(call_data) - } -} - -impl From for EncodedMessage -where - M: InkMessage, -{ - fn from(msg: M) -> Self { - EncodedMessage::new(&msg) - } -} - /// Result of a contract instantiation. pub struct InstantiationResult { /// The account id at which the contract was instantiated. @@ -341,7 +319,7 @@ where pub async fn instantiate( &mut self, contract_name: &str, - signer: &mut Signer, + signer: &Signer, constructor: CreateBuilderPartial, value: E::Balance, storage_deposit_limit: Option, @@ -396,7 +374,7 @@ where /// Executes an `instantiate_with_code` call and captures the resulting events. async fn exec_instantiate( &mut self, - signer: &mut Signer, + signer: &Signer, code: Vec, constructor: CreateBuilderPartial, value: E::Balance, @@ -513,7 +491,7 @@ where pub async fn upload( &mut self, contract_name: &str, - signer: &mut Signer, + signer: &Signer, storage_deposit_limit: Option, ) -> Result, Error> { let contract_metadata = self @@ -531,7 +509,7 @@ where /// Executes an `upload` call and captures the resulting events. pub async fn exec_upload( &mut self, - signer: &mut Signer, + signer: &Signer, code: Vec, storage_deposit_limit: Option, ) -> Result, Error> { @@ -611,7 +589,7 @@ where /// contains all events that are associated with this transaction. pub async fn call( &mut self, - signer: &mut Signer, + signer: &Signer, message: Message, value: E::Balance, storage_deposit_limit: Option, diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index 4d45aa18a8c..7034c561066 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -93,27 +93,6 @@ pub type PolkadotConfig = subxt::config::WithExtrinsicParams< /// cryptography. pub type Signer = PairSigner; -/// Trait for contract constructors. -// TODO(#1421) Merge this with `InkMessage` to be just `InkSelector`. Requires forking `smart-bench-macro`. -pub trait InkConstructor: scale::Encode { - /// Return type of the constructor. - type ReturnType; - /// An ink! selector consists of four bytes. - const SELECTOR: [u8; 4]; - /// Path to the contract bundle. - const CONTRACT_PATH: &'static str; -} - -/// Trait for contract messages. -pub trait InkMessage: scale::Encode { - /// Return type of the message. - type ReturnType; - /// An ink! selector consists of four bytes. - const SELECTOR: [u8; 4]; - /// Path to the contract bundle. - const CONTRACT_PATH: &'static str; -} - /// We use this to only initialize `env_logger` once. pub static INIT: Once = Once::new(); diff --git a/examples/contract-transfer/lib.rs b/examples/contract-transfer/lib.rs index 0e0db311fc2..a479f4dae2f 100644 --- a/examples/contract-transfer/lib.rs +++ b/examples/contract-transfer/lib.rs @@ -194,7 +194,7 @@ pub mod give_me { let contract_acc_id = client .instantiate( "contract_transfer", - &mut ink_e2e::alice(), + &ink_e2e::alice(), constructor, 1000, None, @@ -207,7 +207,7 @@ pub mod give_me { let transfer = ink_e2e::build_message::(contract_acc_id) .call(|contract| contract.give_me(120)); - let call_res = client.call(&mut ink_e2e::bob(), transfer, 10, None).await; + let call_res = client.call(&ink_e2e::bob(), transfer, 10, None).await; // then assert!(call_res.is_err()); @@ -231,7 +231,7 @@ pub mod give_me { let contract_acc_id = client .instantiate( "contract_transfer", - &mut ink_e2e::bob(), + &ink_e2e::bob(), constructor, 1337, None, @@ -249,7 +249,7 @@ pub mod give_me { .call(|contract| contract.give_me(120)); let call_res = client - .call(&mut ink_e2e::eve(), transfer, 0, None) + .call(&ink_e2e::eve(), transfer, 0, None) .await .expect("call failed"); diff --git a/examples/delegator/lib.rs b/examples/delegator/lib.rs index ee4a796c9a7..6b5781925ad 100644 --- a/examples/delegator/lib.rs +++ b/examples/delegator/lib.rs @@ -136,19 +136,19 @@ mod delegator { async fn e2e_delegator(mut client: ink_e2e::Client) -> E2EResult<()> { // given let accumulator_hash = client - .upload("accumulator", &mut ink_e2e::alice(), None) + .upload("accumulator", &ink_e2e::alice(), None) .await .expect("uploading `accumulator` failed") .code_hash; let adder_hash = client - .upload("adder", &mut ink_e2e::alice(), None) + .upload("adder", &ink_e2e::alice(), None) .await .expect("uploading `adder` failed") .code_hash; let subber_hash = client - .upload("subber", &mut ink_e2e::alice(), None) + .upload("subber", &ink_e2e::alice(), None) .await .expect("uploading `subber` failed") .code_hash; @@ -162,7 +162,7 @@ mod delegator { ); let delegator_acc_id = client - .instantiate("delegator", &mut ink_e2e::alice(), constructor, 0, None) + .instantiate("delegator", &ink_e2e::alice(), constructor, 0, None) .await .expect("instantiate failed") .account_id; @@ -171,7 +171,7 @@ mod delegator { let get = build_message::(delegator_acc_id.clone()) .call(|contract| contract.get()); let value = client - .call(&mut ink_e2e::bob(), get, 0, None) + .call(&ink_e2e::bob(), get, 0, None) .await .expect("calling `get` failed") .value @@ -180,7 +180,7 @@ mod delegator { let change = build_message::(delegator_acc_id.clone()) .call(|contract| contract.change(6)); let _ = client - .call(&mut ink_e2e::bob(), change, 0, None) + .call(&ink_e2e::bob(), change, 0, None) .await .expect("calling `change` failed"); @@ -188,7 +188,7 @@ mod delegator { let get = build_message::(delegator_acc_id.clone()) .call(|contract| contract.get()); let value = client - .call(&mut ink_e2e::bob(), get, 0, None) + .call(&ink_e2e::bob(), get, 0, None) .await .expect("calling `get` failed") .value @@ -199,13 +199,13 @@ mod delegator { let switch = build_message::(delegator_acc_id.clone()) .call(|contract| contract.switch()); let _ = client - .call(&mut ink_e2e::bob(), switch, 0, None) + .call(&ink_e2e::bob(), switch, 0, None) .await .expect("calling `switch` failed"); let change = build_message::(delegator_acc_id.clone()) .call(|contract| contract.change(3)); let _ = client - .call(&mut ink_e2e::bob(), change, 0, None) + .call(&ink_e2e::bob(), change, 0, None) .await .expect("calling `change` failed"); @@ -213,7 +213,7 @@ mod delegator { let get = build_message::(delegator_acc_id.clone()) .call(|contract| contract.get()); let value = client - .call(&mut ink_e2e::bob(), get, 0, None) + .call(&ink_e2e::bob(), get, 0, None) .await .expect("calling `get` failed") .value diff --git a/examples/lang-err-integration-tests/call-builder/lib.rs b/examples/lang-err-integration-tests/call-builder/lib.rs index 6125d27674c..8660813f2fe 100755 --- a/examples/lang-err-integration-tests/call-builder/lib.rs +++ b/examples/lang-err-integration-tests/call-builder/lib.rs @@ -99,13 +99,7 @@ mod call_builder { ) -> E2EResult<()> { let constructor = CallBuilderTestRef::new(); let contract_acc_id = client - .instantiate( - "call_builder", - &mut ink_e2e::charlie(), - constructor, - 0, - None, - ) + .instantiate("call_builder", &ink_e2e::charlie(), constructor, 0, None) .await .expect("instantiate failed") .account_id; @@ -114,7 +108,7 @@ mod call_builder { let flipper_acc_id = client .instantiate( "integration_flipper", - &mut ink_e2e::charlie(), + &ink_e2e::charlie(), flipper_constructor, 0, None, @@ -126,7 +120,7 @@ mod call_builder { let flipper_get = build_message::(flipper_acc_id) .call(|contract| contract.get()); let get_call_result = client - .call(&mut ink_e2e::charlie(), flipper_get, 0, None) + .call(&ink_e2e::charlie(), flipper_get, 0, None) .await .expect("Calling `flipper::get` failed"); let initial_value = get_call_result @@ -137,7 +131,7 @@ mod call_builder { let call = build_message::(contract_acc_id) .call(|contract| contract.call(flipper_acc_id, invalid_selector)); let call_result = client - .call(&mut ink_e2e::charlie(), call, 0, None) + .call(&ink_e2e::charlie(), call, 0, None) .await .expect("Calling `call_builder::call` failed"); @@ -153,7 +147,7 @@ mod call_builder { let flipper_get = build_message::(flipper_acc_id) .call(|contract| contract.get()); let get_call_result = client - .call(&mut ink_e2e::charlie(), flipper_get, 0, None) + .call(&ink_e2e::charlie(), flipper_get, 0, None) .await .expect("Calling `flipper::get` failed"); let flipped_value = get_call_result @@ -170,13 +164,13 @@ mod call_builder { ) -> E2EResult<()> { let constructor = CallBuilderTestRef::new(); let contract_acc_id = client - .instantiate("call_builder", &mut ink_e2e::dave(), constructor, 0, None) + .instantiate("call_builder", &ink_e2e::dave(), constructor, 0, None) .await .expect("instantiate failed") .account_id; let code_hash = client - .upload("constructors_return_value", &mut ink_e2e::dave(), None) + .upload("constructors_return_value", &ink_e2e::dave(), None) .await .expect("upload `constructors_return_value` failed") .code_hash; @@ -187,7 +181,7 @@ mod call_builder { contract.call_instantiate(code_hash, new_selector, true) }); let call_result = client - .call(&mut ink_e2e::dave(), call, 0, None) + .call(&ink_e2e::dave(), call, 0, None) .await .expect("Client failed to call `call_builder::call_instantiate`.") .value @@ -207,13 +201,13 @@ mod call_builder { ) -> E2EResult<()> { let constructor = CallBuilderTestRef::new(); let contract_acc_id = client - .instantiate("call_builder", &mut ink_e2e::eve(), constructor, 0, None) + .instantiate("call_builder", &ink_e2e::eve(), constructor, 0, None) .await .expect("instantiate failed") .account_id; let code_hash = client - .upload("constructors_return_value", &mut ink_e2e::eve(), None) + .upload("constructors_return_value", &ink_e2e::eve(), None) .await .expect("upload `constructors_return_value` failed") .code_hash; @@ -224,7 +218,7 @@ mod call_builder { contract.call_instantiate(code_hash, invalid_selector, true) }); let call_result = client - .call(&mut ink_e2e::eve(), call, 0, None) + .call(&ink_e2e::eve(), call, 0, None) .await .expect("Client failed to call `call_builder::call_instantiate`.") .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 4d6db10cd76..22c531ecdcb 100644 --- a/examples/lang-err-integration-tests/constructors-return-value/lib.rs +++ b/examples/lang-err-integration-tests/constructors-return-value/lib.rs @@ -125,7 +125,7 @@ pub mod constructors_return_value { let success = client .instantiate( "constructors_return_value", - &mut ink_e2e::alice(), + &ink_e2e::alice(), constructor, 0, None, @@ -175,7 +175,7 @@ pub mod constructors_return_value { let contract_acc_id = client .instantiate( "constructors_return_value", - &mut ink_e2e::bob(), + &ink_e2e::bob(), constructor, 0, None, @@ -188,7 +188,7 @@ pub mod constructors_return_value { ink_e2e::build_message::(contract_acc_id) .call(|contract| contract.get_value()); let value = client - .call(&mut ink_e2e::bob(), get, 0, None) + .call(&ink_e2e::bob(), get, 0, None) .await .expect("Calling `get_value` failed") .value @@ -240,7 +240,7 @@ pub mod constructors_return_value { let result = client .instantiate( "constructors_return_value", - &mut ink_e2e::charlie(), + &ink_e2e::charlie(), constructor, 0, None, diff --git a/examples/lang-err-integration-tests/contract-ref/lib.rs b/examples/lang-err-integration-tests/contract-ref/lib.rs index 16b4e7806c7..e85f0634e9b 100755 --- a/examples/lang-err-integration-tests/contract-ref/lib.rs +++ b/examples/lang-err-integration-tests/contract-ref/lib.rs @@ -62,14 +62,14 @@ mod contract_ref { mut client: ink_e2e::Client, ) -> E2EResult<()> { let flipper_hash = client - .upload("integration_flipper", &mut ink_e2e::alice(), None) + .upload("integration_flipper", &ink_e2e::alice(), None) .await .expect("uploading `flipper` failed") .code_hash; let constructor = ContractRefRef::new(0, flipper_hash); let contract_acc_id = client - .instantiate("contract_ref", &mut ink_e2e::alice(), constructor, 0, None) + .instantiate("contract_ref", &ink_e2e::alice(), constructor, 0, None) .await .expect("instantiate failed") .account_id; @@ -77,7 +77,7 @@ mod contract_ref { let get_check = build_message::(contract_acc_id.clone()) .call(|contract| contract.get_check()); let get_call_result = client - .call(&mut ink_e2e::alice(), get_check, 0, None) + .call(&ink_e2e::alice(), get_check, 0, None) .await .expect("Calling `get_check` failed"); let initial_value = get_call_result @@ -87,7 +87,7 @@ mod contract_ref { let flip_check = build_message::(contract_acc_id.clone()) .call(|contract| contract.flip_check()); let flip_call_result = client - .call(&mut ink_e2e::alice(), flip_check, 0, None) + .call(&ink_e2e::alice(), flip_check, 0, None) .await .expect("Calling `flip` failed"); assert!( @@ -98,7 +98,7 @@ mod contract_ref { let get_check = build_message::(contract_acc_id.clone()) .call(|contract| contract.get_check()); let get_call_result = client - .call(&mut ink_e2e::alice(), get_check, 0, None) + .call(&ink_e2e::alice(), get_check, 0, None) .await .expect("Calling `get_check` failed"); let flipped_value = get_call_result diff --git a/examples/lang-err-integration-tests/integration-flipper/lib.rs b/examples/lang-err-integration-tests/integration-flipper/lib.rs index 0840694b080..a9858ba9c3e 100644 --- a/examples/lang-err-integration-tests/integration-flipper/lib.rs +++ b/examples/lang-err-integration-tests/integration-flipper/lib.rs @@ -62,7 +62,7 @@ pub mod integration_flipper { let contract_acc_id = client .instantiate( "integration_flipper", - &mut ink_e2e::alice(), + &ink_e2e::alice(), constructor, 0, None, @@ -74,7 +74,7 @@ pub mod integration_flipper { let get = build_message::(contract_acc_id.clone()) .call(|contract| contract.get()); let get_call_result = client - .call(&mut ink_e2e::alice(), get, 0, None) + .call(&ink_e2e::alice(), get, 0, None) .await .expect("Calling `get` failed"); let initial_value = get_call_result @@ -84,7 +84,7 @@ pub mod integration_flipper { let flip = build_message::(contract_acc_id) .call(|contract| contract.flip()); let flip_call_result = client - .call(&mut ink_e2e::alice(), flip, 0, None) + .call(&ink_e2e::alice(), flip, 0, None) .await .expect("Calling `flip` failed"); assert!( @@ -95,7 +95,7 @@ pub mod integration_flipper { let get = build_message::(contract_acc_id.clone()) .call(|contract| contract.get()); let get_call_result = client - .call(&mut ink_e2e::alice(), get, 0, None) + .call(&ink_e2e::alice(), get, 0, None) .await .expect("Calling `get` failed"); let flipped_value = get_call_result @@ -112,13 +112,7 @@ pub mod integration_flipper { ) -> E2EResult<()> { let constructor = FlipperRef::default(); let contract_acc_id = client - .instantiate( - "integration_flipper", - &mut ink_e2e::bob(), - constructor, - 0, - None, - ) + .instantiate("integration_flipper", &ink_e2e::bob(), constructor, 0, None) .await .expect("instantiate failed") .account_id; @@ -126,7 +120,7 @@ pub mod integration_flipper { let get = build_message::(contract_acc_id.clone()) .call(|contract| contract.get()); let get_call_result = client - .call(&mut ink_e2e::bob(), get, 0, None) + .call(&ink_e2e::bob(), get, 0, None) .await .expect("Calling `get` failed"); let initial_value = get_call_result @@ -136,7 +130,7 @@ pub mod integration_flipper { let err_flip = build_message::(contract_acc_id) .call(|contract| contract.err_flip()); let err_flip_call_result = - client.call(&mut ink_e2e::bob(), err_flip, 0, None).await; + client.call(&ink_e2e::bob(), err_flip, 0, None).await; assert!(matches!( err_flip_call_result, @@ -146,7 +140,7 @@ pub mod integration_flipper { let get = build_message::(contract_acc_id.clone()) .call(|contract| contract.get()); let get_call_result = client - .call(&mut ink_e2e::bob(), get, 0, None) + .call(&ink_e2e::bob(), get, 0, None) .await .expect("Calling `get` failed"); let flipped_value = get_call_result