Skip to content

Commit

Permalink
feat: Add cosmwasm_1_2 feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia committed Nov 17, 2023
1 parent 8a0be4e commit 6f6b344
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 35 deletions.
1 change: 0 additions & 1 deletion examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sylvia-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ categories = ["api-bindings", "wasm"]

[features]
mt = []
cosmwasm_1_2 = []

[lib]
proc-macro = true
Expand Down
67 changes: 43 additions & 24 deletions sylvia-derive/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 to be enabled. Consider removing `with_salt` or adding the `cosmwasm_1_2` feature."
);
Err(Into::into(err))
}
}
};

#[cfg(not(tarpaulin_include))]
{
quote! {
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 5 additions & 9 deletions sylvia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ keywords = ["cosmwasm", "blockchain", "confio"]
categories = ["api-bindings", "wasm"]

[features]
mt = [
"sylvia-derive/mt",
"dep:cw-multi-test",
"dep:anyhow",
"dep:derivative",
mt = ["sylvia-derive/mt", "dep:cw-multi-test", "dep:anyhow", "dep:derivative"]
cosmwasm_1_2 = [
"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"]
Expand All @@ -31,16 +30,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"
Expand Down
2 changes: 1 addition & 1 deletion sylvia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6f6b344

Please sign in to comment.