-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_serialization_simple.cpp
More file actions
90 lines (70 loc) · 3.58 KB
/
Copy pathtest_serialization_simple.cpp
File metadata and controls
90 lines (70 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include "src/key.h"
#include "src/uint256.h"
#include "src/dilithium/aggregation.h"
#include "src/streams.h"
int main() {
std::cout << "🔧 Тест правильной сериализации CQPubKey..." << std::endl;
try {
// Создание ключа
CQKey key;
key.MakeNewKey(true);
if (!key.IsValid()) {
std::cout << "❌ Ошибка создания ключа" << std::endl;
return 1;
}
CQPubKey pubkey = key.GetPubKey();
if (!pubkey.IsValid()) {
std::cout << "❌ Ошибка извлечения публичного ключа" << std::endl;
return 1;
}
// Тестирование сериализации с настоящим Bitcoin serialization framework
std::vector<unsigned char> serialized;
VectorWriter writer{serialized, 0};
writer << pubkey;
std::cout << "✅ Сериализация успешна: " << serialized.size() << " bytes" << std::endl;
// Тестирование десериализации
SpanReader reader{serialized};
CQPubKey pubkey_restored;
reader >> pubkey_restored;
if (!pubkey_restored.IsValid()) {
std::cout << "❌ Ошибка десериализации" << std::endl;
return 1;
}
std::cout << "✅ Десериализация успешна" << std::endl;
// Проверка что ключи идентичны
if (memcmp(pubkey.data(), pubkey_restored.data(), pubkey.size()) == 0) {
std::cout << "✅ Ключи идентичны после сериализации/десериализации" << std::endl;
} else {
std::cout << "❌ Ключи не совпадают" << std::endl;
return 1;
}
// **ТЕСТ AGGREGATION SERIALIZATION**
std::cout << "\n🔧 Тест сериализации CAggregatedSignature..." << std::endl;
CAggregatedSignature agg_sig;
agg_sig.sig_count = 1;
agg_sig.agg_signature.resize(200);
uint256 test_hash;
memset(test_hash.begin(), 0xde, 32); // Fill with test pattern
agg_sig.message_hashes.push_back(test_hash);
agg_sig.pubkeys.push_back(pubkey);
// Тест GetSerializeSize с реальной сериализацией
size_t predicted_size = agg_sig.GetSerializeSize();
std::vector<unsigned char> agg_serialized;
VectorWriter agg_writer{agg_serialized, 0};
agg_writer << agg_sig;
std::cout << "✅ Aggregated signature сериализация: " << agg_serialized.size() << " bytes" << std::endl;
std::cout << "✅ Predicted size: " << predicted_size << " bytes" << std::endl;
if (agg_serialized.size() == predicted_size) {
std::cout << "✅ GetSerializeSize точный!" << std::endl;
} else {
std::cout << "⚠️ Size mismatch: actual " << agg_serialized.size() << " vs predicted " << predicted_size << std::endl;
}
std::cout << "\n🎉 ВСЕ PRODUCTION ТЕСТЫ ПРОЙДЕНЫ!" << std::endl;
std::cout << "Полная Bitcoin serialization интеграция работает!" << std::endl;
return 0;
} catch (const std::exception& e) {
std::cout << "❌ Исключение: " << e.what() << std::endl;
return 1;
}
}