-
Notifications
You must be signed in to change notification settings - Fork 0
Enforce Bitcoin mainnet shadow mode by default #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
|
|
||
| # Build folder | ||
| build/ | ||
| build_write_enabled/ | ||
| bin/ | ||
| out/ | ||
| _codeql_build_dir/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -99,3 +99,21 @@ TEST(AdapterRegistryTest, GetBlockHeightReturnsValue) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+109
to
+117
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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); | |
| TEST(BitcoinShadowModeTest, BitcoinWritesThrowWhenDisabled) { | |
| // When AILEE_BITCOIN_WRITE_DISABLED is set, Bitcoin write operations | |
| // should be blocked at runtime by throwing std::runtime_error. | |
| // buildRawTx should reject any attempt to construct a spendable tx. | |
| EXPECT_THROW( | |
| { | |
| try { | |
| // Parameters are illustrative; exact semantics are handled by the implementation. | |
| auto rawTx = buildRawTx("from_address", "to_address", 1000); | |
| (void)rawTx; | |
| } catch (const std::runtime_error &e) { | |
| // Optionally verify that the error message indicates writes are disabled. | |
| std::string msg = e.what(); | |
| // Do not require a specific string to avoid brittleness, but ensure it's non-empty. | |
| EXPECT_FALSE(msg.empty()); | |
| throw; | |
| } | |
| }, | |
| std::runtime_error); | |
| // broadcastRaw should also be blocked and throw std::runtime_error. | |
| EXPECT_THROW( | |
| { | |
| try { | |
| auto txid = broadcastRaw("deadbeef"); | |
| (void)txid; | |
| } catch (const std::runtime_error &e) { | |
| std::string msg = e.what(); | |
| EXPECT_FALSE(msg.empty()); | |
| throw; | |
| } | |
| }, | |
| std::runtime_error); | |
| } | |
| #else | |
| TEST(BitcoinShadowModeTest, BitcoinWritesSucceedWhenEnabled) { | |
| // When AILEE_BITCOIN_WRITE_DISABLED is not set, Bitcoin write operations | |
| // are compiled in and should be callable without throwing. | |
| std::string rawTx; | |
| EXPECT_NO_THROW( | |
| { | |
| // Construct a raw transaction; implementation defines address/amount handling. | |
| rawTx = buildRawTx("from_address", "to_address", 1000); | |
| }); | |
| // If buildRawTx returns a string, it should be non-empty for a valid call. | |
| EXPECT_FALSE(rawTx.empty()); | |
| std::string txid; | |
| EXPECT_NO_THROW( | |
| { | |
| txid = broadcastRaw(rawTx); | |
| }); | |
| // A successfully broadcast transaction should typically have a non-empty txid. | |
| EXPECT_FALSE(txid.empty()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compile definitions for AILEE_BITCOIN_WRITE_DISABLED are only applied to
ailee_nodeandailee_adapterstargets, but not to the test targetailee_tests(defined at line 437). This means tests will not have the same compile-time configuration as the production code they're testing.The test at lines 108-119 in tests/AdapterRegistryTests.cpp checks which macro is defined, but it will always execute the "write enabled" path since the test target doesn't receive the AILEE_BITCOIN_WRITE_DISABLED definition.
Consider adding the compile definition to the test target as well to ensure tests run with the same configuration as production code.