diff --git a/examples/Cargo.lock b/examples/Cargo.lock index 93ec01c7..4a2b8298 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -1079,7 +1079,6 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-multi-test", - "cw-utils", "derivative", "konst", "schemars", diff --git a/sylvia-derive/Cargo.toml b/sylvia-derive/Cargo.toml index b73a563c..ebbcdf9e 100644 --- a/sylvia-derive/Cargo.toml +++ b/sylvia-derive/Cargo.toml @@ -12,6 +12,7 @@ categories = ["api-bindings", "wasm"] [features] mt = [] +cosmwasm_1_2 = [] [lib] proc-macro = true diff --git a/sylvia-derive/src/multitest.rs b/sylvia-derive/src/multitest.rs index c8072164..3cabe1f3 100644 --- a/sylvia-derive/src/multitest.rs +++ b/sylvia-derive/src/multitest.rs @@ -453,6 +453,48 @@ where > }; + let instantiate2 = if cfg!(feature = "cosmwasm_1_2") { + #[cfg(not(tarpaulin_include))] + { + quote! { + let msg = #sylvia ::cw_std::to_json_binary(&msg) + .map_err(Into::< #error_type >::into)?; + let sender = #sylvia ::cw_std::Addr::unchecked(sender); + + let msg = #sylvia ::cw_std::WasmMsg::Instantiate2 { + admin, + code_id: code_id.code_id, + msg, + funds: funds.to_owned(), + label: label.to_owned(), + salt: salt.into(), + }; + let app_response = (*code_id.app) + .app_mut() + .execute(sender.clone(), msg.into()) + .map_err(|err| err.downcast::< #error_type >().unwrap())?; + + #sylvia:: cw_utils::parse_instantiate_response_data(app_response.data.unwrap().as_slice()) + .map_err(|err| Into::into( #sylvia ::cw_std::StdError::generic_err(err.to_string()))) + .map(|data| #proxy_name { + contract_addr: #sylvia ::cw_std::Addr::unchecked(data.contract_address), + app: code_id.app, + _phantom: std::marker::PhantomData::default(), + }) + } + } + } else { + #[cfg(not(tarpaulin_include))] + { + quote! { + let err = #sylvia ::cw_std::StdError::generic_err( + "`with_salt` was called, but it requires `cosmwasm_1_2` feature enabled. Consider removing `with_salt` or adding the `cosmwasm_1_2` feature." + ); + Err(Into::into(err)) + } + } + }; + #[cfg(not(tarpaulin_include))] { quote! { @@ -541,30 +583,7 @@ where match salt { Some(salt) => { - let msg = #sylvia ::cw_std::to_json_binary(&msg) - .map_err(Into::< #error_type >::into)?; - let sender = #sylvia ::cw_std::Addr::unchecked(sender); - - let msg = #sylvia ::cw_std::WasmMsg::Instantiate2 { - admin, - code_id: code_id.code_id, - msg, - funds: funds.to_owned(), - label: label.to_owned(), - salt: salt.into(), - }; - let app_response = (*code_id.app) - .app_mut() - .execute(sender.clone(), msg.into()) - .map_err(|err| err.downcast::< #error_type >().unwrap())?; - - #sylvia:: cw_utils::parse_instantiate_response_data(app_response.data.unwrap().as_slice()) - .map_err(|err| Into::into( #sylvia ::cw_std::StdError::generic_err(err.to_string()))) - .map(|data| #proxy_name { - contract_addr: #sylvia ::cw_std::Addr::unchecked(data.contract_address), - app: code_id.app, - _phantom: std::marker::PhantomData::default(), - }) + #instantiate2 }, None => (*code_id.app) .app_mut() diff --git a/sylvia/Cargo.toml b/sylvia/Cargo.toml index a2567296..7b5986a2 100644 --- a/sylvia/Cargo.toml +++ b/sylvia/Cargo.toml @@ -11,13 +11,13 @@ keywords = ["cosmwasm", "blockchain", "confio"] categories = ["api-bindings", "wasm"] [features] -mt = [ - "sylvia-derive/mt", +mt = ["sylvia-derive/mt", "dep:cw-multi-test", "dep:anyhow", "dep:derivative"] +cosmwasm_1_2 = [ "dep:cw-multi-test", - "dep:anyhow", - "dep:derivative", "cosmwasm-std/cosmwasm_1_2", + "cw-multi-test?/cosmwasm_1_2", "dep:cw-utils", + "sylvia-derive/cosmwasm_1_2", ] stargate = ["cosmwasm-std/stargate", "cw-multi-test?/stargate"] staking = ["cosmwasm-std/staking", "cw-multi-test?/staking"] @@ -31,16 +31,13 @@ serde = { version = "1.0", default-features = false, features = ["derive"] } serde-cw-value = "0.7.0" serde-json-wasm = "1.0.0" konst = "0.3" -cw-multi-test = { version = "0.18.0", optional = true, features = [ - "cosmwasm_1_2", -] } +cw-multi-test = { version = "0.18.0", optional = true } anyhow = { version = "1.0", optional = true } derivative = { version = "2.2.0", optional = true } cw-utils = { version = "1.0.2", optional = true } [dev-dependencies] anyhow = "1.0" -cosmwasm-std = { version = "1.5", features = ["staking", "cosmwasm_1_2"] } cw-multi-test = "0.18" cw-storage-plus = "1.2.0" cw-utils = "1.0.2" diff --git a/sylvia/src/lib.rs b/sylvia/src/lib.rs index a49f6682..69f827a8 100644 --- a/sylvia/src/lib.rs +++ b/sylvia/src/lib.rs @@ -14,7 +14,7 @@ pub use cosmwasm_schema as cw_schema; pub use cosmwasm_std as cw_std; #[cfg(feature = "mt")] pub use cw_multi_test; -#[cfg(feature = "mt")] +#[cfg(feature = "cosmwasm_1_2")] pub use cw_utils; #[cfg(feature = "mt")] pub use derivative;