@@ -441,6 +441,7 @@ pub fn mock_env() -> Env {
441
441
/// }
442
442
/// ```
443
443
pub struct Envs {
444
+ chain_id : String ,
444
445
contract_address : Addr ,
445
446
/// The number of nanoseconds between two consecutive blocks
446
447
block_time : u64 ,
@@ -449,17 +450,45 @@ pub struct Envs {
449
450
envs_produced : u64 ,
450
451
}
451
452
453
+ pub struct EnvsOptions {
454
+ bech32_prefix : & ' static str , /* static due to MockApi's Copy requirement. No better idea for now. */
455
+ block_time : u64 ,
456
+ // The height before the first `make` call
457
+ initial_height : u64 ,
458
+ // The block time before the first `make` call
459
+ initial_time : Timestamp ,
460
+ chain_id : String ,
461
+ }
462
+
463
+ impl Default for EnvsOptions {
464
+ fn default ( ) -> Self {
465
+ EnvsOptions {
466
+ bech32_prefix : BECH32_PREFIX ,
467
+ block_time : 5_000_000_000 , // 5s
468
+ initial_height : 12_344 ,
469
+ initial_time : Timestamp :: from_nanos ( 1_571_797_419_879_305_533 ) . minus_seconds ( 5 ) ,
470
+ chain_id : "cosmos-testnet-14002" . to_string ( ) ,
471
+ }
472
+ }
473
+ }
474
+
452
475
impl Envs {
453
- pub fn new (
454
- bech32_prefix : & ' static str , /* static due to MockApi's Copy requirement. No better idea for now. */
455
- ) -> Self {
456
- let api = MockApi :: default ( ) . with_prefix ( bech32_prefix) ;
476
+ pub fn new ( bech32_prefix : & ' static str ) -> Self {
477
+ Self :: with_options ( EnvsOptions {
478
+ bech32_prefix,
479
+ ..Default :: default ( )
480
+ } )
481
+ }
482
+
483
+ pub fn with_options ( options : EnvsOptions ) -> Self {
484
+ let api = MockApi :: default ( ) . with_prefix ( options. bech32_prefix ) ;
457
485
Envs {
486
+ chain_id : options. chain_id ,
458
487
// Default values here for compatibility with old `mock_env` function. They could be changed to anything else if there is a good reason.
459
488
contract_address : api. addr_make ( "cosmos2contract" ) ,
460
- block_time : 5_000_000_000 , // 5s
461
- last_height : 12_344 ,
462
- last_time : Timestamp :: from_nanos ( 1_571_797_419_879_305_533 ) . minus_seconds ( 5 ) ,
489
+ block_time : options . block_time ,
490
+ last_height : options . initial_height ,
491
+ last_time : options . initial_time ,
463
492
envs_produced : 0 ,
464
493
}
465
494
}
@@ -480,7 +509,7 @@ impl Envs {
480
509
block : BlockInfo {
481
510
height,
482
511
time,
483
- chain_id : "cosmos-testnet-14002" . to_string ( ) ,
512
+ chain_id : self . chain_id . clone ( ) ,
484
513
} ,
485
514
transaction : Some ( TransactionInfo { index : 3 } ) ,
486
515
contract : ContractInfo {
@@ -490,6 +519,12 @@ impl Envs {
490
519
}
491
520
}
492
521
522
+ impl Default for Envs {
523
+ fn default ( ) -> Self {
524
+ Envs :: with_options ( EnvsOptions :: default ( ) )
525
+ }
526
+ }
527
+
493
528
// The iterator implementation ends in case of overflows to avoid panics.
494
529
// Using this is recommended for very long running test suites.
495
530
impl Iterator for Envs {
0 commit comments