diff --git a/base_layer/core/src/chain_storage/tests/blockchain_database.rs b/base_layer/core/src/chain_storage/tests/blockchain_database.rs index bcaf0040dd..0d7365229d 100644 --- a/base_layer/core/src/chain_storage/tests/blockchain_database.rs +++ b/base_layer/core/src/chain_storage/tests/blockchain_database.rs @@ -67,7 +67,13 @@ fn add_many_chained_blocks( size: usize, db: &BlockchainDatabase, ) -> (Vec>, Vec) { - let mut prev_block = Arc::new(db.fetch_block(0).unwrap().try_into_block().unwrap()); + let last_header = db.fetch_last_header().unwrap(); + let mut prev_block = db + .fetch_block(last_header.height) + .unwrap() + .try_into_block() + .map(Arc::new) + .unwrap(); let mut blocks = Vec::with_capacity(size); let mut outputs = Vec::with_capacity(size); for _ in 1..=size as u64 { @@ -547,19 +553,21 @@ mod fetch_header_containing_kernel_mmr { let _ = add_many_chained_blocks(3, &db); let header = db.fetch_header_containing_kernel_mmr(num_genesis_kernels).unwrap(); + assert_eq!(header.height(), 0); + let header = db.fetch_header_containing_kernel_mmr(num_genesis_kernels + 1).unwrap(); assert_eq!(header.height(), 1); for i in 2..=3 { let header = db.fetch_header_containing_kernel_mmr(num_genesis_kernels + i).unwrap(); assert_eq!(header.height(), 2); } - for i in 4..=5 { + for i in 4..=6 { let header = db.fetch_header_containing_kernel_mmr(num_genesis_kernels + i).unwrap(); - assert_eq!(header.height(), i); + assert_eq!(header.height(), i - 1); } let err = db - .fetch_header_containing_kernel_mmr(num_genesis_kernels + 5 + 1) + .fetch_header_containing_kernel_mmr(num_genesis_kernels + 6 + 1) .unwrap_err(); matches!(err, ChainStorageError::ValueNotFound { .. }); } diff --git a/base_layer/core/src/transactions/transaction_entities/mod.rs b/base_layer/core/src/transactions/transaction_entities/mod.rs index 34a1d76771..d5f2201eaa 100644 --- a/base_layer/core/src/transactions/transaction_entities/mod.rs +++ b/base_layer/core/src/transactions/transaction_entities/mod.rs @@ -156,7 +156,7 @@ mod test { }); let script = unblinded_output1.script.clone(); let tx_output1 = unblinded_output1.as_transaction_output(&factories).unwrap(); - assert!(tx_output1.verify_range_proof(&factories.range_proof).unwrap()); + tx_output1.verify_range_proof(&factories.range_proof).unwrap(); let unblinded_output2 = test_params_2.create_unblinded_output(UtxoTestParams { value: (2u64.pow(32) + 1u64).into(), @@ -196,7 +196,7 @@ mod test { ) .unwrap(), ); - assert!(!tx_output3.verify_range_proof(&factories.range_proof).unwrap()); + assert!(tx_output3.verify_range_proof(&factories.range_proof).is_ok()); } #[test] diff --git a/base_layer/core/src/transactions/transaction_entities/transaction_output.rs b/base_layer/core/src/transactions/transaction_entities/transaction_output.rs index 204278b27a..a9f5a290eb 100644 --- a/base_layer/core/src/transactions/transaction_entities/transaction_output.rs +++ b/base_layer/core/src/transactions/transaction_entities/transaction_output.rs @@ -117,8 +117,14 @@ impl TransactionOutput { } /// Verify that range proof is valid - pub fn verify_range_proof(&self, prover: &RangeProofService) -> Result { - Ok(prover.verify(&self.proof.0, &self.commitment)) + pub fn verify_range_proof(&self, prover: &RangeProofService) -> Result<(), TransactionError> { + if prover.verify(&self.proof.0, &self.commitment) { + Ok(()) + } else { + Err(TransactionError::ValidationError( + "Recipient output range proof failed to verify".to_string(), + )) + } } /// Verify that the metadata signature is valid diff --git a/base_layer/core/src/transactions/transaction_protocol/sender.rs b/base_layer/core/src/transactions/transaction_protocol/sender.rs index cf6c4eb388..3961ba05cc 100644 --- a/base_layer/core/src/transactions/transaction_protocol/sender.rs +++ b/base_layer/core/src/transactions/transaction_protocol/sender.rs @@ -752,7 +752,7 @@ mod test { crypto_factories::CryptoFactories, tari_amount::*, test_helpers::{create_test_input, create_unblinded_output, TestParams}, - transaction_entities::{KernelFeatures, OutputFeatures, TransactionOutput}, + transaction_entities::{KernelFeatures, OutputFeatures, TransactionError, TransactionOutput}, transaction_protocol::{ sender::SenderTransactionProtocol, single_receiver::SingleReceiverTransactionProtocol, @@ -1045,7 +1045,9 @@ mod test { Ok(_) => panic!("Range proof should have failed to verify"), Err(e) => assert_eq!( e, - TransactionProtocolError::ValidationError("Recipient output range proof failed to verify".into()) + TransactionProtocolError::TransactionBuildError(TransactionError::ValidationError( + "Recipient output range proof failed to verify".into() + )) ), } }