diff --git a/src/app.rs b/src/app.rs index 91e886b4..2ae4db9b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -248,18 +248,23 @@ where CustomT::ExecT: Clone + Debug + PartialEq + JsonSchema + DeserializeOwned + 'static, CustomT::QueryT: CustomQuery + DeserializeOwned + 'static, { - /// Registers contract code (like uploading wasm bytecode on a chain), - /// so it can later be used to instantiate a contract. - pub fn store_code(&mut self, code: Box>) -> u64 { - self.init_modules(|router, _, _| { - router - .wasm - .store_code(Addr::unchecked("code-creator"), code) - }) + /// Registers contract code, like uploading wasm bytecode on a chain. + /// + /// Registered contract's code can be used later to instantiate a contract. + pub fn store_code( + &mut self, + creator: Addr, + code: Box>, + ) -> u64 { + self.init_modules(|router, _, _| router.wasm.store_code(creator, code)) } /// Registers contract code (like [store_code](Self::store_code)), /// but takes the address of the code creator as an additional argument. + #[deprecated( + since = "1.0.0", + note = "use store_code instead, will be removed in version 2.0.0" + )] pub fn store_code_with_creator( &mut self, creator: Addr, @@ -304,9 +309,10 @@ where /// } /// /// let mut app = App::default(); + /// let creator = Addr::unchecked("creator"); /// /// // store a new contract, save the code id - /// let code_id = app.store_code(echo::contract()); + /// let code_id = app.store_code(creator, echo::contract()); /// /// // duplicate the existing contract, duplicated contract has different code id /// assert_ne!(code_id, app.duplicate_code(code_id).unwrap()); diff --git a/src/tests/test_app.rs b/src/tests/test_app.rs index f6d41f18..a23a31fa 100644 --- a/src/tests/test_app.rs +++ b/src/tests/test_app.rs @@ -9,7 +9,7 @@ use crate::{ 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::testing::{mock_env, MockApi, MockQuerier}; use cosmwasm_std::{ coin, coins, from_json, to_json_binary, Addr, AllBalanceResponse, Api, Attribute, BankMsg, BankQuery, Binary, BlockInfo, Coin, CosmosMsg, CustomQuery, Empty, Event, OverflowError, @@ -170,7 +170,7 @@ fn duplicate_contract_code() { let mut app = App::default(); // store the original contract code - let code_id = app.store_code(payout::contract()); + let code_id = app.store_code(Addr::unchecked("creator"), payout::contract()); // duplicate previously stored contract code let dup_code_id = app.duplicate_code(code_id).unwrap(); @@ -245,7 +245,7 @@ fn simple_contract() { }); // set up contract - let code_id = app.store_code(payout::contract()); + let code_id = app.store_code(owner.clone(), payout::contract()); let msg = payout::InstantiateMessage { payout: coin(5, "eth"), @@ -332,7 +332,7 @@ fn reflect_success() { }); // set up payout contract - let payout_id = app.store_code(payout::contract()); + let payout_id = app.store_code(owner.clone(), payout::contract()); let msg = payout::InstantiateMessage { payout: coin(5, "eth"), @@ -349,7 +349,7 @@ fn reflect_success() { .unwrap(); // set up reflect contract - let reflect_id = app.store_code(reflect::contract()); + let reflect_id = app.store_code(owner.clone(), reflect::contract()); let reflect_addr = app .instantiate_contract(reflect_id, owner, &Empty {}, &[], "Reflect", None) @@ -438,7 +438,7 @@ fn reflect_error() { }); // set up reflect contract - let reflect_id = app.store_code(reflect::contract()); + let reflect_id = app.store_code(owner.clone(), reflect::contract()); let reflect_addr = app .instantiate_contract( @@ -532,7 +532,7 @@ fn sudo_works() { .unwrap(); }); - let payout_id = app.store_code(payout::contract()); + let payout_id = app.store_code(owner.clone(), payout::contract()); let msg = payout::InstantiateMessage { payout: coin(5, "eth"), @@ -589,7 +589,7 @@ fn reflect_sub_message_reply_works() { }); // set up reflect contract - let reflect_id = app.store_code(reflect::contract()); + let reflect_id = app.store_code(owner.clone(), reflect::contract()); let reflect_addr = app .instantiate_contract( @@ -679,7 +679,7 @@ fn send_update_admin_works() { let mut app = App::default(); // create a hackatom contract with some funds - let code_id = app.store_code(hackatom::contract()); + let code_id = app.store_code(owner.clone(), hackatom::contract()); let contract = app .instantiate_contract( @@ -748,7 +748,7 @@ fn sent_wasm_migration_works() { }); // create a hackatom contract with some funds - let code_id = app.store_code(hackatom::contract()); + let code_id = app.store_code(owner.clone(), hackatom::contract()); let contract = app .instantiate_contract( @@ -815,7 +815,7 @@ fn sent_funds_properly_visible_on_execution() { .unwrap(); }); - let code_id = app.store_code(hackatom::contract()); + let code_id = app.store_code(owner.clone(), hackatom::contract()); let contract = app .instantiate_contract( @@ -1035,7 +1035,7 @@ mod reply_data_overwrite { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1062,7 +1062,7 @@ mod reply_data_overwrite { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1095,7 +1095,7 @@ mod reply_data_overwrite { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1123,7 +1123,7 @@ mod reply_data_overwrite { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1151,7 +1151,7 @@ mod reply_data_overwrite { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1191,14 +1191,14 @@ mod reply_data_overwrite { }); // set up reflect contract - let reflect_id = app.store_code(reflect::contract()); + let reflect_id = app.store_code(owner.clone(), reflect::contract()); let reflect_addr = app .instantiate_contract(reflect_id, owner.clone(), &Empty {}, &[], "Reflect", None) .unwrap(); // set up echo contract - let echo_id = app.store_code(echo::custom_contract()); + let echo_id = app.store_code(owner.clone(), echo::custom_contract()); let echo_addr = app .instantiate_contract(echo_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1239,7 +1239,7 @@ mod reply_data_overwrite { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1282,7 +1282,7 @@ mod reply_data_overwrite { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1315,7 +1315,7 @@ mod reply_data_overwrite { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1353,7 +1353,7 @@ mod reply_data_overwrite { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1406,7 +1406,7 @@ mod response_validation { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1437,7 +1437,7 @@ mod response_validation { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1468,7 +1468,7 @@ mod response_validation { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1498,7 +1498,7 @@ mod response_validation { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1528,7 +1528,7 @@ mod response_validation { let owner = Addr::unchecked("owner"); - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let contract = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "Echo", None) @@ -1562,7 +1562,7 @@ mod contract_instantiation { let sender = Addr::unchecked("sender"); // store contract's code - let code_id = app.store_code_with_creator(Addr::unchecked("creator"), echo::contract()); + let code_id = app.store_code(Addr::unchecked("creator"), echo::contract()); // initialize the contract let init_msg = to_json_binary(&Empty {}).unwrap(); @@ -1593,7 +1593,7 @@ mod wasm_queries { fn query_existing_code_info() { use super::*; let mut app = App::default(); - let code_id = app.store_code_with_creator(Addr::unchecked("creator"), echo::contract()); + let code_id = app.store_code(Addr::unchecked("creator"), echo::contract()); let code_info_response = app.wrap().query_wasm_code_info(code_id).unwrap(); assert_eq!(code_id, code_info_response.code_id); assert_eq!("creator", code_info_response.creator); @@ -1677,7 +1677,7 @@ mod protobuf_wrapped_data { }); // set up reflect contract - let code_id = app.store_code(reflect::contract()); + let code_id = app.store_code(owner.clone(), reflect::contract()); let init_msg = to_json_binary(&Empty {}).unwrap(); let msg = WasmMsg::Instantiate { @@ -1707,7 +1707,7 @@ mod protobuf_wrapped_data { let mut app = BasicApp::new(no_init); // set up echo contract - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let msg = echo::InitMessage:: { data: Some("food".into()), @@ -1736,7 +1736,7 @@ mod protobuf_wrapped_data { let mut app = BasicApp::new(no_init); // set up echo contract - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let msg = echo::InitMessage:: { data: Some("food".into()), @@ -1788,7 +1788,7 @@ mod protobuf_wrapped_data { let mut app = BasicApp::new(no_init); // set up reflect contract - let code_id = app.store_code(echo::contract()); + let code_id = app.store_code(owner.clone(), echo::contract()); let echo_addr = app .instantiate_contract(code_id, owner.clone(), &Empty {}, &[], "label", None) @@ -1815,7 +1815,7 @@ mod errors { let mut app = App::default(); // set up contract - let code_id = app.store_code(error::contract(false)); + let code_id = app.store_code(owner.clone(), error::contract(false)); let msg = Empty {}; let err = app @@ -1841,7 +1841,7 @@ mod errors { let mut app = App::default(); // set up contract - let code_id = app.store_code(error::contract(true)); + let code_id = app.store_code(owner.clone(), error::contract(true)); let msg = Empty {}; let contract_addr = app @@ -1871,8 +1871,8 @@ mod errors { let owner = Addr::unchecked("owner"); let mut app = App::default(); - let error_code_id = app.store_code(error::contract(true)); - let caller_code_id = app.store_code(caller::contract()); + let error_code_id = app.store_code(owner.clone(), error::contract(true)); + let caller_code_id = app.store_code(owner.clone(), caller::contract()); // set up contract_helpers let msg = Empty {}; @@ -1911,8 +1911,8 @@ mod errors { let owner = Addr::unchecked("owner"); let mut app = App::default(); - let error_code_id = app.store_code(error::contract(true)); - let caller_code_id = app.store_code(caller::contract()); + let error_code_id = app.store_code(owner.clone(), error::contract(true)); + let caller_code_id = app.store_code(owner.clone(), caller::contract()); // set up contract_helpers let msg = Empty {}; diff --git a/tests/test_app_builder/test_with_storage.rs b/tests/test_app_builder/test_with_storage.rs index b6106d7f..9d6f7651 100644 --- a/tests/test_app_builder/test_with_storage.rs +++ b/tests/test_app_builder/test_with_storage.rs @@ -34,6 +34,7 @@ impl Storage for MyStorage { #[test] fn building_app_with_custom_storage_should_work() { // prepare additional test input data + let creator = Addr::unchecked("creator"); let owner = Addr::unchecked("owner"); let msg = to_json_binary(&Empty {}).unwrap(); let admin = None; @@ -47,7 +48,7 @@ fn building_app_with_custom_storage_should_work() { .build(no_init); // store a contract code - let code_id = app.store_code(test_contracts::counter::contract()); + let code_id = app.store_code(creator, test_contracts::counter::contract()); // instantiate contract, this initializes a counter with value 1 let contract_addr = app diff --git a/tests/test_app_builder/test_with_wasm.rs b/tests/test_app_builder/test_with_wasm.rs index 13f4b05f..1be4149f 100644 --- a/tests/test_app_builder/test_with_wasm.rs +++ b/tests/test_app_builder/test_with_wasm.rs @@ -87,10 +87,14 @@ fn building_app_with_custom_wasm_should_work() { let mut app = app_builder.with_wasm(wasm_keeper).build(no_init); // prepare additional input data + let creator = Addr::unchecked("creator"); let contract_addr = Addr::unchecked("contract"); // calling store_code should return value defined in custom keeper - assert_eq!(CODE_ID, app.store_code(test_contracts::counter::contract())); + assert_eq!( + CODE_ID, + app.store_code(creator, test_contracts::counter::contract()) + ); // calling duplicate_code should return error defined in custom keeper assert_eq!(