diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/block_weight/block_weight.cpp | 9 | ||||
-rw-r--r-- | tests/core_tests/chaingen.cpp | 17 | ||||
-rwxr-xr-x | tests/functional_tests/mining.py | 10 | ||||
-rwxr-xr-x | tests/functional_tests/multisig.py | 155 | ||||
-rw-r--r-- | tests/unit_tests/long_term_block_weight.cpp | 11 | ||||
-rw-r--r-- | tests/unit_tests/net.cpp | 103 | ||||
-rw-r--r-- | tests/unit_tests/output_distribution.cpp | 12 | ||||
-rw-r--r-- | tests/unit_tests/scaling_2021.cpp | 7 |
8 files changed, 184 insertions, 140 deletions
diff --git a/tests/block_weight/block_weight.cpp b/tests/block_weight/block_weight.cpp index 7cd0d572b..4b00fc63f 100644 --- a/tests/block_weight/block_weight.cpp +++ b/tests/block_weight/block_weight.cpp @@ -30,8 +30,6 @@ #include <stdio.h> #include <math.h> -#include "cryptonote_core/blockchain.h" -#include "cryptonote_core/tx_pool.h" #include "cryptonote_core/cryptonote_core.h" #include "blockchain_db/testdb.h" @@ -110,9 +108,6 @@ private: } #define PREFIX_WINDOW(hf_version,window) \ - std::unique_ptr<cryptonote::Blockchain> bc; \ - cryptonote::tx_memory_pool txpool(*bc); \ - bc.reset(new cryptonote::Blockchain(txpool)); \ struct get_test_options { \ const std::pair<uint8_t, uint64_t> hard_forks[3]; \ const cryptonote::test_options test_options = { \ @@ -121,7 +116,9 @@ private: }; \ get_test_options(): hard_forks{std::make_pair(1, (uint64_t)0), std::make_pair((uint8_t)hf_version, (uint64_t)LONG_TERM_BLOCK_WEIGHT_WINDOW), std::make_pair((uint8_t)0, (uint64_t)0)} {} \ } opts; \ - cryptonote::Blockchain *blockchain = bc.get(); \ + cryptonote::BlockchainAndPool bap; \ + cryptonote::Blockchain *blockchain = &bap.blockchain; \ + cryptonote::Blockchain *bc = blockchain; \ bool r = blockchain->init(new TestDB(), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL); \ if (!r) \ { \ diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 9f6fe5387..b66aa7924 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -143,9 +143,8 @@ namespace } -static std::unique_ptr<cryptonote::Blockchain> init_blockchain(const std::vector<test_event_entry> & events, cryptonote::network_type nettype) +static std::unique_ptr<cryptonote::BlockchainAndPool> init_blockchain(const std::vector<test_event_entry> & events, cryptonote::network_type nettype) { - std::unique_ptr<cryptonote::Blockchain> bc; v_hardforks_t hardforks; cryptonote::test_options test_options_tmp{nullptr, 0}; const cryptonote::test_options * test_options = &test_options_tmp; @@ -159,10 +158,8 @@ static std::unique_ptr<cryptonote::Blockchain> init_blockchain(const std::vector test_options_tmp.hard_forks = hardforks.data(); test_options = &test_options_tmp; - cryptonote::tx_memory_pool txpool(*bc); - bc.reset(new cryptonote::Blockchain(txpool)); + std::unique_ptr<cryptonote::BlockchainAndPool> bap(new BlockchainAndPool()); - cryptonote::Blockchain *blockchain = bc.get(); auto bdb = new TestDB(); BOOST_FOREACH(const test_event_entry &ev, events) @@ -177,9 +174,9 @@ static std::unique_ptr<cryptonote::Blockchain> init_blockchain(const std::vector bdb->add_block(*blk, 1, 1, 1, 0, 0, blk_hash); } - bool r = blockchain->init(bdb, nettype, true, test_options, 2, nullptr); + bool r = bap->blockchain.init(bdb, nettype, true, test_options, 2, nullptr); CHECK_AND_ASSERT_THROW_MES(r, "could not init blockchain from events"); - return bc; + return bap; } void test_generator::get_block_chain(std::vector<block_info>& blockchain, const crypto::hash& head, size_t n) const @@ -393,7 +390,7 @@ bool test_generator::construct_block_manually_tx(cryptonote::block& blk, const c void test_generator::fill_nonce(cryptonote::block& blk, const difficulty_type& diffic, uint64_t height) { const cryptonote::Blockchain *blockchain = nullptr; - std::unique_ptr<cryptonote::Blockchain> bc; + std::unique_ptr<cryptonote::BlockchainAndPool> bap; if (blk.major_version >= RX_BLOCK_VERSION && diffic > 1) { @@ -403,8 +400,8 @@ void test_generator::fill_nonce(cryptonote::block& blk, const difficulty_type& d } else { - bc = init_blockchain(*m_events, m_nettype); - blockchain = bc.get(); + bap = init_blockchain(*m_events, m_nettype); + blockchain = &bap->blockchain; } } diff --git a/tests/functional_tests/mining.py b/tests/functional_tests/mining.py index e98037811..242c58dbe 100755 --- a/tests/functional_tests/mining.py +++ b/tests/functional_tests/mining.py @@ -36,6 +36,7 @@ import math import monotonic import util_resources import multiprocessing +import string """Test daemon mining RPC calls @@ -52,6 +53,11 @@ Control the behavior with these environment variables: from framework.daemon import Daemon from framework.wallet import Wallet +def assert_non_null_hash(s): + assert len(s) == 64 # correct length + assert all((c in string.hexdigits for c in s)) # is parseable as hex + assert s != ('0' * 64) # isn't null hash + class MiningTest(): def run_test(self): self.reset() @@ -250,6 +256,8 @@ class MiningTest(): block_hash = hashes[i] assert len(block_hash) == 64 res = daemon.submitblock(blocks[i]) + submitted_block_id = res.block_id + assert_non_null_hash(submitted_block_id) res = daemon.get_height() assert res.height == height + i + 1 assert res.hash == block_hash @@ -346,6 +354,8 @@ class MiningTest(): t0 = time.time() for h in range(len(block_hashes)): res = daemon.submitblock(blocks[h]) + submitted_block_id = res.block_id + assert_non_null_hash(submitted_block_id) t0 = time.time() - t0 res = daemon.get_info() assert height == res.height diff --git a/tests/functional_tests/multisig.py b/tests/functional_tests/multisig.py index 0ca438857..7d3513070 100755 --- a/tests/functional_tests/multisig.py +++ b/tests/functional_tests/multisig.py @@ -29,6 +29,7 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from __future__ import print_function +import random """Test multisig transfers """ @@ -36,42 +37,74 @@ from __future__ import print_function from framework.daemon import Daemon from framework.wallet import Wallet +MULTISIG_PUB_ADDRS = [ + '45J58b7PmKJFSiNPFFrTdtfMcFGnruP7V4CMuRpX7NsH4j3jGHKAjo3YJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ3gr7sG', # 2/2 + '44G2TQNfsiURKkvxp7gbgaJY8WynZvANnhmyMAwv6WeEbAvyAWMfKXRhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5duN94i', # 2/3 + '41mro238grj56GnrWkakAKTkBy2yDcXYsUZ2iXCM9pe5Ueajd2RRc6Fhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5ief4ZP', # 3/3 + '44vZSprQKJQRFe6t1VHgU4ESvq2dv7TjBLVGE7QscKxMdFSiyyPCEV64NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6dakeff', # 3/4 + '47puypSwsV1gvUDratmX4y58fSwikXVehEiBhVLxJA1gRCxHyrRgTDr4NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6aRPj5U', # 2/4 + '4A8RnBQixry4VXkqeWhmg8L7vWJVDJj4FN9PV4E7Mgad5ZZ6LKQdn8dYJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ4S8RSB' # 1/2 +] + class MultisigTest(): def run_test(self): self.reset() - self.mine('45J58b7PmKJFSiNPFFrTdtfMcFGnruP7V4CMuRpX7NsH4j3jGHKAjo3YJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ3gr7sG', 5) - self.mine('44G2TQNfsiURKkvxp7gbgaJY8WynZvANnhmyMAwv6WeEbAvyAWMfKXRhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5duN94i', 5) - self.mine('41mro238grj56GnrWkakAKTkBy2yDcXYsUZ2iXCM9pe5Ueajd2RRc6Fhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5ief4ZP', 5) - self.mine('44vZSprQKJQRFe6t1VHgU4ESvq2dv7TjBLVGE7QscKxMdFSiyyPCEV64NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6dakeff', 5) - self.mine('47puypSwsV1gvUDratmX4y58fSwikXVehEiBhVLxJA1gRCxHyrRgTDr4NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6aRPj5U', 5) + for pub_addr in MULTISIG_PUB_ADDRS: + self.mine(pub_addr, 4) self.mine('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80) self.test_states() + self.fund_addrs_with_normal_wallet(MULTISIG_PUB_ADDRS) + self.create_multisig_wallets(2, 2, '45J58b7PmKJFSiNPFFrTdtfMcFGnruP7V4CMuRpX7NsH4j3jGHKAjo3YJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ3gr7sG') self.import_multisig_info([1, 0], 5) txid = self.transfer([1, 0]) self.import_multisig_info([0, 1], 6) self.check_transaction(txid) + self.remake_some_multisig_wallets_by_multsig_seed(2) + self.import_multisig_info([0, 1], 6) # six outputs, same as before + txid = self.transfer([0, 1]) + self.import_multisig_info([0, 1], 7) # seven outputs b/c we're dest plus change + self.check_transaction(txid) + self.create_multisig_wallets(2, 3, '44G2TQNfsiURKkvxp7gbgaJY8WynZvANnhmyMAwv6WeEbAvyAWMfKXRhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5duN94i') self.import_multisig_info([0, 2], 5) txid = self.transfer([0, 2]) self.import_multisig_info([0, 1, 2], 6) self.check_transaction(txid) + self.remake_some_multisig_wallets_by_multsig_seed(2) + self.import_multisig_info([0, 2], 6) # six outputs, same as before + txid = self.transfer([0, 2]) + self.import_multisig_info([0, 1, 2], 7) # seven outputs b/c we're dest plus change + self.check_transaction(txid) + self.create_multisig_wallets(3, 3, '41mro238grj56GnrWkakAKTkBy2yDcXYsUZ2iXCM9pe5Ueajd2RRc6Fhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5ief4ZP') self.import_multisig_info([2, 0, 1], 5) txid = self.transfer([2, 1, 0]) self.import_multisig_info([0, 2, 1], 6) self.check_transaction(txid) + self.remake_some_multisig_wallets_by_multsig_seed(3) + self.import_multisig_info([2, 0, 1], 6) # six outputs, same as before + txid = self.transfer([2, 1, 0]) + self.import_multisig_info([0, 2, 1], 7) # seven outputs b/c we're dest plus change + self.check_transaction(txid) + self.create_multisig_wallets(3, 4, '44vZSprQKJQRFe6t1VHgU4ESvq2dv7TjBLVGE7QscKxMdFSiyyPCEV64NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6dakeff') self.import_multisig_info([0, 2, 3], 5) txid = self.transfer([0, 2, 3]) self.import_multisig_info([0, 1, 2, 3], 6) self.check_transaction(txid) + self.remake_some_multisig_wallets_by_multsig_seed(3) + self.import_multisig_info([0, 2, 3], 6) # six outputs, same as before + txid = self.transfer([0, 2, 3]) + self.import_multisig_info([0, 1, 2, 3], 7) # seven outputs b/c we're dest plus change + self.check_transaction(txid) + self.create_multisig_wallets(2, 4, '47puypSwsV1gvUDratmX4y58fSwikXVehEiBhVLxJA1gRCxHyrRgTDr4NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6aRPj5U') self.import_multisig_info([1, 2], 5) txid = self.transfer([1, 2]) @@ -81,6 +114,24 @@ class MultisigTest(): self.import_multisig_info([0, 1, 2, 3], 7) self.check_transaction(txid) + self.remake_some_multisig_wallets_by_multsig_seed(2) + self.import_multisig_info([0, 1, 2, 3], 6) # six outputs, same as before + txid = self.transfer([2, 3]) + self.import_multisig_info([0, 1, 2, 3], 7) # seven outputs b/c we're dest plus change + self.check_transaction(txid) + + self.create_multisig_wallets(1, 2, '4A8RnBQixry4VXkqeWhmg8L7vWJVDJj4FN9PV4E7Mgad5ZZ6LKQdn8dYJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ4S8RSB') + self.import_multisig_info([0, 1], 5) + txid = self.transfer([0]) + self.import_multisig_info([0, 1], 6) + self.check_transaction(txid) + + self.remake_some_multisig_wallets_by_multsig_seed(1) + self.import_multisig_info([0, 1], 6) # six outputs, same as before + txid = self.transfer([1]) + self.import_multisig_info([0, 1], 7) # seven outputs b/c we're dest plus change + self.check_transaction(txid) + def reset(self): print('Resetting blockchain') daemon = Daemon() @@ -93,6 +144,11 @@ class MultisigTest(): daemon = Daemon() daemon.generateblocks(address, blocks) + # This method sets up N_total wallets with a threshold of M_threshold doing the following steps: + # * restore_deterministic_wallet(w/ hardcoded seeds) + # * prepare_multisig(enable_multisig_experimental = True) + # * make_multisig() + # * exchange_multisig_keys() def create_multisig_wallets(self, M_threshold, N_total, expected_address): print('Creating ' + str(M_threshold) + '/' + str(N_total) + ' multisig wallet') seeds = [ @@ -103,6 +159,8 @@ class MultisigTest(): ] assert M_threshold <= N_total assert N_total <= len(seeds) + + # restore_deterministic_wallet() & prepare_multisig() self.wallet = [None] * N_total info = [] for i in range(N_total): @@ -114,10 +172,12 @@ class MultisigTest(): assert len(res.multisig_info) > 0 info.append(res.multisig_info) + # Assert that all wallets are multisig for i in range(N_total): res = self.wallet[i].is_multisig() assert res.multisig == False + # make_multisig() with each other's info addresses = [] next_stage = [] for i in range(N_total): @@ -125,6 +185,7 @@ class MultisigTest(): addresses.append(res.address) next_stage.append(res.multisig_info) + # Assert multisig paramaters M/N for each wallet for i in range(N_total): res = self.wallet[i].is_multisig() assert res.multisig == True @@ -132,13 +193,15 @@ class MultisigTest(): assert res.threshold == M_threshold assert res.total == N_total - while True: + # exchange_multisig_keys() + num_exchange_multisig_keys_stages = 0 + while True: # while not all wallets are ready n_ready = 0 for i in range(N_total): res = self.wallet[i].is_multisig() if res.ready == True: n_ready += 1 - assert n_ready == 0 or n_ready == N_total + assert n_ready == 0 or n_ready == N_total # No partial readiness if n_ready == N_total: break info = next_stage @@ -148,10 +211,17 @@ class MultisigTest(): res = self.wallet[i].exchange_multisig_keys(info) next_stage.append(res.multisig_info) addresses.append(res.address) + num_exchange_multisig_keys_stages += 1 + + # We should only need N - M + 1 key exchange rounds + assert num_exchange_multisig_keys_stages == N_total - M_threshold + 1 + + # Assert that the all wallets have expected public address for i in range(N_total): - assert addresses[i] == expected_address + assert addresses[i] == expected_address, addresses[i] self.wallet_address = expected_address + # Assert multisig paramaters M/N and "ready" for each wallet for i in range(N_total): res = self.wallet[i].is_multisig() assert res.multisig == True @@ -159,6 +229,73 @@ class MultisigTest(): assert res.threshold == M_threshold assert res.total == N_total + # We want to test if multisig wallets can receive normal transfers as well and mining transfers + def fund_addrs_with_normal_wallet(self, addrs): + print("Funding multisig wallets with normal wallet-to-wallet transfers") + + # Generate normal deterministic wallet + normal_seed = 'velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted' + assert not hasattr(self, 'wallet') or not self.wallet + self.wallet = [Wallet(idx = 0)] + res = self.wallet[0].restore_deterministic_wallet(seed = normal_seed) + assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' + + self.wallet[0].refresh() + + # Check that we own enough spendable enotes + res = self.wallet[0].incoming_transfers(transfer_type = 'available') + assert 'transfers' in res + num_outs_spendable = 0 + min_out_amount = None + for t in res.transfers: + if not t.spent: + num_outs_spendable += 1 + min_out_amount = min(min_out_amount, t.amount) if min_out_amount is not None else t.amount + assert num_outs_spendable >= 2 * len(addrs) + + # Transfer to addrs and mine to confirm tx + dsts = [{'address': addr, 'amount': int(min_out_amount * 0.95)} for addr in addrs] + res = self.wallet[0].transfer(dsts, get_tx_metadata = True) + tx_hex = res.tx_metadata + res = self.wallet[0].relay_tx(tx_hex) + self.mine('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 10) + + def remake_some_multisig_wallets_by_multsig_seed(self, threshold): + N = len(self.wallet) + signers_to_remake = set() + num_signers_to_remake = random.randint(1, N) # Do at least one + while len(signers_to_remake) < num_signers_to_remake: + signers_to_remake.add(random.randint(0, N - 1)) + + for i in signers_to_remake: + print("Remaking {}/{} multsig wallet from multisig seed: #{}".format(threshold, N, i+1)) + + otherwise_unused_seed = \ + 'factual wiggle awakened maul sash biscuit pause reinvest fonts sleepless knowledge tossed jewels request gusts dagger gumball onward dotted amended powder cynical strained topic request' + + # Get information about wallet, will compare against later + old_viewkey = self.wallet[i].query_key('view_key').key + old_spendkey = self.wallet[i].query_key('spend_key').key + old_multisig_seed = self.wallet[i].query_key('mnemonic').key + + # Close old wallet and restore w/ random seed so we know that restoring actually did something + self.wallet[i].close_wallet() + self.wallet[i].restore_deterministic_wallet(seed=otherwise_unused_seed) + mid_viewkey = self.wallet[i].query_key('view_key').key + assert mid_viewkey != old_viewkey + + # Now restore w/ old multisig seed and check against original + self.wallet[i].close_wallet() + self.wallet[i].restore_deterministic_wallet(seed=old_multisig_seed, enable_multisig_experimental=True) + new_viewkey = self.wallet[i].query_key('view_key').key + new_spendkey = self.wallet[i].query_key('spend_key').key + new_multisig_seed = self.wallet[i].query_key('mnemonic').key + assert new_viewkey == old_viewkey + assert new_spendkey == old_spendkey + assert new_multisig_seed == old_multisig_seed + + self.wallet[i].refresh() + def test_states(self): print('Testing multisig states') seeds = [ @@ -251,7 +388,7 @@ class MultisigTest(): assert res.n_outputs == expected_outputs def transfer(self, signers): - assert len(signers) >= 2 + assert len(signers) >= 1 daemon = Daemon() diff --git a/tests/unit_tests/long_term_block_weight.cpp b/tests/unit_tests/long_term_block_weight.cpp index b9ce2b247..e52bd1955 100644 --- a/tests/unit_tests/long_term_block_weight.cpp +++ b/tests/unit_tests/long_term_block_weight.cpp @@ -106,16 +106,9 @@ static uint32_t lcg() } -struct BlockchainAndPool -{ - cryptonote::tx_memory_pool txpool; - cryptonote::Blockchain bc; - BlockchainAndPool(): txpool(bc), bc(txpool) {} -}; - #define PREFIX_WINDOW(hf_version,window) \ - BlockchainAndPool bap; \ - cryptonote::Blockchain *bc = &bap.bc; \ + cryptonote::BlockchainAndPool bap; \ + cryptonote::Blockchain *bc = &bap.blockchain; \ struct get_test_options { \ const std::pair<uint8_t, uint64_t> hard_forks[3]; \ const cryptonote::test_options test_options = { \ diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp index 03072b283..b9555b213 100644 --- a/tests/unit_tests/net.cpp +++ b/tests/unit_tests/net.cpp @@ -74,6 +74,8 @@ namespace "xmrto2bturnore26.onion"; static constexpr const char v3_onion[] = "vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd.onion"; + static constexpr const char v3_onion_2[] = + "zpv4fa3szgel7vf6jdjeugizdclq2vzkelscs2bhbgnlldzzggcen3ad.onion"; } TEST(tor_address, constants) @@ -94,12 +96,10 @@ TEST(tor_address, invalid) EXPECT_TRUE(net::tor_address::make(":").has_error()); EXPECT_TRUE(net::tor_address::make(".onion").has_error()); EXPECT_TRUE(net::tor_address::make(".onion:").has_error()); - EXPECT_TRUE(net::tor_address::make(v2_onion + 1).has_error()); EXPECT_TRUE(net::tor_address::make(v3_onion + 1).has_error()); - EXPECT_TRUE(net::tor_address::make(boost::string_ref{v2_onion, sizeof(v2_onion) - 2}).has_error()); EXPECT_TRUE(net::tor_address::make(boost::string_ref{v3_onion, sizeof(v3_onion) - 2}).has_error()); - EXPECT_TRUE(net::tor_address::make(std::string{v2_onion} + ":-").has_error()); - EXPECT_TRUE(net::tor_address::make(std::string{v2_onion} + ":900a").has_error()); + EXPECT_TRUE(net::tor_address::make(std::string{v3_onion} + ":-").has_error()); + EXPECT_TRUE(net::tor_address::make(std::string{v3_onion} + ":900a").has_error()); EXPECT_TRUE(net::tor_address::make(std::string{v3_onion} + ":65536").has_error()); EXPECT_TRUE(net::tor_address::make(std::string{v3_onion} + ":-1").has_error()); @@ -163,11 +163,11 @@ TEST(tor_address, valid) EXPECT_FALSE(address2.less(*address1)); EXPECT_FALSE(address1->less(address2)); - address2 = MONERO_UNWRAP(net::tor_address::make(std::string{v2_onion} + ":6545")); + address2 = MONERO_UNWRAP(net::tor_address::make(std::string{v3_onion_2} + ":6545")); EXPECT_EQ(6545, address2.port()); - EXPECT_STREQ(v2_onion, address2.host_str()); - EXPECT_EQ(std::string{v2_onion} + ":6545", address2.str().c_str()); + EXPECT_STREQ(v3_onion_2, address2.host_str()); + EXPECT_EQ(std::string{v3_onion_2} + ":6545", address2.str().c_str()); EXPECT_TRUE(address2.is_blockable()); EXPECT_FALSE(address2.equal(*address1)); EXPECT_FALSE(address1->equal(address2)); @@ -244,57 +244,6 @@ namespace }; } -TEST(tor_address, epee_serializev_v2) -{ - epee::byte_slice buffer{}; - { - test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v2_onion, 10))}; - EXPECT_FALSE(command.tor.is_unknown()); - EXPECT_NE(net::tor_address{}, command.tor); - EXPECT_STREQ(v2_onion, command.tor.host_str()); - EXPECT_EQ(10u, command.tor.port()); - - epee::serialization::portable_storage stg{}; - EXPECT_TRUE(command.store(stg)); - EXPECT_TRUE(stg.store_to_binary(buffer)); - } - - test_command_tor command{}; - { - EXPECT_TRUE(command.tor.is_unknown()); - EXPECT_EQ(net::tor_address{}, command.tor); - EXPECT_STREQ(net::tor_address::unknown_str(), command.tor.host_str()); - EXPECT_EQ(0u, command.tor.port()); - - epee::serialization::portable_storage stg{}; - EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer))); - EXPECT_TRUE(command.load(stg)); - } - EXPECT_FALSE(command.tor.is_unknown()); - EXPECT_NE(net::tor_address{}, command.tor); - EXPECT_STREQ(v2_onion, command.tor.host_str()); - EXPECT_EQ(10u, command.tor.port()); - - // make sure that exceeding max buffer doesn't destroy tor_address::_load - { - epee::serialization::portable_storage stg{}; - stg.load_from_binary(epee::to_span(buffer)); - - std::string host{}; - ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false))); - EXPECT_EQ(std::strlen(v2_onion), host.size()); - - host.push_back('k'); - EXPECT_TRUE(stg.set_value("host", std::move(host), stg.open_section("tor", nullptr, false))); - EXPECT_TRUE(command.load(stg)); // poor error reporting from `KV_SERIALIZE` - } - - EXPECT_TRUE(command.tor.is_unknown()); - EXPECT_EQ(net::tor_address{}, command.tor); - EXPECT_STREQ(net::tor_address::unknown_str(), command.tor.host_str()); - EXPECT_EQ(0u, command.tor.port()); -} - TEST(tor_address, epee_serializev_v3) { epee::byte_slice buffer{}; @@ -397,41 +346,6 @@ TEST(tor_address, epee_serialize_unknown) EXPECT_EQ(0u, command.tor.port()); } -TEST(tor_address, boost_serialize_v2) -{ - std::string buffer{}; - { - const net::tor_address tor = MONERO_UNWRAP(net::tor_address::make(v2_onion, 10)); - EXPECT_FALSE(tor.is_unknown()); - EXPECT_NE(net::tor_address{}, tor); - EXPECT_STREQ(v2_onion, tor.host_str()); - EXPECT_EQ(10u, tor.port()); - - std::ostringstream stream{}; - { - boost::archive::portable_binary_oarchive archive{stream}; - archive << tor; - } - buffer = stream.str(); - } - - net::tor_address tor{}; - { - EXPECT_TRUE(tor.is_unknown()); - EXPECT_EQ(net::tor_address{}, tor); - EXPECT_STREQ(net::tor_address::unknown_str(), tor.host_str()); - EXPECT_EQ(0u, tor.port()); - - std::istringstream stream{buffer}; - boost::archive::portable_binary_iarchive archive{stream}; - archive >> tor; - } - EXPECT_FALSE(tor.is_unknown()); - EXPECT_NE(net::tor_address{}, tor); - EXPECT_STREQ(v2_onion, tor.host_str()); - EXPECT_EQ(10u, tor.port()); -} - TEST(tor_address, boost_serialize_v3) { std::string buffer{}; @@ -511,6 +425,9 @@ TEST(get_network_address, onion) address = net::get_network_address(".onion", 0); EXPECT_EQ(net::error::invalid_tor_address, address); + address = net::get_network_address(v2_onion, 1000); + EXPECT_EQ(net::error::invalid_tor_address, address); + address = net::get_network_address(v3_onion, 1000); ASSERT_TRUE(bool(address)); EXPECT_EQ(epee::net_utils::address_type::tor, address->get_type_id()); diff --git a/tests/unit_tests/output_distribution.cpp b/tests/unit_tests/output_distribution.cpp index ab474a7d8..038c19874 100644 --- a/tests/unit_tests/output_distribution.cpp +++ b/tests/unit_tests/output_distribution.cpp @@ -30,10 +30,7 @@ #include "gtest/gtest.h" #include "misc_log_ex.h" #include "rpc/rpc_handler.h" -#include "blockchain_db/blockchain_db.h" #include "cryptonote_core/cryptonote_core.h" -#include "cryptonote_core/tx_pool.h" -#include "cryptonote_core/blockchain.h" #include "blockchain_db/testdb.h" static const uint64_t test_distribution[32] = { @@ -77,9 +74,6 @@ public: bool get_output_distribution(uint64_t amount, uint64_t from, uint64_t to, uint64_t &start_height, std::vector<uint64_t> &distribution, uint64_t &base) { - std::unique_ptr<cryptonote::Blockchain> bc; - cryptonote::tx_memory_pool txpool(*bc); - bc.reset(new cryptonote::Blockchain(txpool)); struct get_test_options { const std::pair<uint8_t, uint64_t> hard_forks[2]; const cryptonote::test_options test_options = { @@ -87,9 +81,9 @@ bool get_output_distribution(uint64_t amount, uint64_t from, uint64_t to, uint64 }; get_test_options():hard_forks{std::make_pair((uint8_t)1, (uint64_t)0), std::make_pair((uint8_t)0, (uint64_t)0)}{} } opts; - cryptonote::Blockchain *blockchain = bc.get(); - bool r = blockchain->init(new TestDB(test_distribution_size), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL); - return r && bc->get_output_distribution(amount, from, to, start_height, distribution, base); + cryptonote::BlockchainAndPool bap; + bool r = bap.blockchain.init(new TestDB(test_distribution_size), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL); + return r && bap.blockchain.get_output_distribution(amount, from, to, start_height, distribution, base); } crypto::hash get_block_hash(uint64_t height) diff --git a/tests/unit_tests/scaling_2021.cpp b/tests/unit_tests/scaling_2021.cpp index 024a4b4fd..d90f0f9e6 100644 --- a/tests/unit_tests/scaling_2021.cpp +++ b/tests/unit_tests/scaling_2021.cpp @@ -50,9 +50,6 @@ public: } #define PREFIX_WINDOW(hf_version,window) \ - std::unique_ptr<cryptonote::Blockchain> bc; \ - cryptonote::tx_memory_pool txpool(*bc); \ - bc.reset(new cryptonote::Blockchain(txpool)); \ struct get_test_options { \ const std::pair<uint8_t, uint64_t> hard_forks[3]; \ const cryptonote::test_options test_options = { \ @@ -61,7 +58,9 @@ public: }; \ get_test_options(): hard_forks{std::make_pair(1, (uint64_t)0), std::make_pair((uint8_t)hf_version, (uint64_t)1), std::make_pair((uint8_t)0, (uint64_t)0)} {} \ } opts; \ - cryptonote::Blockchain *blockchain = bc.get(); \ + cryptonote::BlockchainAndPool bap; \ + cryptonote::Blockchain *blockchain = &bap.blockchain; \ + cryptonote::Blockchain *bc = blockchain; \ bool r = blockchain->init(new TestDB(), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL); \ ASSERT_TRUE(r) |