Skip to content

Commit

Permalink
Merge pull request #27 from timewave-computer/dowlandaiello/refactor-…
Browse files Browse the repository at this point in the history
…querybuilder-micro

Refactor TestContext Queries to All Use Builder Pattern
  • Loading branch information
dowlandaiello authored Sep 6, 2024
2 parents a8351bc + 73c2fbb commit 60006f6
Show file tree
Hide file tree
Showing 17 changed files with 661 additions and 497 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added examples/contracts_osmosis/auction.wasm
Binary file not shown.
Binary file added examples/contracts_osmosis/auctions_manager.wasm
Binary file not shown.
Binary file added examples/contracts_osmosis/cw1_whitelist.wasm
Binary file not shown.
Binary file added examples/contracts_osmosis/cw20_base.wasm
Binary file not shown.
Binary file added examples/contracts_osmosis/price_oracle.wasm
Binary file not shown.
65 changes: 46 additions & 19 deletions examples/neutron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const ARTIFACTS_DIR: &str = "contracts";
const ACC_0_ADDR: &str = "neutron1hj5fveer5cjtn4wd6wstzugjfdxzl0xpznmsky";
const LOCAL_CODE_ID_CACHE_PATH: &str = "code_id_cache.json";

const TEST_TOKEN_1_NAME: &str = "bruhtoken3";
const TEST_TOKEN_2_NAME: &str = "amoguscoin3";
const TEST_TOKEN_1_NAME: &str = "bruhtoken";
const TEST_TOKEN_2_NAME: &str = "amoguscoin";

/// Demonstrates using localic-utils for neutron.
fn main() -> Result<(), Box<dyn Error>> {
Expand Down Expand Up @@ -39,8 +39,16 @@ fn main() -> Result<(), Box<dyn Error>> {
.with_subdenom(TEST_TOKEN_2_NAME)
.send()?;

let bruhtoken = ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_1_NAME);
let amoguscoin = ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_2_NAME);
let bruhtoken = ctx
.get_tokenfactory_denom()
.creator(ACC_0_ADDR)
.subdenom(TEST_TOKEN_1_NAME.to_owned())
.get();
let amoguscoin = ctx
.get_tokenfactory_denom()
.creator(ACC_0_ADDR)
.subdenom(TEST_TOKEN_2_NAME.to_owned())
.get();

// Deploy valence auctions
ctx.build_tx_create_auctions_manager()
Expand Down Expand Up @@ -81,14 +89,26 @@ fn main() -> Result<(), Box<dyn Error>> {
.with_amount_offer_asset(10000)
.send()?;

ctx.get_auction((
"untrn",
ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_1_NAME),
))?;
ctx.get_auction((
"untrn",
ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_2_NAME),
))?;
let _ = ctx
.get_auction()
.offer_asset("untrn")
.ask_asset(
&ctx.get_tokenfactory_denom()
.creator(ACC_0_ADDR)
.subdenom(TEST_TOKEN_1_NAME.to_owned())
.get(),
)
.get_cw();
let _ = ctx
.get_auction()
.offer_asset("untrn")
.ask_asset(
&ctx.get_tokenfactory_denom()
.creator(ACC_0_ADDR)
.subdenom(TEST_TOKEN_2_NAME.to_owned())
.get(),
)
.get_cw();

ctx.build_tx_create_token_registry()
.with_owner(ACC_0_ADDR)
Expand All @@ -105,10 +125,16 @@ fn main() -> Result<(), Box<dyn Error>> {
.with_denom_b(bruhtoken)
.send()?;

let pool = ctx.get_astroport_pool(
"untrn",
ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_2_NAME),
)?;
let pool = ctx
.get_astro_pool()
.denoms(
"untrn".to_owned(),
ctx.get_tokenfactory_denom()
.creator(ACC_0_ADDR)
.subdenom(TEST_TOKEN_2_NAME.to_owned())
.get(),
)
.get_cw();

assert!(pool
.query_value(&serde_json::json!({
Expand Down Expand Up @@ -140,8 +166,9 @@ fn main() -> Result<(), Box<dyn Error>> {
.send()?;

let factory_contract_code_id = ctx
.get_contract("astroport_whitelist")
.unwrap()
.get_contract()
.contract("astroport_whitelist")
.get_cw()
.code_id
.unwrap();

Expand All @@ -165,7 +192,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.salt_hex_encoded(hex::encode("examplesalt").as_str())
.get();

let mut cw = ctx.get_contract("astroport_whitelist").unwrap();
let mut cw = ctx.get_contract().contract("astroport_whitelist").get_cw();
cw.contract_addr = Some(addr);

cw.execute(
Expand Down
25 changes: 21 additions & 4 deletions examples/neutron_osmosis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ fn main() -> Result<(), Box<dyn Error>> {
.with_chain_name("neutron")
.with_subdenom("bruhtoken")
.send()?;
let bruhtoken = ctx.get_tokenfactory_denom(NEUTRON_ACC_0_ADDR, "bruhtoken");
let bruhtoken = ctx
.get_tokenfactory_denom()
.creator(NEUTRON_ACC_0_ADDR)
.subdenom("bruhtoken".into())
.get();
ctx.build_tx_mint_tokenfactory_token()
.with_chain_name("neutron")
.with_amount(10000000000000000000)
Expand All @@ -53,8 +57,18 @@ fn main() -> Result<(), Box<dyn Error>> {
.with_amount(1000000)
.send()?;

let ibc_bruhtoken = ctx.get_ibc_denom(&bruhtoken, "neutron", "osmosis");
let ibc_neutron = ctx.get_ibc_denom("untrn", "neutron", "osmosis");
let ibc_bruhtoken = ctx
.get_ibc_denom()
.base_denom(bruhtoken.clone())
.src("neutron")
.dest("osmosis")
.get();
let ibc_neutron = ctx
.get_ibc_denom()
.base_denom("untrn".into())
.src("neutron")
.dest("osmosis")
.get();

// Create an osmosis pool
ctx.build_tx_create_osmo_pool()
Expand All @@ -65,7 +79,10 @@ fn main() -> Result<(), Box<dyn Error>> {
.send()?;

// Get its id
let pool_id = ctx.get_osmo_pool(&ibc_neutron, &ibc_bruhtoken)?;
let pool_id = ctx
.get_osmo_pool()
.denoms(ibc_neutron.clone(), ibc_bruhtoken.clone())
.get_u64();

// Fund the pool
ctx.build_tx_fund_osmo_pool()
Expand Down
11 changes: 9 additions & 2 deletions examples/osmosis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ fn main() -> Result<(), Box<dyn Error>> {
.with_chain_name(OSMOSIS_CHAIN_NAME)
.with_subdenom("bruhtoken")
.send()?;
let bruhtoken = ctx.get_tokenfactory_denom(ACC_0_ADDR, "bruhtoken");
let bruhtoken = ctx
.get_tokenfactory_denom()
.creator(ACC_0_ADDR)
.subdenom("bruhtoken".into())
.get();
ctx.build_tx_mint_tokenfactory_token()
.with_chain_name(OSMOSIS_CHAIN_NAME)
.with_amount(10000000000000000000)
Expand All @@ -38,7 +42,10 @@ fn main() -> Result<(), Box<dyn Error>> {
.send()?;

// Get its id
let pool_id = ctx.get_osmo_pool("uosmo", &bruhtoken)?;
let pool_id = ctx
.get_osmo_pool()
.denoms("uosmo".into(), bruhtoken.clone())
.get_u64();

// Fund the pool
ctx.build_tx_fund_osmo_pool()
Expand Down
Loading

0 comments on commit 60006f6

Please sign in to comment.