Skip to content

Commit

Permalink
[fix]: P2SH test (#287)
Browse files Browse the repository at this point in the history
<!-- enter the gh issue after hash -->

- [x] resolves
##243 (comment)
- [x] follows contribution
[guide](https://github.com/keep-starknet-strange/shinigami/blob/main/CONTRIBUTING.md)
- [x] code change includes tests

<!-- PR description below -->
Fixed failing P2SH test 4
  • Loading branch information
varun-doshi authored Dec 3, 2024
1 parent 1963116 commit 1d6d14a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 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
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

0 comments on commit 1d6d14a

Please sign in to comment.