diff --git a/pallas-applying/Cargo.toml b/pallas-applying/Cargo.toml index 2a6f90a7..315617e6 100644 --- a/pallas-applying/Cargo.toml +++ b/pallas-applying/Cargo.toml @@ -20,6 +20,7 @@ pallas-primitives = { version = "=0.31.0", path = "../pallas-primitives" } pallas-traverse = { version = "=0.31.0", path = "../pallas-traverse" } rand = "0.8" hex = "0.4" +chrono = "0.4.39" [dev-dependencies] hex = "0.4" diff --git a/pallas-applying/src/utils/environment.rs b/pallas-applying/src/utils/environment.rs index 369a24f9..498339b5 100644 --- a/pallas-applying/src/utils/environment.rs +++ b/pallas-applying/src/utils/environment.rs @@ -21,6 +21,28 @@ pub enum MultiEraProtocolParameters { } impl MultiEraProtocolParameters { + pub fn system_start(&self) -> chrono::DateTime { + match self { + MultiEraProtocolParameters::Byron(ByronProtParams { start_time, .. }) => { + chrono::DateTime::from_timestamp(*start_time as i64, 0) + .expect("valid timestamp") + .fixed_offset() + } + MultiEraProtocolParameters::Shelley(ShelleyProtParams { system_start, .. }) => { + *system_start + } + MultiEraProtocolParameters::Alonzo(AlonzoProtParams { system_start, .. }) => { + *system_start + } + MultiEraProtocolParameters::Babbage(BabbageProtParams { system_start, .. }) => { + *system_start + } + MultiEraProtocolParameters::Conway(ConwayProtParams { system_start, .. }) => { + *system_start + } + } + } + pub fn protocol_version(&self) -> usize { match self { MultiEraProtocolParameters::Byron(ByronProtParams { @@ -45,11 +67,56 @@ impl MultiEraProtocolParameters { }) => *x as usize, } } + + const FIVE_DAYS_IN_SECONDS: u64 = 5 * 24 * 60 * 60; + + pub fn epoch_length(&self) -> u64 { + match self { + MultiEraProtocolParameters::Byron(ByronProtParams { slot_duration, .. }) => { + // TODO: research if Byron epoch length is actually hardcoded or if you can get + // it from genesis files somehow + Self::FIVE_DAYS_IN_SECONDS / (*slot_duration / 1000) + } + MultiEraProtocolParameters::Shelley(ShelleyProtParams { epoch_length, .. }) => { + *epoch_length + } + MultiEraProtocolParameters::Alonzo(AlonzoProtParams { epoch_length, .. }) => { + *epoch_length + } + MultiEraProtocolParameters::Babbage(BabbageProtParams { epoch_length, .. }) => { + *epoch_length + } + MultiEraProtocolParameters::Conway(ConwayProtParams { epoch_length, .. }) => { + *epoch_length + } + } + } + + pub fn slot_length(&self) -> u64 { + match self { + MultiEraProtocolParameters::Byron(ByronProtParams { slot_duration, .. }) => { + *slot_duration / 1000 + } + MultiEraProtocolParameters::Shelley(ShelleyProtParams { slot_length, .. }) => { + *slot_length + } + MultiEraProtocolParameters::Alonzo(AlonzoProtParams { slot_length, .. }) => { + *slot_length + } + MultiEraProtocolParameters::Babbage(BabbageProtParams { slot_length, .. }) => { + *slot_length + } + MultiEraProtocolParameters::Conway(ConwayProtParams { slot_length, .. }) => { + *slot_length + } + } + } } #[derive(Debug, Clone)] pub struct ByronProtParams { pub block_version: (u16, u16, u8), + pub start_time: u64, pub script_version: u16, pub slot_duration: u64, pub max_block_size: u64, @@ -69,6 +136,9 @@ pub struct ByronProtParams { #[derive(Debug, Clone)] pub struct ShelleyProtParams { + pub system_start: chrono::DateTime, + pub epoch_length: u64, + pub slot_length: u64, pub minfee_a: u32, pub minfee_b: u32, pub max_block_body_size: u32, @@ -90,6 +160,9 @@ pub struct ShelleyProtParams { #[derive(Debug, Clone)] pub struct AlonzoProtParams { + pub system_start: chrono::DateTime, + pub epoch_length: u64, + pub slot_length: u64, pub minfee_a: u32, pub minfee_b: u32, pub max_block_body_size: u32, @@ -118,6 +191,9 @@ pub struct AlonzoProtParams { #[derive(Debug, Clone)] pub struct BabbageProtParams { + pub system_start: chrono::DateTime, + pub epoch_length: u64, + pub slot_length: u64, pub minfee_a: u32, pub minfee_b: u32, pub max_block_body_size: u32, @@ -146,6 +222,9 @@ pub struct BabbageProtParams { #[derive(Debug, Clone)] pub struct ConwayProtParams { + pub system_start: chrono::DateTime, + pub epoch_length: u64, + pub slot_length: u64, pub minfee_a: u32, pub minfee_b: u32, pub max_block_body_size: u32, diff --git a/pallas-applying/tests/alonzo.rs b/pallas-applying/tests/alonzo.rs index 59ad109e..f6bbf453 100644 --- a/pallas-applying/tests/alonzo.rs +++ b/pallas-applying/tests/alonzo.rs @@ -2558,6 +2558,9 @@ mod alonzo_tests { fn mk_params_epoch_334() -> AlonzoProtParams { AlonzoProtParams { + system_start: chrono::DateTime::parse_from_rfc3339("2017-09-23T21:44:51Z").unwrap(), + epoch_length: 432000, + slot_length: 1, minfee_a: 44, minfee_b: 155381, max_block_body_size: 65536, @@ -2633,6 +2636,9 @@ mod alonzo_tests { fn mk_params_epoch_300() -> AlonzoProtParams { AlonzoProtParams { + system_start: chrono::DateTime::parse_from_rfc3339("2017-09-23T21:44:51Z").unwrap(), + epoch_length: 432000, + slot_length: 1, minfee_a: 44, minfee_b: 155381, max_block_body_size: 81920, diff --git a/pallas-applying/tests/babbage.rs b/pallas-applying/tests/babbage.rs index 763642fc..11ae64c5 100644 --- a/pallas-applying/tests/babbage.rs +++ b/pallas-applying/tests/babbage.rs @@ -2369,6 +2369,9 @@ mod babbage_tests { fn mk_mainnet_params_epoch_365() -> BabbageProtParams { BabbageProtParams { + system_start: chrono::DateTime::parse_from_rfc3339("2017-09-23T21:44:51Z").unwrap(), + epoch_length: 432000, + slot_length: 1, minfee_a: 44, minfee_b: 155381, max_block_body_size: 90112, @@ -2445,6 +2448,9 @@ mod babbage_tests { fn mk_mainnet_params_epoch_380() -> BabbageProtParams { BabbageProtParams { + system_start: chrono::DateTime::parse_from_rfc3339("2022-10-25T00:00:00Z").unwrap(), + epoch_length: 432000, + slot_length: 1, minfee_a: 44, minfee_b: 155381, max_block_body_size: 90112, @@ -2697,6 +2703,9 @@ mod babbage_tests { fn mk_preview_params_epoch_30() -> BabbageProtParams { BabbageProtParams { + system_start: chrono::DateTime::parse_from_rfc3339("2022-10-25T00:00:00Z").unwrap(), + epoch_length: 432000, + slot_length: 1, minfee_a: 44, minfee_b: 155381, max_block_body_size: 90112, @@ -2787,6 +2796,9 @@ mod babbage_tests { fn mk_preprod_params_epoch_100() -> BabbageProtParams { BabbageProtParams { + system_start: chrono::DateTime::parse_from_rfc3339("2017-09-23T21:44:51Z").unwrap(), + epoch_length: 432000, + slot_length: 1, minfee_a: 44, minfee_b: 155381, max_block_body_size: 90112, diff --git a/pallas-applying/tests/byron.rs b/pallas-applying/tests/byron.rs index 63813b3d..2e6b81bb 100644 --- a/pallas-applying/tests/byron.rs +++ b/pallas-applying/tests/byron.rs @@ -24,6 +24,45 @@ use std::vec::Vec; mod byron_tests { use super::*; + macro_rules! hardcoded_environment_values { + ($($key:ident = $value:expr),*) => { + { + #[allow(unused_mut)] + let mut pparams = ByronProtParams { + block_version: (1, 0, 0), + start_time: 1506203091, + script_version: 0, + slot_duration: 20000, + max_block_size: 2000000, + max_header_size: 2000000, + max_tx_size: 4096, + max_proposal_size: 700, + mpc_thd: 20000000000000, + heavy_del_thd: 300000000000, + update_vote_thd: 1000000000000, + update_proposal_thd: 100000000000000, + update_implicit: 10000, + soft_fork_rule: (900000000000000, 600000000000000, 50000000000000), + summand: 155381, + multiplier: 44, + unlock_stake_epoch: 18446744073709551615, + }; + + $( + pparams.$key = $value; + )* + + Environment { + prot_params: MultiEraProtocolParameters::Byron(pparams), + prot_magic: 764824073, + block_slot: 6341, + network_id: 1, + acnt: None, + } + } + } + } + #[test] // Transaction hash: // a9e4413a5fb61a7a43c7df006ffcaaf3f2ffc9541f54757023968c5a8f8294fd @@ -38,30 +77,7 @@ mod byron_tests { 19999000000, )], ); - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { - block_version: (1, 0, 0), - script_version: 0, - slot_duration: 20000, - max_block_size: 2000000, - max_header_size: 2000000, - max_tx_size: 4096, - max_proposal_size: 700, - mpc_thd: 20000000000000, - heavy_del_thd: 300000000000, - update_vote_thd: 1000000000000, - update_proposal_thd: 100000000000000, - update_implicit: 10000, - soft_fork_rule: (900000000000000, 600000000000000, 50000000000000), - summand: 155381, - multiplier: 44, - unlock_stake_epoch: 18446744073709551615, - }), - prot_magic: 764824073, - block_slot: 6341, - network_id: 1, - acnt: None, - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => (), @@ -83,30 +99,7 @@ mod byron_tests { 19999000000, )], ); - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { - block_version: (1, 0, 0), - script_version: 0, - slot_duration: 20000, - max_block_size: 2000000, - max_header_size: 2000000, - max_tx_size: 4096, - max_proposal_size: 700, - mpc_thd: 20000000000000, - heavy_del_thd: 300000000000, - update_vote_thd: 1000000000000, - update_proposal_thd: 100000000000000, - update_implicit: 10000, - soft_fork_rule: (900000000000000, 600000000000000, 50000000000000), - summand: 155381, - multiplier: 44, - unlock_stake_epoch: 18446744073709551615, - }), - prot_magic: 764824073, - block_slot: 3241381, - network_id: 1, - acnt: None, - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => (), @@ -136,30 +129,7 @@ mod byron_tests { }; mtxp.transaction = Decode::decode(&mut Decoder::new(tx_buf.as_slice()), &mut ()).unwrap(); let metx: MultiEraTx = MultiEraTx::from_byron(&mtxp); - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { - block_version: (1, 0, 0), - script_version: 0, - slot_duration: 20000, - max_block_size: 2000000, - max_header_size: 2000000, - max_tx_size: 4096, - max_proposal_size: 700, - mpc_thd: 20000000000000, - heavy_del_thd: 300000000000, - update_vote_thd: 1000000000000, - update_proposal_thd: 100000000000000, - update_implicit: 10000, - soft_fork_rule: (900000000000000, 600000000000000, 50000000000000), - summand: 155381, - multiplier: 44, - unlock_stake_epoch: 18446744073709551615, - }), - prot_magic: 764824073, - block_slot: 3241381, - network_id: 1, - acnt: None, - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("Inputs set should not be empty"), @@ -192,30 +162,7 @@ mod byron_tests { 19999000000, )], ); - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { - block_version: (1, 0, 0), - script_version: 0, - slot_duration: 20000, - max_block_size: 2000000, - max_header_size: 2000000, - max_tx_size: 4096, - max_proposal_size: 700, - mpc_thd: 20000000000000, - heavy_del_thd: 300000000000, - update_vote_thd: 1000000000000, - update_proposal_thd: 100000000000000, - update_implicit: 10000, - soft_fork_rule: (900000000000000, 600000000000000, 50000000000000), - summand: 155381, - multiplier: 44, - unlock_stake_epoch: 18446744073709551615, - }), - prot_magic: 764824073, - block_slot: 3241381, - network_id: 1, - acnt: None, - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("Outputs set should not be empty"), @@ -233,30 +180,7 @@ mod byron_tests { let mtxp: MintedTxPayload = minted_tx_payload_from_cbor(&cbor_bytes); let metx: MultiEraTx = MultiEraTx::from_byron(&mtxp); let utxos: UTxOs = UTxOs::new(); - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { - block_version: (1, 0, 0), - script_version: 0, - slot_duration: 20000, - max_block_size: 2000000, - max_header_size: 2000000, - max_tx_size: 4096, - max_proposal_size: 700, - mpc_thd: 20000000000000, - heavy_del_thd: 300000000000, - update_vote_thd: 1000000000000, - update_proposal_thd: 100000000000000, - update_implicit: 10000, - soft_fork_rule: (900000000000000, 600000000000000, 50000000000000), - summand: 155381, - multiplier: 44, - unlock_stake_epoch: 18446744073709551615, - }), - prot_magic: 764824073, - block_slot: 3241381, - network_id: 1, - acnt: None, - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("All inputs must be within the UTxO set"), @@ -295,30 +219,7 @@ mod byron_tests { 19999000000, )], ); - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { - block_version: (1, 0, 0), - script_version: 0, - slot_duration: 20000, - max_block_size: 2000000, - max_header_size: 2000000, - max_tx_size: 4096, - max_proposal_size: 700, - mpc_thd: 20000000000000, - heavy_del_thd: 300000000000, - update_vote_thd: 1000000000000, - update_proposal_thd: 100000000000000, - update_implicit: 10000, - soft_fork_rule: (900000000000000, 600000000000000, 50000000000000), - summand: 155381, - multiplier: 44, - unlock_stake_epoch: 18446744073709551615, - }), - prot_magic: 764824073, - block_slot: 3241381, - network_id: 1, - acnt: None, - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("All outputs must contain lovelace"), @@ -342,30 +243,8 @@ mod byron_tests { 19999000000, )], ); - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { - block_version: (1, 0, 0), - script_version: 0, - slot_duration: 20000, - max_block_size: 2000000, - max_header_size: 2000000, - max_tx_size: 4096, - max_proposal_size: 700, - mpc_thd: 20000000000000, - heavy_del_thd: 300000000000, - update_vote_thd: 1000000000000, - update_proposal_thd: 100000000000000, - update_implicit: 10000, - soft_fork_rule: (900000000000000, 600000000000000, 50000000000000), - summand: 1000, - multiplier: 1000, - unlock_stake_epoch: 18446744073709551615, - }), - prot_magic: 764824073, - block_slot: 3241381, - network_id: 1, - acnt: None, - }; + + let env: Environment = hardcoded_environment_values!(summand = 1000, multiplier = 1000); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("Fees should not be below minimum"), @@ -389,30 +268,7 @@ mod byron_tests { 19999000000, )], ); - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { - block_version: (1, 0, 0), - script_version: 0, - slot_duration: 20000, - max_block_size: 2000000, - max_header_size: 2000000, - max_tx_size: 0, - max_proposal_size: 700, - mpc_thd: 20000000000000, - heavy_del_thd: 300000000000, - update_vote_thd: 1000000000000, - update_proposal_thd: 100000000000000, - update_implicit: 10000, - soft_fork_rule: (900000000000000, 600000000000000, 50000000000000), - summand: 155381, - multiplier: 44, - unlock_stake_epoch: 18446744073709551615, - }), - prot_magic: 764824073, - block_slot: 3241381, - network_id: 1, - acnt: None, - }; + let env: Environment = hardcoded_environment_values!(max_tx_size = 0); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("Transaction size cannot exceed protocol limit"), @@ -444,30 +300,7 @@ mod byron_tests { 19999000000, )], ); - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { - block_version: (1, 0, 0), - script_version: 0, - slot_duration: 20000, - max_block_size: 2000000, - max_header_size: 2000000, - max_tx_size: 4096, - max_proposal_size: 700, - mpc_thd: 20000000000000, - heavy_del_thd: 300000000000, - update_vote_thd: 1000000000000, - update_proposal_thd: 100000000000000, - update_implicit: 10000, - soft_fork_rule: (900000000000000, 600000000000000, 50000000000000), - summand: 155381, - multiplier: 44, - unlock_stake_epoch: 18446744073709551615, - }), - prot_magic: 764824073, - block_slot: 3241381, - network_id: 1, - acnt: None, - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("All inputs must have a witness signature"), @@ -508,30 +341,7 @@ mod byron_tests { 19999000000, )], ); - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { - block_version: (1, 0, 0), - script_version: 0, - slot_duration: 20000, - max_block_size: 2000000, - max_header_size: 2000000, - max_tx_size: 4096, - max_proposal_size: 700, - mpc_thd: 20000000000000, - heavy_del_thd: 300000000000, - update_vote_thd: 1000000000000, - update_proposal_thd: 100000000000000, - update_implicit: 10000, - soft_fork_rule: (900000000000000, 600000000000000, 50000000000000), - summand: 155381, - multiplier: 44, - unlock_stake_epoch: 18446744073709551615, - }), - prot_magic: 764824073, - block_slot: 3241381, - network_id: 1, - acnt: None, - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("Witness signature should verify the transaction"), diff --git a/pallas-applying/tests/shelley_ma.rs b/pallas-applying/tests/shelley_ma.rs index 7f43017a..123ccfcc 100644 --- a/pallas-applying/tests/shelley_ma.rs +++ b/pallas-applying/tests/shelley_ma.rs @@ -29,6 +29,69 @@ use std::str::FromStr; mod shelley_ma_tests { use super::*; + macro_rules! hardcoded_environment_values { + ($($key:ident = $value:expr),*) => { + { + #[allow(unused_mut)] + let mut pparams = ShelleyProtParams { + system_start: chrono::DateTime::parse_from_rfc3339("2017-09-23T21:44:51Z").unwrap(), + epoch_length: 432000, + slot_length: 1, + minfee_b: 155381, + minfee_a: 44, + max_block_body_size: 65536, + max_transaction_size: 4096, + max_block_header_size: 1100, + key_deposit: 2000000, + pool_deposit: 500000000, + maximum_epoch: 18, + desired_number_of_stake_pools: 150, + pool_pledge_influence: RationalNumber { + // FIX: this is a made-up value. + numerator: 1, + denominator: 1, + }, + expansion_rate: RationalNumber { + // FIX: this is a made-up value. + numerator: 1, + denominator: 1, + }, + treasury_growth_rate: RationalNumber { + // FIX: this is a made-up value. + numerator: 1, + denominator: 1, + }, + decentralization_constant: RationalNumber { + numerator: 1, + denominator: 1, + }, + extra_entropy: Nonce { + variant: NonceVariant::NeutralNonce, + hash: None, + }, + protocol_version: (0, 2), + min_utxo_value: 1000000, + min_pool_cost: 340000000, + }; + + $( + pparams.$key = $value; + )* + + Environment { + prot_params: MultiEraProtocolParameters::Shelley(pparams), + prot_magic: 764824073, + block_slot: 5281340, + network_id: 1, + acnt: Some(AccountState { + treasury: 261_254_564_000_000, + reserves: 0, + }), + } + } + } + } + #[test] // Transaction hash: // 50eba65e73c8c5f7b09f4ea28cf15dce169f3d1c322ca3deff03725f51518bb2 @@ -44,54 +107,8 @@ mod shelley_ma_tests { None, )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => (), @@ -115,54 +132,7 @@ mod shelley_ma_tests { )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 17584925, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => (), @@ -171,8 +141,8 @@ mod shelley_ma_tests { } #[test] - // Same as successful_mainnet_shelley_tx_with_script, but changing "All" to "any" and - // deleting one key-witness pair + // Same as successful_mainnet_shelley_tx_with_script, but changing "All" to + // "any" and deleting one key-witness pair fn successful_mainnet_shelley_tx_with_changed_script() { let cbor_bytes: Vec = cbor_to_bytes(include_str!("../../test_data/shelley4.tx")); let mut mtx: MintedTx = minted_tx_from_cbor(&cbor_bytes); @@ -196,54 +166,8 @@ mod shelley_ma_tests { None, )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 17584925, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => (), @@ -267,54 +191,7 @@ mod shelley_ma_tests { )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5860488, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => (), @@ -338,54 +215,7 @@ mod shelley_ma_tests { )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 24381863, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => (), @@ -409,51 +239,7 @@ mod shelley_ma_tests { )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 16384, - max_block_header_size: 1100, - key_deposit: 2_000_000, - pool_deposit: 500_000_000, - maximum_epoch: 18, - desired_number_of_stake_pools: 500, - pool_pledge_influence: RationalNumber { - numerator: 3, - denominator: 10, - }, - expansion_rate: RationalNumber { - numerator: 3, - denominator: 1000, - }, - treasury_growth_rate: RationalNumber { - numerator: 2, - denominator: 10, - }, - decentralization_constant: RationalNumber { - numerator: 0, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (4, 0), - min_utxo_value: 1_000_000, - min_pool_cost: 340_000_000, - }), - prot_magic: 764824073, - block_slot: 26342415, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); let hash = Hash::from_str("FB2B631DB76384F64DD94B47F97FC8C2A206764C17A1DE7DA2F70E83").unwrap(); @@ -551,6 +337,9 @@ mod shelley_ma_tests { Environment { prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { + system_start: chrono::DateTime::parse_from_rfc3339("2017-09-23T21:44:51Z").unwrap(), + epoch_length: 432000, + slot_length: 1, minfee_b: 155381, minfee_a: 44, max_block_body_size: 65536, @@ -608,51 +397,9 @@ mod shelley_ma_tests { )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; + let mut env: Environment = hardcoded_environment_values!(max_transaction_size = 16384); + env.block_slot = 19282133; - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 16384, - max_block_header_size: 1100, - key_deposit: 2_000_000, - pool_deposit: 500_000_000, - maximum_epoch: 18, - desired_number_of_stake_pools: 500, - pool_pledge_influence: RationalNumber { - numerator: 3, - denominator: 10, - }, - expansion_rate: RationalNumber { - numerator: 3, - denominator: 1000, - }, - treasury_growth_rate: RationalNumber { - numerator: 2, - denominator: 10, - }, - decentralization_constant: RationalNumber { - numerator: 3, - denominator: 10, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (3, 0), - min_utxo_value: 1_000_000, - min_pool_cost: 340_000_000, - }), - prot_magic: 764824073, - block_slot: 19282133, - network_id: 1, - acnt: Some(acnt), - }; let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => (), @@ -685,54 +432,7 @@ mod shelley_ma_tests { Decode::decode(&mut Decoder::new(tx_buf.as_slice()), &mut ()).unwrap(); let metx: MultiEraTx = MultiEraTx::from_alonzo_compatible(&mtx, Era::Shelley); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; + let env = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("Inputs set should not be empty"), @@ -751,54 +451,7 @@ mod shelley_ma_tests { let metx: MultiEraTx = MultiEraTx::from_alonzo_compatible(&mtx, Era::Shelley); let utxos: UTxOs = UTxOs::new(); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; + let env = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("All inputs must be within the UTxO set"), @@ -833,54 +486,7 @@ mod shelley_ma_tests { Decode::decode(&mut Decoder::new(tx_buf.as_slice()), &mut ()).unwrap(); let metx: MultiEraTx = MultiEraTx::from_alonzo_compatible(&mtx, Era::Shelley); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("TTL must always be present in Shelley transactions"), @@ -906,54 +512,9 @@ mod shelley_ma_tests { )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; + let mut env: Environment = hardcoded_environment_values!(); + env.block_slot = 9999999; - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 9999999, - network_id: 1, - acnt: Some(acnt), - }; let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("TTL cannot be exceeded"), @@ -979,54 +540,8 @@ mod shelley_ma_tests { )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; + let env: Environment = hardcoded_environment_values!(max_transaction_size = 0); - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 0, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("Tx size exceeds max limit"), @@ -1053,54 +568,7 @@ mod shelley_ma_tests { )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 10000000000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; + let env = hardcoded_environment_values!(min_utxo_value = 10000000000000); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("Output amount must be above min lovelace value"), @@ -1129,61 +597,14 @@ mod shelley_ma_tests { let metx: MultiEraTx = MultiEraTx::from_alonzo_compatible(&mtx, Era::Shelley); let utxos: UTxOs = mk_utxo_for_alonzo_compatible_tx( &mtx.transaction_body, - &[( - String::from("0129bb156d52d014bb444a14138cbee36044c6faed37d0c2d49d2358315c465cbf8c5536970e8a29bb7adcda0d663b20007d481813694c64ef"), - Value::Coin(2332267427205), - None, - )], - ); - - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; + &[( + String::from("0129bb156d52d014bb444a14138cbee36044c6faed37d0c2d49d2358315c465cbf8c5536970e8a29bb7adcda0d663b20007d481813694c64ef"), + Value::Coin(2332267427205), + None, + )], + ); + + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("Preservation of value property doesn't hold"), @@ -1209,54 +630,7 @@ mod shelley_ma_tests { )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 70, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(minfee_b = 155381, minfee_a = 70); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("Fee should not be below minimum"), @@ -1305,54 +679,7 @@ mod shelley_ma_tests { Decode::decode(&mut Decoder::new(tx_buf.as_slice()), &mut ()).unwrap(); let metx: MultiEraTx = MultiEraTx::from_alonzo_compatible(&mtx, Era::Shelley); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let utxos: UTxOs = mk_utxo_for_alonzo_compatible_tx( &mtx.transaction_body, &[( @@ -1389,54 +716,7 @@ mod shelley_ma_tests { )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5860488, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("Output with wrong network ID should be rejected"), @@ -1466,54 +746,7 @@ mod shelley_ma_tests { Decode::decode(&mut Decoder::new(tx_buf.as_slice()), &mut ()).unwrap(); let metx: MultiEraTx = MultiEraTx::from_alonzo_compatible(&mtx, Era::Shelley); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let utxos: UTxOs = mk_utxo_for_alonzo_compatible_tx( &mtx.transaction_body, &[( @@ -1556,54 +789,7 @@ mod shelley_ma_tests { Decode::decode(&mut Decoder::new(tx_buf.as_slice()), &mut ()).unwrap(); let metx: MultiEraTx = MultiEraTx::from_alonzo_compatible(&mtx, Era::Shelley); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let utxos: UTxOs = mk_utxo_for_alonzo_compatible_tx( &mtx.transaction_body, &[( @@ -1641,54 +827,7 @@ mod shelley_ma_tests { Decode::decode(&mut Decoder::new(tx_buf.as_slice()), &mut ()).unwrap(); let metx: MultiEraTx = MultiEraTx::from_alonzo_compatible(&mtx, Era::Shelley); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let utxos: UTxOs = mk_utxo_for_alonzo_compatible_tx( &mtx.transaction_body, &[( @@ -1728,54 +867,7 @@ mod shelley_ma_tests { Decode::decode(&mut Decoder::new(tx_buf.as_slice()), &mut ()).unwrap(); let metx: MultiEraTx = MultiEraTx::from_alonzo_compatible(&mtx, Era::Shelley); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 4096, - max_block_header_size: 1100, - key_deposit: 2000000, - pool_deposit: 500000000, - maximum_epoch: 18, - desired_number_of_stake_pools: 150, - pool_pledge_influence: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - expansion_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - treasury_growth_rate: RationalNumber { - // FIX: this is a made-up value. - numerator: 1, - denominator: 1, - }, - decentralization_constant: RationalNumber { - numerator: 1, - denominator: 1, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (0, 2), - min_utxo_value: 1000000, - min_pool_cost: 340000000, - }), - prot_magic: 764824073, - block_slot: 5281340, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(); let utxos: UTxOs = mk_utxo_for_alonzo_compatible_tx( &mtx.transaction_body, &[( @@ -1874,51 +966,7 @@ mod shelley_ma_tests { )], ); - let acnt = AccountState { - treasury: 261_254_564_000_000, - reserves: 0, - }; - - let env: Environment = Environment { - prot_params: MultiEraProtocolParameters::Shelley(ShelleyProtParams { - minfee_b: 155381, - minfee_a: 44, - max_block_body_size: 65536, - max_transaction_size: 16384, - max_block_header_size: 1100, - key_deposit: 2_000_000, - pool_deposit: 500_000_000, - maximum_epoch: 18, - desired_number_of_stake_pools: 500, - pool_pledge_influence: RationalNumber { - numerator: 3, - denominator: 10, - }, - expansion_rate: RationalNumber { - numerator: 3, - denominator: 1000, - }, - treasury_growth_rate: RationalNumber { - numerator: 2, - denominator: 10, - }, - decentralization_constant: RationalNumber { - numerator: 3, - denominator: 10, - }, - extra_entropy: Nonce { - variant: NonceVariant::NeutralNonce, - hash: None, - }, - protocol_version: (3, 0), - min_utxo_value: 1_000_000, - min_pool_cost: 340_000_000, - }), - prot_magic: 764824073, - block_slot: 19483200, - network_id: 1, - acnt: Some(acnt), - }; + let env: Environment = hardcoded_environment_values!(max_transaction_size = 16384); let mut cert_state: CertState = CertState::default(); match validate_txs(&[metx], &env, &utxos, &mut cert_state) { Ok(()) => panic!("MIR after the stability window"),