Skip to content

Commit

Permalink
dev: Add tests for coinbase maturity (keep-starknet-strange#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoE11-y authored Sep 13, 2024
1 parent be2ea99 commit 6a18368
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions packages/consensus/src/validation/transaction.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,82 @@ mod tests {
let result = validate_transaction(@tx, 500001, 0);
assert!(result.is_ok());
}

#[test]
fn test_immature_coinbase_transaction() {
let block_height = 50;

let tx = Transaction {
version: 1,
is_segwit: false,
inputs: array![
TxIn {
script: @from_hex(""),
sequence: 0xfffffffe,
previous_output: OutPoint {
txid: hex_to_hash_rev(
"0000000000000000000000000000000000000000000000000000000000000000"
),
vout: 0,
data: TxOut { value: 100, ..Default::default() },
block_height: Default::default(),
block_time: Default::default(),
is_coinbase: true,
},
witness: array![].span(),
}
]
.span(),
outputs: array![
TxOut {
value: 50,
pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"),
cached: false,
}
]
.span(),
lock_time: 0
};

validate_transaction(@tx, block_height, 0).unwrap_err();
}

#[test]
fn test_mature_coinbase_transaction() {
let block_height = 150;

let tx = Transaction {
version: 1,
is_segwit: false,
inputs: array![
TxIn {
script: @from_hex(""),
sequence: 0xfffffffe,
previous_output: OutPoint {
txid: hex_to_hash_rev(
"0000000000000000000000000000000000000000000000000000000000000000"
),
vout: 0,
data: TxOut { value: 100, ..Default::default() },
block_height: Default::default(),
block_time: Default::default(),
is_coinbase: true,
},
witness: array![].span(),
}
]
.span(),
outputs: array![
TxOut {
value: 50,
pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"),
cached: false,
}
]
.span(),
lock_time: 0
};

validate_transaction(@tx, block_height, 0).unwrap();
}
}

0 comments on commit 6a18368

Please sign in to comment.