Skip to content

Commit 4e0336a

Browse files
committed
astroport: Add .with_chain builder calls.
1 parent 14ceca2 commit 4e0336a

File tree

2 files changed

+53
-27
lines changed

2 files changed

+53
-27
lines changed

src/types/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ pub mod config;
55
pub mod contract;
66

77
pub mod ibc;
8-
9-
pub mod osmosis;

src/utils/setup/astroport.rs

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use super::super::{
22
super::{
3-
error::Error, CW1_WHITELIST_NAME, DEFAULT_KEY, FACTORY_NAME, FACTORY_ON_OSMOSIS_NAME,
4-
NEUTRON_CHAIN_ADMIN_ADDR, NEUTRON_CHAIN_NAME, OSMOSIS_CHAIN_NAME, PAIR_NAME,
5-
STABLE_PAIR_NAME, TOKEN_NAME, TOKEN_REGISTRY_NAME, WHITELIST_NAME,
3+
error::Error, DEFAULT_KEY, FACTORY_NAME, NEUTRON_CHAIN_ADMIN_ADDR, NEUTRON_CHAIN_NAME,
4+
PAIR_NAME, STABLE_PAIR_NAME, TOKEN_NAME, TOKEN_REGISTRY_NAME, WHITELIST_NAME,
65
},
76
test_context::TestContext,
87
};
@@ -16,6 +15,7 @@ use cosmwasm_std::Decimal;
1615
/// A tx creating a token registry.
1716
pub struct CreateTokenRegistryTxBuilder<'a> {
1817
key: Option<&'a str>,
18+
chain: &'a str,
1919
owner: Option<String>,
2020
test_ctx: &'a mut TestContext,
2121
}
@@ -44,6 +44,7 @@ impl<'a> CreateTokenRegistryTxBuilder<'a> {
4444
self.test_ctx.tx_create_token_registry(
4545
self.key
4646
.ok_or(Error::MissingBuilderParam(String::from("key")))?,
47+
self.chain,
4748
self.owner
4849
.clone()
4950
.ok_or(Error::MissingBuilderParam(String::from("owner")))?,
@@ -54,6 +55,7 @@ impl<'a> CreateTokenRegistryTxBuilder<'a> {
5455
/// A tx creating a token registry.
5556
pub struct CreatePoolTxBuilder<'a> {
5657
key: &'a str,
58+
chain: &'a str,
5759
pair_type: PairType,
5860
denom_a: Option<String>,
5961
denom_b: Option<String>,
@@ -67,6 +69,12 @@ impl<'a> CreatePoolTxBuilder<'a> {
6769
self
6870
}
6971

72+
pub fn with_chain(&mut self, chain: &'a str) -> &mut Self {
73+
self.chain = chain;
74+
75+
self
76+
}
77+
7078
pub fn with_pairtype(&mut self, pairtype: PairType) -> &mut Self {
7179
self.pair_type = pairtype;
7280

@@ -89,6 +97,7 @@ impl<'a> CreatePoolTxBuilder<'a> {
8997
pub fn send(&mut self) -> Result<(), Error> {
9098
self.test_ctx.tx_create_pool(
9199
self.key,
100+
self.chain,
92101
self.pair_type.clone(),
93102
self.denom_a
94103
.clone()
@@ -103,6 +112,7 @@ impl<'a> CreatePoolTxBuilder<'a> {
103112
/// A tx creating an astroport factory.
104113
pub struct CreateFactoryTxBuilder<'a> {
105114
key: &'a str,
115+
chain: &'a str,
106116
owner: String,
107117
test_ctx: &'a mut TestContext,
108118
}
@@ -114,6 +124,12 @@ impl<'a> CreateFactoryTxBuilder<'a> {
114124
self
115125
}
116126

127+
pub fn with_chain(&mut self, chain: &'a str) -> &mut Self {
128+
self.chain = chain;
129+
130+
self
131+
}
132+
117133
pub fn with_owner(&mut self, owner: impl Into<String>) -> &mut Self {
118134
self.owner = owner.into();
119135

@@ -123,13 +139,14 @@ impl<'a> CreateFactoryTxBuilder<'a> {
123139
/// Sends the transaction.
124140
pub fn send(&mut self) -> Result<(), Error> {
125141
self.test_ctx
126-
.tx_create_factory(self.key, self.owner.clone())
142+
.tx_create_factory(self.key, self.chain, self.owner.clone())
127143
}
128144
}
129145

130146
/// A tx funding an astroport pool.
131147
pub struct FundPoolTxBuilder<'a> {
132148
key: &'a str,
149+
chain: &'a str,
133150
denom_a: Option<String>,
134151
denom_b: Option<String>,
135152
amt_denom_a: Option<u128>,
@@ -146,6 +163,12 @@ impl<'a> FundPoolTxBuilder<'a> {
146163
self
147164
}
148165

166+
pub fn with_chain(&mut self, chain: &'a str) -> &mut Self {
167+
self.chain = chain;
168+
169+
self
170+
}
171+
149172
pub fn with_denom_a(&mut self, denom_a: impl Into<String>) -> &mut Self {
150173
self.denom_a = Some(denom_a.into());
151174

@@ -186,6 +209,7 @@ impl<'a> FundPoolTxBuilder<'a> {
186209
pub fn send(&mut self) -> Result<(), Error> {
187210
self.test_ctx.tx_fund_pool(
188211
self.key,
212+
self.chain,
189213
self.denom_a
190214
.clone()
191215
.ok_or(Error::MissingBuilderParam(String::from("denom_a")))?,
@@ -212,6 +236,7 @@ impl TestContext {
212236
pub fn build_tx_create_token_registry(&mut self) -> CreateTokenRegistryTxBuilder {
213237
CreateTokenRegistryTxBuilder {
214238
key: Some(DEFAULT_KEY),
239+
chain: NEUTRON_CHAIN_NAME,
215240
owner: Some(NEUTRON_CHAIN_ADMIN_ADDR.to_owned()),
216241
test_ctx: self,
217242
}
@@ -221,11 +246,12 @@ impl TestContext {
221246
fn tx_create_token_registry(
222247
&mut self,
223248
key: &str,
249+
chain: &str,
224250
owner_addr: impl Into<String>,
225251
) -> Result<(), Error> {
226252
let mut contract_a = self
227253
.get_contract()
228-
.src(NEUTRON_CHAIN_NAME)
254+
.src(chain)
229255
.contract(TOKEN_REGISTRY_NAME)
230256
.get_cw();
231257

@@ -241,7 +267,7 @@ impl TestContext {
241267
)?;
242268
let addr = contract.address;
243269

244-
let neutron = self.get_mut_chain(NEUTRON_CHAIN_NAME);
270+
let neutron = self.get_mut_chain(chain);
245271

246272
neutron
247273
.contract_addrs
@@ -254,6 +280,7 @@ impl TestContext {
254280
pub fn build_tx_create_factory(&mut self) -> CreateFactoryTxBuilder {
255281
CreateFactoryTxBuilder {
256282
key: DEFAULT_KEY,
283+
chain: NEUTRON_CHAIN_NAME,
257284
owner: NEUTRON_CHAIN_ADMIN_ADDR.to_owned(),
258285
test_ctx: self,
259286
}
@@ -263,48 +290,45 @@ impl TestContext {
263290
fn tx_create_factory(
264291
&mut self,
265292
key: &str,
293+
chain: &str,
266294
factory_owner: impl Into<String>,
267295
) -> Result<(), Error> {
268-
let chain = self.get_chain(chain_name);
296+
let local_chain = self.get_chain(chain);
269297

270298
let pair_xyk_code_id =
271-
neutron
299+
local_chain
272300
.contract_codes
273301
.get(PAIR_NAME)
274302
.ok_or(Error::MissingContextVariable(String::from(
275303
"contract_codes::astroport_pair",
276304
)))?;
277-
let pair_stable_code_id =
278-
neutron
279-
.contract_codes
280-
.get(STABLE_PAIR_NAME)
281-
.ok_or(Error::MissingContextVariable(String::from(
282-
"contract_codes::astroport_pair_stable",
283-
)))?;
305+
let pair_stable_code_id = local_chain.contract_codes.get(STABLE_PAIR_NAME).ok_or(
306+
Error::MissingContextVariable(String::from("contract_codes::astroport_pair_stable")),
307+
)?;
284308
let token_code_id =
285-
neutron
309+
local_chain
286310
.contract_codes
287311
.get(TOKEN_NAME)
288312
.ok_or(Error::MissingContextVariable(String::from(
289313
"contract_codes::cw20_base",
290314
)))?;
291315
let whitelist_code_id =
292-
neutron
316+
local_chain
293317
.contract_codes
294318
.get(WHITELIST_NAME)
295319
.ok_or(Error::MissingContextVariable(String::from(
296320
"contract_codes::astroport_whitelist",
297321
)))?;
298322

299-
let native_registry_addr = neutron.contract_addrs.get(TOKEN_REGISTRY_NAME).ok_or(
323+
let native_registry_addr = local_chain.contract_addrs.get(TOKEN_REGISTRY_NAME).ok_or(
300324
Error::MissingContextVariable(String::from(
301325
"contract_ddrs::astroport_native_coin_registry",
302326
)),
303327
)?;
304328

305329
let mut contract_a = self
306330
.get_contract()
307-
.src(NEUTRON_CHAIN_NAME)
331+
.src(chain)
308332
.contract(FACTORY_NAME)
309333
.get_cw();
310334

@@ -345,9 +369,9 @@ impl TestContext {
345369
"",
346370
)?;
347371

348-
let neutron = self.get_mut_chain(NEUTRON_CHAIN_NAME);
372+
let local_chain = self.get_mut_chain(chain);
349373

350-
neutron
374+
local_chain
351375
.contract_addrs
352376
.insert(FACTORY_NAME.to_owned(), contract.address);
353377

@@ -358,6 +382,7 @@ impl TestContext {
358382
pub fn build_tx_create_pool(&mut self) -> CreatePoolTxBuilder {
359383
CreatePoolTxBuilder {
360384
key: DEFAULT_KEY,
385+
chain: NEUTRON_CHAIN_NAME,
361386
pair_type: PairType::Xyk {},
362387
denom_a: Default::default(),
363388
denom_b: Default::default(),
@@ -369,12 +394,13 @@ impl TestContext {
369394
fn tx_create_pool(
370395
&self,
371396
key: &str,
397+
chain: &str,
372398
pair_type: PairType,
373399
denom_a: impl Into<String>,
374400
denom_b: impl Into<String>,
375401
) -> Result<(), Error> {
376402
// Factory contract instance
377-
let contract_a = self.get_factory().src(NEUTRON_CHAIN_NAME).get_cw();
403+
let contract_a = self.get_factory().src(chain).get_cw();
378404

379405
// Create the pair
380406
let tx = contract_a.execute(
@@ -400,7 +426,7 @@ impl TestContext {
400426
"transaction did not produce a tx hash",
401427
)))?;
402428

403-
self.guard_tx_errors(NEUTRON_CHAIN_NAME, tx_hash.as_str())?;
429+
self.guard_tx_errors(chain, tx_hash.as_str())?;
404430

405431
Ok(())
406432
}
@@ -409,6 +435,7 @@ impl TestContext {
409435
pub fn build_tx_fund_pool(&mut self) -> FundPoolTxBuilder {
410436
FundPoolTxBuilder {
411437
key: DEFAULT_KEY,
438+
chain: NEUTRON_CHAIN_NAME,
412439
denom_a: Default::default(),
413440
denom_b: Default::default(),
414441
amt_denom_a: Default::default(),
@@ -424,6 +451,7 @@ impl TestContext {
424451
fn tx_fund_pool(
425452
&mut self,
426453
key: &str,
454+
chain: &str,
427455
denom_a: String,
428456
denom_b: String,
429457
amt_denom_a: u128,
@@ -434,7 +462,7 @@ impl TestContext {
434462
// Get the instance from the address
435463
let pool = self
436464
.get_astro_pool()
437-
.src(NEUTRON_CHAIN_NAME)
465+
.src(chain)
438466
.denoms(denom_a.clone(), denom_b.clone())
439467
.get_cw();
440468

@@ -468,7 +496,7 @@ impl TestContext {
468496
.tx_hash
469497
.ok_or(Error::TxMissingLogs)?;
470498

471-
self.guard_tx_errors(NEUTRON_CHAIN_NAME, tx.as_str())?;
499+
self.guard_tx_errors(chain, tx.as_str())?;
472500

473501
Ok(())
474502
}

0 commit comments

Comments
 (0)