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 16, 2023
1 parent 51c4e56 commit 4ee85c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions sylvia-derive/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ where
self.code_id
}

pub fn code_info(&self) -> #sylvia ::cw_std::StdResult< #sylvia ::cw_std::CodeInfoResponse> {
self.app.app().wrap().query_wasm_code_info(self.code_id)
}

pub fn instantiate(
&self, #(#fields,)*
) -> InstantiateProxy<'_, 'app, #(#generics,)* #mt_app > {
Expand Down
7 changes: 6 additions & 1 deletion sylvia/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::fmt::{Debug, Display};
use std::marker::PhantomData;

use cosmwasm_std::{
Addr, Api, BlockInfo, Coin, CustomQuery, Empty, GovMsg, IbcMsg, IbcQuery, Storage,
Addr, Api, BlockInfo, CodeInfoResponse, Coin, CustomQuery, Empty, GovMsg, IbcMsg, IbcQuery,
StdResult, Storage,
};
use cw_multi_test::{
Bank, BankKeeper, Distribution, DistributionKeeper, Executor, FailingModule, Gov, Ibc, Module,
Expand Down Expand Up @@ -94,6 +95,10 @@ where
pub fn update_block<F: Fn(&mut BlockInfo)>(&self, action: F) {
self.app.borrow_mut().update_block(action)
}

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 4ee85c7

Please sign in to comment.