Skip to content

Commit 60006f6

Browse files
Merge pull request #27 from timewave-computer/dowlandaiello/refactor-querybuilder-micro
Refactor TestContext Queries to All Use Builder Pattern
2 parents a8351bc + 73c2fbb commit 60006f6

17 files changed

+661
-497
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
353 KB
Binary file not shown.
Binary file not shown.
242 KB
Binary file not shown.
369 KB
Binary file not shown.
333 KB
Binary file not shown.

examples/neutron.rs

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const ARTIFACTS_DIR: &str = "contracts";
99
const ACC_0_ADDR: &str = "neutron1hj5fveer5cjtn4wd6wstzugjfdxzl0xpznmsky";
1010
const LOCAL_CODE_ID_CACHE_PATH: &str = "code_id_cache.json";
1111

12-
const TEST_TOKEN_1_NAME: &str = "bruhtoken3";
13-
const TEST_TOKEN_2_NAME: &str = "amoguscoin3";
12+
const TEST_TOKEN_1_NAME: &str = "bruhtoken";
13+
const TEST_TOKEN_2_NAME: &str = "amoguscoin";
1414

1515
/// Demonstrates using localic-utils for neutron.
1616
fn main() -> Result<(), Box<dyn Error>> {
@@ -39,8 +39,16 @@ fn main() -> Result<(), Box<dyn Error>> {
3939
.with_subdenom(TEST_TOKEN_2_NAME)
4040
.send()?;
4141

42-
let bruhtoken = ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_1_NAME);
43-
let amoguscoin = ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_2_NAME);
42+
let bruhtoken = ctx
43+
.get_tokenfactory_denom()
44+
.creator(ACC_0_ADDR)
45+
.subdenom(TEST_TOKEN_1_NAME.to_owned())
46+
.get();
47+
let amoguscoin = ctx
48+
.get_tokenfactory_denom()
49+
.creator(ACC_0_ADDR)
50+
.subdenom(TEST_TOKEN_2_NAME.to_owned())
51+
.get();
4452

4553
// Deploy valence auctions
4654
ctx.build_tx_create_auctions_manager()
@@ -81,14 +89,26 @@ fn main() -> Result<(), Box<dyn Error>> {
8189
.with_amount_offer_asset(10000)
8290
.send()?;
8391

84-
ctx.get_auction((
85-
"untrn",
86-
ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_1_NAME),
87-
))?;
88-
ctx.get_auction((
89-
"untrn",
90-
ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_2_NAME),
91-
))?;
92+
let _ = ctx
93+
.get_auction()
94+
.offer_asset("untrn")
95+
.ask_asset(
96+
&ctx.get_tokenfactory_denom()
97+
.creator(ACC_0_ADDR)
98+
.subdenom(TEST_TOKEN_1_NAME.to_owned())
99+
.get(),
100+
)
101+
.get_cw();
102+
let _ = ctx
103+
.get_auction()
104+
.offer_asset("untrn")
105+
.ask_asset(
106+
&ctx.get_tokenfactory_denom()
107+
.creator(ACC_0_ADDR)
108+
.subdenom(TEST_TOKEN_2_NAME.to_owned())
109+
.get(),
110+
)
111+
.get_cw();
92112

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

108-
let pool = ctx.get_astroport_pool(
109-
"untrn",
110-
ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_2_NAME),
111-
)?;
128+
let pool = ctx
129+
.get_astro_pool()
130+
.denoms(
131+
"untrn".to_owned(),
132+
ctx.get_tokenfactory_denom()
133+
.creator(ACC_0_ADDR)
134+
.subdenom(TEST_TOKEN_2_NAME.to_owned())
135+
.get(),
136+
)
137+
.get_cw();
112138

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

142168
let factory_contract_code_id = ctx
143-
.get_contract("astroport_whitelist")
144-
.unwrap()
169+
.get_contract()
170+
.contract("astroport_whitelist")
171+
.get_cw()
145172
.code_id
146173
.unwrap();
147174

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

168-
let mut cw = ctx.get_contract("astroport_whitelist").unwrap();
195+
let mut cw = ctx.get_contract().contract("astroport_whitelist").get_cw();
169196
cw.contract_addr = Some(addr);
170197

171198
cw.execute(

examples/neutron_osmosis.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ fn main() -> Result<(), Box<dyn Error>> {
3232
.with_chain_name("neutron")
3333
.with_subdenom("bruhtoken")
3434
.send()?;
35-
let bruhtoken = ctx.get_tokenfactory_denom(NEUTRON_ACC_0_ADDR, "bruhtoken");
35+
let bruhtoken = ctx
36+
.get_tokenfactory_denom()
37+
.creator(NEUTRON_ACC_0_ADDR)
38+
.subdenom("bruhtoken".into())
39+
.get();
3640
ctx.build_tx_mint_tokenfactory_token()
3741
.with_chain_name("neutron")
3842
.with_amount(10000000000000000000)
@@ -53,8 +57,18 @@ fn main() -> Result<(), Box<dyn Error>> {
5357
.with_amount(1000000)
5458
.send()?;
5559

56-
let ibc_bruhtoken = ctx.get_ibc_denom(&bruhtoken, "neutron", "osmosis");
57-
let ibc_neutron = ctx.get_ibc_denom("untrn", "neutron", "osmosis");
60+
let ibc_bruhtoken = ctx
61+
.get_ibc_denom()
62+
.base_denom(bruhtoken.clone())
63+
.src("neutron")
64+
.dest("osmosis")
65+
.get();
66+
let ibc_neutron = ctx
67+
.get_ibc_denom()
68+
.base_denom("untrn".into())
69+
.src("neutron")
70+
.dest("osmosis")
71+
.get();
5872

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

6781
// Get its id
68-
let pool_id = ctx.get_osmo_pool(&ibc_neutron, &ibc_bruhtoken)?;
82+
let pool_id = ctx
83+
.get_osmo_pool()
84+
.denoms(ibc_neutron.clone(), ibc_bruhtoken.clone())
85+
.get_u64();
6986

7087
// Fund the pool
7188
ctx.build_tx_fund_osmo_pool()

examples/osmosis.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ fn main() -> Result<(), Box<dyn Error>> {
2121
.with_chain_name(OSMOSIS_CHAIN_NAME)
2222
.with_subdenom("bruhtoken")
2323
.send()?;
24-
let bruhtoken = ctx.get_tokenfactory_denom(ACC_0_ADDR, "bruhtoken");
24+
let bruhtoken = ctx
25+
.get_tokenfactory_denom()
26+
.creator(ACC_0_ADDR)
27+
.subdenom("bruhtoken".into())
28+
.get();
2529
ctx.build_tx_mint_tokenfactory_token()
2630
.with_chain_name(OSMOSIS_CHAIN_NAME)
2731
.with_amount(10000000000000000000)
@@ -38,7 +42,10 @@ fn main() -> Result<(), Box<dyn Error>> {
3842
.send()?;
3943

4044
// Get its id
41-
let pool_id = ctx.get_osmo_pool("uosmo", &bruhtoken)?;
45+
let pool_id = ctx
46+
.get_osmo_pool()
47+
.denoms("uosmo".into(), bruhtoken.clone())
48+
.get_u64();
4249

4350
// Fund the pool
4451
ctx.build_tx_fund_osmo_pool()

0 commit comments

Comments
 (0)