diff --git a/examples/new-meta/tests/read_state.rs b/examples/new-meta/tests/read_state.rs deleted file mode 100644 index 8060bf13022..00000000000 --- a/examples/new-meta/tests/read_state.rs +++ /dev/null @@ -1,196 +0,0 @@ -use demo_new_meta::{ - MessageInitIn, Person, Wallet, META_EXPORTS_V1, META_EXPORTS_V2, META_WASM_V1, META_WASM_V2, -}; -use gstd::Encode; -use gtest::{constants::DEFAULT_USER_ALICE, state_args, state_args_encoded, Program, System}; - -#[test] -fn read_state_bytes_returns_full_state() { - let system = System::new(); - let program = initialize_current_program(&system); - - let actual_state = program - .read_state_bytes(Default::default()) - .expect("Unable to read program state"); - - let expected_state = Wallet::test_sequence().encode(); - - assert_eq!(actual_state, expected_state); -} - -#[test] -fn read_state_bytes_with_wasm_func_returns_transformed_state() { - let system = System::new(); - let program = initialize_current_program(&system); - const FUNC_NAME: &str = "first_wallet"; - assert!(META_EXPORTS_V1.contains(&FUNC_NAME)); - - let actual_state = program - .read_state_bytes_using_wasm( - Default::default(), - FUNC_NAME, - META_WASM_V1.to_vec(), - state_args_encoded!(), - ) - .expect("Unable to read program state"); - - let expected_state = Wallet::test_sequence().first().encode(); - - assert_eq!(expected_state, actual_state); -} - -#[test] -fn read_state_bytes_with_parameterized_wasm_func_returns_transformed_state() { - let system = System::new(); - let program = initialize_current_program(&system); - const FUNC_NAME: &str = "wallet_by_person"; - assert!(META_EXPORTS_V2.contains(&FUNC_NAME)); - let other_person = Person { - surname: "OtherSurname".into(), - name: "OtherName".into(), - }; - - let actual_state = program - .read_state_bytes_using_wasm( - Default::default(), - FUNC_NAME, - META_WASM_V2.to_vec(), - state_args_encoded!(&other_person), - ) - .expect("Unable to read program state"); - - let expected_state = Wallet::test_sequence() - .into_iter() - .find(|wallet| wallet.person == other_person) - .encode(); - - assert_eq!(expected_state, actual_state); -} - -#[test] -fn read_state_bytes_with_two_args_wasm_func_returns_transformed_state() { - let system = System::new(); - let program = initialize_current_program(&system); - const FUNC_NAME: &str = "wallet_by_name_and_surname"; - assert!(META_EXPORTS_V2.contains(&FUNC_NAME)); - - let name = "OtherName".to_string(); - let surname = "OtherSurname".to_string(); - - let actual_state = program - .read_state_bytes_using_wasm( - Default::default(), - FUNC_NAME, - META_WASM_V2.to_vec(), - state_args_encoded!(name.clone(), surname.clone()), - ) - .expect("Unable to read program state"); - - let expected_state = Wallet::test_sequence() - .into_iter() - .find(|wallet| wallet.person.name == name && wallet.person.surname == surname) - .encode(); - - assert_eq!(expected_state, actual_state); -} - -#[test] -fn read_state_returns_full_state() { - let system = System::new(); - let program = initialize_current_program(&system); - - let actual_state: Vec = program - .read_state(Vec::::default()) - .expect("Unable to read program state"); - - let expected_state = Wallet::test_sequence(); - - assert_eq!(actual_state, expected_state); -} - -#[test] -fn read_state_with_wasm_func_returns_transformed_state() { - let system = System::new(); - let program = initialize_current_program(&system); - const FUNC_NAME: &str = "first_wallet"; - assert!(META_EXPORTS_V1.contains(&FUNC_NAME)); - - let actual_state: Option = program - .read_state_using_wasm( - Vec::::default(), - FUNC_NAME, - META_WASM_V1.to_vec(), - state_args!(), - ) - .expect("Unable to read program state"); - - let expected_state = Wallet::test_sequence().first().cloned(); - - assert_eq!(expected_state, actual_state); -} - -#[test] -fn read_state_with_parameterized_wasm_func_returns_transformed_state() { - let system = System::new(); - let program = initialize_current_program(&system); - const FUNC_NAME: &str = "wallet_by_person"; - assert!(META_EXPORTS_V2.contains(&FUNC_NAME)); - let other_person = Person { - surname: "OtherSurname".into(), - name: "OtherName".into(), - }; - - let actual_state: Option = program - .read_state_using_wasm( - Vec::::default(), - FUNC_NAME, - META_WASM_V2.to_vec(), - state_args!(other_person.clone()), - ) - .expect("Unable to read program state"); - - let expected_state = Wallet::test_sequence() - .into_iter() - .find(|wallet| wallet.person == other_person); - - assert_eq!(expected_state, actual_state); -} - -#[test] -fn read_state_with_two_args_wasm_func_returns_transformed_state() { - let system = System::new(); - let program = initialize_current_program(&system); - const FUNC_NAME: &str = "wallet_by_name_and_surname"; - assert!(META_EXPORTS_V2.contains(&FUNC_NAME)); - - let name = "OtherName".to_string(); - let surname = "OtherSurname".to_string(); - - let actual_state: Option = program - .read_state_using_wasm( - Vec::::default(), - FUNC_NAME, - META_WASM_V2.to_vec(), - state_args!(name.clone(), surname.clone()), - ) - .expect("Unable to read program state"); - - let expected_state = Wallet::test_sequence() - .into_iter() - .find(|wallet| wallet.person.name == name && wallet.person.surname == surname); - - assert_eq!(expected_state, actual_state); -} - -fn initialize_current_program(system: &System) -> Program { - let program = Program::current(system); - program.send( - DEFAULT_USER_ALICE, - MessageInitIn { - amount: 123, - currency: "USD".into(), - }, - ); - system.run_next_block(); - program -} diff --git a/gcli/src/cmd/program.rs b/gcli/src/cmd/program.rs index d51e97019e1..ce5117950f9 100644 --- a/gcli/src/cmd/program.rs +++ b/gcli/src/cmd/program.rs @@ -50,15 +50,6 @@ pub enum Program { State { /// Program id. pid: H256, - /// Method of reading state from wasm (hex encoding). - #[arg(short, long)] - method: Option, - /// The path of "*.meta.wasm". - #[arg(short, long)] - wasm: Option>, - /// Method arguments (hex encoding). - #[arg(short, long)] - args: Option>, /// The block hash for reading state. #[arg(long)] at: Option, @@ -78,21 +69,9 @@ impl Program { /// Run command program. pub async fn exec(&self, app: &impl App) -> Result<()> { match self { - Program::State { - pid, - method, - wasm, - args, - at, - } => { + Program::State { pid, at } => { let api = app.signer().await?; - if let (Some(wasm), Some(method)) = (wasm, method) { - // read state from wasm. - Self::wasm_state(&api, *pid, wasm.to_vec(), method, args.clone(), *at).await?; - } else { - // read full state - Self::full_state(&api, *pid, *at).await?; - } + Self::full_state(&api, *pid, *at).await?; } Program::Meta { meta, @@ -112,28 +91,6 @@ impl Program { Ok(()) } - async fn wasm_state( - api: &GearApi, - pid: H256, - wasm: Vec, - method: &str, - args: Option>, - at: Option, - ) -> Result<()> { - let state = api - .read_state_bytes_using_wasm_at( - pid.0.into(), - Default::default(), - method, - wasm, - args, - at, - ) - .await?; - println!("0x{}", hex::encode(state)); - Ok(()) - } - async fn full_state(api: &GearApi, pid: H256, at: Option) -> Result<()> { let state = api .read_state_bytes_at(pid.0.into(), Default::default(), at) diff --git a/gclient/src/api/rpc.rs b/gclient/src/api/rpc.rs index ac4d192a24f..bf3d320ffbc 100644 --- a/gclient/src/api/rpc.rs +++ b/gclient/src/api/rpc.rs @@ -23,10 +23,7 @@ use gear_core::{ message::ReplyInfo, }; use gsdk::{ext::sp_core::H256, GasInfo}; -use parity_scale_codec::{Decode, Encode}; -use std::path::Path; - -use crate::utils; +use parity_scale_codec::Decode; impl GearApi { /// Execute an RPC to calculate the gas required to create a program from a @@ -261,157 +258,6 @@ impl GearApi { D::decode(&mut bytes.as_ref()).map_err(Into::into) } - /// Read the program's state as a byte vector using a meta Wasm. - pub async fn read_state_bytes_using_wasm( - &self, - program_id: ProgramId, - payload: Vec, - fn_name: &str, - wasm: Vec, - argument: Option>, - ) -> Result> { - self.read_state_bytes_using_wasm_at(program_id, payload, fn_name, wasm, argument, None) - .await - } - - /// Same as [`read_state_bytes_using_wasm`](Self::read_state_bytes_using_wasm), but reads the program's state at the block identified by its hash. - pub async fn read_state_bytes_using_wasm_at( - &self, - program_id: ProgramId, - payload: Vec, - fn_name: &str, - wasm: Vec, - argument: Option>, - at: Option, - ) -> Result> { - let response: String = self - .0 - .api() - .read_state_using_wasm( - H256(program_id.into()), - payload, - fn_name, - wasm, - argument, - at, - ) - .await?; - crate::utils::hex_to_vec(response).map_err(Into::into) - } - - /// Read the program's state as decoded data using a meta Wasm. - pub async fn read_state_using_wasm( - &self, - program_id: ProgramId, - payload: Vec, - fn_name: &str, - wasm: Vec, - argument: Option, - ) -> Result { - self.read_state_using_wasm_at(program_id, payload, fn_name, wasm, argument, None) - .await - } - - /// Same as [`read_state_using_wasm`](Self::read_state_using_wasm), but - /// reads the program's state at the block identified by its hash. - pub async fn read_state_using_wasm_at( - &self, - program_id: ProgramId, - payload: Vec, - fn_name: &str, - wasm: Vec, - argument: Option, - at: Option, - ) -> Result { - let bytes = self - .read_state_bytes_using_wasm_at( - program_id, - payload, - fn_name, - wasm, - argument.map(|v| v.encode()), - at, - ) - .await?; - - D::decode(&mut bytes.as_ref()).map_err(Into::into) - } - - /// Read the program's state using a meta Wasm file referenced by its - /// `path`. - pub async fn read_state_bytes_using_wasm_by_path( - &self, - program_id: ProgramId, - payload: Vec, - fn_name: &str, - path: impl AsRef, - argument: Option>, - ) -> Result> { - self.read_state_bytes_using_wasm_by_path_at( - program_id, payload, fn_name, path, argument, None, - ) - .await - } - - /// Same as [`read_state_using_wasm_by_path`](Self::read_state_using_wasm_by_path), but reads the program's state at the block identified by its hash. - pub async fn read_state_bytes_using_wasm_by_path_at( - &self, - program_id: ProgramId, - payload: Vec, - fn_name: &str, - path: impl AsRef, - argument: Option>, - at: Option, - ) -> Result> { - self.read_state_bytes_using_wasm_at( - program_id, - payload, - fn_name, - utils::code_from_os(path.as_ref())?, - argument, - at, - ) - .await - } - - /// Read the program's state using a meta Wasm file referenced by its - /// `path`. - pub async fn read_state_using_wasm_by_path( - &self, - program_id: ProgramId, - payload: Vec, - fn_name: &str, - path: impl AsRef, - argument: Option, - ) -> Result { - self.read_state_using_wasm_by_path_at(program_id, payload, fn_name, path, argument, None) - .await - } - - /// Same as [`read_state_using_wasm_by_path`](Self::read_state_using_wasm_by_path), but reads the program's state at the block identified by its hash. - pub async fn read_state_using_wasm_by_path_at( - &self, - program_id: ProgramId, - payload: Vec, - fn_name: &str, - path: impl AsRef, - argument: Option, - at: Option, - ) -> Result { - let bytes = self - .read_state_bytes_using_wasm_by_path_at( - program_id, - payload, - fn_name, - path, - argument.map(|v| v.encode()), - at, - ) - .await?; - - D::decode(&mut bytes.as_ref()).map_err(Into::into) - } - /// Read the program's metahash. pub async fn read_metahash(&self, program_id: ProgramId) -> Result { self.read_metahash_at(program_id, None).await diff --git a/gclient/tests/state.rs b/gclient/tests/state.rs deleted file mode 100644 index 0eec34dcdbb..00000000000 --- a/gclient/tests/state.rs +++ /dev/null @@ -1,147 +0,0 @@ -// This file is part of Gear. - -// Copyright (C) 2021-2024 Gear Technologies Inc. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -use demo_meta_io::Wallet; -use gclient::{EventProcessor, GearApi}; -use gmeta::MetadataRepr; -use parity_scale_codec::{Decode, Encode}; - -#[tokio::test] -async fn get_state() -> anyhow::Result<()> { - let api = GearApi::dev_from_path("../target/release/gear").await?; - - // Subscribe to events - let mut listener = api.subscribe().await?; - - // Check that blocks are still running - assert!(listener.blocks_running().await?); - - // Calculate gas amount needed for initialization - let gas_info = api - .calculate_upload_gas(None, demo_new_meta::WASM_BINARY.to_vec(), vec![], 0, true) - .await?; - - // Upload and init the program - let (message_id, program_id, _hash) = api - .upload_program_bytes( - demo_new_meta::WASM_BINARY, - gclient::now_micros().to_le_bytes(), - vec![], - gas_info.min_limit, - 0, - ) - .await?; - - assert!(listener.message_processed(message_id).await?.succeed()); - - // Read and check `metahash` - let actual_metahash = api.read_metahash(program_id).await?.0; - - let expected_metahash = MetadataRepr::from_bytes(demo_new_meta::WASM_METADATA) - .expect("Failed to read meta from bytes") - .hash(); - - assert_eq!(actual_metahash, expected_metahash); - - // Read state bytes - let state = api.read_state_bytes(program_id, Default::default()).await?; - let wallets = Vec::::decode(&mut state.as_ref()).expect("Unable to decode"); - assert_eq!(wallets.len(), 2); - - // Read state using Wasm - let wallet: Option = api - .read_state_using_wasm( - program_id, - Default::default(), - "first_wallet", - demo_new_meta::META_WASM_V1.to_vec(), - >::None, - ) - .await?; - let wallet = wallet.expect("No wallet"); - - assert_eq!(wallet.id.decimal, 1); - assert_eq!(wallet.person.surname, "SomeSurname"); - assert_eq!(wallet.person.name, "SomeName"); - - Ok(()) -} - -#[tokio::test] -async fn get_state_request() -> anyhow::Result<()> { - use demo_custom::{btree, InitMessage, WASM_BINARY}; - - let gas_limit = 100_000_000_000; - - let api = GearApi::dev_from_path("../target/release/gear").await?; - - // Or use this comment to run test on custom node - // let api = GearApi::dev().await?.with("//Alice")?; - - // Subscribe to events - let mut listener = api.subscribe().await?; - - // Check that blocks are still running - assert!(listener.blocks_running().await?); - - // Upload btree program and wait initialization is done - let (message_id, program_id, _hash) = api - .upload_program_bytes( - WASM_BINARY, - gclient::now_micros().to_le_bytes(), - InitMessage::BTree.encode(), - gas_limit, - 0, - ) - .await?; - assert!(listener.message_processed(message_id).await?.succeed()); - - let data = [(0u32, 1u32), (1, 2), (3, 4)]; - let batch = data.map(|(key, value)| { - ( - program_id, - btree::Request::Insert(key, value).encode(), - gas_limit, - 0, - ) - }); - - // Store some data in btree and wait the results - let message_ids = api - .send_message_bytes_batch(batch) - .await - .unwrap() - .0 - .into_iter() - .map(|res| res.unwrap().0); - listener - .message_processed_batch(message_ids.into_iter()) - .await? - .into_iter() - .for_each(|(_, status)| assert!(status.succeed())); - - // Check state can be read by one key - for (key, value) in data { - let res: Option = api - .read_state(program_id, btree::StateRequest::ForKey(key).encode()) - .await?; - assert_eq!(res, Some(value)); - } - - Ok(()) -} diff --git a/gsdk/src/rpc.rs b/gsdk/src/rpc.rs index eaad5614282..da1c2170d38 100644 --- a/gsdk/src/rpc.rs +++ b/gsdk/src/rpc.rs @@ -155,32 +155,6 @@ impl Api { .map_err(Into::into) } - /// gear_readStateUsingWasm - pub async fn read_state_using_wasm( - &self, - pid: H256, - payload: Vec, - method: &str, - wasm: Vec, - args: Option>, - at: Option, - ) -> Result { - self.rpc() - .request( - "gear_readStateUsingWasm", - rpc_params![ - pid, - hex::encode(payload), - hex::encode(method), - hex::encode(wasm), - args.map(hex::encode), - at - ], - ) - .await - .map_err(Into::into) - } - /// runtime_wasmBlobVersion pub async fn runtime_wasm_blob_version(&self, at: Option) -> Result { self.rpc() diff --git a/gtest/src/manager.rs b/gtest/src/manager.rs index e636df9af71..7c614cf5cfe 100644 --- a/gtest/src/manager.rs +++ b/gtest/src/manager.rs @@ -49,7 +49,7 @@ use gear_common::{ LockId, Origin, }; use gear_core::{ - code::{Code, CodeAndId, InstrumentedCode, InstrumentedCodeAndId, TryNewCodeConfig}, + code::InstrumentedCode, gas_metering::{DbWeights, RentWeights, Schedule}, ids::{prelude::*, CodeId, MessageId, ProgramId, ReservationId}, memory::PageBuf, diff --git a/gtest/src/manager/memory.rs b/gtest/src/manager/memory.rs index 643d6d82404..abeb3b12ec1 100644 --- a/gtest/src/manager/memory.rs +++ b/gtest/src/manager/memory.rs @@ -55,41 +55,6 @@ impl ExtManager { Err(TestError::ActorIsNotExecutable(*program_id)) } } - - pub(crate) fn read_state_bytes_using_wasm( - &mut self, - payload: Vec, - program_id: &ProgramId, - fn_name: &str, - wasm: Vec, - args: Option>, - ) -> Result> { - let mapping_code = Code::try_new_mock_const_or_no_rules( - wasm, - true, - TryNewCodeConfig::new_no_exports_check(), - ) - .map_err(|_| TestError::Instrumentation)?; - - let mapping_code = InstrumentedCodeAndId::from(CodeAndId::new(mapping_code)) - .into_parts() - .0; - - let mut mapping_code_payload = args.unwrap_or_default(); - mapping_code_payload.append(&mut self.read_state_bytes(payload, program_id)?); - - core_processor::informational::execute_for_reply::, _>( - String::from(fn_name), - mapping_code, - None, - None, - mapping_code_payload, - GAS_ALLOWANCE, - self.blocks_manager.get(), - ) - .map_err(TestError::ReadStateError) - } - pub(crate) fn read_memory_pages(&self, program_id: &ProgramId) -> BTreeMap { Actors::access(*program_id, |actor| { let program = match actor.unwrap_or_else(|| panic!("Actor id {program_id:?} not found")) diff --git a/gtest/src/program.rs b/gtest/src/program.rs index f9ea282fd41..926b2f54264 100644 --- a/gtest/src/program.rs +++ b/gtest/src/program.rs @@ -188,46 +188,6 @@ impl From<&str> for ProgramIdWrapper { } } -/// Construct state arguments. -/// -/// Used for reading and decoding the program’s transformed state, -/// see [`Program::read_state_using_wasm`] for example. -#[macro_export] -macro_rules! state_args { - () => { - Option::<()>::None - }; - ($single:expr) => { - Some($single) - }; - ($($multiple:expr),*) => { - Some(($($multiple,)*)) - }; -} - -/// Construct encoded state arguments. -/// -/// Used for reading the program’s transformed state as a byte vector, -/// see [`Program::read_state_bytes_using_wasm`] for example. -#[macro_export] -macro_rules! state_args_encoded { - () => { - Option::>::None - }; - ($single:expr) => { - { - use $crate::codec::Encode; - Some(($single).encode()) - } - }; - ($($multiple:expr),*) => { - { - use $crate::codec::Encode; - Some((($($multiple,)*)).encode()) - } - }; -} - /// Builder for [`Program`]. #[must_use = "`build()` must be called at the end"] #[derive(Debug, Clone)] @@ -616,128 +576,12 @@ impl<'a> Program<'a> { .read_state_bytes(payload, &self.id) } - /// Reads the program’s transformed state as a byte vector. The transformed - /// state is a result of applying the `fn_name` function from the `wasm` - /// binary with the optional `argument`. - /// - /// # Usage - /// You can pass arguments as `Option<(arg1, arg2, ...).encode()>` or by - /// using [`state_args_encoded`] macro. - /// - /// # Examples - /// - /// ``` - /// # use gtest::{state_args_encoded, Program, System, WasmProgram, Result}; - /// # use codec::Encode; - /// # fn doctest() -> Result<()> { - /// # #[derive(Debug)] - /// # struct MockWasm {} - /// # - /// # impl WasmProgram for MockWasm { - /// # fn init(&mut self, _payload: Vec) -> Result>, &'static str> { unimplemented!() } - /// # fn handle(&mut self, _payload: Vec) -> Result>, &'static str> { unimplemented!() } - /// # fn handle_reply(&mut self, _payload: Vec) -> Result<(), &'static str> {unimplemented!() } - /// # fn handle_signal(&mut self, _payload: Vec) -> Result<(), &'static str> { unimplemented!() } - /// # fn state(&mut self) -> Result, &'static str> { unimplemented!() } - /// # } - /// # let system = System::new(); - /// # let program = Program::mock(&system, MockWasm { }); - /// # let ARG_1 = 0u8; - /// # let ARG_2 = 0u8; - /// //Read state bytes with no arguments passed to wasm. - /// # let WASM = vec![]; - /// let _ = program.read_state_bytes_using_wasm(Default::default(), "fn_name", WASM, Option::>::None)?; - /// # let WASM = vec![]; - /// let _ = program.read_state_bytes_using_wasm(Default::default(), "fn_name", WASM, state_args_encoded!())?; - /// // Read state bytes with one argument passed to wasm. - /// # let WASM = vec![]; - /// let _ = program.read_state_bytes_using_wasm(Default::default(), "fn_name", WASM, Some(ARG_1.encode()))?; - /// # let WASM = vec![]; - /// let _ = program.read_state_bytes_using_wasm(Default::default(), "fn_name", WASM, state_args_encoded!(ARG_1))?; - /// // Read state bytes with multiple arguments passed to wasm. - /// # let WASM = vec![]; - /// let _ = program.read_state_bytes_using_wasm(Default::default(), "fn_name", WASM, Some((ARG_1, ARG_2).encode()))?; - /// # let WASM = vec![]; - /// let _ = program.read_state_bytes_using_wasm(Default::default(), "fn_name", WASM, state_args_encoded!(ARG_1, ARG_2))?; - /// # Ok(()) - /// # } - /// ``` - pub fn read_state_bytes_using_wasm( - &self, - payload: Vec, - fn_name: &str, - wasm: Vec, - args: Option>, - ) -> Result> { - self.manager - .borrow_mut() - .read_state_bytes_using_wasm(payload, &self.id, fn_name, wasm, args) - } - /// Reads and decodes the program's state . pub fn read_state(&self, payload: P) -> Result { let state_bytes = self.read_state_bytes(payload.encode())?; D::decode(&mut state_bytes.as_ref()).map_err(Into::into) } - /// Reads and decodes the program’s transformed state. The transformed state - /// is a result of applying the `fn_name` function from the `wasm` - /// binary with the optional `argument`. - /// - /// # Usage - /// You can pass arguments as `Option<(arg1, arg2, ...)>` or by - /// using [`state_args`] macro. - /// - /// # Examples - /// - /// ``` - /// # use gtest::{state_args, Program, System, WasmProgram, Result}; - /// # fn doctest() -> Result<()> { - /// # #[derive(Debug)] - /// # struct MockWasm; - /// # - /// # impl WasmProgram for MockWasm { - /// # fn init(&mut self, _payload: Vec) -> Result>, &'static str> { unimplemented!() } - /// # fn handle(&mut self, _payload: Vec) -> Result>, &'static str> { unimplemented!() } - /// # fn handle_reply(&mut self, _payload: Vec) -> Result<(), &'static str> {unimplemented!() } - /// # fn handle_signal(&mut self, _payload: Vec) -> Result<(), &'static str> { unimplemented!() } - /// # fn state(&mut self) -> Result, &'static str> { unimplemented!() } - /// # } - /// # let system = System::new(); - /// # let program = Program::mock(&system, MockWasm); - /// # let ARG_1 = 0u8; - /// # let ARG_2 = 0u8; - /// //Read state bytes with no arguments passed to wasm. - /// # let WASM = vec![]; - /// let _ = program.read_state_using_wasm(Vec::::default(), "fn_name", WASM, Option::<()>::None)?; - /// # let WASM = vec![]; - /// let _ = program.read_state_using_wasm(Vec::::default(), "fn_name", WASM, state_args!())?; - /// // Read state bytes with one argument passed to wasm. - /// # let WASM = vec![]; - /// let _ = program.read_state_using_wasm(Vec::::default(), "fn_name", WASM, Some(ARG_1))?; - /// # let WASM = vec![]; - /// let _ = program.read_state_using_wasm(Vec::::default(), "fn_name", WASM, state_args!(ARG_1))?; - /// // Read state bytes with multiple arguments passed to wasm. - /// # let WASM = vec![]; - /// let _ = program.read_state_using_wasm(Vec::::default(), "fn_name", WASM, Some((ARG_1, ARG_2)))?; - /// # let WASM = vec![]; - /// let _ = program.read_state_using_wasm(Vec::::default(), "fn_name", WASM, state_args!(ARG_1, ARG_2))?; - /// # Ok(()) - /// # } - /// ``` - pub fn read_state_using_wasm( - &self, - payload: P, - fn_name: &str, - wasm: Vec, - argument: Option, - ) -> Result { - let argument_bytes = argument.map(|arg| arg.encode()); - let state_bytes = - self.read_state_bytes_using_wasm(payload.encode(), fn_name, wasm, argument_bytes)?; - D::decode(&mut state_bytes.as_ref()).map_err(Into::into) - } - /// Returns the balance of the account. pub fn balance(&self) -> Value { self.manager.borrow().balance_of(&self.id()) diff --git a/utils/cargo-gbuild/tests/smoke.rs b/utils/cargo-gbuild/tests/smoke.rs index e8ac4612612..94744cd0e71 100644 --- a/utils/cargo-gbuild/tests/smoke.rs +++ b/utils/cargo-gbuild/tests/smoke.rs @@ -18,8 +18,8 @@ use anyhow::Result; use cargo_gbuild::GBuild; -use gtest::{constants::DEFAULT_USER_ALICE, state_args, Program, System}; -use std::{fs, path::PathBuf, process::Command}; +use gtest::{constants::DEFAULT_USER_ALICE, Program, System}; +use std::{path::PathBuf, process::Command}; fn ping(sys: &System, prog: PathBuf) -> Program<'_> { // Get program from artifact @@ -61,14 +61,8 @@ fn test_compile() -> Result<()> { gbuild = gbuild.workspace(); let artifacts = gbuild.build()?; ping(&system, artifacts.root.join("gbuild_test_foo.wasm")); - let prog = ping(&system, artifacts.root.join("gbuild_test_bar.wasm")); + ping(&system, artifacts.root.join("gbuild_test_bar.wasm")); - // 3. Test meta build. - let metawasm = fs::read(artifacts.root.join("gbuild_test_meta.meta.wasm"))?; - let modified: bool = prog - .read_state_using_wasm(Vec::::default(), "modified", metawasm, state_args!()) - .expect("Failed to read program state"); - assert!(modified); Ok(()) }