@@ -28,6 +28,7 @@ static void test_surjectionproof_api(void) {
28
28
unsigned char serialized_proof [SECP256K1_SURJECTIONPROOF_SERIALIZATION_BYTES_MAX ];
29
29
size_t serialized_len ;
30
30
secp256k1_surjectionproof proof ;
31
+ secp256k1_surjectionproof * proof_on_heap ;
31
32
size_t n_inputs = sizeof (fixed_input_tags ) / sizeof (fixed_input_tags [0 ]);
32
33
size_t input_index ;
33
34
int32_t ecount = 0 ;
@@ -52,6 +53,46 @@ static void test_surjectionproof_api(void) {
52
53
memcpy (& fixed_output_tag , & fixed_input_tags [0 ], sizeof (fixed_input_tags [0 ]));
53
54
CHECK (secp256k1_generator_generate_blinded (ctx , & ephemeral_output_tag , fixed_output_tag .data , output_blinding_key ));
54
55
56
+ /* check allocate_initialized */
57
+ CHECK (secp256k1_surjectionproof_allocate_initialized (none , & proof_on_heap , & input_index , fixed_input_tags , n_inputs , 0 , & fixed_input_tags [0 ], 100 , seed ) == 0 );
58
+ CHECK (proof_on_heap == 0 );
59
+ CHECK (ecount == 0 );
60
+ CHECK (secp256k1_surjectionproof_allocate_initialized (none , & proof_on_heap , & input_index , fixed_input_tags , n_inputs , 3 , & fixed_input_tags [0 ], 100 , seed ) != 0 );
61
+ CHECK (proof_on_heap != 0 );
62
+ secp256k1_surjectionproof_destroy (proof_on_heap );
63
+ CHECK (ecount == 0 );
64
+ CHECK (secp256k1_surjectionproof_allocate_initialized (none , NULL , & input_index , fixed_input_tags , n_inputs , 3 , & fixed_input_tags [0 ], 100 , seed ) == 0 );
65
+ CHECK (ecount == 1 );
66
+ CHECK (secp256k1_surjectionproof_allocate_initialized (none , & proof_on_heap , NULL , fixed_input_tags , n_inputs , 3 , & fixed_input_tags [0 ], 100 , seed ) == 0 );
67
+ CHECK (proof_on_heap == 0 );
68
+ CHECK (ecount == 2 );
69
+ CHECK (secp256k1_surjectionproof_allocate_initialized (none , & proof_on_heap , & input_index , NULL , n_inputs , 3 , & fixed_input_tags [0 ], 100 , seed ) == 0 );
70
+ CHECK (proof_on_heap == 0 );
71
+ CHECK (ecount == 3 );
72
+ CHECK (secp256k1_surjectionproof_allocate_initialized (none , & proof_on_heap , & input_index , fixed_input_tags , SECP256K1_SURJECTIONPROOF_MAX_N_INPUTS + 1 , 3 , & fixed_input_tags [0 ], 100 , seed ) == 0 );
73
+ CHECK (proof_on_heap == 0 );
74
+ CHECK (ecount == 4 );
75
+ CHECK (secp256k1_surjectionproof_allocate_initialized (none , & proof_on_heap , & input_index , fixed_input_tags , n_inputs , n_inputs , & fixed_input_tags [0 ], 100 , seed ) != 0 );
76
+ CHECK (proof_on_heap != 0 );
77
+ secp256k1_surjectionproof_destroy (proof_on_heap );
78
+ CHECK (ecount == 4 );
79
+ CHECK (secp256k1_surjectionproof_allocate_initialized (none , & proof_on_heap , & input_index , fixed_input_tags , n_inputs , n_inputs + 1 , & fixed_input_tags [0 ], 100 , seed ) == 0 );
80
+ CHECK (proof_on_heap == 0 );
81
+ CHECK (ecount == 5 );
82
+ CHECK (secp256k1_surjectionproof_allocate_initialized (none , & proof_on_heap , & input_index , fixed_input_tags , n_inputs , 3 , NULL , 100 , seed ) == 0 );
83
+ CHECK (proof_on_heap == 0 );
84
+ CHECK (ecount == 6 );
85
+ CHECK ((secp256k1_surjectionproof_allocate_initialized (none , & proof_on_heap , & input_index , fixed_input_tags , n_inputs , 0 , & fixed_input_tags [0 ], 0 , seed ) & 1 ) == 0 );
86
+ CHECK (proof_on_heap == 0 );
87
+ CHECK (ecount == 6 );
88
+ CHECK (secp256k1_surjectionproof_allocate_initialized (none , & proof_on_heap , & input_index , fixed_input_tags , n_inputs , 0 , & fixed_input_tags [0 ], 100 , NULL ) == 0 );
89
+ CHECK (proof_on_heap == 0 );
90
+ CHECK (ecount == 7 );
91
+
92
+ /* we are now going to test essentially the same functions, just without heap allocation.
93
+ * reset ecount. */
94
+ ecount = 0 ;
95
+
55
96
/* check initialize */
56
97
CHECK (secp256k1_surjectionproof_initialize (none , & proof , & input_index , fixed_input_tags , n_inputs , 0 , & fixed_input_tags [0 ], 100 , seed ) == 0 );
57
98
CHECK (ecount == 0 );
0 commit comments