Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix]: P2SH test #287

Merged
merged 11 commits into from
Dec 3, 2024
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
18 changes: 17 additions & 1 deletion packages/tests/src/validate.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,23 @@ 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
Expand Down