Skip to content

Commit

Permalink
chore: fix spend test (#5866)
Browse files Browse the repository at this point in the history
Description
---
Fixes spend test

Motivation and Context
---
double spend test should test for the correct error type

How Has This Been Tested?
---
unit tests

Fixes: #5815
  • Loading branch information
SWvheerden authored Oct 25, 2023
1 parent 3e1ec1f commit 8daa42c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion base_layer/core/src/validation/block_body/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ async fn it_checks_exactly_one_coinbase() {
}

#[tokio::test]
async fn it_checks_double_spends() {
async fn it_checks_duplicate_kernel() {
let (mut blockchain, validator) = setup(true);

let (_, coinbase_a) = blockchain.add_next_tip(block_spec!("A")).await.unwrap();
Expand All @@ -264,6 +264,36 @@ async fn it_checks_double_spends() {
assert!(matches!(err, ValidationError::DuplicateKernelError(_)));
}

#[tokio::test]
async fn it_checks_double_spends() {
let (mut blockchain, validator) = setup(true);

let (_, coinbase_a) = blockchain.add_next_tip(block_spec!("A")).await.unwrap();
let (txs, _) = schema_to_transaction(
&[txn_schema!(from: vec![coinbase_a.clone()], to: vec![50 * T])],
&blockchain.km,
)
.await;

blockchain
.add_next_tip(block_spec!("1", transactions: txs.iter().map(|t| (**t).clone()).collect()))
.await
.unwrap();
// lets create a new transction from the same input
let (txs2, _) =
schema_to_transaction(&[txn_schema!(from: vec![coinbase_a], to: vec![50 * T])], &blockchain.km).await;
let (block, _) = blockchain
.create_next_tip(
BlockSpec::new()
.with_transactions(txs2.iter().map(|t| (**t).clone()).collect())
.finish(),
)
.await;
let txn = blockchain.db().db_read_access().unwrap();
let err = validator.validate_body(&*txn, block.block()).unwrap_err();
assert!(matches!(err, ValidationError::ContainsSTxO));
}

#[tokio::test]
async fn it_checks_input_maturity() {
let (mut blockchain, validator) = setup(true);
Expand Down

0 comments on commit 8daa42c

Please sign in to comment.