@@ -28,6 +28,7 @@ static void test_surjectionproof_api(void) {
2828 unsigned char serialized_proof [SECP256K1_SURJECTIONPROOF_SERIALIZATION_BYTES_MAX ];
2929 size_t serialized_len ;
3030 secp256k1_surjectionproof proof ;
31+ secp256k1_surjectionproof * proof_on_heap ;
3132 size_t n_inputs = sizeof (fixed_input_tags ) / sizeof (fixed_input_tags [0 ]);
3233 size_t input_index ;
3334 int32_t ecount = 0 ;
@@ -52,6 +53,46 @@ static void test_surjectionproof_api(void) {
5253 memcpy (& fixed_output_tag , & fixed_input_tags [0 ], sizeof (fixed_input_tags [0 ]));
5354 CHECK (secp256k1_generator_generate_blinded (ctx , & ephemeral_output_tag , fixed_output_tag .data , output_blinding_key ));
5455
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+
5596 /* check initialize */
5697 CHECK (secp256k1_surjectionproof_initialize (none , & proof , & input_index , fixed_input_tags , n_inputs , 0 , & fixed_input_tags [0 ], 100 , seed ) == 0 );
5798 CHECK (ecount == 0 );
0 commit comments