MCPcopy Create free account
hub / github.com/BitVM/BitVM / test_sha256

Function test_sha256

bitvm/src/hash/sha256_u4.rs:509–542  ·  view source on GitHub ↗
(hex_in: &str)

Source from the content-addressed store, hash-verified

507 }
508
509 fn test_sha256(hex_in: &str) {
510 let mut hasher = Sha256::new();
511 let data = Vec::<u8>::from_hex(hex_in).unwrap();
512 hasher.update(&data);
513 let result = hasher.finalize();
514 let res = result.to_lower_hex_string();
515 println!("Result: {}", res);
516
517 let script = script! {
518 { u4_hex_to_nibbles(hex_in) }
519 { sha256(hex_in.len() as u32 / 2)}
520
521
522 { u4_hex_to_nibbles(res.as_str()) }
523 for _ in 0..64 {
524 OP_TOALTSTACK
525 }
526
527 for i in 1..64 {
528 {i}
529 OP_ROLL
530 }
531
532 for _ in 0..64 {
533 OP_FROMALTSTACK
534 OP_EQUALVERIFY
535 }
536 OP_TRUE
537
538 };
539
540 let res = execute_script(script);
541 assert!(res.success);
542 }
543
544 #[test]
545 fn test_sha256_strs() {

Callers 2

test_sha256_strsFunction · 0.70
test_sha256_two_blocksFunction · 0.70

Calls 2

execute_scriptFunction · 0.85
finalizeMethod · 0.45

Tested by

no test coverage detected