@@ -443,6 +443,7 @@ pub fn mock_env() -> Env {
443443/// }
444444/// ```
445445pub struct Envs {
446+ chain_id : String ,
446447 contract_address : Addr ,
447448 /// The number of nanoseconds between two consecutive blocks
448449 block_time : u64 ,
@@ -451,17 +452,45 @@ pub struct Envs {
451452 envs_produced : u64 ,
452453}
453454
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+
454477impl 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 ) ;
459487 Envs {
488+ chain_id : options. chain_id ,
460489 // Default values here for compatibility with old `mock_env` function. They could be changed to anything else if there is a good reason.
461490 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 ,
465494 envs_produced : 0 ,
466495 }
467496 }
@@ -482,7 +511,7 @@ impl Envs {
482511 block : BlockInfo {
483512 height,
484513 time,
485- chain_id : "cosmos-testnet-14002" . to_string ( ) ,
514+ chain_id : self . chain_id . clone ( ) ,
486515 } ,
487516 transaction : Some ( TransactionInfo { index : 3 } ) ,
488517 contract : ContractInfo {
@@ -492,6 +521,12 @@ impl Envs {
492521 }
493522}
494523
524+ impl Default for Envs {
525+ fn default ( ) -> Self {
526+ Envs :: with_options ( EnvsOptions :: default ( ) )
527+ }
528+ }
529+
495530// The iterator implementation ends in case of overflows to avoid panics.
496531// Using this is recommended for very long running test suites.
497532impl Iterator for Envs {
0 commit comments