1
1
use super :: super :: {
2
2
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 ,
6
5
} ,
7
6
test_context:: TestContext ,
8
7
} ;
@@ -16,6 +15,7 @@ use cosmwasm_std::Decimal;
16
15
/// A tx creating a token registry.
17
16
pub struct CreateTokenRegistryTxBuilder < ' a > {
18
17
key : Option < & ' a str > ,
18
+ chain : & ' a str ,
19
19
owner : Option < String > ,
20
20
test_ctx : & ' a mut TestContext ,
21
21
}
@@ -44,6 +44,7 @@ impl<'a> CreateTokenRegistryTxBuilder<'a> {
44
44
self . test_ctx . tx_create_token_registry (
45
45
self . key
46
46
. ok_or ( Error :: MissingBuilderParam ( String :: from ( "key" ) ) ) ?,
47
+ self . chain ,
47
48
self . owner
48
49
. clone ( )
49
50
. ok_or ( Error :: MissingBuilderParam ( String :: from ( "owner" ) ) ) ?,
@@ -54,6 +55,7 @@ impl<'a> CreateTokenRegistryTxBuilder<'a> {
54
55
/// A tx creating a token registry.
55
56
pub struct CreatePoolTxBuilder < ' a > {
56
57
key : & ' a str ,
58
+ chain : & ' a str ,
57
59
pair_type : PairType ,
58
60
denom_a : Option < String > ,
59
61
denom_b : Option < String > ,
@@ -67,6 +69,12 @@ impl<'a> CreatePoolTxBuilder<'a> {
67
69
self
68
70
}
69
71
72
+ pub fn with_chain ( & mut self , chain : & ' a str ) -> & mut Self {
73
+ self . chain = chain;
74
+
75
+ self
76
+ }
77
+
70
78
pub fn with_pairtype ( & mut self , pairtype : PairType ) -> & mut Self {
71
79
self . pair_type = pairtype;
72
80
@@ -89,6 +97,7 @@ impl<'a> CreatePoolTxBuilder<'a> {
89
97
pub fn send ( & mut self ) -> Result < ( ) , Error > {
90
98
self . test_ctx . tx_create_pool (
91
99
self . key ,
100
+ self . chain ,
92
101
self . pair_type . clone ( ) ,
93
102
self . denom_a
94
103
. clone ( )
@@ -103,6 +112,7 @@ impl<'a> CreatePoolTxBuilder<'a> {
103
112
/// A tx creating an astroport factory.
104
113
pub struct CreateFactoryTxBuilder < ' a > {
105
114
key : & ' a str ,
115
+ chain : & ' a str ,
106
116
owner : String ,
107
117
test_ctx : & ' a mut TestContext ,
108
118
}
@@ -114,6 +124,12 @@ impl<'a> CreateFactoryTxBuilder<'a> {
114
124
self
115
125
}
116
126
127
+ pub fn with_chain ( & mut self , chain : & ' a str ) -> & mut Self {
128
+ self . chain = chain;
129
+
130
+ self
131
+ }
132
+
117
133
pub fn with_owner ( & mut self , owner : impl Into < String > ) -> & mut Self {
118
134
self . owner = owner. into ( ) ;
119
135
@@ -123,13 +139,14 @@ impl<'a> CreateFactoryTxBuilder<'a> {
123
139
/// Sends the transaction.
124
140
pub fn send ( & mut self ) -> Result < ( ) , Error > {
125
141
self . test_ctx
126
- . tx_create_factory ( self . key , self . owner . clone ( ) )
142
+ . tx_create_factory ( self . key , self . chain , self . owner . clone ( ) )
127
143
}
128
144
}
129
145
130
146
/// A tx funding an astroport pool.
131
147
pub struct FundPoolTxBuilder < ' a > {
132
148
key : & ' a str ,
149
+ chain : & ' a str ,
133
150
denom_a : Option < String > ,
134
151
denom_b : Option < String > ,
135
152
amt_denom_a : Option < u128 > ,
@@ -146,6 +163,12 @@ impl<'a> FundPoolTxBuilder<'a> {
146
163
self
147
164
}
148
165
166
+ pub fn with_chain ( & mut self , chain : & ' a str ) -> & mut Self {
167
+ self . chain = chain;
168
+
169
+ self
170
+ }
171
+
149
172
pub fn with_denom_a ( & mut self , denom_a : impl Into < String > ) -> & mut Self {
150
173
self . denom_a = Some ( denom_a. into ( ) ) ;
151
174
@@ -186,6 +209,7 @@ impl<'a> FundPoolTxBuilder<'a> {
186
209
pub fn send ( & mut self ) -> Result < ( ) , Error > {
187
210
self . test_ctx . tx_fund_pool (
188
211
self . key ,
212
+ self . chain ,
189
213
self . denom_a
190
214
. clone ( )
191
215
. ok_or ( Error :: MissingBuilderParam ( String :: from ( "denom_a" ) ) ) ?,
@@ -212,6 +236,7 @@ impl TestContext {
212
236
pub fn build_tx_create_token_registry ( & mut self ) -> CreateTokenRegistryTxBuilder {
213
237
CreateTokenRegistryTxBuilder {
214
238
key : Some ( DEFAULT_KEY ) ,
239
+ chain : NEUTRON_CHAIN_NAME ,
215
240
owner : Some ( NEUTRON_CHAIN_ADMIN_ADDR . to_owned ( ) ) ,
216
241
test_ctx : self ,
217
242
}
@@ -221,11 +246,12 @@ impl TestContext {
221
246
fn tx_create_token_registry (
222
247
& mut self ,
223
248
key : & str ,
249
+ chain : & str ,
224
250
owner_addr : impl Into < String > ,
225
251
) -> Result < ( ) , Error > {
226
252
let mut contract_a = self
227
253
. get_contract ( )
228
- . src ( NEUTRON_CHAIN_NAME )
254
+ . src ( chain )
229
255
. contract ( TOKEN_REGISTRY_NAME )
230
256
. get_cw ( ) ;
231
257
@@ -241,7 +267,7 @@ impl TestContext {
241
267
) ?;
242
268
let addr = contract. address ;
243
269
244
- let neutron = self . get_mut_chain ( NEUTRON_CHAIN_NAME ) ;
270
+ let neutron = self . get_mut_chain ( chain ) ;
245
271
246
272
neutron
247
273
. contract_addrs
@@ -254,6 +280,7 @@ impl TestContext {
254
280
pub fn build_tx_create_factory ( & mut self ) -> CreateFactoryTxBuilder {
255
281
CreateFactoryTxBuilder {
256
282
key : DEFAULT_KEY ,
283
+ chain : NEUTRON_CHAIN_NAME ,
257
284
owner : NEUTRON_CHAIN_ADMIN_ADDR . to_owned ( ) ,
258
285
test_ctx : self ,
259
286
}
@@ -263,48 +290,45 @@ impl TestContext {
263
290
fn tx_create_factory (
264
291
& mut self ,
265
292
key : & str ,
293
+ chain : & str ,
266
294
factory_owner : impl Into < String > ,
267
295
) -> Result < ( ) , Error > {
268
- let chain = self . get_chain ( chain_name ) ;
296
+ let local_chain = self . get_chain ( chain ) ;
269
297
270
298
let pair_xyk_code_id =
271
- neutron
299
+ local_chain
272
300
. contract_codes
273
301
. get ( PAIR_NAME )
274
302
. ok_or ( Error :: MissingContextVariable ( String :: from (
275
303
"contract_codes::astroport_pair" ,
276
304
) ) ) ?;
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
+ ) ?;
284
308
let token_code_id =
285
- neutron
309
+ local_chain
286
310
. contract_codes
287
311
. get ( TOKEN_NAME )
288
312
. ok_or ( Error :: MissingContextVariable ( String :: from (
289
313
"contract_codes::cw20_base" ,
290
314
) ) ) ?;
291
315
let whitelist_code_id =
292
- neutron
316
+ local_chain
293
317
. contract_codes
294
318
. get ( WHITELIST_NAME )
295
319
. ok_or ( Error :: MissingContextVariable ( String :: from (
296
320
"contract_codes::astroport_whitelist" ,
297
321
) ) ) ?;
298
322
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 (
300
324
Error :: MissingContextVariable ( String :: from (
301
325
"contract_ddrs::astroport_native_coin_registry" ,
302
326
) ) ,
303
327
) ?;
304
328
305
329
let mut contract_a = self
306
330
. get_contract ( )
307
- . src ( NEUTRON_CHAIN_NAME )
331
+ . src ( chain )
308
332
. contract ( FACTORY_NAME )
309
333
. get_cw ( ) ;
310
334
@@ -345,9 +369,9 @@ impl TestContext {
345
369
"" ,
346
370
) ?;
347
371
348
- let neutron = self . get_mut_chain ( NEUTRON_CHAIN_NAME ) ;
372
+ let local_chain = self . get_mut_chain ( chain ) ;
349
373
350
- neutron
374
+ local_chain
351
375
. contract_addrs
352
376
. insert ( FACTORY_NAME . to_owned ( ) , contract. address ) ;
353
377
@@ -358,6 +382,7 @@ impl TestContext {
358
382
pub fn build_tx_create_pool ( & mut self ) -> CreatePoolTxBuilder {
359
383
CreatePoolTxBuilder {
360
384
key : DEFAULT_KEY ,
385
+ chain : NEUTRON_CHAIN_NAME ,
361
386
pair_type : PairType :: Xyk { } ,
362
387
denom_a : Default :: default ( ) ,
363
388
denom_b : Default :: default ( ) ,
@@ -369,12 +394,13 @@ impl TestContext {
369
394
fn tx_create_pool (
370
395
& self ,
371
396
key : & str ,
397
+ chain : & str ,
372
398
pair_type : PairType ,
373
399
denom_a : impl Into < String > ,
374
400
denom_b : impl Into < String > ,
375
401
) -> Result < ( ) , Error > {
376
402
// 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 ( ) ;
378
404
379
405
// Create the pair
380
406
let tx = contract_a. execute (
@@ -400,7 +426,7 @@ impl TestContext {
400
426
"transaction did not produce a tx hash" ,
401
427
) ) ) ?;
402
428
403
- self . guard_tx_errors ( NEUTRON_CHAIN_NAME , tx_hash. as_str ( ) ) ?;
429
+ self . guard_tx_errors ( chain , tx_hash. as_str ( ) ) ?;
404
430
405
431
Ok ( ( ) )
406
432
}
@@ -409,6 +435,7 @@ impl TestContext {
409
435
pub fn build_tx_fund_pool ( & mut self ) -> FundPoolTxBuilder {
410
436
FundPoolTxBuilder {
411
437
key : DEFAULT_KEY ,
438
+ chain : NEUTRON_CHAIN_NAME ,
412
439
denom_a : Default :: default ( ) ,
413
440
denom_b : Default :: default ( ) ,
414
441
amt_denom_a : Default :: default ( ) ,
@@ -424,6 +451,7 @@ impl TestContext {
424
451
fn tx_fund_pool (
425
452
& mut self ,
426
453
key : & str ,
454
+ chain : & str ,
427
455
denom_a : String ,
428
456
denom_b : String ,
429
457
amt_denom_a : u128 ,
@@ -434,7 +462,7 @@ impl TestContext {
434
462
// Get the instance from the address
435
463
let pool = self
436
464
. get_astro_pool ( )
437
- . src ( NEUTRON_CHAIN_NAME )
465
+ . src ( chain )
438
466
. denoms ( denom_a. clone ( ) , denom_b. clone ( ) )
439
467
. get_cw ( ) ;
440
468
@@ -468,7 +496,7 @@ impl TestContext {
468
496
. tx_hash
469
497
. ok_or ( Error :: TxMissingLogs ) ?;
470
498
471
- self . guard_tx_errors ( NEUTRON_CHAIN_NAME , tx. as_str ( ) ) ?;
499
+ self . guard_tx_errors ( chain , tx. as_str ( ) ) ?;
472
500
473
501
Ok ( ( ) )
474
502
}
0 commit comments