From 88310e048e8ee315bf9c80d64e27c6e672efe161 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Mon, 9 Sep 2024 08:41:36 +0000 Subject: [PATCH 01/11] Added upload_with_access --- cw-orch-daemon/src/core.rs | 26 ++++++++++++-- cw-orch-daemon/src/sync/core.rs | 11 ++++++ .../src/contract/contract_instance.rs | 34 +++++++++++++++++++ .../src/contract/interface_traits.rs | 9 +++++ packages/cw-orch-core/src/environment/mod.rs | 2 +- .../src/environment/tx_handler.rs | 17 ++++++++++ packages/cw-orch-mock/src/core.rs | 11 +++++- 7 files changed, 106 insertions(+), 4 deletions(-) diff --git a/cw-orch-daemon/src/core.rs b/cw-orch-daemon/src/core.rs index 8e1b882bc..726503514 100644 --- a/cw-orch-daemon/src/core.rs +++ b/cw-orch-daemon/src/core.rs @@ -17,7 +17,9 @@ use cosmrs::{ use cosmwasm_std::{Addr, Binary, Coin}; use cw_orch_core::{ contract::interface_traits::Uploadable, - environment::{AsyncWasmQuerier, ChainInfoOwned, ChainState, IndexResponse, Querier}, + environment::{ + AccessConfig, AsyncWasmQuerier, ChainInfoOwned, ChainState, IndexResponse, Querier, + }, log::transaction_target, }; use flate2::{write, Compression}; @@ -342,8 +344,17 @@ impl DaemonAsyncBase { /// Upload a contract to the chain. pub async fn upload( + &self, + uploadable: &T, + ) -> Result { + self.upload_with_access(uploadable, None).await + } + + /// Upload a contract to the chain. + pub async fn upload_with_access( &self, _uploadable: &T, + access: Option, ) -> Result { let wasm_path = ::wasm(self.chain_info()); @@ -356,7 +367,18 @@ impl DaemonAsyncBase { let store_msg = cosmrs::cosmwasm::MsgStoreCode { sender: self.sender().account_id(), wasm_byte_code, - instantiate_permission: None, + instantiate_permission: access + .map(|a| { + Ok::<_, DaemonError>(cosmrs::cosmwasm::AccessConfig { + permission: a.permission.try_into().unwrap(), + addresses: a + .addresses + .into_iter() + .map(|a| a.parse()) + .collect::>()?, + }) + }) + .transpose()?, }; let result = self diff --git a/cw-orch-daemon/src/sync/core.rs b/cw-orch-daemon/src/sync/core.rs index 1ec49a82d..d5d4fe28f 100644 --- a/cw-orch-daemon/src/sync/core.rs +++ b/cw-orch-daemon/src/sync/core.rs @@ -219,6 +219,17 @@ impl TxHandler for DaemonBase { .instantiate2(code_id, init_msg, label, admin, coins, salt), ) } + + fn upload_with_access( + &self, + contract_source: &T, + access_config: cw_orch_core::environment::AccessConfig, + ) -> Result { + self.rt_handle.block_on( + self.daemon + .upload_with_access(contract_source, Some(access_config)), + ) + } } impl Stargate for DaemonBase { diff --git a/packages/cw-orch-core/src/contract/contract_instance.rs b/packages/cw-orch-core/src/contract/contract_instance.rs index b0c7cfe47..9d16ff6c1 100644 --- a/packages/cw-orch-core/src/contract/contract_instance.rs +++ b/packages/cw-orch-core/src/contract/contract_instance.rs @@ -10,6 +10,7 @@ use crate::{ }; use crate::environment::QueryHandler; +use cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig; use cosmwasm_std::{Addr, Binary, Coin}; use serde::{de::DeserializeOwned, Serialize}; use std::fmt::Debug; @@ -102,6 +103,39 @@ impl Contract { impl Contract { // Chain interfaces + /// Upload a contract given its source and access control option + pub fn upload_with_access( + &self, + source: &impl Uploadable, + access_config: AccessConfig, + ) -> Result, CwEnvError> { + log::info!( + target: &contract_target(), + "[{}][Upload]", + self.id, + ); + + let resp = self + .chain + .upload_with_access(source, access_config) + .map_err(Into::into)?; + let code_id = resp.uploaded_code_id()?; + self.set_code_id(code_id); + log::info!( + target: &contract_target(), + "[{}][Uploaded] code_id {}", + self.id, + code_id + ); + log::debug!( + target: &contract_target(), + "[{}][Uploaded] response {:?}", + self.id, + resp + ); + Ok(resp) + } + /// Upload a contract given its source pub fn upload(&self, source: &impl Uploadable) -> Result, CwEnvError> { log::info!( diff --git a/packages/cw-orch-core/src/contract/interface_traits.rs b/packages/cw-orch-core/src/contract/interface_traits.rs index 5748ba8ff..4cb5f6cd6 100644 --- a/packages/cw-orch-core/src/contract/interface_traits.rs +++ b/packages/cw-orch-core/src/contract/interface_traits.rs @@ -7,6 +7,7 @@ use crate::{ error::CwEnvError, log::contract_target, }; +use cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig; use cosmwasm_std::{Addr, Binary, Coin, Empty}; use cw_multi_test::Contract as MockContract; use cw_storage_plus::{Item, Map, PrimaryKey}; @@ -261,6 +262,14 @@ pub trait CwOrchUpload: ContractInstance + Uploadable + fn upload(&self) -> Result { self.as_instance().upload(self) } + + /// upload the contract to the configured environment with access configuration. + fn upload_with_access( + &self, + access_config: AccessConfig, + ) -> Result { + self.as_instance().upload_with_access(self, access_config) + } } /// enable `.upload()` for contracts that implement `Uploadable` for that environment. diff --git a/packages/cw-orch-core/src/environment/mod.rs b/packages/cw-orch-core/src/environment/mod.rs index faf6bc470..db0c2ac17 100644 --- a/packages/cw-orch-core/src/environment/mod.rs +++ b/packages/cw-orch-core/src/environment/mod.rs @@ -16,4 +16,4 @@ pub use queriers::{ DefaultQueriers, Querier, QuerierGetter, QueryHandler, }; pub use state::{ChainState, StateInterface}; -pub use tx_handler::{TxHandler, TxResponse}; +pub use tx_handler::{TxHandler, TxResponse, AccessConfig}; diff --git a/packages/cw-orch-core/src/environment/tx_handler.rs b/packages/cw-orch-core/src/environment/tx_handler.rs index edd829e47..8316dc87e 100644 --- a/packages/cw-orch-core/src/environment/tx_handler.rs +++ b/packages/cw-orch-core/src/environment/tx_handler.rs @@ -6,6 +6,8 @@ use cosmwasm_std::{Addr, Binary, Coin}; use serde::Serialize; use std::fmt::Debug; +pub use cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig; + /// Response type for actions on an environment pub type TxResponse = ::Response; @@ -35,6 +37,13 @@ pub trait TxHandler: ChainState + Clone { /// Uploads a contract to the chain. fn upload(&self, contract_source: &T) -> Result; + /// Uploads a contract to the chain, and configure the access control to that code instantiation. + fn upload_with_access( + &self, + contract_source: &T, + access_config: AccessConfig, + ) -> Result; + /// Send a InstantiateMsg to a contract. fn instantiate( &self, @@ -203,6 +212,14 @@ mod tests { ) -> Result { unimplemented!() } + + fn upload_with_access( + &self, + _contract_source: &T, + _access_config: AccessConfig, + ) -> Result { + unimplemented!() + } } fn associated_error(t: T) -> anyhow::Result<()> { diff --git a/packages/cw-orch-mock/src/core.rs b/packages/cw-orch-mock/src/core.rs index 7d9313722..40c3937b1 100644 --- a/packages/cw-orch-mock/src/core.rs +++ b/packages/cw-orch-mock/src/core.rs @@ -13,7 +13,7 @@ use serde::Serialize; use super::state::MockState; use cw_orch_core::{ contract::interface_traits::Uploadable, - environment::{ChainState, IndexResponse, StateInterface, TxHandler}, + environment::{AccessConfig, ChainState, IndexResponse, StateInterface, TxHandler}, CwEnvError, }; @@ -248,6 +248,15 @@ impl TxHandler for MockBase { ) .map_err(From::from) } + + fn upload_with_access( + &self, + contract_source: &T, + _access_config: AccessConfig, + ) -> Result { + log::debug!("Uploading with access is not enforced when using Mock testing"); + self.upload(contract_source) + } } #[cfg(test)] From 4f735edab2cce754e6f6fc5cd3f529c4233c0b3c Mon Sep 17 00:00:00 2001 From: Kayanski Date: Mon, 9 Sep 2024 08:41:47 +0000 Subject: [PATCH 02/11] formatting --- packages/cw-orch-core/src/environment/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cw-orch-core/src/environment/mod.rs b/packages/cw-orch-core/src/environment/mod.rs index db0c2ac17..fc1202720 100644 --- a/packages/cw-orch-core/src/environment/mod.rs +++ b/packages/cw-orch-core/src/environment/mod.rs @@ -16,4 +16,4 @@ pub use queriers::{ DefaultQueriers, Querier, QuerierGetter, QueryHandler, }; pub use state::{ChainState, StateInterface}; -pub use tx_handler::{TxHandler, TxResponse, AccessConfig}; +pub use tx_handler::{AccessConfig, TxHandler, TxResponse}; From d8fb7aa5d36d97756118f40290fede630c4a4be6 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Mon, 9 Sep 2024 09:21:40 +0000 Subject: [PATCH 03/11] Option instead of struct for accessconfig --- cw-orch-daemon/src/core.rs | 4 +-- cw-orch-daemon/src/sync/core.rs | 6 ++-- .../src/contract/contract_instance.rs | 29 +++---------------- .../src/contract/interface_traits.rs | 7 +++-- .../src/environment/tx_handler.rs | 8 ++--- packages/cw-orch-mock/src/core.rs | 4 +-- 6 files changed, 19 insertions(+), 39 deletions(-) diff --git a/cw-orch-daemon/src/core.rs b/cw-orch-daemon/src/core.rs index 726503514..366f6c7d2 100644 --- a/cw-orch-daemon/src/core.rs +++ b/cw-orch-daemon/src/core.rs @@ -347,11 +347,11 @@ impl DaemonAsyncBase { &self, uploadable: &T, ) -> Result { - self.upload_with_access(uploadable, None).await + self.upload_with_access_config(uploadable, None).await } /// Upload a contract to the chain. - pub async fn upload_with_access( + pub async fn upload_with_access_config( &self, _uploadable: &T, access: Option, diff --git a/cw-orch-daemon/src/sync/core.rs b/cw-orch-daemon/src/sync/core.rs index d5d4fe28f..f675d168c 100644 --- a/cw-orch-daemon/src/sync/core.rs +++ b/cw-orch-daemon/src/sync/core.rs @@ -220,14 +220,14 @@ impl TxHandler for DaemonBase { ) } - fn upload_with_access( + fn upload_with_access_config( &self, contract_source: &T, - access_config: cw_orch_core::environment::AccessConfig, + access_config: Option, ) -> Result { self.rt_handle.block_on( self.daemon - .upload_with_access(contract_source, Some(access_config)), + .upload_with_access_config(contract_source, access_config), ) } } diff --git a/packages/cw-orch-core/src/contract/contract_instance.rs b/packages/cw-orch-core/src/contract/contract_instance.rs index 9d16ff6c1..cf59cdef0 100644 --- a/packages/cw-orch-core/src/contract/contract_instance.rs +++ b/packages/cw-orch-core/src/contract/contract_instance.rs @@ -104,10 +104,10 @@ impl Contract { // Chain interfaces /// Upload a contract given its source and access control option - pub fn upload_with_access( + pub fn upload_with_access_config( &self, source: &impl Uploadable, - access_config: AccessConfig, + access_config: Option, ) -> Result, CwEnvError> { log::info!( target: &contract_target(), @@ -117,7 +117,7 @@ impl Contract { let resp = self .chain - .upload_with_access(source, access_config) + .upload_with_access_config(source, access_config) .map_err(Into::into)?; let code_id = resp.uploaded_code_id()?; self.set_code_id(code_id); @@ -138,28 +138,7 @@ impl Contract { /// Upload a contract given its source pub fn upload(&self, source: &impl Uploadable) -> Result, CwEnvError> { - log::info!( - target: &contract_target(), - "[{}][Upload]", - self.id, - ); - - let resp = self.chain.upload(source).map_err(Into::into)?; - let code_id = resp.uploaded_code_id()?; - self.set_code_id(code_id); - log::info!( - target: &contract_target(), - "[{}][Uploaded] code_id {}", - self.id, - code_id - ); - log::debug!( - target: &contract_target(), - "[{}][Uploaded] response {:?}", - self.id, - resp - ); - Ok(resp) + self.upload_with_access_config(source, None) } /// Executes an operation on the contract diff --git a/packages/cw-orch-core/src/contract/interface_traits.rs b/packages/cw-orch-core/src/contract/interface_traits.rs index 4cb5f6cd6..e86ce19c4 100644 --- a/packages/cw-orch-core/src/contract/interface_traits.rs +++ b/packages/cw-orch-core/src/contract/interface_traits.rs @@ -264,11 +264,12 @@ pub trait CwOrchUpload: ContractInstance + Uploadable + } /// upload the contract to the configured environment with access configuration. - fn upload_with_access( + fn upload_with_access_config( &self, - access_config: AccessConfig, + access_config: Option, ) -> Result { - self.as_instance().upload_with_access(self, access_config) + self.as_instance() + .upload_with_access_config(self, access_config) } } diff --git a/packages/cw-orch-core/src/environment/tx_handler.rs b/packages/cw-orch-core/src/environment/tx_handler.rs index 8316dc87e..0365d4896 100644 --- a/packages/cw-orch-core/src/environment/tx_handler.rs +++ b/packages/cw-orch-core/src/environment/tx_handler.rs @@ -38,10 +38,10 @@ pub trait TxHandler: ChainState + Clone { fn upload(&self, contract_source: &T) -> Result; /// Uploads a contract to the chain, and configure the access control to that code instantiation. - fn upload_with_access( + fn upload_with_access_config( &self, contract_source: &T, - access_config: AccessConfig, + access_config: Option, ) -> Result; /// Send a InstantiateMsg to a contract. @@ -213,10 +213,10 @@ mod tests { unimplemented!() } - fn upload_with_access( + fn upload_with_access_config( &self, _contract_source: &T, - _access_config: AccessConfig, + _access_config: Option, ) -> Result { unimplemented!() } diff --git a/packages/cw-orch-mock/src/core.rs b/packages/cw-orch-mock/src/core.rs index 40c3937b1..9d376a489 100644 --- a/packages/cw-orch-mock/src/core.rs +++ b/packages/cw-orch-mock/src/core.rs @@ -249,10 +249,10 @@ impl TxHandler for MockBase { .map_err(From::from) } - fn upload_with_access( + fn upload_with_access_config( &self, contract_source: &T, - _access_config: AccessConfig, + _access_config: Option, ) -> Result { log::debug!("Uploading with access is not enforced when using Mock testing"); self.upload(contract_source) From 012eee8b1fcfe4583f7f0d44f94ff3d3ad0cd093 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Mon, 9 Sep 2024 09:23:08 +0000 Subject: [PATCH 04/11] Better docs --- cw-orch-daemon/src/core.rs | 2 +- packages/cw-orch-core/src/contract/contract_instance.rs | 2 +- packages/cw-orch-core/src/contract/interface_traits.rs | 2 +- packages/cw-orch-core/src/environment/tx_handler.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cw-orch-daemon/src/core.rs b/cw-orch-daemon/src/core.rs index 366f6c7d2..0738edd2b 100644 --- a/cw-orch-daemon/src/core.rs +++ b/cw-orch-daemon/src/core.rs @@ -350,7 +350,7 @@ impl DaemonAsyncBase { self.upload_with_access_config(uploadable, None).await } - /// Upload a contract to the chain. + /// Upload a contract to the chain and specify the permissions for instantiating pub async fn upload_with_access_config( &self, _uploadable: &T, diff --git a/packages/cw-orch-core/src/contract/contract_instance.rs b/packages/cw-orch-core/src/contract/contract_instance.rs index cf59cdef0..521043d0d 100644 --- a/packages/cw-orch-core/src/contract/contract_instance.rs +++ b/packages/cw-orch-core/src/contract/contract_instance.rs @@ -103,7 +103,7 @@ impl Contract { impl Contract { // Chain interfaces - /// Upload a contract given its source and access control option + /// Upload a contract given its source and specify the permissions for instantiating pub fn upload_with_access_config( &self, source: &impl Uploadable, diff --git a/packages/cw-orch-core/src/contract/interface_traits.rs b/packages/cw-orch-core/src/contract/interface_traits.rs index e86ce19c4..f08d9b3a2 100644 --- a/packages/cw-orch-core/src/contract/interface_traits.rs +++ b/packages/cw-orch-core/src/contract/interface_traits.rs @@ -263,7 +263,7 @@ pub trait CwOrchUpload: ContractInstance + Uploadable + self.as_instance().upload(self) } - /// upload the contract to the configured environment with access configuration. + /// upload the contract to the configured environment and specify the permissions for instantiating fn upload_with_access_config( &self, access_config: Option, diff --git a/packages/cw-orch-core/src/environment/tx_handler.rs b/packages/cw-orch-core/src/environment/tx_handler.rs index 0365d4896..c24f1d636 100644 --- a/packages/cw-orch-core/src/environment/tx_handler.rs +++ b/packages/cw-orch-core/src/environment/tx_handler.rs @@ -37,7 +37,7 @@ pub trait TxHandler: ChainState + Clone { /// Uploads a contract to the chain. fn upload(&self, contract_source: &T) -> Result; - /// Uploads a contract to the chain, and configure the access control to that code instantiation. + /// Uploads a contract to the chain and specify the permissions for instantiating fn upload_with_access_config( &self, contract_source: &T, From 8e174b3be635911d062d2ebb2b2a83d9bd35a4f6 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Mon, 9 Sep 2024 09:24:15 +0000 Subject: [PATCH 05/11] Chanelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86cd91383..9a5fb87ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unpublished +- Add a method on TxHandler to select instantiation permissions on Wasm upload + ### Breaking ## 0.25.0 From 68f1715b5498f9bc63646bdf2a97df60cbc6cee8 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Mon, 9 Sep 2024 09:28:33 +0000 Subject: [PATCH 06/11] nit --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a5fb87ec..9ef0ecd33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unpublished -- Add a method on TxHandler to select instantiation permissions on Wasm upload +- Add a method on `TxHandler` to select instantiation permissions on Wasm upload ### Breaking From 4b8833880d7614c8adf59ea457f8b4227ba55b0a Mon Sep 17 00:00:00 2001 From: Kayanski Date: Mon, 9 Sep 2024 12:06:56 +0000 Subject: [PATCH 07/11] Better API and avoid exposing un-necessary dependencies --- cw-orch-daemon/src/core.rs | 26 +++++++++++----- cw-orch/src/prelude.rs | 5 ++-- .../src/contract/contract_instance.rs | 2 +- .../src/contract/interface_traits.rs | 2 +- .../src/environment/tx_handler.rs | 30 +++++++++++++++++-- 5 files changed, 51 insertions(+), 14 deletions(-) diff --git a/cw-orch-daemon/src/core.rs b/cw-orch-daemon/src/core.rs index 0738edd2b..39d017cee 100644 --- a/cw-orch-daemon/src/core.rs +++ b/cw-orch-daemon/src/core.rs @@ -369,14 +369,24 @@ impl DaemonAsyncBase { wasm_byte_code, instantiate_permission: access .map(|a| { - Ok::<_, DaemonError>(cosmrs::cosmwasm::AccessConfig { - permission: a.permission.try_into().unwrap(), - addresses: a - .addresses - .into_iter() - .map(|a| a.parse()) - .collect::>()?, - }) + let response = match a { + AccessConfig::Nobody => cosmrs::cosmwasm::AccessConfig { + permission: cosmrs::cosmwasm::AccessType::Nobody, + addresses: vec![], + }, + AccessConfig::Everybody => cosmrs::cosmwasm::AccessConfig { + permission: cosmrs::cosmwasm::AccessType::Everybody, + addresses: vec![], + }, + AccessConfig::AnyOfAddresses(addresses) => cosmrs::cosmwasm::AccessConfig { + permission: cosmrs::cosmwasm::AccessType::AnyOfAddresses, + addresses: addresses + .into_iter() + .map(|a| a.parse()) + .collect::>()?, + }, + }; + Ok::<_, DaemonError>(response) }) .transpose()?, }; diff --git a/cw-orch/src/prelude.rs b/cw-orch/src/prelude.rs index 79bf61aba..574c7f528 100644 --- a/cw-orch/src/prelude.rs +++ b/cw-orch/src/prelude.rs @@ -27,8 +27,9 @@ pub use crate::environment::IndexResponse; // Environment pub use crate::environment::{ - BankQuerier, BankSetter, CwEnv, DefaultQueriers, EnvironmentInfo, EnvironmentQuerier, - NodeQuerier, QuerierGetter, QueryHandler, TxHandler, TxResponse, WasmQuerier, + AccessConfig, BankQuerier, BankSetter, CwEnv, DefaultQueriers, EnvironmentInfo, + EnvironmentQuerier, NodeQuerier, QuerierGetter, QueryHandler, TxHandler, TxResponse, + WasmQuerier, }; pub use cw_orch_core::environment::Environment; diff --git a/packages/cw-orch-core/src/contract/contract_instance.rs b/packages/cw-orch-core/src/contract/contract_instance.rs index 521043d0d..1958d45e2 100644 --- a/packages/cw-orch-core/src/contract/contract_instance.rs +++ b/packages/cw-orch-core/src/contract/contract_instance.rs @@ -9,8 +9,8 @@ use crate::{ log::{contract_target, transaction_target}, }; +use crate::environment::AccessConfig; use crate::environment::QueryHandler; -use cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig; use cosmwasm_std::{Addr, Binary, Coin}; use serde::{de::DeserializeOwned, Serialize}; use std::fmt::Debug; diff --git a/packages/cw-orch-core/src/contract/interface_traits.rs b/packages/cw-orch-core/src/contract/interface_traits.rs index f08d9b3a2..352cf777e 100644 --- a/packages/cw-orch-core/src/contract/interface_traits.rs +++ b/packages/cw-orch-core/src/contract/interface_traits.rs @@ -1,4 +1,5 @@ use super::{Contract, WasmPath}; +use crate::environment::AccessConfig; use crate::{ environment::{ AsyncWasmQuerier, ChainInfoOwned, ChainState, CwEnv, Environment, QueryHandler, TxHandler, @@ -7,7 +8,6 @@ use crate::{ error::CwEnvError, log::contract_target, }; -use cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig; use cosmwasm_std::{Addr, Binary, Coin, Empty}; use cw_multi_test::Contract as MockContract; use cw_storage_plus::{Item, Map, PrimaryKey}; diff --git a/packages/cw-orch-core/src/environment/tx_handler.rs b/packages/cw-orch-core/src/environment/tx_handler.rs index c24f1d636..86d019d7e 100644 --- a/packages/cw-orch-core/src/environment/tx_handler.rs +++ b/packages/cw-orch-core/src/environment/tx_handler.rs @@ -6,8 +6,6 @@ use cosmwasm_std::{Addr, Binary, Coin}; use serde::Serialize; use std::fmt::Debug; -pub use cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig; - /// Response type for actions on an environment pub type TxResponse = ::Response; @@ -90,6 +88,34 @@ pub trait TxHandler: ChainState + Clone { } } +pub enum AccessConfig { + Nobody, + Everybody, + AnyOfAddresses(Vec), +} + +impl From for cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig { + fn from(val: AccessConfig) -> Self { + match val { + AccessConfig::Nobody => cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig { + permission: cosmos_sdk_proto::cosmwasm::wasm::v1::AccessType::Nobody.into(), + addresses: vec![], + }, + AccessConfig::Everybody => cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig { + permission: cosmos_sdk_proto::cosmwasm::wasm::v1::AccessType::Everybody.into(), + addresses: vec![], + }, + AccessConfig::AnyOfAddresses(addresses) => { + cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig { + permission: cosmos_sdk_proto::cosmwasm::wasm::v1::AccessType::AnyOfAddresses + .into(), + addresses, + } + } + } + } +} + // TODO: Perfect test candidate for `trybuild` #[cfg(test)] mod tests { From 1f2d07fce74ea999a559dbc6f73df3228ee3d0ff Mon Sep 17 00:00:00 2001 From: Kayanski Date: Mon, 9 Sep 2024 12:09:17 +0000 Subject: [PATCH 08/11] Nits --- cw-orch-daemon/src/core.rs | 1 + packages/cw-orch-core/src/environment/tx_handler.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/cw-orch-daemon/src/core.rs b/cw-orch-daemon/src/core.rs index 39d017cee..25b9e915f 100644 --- a/cw-orch-daemon/src/core.rs +++ b/cw-orch-daemon/src/core.rs @@ -385,6 +385,7 @@ impl DaemonAsyncBase { .map(|a| a.parse()) .collect::>()?, }, + _ => unimplemented!(), }; Ok::<_, DaemonError>(response) }) diff --git a/packages/cw-orch-core/src/environment/tx_handler.rs b/packages/cw-orch-core/src/environment/tx_handler.rs index 86d019d7e..c26376c61 100644 --- a/packages/cw-orch-core/src/environment/tx_handler.rs +++ b/packages/cw-orch-core/src/environment/tx_handler.rs @@ -88,6 +88,7 @@ pub trait TxHandler: ChainState + Clone { } } +#[non_exhaustive] pub enum AccessConfig { Nobody, Everybody, From 47f495474401db53ec755e3ece4531e1c0c4fc02 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Wed, 11 Sep 2024 13:07:23 +0000 Subject: [PATCH 09/11] Nit --- cw-orch-daemon/src/core.rs | 51 ++++++++++--------- cw-orch/src/prelude.rs | 5 +- .../src/environment/tx_handler.rs | 6 ++- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/cw-orch-daemon/src/core.rs b/cw-orch-daemon/src/core.rs index 25b9e915f..e2164e2a9 100644 --- a/cw-orch-daemon/src/core.rs +++ b/cw-orch-daemon/src/core.rs @@ -367,29 +367,7 @@ impl DaemonAsyncBase { let store_msg = cosmrs::cosmwasm::MsgStoreCode { sender: self.sender().account_id(), wasm_byte_code, - instantiate_permission: access - .map(|a| { - let response = match a { - AccessConfig::Nobody => cosmrs::cosmwasm::AccessConfig { - permission: cosmrs::cosmwasm::AccessType::Nobody, - addresses: vec![], - }, - AccessConfig::Everybody => cosmrs::cosmwasm::AccessConfig { - permission: cosmrs::cosmwasm::AccessType::Everybody, - addresses: vec![], - }, - AccessConfig::AnyOfAddresses(addresses) => cosmrs::cosmwasm::AccessConfig { - permission: cosmrs::cosmwasm::AccessType::AnyOfAddresses, - addresses: addresses - .into_iter() - .map(|a| a.parse()) - .collect::>()?, - }, - _ => unimplemented!(), - }; - Ok::<_, DaemonError>(response) - }) - .transpose()?, + instantiate_permission: access.map(access_config_to_cosmrs).transpose()?, }; let result = self @@ -411,6 +389,33 @@ impl DaemonAsyncBase { } } +fn access_config_to_cosmrs( + access_config: AccessConfig, +) -> Result { + let response = match access_config { + AccessConfig::Nobody => cosmrs::cosmwasm::AccessConfig { + permission: cosmrs::cosmwasm::AccessType::Nobody, + addresses: vec![], + }, + AccessConfig::Everybody => cosmrs::cosmwasm::AccessConfig { + permission: cosmrs::cosmwasm::AccessType::Everybody, + addresses: vec![], + }, + AccessConfig::AnyOfAddresses(addresses) => cosmrs::cosmwasm::AccessConfig { + permission: cosmrs::cosmwasm::AccessType::AnyOfAddresses, + addresses: addresses + .into_iter() + .map(|a| a.parse()) + .collect::>()?, + }, + AccessConfig::Unspecified => cosmrs::cosmwasm::AccessConfig { + permission: cosmrs::cosmwasm::AccessType::Unspecified, + addresses: vec![], + }, + }; + Ok(response) +} + impl Querier for DaemonAsync { type Error = DaemonError; } diff --git a/cw-orch/src/prelude.rs b/cw-orch/src/prelude.rs index 574c7f528..79bf61aba 100644 --- a/cw-orch/src/prelude.rs +++ b/cw-orch/src/prelude.rs @@ -27,9 +27,8 @@ pub use crate::environment::IndexResponse; // Environment pub use crate::environment::{ - AccessConfig, BankQuerier, BankSetter, CwEnv, DefaultQueriers, EnvironmentInfo, - EnvironmentQuerier, NodeQuerier, QuerierGetter, QueryHandler, TxHandler, TxResponse, - WasmQuerier, + BankQuerier, BankSetter, CwEnv, DefaultQueriers, EnvironmentInfo, EnvironmentQuerier, + NodeQuerier, QuerierGetter, QueryHandler, TxHandler, TxResponse, WasmQuerier, }; pub use cw_orch_core::environment::Environment; diff --git a/packages/cw-orch-core/src/environment/tx_handler.rs b/packages/cw-orch-core/src/environment/tx_handler.rs index c26376c61..d4287350a 100644 --- a/packages/cw-orch-core/src/environment/tx_handler.rs +++ b/packages/cw-orch-core/src/environment/tx_handler.rs @@ -88,8 +88,8 @@ pub trait TxHandler: ChainState + Clone { } } -#[non_exhaustive] pub enum AccessConfig { + Unspecified, Nobody, Everybody, AnyOfAddresses(Vec), @@ -113,6 +113,10 @@ impl From for cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig { addresses, } } + AccessConfig::Unspecified => cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig { + permission: cosmos_sdk_proto::cosmwasm::wasm::v1::AccessType::Unspecified.into(), + addresses: vec![], + }, } } } From 0415ed369c83ada5beae9f8cbef9e7cedc06ae2d Mon Sep 17 00:00:00 2001 From: Kayanski Date: Wed, 11 Sep 2024 13:09:57 +0000 Subject: [PATCH 10/11] Fix clone testing --- packages/clone-testing/src/core.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/clone-testing/src/core.rs b/packages/clone-testing/src/core.rs index bd7781a7d..58772801f 100644 --- a/packages/clone-testing/src/core.rs +++ b/packages/clone-testing/src/core.rs @@ -5,19 +5,19 @@ use clone_cw_multi_test::{ wasm_emulation::{channel::RemoteChannel, storage::analyzer::StorageAnalyzer}, App, AppBuilder, BankKeeper, Contract, Executor, WasmKeeper, }; -use cosmwasm_std::{to_json_binary, WasmMsg}; -use cosmwasm_std::{Addr, Binary, Coin, CosmosMsg, Empty, Event, StdError, StdResult, Uint128}; -use cw_orch_core::contract::interface_traits::ContractInstance; +use cosmwasm_std::{ + to_json_binary, Addr, Binary, Coin, CosmosMsg, Empty, Event, StdError, StdResult, Uint128, + WasmMsg, +}; use cw_orch_core::{ - contract::interface_traits::Uploadable, + contract::interface_traits::{ContractInstance, Uploadable}, environment::{ - BankQuerier, BankSetter, ChainInfoOwned, ChainState, DefaultQueriers, IndexResponse, - StateInterface, TxHandler, + AccessConfig, BankQuerier, BankSetter, ChainInfoOwned, ChainState, DefaultQueriers, + IndexResponse, StateInterface, TxHandler, }, CwEnvError, }; -use cw_orch_daemon::{queriers::Node, RUNTIME}; -use cw_orch_daemon::{read_network_config, DEFAULT_DEPLOYMENT}; +use cw_orch_daemon::{queriers::Node, read_network_config, DEFAULT_DEPLOYMENT, RUNTIME}; use cw_utils::NativeBalance; use serde::Serialize; use tokio::runtime::Runtime; @@ -305,6 +305,15 @@ impl TxHandler for CloneTesting { Ok(resp) } + fn upload_with_access_config( + &self, + contract_source: &T, + _access_config: Option, + ) -> Result { + log::debug!("Uploading with access is not enforced when using Clone Testing"); + self.upload(contract_source) + } + fn execute( &self, exec_msg: &E, From 93f00d57e26530e0dfcaef7453d01c57b12a9aa7 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Wed, 11 Sep 2024 13:10:30 +0000 Subject: [PATCH 11/11] nitgp --- cw-orch-daemon/src/senders/query_only.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cw-orch-daemon/src/senders/query_only.rs b/cw-orch-daemon/src/senders/query_only.rs index c2437547b..7238e1e1e 100644 --- a/cw-orch-daemon/src/senders/query_only.rs +++ b/cw-orch-daemon/src/senders/query_only.rs @@ -46,7 +46,7 @@ impl QuerySender for QueryOnlySender { #[cfg(test)] mod tests { - use cw_orch_networks::networks::{ARCHWAY_1, JUNO_1, VOTA_ASH}; + use cw_orch_networks::networks::{ARCHWAY_1, JUNO_1}; use super::QueryOnlyDaemon; use crate::DaemonBuilder;