From 8b54acaf652807d4e93cffc9b2b719751a939483 Mon Sep 17 00:00:00 2001 From: mertwole <33563701+mertwole@users.noreply.github.com> Date: Sat, 19 Aug 2023 18:17:20 +0400 Subject: [PATCH] refactoring(gsdk): structure gsdk API (#3035) --- gcli/src/cmd/claim.rs | 2 +- gcli/src/cmd/create.rs | 2 + gcli/src/cmd/reply.rs | 1 + gcli/src/cmd/send.rs | 1 + gcli/src/cmd/transfer.rs | 1 + gcli/src/cmd/upload.rs | 4 +- gclient/src/api/calls.rs | 18 ++++- gclient/src/api/rpc.rs | 4 + gsdk/src/signer/calls.rs | 159 ++++++++++++++++++++++----------------- gsdk/src/signer/mod.rs | 83 ++++++++++++++++++-- gsdk/src/signer/rpc.rs | 32 ++++++-- gsdk/src/signer/utils.rs | 19 +++-- gsdk/tests/rpc.rs | 13 +++- 13 files changed, 238 insertions(+), 101 deletions(-) diff --git a/gcli/src/cmd/claim.rs b/gcli/src/cmd/claim.rs index cd248d8a60d..730cbcff38d 100644 --- a/gcli/src/cmd/claim.rs +++ b/gcli/src/cmd/claim.rs @@ -32,7 +32,7 @@ impl Claim { pub async fn exec(&self, signer: Signer) -> Result<()> { let message_id = self.message_id.to_hash()?.into(); - signer.claim_value(message_id).await?; + signer.calls.claim_value(message_id).await?; Ok(()) } diff --git a/gcli/src/cmd/create.rs b/gcli/src/cmd/create.rs index fb7e4f9b513..0f30db2b585 100644 --- a/gcli/src/cmd/create.rs +++ b/gcli/src/cmd/create.rs @@ -50,6 +50,7 @@ impl Create { let gas = if self.gas_limit == 0 { signer + .rpc .calculate_create_gas(None, code_id, payload.clone(), self.value, false, None) .await? .min_limit @@ -62,6 +63,7 @@ impl Create { // create program signer + .calls .create_program(code_id, self.salt.to_vec()?, payload, gas_limit, self.value) .await?; diff --git a/gcli/src/cmd/reply.rs b/gcli/src/cmd/reply.rs index b2c4b60f56f..ebf48079fb9 100644 --- a/gcli/src/cmd/reply.rs +++ b/gcli/src/cmd/reply.rs @@ -57,6 +57,7 @@ impl Reply { let reply_to_id = self.reply_to_id.to_hash()?; signer + .calls .send_reply( reply_to_id.into(), self.payload.to_vec()?, diff --git a/gcli/src/cmd/send.rs b/gcli/src/cmd/send.rs index 551c4d033ff..8fee0608a0c 100644 --- a/gcli/src/cmd/send.rs +++ b/gcli/src/cmd/send.rs @@ -60,6 +60,7 @@ pub struct Send { impl Send { pub async fn exec(&self, signer: Signer) -> Result<()> { signer + .calls .send_message( self.destination.to_hash()?.into(), self.payload.to_vec()?, diff --git a/gcli/src/cmd/transfer.rs b/gcli/src/cmd/transfer.rs index 633239f9ce1..ff0f4feb956 100644 --- a/gcli/src/cmd/transfer.rs +++ b/gcli/src/cmd/transfer.rs @@ -50,6 +50,7 @@ impl Transfer { println!("Value: {}", self.value); signer + .calls .transfer(AccountId32::from_ss58check(&self.destination)?, self.value) .await?; diff --git a/gcli/src/cmd/upload.rs b/gcli/src/cmd/upload.rs index 1b9a115322f..34635284f92 100644 --- a/gcli/src/cmd/upload.rs +++ b/gcli/src/cmd/upload.rs @@ -49,13 +49,14 @@ impl Upload { pub async fn exec(&self, signer: Signer) -> Result<()> { let code = fs::read(&self.code)?; if self.code_only { - signer.upload_code(code).await?; + signer.calls.upload_code(code).await?; return Ok(()); } let payload = self.payload.to_vec()?; let gas = if self.gas_limit == 0 { signer + .rpc .calculate_upload_gas(None, code.clone(), payload.clone(), self.value, false, None) .await? .min_limit @@ -66,6 +67,7 @@ impl Upload { // Estimate gas and upload program. let gas_limit = signer.api().cmp_gas_limit(gas)?; signer + .calls .upload_program(code, self.salt.to_vec()?, payload, gas_limit, self.value) .await?; diff --git a/gclient/src/api/calls.rs b/gclient/src/api/calls.rs index 4d6cd0d3c39..bf4cee2aee7 100644 --- a/gclient/src/api/calls.rs +++ b/gclient/src/api/calls.rs @@ -98,7 +98,7 @@ impl GearApi { pub async fn transfer(&self, destination: ProgramId, value: u128) -> Result { let destination: [u8; 32] = destination.into(); - let tx = self.0.transfer(destination, value).await?; + let tx = self.0.calls.transfer(destination, value).await?; for event in tx.wait_for_success().await?.iter() { if let Event::Balances(BalancesEvent::Transfer { .. }) = @@ -165,6 +165,7 @@ impl GearApi { let tx = self .0 + .calls .create_program(code_id, salt, payload, gas_limit, value) .await?; @@ -357,16 +358,19 @@ impl GearApi { dest_node_api .0 + .storage .set_code_storage(src_code_id, &src_code) .await?; dest_node_api .0 + .storage .set_code_len_storage(src_code_id, src_code_len) .await?; dest_node_api .0 + .storage .set_gas_nodes(&src_program_reserved_gas_nodes) .await?; @@ -411,6 +415,7 @@ impl GearApi { dest_node_api .0 + .storage .set_total_issuance( dest_gas_total_issuance.saturating_add(src_program_reserved_gas_total), ) @@ -418,12 +423,14 @@ impl GearApi { dest_node_api .0 + .storage .set_gpages(dest_program_id, &src_program_pages) .await?; src_program.expiration_block = dest_node_api.last_block_number().await?; dest_node_api .0 + .storage .set_gprog(dest_program_id, src_program) .await?; @@ -513,7 +520,7 @@ impl GearApi { ) .await?; - self.0.set_gpages(program_id, &pages).await?; + self.0.storage.set_gpages(program_id, &pages).await?; Ok(()) } @@ -537,7 +544,7 @@ impl GearApi { .await? .map(|(message, _interval)| message.value()); - let tx = self.0.claim_value(message_id).await?; + let tx = self.0.calls.claim_value(message_id).await?; for event in tx.wait_for_success().await?.iter() { if let Event::Gear(GearEvent::UserMessageRead { .. }) = @@ -639,6 +646,7 @@ impl GearApi { let tx = self .0 + .calls .send_message(destination, payload, gas_limit, value, prepaid) .await?; @@ -754,6 +762,7 @@ impl GearApi { let tx = self .0 + .calls .send_reply(reply_to_id, payload, gas_limit, value, prepaid) .await?; @@ -884,7 +893,7 @@ impl GearApi { /// - [`upload_program`](Self::upload_program) function uploads a new /// program and initialize it. pub async fn upload_code(&self, code: impl AsRef<[u8]>) -> Result<(CodeId, H256)> { - let tx = self.0.upload_code(code.as_ref().to_vec()).await?; + let tx = self.0.calls.upload_code(code.as_ref().to_vec()).await?; for event in tx.wait_for_success().await?.iter() { if let Event::Gear(GearEvent::CodeChanged { @@ -999,6 +1008,7 @@ impl GearApi { let tx = self .0 + .calls .upload_program(code, salt, payload, gas_limit, value) .await?; diff --git a/gclient/src/api/rpc.rs b/gclient/src/api/rpc.rs index 13d435a968f..e1afb50312b 100644 --- a/gclient/src/api/rpc.rs +++ b/gclient/src/api/rpc.rs @@ -65,6 +65,7 @@ impl GearApi { at: Option, ) -> Result { self.0 + .rpc .calculate_create_gas(origin, code_id, payload, value, allow_other_panics, at) .await .map_err(Into::into) @@ -109,6 +110,7 @@ impl GearApi { at: Option, ) -> Result { self.0 + .rpc .calculate_upload_gas(origin, code, payload, value, allow_other_panics, at) .await .map_err(Into::into) @@ -158,6 +160,7 @@ impl GearApi { at: Option, ) -> Result { self.0 + .rpc .calculate_handle_gas(origin, destination, payload, value, allow_other_panics, at) .await .map_err(Into::into) @@ -203,6 +206,7 @@ impl GearApi { at: Option, ) -> Result { self.0 + .rpc .calculate_reply_gas(origin, message_id, payload, value, allow_other_panics, at) .await .map_err(Into::into) diff --git a/gsdk/src/signer/calls.rs b/gsdk/src/signer/calls.rs index d7aef241e9f..d148d92af2a 100644 --- a/gsdk/src/signer/calls.rs +++ b/gsdk/src/signer/calls.rs @@ -17,6 +17,7 @@ // along with this program. If not, see . //! gear api calls +use super::SignerInner; use crate::{ config::GearConfig, metadata::{ @@ -32,7 +33,7 @@ use crate::{ sudo::Event as SudoEvent, Event, }, - signer::Signer, + signer::SignerRpc, utils::storage_address_bytes, Api, BlockNumber, Error, GearGasNode, GearGasNodeId, GearPages, Result, TxInBlock, TxStatus, }; @@ -44,6 +45,7 @@ use gear_core::{ use hex::ToHex; use parity_scale_codec::Encode; use sp_runtime::AccountId32; +use std::sync::Arc; use subxt::{ blocks::ExtrinsicEvents, dynamic::Value, @@ -57,23 +59,32 @@ use subxt::{ type TxProgressT = TxProgress>; type EventsResult = Result, Error>; +/// Implementation of calls to programs/other users for [`Signer`]. +#[derive(Clone)] +pub struct SignerCalls(pub(crate) Arc); + +/// Implementation of storage calls for [`Signer`]. +#[derive(Clone)] +pub struct SignerStorage(pub(crate) Arc); + // pallet-balances -impl Signer { +impl SignerCalls { /// `pallet_balances::transfer` pub async fn transfer(&self, dest: impl Into, value: u128) -> Result { - self.run_tx( - BalancesCall::Transfer, - vec![ - Value::unnamed_variant("Id", [Value::from_bytes(dest.into())]), - Value::u128(value), - ], - ) - .await + self.0 + .run_tx( + BalancesCall::Transfer, + vec![ + Value::unnamed_variant("Id", [Value::from_bytes(dest.into())]), + Value::u128(value), + ], + ) + .await } } // pallet-gear -impl Signer { +impl SignerCalls { /// `pallet_gear::create_program` pub async fn create_program( &self, @@ -83,22 +94,24 @@ impl Signer { gas_limit: u64, value: u128, ) -> Result { - self.run_tx( - GearCall::CreateProgram, - vec![ - Value::from_bytes(code_id), - Value::from_bytes(salt), - Value::from_bytes(payload), - Value::u128(gas_limit as u128), - Value::u128(value), - ], - ) - .await + self.0 + .run_tx( + GearCall::CreateProgram, + vec![ + Value::from_bytes(code_id), + Value::from_bytes(salt), + Value::from_bytes(payload), + Value::u128(gas_limit as u128), + Value::u128(value), + ], + ) + .await } /// `pallet_gear::claim_value` pub async fn claim_value(&self, message_id: MessageId) -> Result { - self.run_tx(GearCall::ClaimValue, vec![Value::from_bytes(message_id)]) + self.0 + .run_tx(GearCall::ClaimValue, vec![Value::from_bytes(message_id)]) .await } @@ -111,17 +124,18 @@ impl Signer { value: u128, prepaid: bool, ) -> Result { - self.run_tx( - GearCall::SendMessage, - vec![ - Value::from_bytes(destination), - Value::from_bytes(payload), - Value::u128(gas_limit as u128), - Value::u128(value), - Value::bool(prepaid), - ], - ) - .await + self.0 + .run_tx( + GearCall::SendMessage, + vec![ + Value::from_bytes(destination), + Value::from_bytes(payload), + Value::u128(gas_limit as u128), + Value::u128(value), + Value::bool(prepaid), + ], + ) + .await } /// `pallet_gear::send_reply` @@ -133,22 +147,24 @@ impl Signer { value: u128, prepaid: bool, ) -> Result { - self.run_tx( - GearCall::SendReply, - vec![ - Value::from_bytes(reply_to_id), - Value::from_bytes(payload), - Value::u128(gas_limit as u128), - Value::u128(value), - Value::bool(prepaid), - ], - ) - .await + self.0 + .run_tx( + GearCall::SendReply, + vec![ + Value::from_bytes(reply_to_id), + Value::from_bytes(payload), + Value::u128(gas_limit as u128), + Value::u128(value), + Value::bool(prepaid), + ], + ) + .await } /// `pallet_gear::upload_code` pub async fn upload_code(&self, code: Vec) -> Result { - self.run_tx(GearCall::UploadCode, vec![Value::from_bytes(code)]) + self.0 + .run_tx(GearCall::UploadCode, vec![Value::from_bytes(code)]) .await } @@ -161,22 +177,23 @@ impl Signer { gas_limit: u64, value: u128, ) -> Result { - self.run_tx( - GearCall::UploadProgram, - vec![ - Value::from_bytes(code), - Value::from_bytes(salt), - Value::from_bytes(payload), - Value::u128(gas_limit as u128), - Value::u128(value), - ], - ) - .await + self.0 + .run_tx( + GearCall::UploadProgram, + vec![ + Value::from_bytes(code), + Value::from_bytes(salt), + Value::from_bytes(payload), + Value::u128(gas_limit as u128), + Value::u128(value), + ], + ) + .await } } // pallet-utility -impl Signer { +impl SignerInner { /// `pallet_utility::force_batch` pub async fn force_batch(&self, calls: Vec) -> Result { self.run_tx( @@ -188,7 +205,7 @@ impl Signer { } // pallet-sudo -impl Signer { +impl SignerInner { pub async fn process_sudo(&self, tx: DynamicPayload) -> EventsResult { let tx = self.process(tx).await?; let events = tx.wait_for_success().await?; @@ -229,10 +246,10 @@ impl Signer { } // pallet-system -impl Signer { +impl SignerStorage { /// Sets storage values via calling sudo pallet pub async fn set_storage(&self, items: &[(impl StorageAddress, impl Encode)]) -> EventsResult { - let metadata = self.api().metadata(); + let metadata = self.0.api().metadata(); let mut items_to_set = Vec::with_capacity(items.len()); for item in items { let item_key = storage_address_bytes(&item.0, &metadata)?; @@ -246,15 +263,16 @@ impl Signer { items_to_set.push((item_key, item_value_bytes)); } - self.sudo(RuntimeCall::System(Call::set_storage { - items: items_to_set, - })) - .await + self.0 + .sudo(RuntimeCall::System(Call::set_storage { + items: items_to_set, + })) + .await } } // pallet-gas -impl Signer { +impl SignerStorage { /// Writes gas total issuance into storage. pub async fn set_total_issuance(&self, value: u64) -> EventsResult { let addr = Api::storage_root(GearGasStorage::TotalIssuance); @@ -277,7 +295,7 @@ impl Signer { } // pallet-gear-program -impl Signer { +impl SignerStorage { /// Writes `InstrumentedCode` length into storage at `CodeId` pub async fn set_code_len_storage(&self, code_id: CodeId, code_len: u32) -> EventsResult { let addr = Api::storage( @@ -334,7 +352,7 @@ impl Signer { } // Singer utils -impl Signer { +impl SignerInner { /// Propagates log::info for given status. pub(crate) fn log_status(&self, status: &TxStatus) { match status { @@ -382,7 +400,9 @@ impl Signer { pub async fn process<'a>(&self, tx: DynamicPayload) -> Result { use subxt::tx::TxStatus::*; - let before = self.balance().await?; + let signer_rpc = SignerRpc(Arc::new(self.clone())); + let before = signer_rpc.get_balance().await?; + let mut process = self.sign_and_submit_then_watch(&tx).await?; let (pallet, name) = (tx.pallet_name(), tx.call_name()); @@ -401,7 +421,6 @@ impl Signer { b.extrinsic_hash(), b.block_hash() ); - self.log_balance_spent(before).await?; return Ok(b); } diff --git a/gsdk/src/signer/mod.rs b/gsdk/src/signer/mod.rs index c421673bc69..d8e1f1161b5 100644 --- a/gsdk/src/signer/mod.rs +++ b/gsdk/src/signer/mod.rs @@ -17,22 +17,44 @@ // along with this program. If not, see . //! Gear api with signer + use crate::{ config::GearConfig, result::{Error, Result}, Api, }; +use calls::{SignerCalls, SignerStorage}; +use core::ops::Deref; pub use pair_signer::PairSigner; +use rpc::SignerRpc; use sp_core::{crypto::Ss58Codec, sr25519::Pair, Pair as PairT}; use sp_runtime::AccountId32; +use std::sync::Arc; mod calls; mod pair_signer; mod rpc; mod utils; +/// Signer representation that provides access to gear API. +/// Implements low-level methods such as [`run_tx`](`SignerInner::run_tx`) +/// and [`force_batch`](`SignerInner::force_batch`). +/// Other higher-level calls are provided by [`Signer::storage`], +/// [`Signer::calls`], [`Signer::rpc`]. #[derive(Clone)] pub struct Signer { + signer: Arc, + /// Calls that get or set storage. + pub storage: SignerStorage, + /// Calls for interaction with on-chain programs. + pub calls: SignerCalls, + /// Calls to fetch data from node. + pub rpc: SignerRpc, +} + +/// Implementation of low-level calls for [`Signer`]. +#[derive(Clone)] +pub struct SignerInner { api: Api, /// Current signer. signer: PairSigner, @@ -42,32 +64,69 @@ pub struct Signer { impl Signer { /// New signer api. pub fn new(api: Api, suri: &str, passwd: Option<&str>) -> Result { - Ok(Self { + let signer = SignerInner { api, signer: PairSigner::new( Pair::from_string(suri, passwd).map_err(|_| Error::InvalidSecret)?, ), nonce: None, - }) + }; + + Ok(Self::from_inner(signer)) + } + + fn from_inner(signer: SignerInner) -> Self { + let signer = Arc::new(signer); + + Self { + storage: SignerStorage(signer.clone()), + calls: SignerCalls(signer.clone()), + rpc: SignerRpc(signer.clone()), + signer, + } + } + + #[deny(unused_variables)] + fn replace_inner(&mut self, inner: SignerInner) { + let Signer { + signer, + storage, + calls, + rpc, + } = self; + + *signer = Arc::new(inner); + *storage = SignerStorage(signer.clone()); + *calls = SignerCalls(signer.clone()); + *rpc = SignerRpc(signer.clone()); } /// Change inner signer. pub fn change(mut self, suri: &str, passwd: Option<&str>) -> Result { let signer = PairSigner::new(Pair::from_string(suri, passwd).map_err(|_| Error::InvalidSecret)?); - self.signer = signer; + + self.replace_inner(SignerInner { + signer, + ..self.signer.as_ref().clone() + }); Ok(self) } /// Set nonce of the signer pub fn set_nonce(&mut self, nonce: u32) { - self.nonce = Some(nonce) + self.replace_inner(SignerInner { + nonce: Some(nonce), + ..self.signer.as_ref().clone() + }); } +} +impl SignerInner { /// Get address of the current signer pub fn address(&self) -> String { - self.signer.account_id().to_ss58check() + self.account_id().to_ss58check() } /// Get address of the current signer @@ -83,10 +142,20 @@ impl Signer { impl From<(Api, PairSigner)> for Signer { fn from((api, signer): (Api, PairSigner)) -> Self { - Signer { + let signer = SignerInner { api, signer, nonce: None, - } + }; + + Self::from_inner(signer) + } +} + +impl Deref for Signer { + type Target = SignerInner; + + fn deref(&self) -> &SignerInner { + self.signer.as_ref() } } diff --git a/gsdk/src/signer/rpc.rs b/gsdk/src/signer/rpc.rs index 6fa642be1c1..912531fd809 100644 --- a/gsdk/src/signer/rpc.rs +++ b/gsdk/src/signer/rpc.rs @@ -18,14 +18,28 @@ //! RPC calls with signer -use crate::{result::Result, signer::Signer, GasInfo}; +use crate::{result::Result, signer::SignerInner, GasInfo}; use gear_core::ids::{CodeId, MessageId, ProgramId}; use sp_core::H256; +use std::sync::Arc; -impl Signer { +/// Implementation of calls to node RPC for [`Signer`]. +#[derive(Clone)] +pub struct SignerRpc(pub(crate) Arc); + +impl SignerRpc { /// public key of the signer in H256 pub fn source(&self) -> H256 { - AsRef::<[u8; 32]>::as_ref(self.signer.account_id()).into() + AsRef::<[u8; 32]>::as_ref(self.0.account_id()).into() + } + + /// Get self balance. + pub async fn get_balance(&self) -> Result { + self.0 + .as_ref() + .api() + .get_balance(&self.0.as_ref().address()) + .await } /// gear_calculateInitCreateGas @@ -38,7 +52,8 @@ impl Signer { allow_other_panics: bool, at: Option, ) -> Result { - self.api + self.0 + .api .calculate_create_gas( origin.unwrap_or_else(|| self.source()), code_id, @@ -60,7 +75,8 @@ impl Signer { allow_other_panics: bool, at: Option, ) -> Result { - self.api + self.0 + .api .calculate_upload_gas( origin.unwrap_or_else(|| self.source()), code, @@ -82,7 +98,8 @@ impl Signer { allow_other_panics: bool, at: Option, ) -> Result { - self.api + self.0 + .api .calculate_handle_gas( origin.unwrap_or_else(|| self.source()), destination, @@ -104,7 +121,8 @@ impl Signer { allow_other_panics: bool, at: Option, ) -> Result { - self.api + self.0 + .api .calculate_reply_gas( origin.unwrap_or_else(|| self.source()), message_id, diff --git a/gsdk/src/signer/utils.rs b/gsdk/src/signer/utils.rs index e815cf92efc..f4d88a5f4a5 100644 --- a/gsdk/src/signer/utils.rs +++ b/gsdk/src/signer/utils.rs @@ -18,23 +18,22 @@ //! Utils +use std::sync::Arc; + +use super::SignerInner; use crate::{ - config::GearConfig, metadata::CallInfo, result::Result, signer::Signer, Error, TxInBlock, + config::GearConfig, metadata::CallInfo, result::Result, signer::SignerRpc, Error, TxInBlock, }; use scale_value::Composite; use subxt::blocks::ExtrinsicEvents; type EventsResult = Result, Error>; -impl Signer { - /// Get self balance - pub async fn balance(&self) -> Result { - self.api().get_balance(&self.address()).await - } - +impl SignerInner { /// Logging balance spent pub async fn log_balance_spent(&self, before: u128) -> Result<()> { - let after = before.saturating_sub(self.balance().await?); + let signer_rpc = SignerRpc(Arc::new(self.clone())); + let after = before.saturating_sub(signer_rpc.get_balance().await?); log::info!(" Balance spent: {after}"); Ok(()) @@ -46,7 +45,7 @@ impl Signer { /// /// # You may not need this. /// - /// Read the docs of [`Signer`] to checkout the wrappred transactions, + /// Read the docs of [`Signer`](`super::Signer`) to checkout the wrappred transactions, /// we need this function only when we want to execute a transaction /// which has not been wrapped in `gsdk`. /// @@ -74,7 +73,7 @@ impl Signer { /// // The code above euqals to: /// /// { - /// let in_block = signer.transfer(dest, value).await?; + /// let in_block = signer.calls.transfer(dest, value).await?; /// } /// /// // ... diff --git a/gsdk/tests/rpc.rs b/gsdk/tests/rpc.rs index 8d4d111cd39..ec375c5b6d0 100644 --- a/gsdk/tests/rpc.rs +++ b/gsdk/tests/rpc.rs @@ -84,16 +84,19 @@ async fn test_calculate_create_gas() -> Result<()> { .await? .signer("//Alice", None)?; signer + .calls .upload_code(demo_messager::WASM_BINARY.to_vec()) .await?; // 2. calculate create gas and create program. let code_id = CodeId::generate(demo_messager::WASM_BINARY); let gas_info = signer + .rpc .calculate_create_gas(None, code_id, vec![], 0, true, None) .await?; signer + .calls .create_program(code_id, vec![], vec![], gas_info.min_limit, 0) .await?; @@ -113,6 +116,7 @@ async fn test_calculate_handle_gas() -> Result<()> { .signer("//Alice", None)?; signer + .calls .upload_program( demo_messager::WASM_BINARY.to_vec(), salt, @@ -126,10 +130,12 @@ async fn test_calculate_handle_gas() -> Result<()> { // 2. calculate handle gas and send message. let gas_info = signer + .rpc .calculate_handle_gas(None, pid, vec![], 0, true, None) .await?; signer + .calls .send_message(pid, vec![], gas_info.min_limit, 0, false) .await?; @@ -151,6 +157,7 @@ async fn test_calculate_reply_gas() -> Result<()> { .await? .signer("//Alice", None)?; signer + .calls .upload_program( demo_waiter::WASM_BINARY.to_vec(), salt, @@ -164,6 +171,7 @@ async fn test_calculate_reply_gas() -> Result<()> { // 2. send wait message. signer + .calls .send_message(pid, payload.encode(), 100_000_000_000, 0, false) .await?; @@ -176,10 +184,12 @@ async fn test_calculate_reply_gas() -> Result<()> { // 3. calculate reply gas and send reply. let gas_info = signer + .rpc .calculate_reply_gas(None, message_id, vec![], 0, true, None) .await?; signer + .calls .send_reply(message_id, vec![], gas_info.min_limit, 0, false) .await?; @@ -278,6 +288,7 @@ async fn test_original_code_storage() -> Result<()> { .signer("//Alice", None)?; signer + .calls .upload_program( demo_messager::WASM_BINARY.to_vec(), salt, @@ -290,7 +301,7 @@ async fn test_original_code_storage() -> Result<()> { let program = signer.api().gprog(pid).await?; let rpc = signer.api().rpc(); let last_block = rpc.block(None).await?.unwrap().block.header.number(); - let block_hash = rpc.block_hash(Some(last_block.into())).await?.unwrap(); + let block_hash = rpc.block_hash(Some(last_block.into())).await?; let code = signer .api() .original_code_storage_at(program.code_hash.0.into(), block_hash)