diff --git a/Cargo.lock b/Cargo.lock index d9bff1f..f7669d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,8 +58,9 @@ dependencies = [ [[package]] name = "apollo-cw-multi-test" -version = "0.18.1" -source = "git+https://github.com/apollodao/cw-multi-test.git?rev=7e7bc2b91a8199c47815b45ef23b3ab07390ae3a#7e7bc2b91a8199c47815b45ef23b3ab07390ae3a" +version = "0.19.0-rc.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7c7f08fd29e20927635f8b976e9689f5b681bc8536f6b563bd8b728a606cc2c" dependencies = [ "anyhow", "cosmwasm-std", @@ -933,7 +934,7 @@ dependencies = [ [[package]] name = "cw-it" -version = "0.4.0-rc.2" +version = "0.4.0-rc.3" dependencies = [ "anyhow", "apollo-cw-multi-test", diff --git a/Cargo.toml b/Cargo.toml index a351597..c0deec1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cw-it" -version = "0.4.0-rc.2" +version = "0.4.0-rc.3" authors = ["Pacman ", "Sturdy "] edition = "2021" license = "MPL-2.0" @@ -112,7 +112,7 @@ apollo-utils = { version = "0.1.1", optional = true } regex = { version = "1.7.3", optional = true } # Cw-multi-test deps -apollo-cw-multi-test = { git = "https://github.com/apollodao/cw-multi-test.git", rev = "7e7bc2b91a8199c47815b45ef23b3ab07390ae3a",features = ["stargate"], optional = true } +apollo-cw-multi-test = { version = "0.19.0-rc.1", features = ["stargate"], optional = true } bech32 = { version = "0.11.0", optional = true } sha2 = { version = "0.10.8", optional = true } paste = { version = "1.0.12", optional = true } diff --git a/src/multi_test/mod.rs b/src/multi_test/mod.rs index a554b74..49686bc 100644 --- a/src/multi_test/mod.rs +++ b/src/multi_test/mod.rs @@ -11,4 +11,3 @@ pub mod api; pub use crate::create_contract_wrappers; pub use runner::MultiTestRunner; -pub mod test_addresses; diff --git a/src/multi_test/runner.rs b/src/multi_test/runner.rs index 73224c4..e7d0354 100644 --- a/src/multi_test/runner.rs +++ b/src/multi_test/runner.rs @@ -1,10 +1,9 @@ use crate::multi_test::api::MockApiBech32; -use crate::multi_test::test_addresses::MockAddressGenerator; use crate::{traits::CwItRunner, ContractType}; use anyhow::bail; -use apollo_cw_multi_test::BankKeeper; -use apollo_cw_multi_test::WasmKeeper; -use apollo_cw_multi_test::{BankSudo, BasicAppBuilder}; +use apollo_cw_multi_test::{ + BankKeeper, BankSudo, BasicAppBuilder, MockAddressGenerator, WasmKeeper, +}; use cosmrs::{crypto::secp256k1::SigningKey, proto::cosmos::base::abci::v1beta1::GasInfo}; use cosmwasm_std::{ coin, Addr, BankMsg, Binary, Coin, CosmosMsg, Empty, QueryRequest, StakingMsg, WasmMsg, @@ -37,7 +36,7 @@ impl<'a> MultiTestRunner<'a> { pub fn new(address_prefix: &'a str) -> Self { // Construct app let wasm_keeper: WasmKeeper = - WasmKeeper::new().with_address_generator(MockAddressGenerator); + WasmKeeper::new_with_custom_address_generator(MockAddressGenerator); let app = BasicAppBuilder::::new() .with_api(MockApiBech32::new(address_prefix)) @@ -483,7 +482,7 @@ mod tests { assert_eq!( wasm_event, &Event::new("wasm") - .add_attribute("_contract_address", contract_addr) + .add_attribute("_contract_addr", contract_addr) .add_attribute("action", "mint") .add_attribute("to", alice.address()) .add_attribute("amount", "100") @@ -673,4 +672,3 @@ mod tests { assert_eq!(app.app.block_info().time.seconds(), time.seconds() + 69); } } - diff --git a/src/multi_test/test_addresses.rs b/src/multi_test/test_addresses.rs deleted file mode 100644 index 7bfa681..0000000 --- a/src/multi_test/test_addresses.rs +++ /dev/null @@ -1,52 +0,0 @@ -use anyhow::Result; -use apollo_cw_multi_test::AddressGenerator; -use cosmwasm_std::{instantiate2_address, Addr, Api, CanonicalAddr, Storage}; -use sha2::digest::Update; -use sha2::{Digest, Sha256}; -#[derive(Default)] -pub struct MockAddressGenerator; - -impl AddressGenerator for MockAddressGenerator { - fn contract_address( - &self, - api: &dyn Api, - _storage: &mut dyn Storage, - code_id: u64, - instance_id: u64, - ) -> Result { - let canonical_addr = Self::instantiate_address(code_id, instance_id); - Ok(Addr::unchecked(api.addr_humanize(&canonical_addr)?)) - } - - fn predictable_contract_address( - &self, - api: &dyn Api, - _storage: &mut dyn Storage, - _code_id: u64, - _instance_id: u64, - checksum: &[u8], - creator: &CanonicalAddr, - salt: &[u8], - ) -> Result { - let canonical_addr = instantiate2_address(checksum, creator, salt)?; - Ok(Addr::unchecked(api.addr_humanize(&canonical_addr)?)) - } -} - -impl MockAddressGenerator { - // non-predictable contract address generator, see `BuildContractAddressClassic` - // implementation in wasmd: https://github.com/CosmWasm/wasmd/blob/main/x/wasm/keeper/addresses.go#L35-L42 - fn instantiate_address(code_id: u64, instance_id: u64) -> CanonicalAddr { - let mut key = Vec::::new(); - key.extend_from_slice(b"wasm\0"); - key.extend_from_slice(&code_id.to_be_bytes()); - key.extend_from_slice(&instance_id.to_be_bytes()); - let module = Sha256::digest("module".as_bytes()); - Sha256::new() - .chain(module) - .chain(key) - .finalize() - .to_vec() - .into() - } -}