Repository: CosmWasm/cw-multi-test
Pull request #107 (2023-11-29 10:06:47)

Made `no_init` function public
Exported `no_init` function and used in place of empty initialization closure.


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 548d3c8..e9ffa42 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -794,9 +794,9 @@ dependencies = [
 
 [[package]]
 name = "spki"
-version = "0.7.2"
+version = "0.7.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a"
+checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d"
 dependencies = [
  "base64ct",
  "der",
diff --git a/src/app.rs b/src/app.rs
index a52c3b5..5c91327 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -59,11 +59,13 @@ pub struct App<
     pub(crate) block: BlockInfo,
 }
 
+/// No-op application initialization function.
 pub fn no_init<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>(
-    _: &mut Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>,
-    _: &dyn Api,
-    _: &mut dyn Storage,
+    router: &mut Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT>,
+    api: &dyn Api,
+    storage: &mut dyn Storage,
 ) {
+    let _ = (router, api, storage);
 }
 
 impl Default for BasicApp {
diff --git a/src/app_builder.rs b/src/app_builder.rs
index 884a556..8e9e738 100644
--- a/src/app_builder.rs
+++ b/src/app_builder.rs
@@ -16,14 +16,14 @@ use std::fmt::Debug;
 ///
 /// ```
 /// # use cosmwasm_std::Empty;
-/// # use cw_multi_test::{BasicAppBuilder, FailingModule, Module};
+/// # use cw_multi_test::{BasicAppBuilder, FailingModule, Module, no_init};
 /// # type MyHandler = FailingModule<Empty, Empty, Empty>;
 /// # type MyExecC = Empty;
 /// # type MyQueryC = Empty;
 ///
 /// let mut app = BasicAppBuilder::<MyExecC, MyQueryC>::new_custom()
 ///                   .with_custom(MyHandler::default())
-///                   .build(|_, _, _| {});
+///                   .build(no_init);
 /// ```
 pub type BasicAppBuilder<ExecC, QueryC> = AppBuilder<
     BankKeeper,
diff --git a/src/lib.rs b/src/lib.rs
index 91a9f40..e30c218 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -28,7 +28,9 @@ mod transactions;
 mod wasm;
 
 pub use crate::addresses::{AddressGenerator, SimpleAddressGenerator};
-pub use crate::app::{custom_app, next_block, App, BasicApp, CosmosRouter, Router, SudoMsg};
+pub use crate::app::{
+    custom_app, next_block, no_init, App, BasicApp, CosmosRouter, Router, SudoMsg,
+};
 pub use crate::app_builder::{AppBuilder, BasicAppBuilder};
 pub use crate::bank::{Bank, BankKeeper, BankSudo};
 pub use crate::checksums::ChecksumGenerator;


Test patch:
diff --git a/src/tests/test_app.rs b/src/tests/test_app.rs
index 6d9817a..8e19e3d 100644
--- a/src/tests/test_app.rs
+++ b/src/tests/test_app.rs
@@ -1,4 +1,3 @@
-use crate::app::no_init;
 use crate::custom_handler::CachingCustomHandler;
 use crate::error::{bail, AnyResult};
 use crate::test_helpers::echo::EXECUTE_REPLY_BASE_ID;
@@ -7,8 +6,8 @@ use crate::transactions::{transactional, StorageTransaction};
 use crate::wasm::ContractData;
 use crate::AppBuilder;
 use crate::{
-    custom_app, next_block, App, AppResponse, Bank, CosmosRouter, Distribution, Executor, Module,
-    Router, Staking, Wasm, WasmSudo,
+    custom_app, next_block, no_init, App, AppResponse, Bank, CosmosRouter, Distribution, Executor,
+    Module, Router, Staking, Wasm, WasmSudo,
 };
 use cosmwasm_std::testing::{mock_env, MockQuerier};
 use cosmwasm_std::{
@@ -1705,7 +1704,7 @@ mod protobuf_wrapped_data {
     #[test]
     fn instantiate_with_data_works() {
         let owner = Addr::unchecked("owner");
-        let mut app = BasicApp::new(|_, _, _| {});
+        let mut app = BasicApp::new(no_init);
 
         // set up echo contract
         let code_id = app.store_code(echo::contract());
@@ -1734,7 +1733,7 @@ mod protobuf_wrapped_data {
     #[test]
     fn instantiate_with_reply_works() {
         let owner = Addr::unchecked("owner");
-        let mut app = BasicApp::new(|_, _, _| {});
+        let mut app = BasicApp::new(no_init);
 
         // set up echo contract
         let code_id = app.store_code(echo::contract());
@@ -1786,7 +1785,7 @@ mod protobuf_wrapped_data {
     #[test]
     fn execute_wrapped_properly() {
         let owner = Addr::unchecked("owner");
-        let mut app = BasicApp::new(|_, _, _| {});
+        let mut app = BasicApp::new(no_init);
 
         // set up reflect contract
         let code_id = app.store_code(echo::contract());
diff --git a/tests/test_app/test_instantiate2.rs b/tests/test_app/test_instantiate2.rs
index 4e2a810..13cc8d3 100644
--- a/tests/test_app/test_instantiate2.rs
+++ b/tests/test_app/test_instantiate2.rs
@@ -3,7 +3,7 @@
 use crate::test_contracts::counter;
 use cosmwasm_std::{instantiate2_address, to_json_binary, Api, Empty, WasmMsg};
 use cw_multi_test::addons::{MockAddressGenerator, MockApiBech32};
-use cw_multi_test::{AppBuilder, Executor, WasmKeeper};
+use cw_multi_test::{no_init, AppBuilder, Executor, WasmKeeper};
 use cw_utils::parse_instantiate_response_data;
 
 #[test]
@@ -12,7 +12,7 @@ fn instantiate2_works() {
     let mut app = AppBuilder::default()
         .with_api(MockApiBech32::new("juno"))
         .with_wasm(WasmKeeper::default().with_address_generator(MockAddressGenerator))
-        .build(|_, _, _| {});
+        .build(no_init);
 
     // prepare addresses for sender and creator
     let sender = app.api().addr_make("sender");
diff --git a/tests/test_app_builder/test_with_api.rs b/tests/test_app_builder/test_with_api.rs
index 46a92b7..c96184d 100644
--- a/tests/test_app_builder/test_with_api.rs
+++ b/tests/test_app_builder/test_with_api.rs
@@ -1,6 +1,6 @@
 use cosmwasm_std::{Addr, Api, CanonicalAddr, HexBinary};
 use cw_multi_test::addons::MockApiBech32;
-use cw_multi_test::AppBuilder;
+use cw_multi_test::{no_init, AppBuilder};
 
 #[test]
 fn building_app_with_custom_api_should_work() {
@@ -12,7 +12,7 @@ fn building_app_with_custom_api_should_work() {
     // Bech32 address encoding with 'juno' prefix
     let app = AppBuilder::default()
         .with_api(MockApiBech32::new("juno"))
-        .build(|_, _, _| {});
+        .build(no_init);
 
     // check address validation function
     assert_eq!(
diff --git a/tests/test_app_builder/test_with_bank.rs b/tests/test_app_builder/test_with_bank.rs
index 7dd63fb..fa9f175 100644
--- a/tests/test_app_builder/test_with_bank.rs
+++ b/tests/test_app_builder/test_with_bank.rs
@@ -1,6 +1,6 @@
 use crate::test_app_builder::MyKeeper;
 use cosmwasm_std::{coins, Addr, BankMsg, BankQuery};
-use cw_multi_test::{AppBuilder, Bank, BankSudo, Executor};
+use cw_multi_test::{no_init, AppBuilder, Bank, BankSudo, Executor};
 
 type MyBankKeeper = MyKeeper<BankMsg, BankQuery, BankSudo>;
 
@@ -17,7 +17,7 @@ fn building_app_with_custom_bank_should_work() {
 
     // build the application with custom bank keeper
     let app_builder = AppBuilder::default();
-    let mut app = app_builder.with_bank(bank_keeper).build(|_, _, _| {});
+    let mut app = app_builder.with_bank(bank_keeper).build(no_init);
 
     // prepare additional input data
     let recipient = Addr::unchecked("recipient");
diff --git a/tests/test_app_builder/test_with_block.rs b/tests/test_app_builder/test_with_block.rs
index 18178ba..35faed2 100644
--- a/tests/test_app_builder/test_with_block.rs
+++ b/tests/test_app_builder/test_with_block.rs
@@ -1,5 +1,5 @@
 use cosmwasm_std::{BlockInfo, Timestamp};
-use cw_multi_test::AppBuilder;
+use cw_multi_test::{no_init, AppBuilder};
 
 #[test]
 fn building_app_with_custom_block_should_work() {
@@ -12,9 +12,7 @@ fn building_app_with_custom_block_should_work() {
 
     // build the application with custom block
     let app_builder = AppBuilder::default();
-    let app = app_builder
-        .with_block(block_info.clone())
-        .build(|_, _, _| {});
+    let app = app_builder.with_block(block_info.clone()).build(no_init);
 
     // calling block_info should return the same block used during initialization
     assert_eq!(block_info, app.block_info());
diff --git a/tests/test_app_builder/test_with_distribution.rs b/tests/test_app_builder/test_with_distribution.rs
index a3ec713..b7e653e 100644
--- a/tests/test_app_builder/test_with_distribution.rs
+++ b/tests/test_app_builder/test_with_distribution.rs
@@ -1,6 +1,6 @@
 use crate::test_app_builder::{MyKeeper, NO_MESSAGE};
 use cosmwasm_std::{Addr, DistributionMsg, Empty};
-use cw_multi_test::{AppBuilder, Distribution, Executor};
+use cw_multi_test::{no_init, AppBuilder, Distribution, Executor};
 
 type MyDistributionKeeper = MyKeeper<DistributionMsg, Empty, Empty>;
 
@@ -18,7 +18,7 @@ fn building_app_with_custom_distribution_should_work() {
     let app_builder = AppBuilder::default();
     let mut app = app_builder
         .with_distribution(distribution_keeper)
-        .build(|_, _, _| {});
+        .build(no_init);
 
     // prepare additional input data
     let recipient = Addr::unchecked("recipient");
diff --git a/tests/test_app_builder/test_with_gov.rs b/tests/test_app_builder/test_with_gov.rs
index 92536c8..7f47095 100644
--- a/tests/test_app_builder/test_with_gov.rs
+++ b/tests/test_app_builder/test_with_gov.rs
@@ -1,6 +1,6 @@
 use crate::test_app_builder::{MyKeeper, NO_MESSAGE};
 use cosmwasm_std::{Addr, Empty, GovMsg, VoteOption};
-use cw_multi_test::{AppBuilder, Executor, Gov};
+use cw_multi_test::{no_init, AppBuilder, Executor, Gov};
 
 type MyGovKeeper = MyKeeper<GovMsg, Empty, Empty>;
 
@@ -15,7 +15,7 @@ fn building_app_with_custom_gov_should_work() {
 
     // build the application with custom gov keeper
     let app_builder = AppBuilder::default();
-    let mut app = app_builder.with_gov(gov_keeper).build(|_, _, _| {});
+    let mut app = app_builder.with_gov(gov_keeper).build(no_init);
 
     // executing gov message should return an error defined in custom keeper
     assert_eq!(
diff --git a/tests/test_app_builder/test_with_ibc.rs b/tests/test_app_builder/test_with_ibc.rs
index 4e4e8a9..431570e 100644
--- a/tests/test_app_builder/test_with_ibc.rs
+++ b/tests/test_app_builder/test_with_ibc.rs
@@ -1,6 +1,6 @@
 use crate::test_app_builder::{MyKeeper, NO_MESSAGE};
 use cosmwasm_std::{Addr, Empty, IbcMsg, IbcQuery, QueryRequest};
-use cw_multi_test::{AppBuilder, Executor, Ibc};
+use cw_multi_test::{no_init, AppBuilder, Executor, Ibc};
 
 type MyIbcKeeper = MyKeeper<IbcMsg, IbcQuery, Empty>;
 
@@ -16,7 +16,7 @@ fn building_app_with_custom_ibc_should_work() {
 
     // build the application with custom ibc keeper
     let app_builder = AppBuilder::default();
-    let mut app = app_builder.with_ibc(ibc_keeper).build(|_, _, _| {});
+    let mut app = app_builder.with_ibc(ibc_keeper).build(no_init);
 
     // executing ibc message should return an error defined in custom keeper
     assert_eq!(
diff --git a/tests/test_app_builder/test_with_staking.rs b/tests/test_app_builder/test_with_staking.rs
index 97990dc..798b42d 100644
--- a/tests/test_app_builder/test_with_staking.rs
+++ b/tests/test_app_builder/test_with_staking.rs
@@ -1,7 +1,9 @@
 use crate::test_app_builder::MyKeeper;
 use cosmwasm_std::{Addr, Api, BlockInfo, Coin, CustomQuery, StakingMsg, StakingQuery, Storage};
 use cw_multi_test::error::AnyResult;
-use cw_multi_test::{AppBuilder, AppResponse, CosmosRouter, Executor, Staking, StakingSudo};
+use cw_multi_test::{
+    no_init, AppBuilder, AppResponse, CosmosRouter, Executor, Staking, StakingSudo,
+};
 
 type MyStakeKeeper = MyKeeper<StakingMsg, StakingQuery, StakingSudo>;
 
@@ -29,7 +31,7 @@ fn building_app_with_custom_staking_should_work() {
 
     // build the application with custom stake keeper
     let app_builder = AppBuilder::default();
-    let mut app = app_builder.with_staking(stake_keeper).build(|_, _, _| {});
+    let mut app = app_builder.with_staking(stake_keeper).build(no_init);
 
     // prepare additional input data
     let validator = Addr::unchecked("recipient");
diff --git a/tests/test_app_builder/test_with_storage.rs b/tests/test_app_builder/test_with_storage.rs
index 378b321..b6106d7 100644
--- a/tests/test_app_builder/test_with_storage.rs
+++ b/tests/test_app_builder/test_with_storage.rs
@@ -1,6 +1,6 @@
 use crate::{test_contracts, CounterQueryMsg, CounterResponseMsg};
 use cosmwasm_std::{to_json_binary, Addr, Empty, Order, Record, Storage, WasmMsg};
-use cw_multi_test::{AppBuilder, Executor};
+use cw_multi_test::{no_init, AppBuilder, Executor};
 use std::collections::BTreeMap;
 use std::iter;
 
@@ -44,7 +44,7 @@ fn building_app_with_custom_storage_should_work() {
     let app_builder = AppBuilder::default();
     let mut app = app_builder
         .with_storage(MyStorage::default())
-        .build(|_, _, _| {});
+        .build(no_init);
 
     // store a contract code
     let code_id = app.store_code(test_contracts::counter::contract());
diff --git a/tests/test_app_builder/test_with_wasm.rs b/tests/test_app_builder/test_with_wasm.rs
index 96a5bb7..13f4b05 100644
--- a/tests/test_app_builder/test_with_wasm.rs
+++ b/tests/test_app_builder/test_with_wasm.rs
@@ -5,8 +5,8 @@ use cosmwasm_std::{
 };
 use cw_multi_test::error::{bail, AnyResult};
 use cw_multi_test::{
-    AppBuilder, AppResponse, Contract, ContractData, CosmosRouter, Executor, Wasm, WasmKeeper,
-    WasmSudo,
+    no_init, AppBuilder, AppResponse, Contract, ContractData, CosmosRouter, Executor, Wasm,
+    WasmKeeper, WasmSudo,
 };
 use once_cell::sync::Lazy;
 
@@ -84,7 +84,7 @@ fn building_app_with_custom_wasm_should_work() {
 
     // build the application with custom wasm keeper
     let app_builder = AppBuilder::default();
-    let mut app = app_builder.with_wasm(wasm_keeper).build(|_, _, _| {});
+    let mut app = app_builder.with_wasm(wasm_keeper).build(no_init);
 
     // prepare additional input data
     let contract_addr = Addr::unchecked("contract");
@@ -155,7 +155,5 @@ fn compiling_with_wasm_keeper_should_work() {
     // this verifies only compilation errors
     // while our WasmKeeper does not implement Module
     let app_builder = AppBuilder::default();
-    let _ = app_builder
-        .with_wasm(WasmKeeper::default())
-        .build(|_, _, _| {});
+    let _ = app_builder.with_wasm(WasmKeeper::default()).build(no_init);
 }
diff --git a/tests/test_wasm/test_with_addr_gen.rs b/tests/test_wasm/test_with_addr_gen.rs
index ef7bdaa..61bb460 100644
--- a/tests/test_wasm/test_with_addr_gen.rs
+++ b/tests/test_wasm/test_with_addr_gen.rs
@@ -1,7 +1,7 @@
 use crate::test_contracts;
 use cosmwasm_std::{Addr, Empty};
 use cw_multi_test::addons::{MockAddressGenerator, MockApiBech32};
-use cw_multi_test::{AppBuilder, Executor, WasmKeeper};
+use cw_multi_test::{no_init, AppBuilder, Executor, WasmKeeper};
 
 #[test]
 fn contract_address_should_work() {
@@ -13,7 +13,7 @@ fn contract_address_should_work() {
     let mut app = AppBuilder::default()
         .with_api(MockApiBech32::new("purple"))
         .with_wasm(wasm_keeper)
-        .build(|_, _, _| {});
+        .build(no_init);
 
     // store contract's code
     let code_id = app.store_code_with_creator(
@@ -56,7 +56,7 @@ fn predictable_contract_address_should_work() {
     let mut app = AppBuilder::default()
         .with_api(MockApiBech32::new("juno"))
         .with_wasm(wasm_keeper)
-        .build(|_, _, _| {});
+        .build(no_init);
 
     let creator = app.api().addr_make("creator");
 
@@ -114,7 +114,7 @@ fn creating_contract_with_the_same_predictable_address_should_fail() {
     let mut app = AppBuilder::default()
         .with_api(MockApiBech32::new("juno"))
         .with_wasm(wasm_keeper)
-        .build(|_, _, _| {});
+        .build(no_init);
 
     let creator = app.api().addr_make("creator");
 
diff --git a/tests/test_wasm/test_with_checksum_gen.rs b/tests/test_wasm/test_with_checksum_gen.rs
index 56029b9..8917a29 100644
--- a/tests/test_wasm/test_with_checksum_gen.rs
+++ b/tests/test_wasm/test_with_checksum_gen.rs
@@ -2,7 +2,7 @@
 
 use crate::test_contracts;
 use cosmwasm_std::{Addr, Empty, HexBinary};
-use cw_multi_test::{App, AppBuilder, ChecksumGenerator, WasmKeeper};
+use cw_multi_test::{no_init, App, AppBuilder, ChecksumGenerator, WasmKeeper};
 
 #[test]
 fn default_checksum_generator_should_work() {
@@ -41,9 +41,7 @@ fn custom_checksum_generator_should_work() {
         WasmKeeper::default().with_checksum_generator(MyChecksumGenerator);
 
     // prepare application with custom wasm keeper
-    let mut app = AppBuilder::default()
-        .with_wasm(wasm_keeper)
-        .build(|_, _, _| {});
+    let mut app = AppBuilder::default().with_wasm(wasm_keeper).build(no_init);
 
     // store contract's code
     let code_id = app.store_code_with_creator(