aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/functional_tests/functional_tests_rpc.py14
-rwxr-xr-xtests/functional_tests/transfer.py52
-rwxr-xr-xtests/functional_tests/txpool.py24
-rw-r--r--tests/performance_tests/crypto_ops.h2
-rw-r--r--tests/performance_tests/main.cpp1
-rw-r--r--tests/trezor/daemon.cpp4
-rw-r--r--tests/trezor/daemon.h2
-rw-r--r--tests/trezor/trezor_tests.cpp88
-rw-r--r--tests/trezor/trezor_tests.h6
-rw-r--r--tests/unit_tests/epee_utils.cpp256
-rw-r--r--tests/unit_tests/json_serialization.cpp8
-rw-r--r--tests/unit_tests/levin.cpp4
-rw-r--r--tests/unit_tests/net.cpp39
-rw-r--r--tests/unit_tests/ringct.cpp8
14 files changed, 381 insertions, 127 deletions
diff --git a/tests/functional_tests/functional_tests_rpc.py b/tests/functional_tests/functional_tests_rpc.py
index 42d14e91a..5f2a3d077 100755
--- a/tests/functional_tests/functional_tests_rpc.py
+++ b/tests/functional_tests/functional_tests_rpc.py
@@ -34,8 +34,8 @@ try:
except:
tests = DEFAULT_TESTS
-N_MONERODS = 3
-N_WALLETS = 7
+N_MONERODS = 2
+N_WALLETS = 4
WALLET_DIRECTORY = builddir + "/functional-tests-directory"
DIFFICULTY = 10
@@ -43,17 +43,9 @@ monerod_base = [builddir + "/bin/monerod", "--regtest", "--fixed-difficulty", st
monerod_extra = [
[],
["--rpc-payment-address", "44SKxxLQw929wRF6BA9paQ1EWFshNnKhXM3qz6Mo3JGDE2YG3xyzVutMStEicxbQGRfrYvAAYxH6Fe8rnD56EaNwUiqhcwR", "--rpc-payment-difficulty", str(DIFFICULTY), "--rpc-payment-credits", "5000", "--data-dir", builddir + "/functional-tests-directory/monerod1"],
- ["--rpc-restricted-bind-port", "18482", "--data-dir", builddir + "/functional-tests-directory/monerod2"]
]
-wallet_base = [builddir + "/bin/monero-wallet-rpc", "--wallet-dir", WALLET_DIRECTORY, "--rpc-bind-port", "wallet_port", "--disable-rpc-login", "--rpc-ssl", "disabled", "--daemon-ssl", "disabled", "--log-level", "1"]
+wallet_base = [builddir + "/bin/monero-wallet-rpc", "--wallet-dir", WALLET_DIRECTORY, "--rpc-bind-port", "wallet_port", "--disable-rpc-login", "--rpc-ssl", "disabled", "--daemon-ssl", "disabled", "--daemon-port", "18180", "--log-level", "1"]
wallet_extra = [
- ["--daemon-port", "18180"],
- ["--daemon-port", "18180"],
- ["--daemon-port", "18180"],
- ["--daemon-port", "18180"],
- ["--daemon-port", "18182"],
- ["--daemon-port", "18182"],
- ["--daemon-port", "18182"]
]
command_lines = []
diff --git a/tests/functional_tests/transfer.py b/tests/functional_tests/transfer.py
index f7a39fa0c..c3d71aa9c 100755
--- a/tests/functional_tests/transfer.py
+++ b/tests/functional_tests/transfer.py
@@ -55,7 +55,7 @@ class TransferTest():
def reset(self):
print('Resetting blockchain')
- daemon = Daemon(idx = 2)
+ daemon = Daemon()
res = daemon.get_height()
daemon.pop_blocks(res.height - 1)
daemon.flush_txpool()
@@ -69,7 +69,7 @@ class TransferTest():
]
self.wallet = [None] * len(seeds)
for i in range(len(seeds)):
- self.wallet[i] = Wallet(idx = i + 4)
+ self.wallet[i] = Wallet(idx = i)
# close the wallet if any, will throw if none is loaded
try: self.wallet[i].close_wallet()
except: pass
@@ -77,7 +77,7 @@ class TransferTest():
def mine(self):
print("Mining some blocks")
- daemon = Daemon(idx = 2)
+ daemon = Daemon()
res = daemon.get_info()
height = res.height
@@ -89,7 +89,7 @@ class TransferTest():
assert res.height == height + 80
def transfer(self):
- daemon = Daemon(idx = 2)
+ daemon = Daemon()
print("Creating transfer to self")
@@ -508,7 +508,7 @@ class TransferTest():
def check_get_bulk_payments(self):
print('Checking get_bulk_payments')
- daemon = Daemon(idx = 2)
+ daemon = Daemon()
res = daemon.get_info()
height = res.height
@@ -544,7 +544,7 @@ class TransferTest():
def check_get_payments(self):
print('Checking get_payments')
- daemon = Daemon(idx = 2)
+ daemon = Daemon()
res = daemon.get_info()
height = res.height
@@ -587,8 +587,7 @@ class TransferTest():
assert len(res.tx_blob_list) == 1
txes[i][1] = res.tx_blob_list[0]
- daemon = Daemon(idx = 2)
- restricted_daemon = Daemon(idx = 2, restricted_rpc = True)
+ daemon = Daemon()
res = daemon.send_raw_transaction(txes[0][1])
assert res.not_relayed == False
assert res.low_mixin == False
@@ -599,18 +598,6 @@ class TransferTest():
assert res.overspend == False
assert res.fee_too_low == False
- res = restricted_daemon.send_raw_transaction(txes[0][1])
- assert res.not_relayed == False
- assert res.low_mixin == False
- assert res.double_spend == False
- assert res.invalid_input == False
- assert res.invalid_output == False
- assert res.too_big == False
- assert res.overspend == False
- assert res.fee_too_low == False
-
- res = restricted_daemon.get_transactions([txes[0][0]])
- assert not 'txs' in res or len(res.txs) == 0
res = daemon.get_transactions([txes[0][0]])
assert len(res.txs) >= 1
tx = [tx for tx in res.txs if tx.tx_hash == txes[0][0]][0]
@@ -628,19 +615,6 @@ class TransferTest():
assert res.fee_too_low == False
assert res.too_few_outputs == False
- res = restricted_daemon.send_raw_transaction(txes[1][1])
- assert res.not_relayed == False
- assert res.low_mixin == False
- assert res.double_spend == True
- assert res.invalid_input == False
- assert res.invalid_output == False
- assert res.too_big == False
- assert res.overspend == False
- assert res.fee_too_low == False
- assert res.too_few_outputs == False
-
- res = restricted_daemon.get_transactions([txes[0][0]])
- assert not 'txs' in res or len(res.txs) == 0
res = daemon.get_transactions([txes[0][0]])
assert len(res.txs) >= 1
tx = [tx for tx in res.txs if tx.tx_hash == txes[0][0]][0]
@@ -649,13 +623,13 @@ class TransferTest():
def sweep_dust(self):
print("Sweeping dust")
- daemon = Daemon(idx = 2)
+ daemon = Daemon()
self.wallet[0].refresh()
res = self.wallet[0].sweep_dust()
assert not 'tx_hash_list' in res or len(res.tx_hash_list) == 0 # there's just one, but it cannot meet the fee
def sweep_single(self):
- daemon = Daemon(idx = 2)
+ daemon = Daemon()
print("Sending single output")
@@ -711,7 +685,7 @@ class TransferTest():
assert len([t for t in res.transfers if t.key_image == ki]) == 1
def check_destinations(self):
- daemon = Daemon(idx = 2)
+ daemon = Daemon()
print("Checking transaction destinations")
@@ -767,7 +741,7 @@ class TransferTest():
self.wallet[0].refresh()
def check_tx_notes(self):
- daemon = Daemon(idx = 2)
+ daemon = Daemon()
print('Testing tx notes')
res = self.wallet[0].get_transfers()
@@ -784,7 +758,7 @@ class TransferTest():
assert res.notes == ['out txid', 'in txid']
def check_rescan(self):
- daemon = Daemon(idx = 2)
+ daemon = Daemon()
print('Testing rescan_spent')
res = self.wallet[0].incoming_transfers(transfer_type = 'all')
@@ -824,7 +798,7 @@ class TransferTest():
assert sorted(old_t_out, key = lambda k: k['txid']) == sorted(new_t_out, key = lambda k: k['txid'])
def check_is_key_image_spent(self):
- daemon = Daemon(idx = 2)
+ daemon = Daemon()
print('Testing is_key_image_spent')
res = self.wallet[0].incoming_transfers(transfer_type = 'all')
diff --git a/tests/functional_tests/txpool.py b/tests/functional_tests/txpool.py
index 2d7f69f3c..27ae89764 100755
--- a/tests/functional_tests/txpool.py
+++ b/tests/functional_tests/txpool.py
@@ -45,14 +45,14 @@ class TransferTest():
def reset(self):
print('Resetting blockchain')
- daemon = Daemon(idx=2)
+ daemon = Daemon()
res = daemon.get_height()
daemon.pop_blocks(res.height - 1)
daemon.flush_txpool()
def create(self):
print('Creating wallet')
- wallet = Wallet(idx = 4)
+ wallet = Wallet()
# close the wallet if any, will throw if none is loaded
try: wallet.close_wallet()
except: pass
@@ -61,8 +61,8 @@ class TransferTest():
def mine(self):
print("Mining some blocks")
- daemon = Daemon(idx = 2)
- wallet = Wallet(idx = 4)
+ daemon = Daemon()
+ wallet = Wallet()
daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80)
wallet.refresh()
@@ -70,8 +70,8 @@ class TransferTest():
def create_txes(self, address, ntxes):
print('Creating ' + str(ntxes) + ' transactions')
- daemon = Daemon(idx = 2)
- wallet = Wallet(idx = 4)
+ daemon = Daemon()
+ wallet = Wallet()
dst = {'address': address, 'amount': 1000000000000}
@@ -83,10 +83,8 @@ class TransferTest():
return txes
def check_empty_pool(self):
- self.check_empty_rpc_pool(Daemon(idx = 2))
- self.check_empty_rpc_pool(Daemon(idx = 2, restricted_rpc = True))
+ daemon = Daemon()
- def check_empty_rpc_pool(self, daemon):
res = daemon.get_transaction_pool_hashes()
assert not 'tx_hashes' in res or len(res.tx_hashes) == 0
res = daemon.get_transaction_pool_stats()
@@ -105,9 +103,8 @@ class TransferTest():
assert res.pool_stats.num_double_spends == 0
def check_txpool(self):
- daemon = Daemon(idx = 2)
- restricted_daemon = Daemon(idx = 2, restricted_rpc = True)
- wallet = Wallet(idx = 4)
+ daemon = Daemon()
+ wallet = Wallet()
res = daemon.get_info()
height = res.height
@@ -120,7 +117,6 @@ class TransferTest():
res = daemon.get_info()
assert res.tx_pool_size == txpool_size + 5
txpool_size = res.tx_pool_size
- self.check_empty_rpc_pool(restricted_daemon)
res = daemon.get_transaction_pool()
assert len(res.transactions) == txpool_size
@@ -164,7 +160,6 @@ class TransferTest():
print('Flushing 2 transactions')
txes_keys = list(txes.keys())
daemon.flush_txpool([txes_keys[1], txes_keys[3]])
- self.check_empty_rpc_pool(restricted_daemon)
res = daemon.get_transaction_pool()
assert len(res.transactions) == txpool_size - 2
assert len([x for x in res.transactions if x.id_hash == txes_keys[1]]) == 0
@@ -215,7 +210,6 @@ class TransferTest():
print('Flushing unknown transactions')
unknown_txids = ['1'*64, '2'*64, '3'*64]
daemon.flush_txpool(unknown_txids)
- self.check_empty_rpc_pool(restricted_daemon)
res = daemon.get_transaction_pool()
assert len(res.transactions) == txpool_size - 2
diff --git a/tests/performance_tests/crypto_ops.h b/tests/performance_tests/crypto_ops.h
index 5b215cef4..2859873ef 100644
--- a/tests/performance_tests/crypto_ops.h
+++ b/tests/performance_tests/crypto_ops.h
@@ -48,6 +48,7 @@ enum test_op
op_scalarmultKey,
op_scalarmultH,
op_scalarmult8,
+ op_scalarmult8_p3,
op_ge_dsm_precomp,
op_ge_double_scalarmult_base_vartime,
op_ge_double_scalarmult_precomp_vartime,
@@ -105,6 +106,7 @@ public:
case op_scalarmultKey: rct::scalarmultKey(point0, scalar0); break;
case op_scalarmultH: rct::scalarmultH(scalar0); break;
case op_scalarmult8: rct::scalarmult8(point0); break;
+ case op_scalarmult8_p3: rct::scalarmult8(p3_0,point0); break;
case op_ge_dsm_precomp: ge_dsm_precomp(dsmp, &p3_0); break;
case op_ge_double_scalarmult_base_vartime: ge_double_scalarmult_base_vartime(&tmp_p2, scalar0.bytes, &p3_0, scalar1.bytes); break;
case op_ge_double_scalarmult_precomp_vartime: ge_double_scalarmult_precomp_vartime(&tmp_p2, scalar0.bytes, &p3_0, scalar1.bytes, precomp0); break;
diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp
index bd7414c59..d3ba57270 100644
--- a/tests/performance_tests/main.cpp
+++ b/tests/performance_tests/main.cpp
@@ -254,6 +254,7 @@ int main(int argc, char** argv)
TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_scalarmultKey);
TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_scalarmultH);
TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_scalarmult8);
+ TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_scalarmult8_p3);
TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_ge_dsm_precomp);
TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_ge_double_scalarmult_base_vartime);
TEST_PERFORMANCE1(filter, p, test_crypto_ops, op_ge_double_scalarmult_precomp_vartime);
diff --git a/tests/trezor/daemon.cpp b/tests/trezor/daemon.cpp
index 41af93f3f..aba835ae2 100644
--- a/tests/trezor/daemon.cpp
+++ b/tests/trezor/daemon.cpp
@@ -129,7 +129,7 @@ void mock_daemon::init()
m_rpc_server.nettype(m_network_type);
CHECK_AND_ASSERT_THROW_MES(m_protocol.init(m_vm), "Failed to initialize cryptonote protocol.");
- CHECK_AND_ASSERT_THROW_MES(m_rpc_server.init(m_vm, false, main_rpc_port), "Failed to initialize RPC server.");
+ CHECK_AND_ASSERT_THROW_MES(m_rpc_server.init(m_vm, false, main_rpc_port, false), "Failed to initialize RPC server.");
if (m_start_p2p)
CHECK_AND_ASSERT_THROW_MES(m_server.init(m_vm), "Failed to initialize p2p server.");
@@ -313,7 +313,7 @@ void mock_daemon::mine_blocks(size_t num_blocks, const std::string &miner_addres
{
bool blocks_mined = false;
const uint64_t start_height = get_height();
- const auto mining_timeout = std::chrono::seconds(30);
+ const auto mining_timeout = std::chrono::seconds(120);
MDEBUG("Current height before mining: " << start_height);
start_mining(miner_address);
diff --git a/tests/trezor/daemon.h b/tests/trezor/daemon.h
index 046b09a5d..4b8094e05 100644
--- a/tests/trezor/daemon.h
+++ b/tests/trezor/daemon.h
@@ -76,7 +76,7 @@ public:
typedef cryptonote::t_cryptonote_protocol_handler<cryptonote::core> t_protocol_raw;
typedef nodetool::node_server<t_protocol_raw> t_node_server;
- static constexpr const std::chrono::seconds rpc_timeout = std::chrono::seconds(60);
+ static constexpr const std::chrono::seconds rpc_timeout = std::chrono::seconds(120);
cryptonote::core * m_core;
t_protocol_raw m_protocol;
diff --git a/tests/trezor/trezor_tests.cpp b/tests/trezor/trezor_tests.cpp
index a867a4047..f5867f5e7 100644
--- a/tests/trezor/trezor_tests.cpp
+++ b/tests/trezor/trezor_tests.cpp
@@ -38,6 +38,7 @@
using namespace cryptonote;
#include <boost/regex.hpp>
+#include <common/apply_permutation.h>
#include "common/util.h"
#include "common/command_line.h"
#include "trezor_tests.h"
@@ -72,9 +73,10 @@ namespace
#define TREZOR_SETUP_CHAIN(NAME) do { \
++tests_count; \
try { \
- setup_chain(core, trezor_base, chain_path, fix_chain, vm_core); \
+ setup_chain(core, trezor_base, chain_path, fix_chain, vm_core); \
} catch (const std::exception& ex) { \
- failed_tests.emplace_back("gen_trezor_base " #NAME); \
+ MERROR("Chain setup failed for " << NAME); \
+ throw; \
} \
} while(0)
@@ -136,10 +138,11 @@ int main(int argc, char* argv[])
hw::register_device(HW_TREZOR_NAME, ensure_trezor_test_device()); // shim device for call tracking
// Bootstrapping common chain & accounts
- const uint8_t initial_hf = (uint8_t)get_env_long("TEST_MIN_HF", 11);
- const uint8_t max_hf = (uint8_t)get_env_long("TEST_MAX_HF", 11);
+ const uint8_t initial_hf = (uint8_t)get_env_long("TEST_MIN_HF", 12);
+ const uint8_t max_hf = (uint8_t)get_env_long("TEST_MAX_HF", 12);
+ auto sync_test = get_env_long("TEST_KI_SYNC", 1);
MINFO("Test versions " << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")");
- MINFO("Testing hardforks [" << (int)initial_hf << ", " << (int)max_hf << "]");
+ MINFO("Testing hardforks [" << (int)initial_hf << ", " << (int)max_hf << "], sync-test: " << sync_test);
cryptonote::core core_obj(nullptr);
cryptonote::core * const core = &core_obj;
@@ -181,7 +184,7 @@ int main(int argc, char* argv[])
trezor_base.daemon(daemon);
// Hard-fork independent tests
- if (hf == initial_hf)
+ if (hf == initial_hf && sync_test > 0)
{
TREZOR_COMMON_TEST_CASE(gen_trezor_ki_sync_without_refresh, core, trezor_base);
TREZOR_COMMON_TEST_CASE(gen_trezor_live_refresh, core, trezor_base);
@@ -191,7 +194,6 @@ int main(int argc, char* argv[])
TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo, core, trezor_base);
TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo_paymentid_short, core, trezor_base);
TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo_paymentid_short_integrated, core, trezor_base);
- TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo_paymentid_long, core, trezor_base);
TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo, core, trezor_base);
TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_acc1, core, trezor_base);
TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_sub, core, trezor_base);
@@ -338,10 +340,7 @@ static void setup_chain(cryptonote::core * core, gen_trezor_base & trezor_base,
if (!unserialize_chain_from_file(events, trezor_base, chain_path))
{
MERROR("Failed to deserialize data from file: " << chain_path);
- if (!fix_chain)
- {
- throw std::runtime_error("Chain load error");
- }
+ CHECK_AND_ASSERT_THROW_MES(fix_chain, "Chain load error");
} else
{
trezor_base.load(events);
@@ -648,6 +647,8 @@ void gen_trezor_base::fork(gen_trezor_base & other)
other.m_alice_account = m_alice_account;
other.m_eve_account = m_eve_account;
other.m_trezor = m_trezor;
+ other.m_generator.set_events(&other.m_events);
+ other.m_generator.set_network_type(m_network_type);
}
void gen_trezor_base::clear()
@@ -700,6 +701,8 @@ bool gen_trezor_base::generate(std::vector<test_event_entry>& events)
// Events, custom genesis so it matches wallet genesis
auto & generator = m_generator; // macro shortcut
+ generator.set_events(&events);
+ generator.set_network_type(m_network_type);
cryptonote::block blk_gen;
std::vector<size_t> block_weights;
@@ -852,6 +855,8 @@ void gen_trezor_base::load(std::vector<test_event_entry>& events)
{
init_fields();
m_events = events;
+ m_generator.set_events(&m_events);
+ m_generator.set_network_type(m_network_type);
unsigned acc_idx = 0;
cryptonote::account_base * accounts[] = {TREZOR_ACCOUNT_ORDERING};
@@ -919,29 +924,19 @@ void gen_trezor_base::rewind_blocks(std::vector<test_event_entry>& events, size_
void gen_trezor_base::fix_hf(std::vector<test_event_entry>& events)
{
// If current test requires higher hard-fork, move it up
- const auto current_hf = m_hard_forks.back().first;
-
- if (current_hf > m_top_hard_fork)
- {
- throw std::runtime_error("Generated chain hardfork is higher than desired maximum");
- }
-
- if (m_rct_config.bp_version == 2 && m_top_hard_fork < 10)
- {
- throw std::runtime_error("Desired maximum is too low for BPv2");
- }
+ auto current_hf = m_hard_forks.back().first;
+ CHECK_AND_ASSERT_THROW_MES(current_hf <= m_top_hard_fork, "Generated chain hardfork is higher than desired maximum");
+ CHECK_AND_ASSERT_THROW_MES(m_rct_config.bp_version != 2 || m_top_hard_fork >= 10, "Desired maximum is too low for BPv2");
- if (current_hf < m_top_hard_fork)
+ for(;current_hf < m_top_hard_fork; current_hf+=1)
{
+ auto const hf_to_add = current_hf + 1;
auto hardfork_height = num_blocks(events);
- ADD_HARDFORK(m_hard_forks, m_top_hard_fork, hardfork_height);
- add_top_hfork(events, m_hard_forks);
- MDEBUG("Hardfork added at height: " << hardfork_height << ", from " << (int)current_hf << " to " << (int)m_top_hard_fork);
- if (current_hf < 10)
- { // buffer blocks, add 10 to apply v10 rules
- rewind_blocks(events, 10, m_top_hard_fork);
- }
+ ADD_HARDFORK(m_hard_forks, hf_to_add, hardfork_height);
+ add_top_hfork(events, m_hard_forks);
+ MDEBUG("Hardfork added at height: " << hardfork_height << ", from " << (int)current_hf << " to " << (int)hf_to_add);
+ rewind_blocks(events, 10, hf_to_add);
}
}
@@ -1271,7 +1266,6 @@ void gen_trezor_base::set_hard_fork(uint8_t hf)
#define TREZOR_SKIP_IF_VERSION_LEQ(x) if (m_trezor->get_version() <= x) { MDEBUG("Test skipped"); return true; }
#define TREZOR_TEST_PAYMENT_ID "\xde\xad\xc0\xde\xde\xad\xc0\xde"
-#define TREZOR_TEST_PAYMENT_ID_LONG "\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde"
tsx_builder * tsx_builder::sources(std::vector<cryptonote::tx_source_entry> & sources, std::vector<size_t> & selected_transfers)
{
@@ -1424,13 +1418,26 @@ tsx_builder * tsx_builder::construct_pending_tx(tools::wallet2::pending_tx &ptx,
std::vector<crypto::secret_key> additional_tx_keys;
std::vector<tx_destination_entry> destinations_copy = m_destinations;
+ auto sources_copy = m_sources;
auto change_addr = m_from->get_account().get_keys().m_account_address;
bool r = construct_tx_and_get_tx_key(m_from->get_account().get_keys(), subaddresses, m_sources, destinations_copy,
change_addr, extra ? extra.get() : std::vector<uint8_t>(), tx, 0, tx_key,
additional_tx_keys, true, m_rct_config, nullptr);
-
CHECK_AND_ASSERT_THROW_MES(r, "Transaction construction failed");
+ // Selected transfers permutation
+ std::vector<size_t> ins_order;
+ for (size_t n = 0; n < m_sources.size(); ++n)
+ {
+ for (size_t idx = 0; idx < sources_copy.size(); ++idx)
+ {
+ CHECK_AND_ASSERT_THROW_MES((size_t)sources_copy[idx].real_output < sources_copy[idx].outputs.size(), "Invalid real_output");
+ if (sources_copy[idx].outputs[sources_copy[idx].real_output].second.dest == m_sources[n].outputs[m_sources[n].real_output].second.dest)
+ ins_order.push_back(idx);
+ }
+ }
+ CHECK_AND_ASSERT_THROW_MES(ins_order.size() == m_sources.size(), "Failed to work out sources permutation");
+
ptx.key_images = "";
ptx.fee = TESTS_DEFAULT_FEE;
ptx.dust = 0;
@@ -1438,6 +1445,7 @@ tsx_builder * tsx_builder::construct_pending_tx(tools::wallet2::pending_tx &ptx,
ptx.tx = tx;
ptx.change_dts = m_destinations.back();
ptx.selected_transfers = m_selected_transfers;
+ tools::apply_permutation(ins_order, ptx.selected_transfers);
ptx.tx_key = tx_key;
ptx.additional_tx_keys = additional_tx_keys;
ptx.dests = m_destinations;
@@ -1671,22 +1679,6 @@ bool gen_trezor_1utxo_paymentid_short_integrated::generate(std::vector<test_even
TREZOR_TEST_SUFFIX();
}
-bool gen_trezor_1utxo_paymentid_long::generate(std::vector<test_event_entry>& events)
-{
- TREZOR_TEST_PREFIX();
- t_builder->cur_height(num_blocks(events) - 1)
- ->mixin(TREZOR_TEST_MIXIN)
- ->fee(TREZOR_TEST_FEE)
- ->from(m_wl_alice.get(), 0)
- ->compute_sources(boost::none, MK_COINS(1), -1, -1)
- ->add_destination(m_eve_account, false, 1000)
- ->payment_id(TREZOR_TEST_PAYMENT_ID_LONG)
- ->rct_config(m_rct_config)
- ->build_tx();
-
- TREZOR_TEST_SUFFIX();
-}
-
bool gen_trezor_4utxo::generate(std::vector<test_event_entry>& events)
{
TREZOR_TEST_PREFIX();
diff --git a/tests/trezor/trezor_tests.h b/tests/trezor/trezor_tests.h
index 46eb5e6a5..67714f102 100644
--- a/tests/trezor/trezor_tests.h
+++ b/tests/trezor/trezor_tests.h
@@ -264,12 +264,6 @@ public:
bool generate(std::vector<test_event_entry>& events) override;
};
-class gen_trezor_1utxo_paymentid_long : public gen_trezor_base
-{
-public:
- bool generate(std::vector<test_event_entry>& events) override;
-};
-
class gen_trezor_4utxo : public gen_trezor_base
{
public:
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index 4f42140b3..2e93f9e67 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2019, The Monero Project
+// Copyright (c) 2014-2020, The Monero Project
//
// All rights reserved.
//
@@ -45,6 +45,7 @@
#include "boost/archive/portable_binary_iarchive.hpp"
#include "boost/archive/portable_binary_oarchive.hpp"
#include "byte_slice.h"
+#include "byte_stream.h"
#include "crypto/crypto.h"
#include "hex.h"
#include "net/net_utils_base.h"
@@ -809,6 +810,259 @@ TEST(ByteSlice, GetSlice)
EXPECT_TRUE(boost::range::equal(base_string, original));
}
+TEST(ByteStream, Construction)
+{
+ EXPECT_TRUE(std::is_default_constructible<epee::byte_stream>());
+ EXPECT_TRUE(std::is_move_constructible<epee::byte_stream>());
+ EXPECT_FALSE(std::is_copy_constructible<epee::byte_stream>());
+ EXPECT_TRUE(std::is_move_assignable<epee::byte_stream>());
+ EXPECT_FALSE(std::is_copy_assignable<epee::byte_stream>());
+}
+
+TEST(ByteStream, Noexcept)
+{
+ EXPECT_TRUE(std::is_nothrow_default_constructible<epee::byte_stream>());
+ EXPECT_TRUE(std::is_nothrow_move_constructible<epee::byte_stream>());
+ EXPECT_TRUE(std::is_nothrow_move_assignable<epee::byte_stream>());
+
+ epee::byte_stream lvalue;
+ const epee::byte_stream clvalue;
+
+ EXPECT_TRUE(noexcept(lvalue.data()));
+ EXPECT_TRUE(noexcept(clvalue.data()));
+ EXPECT_TRUE(noexcept(lvalue.tellp()));
+ EXPECT_TRUE(noexcept(clvalue.tellp()));
+ EXPECT_TRUE(noexcept(lvalue.available()));
+ EXPECT_TRUE(noexcept(clvalue.available()));
+ EXPECT_TRUE(noexcept(lvalue.size()));
+ EXPECT_TRUE(noexcept(clvalue.size()));
+ EXPECT_TRUE(noexcept(lvalue.capacity()));
+ EXPECT_TRUE(noexcept(clvalue.capacity()));
+ EXPECT_TRUE(noexcept(lvalue.put_unsafe(4)));
+ EXPECT_TRUE(noexcept(lvalue.take_buffer()));
+}
+
+TEST(ByteStream, Empty)
+{
+ epee::byte_stream stream;
+
+ EXPECT_EQ(epee::byte_stream::default_increase(), stream.increase_size());
+
+ EXPECT_EQ(nullptr, stream.data());
+ EXPECT_EQ(nullptr, stream.tellp());
+ EXPECT_EQ(0u, stream.available());
+ EXPECT_EQ(0u, stream.size());
+ EXPECT_EQ(0u, stream.capacity());
+
+ const auto buf = stream.take_buffer();
+ EXPECT_EQ(nullptr, buf.get());
+ EXPECT_EQ(nullptr, stream.data());
+ EXPECT_EQ(nullptr, stream.tellp());
+ EXPECT_EQ(0u, stream.available());
+ EXPECT_EQ(0u, stream.size());
+ EXPECT_EQ(0u, stream.capacity());
+}
+
+TEST(ByteStream, Write)
+{
+ using boost::range::equal;
+ using byte_span = epee::span<const std::uint8_t>;
+
+ static constexpr const std::uint8_t source[] =
+ {0xde, 0xad, 0xbe, 0xef, 0xef};
+
+ std::vector<std::uint8_t> bytes;
+ epee::byte_stream stream{4};
+
+ EXPECT_EQ(4u, stream.increase_size());
+
+ stream.write({source, 3});
+ bytes.insert(bytes.end(), source, source + 3);
+ EXPECT_EQ(3u, stream.size());
+ EXPECT_EQ(1u, stream.available());
+ EXPECT_EQ(4u, stream.capacity());
+ EXPECT_TRUE(equal(bytes, byte_span{stream.data(), stream.size()}));
+
+ stream.write({source, 2});
+ bytes.insert(bytes.end(), source, source + 2);
+ EXPECT_EQ(5u, stream.size());
+ EXPECT_EQ(3u, stream.available());
+ EXPECT_EQ(8u, stream.capacity());
+ EXPECT_TRUE(equal(bytes, byte_span{stream.data(), stream.size()}));
+
+ stream.write({source, 5});
+ bytes.insert(bytes.end(), source, source + 5);
+ EXPECT_EQ(10u, stream.size());
+ EXPECT_EQ(2u, stream.available());
+ EXPECT_EQ(12u, stream.capacity());
+ EXPECT_TRUE(equal(bytes, byte_span{stream.data(), stream.size()}));
+
+ stream.write({source, 2});
+ bytes.insert(bytes.end(), source, source + 2);
+ EXPECT_EQ(12u, stream.size());
+ EXPECT_EQ(0u, stream.available());
+ EXPECT_EQ(12u, stream.capacity());
+ EXPECT_TRUE(equal(bytes, byte_span{stream.data(), stream.size()}));
+
+ stream.write({source, 5});
+ bytes.insert(bytes.end(), source, source + 5);
+ EXPECT_EQ(17u, stream.size());
+ EXPECT_EQ(0u, stream.available());
+ EXPECT_EQ(17u, stream.capacity());
+ EXPECT_TRUE(equal(bytes, byte_span{stream.data(), stream.size()}));
+}
+
+TEST(ByteStream, Put)
+{
+ using boost::range::equal;
+ using byte_span = epee::span<const std::uint8_t>;
+
+ std::vector<std::uint8_t> bytes;
+ epee::byte_stream stream;
+
+ for (std::uint8_t i = 0; i < 200; ++i)
+ {
+ bytes.push_back(i);
+ stream.put(i);
+ }
+
+ EXPECT_EQ(200u, stream.size());
+ EXPECT_EQ(epee::byte_stream::default_increase() - 200, stream.available());
+ EXPECT_EQ(epee::byte_stream::default_increase(), stream.capacity());
+ EXPECT_TRUE(equal(bytes, byte_span{stream.data(), stream.size()}));
+}
+
+TEST(ByteStream, Reserve)
+{
+ using boost::range::equal;
+ using byte_span = epee::span<const std::uint8_t>;
+
+ static constexpr const std::uint8_t source[] =
+ {0xde, 0xad, 0xbe, 0xef, 0xef};
+
+ std::vector<std::uint8_t> bytes;
+ epee::byte_stream stream{4};
+
+ EXPECT_EQ(4u, stream.increase_size());
+
+ stream.reserve(100);
+ EXPECT_EQ(100u, stream.capacity());
+ EXPECT_EQ(0u, stream.size());
+ EXPECT_EQ(100u, stream.available());
+
+ for (std::size_t i = 0; i < 100 / sizeof(source); ++i)
+ {
+ stream.write(source);
+ bytes.insert(bytes.end(), source, source + sizeof(source));
+ }
+
+ EXPECT_EQ(100u, stream.size());
+ EXPECT_EQ(0u, stream.available());
+ EXPECT_EQ(100u, stream.capacity());
+ EXPECT_TRUE(equal(bytes, byte_span{stream.data(), stream.size()}));
+}
+
+TEST(ByteStream, TakeBuffer)
+{
+ using boost::range::equal;
+ using byte_span = epee::span<const std::uint8_t>;
+
+ static constexpr const std::uint8_t source[] =
+ {0xde, 0xad, 0xbe, 0xef, 0xef};
+
+ epee::byte_stream stream;
+
+ stream.write(source);
+ ASSERT_EQ(sizeof(source), stream.size());
+ EXPECT_TRUE(equal(source, byte_span{stream.data(), stream.size()}));
+
+ const auto buffer = stream.take_buffer();
+ EXPECT_EQ(0u, stream.size());
+ EXPECT_EQ(0u, stream.available());
+ EXPECT_EQ(0u, stream.capacity());
+ EXPECT_EQ(nullptr, stream.data());
+ EXPECT_EQ(nullptr, stream.tellp());
+ EXPECT_TRUE(equal(source, byte_span{buffer.get(), sizeof(source)}));
+}
+
+TEST(ByteStream, Move)
+{
+ using boost::range::equal;
+ using byte_span = epee::span<const std::uint8_t>;
+
+ static constexpr const std::uint8_t source[] =
+ {0xde, 0xad, 0xbe, 0xef, 0xef};
+
+ epee::byte_stream stream{10};
+ stream.write(source);
+
+ epee::byte_stream stream2{std::move(stream)};
+
+ EXPECT_EQ(10u, stream.increase_size());
+ EXPECT_EQ(0u, stream.size());
+ EXPECT_EQ(0u, stream.available());
+ EXPECT_EQ(0u, stream.capacity());
+ EXPECT_EQ(nullptr, stream.data());
+ EXPECT_EQ(nullptr, stream.tellp());
+
+ EXPECT_EQ(10u, stream2.increase_size());
+ EXPECT_EQ(5u, stream2.size());
+ EXPECT_EQ(5u, stream2.available());
+ EXPECT_EQ(10u, stream2.capacity());
+ EXPECT_NE(nullptr, stream2.data());
+ EXPECT_NE(nullptr, stream2.tellp());
+ EXPECT_TRUE(equal(source, byte_span{stream2.data(), stream2.size()}));
+
+ stream = epee::byte_stream{};
+
+ EXPECT_EQ(epee::byte_stream::default_increase(), stream.increase_size());
+ EXPECT_EQ(0u, stream.size());
+ EXPECT_EQ(0u, stream.available());
+ EXPECT_EQ(0u, stream.capacity());
+ EXPECT_EQ(nullptr, stream.data());
+ EXPECT_EQ(nullptr, stream.tellp());
+
+ stream = std::move(stream2);
+
+ EXPECT_EQ(10u, stream.increase_size());
+ EXPECT_EQ(5u, stream.size());
+ EXPECT_EQ(5u, stream.available());
+ EXPECT_EQ(10u, stream.capacity());
+ EXPECT_NE(nullptr, stream.data());
+ EXPECT_NE(nullptr, stream.tellp());
+ EXPECT_TRUE(equal(source, byte_span{stream.data(), stream.size()}));
+
+ EXPECT_EQ(10u, stream2.increase_size());
+ EXPECT_EQ(0u, stream2.size());
+ EXPECT_EQ(0u, stream2.available());
+ EXPECT_EQ(0u, stream2.capacity());
+ EXPECT_EQ(nullptr, stream2.data());
+ EXPECT_EQ(nullptr, stream2.tellp());
+}
+
+TEST(ByteStream, ToByteSlice)
+{
+ using boost::range::equal;
+ using byte_span = epee::span<const std::uint8_t>;
+
+ static constexpr const std::uint8_t source[] =
+ {0xde, 0xad, 0xbe, 0xef, 0xef};
+
+ epee::byte_stream stream;
+
+ stream.write(source);
+ EXPECT_EQ(sizeof(source), stream.size());
+ EXPECT_TRUE(equal(source, byte_span{stream.data(), stream.size()}));
+
+ const epee::byte_slice slice{std::move(stream)};
+ EXPECT_EQ(0u, stream.size());
+ EXPECT_EQ(0u, stream.available());
+ EXPECT_EQ(0u, stream.capacity());
+ EXPECT_EQ(nullptr, stream.data());
+ EXPECT_EQ(nullptr, stream.tellp());
+ EXPECT_TRUE(equal(source, slice));
+}
+
TEST(ToHex, String)
{
EXPECT_TRUE(epee::to_hex::string(nullptr).empty());
diff --git a/tests/unit_tests/json_serialization.cpp b/tests/unit_tests/json_serialization.cpp
index 6f98d854d..5873d0ab6 100644
--- a/tests/unit_tests/json_serialization.cpp
+++ b/tests/unit_tests/json_serialization.cpp
@@ -3,10 +3,10 @@
#include <boost/range/adaptor/indexed.hpp>
#include <gtest/gtest.h>
#include <rapidjson/document.h>
-#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <vector>
+#include "byte_stream.h"
#include "crypto/hash.h"
#include "cryptonote_basic/account.h"
#include "cryptonote_basic/cryptonote_basic.h"
@@ -86,14 +86,14 @@ namespace
template<typename T>
T test_json(const T& value)
{
- rapidjson::StringBuffer buffer;
+ epee::byte_stream buffer;
{
- rapidjson::Writer<rapidjson::StringBuffer> dest{buffer};
+ rapidjson::Writer<epee::byte_stream> dest{buffer};
cryptonote::json::toJsonValue(dest, value);
}
rapidjson::Document doc;
- doc.Parse(buffer.GetString());
+ doc.Parse(reinterpret_cast<const char*>(buffer.data()), buffer.size());
if (doc.HasParseError() || !doc.IsObject())
{
throw cryptonote::json::PARSE_FAIL();
diff --git a/tests/unit_tests/levin.cpp b/tests/unit_tests/levin.cpp
index 62b101a42..d2ef920ef 100644
--- a/tests/unit_tests/levin.cpp
+++ b/tests/unit_tests/levin.cpp
@@ -583,7 +583,9 @@ TEST_F(levin_notify, stem_without_padding)
{
const std::size_t sent = context->process_send_queue();
if (sent && is_stem)
+ {
EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
+ }
send_count += sent;
}
@@ -653,7 +655,9 @@ TEST_F(levin_notify, local_without_padding)
{
const std::size_t sent = context->process_send_queue();
if (sent && is_stem)
+ {
EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
+ }
send_count += sent;
}
diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp
index 36cb28ae0..f5aef4796 100644
--- a/tests/unit_tests/net.cpp
+++ b/tests/unit_tests/net.cpp
@@ -1702,6 +1702,45 @@ TEST(zmq, read_write)
EXPECT_EQ(message, *received);
}
+TEST(zmq, read_write_slice)
+{
+ net::zmq::context context{zmq_init(1)};
+ ASSERT_NE(nullptr, context);
+
+ net::zmq::socket send_socket{zmq_socket(context.get(), ZMQ_REQ)};
+ net::zmq::socket recv_socket{zmq_socket(context.get(), ZMQ_REP)};
+ ASSERT_NE(nullptr, send_socket);
+ ASSERT_NE(nullptr, recv_socket);
+
+ ASSERT_EQ(0u, zmq_bind(recv_socket.get(), "inproc://testing"));
+ ASSERT_EQ(0u, zmq_connect(send_socket.get(), "inproc://testing"));
+
+ std::string message;
+ message.resize(1024);
+ crypto::rand(message.size(), reinterpret_cast<std::uint8_t*>(std::addressof(message[0])));
+
+ {
+ epee::byte_slice slice_message{{epee::strspan<std::uint8_t>(message)}};
+ ASSERT_TRUE(bool(net::zmq::send(std::move(slice_message), send_socket.get())));
+ EXPECT_TRUE(slice_message.empty());
+ }
+
+ const expect<std::string> received = net::zmq::receive(recv_socket.get());
+ ASSERT_TRUE(bool(received));
+ EXPECT_EQ(message, *received);
+}
+
+TEST(zmq, write_slice_fail)
+{
+ std::string message;
+ message.resize(1024);
+ crypto::rand(message.size(), reinterpret_cast<std::uint8_t*>(std::addressof(message[0])));
+
+ epee::byte_slice slice_message{std::move(message)};
+ EXPECT_FALSE(bool(net::zmq::send(std::move(slice_message), nullptr)));
+ EXPECT_TRUE(slice_message.empty());
+}
+
TEST(zmq, read_write_multipart)
{
net::zmq::context context{zmq_init(1)};
diff --git a/tests/unit_tests/ringct.cpp b/tests/unit_tests/ringct.cpp
index 075aeac40..64fcbba4c 100644
--- a/tests/unit_tests/ringct.cpp
+++ b/tests/unit_tests/ringct.cpp
@@ -1077,8 +1077,16 @@ TEST(ringct, H)
TEST(ringct, mul8)
{
+ ge_p3 p3;
+ rct::key key;
ASSERT_EQ(rct::scalarmult8(rct::identity()), rct::identity());
+ rct::scalarmult8(p3,rct::identity());
+ ge_p3_tobytes(key.bytes, &p3);
+ ASSERT_EQ(key, rct::identity());
ASSERT_EQ(rct::scalarmult8(rct::H), rct::scalarmultKey(rct::H, rct::EIGHT));
+ rct::scalarmult8(p3,rct::H);
+ ge_p3_tobytes(key.bytes, &p3);
+ ASSERT_EQ(key, rct::scalarmultKey(rct::H, rct::EIGHT));
ASSERT_EQ(rct::scalarmultKey(rct::scalarmultKey(rct::H, rct::INV_EIGHT), rct::EIGHT), rct::H);
}