Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BCS_API protocol_electrum_version
using rpc_interface = interface::electrum;

static constexpr electrum::version minimum = electrum::version::v1_0;
static constexpr electrum::version maximum = electrum::version::v1_6;
static constexpr electrum::version maximum = electrum::version::v1_7;

inline protocol_electrum_version(const auto& session,
const network::channel::ptr& channel,
Expand Down
12 changes: 6 additions & 6 deletions src/protocols/electrum/protocol_electrum_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void protocol_electrum::handle_blockchain_scriptpubkey_get_balance(
if (stopped(ec))
return;

if (at_least(electrum::version::v1_7))
if (!at_least(electrum::version::v1_7))
{
send_code(error::wrong_version);
return;
Expand Down Expand Up @@ -71,7 +71,7 @@ void protocol_electrum::handle_blockchain_scriptpubkey_get_history(
if (stopped(ec))
return;

if (at_least(electrum::version::v1_7))
if (!at_least(electrum::version::v1_7))
{
send_code(error::wrong_version);
return;
Expand Down Expand Up @@ -101,7 +101,7 @@ void protocol_electrum::handle_blockchain_scriptpubkey_get_mempool(
if (stopped(ec))
return;

if (at_least(electrum::version::v1_7))
if (!at_least(electrum::version::v1_7))
{
send_code(error::wrong_version);
return;
Expand Down Expand Up @@ -131,7 +131,7 @@ void protocol_electrum::handle_blockchain_scriptpubkey_list_unspent(
if (stopped(ec))
return;

if (at_least(electrum::version::v1_7))
if (!at_least(electrum::version::v1_7))
{
send_code(error::wrong_version);
return;
Expand Down Expand Up @@ -161,7 +161,7 @@ void protocol_electrum::handle_blockchain_scriptpubkey_subscribe(
if (stopped(ec))
return;

if (at_least(electrum::version::v1_7))
if (!at_least(electrum::version::v1_7))
{
send_code(error::wrong_version);
return;
Expand Down Expand Up @@ -195,7 +195,7 @@ void protocol_electrum::handle_blockchain_scriptpubkey_unsubscribe(
if (stopped(ec))
return;

if (at_least(electrum::version::v1_7))
if (!at_least(electrum::version::v1_7))
{
send_code(error::wrong_version);
return;
Expand Down
152 changes: 135 additions & 17 deletions test/protocols/blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,33 +94,33 @@ bool setup_ten_block_store(query_t& query) NOEXCEPT
query.set(block7, database::context{ 0, 7, 0 }, false, false) &&
query.set(block8, database::context{ 0, 8, 0 }, false, false) &&
query.set(block9, database::context{ 0, 9, 0 }, false, false) &&
query.push_confirmed(query.to_header(block1_hash), false) &&
query.push_confirmed(query.to_header(block2_hash), false) &&
query.push_confirmed(query.to_header(block3_hash), false) &&
query.push_confirmed(query.to_header(block4_hash), false) &&
query.push_confirmed(query.to_header(block5_hash), false) &&
query.push_confirmed(query.to_header(block6_hash), false) &&
query.push_confirmed(query.to_header(block7_hash), false) &&
query.push_confirmed(query.to_header(block8_hash), false) &&
query.push_confirmed(query.to_header(block9_hash), false);
query.push_confirmed(query.to_header(block1_hash), true) &&
query.push_confirmed(query.to_header(block2_hash), true) &&
query.push_confirmed(query.to_header(block3_hash), true) &&
query.push_confirmed(query.to_header(block4_hash), true) &&
query.push_confirmed(query.to_header(block5_hash), true) &&
query.push_confirmed(query.to_header(block6_hash), true) &&
query.push_confirmed(query.to_header(block7_hash), true) &&
query.push_confirmed(query.to_header(block8_hash), true) &&
query.push_confirmed(query.to_header(block9_hash), true);
}

bool setup_three_block_store(query_t& query) NOEXCEPT
{
return query.initialize(genesis) &&
query.set(block1, database::context{ 0, 1, 0 }, false, false) &&
query.set(block2, database::context{ 0, 2, 0 }, false, false) &&
query.push_confirmed(query.to_header(block1_hash), false) &&
query.push_confirmed(query.to_header(block2_hash), false);
query.push_confirmed(query.to_header(block1_hash), true) &&
query.push_confirmed(query.to_header(block2_hash), true);
}

bool setup_three_block_witness_store(query_t& query) NOEXCEPT
{
return query.initialize(genesis) &&
query.set(block1a, database::context{ 0, 1, 0 }, false, false) &&
query.set(block2a, database::context{ 0, 2, 0 }, false, false) &&
query.push_confirmed(query.to_header(block1a.hash()), false) &&
query.push_confirmed(query.to_header(block2a.hash()), false);
query.push_confirmed(query.to_header(block1a.hash()), true) &&
query.push_confirmed(query.to_header(block2a.hash()), true);
}

bool setup_three_block_confirmed_address_store(query_t& query) NOEXCEPT
Expand Down Expand Up @@ -154,7 +154,7 @@ const block bogus_block10
{
0x31323334,
block9_hash,
one_hash,
hash_digest{ 0x10, 0xbb },
0x41424344,
0x51525354,
0x61626364
Expand Down Expand Up @@ -198,14 +198,14 @@ const block bogus_block10
{
input
{
point{},
point{ block1.transactions_ptr()->front()->hash(false), 0x00 },
script{},
witness{},
0x07
},
input
{
point{},
point{ block2.transactions_ptr()->front()->hash(false), 0x00 },
script{},
witness{},
0x08
Expand All @@ -216,11 +216,13 @@ const block bogus_block10
output
{
0x09,
// "1BaMPFdqMUQ46BV8iRcwbVfsam57oBLMM"
script::to_pay_key_hash_pattern({ 0x02 })
},
output
{
0x09,
0x10,
// "31xsx7sPoS2UfoUAKfoXLX6wTPvpetyo7s"
script::to_pay_script_hash_pattern({ 0x03 })
}
},
Expand Down Expand Up @@ -258,6 +260,122 @@ const block bogus_block10
}
}
};
const block bogus_block11
{
header
{
0x31323334,
bogus_block10.hash(),
hash_digest{ 0x11, 0xbb },
0x41424344,
0x51525354,
0x61626364
},
transactions
{
transaction
{
0x07,
inputs
{
input
{
point{ block3.transactions_ptr()->front()->hash(false), 0x00 },
script{},
witness{},
0x08
},
input
{
point{ block4.transactions_ptr()->front()->hash(false), 0x00 },
script{},
witness{},
0x09
}
},
outputs
{
output
{
0x10,
// "1BaMPFdqMUQ46BV8iRcwbVfsam57oBLMM"
script::to_pay_key_hash_pattern({ 0x02 })
},
output
{
0x11,
// "1BaMPFdqMUQ46BV8iRcwbVfsam57oBLMM"
script::to_pay_key_hash_pattern({ 0x02 })
},
output
{
0x12,
// "31xsx7sPoS2UfoUAKfoXLX6wTPvpetyo7s"
script::to_pay_script_hash_pattern({ 0x03 })
},
output
{
0x13,
// "31xsx7sPoS2UfoUAKfoXLX6wTPvpetyo7s"
script::to_pay_script_hash_pattern({ 0x03 })
},
output
{
0x14,
// "31xsx7sPoS2UfoUAKfoXLX6wTPvpetyo7s"
script::to_pay_script_hash_pattern({ 0x03 })
}
},
0x0a
}
}
};
const block bogus_block12
{
header
{
0x31323334,
bogus_block11.hash(),
hash_digest{ 0x12, 0xbb },
0x41424344,
0x51525354,
0x61626364
},
transactions
{
transaction
{
0x07,
inputs
{
input
{
point{ bogus_block11.transactions_ptr()->front()->hash(false), 0x03 },
script{},
witness{},
0x08
},
input
{
point{ bogus_block11.transactions_ptr()->front()->hash(false), 0x04 },
script{},
witness{},
0x09
}
},
outputs
{
output
{
0x10,
// "1BaMPFdqMUQ46BV8iRcwbVfsam57oBLMM"
script::to_pay_key_hash_pattern({ 0x02 })
}
},
0x0a
}
}
};
const block bogus_block
{
header
Expand Down
2 changes: 2 additions & 0 deletions test/protocols/blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ extern const system::chain::block block7;
extern const system::chain::block block8;
extern const system::chain::block block9;
extern const system::chain::block bogus_block10;
extern const system::chain::block bogus_block11;
extern const system::chain::block bogus_block12;

extern const system::chain::block bogus_block;
extern const system::chain::block block1a;
Expand Down
6 changes: 5 additions & 1 deletion test/protocols/electrum/electrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#include <future>
#include <boost/format.hpp>

electrum_setup_fixture::electrum_setup_fixture(const initializer& setup)
electrum_setup_fixture::electrum_setup_fixture(const initializer& setup,
bool address_index)
: config_
{
system::chain::selection::mainnet,
Expand All @@ -33,6 +34,9 @@ electrum_setup_fixture::electrum_setup_fixture(const initializer& setup)
{
[&]() NOEXCEPT -> const database::settings&
{
if (!address_index)
config_.database.address_buckets = 0;

config_.database.path = TEST_DIRECTORY;
return config_.database;
}()
Expand Down
15 changes: 14 additions & 1 deletion test/protocols/electrum/electrum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ struct electrum_setup_fixture
DELETE_COPY_MOVE(electrum_setup_fixture);

using initializer = std::function<bool(test::query_t&)>;
explicit electrum_setup_fixture(const initializer& setup);
explicit electrum_setup_fixture(const initializer& setup,
bool address_index=true);
~electrum_setup_fixture();

boost::json::value get(const std::string& request);
Expand Down Expand Up @@ -72,4 +73,16 @@ struct electrum_three_block_confirmed_address_setup_fixture
}
};

struct electrum_disabled_address_index_setup_fixture
: electrum_setup_fixture
{
inline electrum_disabled_address_index_setup_fixture()
: electrum_setup_fixture([](test::query_t& query)
{
return test::setup_three_block_confirmed_address_store(query);
}, false)
{
}
};

#endif
Loading