diff --git a/pallas-applying/tests/byron.rs b/pallas-applying/tests/byron.rs index 5c45cd21d..56ed33e0c 100644 --- a/pallas-applying/tests/byron.rs +++ b/pallas-applying/tests/byron.rs @@ -27,13 +27,11 @@ mod byron_tests { pallas_codec::minicbor::decode::(&tx_cbor[..]).unwrap() } - fn build_utxo<'a>(tx: &Tx) -> UTxOs<'a> { + // Careful: this function assumes tx has exactly one input. + fn mk_utxo_for_single_input_tx<'a>(tx: &Tx, address_payload: String, amount: u64) -> UTxOs<'a> { let mut tx_ins: Vec = tx.inputs.clone().to_vec(); assert_eq!(tx_ins.len(), 1, "Unexpected number of inputs."); let tx_in: TxIn = tx_ins.pop().unwrap(); - let address_payload = - "83581cff66e7549ee0706abe5ce63ba325f792f2c1145d918baf563db2b457a101581e581cca3e553c9c63\ - c5927480e7434620200eb3a162ef0b6cf6f671ba925100"; let input_tx_out_addr: Address = match hex::decode(address_payload) { Ok(addr_bytes) => Address { payload: TagWrap(ByteVec::from(addr_bytes)), @@ -43,18 +41,47 @@ mod byron_tests { }; let tx_out: TxOut = TxOut { address: input_tx_out_addr, - amount: 19999000000, + amount: amount, }; let mut utxos: UTxOs = new_utxos(); add_to_utxo(&mut utxos, tx_in, tx_out); utxos } + #[test] + fn successful_mainnet_tx_with_genesis_utxos() { + let cbor_bytes: Vec = cbor_to_bytes(include_str!("../../test_data/byron2.tx")); + let mtxp: MintedTxPayload = mainnet_tx_from_bytes_cbor(&cbor_bytes); + let utxos: UTxOs = mk_utxo_for_single_input_tx( + &mtxp.transaction, + String::from(include_str!("../../test_data/byron2.address")), + // The number of lovelace in this input is irrelevant, since no fees have to be paid for + // this transaction. + 1, + ); + let env: Environment = Environment { + prot_params: MultiEraProtParams::Byron(ByronProtParams { + min_fees_const: 155381, + min_fees_factor: 44, + max_tx_size: 4096, + }), + prot_magic: 764824073, + }; + match mk_byron_tx_and_validate(&mtxp.transaction, &mtxp.witness, &utxos, &env) { + Ok(()) => (), + Err(err) => assert!(false, "Unexpected error ({:?}).", err), + } + } + #[test] fn successful_mainnet_tx() { let cbor_bytes: Vec = cbor_to_bytes(include_str!("../../test_data/byron1.tx")); let mtxp: MintedTxPayload = mainnet_tx_from_bytes_cbor(&cbor_bytes); - let utxos: UTxOs = build_utxo(&mtxp.transaction); + let utxos: UTxOs = mk_utxo_for_single_input_tx( + &mtxp.transaction, + String::from(include_str!("../../test_data/byron1.address")), + 19999000000, + ); let env: Environment = Environment { prot_params: MultiEraProtParams::Byron(ByronProtParams { min_fees_const: 155381, @@ -74,7 +101,11 @@ mod byron_tests { fn empty_ins() { let cbor_bytes: Vec = cbor_to_bytes(include_str!("../../test_data/byron1.tx")); let mut mtxp: MintedTxPayload = mainnet_tx_from_bytes_cbor(&cbor_bytes); - let utxos: UTxOs = build_utxo(&mtxp.transaction); + let utxos: UTxOs = mk_utxo_for_single_input_tx( + &mtxp.transaction, + String::from(include_str!("../../test_data/byron1.address")), + 19999000000, + ); // Clear the set of inputs in the transaction. let mut tx: Tx = (*mtxp.transaction).clone(); tx.inputs = MaybeIndefArray::Def(Vec::new()); @@ -106,7 +137,11 @@ mod byron_tests { fn empty_outs() { let cbor_bytes: Vec = cbor_to_bytes(include_str!("../../test_data/byron1.tx")); let mut mtxp: MintedTxPayload = mainnet_tx_from_bytes_cbor(&cbor_bytes); - let utxos: UTxOs = build_utxo(&mtxp.transaction); + let utxos: UTxOs = mk_utxo_for_single_input_tx( + &mtxp.transaction, + String::from(include_str!("../../test_data/byron1.address")), + 19999000000, + ); // Clear the set of outputs in the transaction. let mut tx: Tx = (*mtxp.transaction).clone(); tx.outputs = MaybeIndefArray::Def(Vec::new()); @@ -161,7 +196,11 @@ mod byron_tests { fn output_without_lovelace() { let cbor_bytes: Vec = cbor_to_bytes(include_str!("../../test_data/byron1.tx")); let mut mtxp: MintedTxPayload = mainnet_tx_from_bytes_cbor(&cbor_bytes); - let utxos: UTxOs = build_utxo(&mtxp.transaction); + let utxos: UTxOs = mk_utxo_for_single_input_tx( + &mtxp.transaction, + String::from(include_str!("../../test_data/byron1.address")), + 19999000000, + ); // Remove lovelace from output. let mut tx: Tx = (*mtxp.transaction).clone(); let altered_tx_out: TxOut = TxOut { @@ -200,7 +239,11 @@ mod byron_tests { fn not_enough_fees() { let cbor_bytes: Vec = cbor_to_bytes(include_str!("../../test_data/byron1.tx")); let mtxp: MintedTxPayload = mainnet_tx_from_bytes_cbor(&cbor_bytes); - let utxos: UTxOs = build_utxo(&mtxp.transaction); + let utxos: UTxOs = mk_utxo_for_single_input_tx( + &mtxp.transaction, + String::from(include_str!("../../test_data/byron1.address")), + 19999000000, + ); let env: Environment = Environment { prot_params: MultiEraProtParams::Byron(ByronProtParams { min_fees_const: 1000, @@ -223,7 +266,11 @@ mod byron_tests { fn tx_size_exceeds_max() { let cbor_bytes: Vec = cbor_to_bytes(include_str!("../../test_data/byron1.tx")); let mtxp: MintedTxPayload = mainnet_tx_from_bytes_cbor(&cbor_bytes); - let utxos: UTxOs = build_utxo(&mtxp.transaction); + let utxos: UTxOs = mk_utxo_for_single_input_tx( + &mtxp.transaction, + String::from(include_str!("../../test_data/byron1.address")), + 19999000000, + ); let env: Environment = Environment { prot_params: MultiEraProtParams::Byron(ByronProtParams { min_fees_const: 155381, @@ -246,7 +293,11 @@ mod byron_tests { fn missing_witness() { let cbor_bytes: Vec = cbor_to_bytes(include_str!("../../test_data/byron1.tx")); let mut mtxp: MintedTxPayload = mainnet_tx_from_bytes_cbor(&cbor_bytes); - let utxos: UTxOs = build_utxo(&mtxp.transaction); + let utxos: UTxOs = mk_utxo_for_single_input_tx( + &mtxp.transaction, + String::from(include_str!("../../test_data/byron1.address")), + 19999000000, + ); // Remove witness let new_witnesses: Witnesses = MaybeIndefArray::Def(Vec::new()); let mut tx_buf: Vec = Vec::new(); @@ -277,7 +328,11 @@ mod byron_tests { fn wrong_signature() { let cbor_bytes: Vec = cbor_to_bytes(include_str!("../../test_data/byron1.tx")); let mut mtxp: MintedTxPayload = mainnet_tx_from_bytes_cbor(&cbor_bytes); - let utxos: UTxOs = build_utxo(&mtxp.transaction); + let utxos: UTxOs = mk_utxo_for_single_input_tx( + &mtxp.transaction, + String::from(include_str!("../../test_data/byron1.address")), + 19999000000, + ); // Modify signature in witness let new_wit: Twit = match mtxp.witness[0].clone() { Twit::PkWitness(CborWrap((pk, _))) => { diff --git a/test_data/byron1.address b/test_data/byron1.address new file mode 100644 index 000000000..7a6730ac5 --- /dev/null +++ b/test_data/byron1.address @@ -0,0 +1 @@ +83581cff66e7549ee0706abe5ce63ba325f792f2c1145d918baf563db2b457a101581e581cca3e553c9c63c5927480e7434620200eb3a162ef0b6cf6f671ba925100 \ No newline at end of file diff --git a/test_data/byron2.address b/test_data/byron2.address new file mode 100644 index 000000000..20297e85d --- /dev/null +++ b/test_data/byron2.address @@ -0,0 +1 @@ +83581CDC7E4DD6A44886816DEC9A4B2021056A8FCAF500C09E316028F2985FA002 \ No newline at end of file diff --git a/test_data/byron2.tx b/test_data/byron2.tx new file mode 100644 index 000000000..a49e9d3f9 --- /dev/null +++ b/test_data/byron2.tx @@ -0,0 +1 @@ +82839f8200d818582482582031eae73dd9b018a6bc2eb1b229b5497de563a81872d54516251cc8185f93288300ff9f8282d818584283581c29bb9c5f4e8d38a10117e700a9238238d6f528df04b998af83ecc424a101581e581cc9deb2c011989356a5dc96450244e7ed22bfb30fbfc3f5807237fc39001a97bf58b71a000f4240ffa0818202d81858658258204d99cc5ec6c1891a483157560771a114463d92a530df8fd64e03f68f571de9b75840f67993afa4ec3b897355593e77baaf754ecfba2bba96265b829d79e4f452c7d6a6f363d41dea6731bff7a14efcc900e08f94e92c326344e540064ddf99052806 \ No newline at end of file