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

Function test_genesis_block

bitvm/src/hash/sha256_u4_stack.rs:920–971  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

918
919 #[test]
920 fn test_genesis_block() {
921 // the genesis block header of bitcoin
922 // version previous-block merkle-root time bits nonce
923 // 01000000 0000000000000000000000000000000000000000000000000000000000000000 3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a 29ab5f49 ffff001d 1dac2b7c
924 let block_header = "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c";
925 let mut hasher = Sha256::new();
926 let data = Vec::<u8>::from_hex(block_header).unwrap();
927 hasher.update(&data);
928 let mut result = hasher.finalize();
929 hasher = Sha256::new();
930 hasher.update(result);
931 result = hasher.finalize();
932 let res = result.to_lower_hex_string();
933 let genesis_block_hash = "6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000";
934 assert_eq!(res.as_str(), genesis_block_hash);
935
936 let mut stack = StackTracker::new();
937 stack.custom(
938 script! { {u4_hex_to_nibbles(block_header)}},
939 0,
940 false,
941 0,
942 "message",
943 );
944 sha256_stack(&mut stack, block_header.len() as u32 / 2, true, true);
945 let shascript = sha256_stack(&mut stack, 32, true, true);
946
947 let script = script! {
948
949 { shascript }
950
951 { u4_hex_to_nibbles(res.as_str())}
952 for _ in 0..64 {
953 OP_TOALTSTACK
954 }
955
956 for i in 1..64 {
957 {i}
958 OP_ROLL
959 }
960
961 for _ in 0..64 {
962 OP_FROMALTSTACK
963 OP_EQUALVERIFY
964 }
965 OP_TRUE
966
967
968 };
969 let res = execute_script(StructuredScript::new("").push_script(script.compile()));
970 assert!(res.success);
971 }
972}

Callers

nothing calls this directly

Calls 4

sha256_stackFunction · 0.85
execute_scriptFunction · 0.85
lenMethod · 0.80
finalizeMethod · 0.45

Tested by

no test coverage detected