Skip to content

Commit

Permalink
feat: use new WasmKeeper
Browse files Browse the repository at this point in the history
  • Loading branch information
ApolloGie committed Aug 15, 2024
1 parent 77505f2 commit 389c6a2
Show file tree
Hide file tree
Showing 51 changed files with 134 additions and 68 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ osmosis-test-tube = { version = "25.0.0", optional = true }

# Astroport deps
astroport = { version = "2.9.0", optional = true }
astroport_v5 = { package = "astroport", version = "5.1.0", optional = true }
astroport_v5 = { package = "astroport", version = "5.2.0", optional = true }
cw20 = { version = "0.15", optional = true }

# Astroport contracts for multi-test
Expand All @@ -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 = { version = "0.18.1", features = ["stargate"], optional = true }
apollo-cw-multi-test = { git = "https://github.com/apollodao/cw-multi-test.git", rev = "7e7bc2b91a8199c47815b45ef23b3ab07390ae3a",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 }
Expand Down
Empty file added artifacts/4d3be0e/Macd
Empty file.
Binary file added artifacts/4d3be0e/astro_token_converter.wasm
Binary file not shown.
Binary file not shown.
Binary file added artifacts/4d3be0e/astroport_factory.wasm
Binary file not shown.
Binary file added artifacts/4d3be0e/astroport_fee_granter.wasm
Binary file not shown.
Binary file added artifacts/4d3be0e/astroport_incentives.wasm
Binary file not shown.
Binary file added artifacts/4d3be0e/astroport_maker.wasm
Binary file not shown.
Binary file not shown.
Binary file added artifacts/4d3be0e/astroport_oracle.wasm
Binary file not shown.
Binary file added artifacts/4d3be0e/astroport_pair.wasm
Binary file not shown.
Binary file not shown.
Binary file added artifacts/4d3be0e/astroport_pair_converter.wasm
Binary file not shown.
Binary file added artifacts/4d3be0e/astroport_pair_stable.wasm
Binary file not shown.
Binary file added artifacts/4d3be0e/astroport_pair_transmuter.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added artifacts/4d3be0e/astroport_staking.wasm
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file added artifacts/4d3be0e/astroport_vesting.wasm
Binary file not shown.
Binary file added artifacts/4d3be0e/astroport_whitelist.wasm
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions artifacts/4d3be0e/checksums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
a756ab73b4d6e7377359d5bf1b3d0af759b58cfb3352ec4927626bcf0f5ef245 astro_token_converter.wasm
9dc8255553d46a4abd2314f63a6940b6ea291224ded6d046aee42720c1bf5364 astro_token_converter_neutron.wasm
d57d8dadf98df6d7c6dbea1f69984c8894b96af7c71bc3b973b40995bbac4a46 astroport_factory.wasm
df47bf038de4ae73fd6d725bddf0e70bb58199bf9a17f6b90b3eba83b0855a28 astroport_fee_granter.wasm
d529ef4af3deb9438e4e40ee06020d9335b2a626b4a645da4bab38304d2197fe astroport_incentives.wasm
adefc4ee995b783bc45b0c338a6299a03fdeadb1f69ced4c2b6f22af07b9ec1a astroport_maker.wasm
ef3ea4ad2e4f671a4843827dab7bf8e6ed1075d9adc487671e9b24e551d21eac astroport_native_coin_registry.wasm
485ccdb2dbd2268fb6ab0466f33357d0cd44a837ee4fa6cc73f8be46a623edc9 astroport_oracle.wasm
c89f5c656491a031980debff8396ea54afa1a09acbf13ea75c1413d62c930cff astroport_pair.wasm
9c3722049102fa394eee49a4b1a7af4e57e55e5c24875c5412a047b62db01da7 astroport_pair_concentrated.wasm
22f5ae889bf8ba1f386f2e00b382a825b224b551c8510011a61777cdda28dc15 astroport_pair_converter.wasm
7f02590d0de9dfa8db1cd3b194981edb4d62e4d99ebd2ff2107e60cdeca8335e astroport_pair_stable.wasm
5f143cd5ae92c8934291a3e6bea86fe38135a11ba609660e50c70a1d9abeae8c astroport_pair_transmuter.wasm
d38b32306558cf1d2919e9ebc5618b60585c33fa30960651aecef90418437095 astroport_pair_xyk_sale_tax.wasm
6fef673b1318c84ac8ab2ca81b2cdca96b8c8c9d0995b8038d919f539ae7c3cc astroport_router.wasm
b174c208fe505d20e70735589785b5b852876c29cfead91bfaf6d5708431eb5b astroport_staking.wasm
57a252398ea44a1182464435a8351983202c3166a3c0d915d8c0981350bf90ef astroport_tokenfactory_tracker.wasm
f2f3345a85284a477d35955618a93d38037ff5a82aec68589e98239e50ff9880 astroport_vesting.wasm
fcb69841024490d0b935a55ee6134c8d72fee8b0deb07a3dc2fa29c3e5f5c02a astroport_whitelist.wasm
431a6e47a90f3780e7e4aae120056b604e2f5949180d29979c1f488ba889e7fe astroport_xastro_token.wasm
Binary file removed artifacts/99884be/astro_token_converter.wasm
Binary file not shown.
Binary file not shown.
Binary file removed artifacts/99884be/astroport_factory.wasm
Binary file not shown.
Binary file removed artifacts/99884be/astroport_fee_granter.wasm
Binary file not shown.
Binary file removed artifacts/99884be/astroport_generator.wasm
Binary file not shown.
Binary file removed artifacts/99884be/astroport_incentives.wasm
Binary file not shown.
Binary file removed artifacts/99884be/astroport_maker.wasm
Binary file not shown.
Binary file not shown.
Binary file removed artifacts/99884be/astroport_oracle.wasm
Binary file not shown.
Binary file removed artifacts/99884be/astroport_pair.wasm
Binary file not shown.
Binary file removed artifacts/99884be/astroport_pair_concentrated.wasm
Binary file not shown.
Binary file removed artifacts/99884be/astroport_pair_converter.wasm
Binary file not shown.
Binary file removed artifacts/99884be/astroport_pair_stable.wasm
Binary file not shown.
Binary file removed artifacts/99884be/astroport_pair_transmuter.wasm
Binary file not shown.
Binary file removed artifacts/99884be/astroport_pair_xyk_sale_tax.wasm
Binary file not shown.
Binary file removed artifacts/99884be/astroport_staking.wasm
Binary file not shown.
Binary file not shown.
Binary file removed artifacts/99884be/astroport_vesting.wasm
Binary file not shown.
Binary file removed artifacts/99884be/astroport_whitelist.wasm
Binary file not shown.
5 changes: 3 additions & 2 deletions src/astroport/robot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,10 @@ mod tests {
let admin = &robot.accs[0];

let precision = robot
.add_denom_precision_to_coin_registry("uatom", 69, admin)
.add_denom_precision_to_coin_registry("uatom", 6, admin)
.query_native_coin_registry("uatom")
.unwrap();
assert_eq!(precision, 69);
assert_eq!(precision, 6);
}
}

1 change: 0 additions & 1 deletion src/astroport/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,4 +1014,3 @@ mod tests {
);
}
}

20 changes: 19 additions & 1 deletion src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use std::fmt::Debug;
use std::{collections::HashMap, str::FromStr};

use cosmwasm_std::{Coin, StdError, StdResult, Uint128};
use osmosis_std::types::cosmos::bank::v1beta1::{MsgSend, MsgSendResponse, QueryBalanceRequest};
use osmosis_std::types::cosmos::bank::v1beta1::{
MsgSend, MsgSendResponse, QueryAllBalancesRequest, QueryAllBalancesResponse,
QueryBalanceRequest,
};
use osmosis_std::types::cosmos::base::query::v1beta1::PageRequest;
use osmosis_std::types::cosmos::base::v1beta1::Coin as ProtoCoin;
use serde::Serialize;
use test_tube::{Account, Module, Runner, RunnerExecuteResult, RunnerResult, SigningAccount};
Expand Down Expand Up @@ -108,6 +112,19 @@ pub fn bank_balance_query<'a>(
.ok_or_else(|| StdError::generic_err("Bank balance query failed"))
}

pub fn bank_all_balances_query<'a>(
runner: &'a impl Runner<'a>,
address: String,
pagination: Option<PageRequest>,
) -> StdResult<QueryAllBalancesResponse> {
Bank::new(runner)
.query_all_balances(&QueryAllBalancesRequest {
address,
pagination,
})
.or_else(|_| Err(StdError::generic_err("Bank all balances query failed")))
}

pub fn bank_send<'a>(
runner: &'a impl Runner<'a>,
sender: &SigningAccount,
Expand Down Expand Up @@ -187,3 +204,4 @@ fn test_unwrap_panic() {
let res: Result<u32, &str> = Err("random");
Unwrap::Err("test").unwrap(res);
}

1 change: 1 addition & 0 deletions src/multi_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ pub mod api;

pub use crate::create_contract_wrappers;
pub use runner::MultiTestRunner;
pub mod test_addresses;
2 changes: 1 addition & 1 deletion src/multi_test/modules/token_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl TokenFactory<'_> {
res.data = Some(data.into());
res.events.push(
Event::new("tf_mint")
.add_attribute("mint_to_address", "sender")
.add_attribute("mint_to_address", sender.to_string())
.add_attribute("amount", amount.to_string()),
);
Ok(res)
Expand Down
77 changes: 26 additions & 51 deletions src/multi_test/runner.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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 cosmrs::{crypto::secp256k1::SigningKey, proto::cosmos::base::abci::v1beta1::GasInfo};

use cosmwasm_std::{
coin, Addr, BankMsg, Binary, Coin, CosmosMsg, Empty, QueryRequest, StakingMsg, WasmMsg,
};
Expand All @@ -25,8 +26,6 @@ use test_tube::{
Account, DecodeError, EncodeError, FeeSetting, Runner, RunnerError, SigningAccount,
};

use super::api::MockApiBech;

pub struct MultiTestRunner<'a> {
pub app: apollo_cw_multi_test::App<BankKeeper, MockApiBech32<'a>>,
pub address_prefix: &'a str,
Expand All @@ -37,8 +36,12 @@ impl<'a> MultiTestRunner<'a> {
/// with the given address prefix.
pub fn new(address_prefix: &'a str) -> Self {
// Construct app
let wasm_keeper: WasmKeeper<Empty, Empty> =
WasmKeeper::new().with_address_generator(MockAddressGenerator);

let app = BasicAppBuilder::<Empty, Empty>::new()
.with_api(MockApiBech32::new(address_prefix))
.with_wasm(wasm_keeper)
.build(|_, _, _| {});

Self {
Expand Down Expand Up @@ -362,7 +365,10 @@ mod tests {
use cosmrs::proto::cosmos::bank::v1beta1::MsgSendResponse;
use cosmwasm_std::{coin, Event, Uint128};

use crate::test_helpers::*;
use crate::{artifact::Artifact, helpers::upload_wasm_file};
use apollo_cw_multi_test::ContractWrapper;

use cw20::MinterResponse;
use osmosis_std::types::cosmos::bank::v1beta1::{
QueryBalanceRequest, QuerySupplyOfRequest, QueryTotalSupplyRequest,
Expand All @@ -374,11 +380,6 @@ mod tests {
};
use test_tube::{Bank, Module, RunnerExecuteResult, Wasm};

use crate::multi_test::api::MockApiBech;
use crate::{artifact::Artifact, helpers::upload_wasm_file};

use crate::test_helpers::*;

use super::*;

fn instantiate_astro_token(
Expand Down Expand Up @@ -457,18 +458,17 @@ mod tests {
fn wasm_execute_contract() {
// start the keeper
let app = MultiTestRunner::new("osmo");
let mock_api = MockApiBech32::new("osmo");

let alice = app.init_account(&[coin(1000, "uosmo")]).unwrap();

let res = instantiate_astro_token(&app, &alice).unwrap();

let contract_addr = mock_api.addr_make(&res.data.address);
let contract_addr = res.data.address;

let wasm = Wasm::new(&app);
let res = wasm
.execute(
&contract_addr.to_string(),
&contract_addr,
&cw20_base::msg::ExecuteMsg::Mint {
recipient: alice.address(),
amount: 100u128.into(),
Expand All @@ -483,7 +483,7 @@ mod tests {
assert_eq!(
wasm_event,
&Event::new("wasm")
.add_attribute("_contract_addr", contract_addr)
.add_attribute("_contract_address", contract_addr)
.add_attribute("action", "mint")
.add_attribute("to", alice.address())
.add_attribute("amount", "100")
Expand All @@ -493,6 +493,7 @@ mod tests {
#[test]
fn wasm_smart_query_contract() {
let app = MultiTestRunner::new("osmo");

let alice = app.init_account(&[coin(1000, "uosmo")]).unwrap();

let res = instantiate_astro_token(&app, &alice).unwrap();
Expand Down Expand Up @@ -527,20 +528,21 @@ mod tests {
#[test]
fn wasm_contract_info_query() {
let app = MultiTestRunner::new("osmo");

let alice = app.init_account(&[coin(1000, "uosmo")]).unwrap();

let res = instantiate_astro_token(&app, &alice).unwrap();
println!("res: {:?}", res);
let mock_api = MockApiBech32::new("osmo");
let contract_addr = res.data.address; //mock_api.addr_make(&res.data.address).to_string();
println!("contract_addr: {:?}", contract_addr);
println!("MsgInstantiateContractRes: {:?}", res);
let contract_addr = res.data.address;

let res = QueryContractInfoRequest {
address: contract_addr.clone(),
}
.query(&app.app.wrap())
.unwrap();

println!("QueryContractInfoRes: {:?}", res);

assert_eq!(res.address, contract_addr);
let info = res.contract_info.unwrap();
assert_eq!(info.code_id, 1);
Expand All @@ -551,42 +553,16 @@ mod tests {
#[test]
fn bank_send() {
let app = MultiTestRunner::new("osmo");
let bank: Bank<MultiTestRunner> = Bank::new(&app);
let alice = app.init_account(&[coin(1000, "uatom")]).unwrap();
let bob = app.init_account(&[]).unwrap();

let mock_api_bech = MockApiBech32::new("osmo");
let alice_address = mock_api_bech.addr_make(&alice.address()).to_string();
let bob_address = mock_api_bech.addr_make(&bob.address()).to_string();
let bank_query = bank
.query_all_balances(&QueryAllBalancesRequest {
address: alice_address.clone(),
pagination: None,
})
.unwrap();

println!("alice_address bank_query: {:?}", bank_query);

let bank_query = bank
.query_all_balances(&QueryAllBalancesRequest {
address: bob_address.clone(),
pagination: None,
})
.unwrap();

println!("bob_address bank_query: {:?}", bank_query);

println!("alice_address {}", alice_address);
println!("bob_address {}", bob_address);
let msgs = vec![cosmwasm_std::CosmosMsg::Bank(cosmwasm_std::BankMsg::Send {
to_address: bob.address(),
amount: vec![cosmwasm_std::Coin {
denom: "uatom".to_string(),
amount: 100u128.into(),
}],
})];
println!("alice.address(): {:?}", alice.address());


let res = app
.execute_cosmos_msgs::<MsgSendResponse>(&msgs, &alice)
Expand All @@ -596,9 +572,9 @@ mod tests {
assert_eq!(
res.events[0],
Event::new("transfer")
.add_attribute("recipient", bob.address())
.add_attribute("sender", alice.address())
.add_attribute("amount", "100uatom")
.add_attribute("recipient", bob.address())
.add_attribute("sender", alice.address())
.add_attribute("amount", "100uatom")
);

let bank = Bank::new(&app);
Expand All @@ -616,9 +592,9 @@ mod tests {
assert_eq!(
res.events[0],
Event::new("transfer")
.add_attribute("recipient", bob.address())
.add_attribute("sender", alice.address())
.add_attribute("amount", "100uatom")
.add_attribute("recipient", bob.address())
.add_attribute("sender", alice.address())
.add_attribute("amount", "100uatom")
);
}

Expand All @@ -627,9 +603,8 @@ mod tests {
let app = MultiTestRunner::new("osmo");
let alice = app.init_account(&[coin(1000, "uatom")]).unwrap();

let mock_api_bech = MockApiBech32::new("osmo");
let bank: Bank<MultiTestRunner> = Bank::new(&app);
let alice_address = mock_api_bech.addr_make(&alice.address());
let bank = Bank::new(&app);

// Query all balances
let res = bank
.query_all_balances(&QueryAllBalancesRequest {
Expand Down
Loading

0 comments on commit 389c6a2

Please sign in to comment.