-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdapterRegistryTests.cpp
More file actions
119 lines (101 loc) · 3.86 KB
/
Copy pathAdapterRegistryTests.cpp
File metadata and controls
119 lines (101 loc) · 3.86 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// AdapterRegistryTests.cpp
// Unit tests for AILEE‑Core Global_Seven AdapterRegistry
// Requires GoogleTest (gtest) framework
#include "Global_Seven.h"
#include <gtest/gtest.h>
using namespace ailee::global_seven;
// Dummy adapter for testing
class DummyAdapter : public IChainAdapter {
public:
bool init(const AdapterConfig&, ErrorCallback) override { return true; }
bool start(TxCallback, BlockCallback, EnergyCallback) override { return true; }
void stop() override {}
bool broadcastTransaction(const std::vector<TxOut>&,
const std::unordered_map<std::string, std::string>&,
std::string& outChainTxId) override {
outChainTxId = "dummy_txid";
return true;
}
std::optional<NormalizedTx> getTransaction(const std::string& chainTxId) override {
NormalizedTx nt;
nt.chainTxId = chainTxId;
nt.chain = Chain::Custom1;
return nt;
}
std::optional<BlockHeader> getBlockHeader(const std::string& blockHash) override {
BlockHeader bh;
bh.hash = blockHash;
bh.chain = Chain::Custom1;
return bh;
}
std::optional<uint64_t> getBlockHeight() override { return 42ULL; }
Chain chain() const override { return Chain::Custom1; }
AdapterTraits traits() const override {
return AdapterTraits{true,true,false,false,false,
UnitSpec{8,"sats","DUM"}, "DummyAdapter","0.1.0",true};
}
};
// ---- Tests ----
TEST(AdapterRegistryTest, RegisterAndRetrieveAdapter) {
auto& registry = AdapterRegistry::instance();
// Register dummy adapter
registry.registerAdapter(Chain::Custom1, std::unique_ptr<IChainAdapter>(new DummyAdapter()));
// Retrieve adapter
IChainAdapter* adapter = registry.get(Chain::Custom1);
ASSERT_NE(adapter, nullptr);
// Verify traits
AdapterTraits traits = adapter->traits();
EXPECT_EQ(traits.adapterName, "DummyAdapter");
EXPECT_TRUE(traits.audited);
}
TEST(AdapterRegistryTest, BroadcastTransactionWorks) {
auto& registry = AdapterRegistry::instance();
IChainAdapter* adapter = registry.get(Chain::Custom1);
ASSERT_NE(adapter, nullptr);
std::string txid;
bool ok = adapter->broadcastTransaction({}, {}, txid);
EXPECT_TRUE(ok);
EXPECT_EQ(txid, "dummy_txid");
}
TEST(AdapterRegistryTest, GetTransactionReturnsNormalizedTx) {
auto& registry = AdapterRegistry::instance();
IChainAdapter* adapter = registry.get(Chain::Custom1);
ASSERT_NE(adapter, nullptr);
auto tx = adapter->getTransaction("abc123");
ASSERT_TRUE(tx.has_value());
EXPECT_EQ(tx->chainTxId, "abc123");
EXPECT_EQ(tx->chain, Chain::Custom1);
}
TEST(AdapterRegistryTest, GetBlockHeaderReturnsHeader) {
auto& registry = AdapterRegistry::instance();
IChainAdapter* adapter = registry.get(Chain::Custom1);
ASSERT_NE(adapter, nullptr);
auto bh = adapter->getBlockHeader("blockhash");
ASSERT_TRUE(bh.has_value());
EXPECT_EQ(bh->hash, "blockhash");
EXPECT_EQ(bh->chain, Chain::Custom1);
}
TEST(AdapterRegistryTest, GetBlockHeightReturnsValue) {
auto& registry = AdapterRegistry::instance();
IChainAdapter* adapter = registry.get(Chain::Custom1);
ASSERT_NE(adapter, nullptr);
auto h = adapter->getBlockHeight();
ASSERT_TRUE(h.has_value());
EXPECT_EQ(h.value(), 42ULL);
}
TEST(AdapterConfigTest, ReadOnlyDefaultIsTrue) {
AdapterConfig cfg;
EXPECT_TRUE(cfg.readOnly);
}
#if defined(AILEE_BITCOIN_WRITE_DISABLED)
TEST(BitcoinShadowModeTest, WriteDisabledAtCompileTime) {
// When AILEE_BITCOIN_WRITE_DISABLED is set, the macro is active.
// This test documents that the compile-time gate is in effect.
EXPECT_TRUE(true);
}
#else
TEST(BitcoinShadowModeTest, WriteEnabledAtCompileTime) {
// AILEE_BITCOIN_WRITE_ENABLED=ON was set; write ops are compiled in.
EXPECT_TRUE(true);
}
#endif