Skip to content

Commit dbf40c9

Browse files
authored
Merge pull request #698 from evoskuil/master
Tests for electrum address methods.
2 parents 9335bc6 + ce53ed9 commit dbf40c9

12 files changed

Lines changed: 1434 additions & 46 deletions

File tree

include/bitcoin/server/protocols/protocol_electrum_version.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BCS_API protocol_electrum_version
3838
using rpc_interface = interface::electrum;
3939

4040
static constexpr electrum::version minimum = electrum::version::v1_0;
41-
static constexpr electrum::version maximum = electrum::version::v1_6;
41+
static constexpr electrum::version maximum = electrum::version::v1_7;
4242

4343
inline protocol_electrum_version(const auto& session,
4444
const network::channel::ptr& channel,

src/protocols/electrum/protocol_electrum_scripts.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void protocol_electrum::handle_blockchain_scriptpubkey_get_balance(
4141
if (stopped(ec))
4242
return;
4343

44-
if (at_least(electrum::version::v1_7))
44+
if (!at_least(electrum::version::v1_7))
4545
{
4646
send_code(error::wrong_version);
4747
return;
@@ -71,7 +71,7 @@ void protocol_electrum::handle_blockchain_scriptpubkey_get_history(
7171
if (stopped(ec))
7272
return;
7373

74-
if (at_least(electrum::version::v1_7))
74+
if (!at_least(electrum::version::v1_7))
7575
{
7676
send_code(error::wrong_version);
7777
return;
@@ -101,7 +101,7 @@ void protocol_electrum::handle_blockchain_scriptpubkey_get_mempool(
101101
if (stopped(ec))
102102
return;
103103

104-
if (at_least(electrum::version::v1_7))
104+
if (!at_least(electrum::version::v1_7))
105105
{
106106
send_code(error::wrong_version);
107107
return;
@@ -131,7 +131,7 @@ void protocol_electrum::handle_blockchain_scriptpubkey_list_unspent(
131131
if (stopped(ec))
132132
return;
133133

134-
if (at_least(electrum::version::v1_7))
134+
if (!at_least(electrum::version::v1_7))
135135
{
136136
send_code(error::wrong_version);
137137
return;
@@ -161,7 +161,7 @@ void protocol_electrum::handle_blockchain_scriptpubkey_subscribe(
161161
if (stopped(ec))
162162
return;
163163

164-
if (at_least(electrum::version::v1_7))
164+
if (!at_least(electrum::version::v1_7))
165165
{
166166
send_code(error::wrong_version);
167167
return;
@@ -195,7 +195,7 @@ void protocol_electrum::handle_blockchain_scriptpubkey_unsubscribe(
195195
if (stopped(ec))
196196
return;
197197

198-
if (at_least(electrum::version::v1_7))
198+
if (!at_least(electrum::version::v1_7))
199199
{
200200
send_code(error::wrong_version);
201201
return;

test/protocols/blocks.cpp

Lines changed: 135 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,33 +94,33 @@ bool setup_ten_block_store(query_t& query) NOEXCEPT
9494
query.set(block7, database::context{ 0, 7, 0 }, false, false) &&
9595
query.set(block8, database::context{ 0, 8, 0 }, false, false) &&
9696
query.set(block9, database::context{ 0, 9, 0 }, false, false) &&
97-
query.push_confirmed(query.to_header(block1_hash), false) &&
98-
query.push_confirmed(query.to_header(block2_hash), false) &&
99-
query.push_confirmed(query.to_header(block3_hash), false) &&
100-
query.push_confirmed(query.to_header(block4_hash), false) &&
101-
query.push_confirmed(query.to_header(block5_hash), false) &&
102-
query.push_confirmed(query.to_header(block6_hash), false) &&
103-
query.push_confirmed(query.to_header(block7_hash), false) &&
104-
query.push_confirmed(query.to_header(block8_hash), false) &&
105-
query.push_confirmed(query.to_header(block9_hash), false);
97+
query.push_confirmed(query.to_header(block1_hash), true) &&
98+
query.push_confirmed(query.to_header(block2_hash), true) &&
99+
query.push_confirmed(query.to_header(block3_hash), true) &&
100+
query.push_confirmed(query.to_header(block4_hash), true) &&
101+
query.push_confirmed(query.to_header(block5_hash), true) &&
102+
query.push_confirmed(query.to_header(block6_hash), true) &&
103+
query.push_confirmed(query.to_header(block7_hash), true) &&
104+
query.push_confirmed(query.to_header(block8_hash), true) &&
105+
query.push_confirmed(query.to_header(block9_hash), true);
106106
}
107107

108108
bool setup_three_block_store(query_t& query) NOEXCEPT
109109
{
110110
return query.initialize(genesis) &&
111111
query.set(block1, database::context{ 0, 1, 0 }, false, false) &&
112112
query.set(block2, database::context{ 0, 2, 0 }, false, false) &&
113-
query.push_confirmed(query.to_header(block1_hash), false) &&
114-
query.push_confirmed(query.to_header(block2_hash), false);
113+
query.push_confirmed(query.to_header(block1_hash), true) &&
114+
query.push_confirmed(query.to_header(block2_hash), true);
115115
}
116116

117117
bool setup_three_block_witness_store(query_t& query) NOEXCEPT
118118
{
119119
return query.initialize(genesis) &&
120120
query.set(block1a, database::context{ 0, 1, 0 }, false, false) &&
121121
query.set(block2a, database::context{ 0, 2, 0 }, false, false) &&
122-
query.push_confirmed(query.to_header(block1a.hash()), false) &&
123-
query.push_confirmed(query.to_header(block2a.hash()), false);
122+
query.push_confirmed(query.to_header(block1a.hash()), true) &&
123+
query.push_confirmed(query.to_header(block2a.hash()), true);
124124
}
125125

126126
bool setup_three_block_confirmed_address_store(query_t& query) NOEXCEPT
@@ -154,7 +154,7 @@ const block bogus_block10
154154
{
155155
0x31323334,
156156
block9_hash,
157-
one_hash,
157+
hash_digest{ 0x10, 0xbb },
158158
0x41424344,
159159
0x51525354,
160160
0x61626364
@@ -198,14 +198,14 @@ const block bogus_block10
198198
{
199199
input
200200
{
201-
point{},
201+
point{ block1.transactions_ptr()->front()->hash(false), 0x00 },
202202
script{},
203203
witness{},
204204
0x07
205205
},
206206
input
207207
{
208-
point{},
208+
point{ block2.transactions_ptr()->front()->hash(false), 0x00 },
209209
script{},
210210
witness{},
211211
0x08
@@ -216,11 +216,13 @@ const block bogus_block10
216216
output
217217
{
218218
0x09,
219+
// "1BaMPFdqMUQ46BV8iRcwbVfsam57oBLMM"
219220
script::to_pay_key_hash_pattern({ 0x02 })
220221
},
221222
output
222223
{
223-
0x09,
224+
0x10,
225+
// "31xsx7sPoS2UfoUAKfoXLX6wTPvpetyo7s"
224226
script::to_pay_script_hash_pattern({ 0x03 })
225227
}
226228
},
@@ -258,6 +260,122 @@ const block bogus_block10
258260
}
259261
}
260262
};
263+
const block bogus_block11
264+
{
265+
header
266+
{
267+
0x31323334,
268+
bogus_block10.hash(),
269+
hash_digest{ 0x11, 0xbb },
270+
0x41424344,
271+
0x51525354,
272+
0x61626364
273+
},
274+
transactions
275+
{
276+
transaction
277+
{
278+
0x07,
279+
inputs
280+
{
281+
input
282+
{
283+
point{ block3.transactions_ptr()->front()->hash(false), 0x00 },
284+
script{},
285+
witness{},
286+
0x08
287+
},
288+
input
289+
{
290+
point{ block4.transactions_ptr()->front()->hash(false), 0x00 },
291+
script{},
292+
witness{},
293+
0x09
294+
}
295+
},
296+
outputs
297+
{
298+
output
299+
{
300+
0x10,
301+
// "1BaMPFdqMUQ46BV8iRcwbVfsam57oBLMM"
302+
script::to_pay_key_hash_pattern({ 0x02 })
303+
},
304+
output
305+
{
306+
0x11,
307+
// "1BaMPFdqMUQ46BV8iRcwbVfsam57oBLMM"
308+
script::to_pay_key_hash_pattern({ 0x02 })
309+
},
310+
output
311+
{
312+
0x12,
313+
// "31xsx7sPoS2UfoUAKfoXLX6wTPvpetyo7s"
314+
script::to_pay_script_hash_pattern({ 0x03 })
315+
},
316+
output
317+
{
318+
0x13,
319+
// "31xsx7sPoS2UfoUAKfoXLX6wTPvpetyo7s"
320+
script::to_pay_script_hash_pattern({ 0x03 })
321+
},
322+
output
323+
{
324+
0x14,
325+
// "31xsx7sPoS2UfoUAKfoXLX6wTPvpetyo7s"
326+
script::to_pay_script_hash_pattern({ 0x03 })
327+
}
328+
},
329+
0x0a
330+
}
331+
}
332+
};
333+
const block bogus_block12
334+
{
335+
header
336+
{
337+
0x31323334,
338+
bogus_block11.hash(),
339+
hash_digest{ 0x12, 0xbb },
340+
0x41424344,
341+
0x51525354,
342+
0x61626364
343+
},
344+
transactions
345+
{
346+
transaction
347+
{
348+
0x07,
349+
inputs
350+
{
351+
input
352+
{
353+
point{ bogus_block11.transactions_ptr()->front()->hash(false), 0x03 },
354+
script{},
355+
witness{},
356+
0x08
357+
},
358+
input
359+
{
360+
point{ bogus_block11.transactions_ptr()->front()->hash(false), 0x04 },
361+
script{},
362+
witness{},
363+
0x09
364+
}
365+
},
366+
outputs
367+
{
368+
output
369+
{
370+
0x10,
371+
// "1BaMPFdqMUQ46BV8iRcwbVfsam57oBLMM"
372+
script::to_pay_key_hash_pattern({ 0x02 })
373+
}
374+
},
375+
0x0a
376+
}
377+
}
378+
};
261379
const block bogus_block
262380
{
263381
header

test/protocols/blocks.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ extern const system::chain::block block7;
8585
extern const system::chain::block block8;
8686
extern const system::chain::block block9;
8787
extern const system::chain::block bogus_block10;
88+
extern const system::chain::block bogus_block11;
89+
extern const system::chain::block bogus_block12;
8890

8991
extern const system::chain::block bogus_block;
9092
extern const system::chain::block block1a;

test/protocols/electrum/electrum.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
#include <future>
2323
#include <boost/format.hpp>
2424

25-
electrum_setup_fixture::electrum_setup_fixture(const initializer& setup)
25+
electrum_setup_fixture::electrum_setup_fixture(const initializer& setup,
26+
bool address_index)
2627
: config_
2728
{
2829
system::chain::selection::mainnet,
@@ -33,6 +34,9 @@ electrum_setup_fixture::electrum_setup_fixture(const initializer& setup)
3334
{
3435
[&]() NOEXCEPT -> const database::settings&
3536
{
37+
if (!address_index)
38+
config_.database.address_buckets = 0;
39+
3640
config_.database.path = TEST_DIRECTORY;
3741
return config_.database;
3842
}()

test/protocols/electrum/electrum.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ struct electrum_setup_fixture
2929
DELETE_COPY_MOVE(electrum_setup_fixture);
3030

3131
using initializer = std::function<bool(test::query_t&)>;
32-
explicit electrum_setup_fixture(const initializer& setup);
32+
explicit electrum_setup_fixture(const initializer& setup,
33+
bool address_index=true);
3334
~electrum_setup_fixture();
3435

3536
boost::json::value get(const std::string& request);
@@ -72,4 +73,16 @@ struct electrum_three_block_confirmed_address_setup_fixture
7273
}
7374
};
7475

76+
struct electrum_disabled_address_index_setup_fixture
77+
: electrum_setup_fixture
78+
{
79+
inline electrum_disabled_address_index_setup_fixture()
80+
: electrum_setup_fixture([](test::query_t& query)
81+
{
82+
return test::setup_three_block_confirmed_address_store(query);
83+
}, false)
84+
{
85+
}
86+
};
87+
7588
#endif

0 commit comments

Comments
 (0)