Skip to content

Commit 627190f

Browse files
committed
Add electrum blockchain_relay_fee test, stub in test files.
1 parent 1499c47 commit 627190f

12 files changed

Lines changed: 285 additions & 244 deletions

Makefile.am

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ test_libbitcoin_server_test_SOURCES = \
8181
test/protocols/blocks.hpp \
8282
test/protocols/electrum/electrum.cpp \
8383
test/protocols/electrum/electrum.hpp \
84-
test/protocols/electrum/electrum_block_header.cpp \
85-
test/protocols/electrum/electrum_block_headers.cpp \
86-
test/protocols/electrum/electrum_headers_subscribe.cpp \
84+
test/protocols/electrum/electrum_addresses.cpp \
85+
test/protocols/electrum/electrum_fees.cpp \
86+
test/protocols/electrum/electrum_headers.cpp \
8787
test/protocols/electrum/electrum_server.cpp \
88-
test/protocols/electrum/electrum_server_version.cpp
88+
test/protocols/electrum/electrum_server_version.cpp \
89+
test/protocols/electrum/electrum_transactions.cpp
8990

9091
endif WITH_TESTS
9192

builds/cmake/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,12 @@ if (with-tests)
310310
"../../test/protocols/blocks.hpp"
311311
"../../test/protocols/electrum/electrum.cpp"
312312
"../../test/protocols/electrum/electrum.hpp"
313-
"../../test/protocols/electrum/electrum_block_header.cpp"
314-
"../../test/protocols/electrum/electrum_block_headers.cpp"
315-
"../../test/protocols/electrum/electrum_headers_subscribe.cpp"
313+
"../../test/protocols/electrum/electrum_addresses.cpp"
314+
"../../test/protocols/electrum/electrum_fees.cpp"
315+
"../../test/protocols/electrum/electrum_headers.cpp"
316316
"../../test/protocols/electrum/electrum_server.cpp"
317-
"../../test/protocols/electrum/electrum_server_version.cpp" )
317+
"../../test/protocols/electrum/electrum_server_version.cpp"
318+
"../../test/protocols/electrum/electrum_transactions.cpp" )
318319
319320
add_test( NAME libbitcoin-server-test COMMAND libbitcoin-server-test
320321
--run_test=*

builds/msvc/vs2022/libbitcoin-server-test/libbitcoin-server-test.vcxproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@
133133
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum.cpp">
134134
<ObjectFileName>$(IntDir)test_protocols_electrum_electrum.obj</ObjectFileName>
135135
</ClCompile>
136-
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_block_header.cpp" />
137-
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_block_headers.cpp" />
138-
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_headers_subscribe.cpp" />
136+
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_addresses.cpp" />
137+
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_fees.cpp" />
138+
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_headers.cpp" />
139139
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_server.cpp" />
140140
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_server_version.cpp" />
141+
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_transactions.cpp" />
141142
<ClCompile Include="..\..\..\..\test\settings.cpp" />
142143
<ClCompile Include="..\..\..\..\test\test.cpp">
143144
<ObjectFileName>$(IntDir)test_test.obj</ObjectFileName>

builds/msvc/vs2022/libbitcoin-server-test/libbitcoin-server-test.vcxproj.filters

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@
5757
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum.cpp">
5858
<Filter>src\protocols\electrum</Filter>
5959
</ClCompile>
60-
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_block_header.cpp">
60+
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_addresses.cpp">
6161
<Filter>src\protocols\electrum</Filter>
6262
</ClCompile>
63-
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_block_headers.cpp">
63+
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_fees.cpp">
6464
<Filter>src\protocols\electrum</Filter>
6565
</ClCompile>
66-
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_headers_subscribe.cpp">
66+
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_headers.cpp">
6767
<Filter>src\protocols\electrum</Filter>
6868
</ClCompile>
6969
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_server.cpp">
@@ -72,6 +72,9 @@
7272
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_server_version.cpp">
7373
<Filter>src\protocols\electrum</Filter>
7474
</ClCompile>
75+
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_transactions.cpp">
76+
<Filter>src\protocols\electrum</Filter>
77+
</ClCompile>
7578
<ClCompile Include="..\..\..\..\test\settings.cpp">
7679
<Filter>src</Filter>
7780
</ClCompile>

src/protocols/protocol_electrum.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ void protocol_electrum::handle_blockchain_scripthash_unsubscribe(const code& ec,
407407
send_code(error::not_implemented);
408408
}
409409

410+
// TODO: requires tx pool in order to validate against unconfirmed txs.
411+
// TODO: requires that p2p channels subscribe to transaction broadcast.
410412
void protocol_electrum::handle_blockchain_transaction_broadcast(const code& ec,
411413
rpc_interface::blockchain_transaction_broadcast,
412414
const std::string& ) NOEXCEPT

test/protocols/electrum/electrum.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ electrum_setup_fixture::electrum_setup_fixture()
5252
electrum.connections = 1;
5353
database_settings.interval_depth = 2;
5454
node_settings.delay_inbound = false;
55+
node_settings.minimum_fee_rate = 99.0;
5556
network_settings.inbound.connections = 0;
5657
network_settings.outbound.connections = 0;
5758
auto ec = store_.create([](auto, auto) {});
@@ -127,4 +128,4 @@ bool electrum_setup_fixture::handshake(const std::string& version,
127128
(result.at(0).is_string() && result.at(1).is_string()) &&
128129
(result.at(0).as_string() == config().server.electrum.server_name) &&
129130
(result.at(1).as_string() == version);
130-
}
131+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) 2011-2026 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#include "../../test.hpp"
20+
#include "electrum.hpp"
21+
22+
BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture)
23+
24+
BOOST_AUTO_TEST_SUITE_END()

test/protocols/electrum/electrum_block_header.cpp

Lines changed: 0 additions & 162 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) 2011-2026 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#include "../../test.hpp"
20+
#include "electrum.hpp"
21+
22+
BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture)
23+
24+
// blockchain.relay_fee
25+
26+
BOOST_AUTO_TEST_CASE(electrum__blockchain_relay_fee__default__expected)
27+
{
28+
BOOST_CHECK(handshake());
29+
30+
constexpr auto expected = 99.0;
31+
const auto response = get(R"({"id":90,"method":"blockchain.relayfee","params":[]})" "\n");
32+
BOOST_CHECK_EQUAL(response.at("id").as_int64(), 90);
33+
BOOST_CHECK(response.at("result").is_number());
34+
BOOST_CHECK_EQUAL(response.at("result").as_double(), expected);
35+
}
36+
37+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)