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 17, 2023
1 parent 2986d45 commit 009f657
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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 009f657

Please sign in to comment.