Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Nov 25, 2021
1 parent 88eeed0 commit 12ab3d6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
16 changes: 12 additions & 4 deletions base_layer/core/src/chain_storage/tests/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ fn add_many_chained_blocks(
size: usize,
db: &BlockchainDatabase<TempDatabase>,
) -> (Vec<Arc<Block>>, Vec<UnblindedOutput>) {
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 {
Expand Down Expand Up @@ -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 { .. });
}
Expand Down
4 changes: 2 additions & 2 deletions base_layer/core/src/transactions/transaction_entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -196,7 +196,7 @@ mod test {
)
.unwrap(),
);
assert!(!tx_output3.verify_range_proof(&factories.range_proof).unwrap());
tx_output3.verify_range_proof(&factories.range_proof).unwrap();
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,14 @@ impl TransactionOutput {
}

/// Verify that range proof is valid
pub fn verify_range_proof(&self, prover: &RangeProofService) -> Result<bool, TransactionError> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
))
),
}
}
Expand Down

0 comments on commit 12ab3d6

Please sign in to comment.