Skip to content

Commit

Permalink
resolved test 4 fails
Browse files Browse the repository at this point in the history
  • Loading branch information
varun-doshi committed Nov 25, 2024
1 parent 0416fe0 commit b422584
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 2 additions & 3 deletions packages/tests/src/tests/test_p2sh.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ fn test_p2sh_transaction_3() {
assert!(res.is_ok(), "P2SH failed!:{:?}", res.unwrap_err());
}

// TODO: Fix this test
#[ignore]

#[test]
fn test_p2sh_transaction_4() {
//https://learnmeabitcoin.com/explorer/tx/cc11ca9e9dc188663c41eb23b15370f68eded56b7ec54dd5bc4f2d2ae93addb2
Expand All @@ -84,7 +83,7 @@ fn test_p2sh_transaction_4() {

let utxo_hints = array![prev_out];

let res = validate_p2sh(@transaction, 0, utxo_hints, 0);
let res = validate_p2sh(@transaction, 1, utxo_hints, 0);
assert!(res.is_ok(), "P2SH failed!:{:?}", res.unwrap_err());
}

Expand Down
15 changes: 11 additions & 4 deletions packages/tests/src/validate.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,21 @@ pub fn validate_p2sh(
let mut redeem_script_size = 0;
if scriptSig_bytes[0] == 0 || scriptSig_bytes[0] == 1 || scriptSig_bytes[0] == 2 {
//OP_0 OP_PushData <Sig> OP_PushData <RedeemScript> Standard locking scripts
redeem_Script_start_index = (2 + scriptSig_bytes[1] + 1).into();
if(flags==0){
redeem_Script_start_index = (2 + scriptSig_bytes[1] + 1).into();
}else if(flags==1){

redeem_Script_start_index = (1+1 + scriptSig_bytes[1] + 1+
scriptSig_bytes[(1+1 + scriptSig_bytes[1]).into()]+
scriptSig_bytes[(1+1 + scriptSig_bytes[1]+scriptSig_bytes[(1+1 + scriptSig_bytes[1]).into()]).into()]+1).into();
}
redeem_script_size = (scriptSig_bytes.len()) - redeem_Script_start_index;
} else {
// non-standard locking script containing a mathematical puzzle
redeem_Script_start_index = find_last_index(scriptSig_bytes.clone());
redeem_script_size = (scriptSig_bytes.len()) - redeem_Script_start_index;
}

let redeem_script = sub_byte_array(
@scriptSig_bytes, ref redeem_Script_start_index, redeem_script_size
);
Expand All @@ -181,11 +188,11 @@ pub fn validate_p2sh(
if redeem_script.len() > 520 {
return Result::Err('P2SH: Redeem Script size > 520');
}

let hashed_redeem_script: ByteArray = ripemd160::ripemd160_hash(
@sha256_byte_array(@redeem_script)
)
.into();
.into();

let script_pubkey = utxo_hints[0].pubkey_script;
let mut script_hash_start_index = 2;
Expand Down

0 comments on commit b422584

Please sign in to comment.