diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core_proxy/core_proxy.cpp | 14 | ||||
-rw-r--r-- | tests/core_proxy/core_proxy.h | 10 | ||||
-rw-r--r-- | tests/core_tests/chaingen.h | 18 | ||||
-rwxr-xr-x | tests/functional_tests/cold_signing.py | 5 | ||||
-rwxr-xr-x | tests/functional_tests/multisig.py | 2 | ||||
-rwxr-xr-x | tests/functional_tests/transfer.py | 34 | ||||
-rw-r--r-- | tests/unit_tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/unit_tests/levin.cpp | 97 | ||||
-rw-r--r-- | tests/unit_tests/net.cpp | 9 | ||||
-rw-r--r-- | tests/unit_tests/node_server.cpp (renamed from tests/unit_tests/ban.cpp) | 47 | ||||
-rw-r--r-- | tests/unit_tests/ringdb.cpp | 16 |
11 files changed, 198 insertions, 56 deletions
diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp index ed68f04e7..db5b7797a 100644 --- a/tests/core_proxy/core_proxy.cpp +++ b/tests/core_proxy/core_proxy.cpp @@ -160,7 +160,7 @@ string tx2str(const cryptonote::transaction& tx, const cryptonote::hash256& tx_h return ss.str(); }*/ -bool tests::proxy_core::handle_incoming_tx(const cryptonote::blobdata& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { +bool tests::proxy_core::handle_incoming_tx(const cryptonote::tx_blob_entry& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { if (!keeped_by_block) return true; @@ -168,7 +168,13 @@ bool tests::proxy_core::handle_incoming_tx(const cryptonote::blobdata& tx_blob, crypto::hash tx_prefix_hash = null_hash; transaction tx; - if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash, tx_prefix_hash)) { + if (tx_blob.prunable_hash != crypto::null_hash) + { + cerr << "WRONG TRANSACTION, pruned blob rejected" << endl; + return false; + } + + if (!parse_and_validate_tx_from_blob(tx_blob.blob, tx, tx_hash, tx_prefix_hash)) { cerr << "WRONG TRANSACTION BLOB, Failed to parse, rejected" << endl; return false; } @@ -176,7 +182,7 @@ bool tests::proxy_core::handle_incoming_tx(const cryptonote::blobdata& tx_blob, cout << "TX " << endl << endl; cout << tx_hash << endl; cout << tx_prefix_hash << endl; - cout << tx_blob.size() << endl; + cout << tx_blob.blob.size() << endl; //cout << string_tools::buff_to_hex_nodelimer(tx_blob) << endl << endl; cout << obj_to_json_str(tx) << endl; cout << endl << "ENDTX" << endl; @@ -184,7 +190,7 @@ bool tests::proxy_core::handle_incoming_tx(const cryptonote::blobdata& tx_blob, return true; } -bool tests::proxy_core::handle_incoming_txs(const std::vector<blobdata>& tx_blobs, std::vector<tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) +bool tests::proxy_core::handle_incoming_txs(const std::vector<tx_blob_entry>& tx_blobs, std::vector<tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { tvc.resize(tx_blobs.size()); size_t i = 0; diff --git a/tests/core_proxy/core_proxy.h b/tests/core_proxy/core_proxy.h index 6c8b3ccb6..0e41a2be0 100644 --- a/tests/core_proxy/core_proxy.h +++ b/tests/core_proxy/core_proxy.h @@ -75,13 +75,13 @@ namespace tests bool get_stat_info(cryptonote::core_stat_info& st_inf){return true;} bool have_block(const crypto::hash& id); void get_blockchain_top(uint64_t& height, crypto::hash& top_id); - bool handle_incoming_tx(const cryptonote::blobdata& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay); - bool handle_incoming_txs(const std::vector<cryptonote::blobdata>& tx_blobs, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay); + bool handle_incoming_tx(const cryptonote::tx_blob_entry& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay); + bool handle_incoming_txs(const std::vector<cryptonote::tx_blob_entry>& tx_blobs, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay); bool handle_incoming_block(const cryptonote::blobdata& block_blob, const cryptonote::block *block, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true); void pause_mine(){} void resume_mine(){} bool on_idle(){return true;} - bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp){return true;} + bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, bool clip_pruned, cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp){return true;} bool handle_get_objects(cryptonote::NOTIFY_REQUEST_GET_OBJECTS::request& arg, cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request& rsp, cryptonote::cryptonote_connection_context& context){return true;} cryptonote::Blockchain &get_blockchain_storage() { throw std::runtime_error("Called invalid member function: please never call get_blockchain_storage on the TESTING class proxy_core."); } bool get_test_drop_download() {return true;} @@ -103,7 +103,9 @@ namespace tests uint64_t get_earliest_ideal_height_for_version(uint8_t version) const { return 0; } cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; } bool fluffy_blocks_enabled() const { return false; } - uint64_t prevalidate_block_hashes(uint64_t height, const std::vector<crypto::hash> &hashes) { return 0; } + uint64_t prevalidate_block_hashes(uint64_t height, const std::vector<crypto::hash> &hashes, const std::vector<uint64_t> &weights) { return 0; } + bool has_block_weights(uint64_t height, uint64_t nblocks) const { return false; } + bool is_within_compiled_block_hash_area(uint64_t height) const { return false; } bool pad_transactions() const { return false; } uint32_t get_blockchain_pruning_seed() const { return 0; } bool prune_blockchain(uint32_t pruning_seed) const { return true; } diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index c0d31bb8a..b78640dc9 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -544,7 +544,7 @@ public: cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc); size_t pool_size = m_c.get_pool_transactions_count(); - m_c.handle_incoming_tx(t_serializable_object_to_blob(tx), tvc, m_txs_keeped_by_block, false, false); + m_c.handle_incoming_tx({t_serializable_object_to_blob(tx), crypto::null_hash}, tvc, m_txs_keeped_by_block, false, false); bool tx_added = pool_size + 1 == m_c.get_pool_transactions_count(); bool r = m_validator.check_tx_verification_context(tvc, tx_added, m_ev_index, tx); CHECK_AND_NO_ASSERT_MES(r, false, "tx verification context check failed"); @@ -555,12 +555,12 @@ public: { log_event("cryptonote::transaction"); - std::vector<cryptonote::blobdata> tx_blobs; + std::vector<cryptonote::tx_blob_entry> tx_blobs; std::vector<cryptonote::tx_verification_context> tvcs; cryptonote::tx_verification_context tvc0 = AUTO_VAL_INIT(tvc0); for (const auto &tx: txs) { - tx_blobs.push_back(t_serializable_object_to_blob(tx)); + tx_blobs.push_back({t_serializable_object_to_blob(tx)}); tvcs.push_back(tvc0); } size_t pool_size = m_c.get_pool_transactions_count(); @@ -578,7 +578,11 @@ public: cryptonote::block_verification_context bvc = AUTO_VAL_INIT(bvc); cryptonote::blobdata bd = t_serializable_object_to_blob(b); std::vector<cryptonote::block> pblocks; - if (m_c.prepare_handle_incoming_blocks(std::vector<cryptonote::block_complete_entry>(1, {bd, {}}), pblocks)) + cryptonote::block_complete_entry bce; + bce.pruned = false; + bce.block = bd; + bce.txs = {}; + if (m_c.prepare_handle_incoming_blocks(std::vector<cryptonote::block_complete_entry>(1, bce), pblocks)) { m_c.handle_incoming_block(bd, &b, bvc); m_c.cleanup_handle_incoming_blocks(); @@ -608,7 +612,11 @@ public: cryptonote::block_verification_context bvc = AUTO_VAL_INIT(bvc); std::vector<cryptonote::block> pblocks; - if (m_c.prepare_handle_incoming_blocks(std::vector<cryptonote::block_complete_entry>(1, {sr_block.data, {}}), pblocks)) + cryptonote::block_complete_entry bce; + bce.pruned = false; + bce.block = sr_block.data; + bce.txs = {}; + if (m_c.prepare_handle_incoming_blocks(std::vector<cryptonote::block_complete_entry>(1, bce), pblocks)) { m_c.handle_incoming_block(sr_block.data, NULL, bvc); m_c.cleanup_handle_incoming_blocks(); diff --git a/tests/functional_tests/cold_signing.py b/tests/functional_tests/cold_signing.py index f915df77a..698217436 100755 --- a/tests/functional_tests/cold_signing.py +++ b/tests/functional_tests/cold_signing.py @@ -94,7 +94,6 @@ class ColdSigningTest(): print("Creating transaction in hot wallet") dst = {'address': '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'amount': 1000000000000} - payment_id = '1234500000012345abcde00000abcdeff1234500000012345abcde00000abcde' self.hot_wallet.refresh() res = self.hot_wallet.export_outputs() @@ -102,7 +101,7 @@ class ColdSigningTest(): res = self.cold_wallet.export_key_images(True) self.hot_wallet.import_key_images(res.signed_key_images, offset = res.offset) - res = self.hot_wallet.transfer([dst], ring_size = 11, payment_id = payment_id, get_tx_key = False) + res = self.hot_wallet.transfer([dst], ring_size = 11, get_tx_key = False) assert len(res.tx_hash) == 32*2 txid = res.tx_hash assert len(res.tx_key) == 0 @@ -124,7 +123,7 @@ class ColdSigningTest(): assert desc.amount_out == desc.amount_in - fee assert desc.ring_size == 11 assert desc.unlock_time == 0 - assert desc.payment_id == payment_id + assert desc.payment_id in ['', '0000000000000000'] assert desc.change_amount == desc.amount_in - 1000000000000 - fee assert desc.change_address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert desc.fee == fee diff --git a/tests/functional_tests/multisig.py b/tests/functional_tests/multisig.py index e0d8b06a4..e4e908aa1 100755 --- a/tests/functional_tests/multisig.py +++ b/tests/functional_tests/multisig.py @@ -272,7 +272,7 @@ class MultisigTest(): assert desc.amount_out == desc.amount_in - fee assert desc.ring_size == 11 assert desc.unlock_time == 0 - assert desc.payment_id == '0000000000000000' + assert not 'payment_id' in desc or desc.payment_id in ['', '0000000000000000'] assert desc.change_amount == desc.amount_in - 1000000000000 - fee assert desc.change_address == self.wallet_address assert desc.fee == fee diff --git a/tests/functional_tests/transfer.py b/tests/functional_tests/transfer.py index b4264f72d..0c942f48b 100755 --- a/tests/functional_tests/transfer.py +++ b/tests/functional_tests/transfer.py @@ -114,13 +114,19 @@ class TransferTest(): except: ok = True assert ok + print ('Checking long payment IDs are rejected') + ok = False + try: self.wallet[0].transfer([dst], ring_size = 11, payment_id = payment_id, get_tx_key = False, get_tx_hex = True) + except: ok = True + assert ok + print ('Checking empty destination is rejected') ok = False try: self.wallet[0].transfer([], ring_size = 11, get_tx_key = False) except: ok = True assert ok - res = self.wallet[0].transfer([dst], ring_size = 11, payment_id = payment_id, get_tx_key = False, get_tx_hex = True) + res = self.wallet[0].transfer([dst], ring_size = 11, get_tx_key = False, get_tx_hex = True) assert len(res.tx_hash) == 32*2 txid = res.tx_hash assert len(res.tx_key) == 0 @@ -156,7 +162,7 @@ class TransferTest(): assert e.type == 'block' e = res.pending[0] assert e.txid == txid - assert e.payment_id == payment_id + assert e.payment_id in ['', '0000000000000000'] assert e.type == 'pending' assert e.unlock_time == 0 assert e.subaddr_index.major == 0 @@ -189,7 +195,7 @@ class TransferTest(): assert e.type == 'block' e = res.out[0] assert e.txid == txid - assert e.payment_id == payment_id + assert e.payment_id in ['', '0000000000000000'] assert e.type == 'out' assert e.unlock_time == 0 assert e.subaddr_index.major == 0 @@ -205,7 +211,7 @@ class TransferTest(): assert res.transfers[0] == res.transfer t = res.transfer assert t.txid == txid - assert t.payment_id == payment_id + assert t.payment_id in ['', '0000000000000000'] assert t.height == wallet_height - 1 assert t.timestamp > 0 assert t.amount == 0 # to self, so it's just "pay a fee" really @@ -227,7 +233,7 @@ class TransferTest(): print("Creating transfer to another, manual relay") dst = {'address': '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW', 'amount': 1000000000000} - res = self.wallet[0].transfer([dst], ring_size = 11, payment_id = payment_id, get_tx_key = True, do_not_relay = True, get_tx_hex = True) + res = self.wallet[0].transfer([dst], ring_size = 11, get_tx_key = True, do_not_relay = True, get_tx_hex = True) assert len(res.tx_hash) == 32*2 txid = res.tx_hash assert len(res.tx_key) == 32*2 @@ -269,7 +275,7 @@ class TransferTest(): assert not 'failed' in res or len(res.failed) == 0 e = res.pool[0] assert e.txid == txid - assert e.payment_id == payment_id + assert e.payment_id in ["", "0000000000000000"] # long payment IDs are now ignored assert e.type == 'pool' assert e.unlock_time == 0 assert e.subaddr_index.major == 0 @@ -295,7 +301,7 @@ class TransferTest(): assert not 'failed' in res or len(res.failed) == 0 e = res['in'][0] assert e.txid == txid - assert e.payment_id == payment_id + assert e.payment_id in ["", "0000000000000000"] # long payment IDs are now ignored assert e.type == 'in' assert e.unlock_time == 0 assert e.subaddr_index.major == 0 @@ -318,7 +324,7 @@ class TransferTest(): dst0 = {'address': '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'amount': 1000000000000} dst1 = {'address': '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW', 'amount': 1100000000000} dst2 = {'address': '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', 'amount': 1200000000000} - res = self.wallet[0].transfer([dst0, dst1, dst2], ring_size = 11, payment_id = payment_id, get_tx_key = True) + res = self.wallet[0].transfer([dst0, dst1, dst2], ring_size = 11, get_tx_key = True) assert len(res.tx_hash) == 32*2 txid = res.tx_hash assert len(res.tx_key) == 32*2 @@ -357,7 +363,7 @@ class TransferTest(): assert len(e) == 1 e = e[0] assert e.txid == txid - assert e.payment_id == payment_id + assert e.payment_id in ["", "0000000000000000"] # long payment IDs are now ignored assert e.type == 'out' assert e.unlock_time == 0 assert e.subaddr_index.major == 0 @@ -385,7 +391,7 @@ class TransferTest(): assert len(e) == 1 e = e[0] assert e.txid == txid - assert e.payment_id == payment_id + assert e.payment_id in ["", "0000000000000000"] # long payment IDs are now ignored assert e.type == 'in' assert e.unlock_time == 0 assert e.subaddr_index.major == 0 @@ -412,7 +418,7 @@ class TransferTest(): assert len(e) == 1 e = e[0] assert e.txid == txid - assert e.payment_id == payment_id + assert e.payment_id in ["", "0000000000000000"] # long payment IDs are now ignored assert e.type == 'in' assert e.unlock_time == 0 assert e.subaddr_index.major == 0 @@ -521,7 +527,7 @@ class TransferTest(): res = self.wallet[1].get_bulk_payments() assert len(res.payments) >= 3 # two txes to standard address were sent, plus one to integrated address res = self.wallet[1].get_bulk_payments(payment_ids = ['1234500000012345abcde00000abcdeff1234500000012345abcde00000abcde']) - assert len(res.payments) >= 2 # two txes were sent with that payment id + assert not 'payments' in res or len(res.payments) == 0 # long payment IDs are now ignored on receipt res = self.wallet[1].get_bulk_payments(payment_ids = ['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff']) assert 'payments' not in res or len(res.payments) == 0 # none with that payment id res = self.wallet[1].get_bulk_payments(payment_ids = ['1111111122222222' + '0'*48]) @@ -531,7 +537,7 @@ class TransferTest(): res = self.wallet[2].get_bulk_payments() assert len(res.payments) >= 1 # one tx was sent res = self.wallet[2].get_bulk_payments(payment_ids = ['1'*64, '1234500000012345abcde00000abcdeff1234500000012345abcde00000abcde', '2'*64]) - assert len(res.payments) >= 1 # one tx was sent + assert not 'payments' in res or len(res.payments) == 0 # long payment IDs are now ignored res = self.wallet[1].get_bulk_payments(["1111111122222222"]) assert len(res.payments) >= 1 # we have one of these @@ -550,7 +556,7 @@ class TransferTest(): assert 'payments' not in res or len(res.payments) == 0 res = self.wallet[1].get_payments('1234500000012345abcde00000abcdeff1234500000012345abcde00000abcde') - assert len(res.payments) >= 2 + assert 'payments' not in res or len(res.payments) == 0 res = self.wallet[1].get_payments('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff') assert 'payments' not in res or len(res.payments) == 0 diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index cac1fa943..96825f54f 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -30,7 +30,6 @@ set(unit_tests_sources account.cpp apply_permutation.cpp address_from_url.cpp - ban.cpp base58.cpp blockchain_db.cpp block_queue.cpp @@ -68,6 +67,7 @@ set(unit_tests_sources multiexp.cpp multisig.cpp net.cpp + node_server.cpp notify.cpp output_distribution.cpp parse_amount.cpp diff --git a/tests/unit_tests/levin.cpp b/tests/unit_tests/levin.cpp index 3188167f9..e5ca4e41e 100644 --- a/tests/unit_tests/levin.cpp +++ b/tests/unit_tests/levin.cpp @@ -38,6 +38,7 @@ #include "byte_slice.h" #include "crypto/crypto.h" #include "cryptonote_basic/connection_context.h" +#include "cryptonote_core/cryptonote_core.h" #include "cryptonote_protocol/cryptonote_protocol_defs.h" #include "cryptonote_protocol/levin_notify.h" #include "int-util.h" @@ -119,12 +120,13 @@ namespace epee::levin::async_protocol_handler<cryptonote::levin::detail::p2p_context> handler_; public: - test_connection(boost::asio::io_service& io_service, cryptonote::levin::connections& connections, boost::uuids::random_generator& random_generator) - : context_(), - endpoint_(io_service), + test_connection(boost::asio::io_service& io_service, cryptonote::levin::connections& connections, boost::uuids::random_generator& random_generator, const bool is_incoming) + : endpoint_(io_service), + context_(), handler_(std::addressof(endpoint_), connections, context_) { - const_cast<boost::uuids::uuid&>(context_.m_connection_id) = random_generator(); + using base_type = epee::net_utils::connection_context_base; + static_cast<base_type&>(context_) = base_type{random_generator(), {}, is_incoming, false}; handler_.after_init_connection(); } @@ -262,19 +264,19 @@ namespace EXPECT_EQ(0u, receiver_.notified_size()); } - void add_connection() + void add_connection(const bool is_incoming) { - contexts_.emplace_back(io_service_, *connections_, random_generator_); + contexts_.emplace_back(io_service_, *connections_, random_generator_, is_incoming); EXPECT_TRUE(connection_ids_.emplace(contexts_.back().get_id()).second); EXPECT_EQ(connection_ids_.size(), connections_->get_connections_count()); } - cryptonote::levin::notify make_notifier(const std::size_t noise_size) + cryptonote::levin::notify make_notifier(const std::size_t noise_size, bool is_public) { epee::byte_slice noise = nullptr; if (noise_size) noise = epee::levin::make_noise_notify(noise_size); - return cryptonote::levin::notify{io_service_, connections_, std::move(noise)}; + return cryptonote::levin::notify{io_service_, connections_, std::move(noise), is_public}; } boost::uuids::random_generator random_generator_; @@ -437,10 +439,10 @@ TEST_F(levin_notify, defaulted) TEST_F(levin_notify, flood) { - cryptonote::levin::notify notifier = make_notifier(0); + cryptonote::levin::notify notifier = make_notifier(0, true); for (unsigned count = 0; count < 10; ++count) - add_connection(); + add_connection(count % 2 == 0); { const auto status = notifier.get_status(); @@ -500,16 +502,87 @@ TEST_F(levin_notify, flood) } } +TEST_F(levin_notify, private_flood) +{ + cryptonote::levin::notify notifier = make_notifier(0, false); + + for (unsigned count = 0; count < 10; ++count) + add_connection(count % 2 == 0); + + { + const auto status = notifier.get_status(); + EXPECT_FALSE(status.has_noise); + EXPECT_FALSE(status.connections_filled); + } + notifier.new_out_connection(); + io_service_.poll(); + { + const auto status = notifier.get_status(); + EXPECT_FALSE(status.has_noise); + EXPECT_FALSE(status.connections_filled); // not tracked + } + + std::vector<cryptonote::blobdata> txs(2); + txs[0].resize(100, 'e'); + txs[1].resize(200, 'f'); + + ASSERT_EQ(10u, contexts_.size()); + { + auto context = contexts_.begin(); + EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), false)); + + io_service_.reset(); + ASSERT_LT(0u, io_service_.poll()); + EXPECT_EQ(0u, context->process_send_queue()); + for (++context; context != contexts_.end(); ++context) + { + const bool is_incoming = ((context - contexts_.begin()) % 2 == 0); + EXPECT_EQ(is_incoming ? 0u : 1u, context->process_send_queue()); + } + + ASSERT_EQ(5u, receiver_.notified_size()); + for (unsigned count = 0; count < 5; ++count) + { + auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second; + EXPECT_EQ(txs, notification.txs); + EXPECT_TRUE(notification._.empty()); + } + } + + ASSERT_EQ(10u, contexts_.size()); + { + auto context = contexts_.begin(); + EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), true)); + + io_service_.reset(); + ASSERT_LT(0u, io_service_.poll()); + EXPECT_EQ(0u, context->process_send_queue()); + for (++context; context != contexts_.end(); ++context) + { + const bool is_incoming = ((context - contexts_.begin()) % 2 == 0); + EXPECT_EQ(is_incoming ? 0u : 1u, context->process_send_queue()); + } + + ASSERT_EQ(5u, receiver_.notified_size()); + for (unsigned count = 0; count < 5; ++count) + { + auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second; + EXPECT_EQ(txs, notification.txs); + EXPECT_FALSE(notification._.empty()); + } + } +} + TEST_F(levin_notify, noise) { for (unsigned count = 0; count < 10; ++count) - add_connection(); + add_connection(count % 2 == 0); std::vector<cryptonote::blobdata> txs(1); txs[0].resize(1900, 'h'); const boost::uuids::uuid incoming_id = random_generator_(); - cryptonote::levin::notify notifier = make_notifier(2048); + cryptonote::levin::notify notifier = make_notifier(2048, false); { const auto status = notifier.get_status(); diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp index 253280d4d..262541bd2 100644 --- a/tests/unit_tests/net.cpp +++ b/tests/unit_tests/net.cpp @@ -893,7 +893,8 @@ TEST(dandelionpp_map, empty) TEST(dandelionpp_map, zero_stems) { std::vector<boost::uuids::uuid> connections{6}; - std::generate(connections.begin(), connections.end(), boost::uuids::random_generator{}); + for (auto &c: connections) + c = boost::uuids::random_generator{}(); net::dandelionpp::connection_map mapper{connections, 0}; EXPECT_EQ(mapper.begin(), mapper.end()); @@ -917,7 +918,8 @@ TEST(dandelionpp_map, zero_stems) TEST(dandelionpp_map, dropped_connection) { std::vector<boost::uuids::uuid> connections{6}; - std::generate(connections.begin(), connections.end(), boost::uuids::random_generator{}); + for (auto &c: connections) + c = boost::uuids::random_generator{}(); std::sort(connections.begin(), connections.end()); // select 3 of 6 outgoing connections @@ -953,7 +955,8 @@ TEST(dandelionpp_map, dropped_connection) } std::map<boost::uuids::uuid, boost::uuids::uuid> mapping; std::vector<boost::uuids::uuid> in_connections{9}; - std::generate(in_connections.begin(), in_connections.end(), boost::uuids::random_generator{}); + for (auto &c: in_connections) + c = boost::uuids::random_generator{}(); { std::map<boost::uuids::uuid, std::size_t> used; std::multimap<boost::uuids::uuid, boost::uuids::uuid> inverse_mapping; diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/node_server.cpp index b710f9226..2c89323c7 100644 --- a/tests/unit_tests/ban.cpp +++ b/tests/unit_tests/node_server.cpp @@ -56,13 +56,13 @@ public: bool get_stat_info(cryptonote::core_stat_info& st_inf) const {return true;} bool have_block(const crypto::hash& id) const {return true;} void get_blockchain_top(uint64_t& height, crypto::hash& top_id)const{height=0;top_id=crypto::null_hash;} - bool handle_incoming_tx(const cryptonote::blobdata& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; } - bool handle_incoming_txs(const std::vector<cryptonote::blobdata>& tx_blob, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; } + bool handle_incoming_tx(const cryptonote::tx_blob_entry& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; } + bool handle_incoming_txs(const std::vector<cryptonote::tx_blob_entry>& tx_blob, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; } bool handle_incoming_block(const cryptonote::blobdata& block_blob, const cryptonote::block *block, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true) { return true; } void pause_mine(){} void resume_mine(){} bool on_idle(){return true;} - bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp){return true;} + bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, bool clip_pruned, cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp){return true;} bool handle_get_objects(cryptonote::NOTIFY_REQUEST_GET_OBJECTS::request& arg, cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request& rsp, cryptonote::cryptonote_connection_context& context){return true;} cryptonote::blockchain_storage &get_blockchain_storage() { throw std::runtime_error("Called invalid member function: please never call get_blockchain_storage on the TESTING class test_core."); } bool get_test_drop_download() const {return true;} @@ -84,10 +84,12 @@ public: uint64_t get_earliest_ideal_height_for_version(uint8_t version) const { return 0; } cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; } bool fluffy_blocks_enabled() const { return false; } - uint64_t prevalidate_block_hashes(uint64_t height, const std::vector<crypto::hash> &hashes) { return 0; } + uint64_t prevalidate_block_hashes(uint64_t height, const std::vector<crypto::hash> &hashes, const std::vector<uint64_t> &weights) { return 0; } bool pad_transactions() { return false; } uint32_t get_blockchain_pruning_seed() const { return 0; } bool prune_blockchain(uint32_t pruning_seed = 0) { return true; } + bool is_within_compiled_block_hash_area(uint64_t height) const { return false; } + bool has_block_weights(uint64_t height, uint64_t nblocks) const { return false; } void stop() {} }; @@ -258,5 +260,42 @@ TEST(ban, ignores_port) ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS_PORT(1,2,3,4,6))); } +TEST(node_server, bind_same_p2p_port) +{ + const auto new_node = []() -> std::unique_ptr<Server> { + test_core pr_core; + cryptonote::t_cryptonote_protocol_handler<test_core> cprotocol(pr_core, NULL); + std::unique_ptr<Server> server(new Server(cprotocol)); + cprotocol.set_p2p_endpoint(server.get()); + + return server; + }; + + const auto init = [](const std::unique_ptr<Server>& server, const char* port) -> bool { + boost::program_options::options_description desc_options("Command line options"); + cryptonote::core::init_options(desc_options); + Server::init_options(desc_options); + + const char *argv[2] = {nullptr, nullptr}; + boost::program_options::variables_map vm; + boost::program_options::store(boost::program_options::parse_command_line(1, argv, desc_options), vm); + + vm.find(nodetool::arg_p2p_bind_port.name)->second = boost::program_options::variable_value(std::string(port), false); + + boost::program_options::notify(vm); + + return server->init(vm); + }; + + constexpr char port[] = "48080"; + constexpr char port_another[] = "58080"; + + const auto node = new_node(); + EXPECT_TRUE(init(node, port)); + + EXPECT_FALSE(init(new_node(), port)); + EXPECT_TRUE(init(new_node(), port_another)); +} + namespace nodetool { template class node_server<cryptonote::t_cryptonote_protocol_handler<test_core>>; } namespace cryptonote { template class t_cryptonote_protocol_handler<test_core>; } diff --git a/tests/unit_tests/ringdb.cpp b/tests/unit_tests/ringdb.cpp index 626616acc..0838d2bd9 100644 --- a/tests/unit_tests/ringdb.cpp +++ b/tests/unit_tests/ringdb.cpp @@ -65,11 +65,17 @@ static std::pair<uint64_t, uint64_t> generate_output() } -#define KEY_1 []{ static const crypto::chacha_key KEY_1 = generate_chacha_key(); return KEY_1; }() -#define KEY_2 []{ static const crypto::chacha_key KEY_2 = generate_chacha_key(); return KEY_2; }() -#define KEY_IMAGE_1 []{ static const crypto::key_image KEY_IMAGE_1 = generate_key_image(); return KEY_IMAGE_1; }() -#define OUTPUT_1 []{ static const std::pair<uint64_t, uint64_t> OUTPUT_1 = generate_output(); return OUTPUT_1; }() -#define OUTPUT_2 []{ static const std::pair<uint64_t, uint64_t> OUTPUT_2 = generate_output(); return OUTPUT_2; }() +static crypto::chacha_key get_KEY_1() { static const crypto::chacha_key KEY_1 = generate_chacha_key(); return KEY_1; } +static crypto::chacha_key get_KEY_2() { static const crypto::chacha_key KEY_2 = generate_chacha_key(); return KEY_2; } +static crypto::key_image get_KEY_IMAGE_1() { static const crypto::key_image KEY_IMAGE_1 = generate_key_image(); return KEY_IMAGE_1; } +static std::pair<uint64_t, uint64_t> get_OUTPUT_1() { static const std::pair<uint64_t, uint64_t> OUTPUT_1 = generate_output(); return OUTPUT_1; } +static std::pair<uint64_t, uint64_t> get_OUTPUT_2() { static const std::pair<uint64_t, uint64_t> OUTPUT_2 = generate_output(); return OUTPUT_2; } + +#define KEY_1 get_KEY_1() +#define KEY_2 get_KEY_2() +#define KEY_IMAGE_1 get_KEY_IMAGE_1() +#define OUTPUT_1 get_OUTPUT_1() +#define OUTPUT_2 get_OUTPUT_2() class RingDB: public tools::ringdb { |