Skip to content

Commit

Permalink
Adding tests for is_pubscript_unspendable
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerson2102 committed Sep 20, 2024
1 parent 91c8918 commit 53f76be
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/consensus/src/validation/transaction.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mod tests {
use crate::types::transaction::{Transaction, TxIn, TxOut, OutPoint};
use crate::types::utxo_set::UtxoSet;
use utils::{hex::{from_hex, hex_to_hash_rev}, double_sha256::double_sha256_byte_array};
use super::validate_transaction;
use super::{validate_transaction, is_pubscript_unspendable, MAX_SCRIPT_SIZE};

// TODO: tests for coinbase maturity

Expand Down Expand Up @@ -630,4 +630,24 @@ mod tests {

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

#[test]
fn test_pubscript_starts_with_op_return() {
let op_return_script = from_hex("6a146f6e65207069656365206f6620646174612068657265");
assert!(is_pubscript_unspendable(@op_return_script));
}

#[test]
fn test_pubscript_within_size_limit() {
let normal_script = from_hex("76a91489abcdefabbaabbaabbaabbaabbaabbaabbaabba88ac");
assert!(!is_pubscript_unspendable(@normal_script));
}
#[test]
fn test_pubscript_exceeds_max_size() {
let mut large_script: ByteArray = Default::default();
for _ in 0..(MAX_SCRIPT_SIZE + 1) {
large_script.append_byte(0x00);
};
assert!(is_pubscript_unspendable(@large_script));
}
}

0 comments on commit 53f76be

Please sign in to comment.