File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 5
5
#include < key.h>
6
6
7
7
#include < key_io.h>
8
+ #include < streams.h>
8
9
#include < test/util/setup_common.h>
9
10
#include < uint256.h>
10
11
#include < util/strencodings.h>
@@ -220,4 +221,47 @@ BOOST_AUTO_TEST_CASE(key_key_negation)
220
221
BOOST_CHECK (key.GetPubKey ().data ()[0 ] == 0x03 );
221
222
}
222
223
224
+ static CPubKey UnserializePubkey (const std::vector<uint8_t >& data)
225
+ {
226
+ CDataStream stream{SER_NETWORK, INIT_PROTO_VERSION};
227
+ stream << data;
228
+ CPubKey pubkey;
229
+ stream >> pubkey;
230
+ return pubkey;
231
+ }
232
+
233
+ static unsigned int GetLen (unsigned char chHeader)
234
+ {
235
+ if (chHeader == 2 || chHeader == 3 )
236
+ return CPubKey::COMPRESSED_SIZE;
237
+ if (chHeader == 4 || chHeader == 6 || chHeader == 7 )
238
+ return CPubKey::SIZE;
239
+ return 0 ;
240
+ }
241
+
242
+ static void CmpSerializationPubkey (const CPubKey& pubkey)
243
+ {
244
+ CDataStream stream{SER_NETWORK, INIT_PROTO_VERSION};
245
+ stream << pubkey;
246
+ CPubKey pubkey2;
247
+ stream >> pubkey2;
248
+ BOOST_CHECK (pubkey == pubkey2);
249
+ }
250
+
251
+ BOOST_AUTO_TEST_CASE (pubkey_unserialize)
252
+ {
253
+ for (uint8_t i = 2 ; i <= 7 ; ++i) {
254
+ CPubKey key = UnserializePubkey ({0x02 });
255
+ BOOST_CHECK (!key.IsValid ());
256
+ CmpSerializationPubkey (key);
257
+ key = UnserializePubkey (std::vector<uint8_t >(GetLen (i), i));
258
+ CmpSerializationPubkey (key);
259
+ if (i == 5 ) {
260
+ BOOST_CHECK (!key.IsValid ());
261
+ } else {
262
+ BOOST_CHECK (key.IsValid ());
263
+ }
264
+ }
265
+ }
266
+
223
267
BOOST_AUTO_TEST_SUITE_END ()
You can’t perform that action at this time.
0 commit comments