Skip to content

Commit

Permalink
test: sv2 template provider tests
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Coverdale <[email protected]>
  • Loading branch information
Sjors and ccdle12 committed Nov 30, 2023
1 parent a855a7f commit 2f3eb23
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ BITCOIN_TESTS =\
test/system_tests.cpp \
test/sv2_noise_tests.cpp \
test/sv2_messages_tests.cpp \
test/sv2_template_provider_tests.cpp \
test/timedata_tests.cpp \
test/torcontrol_tests.cpp \
test/transaction_tests.cpp \
Expand Down
141 changes: 141 additions & 0 deletions src/test/sv2_template_provider_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#include <boost/test/unit_test.hpp>
#include <node/sv2_messages.h>
#include <sv2_template_provider.h>
#include <util/strencodings.h>
#include <util/sock.h>
#include <test/util/setup_common.h>
#include <test/util/net.h>

/* BOOST_FIXTURE_TEST_SUITE(sv2_template_provider_tests, TestChain100Setup) */

/* BOOST_AUTO_TEST_CASE(Sv2TemplateProvider_ProcessSv2Message_test) */
/* { */
/* Sv2TemplateProvider template_provider{*m_node.chainman, *m_node.mempool}; */

/* auto sock = std::make_shared<StaticContentsSock>(std::string(1, 'a')); */
/* Sv2Client client{sock}; */
/* client.m_disconnect_flag = false; */
/* client.m_setup_connection_confirmed = false; */
/* BOOST_CHECK(!client.m_disconnect_flag); */
/* BOOST_CHECK(!client.m_setup_connection_confirmed); */

/* std::map<uint64_t, std::unique_ptr<node::CBlockTemplate>> block_cache; */
/* uint64_t template_id{0}; */

/* node::Sv2NewTemplateMsg best_new_template; */
/* node::Sv2SetNewPrevHashMsg best_prev_hash; */

/* // Check that failure to deserialize the body of the message into a SetupConnection */
/* // results in a disconnection for the client. */
/* node::Sv2NetHeader setup_conn_header{node::Sv2MsgType::SETUP_CONNECTION, 0}; */
/* std::vector<uint8_t> empty_body; */
/* node::Sv2NetMsg sv2_msg{std::move(setup_conn_header), std::move(empty_body)}; */

/* template_provider.ProcessSv2Message(sv2_msg, */
/* client, */
/* best_new_template, */
/* best_prev_hash, */
/* block_cache, */
/* template_id); */
/* BOOST_CHECK(client.m_disconnect_flag); */

/* // Check that if a client is already connected and sends a SetupConnection message twice, */
/* // they do not get marked for disconnection. */
/* client.m_setup_connection_confirmed = true; */
/* client.m_disconnect_flag = false; */

/* template_provider.ProcessSv2Message(sv2_msg, */
/* client, */
/* best_new_template, */
/* best_prev_hash, */
/* block_cache, */
/* template_id); */
/* BOOST_CHECK(!client.m_disconnect_flag); */

/* // Check that sending a valid setup connection message can be handled successfully. */
/* /1* uint8_t setup_conn_bytes[]{ *1/ */
/* std::vector<uint8_t> setup_conn_bytes{ */
/* 0x02, // protocol */
/* 0x02, 0x00, // min_version */
/* 0x02, 0x00, // max_version */
/* 0x01, 0x00, 0x00, 0x00, // flags */
/* 0x07, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, // endpoint_host */
/* 0x61, 0x21, // endpoint_port */
/* 0x07, 0x42, 0x69, 0x74, 0x6d, 0x61, 0x69, 0x6e, // vendor */
/* 0x08, 0x53, 0x39, 0x69, 0x20, 0x31, 0x33, 0x2e, 0x35, // hardware_version */
/* 0x1c, 0x62, 0x72, 0x61, 0x69, 0x69, 0x6e, 0x73, 0x2d, 0x6f, 0x73, 0x2d, 0x32, 0x30, */
/* 0x31, 0x38, 0x2d, 0x30, 0x39, 0x2d, 0x32, 0x32, 0x2d, 0x31, 0x2d, 0x68, 0x61, 0x73, */
/* 0x68, // firmware */
/* 0x10, 0x73, 0x6f, 0x6d, 0x65, 0x2d, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x2d, 0x75, */
/* 0x75, 0x69, 0x64, // device_id */
/* }; */

/* auto bytes_copy = setup_conn_bytes; */
/* setup_conn_header = node::Sv2NetHeader{node::Sv2MsgType::SETUP_CONNECTION, static_cast<uint32_t>(bytes_copy.size())}; */
/* sv2_msg = node::Sv2NetMsg{std::move(setup_conn_header), std::move(bytes_copy)}; */
/* template_provider.ProcessSv2Message(sv2_msg, */
/* client, */
/* best_new_template, */
/* best_prev_hash, */
/* block_cache, */
/* template_id); */

/* BOOST_CHECK(client.m_setup_connection_confirmed); */
/* BOOST_CHECK(!client.m_disconnect_flag); */

/* // Check that sending an invalid sub protocol results in the client */
/* // being set for disconnection. */
/* client.m_setup_connection_confirmed = false; */
/* setup_conn_bytes[0] = 0x03; */
/* setup_conn_header = node::Sv2NetHeader{node::Sv2MsgType::SETUP_CONNECTION, static_cast<uint32_t>(setup_conn_bytes.size())}; */
/* sv2_msg = node::Sv2NetMsg{std::move(setup_conn_header), std::move(setup_conn_bytes)}; */

/* template_provider.ProcessSv2Message(sv2_msg, */
/* client, */
/* best_new_template, */
/* best_prev_hash, */
/* block_cache, */
/* template_id); */

/* /1* BOOST_CHECK(!client.m_setup_connection_confirmed); *1/ */
/* /1* BOOST_CHECK(client.m_disconnect_flag); *1/ */

/* /1* // Check that incompatible versions of the current sv2 protocol means the client is *1/ */
/* /1* // set for disconnection. *1/ */
/* /1* client.m_disconnect_flag = false; *1/ */
/* /1* BOOST_CHECK(!client.m_disconnect_flag); *1/ */
/* /1* setup_conn_bytes[1] = 0x05; *1/ */
/* /1* setup_conn_bytes[3] = 0x1a; *1/ */
/* /1* ss_setup_conn.clear(); *1/ */
/* /1* ss_setup_conn = CDataStream(setup_conn_bytes, SER_NETWORK, PROTOCOL_VERSION); *1/ */

/* /1* template_provider.ProcessSv2Message(node::Sv2NetHeader{node::Sv2MsgType::SETUP_CONNECTION, sizeof(setup_conn_bytes)}, *1/ */
/* /1* ss_setup_conn, *1/ */
/* /1* client, *1/ */
/* /1* best_new_template, *1/ */
/* /1* best_prev_hash, *1/ */
/* /1* block_cache, *1/ */
/* /1* template_id); *1/ */

/* /1* BOOST_CHECK(!client.m_setup_connection_confirmed); *1/ */
/* /1* BOOST_CHECK(client.m_disconnect_flag); *1/ */

/* /1* // Check that receiving a valid coinbase_output_max_additional_size_bytes results *1/ */
/* /1* // in a new block in the block cache matched with an incremented template id. *1/ */
/* /1* client.m_setup_connection_confirmed = true; *1/ */
/* /1* uint8_t coinbase_output_max_additional_size_bytes[]{ *1/ */
/* /1* 0x01, 0x00, 0x00, 0x00, // additional coinbase output size *1/ */
/* /1* }; *1/ */
/* /1* CDataStream ss_coinbase_output_max_additional_size(coinbase_output_max_additional_size_bytes, SER_NETWORK, PROTOCOL_VERSION); *1/ */

/* /1* template_provider.ProcessSv2Message(node::Sv2NetHeader{node::Sv2MsgType::COINBASE_OUTPUT_DATA_SIZE, sizeof(coinbase_output_max_additional_size_bytes)}, *1/ */
/* /1* ss_coinbase_output_max_additional_size, *1/ */
/* /1* client, *1/ */
/* /1* best_new_template, *1/ */
/* /1* best_prev_hash, *1/ */
/* /1* block_cache, *1/ */
/* /1* template_id); *1/ */
/* /1* BOOST_CHECK_EQUAL(template_id, 1); *1/ */
/* /1* BOOST_CHECK(block_cache.count(template_id)); *1/ */
/* } */
/* BOOST_AUTO_TEST_SUITE_END() */

0 comments on commit 2f3eb23

Please sign in to comment.