From 3a2313a6f760888b0d1f817d9872387fcb3e5eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Thu, 16 Nov 2023 18:27:11 +0100 Subject: [PATCH] feat: Allow querying code_info from CodeId and App --- examples/Cargo.toml | 2 +- examples/contracts/custom/Cargo.toml | 2 +- examples/contracts/cw1-subkeys/Cargo.toml | 2 +- examples/contracts/cw1-whitelist/Cargo.toml | 2 +- examples/contracts/cw20-base/Cargo.toml | 2 +- .../contracts/entry-points-overriding/Cargo.toml | 2 +- examples/contracts/generic_contract/Cargo.toml | 2 +- .../contracts/generic_iface_on_contract/Cargo.toml | 2 +- examples/interfaces/custom-and-generic/Cargo.toml | 2 +- examples/interfaces/cw1/Cargo.toml | 2 +- examples/interfaces/cw20-allowances/Cargo.toml | 2 +- examples/interfaces/cw20-marketing/Cargo.toml | 2 +- examples/interfaces/cw20-minting/Cargo.toml | 2 +- examples/interfaces/cw4/Cargo.toml | 2 +- examples/interfaces/generic/Cargo.toml | 2 +- examples/interfaces/whitelist/Cargo.toml | 2 +- sylvia-derive/src/multitest.rs | 13 +++++++++++++ sylvia/src/multitest.rs | 7 +++++++ sylvia/tests/multitest.rs | 12 +++++++++++- 19 files changed, 47 insertions(+), 17 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 5bc2fab5..1197ee60 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -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" diff --git a/examples/contracts/custom/Cargo.toml b/examples/contracts/custom/Cargo.toml index 8945b3f2..6229ece4 100644 --- a/examples/contracts/custom/Cargo.toml +++ b/examples/contracts/custom/Cargo.toml @@ -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 } diff --git a/examples/contracts/cw1-subkeys/Cargo.toml b/examples/contracts/cw1-subkeys/Cargo.toml index bb433a6d..2124d343 100644 --- a/examples/contracts/cw1-subkeys/Cargo.toml +++ b/examples/contracts/cw1-subkeys/Cargo.toml @@ -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 } diff --git a/examples/contracts/cw1-whitelist/Cargo.toml b/examples/contracts/cw1-whitelist/Cargo.toml index a7878c80..b804ba5f 100644 --- a/examples/contracts/cw1-whitelist/Cargo.toml +++ b/examples/contracts/cw1-whitelist/Cargo.toml @@ -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" } diff --git a/examples/contracts/cw20-base/Cargo.toml b/examples/contracts/cw20-base/Cargo.toml index 67a9102e..b68664d4 100644 --- a/examples/contracts/cw20-base/Cargo.toml +++ b/examples/contracts/cw20-base/Cargo.toml @@ -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 } diff --git a/examples/contracts/entry-points-overriding/Cargo.toml b/examples/contracts/entry-points-overriding/Cargo.toml index 5fb6463b..46cc3dda 100644 --- a/examples/contracts/entry-points-overriding/Cargo.toml +++ b/examples/contracts/entry-points-overriding/Cargo.toml @@ -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] diff --git a/examples/contracts/generic_contract/Cargo.toml b/examples/contracts/generic_contract/Cargo.toml index 64cc7408..d361af09 100644 --- a/examples/contracts/generic_contract/Cargo.toml +++ b/examples/contracts/generic_contract/Cargo.toml @@ -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" } diff --git a/examples/contracts/generic_iface_on_contract/Cargo.toml b/examples/contracts/generic_iface_on_contract/Cargo.toml index 986a10cf..05b8791a 100644 --- a/examples/contracts/generic_iface_on_contract/Cargo.toml +++ b/examples/contracts/generic_iface_on_contract/Cargo.toml @@ -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" } diff --git a/examples/interfaces/custom-and-generic/Cargo.toml b/examples/interfaces/custom-and-generic/Cargo.toml index 0efd4119..12a74d81 100644 --- a/examples/interfaces/custom-and-generic/Cargo.toml +++ b/examples/interfaces/custom-and-generic/Cargo.toml @@ -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] diff --git a/examples/interfaces/cw1/Cargo.toml b/examples/interfaces/cw1/Cargo.toml index 6c6e64b9..f4fc06e0 100644 --- a/examples/interfaces/cw1/Cargo.toml +++ b/examples/interfaces/cw1/Cargo.toml @@ -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] diff --git a/examples/interfaces/cw20-allowances/Cargo.toml b/examples/interfaces/cw20-allowances/Cargo.toml index 72dbfd1f..71a177f6 100644 --- a/examples/interfaces/cw20-allowances/Cargo.toml +++ b/examples/interfaces/cw20-allowances/Cargo.toml @@ -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 } diff --git a/examples/interfaces/cw20-marketing/Cargo.toml b/examples/interfaces/cw20-marketing/Cargo.toml index daf52601..7c7bb821 100644 --- a/examples/interfaces/cw20-marketing/Cargo.toml +++ b/examples/interfaces/cw20-marketing/Cargo.toml @@ -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] diff --git a/examples/interfaces/cw20-minting/Cargo.toml b/examples/interfaces/cw20-minting/Cargo.toml index 0a775559..db11866a 100644 --- a/examples/interfaces/cw20-minting/Cargo.toml +++ b/examples/interfaces/cw20-minting/Cargo.toml @@ -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] diff --git a/examples/interfaces/cw4/Cargo.toml b/examples/interfaces/cw4/Cargo.toml index 313f21b5..1e849017 100644 --- a/examples/interfaces/cw4/Cargo.toml +++ b/examples/interfaces/cw4/Cargo.toml @@ -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] diff --git a/examples/interfaces/generic/Cargo.toml b/examples/interfaces/generic/Cargo.toml index 04ad4e83..cfb9eb30 100644 --- a/examples/interfaces/generic/Cargo.toml +++ b/examples/interfaces/generic/Cargo.toml @@ -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] diff --git a/examples/interfaces/whitelist/Cargo.toml b/examples/interfaces/whitelist/Cargo.toml index ee72c262..3bcee9f9 100644 --- a/examples/interfaces/whitelist/Cargo.toml +++ b/examples/interfaces/whitelist/Cargo.toml @@ -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] diff --git a/sylvia-derive/src/multitest.rs b/sylvia-derive/src/multitest.rs index 3cabe1f3..ebc5fcfc 100644 --- a/sylvia-derive/src/multitest.rs +++ b/sylvia-derive/src/multitest.rs @@ -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! { @@ -530,6 +541,8 @@ where self.code_id } + #code_info + pub fn instantiate( &self, #(#fields,)* ) -> InstantiateProxy<'_, 'app, #(#generics,)* #mt_app > { diff --git a/sylvia/src/multitest.rs b/sylvia/src/multitest.rs index 2f129b09..c0fe0eac 100644 --- a/sylvia/src/multitest.rs +++ b/sylvia/src/multitest.rs @@ -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, @@ -94,6 +96,11 @@ where pub fn update_block(&self, action: F) { self.app.borrow_mut().update_block(action) } + + #[cfg(feature = "cosmwasm_1_2")] + pub fn code_info(&self, code_id: u64) -> StdResult { + self.app.borrow().wrap().query_wasm_code_info(code_id) + } } #[must_use] diff --git a/sylvia/tests/multitest.rs b/sylvia/tests/multitest.rs index 220f7213..4c5a46c9 100644 --- a/sylvia/tests/multitest.rs +++ b/sylvia/tests/multitest.rs @@ -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; @@ -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::::store_code(&app); + + let _: CodeInfoResponse = code_id.code_info().unwrap(); + let _: CodeInfoResponse = app.code_info(code_id.code_id()).unwrap(); +}