@@ -400,40 +400,47 @@ TEST(btc_txn_helper_test, btc_txn_helper_verify_input_p2wpkh_fail) {
400
400
TEST_ASSERT_EQUAL_INT (2 , status );
401
401
}
402
402
403
-
404
403
TEST (btc_txn_helper_test , btc_txn_helper_verify_input_p2wpkh_in_p2sh ) {
405
404
/* Test data source: Bip143
406
405
* https://blockstream.info/testnet/tx/b095225e60df2896a4e03fcc4fb2ba9622ee513f34b3e8de45c25a4793a244a2?expand
407
406
*/
408
407
int status = 2 ;
409
408
uint8_t raw_txn [2000 ] = {0 };
410
409
hex_string_to_byte_array (
411
- "0200000000010258afb1ece76f01c24f4935f453d210518163cb1d0383eaec331b202ebeb5e389"
412
- "0000000017160014a76cad25cb569bb47305513ebedd6011dc419deeffffffff2b3682b3592588"
413
- "5001f0e321df28d4ac675a9cbbccef2a69533bea7c5e5ad2c40000000017160014a76cad25cb56"
414
- "9bb47305513ebedd6011dc419deeffffffff02941100000000000017a914bd7aabdeeef211b1bd"
415
- "ad7218e14fea6c032101c087f22f00000000000017a914eaf97514c5ac1e41e413502e97ae42eb"
416
- "f27ace3a870247304402206e038f4712541d699697ed55efc41219df4f244fc72caa5edd653837"
417
- "f6555f6f02201cd8ea15b65fda17992abafaed86e066c3271ac16b9c46c54c2192438843dd0401"
418
- "21029f75e1ef6b04e004a308b1f59215a8a3a5b7958bbcf184cc24ba7ab6574448780248304502"
419
- "2100d15ce61648edc28b8b5a3531b80a1e8fc3b3eebe7d3fc4ca962cb04afc770dda02207c7eaf8"
420
- "82d7fac45d2752f20e48d2f896715cbc5a3b0f5de3e19fea0da99beac0121029f75e1ef6b04e004"
410
+ "0200000000010258afb1ece76f01c24f4935f453d210518163cb1d0383eaec331b202ebe"
411
+ "b5e389"
412
+ "0000000017160014a76cad25cb569bb47305513ebedd6011dc419deeffffffff2b3682b3"
413
+ "592588"
414
+ "5001f0e321df28d4ac675a9cbbccef2a69533bea7c5e5ad2c40000000017160014a76cad"
415
+ "25cb56"
416
+ "9bb47305513ebedd6011dc419deeffffffff02941100000000000017a914bd7aabdeeef2"
417
+ "11b1bd"
418
+ "ad7218e14fea6c032101c087f22f00000000000017a914eaf97514c5ac1e41e413502e97"
419
+ "ae42eb"
420
+ "f27ace3a870247304402206e038f4712541d699697ed55efc41219df4f244fc72caa5edd"
421
+ "653837"
422
+ "f6555f6f02201cd8ea15b65fda17992abafaed86e066c3271ac16b9c46c54c2192438843"
423
+ "dd0401"
424
+ "21029f75e1ef6b04e004a308b1f59215a8a3a5b7958bbcf184cc24ba7ab6574448780248"
425
+ "304502"
426
+ "2100d15ce61648edc28b8b5a3531b80a1e8fc3b3eebe7d3fc4ca962cb04afc770dda0220"
427
+ "7c7eaf8"
428
+ "82d7fac45d2752f20e48d2f896715cbc5a3b0f5de3e19fea0da99beac0121029f75e1ef6"
429
+ "b04e004"
421
430
"a308b1f59215a8a3a5b7958bbcf184cc24ba7ab65744487800000000" ,
422
431
838 ,
423
432
raw_txn );
424
433
// only fill necessary values
425
- btc_txn_input_t input [] = {
426
- {
427
- .value = 4500 ,
428
- .prev_output_index = 0x00000000 ,
429
- .script_pub_key = {.size = 23 },
430
- },
431
- {
432
- .value = 12274 ,
433
- .prev_output_index = 0x00000001 ,
434
- .script_pub_key = {.size = 23 },
435
- }
436
- };
434
+ btc_txn_input_t input [] = {{
435
+ .value = 4500 ,
436
+ .prev_output_index = 0x00000000 ,
437
+ .script_pub_key = {.size = 23 },
438
+ },
439
+ {
440
+ .value = 12274 ,
441
+ .prev_output_index = 0x00000001 ,
442
+ .script_pub_key = {.size = 23 },
443
+ }};
437
444
438
445
hex_string_to_byte_array (
439
446
"b095225e60df2896a4e03fcc4fb2ba9622ee513f34b3e8de45c25a4793a244a2" ,
@@ -460,7 +467,7 @@ TEST(btc_txn_helper_test, btc_txn_helper_verify_input_p2wpkh_in_p2sh) {
460
467
461
468
status = btc_verify_input_test (input , raw_txn , 419 );
462
469
TEST_ASSERT_EQUAL_INT (0 , status );
463
- status = btc_verify_input_test (input + 1 , raw_txn , 419 );
470
+ status = btc_verify_input_test (input + 1 , raw_txn , 419 );
464
471
TEST_ASSERT_EQUAL_INT (0 , status );
465
472
}
466
473
@@ -471,32 +478,40 @@ TEST(btc_txn_helper_test, btc_txn_helper_verify_input_p2wpkh_in_p2sh_fail) {
471
478
int status = 2 ;
472
479
uint8_t raw_txn [2000 ] = {0 };
473
480
hex_string_to_byte_array (
474
- "0200000000010258afb1ece76f01c24f4935f453d210518163cb1d0383eaec331b202ebeb5e389"
475
- "0000000017160014a76cad25cb569bb47305513ebedd6011dc419deeffffffff2b3682b3592588"
476
- "5001f0e321df28d4ac675a9cbbccef2a69533bea7c5e5ad2c40000000017160014a76cad25cb56"
477
- "9bb47305513ebedd6011dc419deeffffffff02941100000000000017a914bd7aabdeeef211b1bd"
478
- "ad7218e14fea6c032101c087f22f00000000000017a914eaf97514c5ac1e41e413502e97ae42eb"
479
- "f27ace3a870247304402206e038f4712541d699697ed55efc41219df4f244fc72caa5edd653837"
480
- "f6555f6f02201cd8ea15b65fda17992abafaed86e066c3271ac16b9c46c54c2192438843dd0401"
481
- "21029f75e1ef6b04e004a308b1f59215a8a3a5b7958bbcf184cc24ba7ab6574448780248304502"
482
- "2100d15ce61648edc28b8b5a3531b80a1e8fc3b3eebe7d3fc4ca962cb04afc770dda02207c7eaf8"
483
- "82d7fac45d2752f20e48d2f896715cbc5a3b0f5de3e19fea0da99beac0121029f75e1ef6b04e004"
481
+ "0200000000010258afb1ece76f01c24f4935f453d210518163cb1d0383eaec331b202ebe"
482
+ "b5e389"
483
+ "0000000017160014a76cad25cb569bb47305513ebedd6011dc419deeffffffff2b3682b3"
484
+ "592588"
485
+ "5001f0e321df28d4ac675a9cbbccef2a69533bea7c5e5ad2c40000000017160014a76cad"
486
+ "25cb56"
487
+ "9bb47305513ebedd6011dc419deeffffffff02941100000000000017a914bd7aabdeeef2"
488
+ "11b1bd"
489
+ "ad7218e14fea6c032101c087f22f00000000000017a914eaf97514c5ac1e41e413502e97"
490
+ "ae42eb"
491
+ "f27ace3a870247304402206e038f4712541d699697ed55efc41219df4f244fc72caa5edd"
492
+ "653837"
493
+ "f6555f6f02201cd8ea15b65fda17992abafaed86e066c3271ac16b9c46c54c2192438843"
494
+ "dd0401"
495
+ "21029f75e1ef6b04e004a308b1f59215a8a3a5b7958bbcf184cc24ba7ab6574448780248"
496
+ "304502"
497
+ "2100d15ce61648edc28b8b5a3531b80a1e8fc3b3eebe7d3fc4ca962cb04afc770dda0220"
498
+ "7c7eaf8"
499
+ "82d7fac45d2752f20e48d2f896715cbc5a3b0f5de3e19fea0da99beac0121029f75e1ef6"
500
+ "b04e004"
484
501
"a308b1f59215a8a3a5b7958bbcf184cc24ba7ab65744487800000000" ,
485
502
838 ,
486
503
raw_txn );
487
504
// only fill necessary values
488
- btc_txn_input_t input [] = {
489
- {
490
- .value = 4500 ,
491
- .prev_output_index = 0x00000000 ,
492
- .script_pub_key = {.size = 23 },
493
- },
494
- {
495
- .value = 12274 ,
496
- .prev_output_index = 0x00000001 ,
497
- .script_pub_key = {.size = 23 },
498
- }
499
- };
505
+ btc_txn_input_t input [] = {{
506
+ .value = 4500 ,
507
+ .prev_output_index = 0x00000000 ,
508
+ .script_pub_key = {.size = 23 },
509
+ },
510
+ {
511
+ .value = 12274 ,
512
+ .prev_output_index = 0x00000001 ,
513
+ .script_pub_key = {.size = 23 },
514
+ }};
500
515
501
516
hex_string_to_byte_array (
502
517
// invalid txn hash test. valid txn hash/id:
@@ -527,7 +542,7 @@ TEST(btc_txn_helper_test, btc_txn_helper_verify_input_p2wpkh_in_p2sh_fail) {
527
542
528
543
status = btc_verify_input_test (input , raw_txn , 419 );
529
544
TEST_ASSERT_EQUAL_INT (2 , status );
530
- status = btc_verify_input_test (input + 1 , raw_txn , 419 );
545
+ status = btc_verify_input_test (input + 1 , raw_txn , 419 );
531
546
TEST_ASSERT_EQUAL_INT (2 , status );
532
547
}
533
548
@@ -943,7 +958,6 @@ TEST(btc_txn_helper_test, btc_txn_helper_p2wpkh_digest_1_2) {
943
958
TEST (btc_txn_helper_test , btc_txn_helper_p2wpkh_digest_2_2 ) {
944
959
}
945
960
946
-
947
961
TEST (btc_txn_helper_test , btc_txn_helper_p2wpkh_in_p2sh_digest_1_2 ) {
948
962
uint8_t calculated_digest [32 ] = {0 };
949
963
uint8_t expected_digest [32 ] = {0 };
@@ -1019,10 +1033,13 @@ TEST(btc_txn_helper_test, btc_txn_helper_p2wpkh_in_p2sh_digest_1_2) {
1019
1033
expected_digest );
1020
1034
1021
1035
btc_segwit_init_cache (& context );
1022
- TEST_ASSERT_EQUAL_UINT8_ARRAY (expected_cache .hash_prevouts , context .segwit_cache .hash_prevouts , 32 );
1023
- TEST_ASSERT_EQUAL_UINT8_ARRAY (expected_cache .hash_sequence , context .segwit_cache .hash_sequence , 32 );
1024
- TEST_ASSERT_EQUAL_UINT8_ARRAY (expected_cache .hash_outputs , context .segwit_cache .hash_outputs , 32 );
1025
-
1036
+ TEST_ASSERT_EQUAL_UINT8_ARRAY (
1037
+ expected_cache .hash_prevouts , context .segwit_cache .hash_prevouts , 32 );
1038
+ TEST_ASSERT_EQUAL_UINT8_ARRAY (
1039
+ expected_cache .hash_sequence , context .segwit_cache .hash_sequence , 32 );
1040
+ TEST_ASSERT_EQUAL_UINT8_ARRAY (
1041
+ expected_cache .hash_outputs , context .segwit_cache .hash_outputs , 32 );
1042
+
1026
1043
btc_digest_input (& context , 0 , calculated_digest );
1027
1044
TEST_ASSERT_EQUAL_UINT8_ARRAY (expected_digest , calculated_digest , 32 );
1028
1045
}
@@ -1032,24 +1049,22 @@ TEST(btc_txn_helper_test, btc_txn_helper_p2wpkh_in_p2sh_digest_2_2) {
1032
1049
uint8_t calculated_digest [32 ] = {0 };
1033
1050
uint8_t expected_digest [2 ][32 ] = {0 };
1034
1051
btc_segwit_cache_t expected_cache = {.filled = true};
1035
- btc_txn_input_t input [] = {
1036
- {
1037
- .prev_txn_hash = {0 },
1038
- .value = 8650 ,
1039
- .prev_output_index = 0x00000000 ,
1040
- .script_pub_key = {.size = 22 },
1041
- .address_index = 0 ,
1042
- .sequence = 4294967295 ,
1043
- },
1044
- {
1045
- .prev_txn_hash = {0 },
1046
- .value = 18123 ,
1047
- .prev_output_index = 0x00000000 ,
1048
- .script_pub_key = {.size = 22 },
1049
- .address_index = 0 ,
1050
- .sequence = 4294967295 ,
1051
- }
1052
- };
1052
+ btc_txn_input_t input [] = {{
1053
+ .prev_txn_hash = {0 },
1054
+ .value = 8650 ,
1055
+ .prev_output_index = 0x00000000 ,
1056
+ .script_pub_key = {.size = 22 },
1057
+ .address_index = 0 ,
1058
+ .sequence = 4294967295 ,
1059
+ },
1060
+ {
1061
+ .prev_txn_hash = {0 },
1062
+ .value = 18123 ,
1063
+ .prev_output_index = 0x00000000 ,
1064
+ .script_pub_key = {.size = 22 },
1065
+ .address_index = 0 ,
1066
+ .sequence = 4294967295 ,
1067
+ }};
1053
1068
btc_sign_txn_output_t outputs [] = {
1054
1069
{
1055
1070
.value = 4500 ,
@@ -1114,15 +1129,14 @@ TEST(btc_txn_helper_test, btc_txn_helper_p2wpkh_in_p2sh_digest_2_2) {
1114
1129
64 ,
1115
1130
expected_cache .hash_outputs );
1116
1131
1117
-
1118
1132
btc_segwit_init_cache (& context );
1119
1133
TEST_ASSERT_EQUAL_UINT8_ARRAY (
1120
1134
expected_cache .hash_prevouts , context .segwit_cache .hash_prevouts , 32 );
1121
1135
TEST_ASSERT_EQUAL_UINT8_ARRAY (
1122
1136
expected_cache .hash_sequence , context .segwit_cache .hash_sequence , 32 );
1123
1137
TEST_ASSERT_EQUAL_UINT8_ARRAY (
1124
1138
expected_cache .hash_outputs , context .segwit_cache .hash_outputs , 32 );
1125
-
1139
+
1126
1140
/* digest input 0*/
1127
1141
hex_string_to_byte_array (
1128
1142
"84b6c444101a5d7d41c521b1034bf2c82afb19d45fe2a4fc6bdfae4edd720334" ,
@@ -1132,7 +1146,7 @@ TEST(btc_txn_helper_test, btc_txn_helper_p2wpkh_in_p2sh_digest_2_2) {
1132
1146
status = btc_digest_input (& context , 0 , calculated_digest );
1133
1147
TEST_ASSERT_TRUE (status );
1134
1148
TEST_ASSERT_EQUAL_UINT8_ARRAY (expected_digest [0 ], calculated_digest , 32 );
1135
-
1149
+
1136
1150
/* digest input 1*/
1137
1151
hex_string_to_byte_array (
1138
1152
"7503b14676ff1de1d85819f31e43b96a5f400c273e7f143d8b05aa32e261a2b1" ,
0 commit comments