Skip to content

Commit

Permalink
feat: Allow querying code_info from CodeId and App
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia committed Nov 20, 2023
1 parent ff1d6ce commit ef1da32
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ cw-utils = "1.0.2"
cw2 = "1.1.1"
getrandom = "0.2.11"
semver = "1.0.20"
serde = "1.0.192"
serde = { version = "1.0.192", default-features = false, features = ["derive"] }
thiserror = "1.0.50"
assert_matches = "1.5.0"
2 changes: 1 addition & 1 deletion examples/contracts/custom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cw1 = { path = "../../interfaces/cw1" }
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true, features = ["staking"] }
cw-storage-plus = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }
cw-multi-test = { workspace = true, optional = true }
anyhow = { workspace = true, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/cw1-subkeys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ whitelist = { path = "../../interfaces/whitelist" }
cw1-whitelist = { path = "../cw1-whitelist", features = ["library"] }
cw2 = { workspace = true }
getrandom = { workspace = true, features = ["js"] }
serde = { workspace = true, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }
thiserror = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/cw1-whitelist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mt = ["sylvia/mt", "library"]
[dependencies]
cosmwasm-std = { workspace = true, features = ["staking"] }
cosmwasm-schema = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }
cw1 = { path = "../../interfaces/cw1" }
whitelist = { path = "../../interfaces/whitelist" }
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/cw20-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cw20-marketing = { path = "../../interfaces/cw20-marketing" }
cw20-minting = { path = "../../interfaces/cw20-minting" }
getrandom = { workspace = true, features = ["js"] }
semver = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }
thiserror = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/entry-points-overriding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cosmwasm-std = { workspace = true, features = ["staking"] }
cw-multi-test = { workspace = true, optional = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/generic_contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cosmwasm-std = { workspace = true, features = ["staking"] }
cw-multi-test = { workspace = true, optional = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }
cw1 = { path = "../../interfaces/cw1" }
generic = { path = "../../interfaces/generic" }
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/generic_iface_on_contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cosmwasm-std = { workspace = true, features = ["staking"] }
cw-multi-test = { workspace = true, optional = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }
cw1 = { path = "../../interfaces/cw1" }
generic = { path = "../../interfaces/generic" }
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/custom-and-generic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mt = ["sylvia/mt"]
[dependencies]
cosmwasm-std = { workspace = true, features = ["staking"] }
cosmwasm-schema = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/cw1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mt = ["sylvia/mt"]
[dependencies]
cosmwasm-std = { workspace = true, features = ["staking"] }
cosmwasm-schema = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/cw20-allowances/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mt = ["sylvia/mt"]
[dependencies]
cosmwasm-std = { workspace = true, features = ["staking"] }
cosmwasm-schema = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }
cw-utils = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/cw20-marketing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mt = ["sylvia/mt"]
[dependencies]
cosmwasm-std = { workspace = true, features = ["staking"] }
cosmwasm-schema = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/cw20-minting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mt = ["sylvia/mt"]
[dependencies]
cosmwasm-std = { workspace = true, features = ["staking"] }
cosmwasm-schema = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/cw4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mt = ["sylvia/mt"]
[dependencies]
cosmwasm-std = { workspace = true, features = ["staking"] }
cosmwasm-schema = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/generic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mt = ["sylvia/mt"]
[dependencies]
cosmwasm-std = { workspace = true, features = ["staking"] }
cosmwasm-schema = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/whitelist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mt = ["sylvia/mt"]
[dependencies]
cosmwasm-std = { workspace = true, features = ["staking"] }
cosmwasm-schema = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde = { workspace = true }
sylvia = { path = "../../../sylvia" }

[dev-dependencies]
Expand Down
13 changes: 13 additions & 0 deletions sylvia-derive/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,17 @@ where
}
};

#[cfg(not(tarpaulin_include))]
let code_info = if cfg!(feature = "cosmwasm_1_2") {
quote! {
pub fn code_info(&self) -> #sylvia ::cw_std::StdResult< #sylvia ::cw_std::CodeInfoResponse> {
self.app.app().wrap().query_wasm_code_info(self.code_id)
}
}
} else {
quote! {}
};

#[cfg(not(tarpaulin_include))]
{
quote! {
Expand Down Expand Up @@ -530,6 +541,8 @@ where
self.code_id
}

#code_info

pub fn instantiate(
&self, #(#fields,)*
) -> InstantiateProxy<'_, 'app, #(#generics,)* #mt_app > {
Expand Down
7 changes: 7 additions & 0 deletions sylvia/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::marker::PhantomData;
use cosmwasm_std::{
Addr, Api, BlockInfo, Coin, CustomQuery, Empty, GovMsg, IbcMsg, IbcQuery, Storage,
};
#[cfg(feature = "cosmwasm_1_2")]
use cosmwasm_std::{CodeInfoResponse, StdResult};
use cw_multi_test::{
Bank, BankKeeper, Distribution, DistributionKeeper, Executor, FailingModule, Gov, Ibc, Module,
Router, StakeKeeper, Staking, Wasm, WasmKeeper,
Expand Down Expand Up @@ -94,6 +96,11 @@ where
pub fn update_block<F: Fn(&mut BlockInfo)>(&self, action: F) {
self.app.borrow_mut().update_block(action)
}

#[cfg(feature = "cosmwasm_1_2")]
pub fn code_info(&self, code_id: u64) -> StdResult<CodeInfoResponse> {
self.app.borrow().wrap().query_wasm_code_info(code_id)
}
}

#[must_use]
Expand Down
12 changes: 11 additions & 1 deletion sylvia/tests/multitest.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(feature = "mt")]

use cosmwasm_std::{Empty, Response, StdResult};
use cosmwasm_std::{CodeInfoResponse, Empty, Response, StdResult};
use std::marker::PhantomData;
use sylvia::multitest::App;
use sylvia::types::InstantiateCtx;
Expand Down Expand Up @@ -42,3 +42,13 @@ fn instantiate_with_salt() {
.call(owner)
.unwrap();
}

#[test]
fn code_info() {
let app = App::default();

let code_id = sv::multitest_utils::CodeId::<Empty, _>::store_code(&app);

let _: CodeInfoResponse = code_id.code_info().unwrap();
let _: CodeInfoResponse = app.code_info(code_id.code_id()).unwrap();
}

0 comments on commit ef1da32

Please sign in to comment.