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