aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/core_proxy/CMakeLists.txt1
-rw-r--r--tests/core_proxy/core_proxy.cpp7
-rw-r--r--tests/core_proxy/core_proxy.h4
-rw-r--r--tests/core_tests/CMakeLists.txt1
-rw-r--r--tests/core_tests/chain_switch_1.cpp2
-rw-r--r--tests/core_tests/chaingen.cpp7
-rw-r--r--tests/core_tests/integer_overflow.cpp6
-rw-r--r--tests/core_tests/rct.cpp16
-rw-r--r--tests/core_tests/ring_signature_1.cpp3
-rw-r--r--tests/core_tests/transaction_tests.cpp10
-rw-r--r--tests/core_tests/tx_validation.cpp5
-rw-r--r--tests/crypto/main.cpp6
-rw-r--r--tests/functional_tests/transactions_flow_test.cpp8
-rw-r--r--tests/fuzz/signature.cpp5
-rw-r--r--tests/libwallet_api_tests/CMakeLists.txt1
-rw-r--r--tests/libwallet_api_tests/main.cpp116
-rw-r--r--tests/performance_tests/check_tx_signature.h7
-rw-r--r--tests/performance_tests/construct_tx.h9
-rw-r--r--tests/performance_tests/derive_secret_key.h2
-rw-r--r--tests/performance_tests/ge_frombytes_vartime.h2
-rw-r--r--tests/performance_tests/generate_key_image_helper.h5
-rw-r--r--tests/performance_tests/is_out_to_acc.h24
-rw-r--r--tests/performance_tests/main.cpp1
-rw-r--r--tests/performance_tests/single_tx_test_base.h2
-rw-r--r--tests/unit_tests/CMakeLists.txt5
-rw-r--r--tests/unit_tests/apply_permutation.cpp74
-rw-r--r--tests/unit_tests/ban.cpp4
-rw-r--r--tests/unit_tests/base58.cpp32
-rw-r--r--tests/unit_tests/checkpoints.cpp2
-rw-r--r--tests/unit_tests/epee_utils.cpp231
-rw-r--r--tests/unit_tests/hardfork.cpp2
-rw-r--r--tests/unit_tests/hashchain.cpp129
-rw-r--r--tests/unit_tests/main.cpp20
-rw-r--r--tests/unit_tests/output_selection.cpp2
-rw-r--r--tests/unit_tests/serialization.cpp37
-rw-r--r--tests/unit_tests/test_peerlist.cpp2
-rw-r--r--tests/unit_tests/test_tx_utils.cpp2
-rw-r--r--tests/unit_tests/unit_tests_utils.h3
39 files changed, 653 insertions, 143 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 85763f8b5..a5f5335db 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -30,6 +30,7 @@
# The docs say this only affects grouping in IDEs
set(folder "tests")
+set(TEST_DATA_DIR "${CMAKE_CURRENT_LIST_DIR}/data")
if (WIN32 AND STATIC)
add_definitions(-DSTATICLIB)
diff --git a/tests/core_proxy/CMakeLists.txt b/tests/core_proxy/CMakeLists.txt
index d22fecc9c..d2dc93cf0 100644
--- a/tests/core_proxy/CMakeLists.txt
+++ b/tests/core_proxy/CMakeLists.txt
@@ -40,6 +40,7 @@ target_link_libraries(core_proxy
cryptonote_core
cryptonote_protocol
p2p
+ version
epee
${CMAKE_THREAD_LIBS_INIT}
${EXTRA_LIBRARIES})
diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp
index 366937e1d..a0be3db96 100644
--- a/tests/core_proxy/core_proxy.cpp
+++ b/tests/core_proxy/core_proxy.cpp
@@ -229,10 +229,9 @@ bool tests::proxy_core::get_short_chain_history(std::list<crypto::hash>& ids) {
return true;
}
-bool tests::proxy_core::get_blockchain_top(uint64_t& height, crypto::hash& top_id) {
+void tests::proxy_core::get_blockchain_top(uint64_t& height, crypto::hash& top_id) {
height = 0;
top_id = get_block_hash(m_genesis);
- return true;
}
bool tests::proxy_core::init(const boost::program_options::variables_map& /*vm*/) {
@@ -256,7 +255,7 @@ void tests::proxy_core::build_short_history(std::list<crypto::hash> &m_history,
m_history.push_front(cit->first);
size_t n = 1 << m_history.size();
- while (m_hash2blkidx.end() != cit && cryptonote::null_hash != cit->second.blk.prev_id && n > 0) {
+ while (m_hash2blkidx.end() != cit && crypto::null_hash != cit->second.blk.prev_id && n > 0) {
n--;
cit = m_hash2blkidx.find(cit->second.blk.prev_id);
}
@@ -266,7 +265,7 @@ void tests::proxy_core::build_short_history(std::list<crypto::hash> &m_history,
bool tests::proxy_core::add_block(const crypto::hash &_id, const crypto::hash &_longhash, const cryptonote::block &_blk, const cryptonote::blobdata &_blob) {
size_t height = 0;
- if (cryptonote::null_hash != _blk.prev_id) {
+ if (crypto::null_hash != _blk.prev_id) {
std::unordered_map<crypto::hash, tests::block_index>::const_iterator cit = m_hash2blkidx.find(_blk.prev_id);
if (m_hash2blkidx.end() == cit) {
cerr << "ERROR: can't find previous block with id \"" << _blk.prev_id << "\"" << endl;
diff --git a/tests/core_proxy/core_proxy.h b/tests/core_proxy/core_proxy.h
index 4f056ec7e..51f0f892c 100644
--- a/tests/core_proxy/core_proxy.h
+++ b/tests/core_proxy/core_proxy.h
@@ -46,7 +46,7 @@ namespace tests
cryptonote::blobdata blob;
std::list<cryptonote::transaction> txes;
- block_index() : height(0), id(cryptonote::null_hash), longhash(cryptonote::null_hash) { }
+ block_index() : height(0), id(crypto::null_hash), longhash(crypto::null_hash) { }
block_index(size_t _height, const crypto::hash &_id, const crypto::hash &_longhash, const cryptonote::block &_blk, const cryptonote::blobdata &_blob, const std::list<cryptonote::transaction> &_txes)
: height(_height), id(_id), longhash(_longhash), blk(_blk), blob(_blob), txes(_txes) { }
};
@@ -74,7 +74,7 @@ namespace tests
bool get_short_chain_history(std::list<crypto::hash>& ids);
bool get_stat_info(cryptonote::core_stat_info& st_inf){return true;}
bool have_block(const crypto::hash& id);
- bool get_blockchain_top(uint64_t& height, crypto::hash& top_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::list<cryptonote::blobdata>& 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, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true);
diff --git a/tests/core_tests/CMakeLists.txt b/tests/core_tests/CMakeLists.txt
index c1d3161bc..a24bd4fce 100644
--- a/tests/core_tests/CMakeLists.txt
+++ b/tests/core_tests/CMakeLists.txt
@@ -65,6 +65,7 @@ target_link_libraries(coretests
PRIVATE
cryptonote_core
p2p
+ version
epee
${CMAKE_THREAD_LIBS_INIT}
${EXTRA_LIBRARIES})
diff --git a/tests/core_tests/chain_switch_1.cpp b/tests/core_tests/chain_switch_1.cpp
index a48105f49..b04d05219 100644
--- a/tests/core_tests/chain_switch_1.cpp
+++ b/tests/core_tests/chain_switch_1.cpp
@@ -152,7 +152,7 @@ bool gen_chain_switch_1::check_split_not_switched(cryptonote::core& c, size_t ev
std::vector<size_t> tx_outs;
uint64_t transfered;
- lookup_acc_outs(m_recipient_account_4.get_keys(), tx_pool.front(), get_tx_pub_key_from_extra(tx_pool.front()), tx_outs, transfered);
+ lookup_acc_outs(m_recipient_account_4.get_keys(), tx_pool.front(), get_tx_pub_key_from_extra(tx_pool.front()), get_additional_tx_pub_keys_from_extra(tx_pool.front()), tx_outs, transfered);
CHECK_EQ(MK_COINS(13), transfered);
m_chain_1.swap(blocks);
diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp
index b15487a24..f23aa8ecb 100644
--- a/tests/core_tests/chaingen.cpp
+++ b/tests/core_tests/chaingen.cpp
@@ -344,7 +344,7 @@ bool init_output_indices(map_output_idx_t& outs, std::map<uint64_t, std::vector<
size_t tx_global_idx = outs[out.amount].size() - 1;
outs[out.amount][tx_global_idx].idx = tx_global_idx;
// Is out to me?
- if (is_out_to_acc(from.get_keys(), boost::get<txout_to_key>(out.target), get_tx_pub_key_from_extra(tx), j)) {
+ if (is_out_to_acc(from.get_keys(), boost::get<txout_to_key>(out.target), get_tx_pub_key_from_extra(tx), get_additional_tx_pub_keys_from_extra(tx), j)) {
outs_mine[out.amount].push_back(tx_global_idx);
}
}
@@ -364,7 +364,10 @@ bool init_spent_output_indices(map_output_idx_t& outs, map_output_t& outs_mine,
// construct key image for this output
crypto::key_image img;
keypair in_ephemeral;
- generate_key_image_helper(from.get_keys(), get_tx_pub_key_from_extra(*oi.p_tx), oi.out_no, in_ephemeral, img);
+ crypto::public_key out_key = boost::get<txout_to_key>(oi.out).key;
+ std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
+ subaddresses[from.get_keys().m_account_address.m_spend_public_key] = {0,0};
+ generate_key_image_helper(from.get_keys(), subaddresses, out_key, get_tx_pub_key_from_extra(*oi.p_tx), get_additional_tx_pub_keys_from_extra(*oi.p_tx), oi.out_no, in_ephemeral, img);
// lookup for this key image in the events vector
BOOST_FOREACH(auto& tx_pair, mtx) {
diff --git a/tests/core_tests/integer_overflow.cpp b/tests/core_tests/integer_overflow.cpp
index 75f374434..3ac55c073 100644
--- a/tests/core_tests/integer_overflow.cpp
+++ b/tests/core_tests/integer_overflow.cpp
@@ -169,10 +169,10 @@ bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const
std::vector<cryptonote::tx_destination_entry> destinations;
const account_public_address& bob_addr = bob_account.get_keys().m_account_address;
- destinations.push_back(tx_destination_entry(MONEY_SUPPLY, bob_addr));
- destinations.push_back(tx_destination_entry(MONEY_SUPPLY - 1, bob_addr));
+ destinations.push_back(tx_destination_entry(MONEY_SUPPLY, bob_addr, false));
+ destinations.push_back(tx_destination_entry(MONEY_SUPPLY - 1, bob_addr, false));
// sources.front().amount = destinations[0].amount + destinations[2].amount + destinations[3].amount + TESTS_DEFAULT_FEE
- destinations.push_back(tx_destination_entry(sources.front().amount - MONEY_SUPPLY - MONEY_SUPPLY + 1 - TESTS_DEFAULT_FEE, bob_addr));
+ destinations.push_back(tx_destination_entry(sources.front().amount - MONEY_SUPPLY - MONEY_SUPPLY + 1 - TESTS_DEFAULT_FEE, bob_addr, false));
cryptonote::transaction tx_1;
if (!construct_tx(miner_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tx_1, 0))
diff --git a/tests/core_tests/rct.cpp b/tests/core_tests/rct.cpp
index 21638354d..8a38cbc22 100644
--- a/tests/core_tests/rct.cpp
+++ b/tests/core_tests/rct.cpp
@@ -117,7 +117,10 @@ bool gen_rct_tx_validation_base::generate_with(std::vector<test_event_entry>& ev
destinations.push_back(td); // 30 -> 7.39 * 4
crypto::secret_key tx_key;
- bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), sources, destinations, std::vector<uint8_t>(), rct_txes[n], 0, tx_key, true);
+ std::vector<crypto::secret_key> additional_tx_keys;
+ std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
+ subaddresses[miner_accounts[n].get_keys().m_account_address.m_spend_public_key] = {0,0};
+ bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes[n], 0, tx_key, additional_tx_keys, true);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
events.push_back(rct_txes[n]);
starting_rct_tx_hashes.push_back(get_transaction_hash(rct_txes[n]));
@@ -215,7 +218,10 @@ bool gen_rct_tx_validation_base::generate_with(std::vector<test_event_entry>& ev
transaction tx;
crypto::secret_key tx_key;
- bool r = construct_tx_and_get_tx_key(miner_accounts[0].get_keys(), sources, destinations, std::vector<uint8_t>(), tx, 0, tx_key, true);
+ std::vector<crypto::secret_key> additional_tx_keys;
+ std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
+ subaddresses[miner_accounts[0].get_keys().m_account_address.m_spend_public_key] = {0,0};
+ bool r = construct_tx_and_get_tx_key(miner_accounts[0].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), tx, 0, tx_key, additional_tx_keys, true);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
if (post_tx)
@@ -484,8 +490,9 @@ bool gen_rct_tx_pre_rct_altered_extra::generate(std::vector<test_event_entry>& e
const int mixin = 2;
const int out_idx[] = {0, -1};
const uint64_t amount_paid = 10000;
+ bool failed = false;
return generate_with(events, out_idx, mixin, amount_paid, false,
- NULL, [](transaction &tx) {std::string extra_nonce; crypto::hash pid = cryptonote::null_hash; set_payment_id_to_tx_extra_nonce(extra_nonce, pid); add_extra_nonce_to_tx_extra(tx.extra, extra_nonce);});
+ NULL, [&failed](transaction &tx) {std::string extra_nonce; crypto::hash pid = crypto::null_hash; set_payment_id_to_tx_extra_nonce(extra_nonce, pid); if (!add_extra_nonce_to_tx_extra(tx.extra, extra_nonce)) failed = true; }) && !failed;
}
bool gen_rct_tx_rct_altered_extra::generate(std::vector<test_event_entry>& events) const
@@ -493,7 +500,8 @@ bool gen_rct_tx_rct_altered_extra::generate(std::vector<test_event_entry>& event
const int mixin = 2;
const int out_idx[] = {1, -1};
const uint64_t amount_paid = 10000;
+ bool failed = false;
return generate_with(events, out_idx, mixin, amount_paid, false,
- NULL, [](transaction &tx) {std::string extra_nonce; crypto::hash pid = cryptonote::null_hash; set_payment_id_to_tx_extra_nonce(extra_nonce, pid); add_extra_nonce_to_tx_extra(tx.extra, extra_nonce);});
+ NULL, [&failed](transaction &tx) {std::string extra_nonce; crypto::hash pid = crypto::null_hash; set_payment_id_to_tx_extra_nonce(extra_nonce, pid); if (!add_extra_nonce_to_tx_extra(tx.extra, extra_nonce)) failed = true; }) && !failed;
}
diff --git a/tests/core_tests/ring_signature_1.cpp b/tests/core_tests/ring_signature_1.cpp
index 997f3090d..f9ec68e45 100644
--- a/tests/core_tests/ring_signature_1.cpp
+++ b/tests/core_tests/ring_signature_1.cpp
@@ -337,7 +337,8 @@ bool gen_ring_signature_big::check_balances_2(cryptonote::core& c, size_t ev_ind
std::vector<size_t> tx_outs;
uint64_t transfered;
- lookup_acc_outs(m_alice_account.get_keys(), boost::get<transaction>(events[events.size() - 3]), get_tx_pub_key_from_extra(boost::get<transaction>(events[events.size() - 3])), tx_outs, transfered);
+ const transaction& tx = boost::get<transaction>(events[events.size() - 3]);
+ lookup_acc_outs(m_alice_account.get_keys(), boost::get<transaction>(events[events.size() - 3]), get_tx_pub_key_from_extra(tx), get_additional_tx_pub_keys_from_extra(tx), tx_outs, transfered);
CHECK_EQ(m_tx_amount, transfered);
return true;
diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp
index 8c0d92a8f..dcba36e80 100644
--- a/tests/core_tests/transaction_tests.cpp
+++ b/tests/core_tests/transaction_tests.cpp
@@ -125,11 +125,11 @@ bool test_transaction_generation_and_ring_signature()
std::vector<size_t> outs;
uint64_t money = 0;
- r = lookup_acc_outs(rv_acc.get_keys(), tx_rc1, get_tx_pub_key_from_extra(tx_rc1), outs, money);
+ r = lookup_acc_outs(rv_acc.get_keys(), tx_rc1, get_tx_pub_key_from_extra(tx_rc1), get_additional_tx_pub_keys_from_extra(tx_rc1), outs, money);
CHECK_AND_ASSERT_MES(r, false, "failed to lookup_acc_outs");
CHECK_AND_ASSERT_MES(td.amount == money, false, "wrong money amount in new transaction");
money = 0;
- r = lookup_acc_outs(rv_acc2.get_keys(), tx_rc1, get_tx_pub_key_from_extra(tx_rc1), outs, money);
+ r = lookup_acc_outs(rv_acc2.get_keys(), tx_rc1, get_tx_pub_key_from_extra(tx_rc1), get_additional_tx_pub_keys_from_extra(tx_rc1), outs, money);
CHECK_AND_ASSERT_MES(r, false, "failed to lookup_acc_outs");
CHECK_AND_ASSERT_MES(0 == money, false, "wrong money amount in new transaction");
return true;
@@ -139,11 +139,11 @@ bool test_block_creation()
{
uint64_t vszs[] = {80,476,476,475,475,474,475,474,474,475,472,476,476,475,475,474,475,474,474,475,472,476,476,475,475,474,475,474,474,475,9391,476,476,475,475,474,475,8819,8301,475,472,4302,5316,14347,16620,19583,19403,19728,19442,19852,19015,19000,19016,19795,19749,18087,19787,19704,19750,19267,19006,19050,19445,19407,19522,19546,19788,19369,19486,19329,19370,18853,19600,19110,19320,19746,19474,19474,19743,19494,19755,19715,19769,19620,19368,19839,19532,23424,28287,30707};
std::vector<uint64_t> szs(&vszs[0], &vszs[90]);
- account_public_address adr;
- bool r = get_account_address_from_str(adr, false, "0099be99c70ef10fd534c43c88e9d13d1c8853213df7e362afbec0e4ee6fec4948d0c190b58f4b356cd7feaf8d9d0a76e7c7e5a9a0a497a6b1faf7a765882dd08ac2");
+ address_parse_info info;
+ bool r = get_account_address_from_str(info, false, "0099be99c70ef10fd534c43c88e9d13d1c8853213df7e362afbec0e4ee6fec4948d0c190b58f4b356cd7feaf8d9d0a76e7c7e5a9a0a497a6b1faf7a765882dd08ac2");
CHECK_AND_ASSERT_MES(r, false, "failed to import");
block b;
- r = construct_miner_tx(90, epee::misc_utils::median(szs), 3553616528562147, 33094, 10000000, adr, b.miner_tx, blobdata(), 11);
+ r = construct_miner_tx(90, epee::misc_utils::median(szs), 3553616528562147, 33094, 10000000, info.address, b.miner_tx, blobdata(), 11);
return r;
}
diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp
index 66460e876..0e4b2e71a 100644
--- a/tests/core_tests/tx_validation.cpp
+++ b/tests/core_tests/tx_validation.cpp
@@ -59,7 +59,10 @@ namespace
m_in_contexts.push_back(keypair());
keypair& in_ephemeral = m_in_contexts.back();
crypto::key_image img;
- generate_key_image_helper(sender_account_keys, src_entr.real_out_tx_key, src_entr.real_output_in_tx_index, in_ephemeral, img);
+ std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
+ subaddresses[sender_account_keys.m_account_address.m_spend_public_key] = {0,0};
+ auto& out_key = reinterpret_cast<const crypto::public_key&>(src_entr.outputs[src_entr.real_output].second.dest);
+ generate_key_image_helper(sender_account_keys, subaddresses, out_key, src_entr.real_out_tx_key, src_entr.real_out_additional_tx_keys, src_entr.real_output_in_tx_index, in_ephemeral, img);
// put key image into tx input
txin_to_key input_to_key;
diff --git a/tests/crypto/main.cpp b/tests/crypto/main.cpp
index 4264409b5..0fc8aba59 100644
--- a/tests/crypto/main.cpp
+++ b/tests/crypto/main.cpp
@@ -52,10 +52,6 @@ bool operator !=(const ec_point &a, const ec_point &b) {
return 0 != memcmp(&a, &b, sizeof(ec_point));
}
-bool operator !=(const secret_key &a, const secret_key &b) {
- return 0 != memcmp(&a, &b, sizeof(secret_key));
-}
-
bool operator !=(const key_derivation &a, const key_derivation &b) {
return 0 != memcmp(&a, &b, sizeof(key_derivation));
}
@@ -99,7 +95,7 @@ int main(int argc, char *argv[]) {
vector<char> data;
ec_scalar expected, actual;
get(input, data, expected);
- hash_to_scalar(data.data(), data.size(), actual);
+ crypto::hash_to_scalar(data.data(), data.size(), actual);
if (expected != actual) {
goto error;
}
diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp
index 48e7b5ab6..d39b1b2e8 100644
--- a/tests/functional_tests/transactions_flow_test.cpp
+++ b/tests/functional_tests/transactions_flow_test.cpp
@@ -172,7 +172,7 @@ bool transactions_flow_test(std::string& working_folder,
//wait for money, until balance will have enough money
w1.refresh(blocks_fetched, received_money, ok);
- while(w1.unlocked_balance() < amount_to_transfer)
+ while(w1.unlocked_balance(0) < amount_to_transfer)
{
misc_utils::sleep_no_w(1000);
w1.refresh(blocks_fetched, received_money, ok);
@@ -185,7 +185,7 @@ bool transactions_flow_test(std::string& working_folder,
{
tools::wallet2::transfer_container incoming_transfers;
w1.get_transfers(incoming_transfers);
- if(incoming_transfers.size() > FIRST_N_TRANSFERS && get_money_in_first_transfers(incoming_transfers, FIRST_N_TRANSFERS) < w1.unlocked_balance() )
+ if(incoming_transfers.size() > FIRST_N_TRANSFERS && get_money_in_first_transfers(incoming_transfers, FIRST_N_TRANSFERS) < w1.unlocked_balance(0) )
{
//lets go!
size_t count = 0;
@@ -220,7 +220,7 @@ bool transactions_flow_test(std::string& working_folder,
for(i = 0; i != transactions_count; i++)
{
uint64_t amount_to_tx = (amount_to_transfer - transfered_money) > transfer_size ? transfer_size: (amount_to_transfer - transfered_money);
- while(w1.unlocked_balance() < amount_to_tx + TEST_FEE)
+ while(w1.unlocked_balance(0) < amount_to_tx + TEST_FEE)
{
misc_utils::sleep_no_w(1000);
LOG_PRINT_L0("not enough money, waiting for cashback or mining");
@@ -269,7 +269,7 @@ bool transactions_flow_test(std::string& working_folder,
misc_utils::sleep_no_w(DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN*1000);//wait two blocks before sync on another wallet on another daemon
}
- uint64_t money_2 = w2.balance();
+ uint64_t money_2 = w2.balance(0);
if(money_2 == transfered_money)
{
MGINFO_GREEN("-----------------------FINISHING TRANSACTIONS FLOW TEST OK-----------------------");
diff --git a/tests/fuzz/signature.cpp b/tests/fuzz/signature.cpp
index 69d0ad25b..071297ba8 100644
--- a/tests/fuzz/signature.cpp
+++ b/tests/fuzz/signature.cpp
@@ -66,9 +66,8 @@ int SignatureFuzzer::init()
boost::filesystem::remove("/tmp/signature-test.address.txt");
boost::filesystem::remove("/tmp/signature-test");
- bool has_payment_id;
- crypto::hash8 new_payment_id;
- if (!cryptonote::get_account_address_from_str_or_url(address, has_payment_id, new_payment_id, true, "9uVsvEryzpN8WH2t1WWhFFCG5tS8cBNdmJYNRuckLENFimfauV5pZKeS1P2CbxGkSDTUPHXWwiYE5ZGSXDAGbaZgDxobqDN"))
+ cryptonote::address_parse_info info;
+ if (!cryptonote::get_account_address_from_str_or_url(info, true, "9uVsvEryzpN8WH2t1WWhFFCG5tS8cBNdmJYNRuckLENFimfauV5pZKeS1P2CbxGkSDTUPHXWwiYE5ZGSXDAGbaZgDxobqDN"))
{
std::cerr << "failed to parse address" << std::endl;
return 1;
diff --git a/tests/libwallet_api_tests/CMakeLists.txt b/tests/libwallet_api_tests/CMakeLists.txt
index 51375440b..4c5542d91 100644
--- a/tests/libwallet_api_tests/CMakeLists.txt
+++ b/tests/libwallet_api_tests/CMakeLists.txt
@@ -40,6 +40,7 @@ add_executable(libwallet_api_tests
target_link_libraries(libwallet_api_tests
PRIVATE
wallet
+ version
epee
${Boost_CHRONO_LIBRARY}
${Boost_SERIALIZATION_LIBRARY}
diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp
index bf0483b0f..a3cf227de 100644
--- a/tests/libwallet_api_tests/main.cpp
+++ b/tests/libwallet_api_tests/main.cpp
@@ -130,7 +130,7 @@ struct Utils
{
Monero::WalletManager *wmgr = Monero::WalletManagerFactory::getWalletManager();
Monero::Wallet * w = wmgr->openWallet(filename, password, true);
- std::string result = w->address();
+ std::string result = w->mainAddress();
wmgr->closeWallet(w);
return result;
}
@@ -215,8 +215,8 @@ TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
boost::split(words, seed, boost::is_any_of(" "), boost::token_compress_on);
ASSERT_TRUE(words.size() == 25);
std::cout << "** seed: " << wallet->seed() << std::endl;
- ASSERT_FALSE(wallet->address().empty());
- std::cout << "** address: " << wallet->address() << std::endl;
+ ASSERT_FALSE(wallet->mainAddress().empty());
+ std::cout << "** address: " << wallet->mainAddress() << std::endl;
ASSERT_TRUE(wmgr->closeWallet(wallet));
}
@@ -261,7 +261,7 @@ void open_wallet_helper(Monero::WalletManager *wmgr, Monero::Wallet **wallet, co
mutex->lock();
LOG_PRINT_L3("opening wallet in thread: " << boost::this_thread::get_id());
*wallet = wmgr->openWallet(WALLET_NAME, pass, true);
- LOG_PRINT_L3("wallet address: " << (*wallet)->address());
+ LOG_PRINT_L3("wallet address: " << (*wallet)->mainAddress());
LOG_PRINT_L3("wallet status: " << (*wallet)->status());
LOG_PRINT_L3("closing wallet in thread: " << boost::this_thread::get_id());
if (mutex)
@@ -371,14 +371,14 @@ TEST_F(WalletManagerTest, WalletManagerRecoversWallet)
{
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
- std::string address1 = wallet1->address();
+ std::string address1 = wallet1->mainAddress();
ASSERT_FALSE(address1.empty());
ASSERT_TRUE(wmgr->closeWallet(wallet1));
Utils::deleteWallet(WALLET_NAME);
Monero::Wallet * wallet2 = wmgr->recoveryWallet(WALLET_NAME, seed1);
ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet2->seed() == seed1);
- ASSERT_TRUE(wallet2->address() == address1);
+ ASSERT_TRUE(wallet2->mainAddress() == address1);
ASSERT_TRUE(wmgr->closeWallet(wallet2));
}
@@ -387,7 +387,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet1)
{
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
- std::string address1 = wallet1->address();
+ std::string address1 = wallet1->mainAddress();
ASSERT_TRUE(wallet1->store(""));
ASSERT_TRUE(wallet1->store(WALLET_NAME_COPY));
@@ -395,7 +395,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet1)
Monero::Wallet * wallet2 = wmgr->openWallet(WALLET_NAME_COPY, WALLET_PASS);
ASSERT_TRUE(wallet2->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet2->seed() == seed1);
- ASSERT_TRUE(wallet2->address() == address1);
+ ASSERT_TRUE(wallet2->mainAddress() == address1);
ASSERT_TRUE(wmgr->closeWallet(wallet2));
}
@@ -404,7 +404,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet2)
{
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
- std::string address1 = wallet1->address();
+ std::string address1 = wallet1->mainAddress();
ASSERT_TRUE(wallet1->store(WALLET_NAME_WITH_DIR));
ASSERT_TRUE(wmgr->closeWallet(wallet1));
@@ -412,7 +412,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet2)
wallet1 = wmgr->openWallet(WALLET_NAME_WITH_DIR, WALLET_PASS);
ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet1->seed() == seed1);
- ASSERT_TRUE(wallet1->address() == address1);
+ ASSERT_TRUE(wallet1->mainAddress() == address1);
ASSERT_TRUE(wmgr->closeWallet(wallet1));
}
@@ -421,7 +421,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
{
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
- std::string address1 = wallet1->address();
+ std::string address1 = wallet1->mainAddress();
ASSERT_FALSE(wallet1->store(WALLET_NAME_WITH_DIR_NON_WRITABLE));
ASSERT_TRUE(wmgr->closeWallet(wallet1));
@@ -435,7 +435,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet1->seed() == seed1);
- ASSERT_TRUE(wallet1->address() == address1);
+ ASSERT_TRUE(wallet1->mainAddress() == address1);
ASSERT_TRUE(wmgr->closeWallet(wallet1));
}
@@ -445,7 +445,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet4)
{
Monero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
std::string seed1 = wallet1->seed();
- std::string address1 = wallet1->address();
+ std::string address1 = wallet1->mainAddress();
ASSERT_TRUE(wallet1->store(""));
ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
@@ -458,7 +458,7 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet4)
wallet1 = wmgr->openWallet(WALLET_NAME, WALLET_PASS);
ASSERT_TRUE(wallet1->status() == Monero::Wallet::Status_Ok);
ASSERT_TRUE(wallet1->seed() == seed1);
- ASSERT_TRUE(wallet1->address() == address1);
+ ASSERT_TRUE(wallet1->mainAddress() == address1);
ASSERT_TRUE(wmgr->closeWallet(wallet1));
}
@@ -496,18 +496,18 @@ TEST_F(WalletTest1, WalletGeneratesIntegratedAddress)
TEST_F(WalletTest1, WalletShowsBalance)
{
Monero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
- ASSERT_TRUE(wallet1->balance() > 0);
- ASSERT_TRUE(wallet1->unlockedBalance() > 0);
+ ASSERT_TRUE(wallet1->balance(0) > 0);
+ ASSERT_TRUE(wallet1->unlockedBalance(0) > 0);
- uint64_t balance1 = wallet1->balance();
- uint64_t unlockedBalance1 = wallet1->unlockedBalance();
+ uint64_t balance1 = wallet1->balance(0);
+ uint64_t unlockedBalance1 = wallet1->unlockedBalance(0);
ASSERT_TRUE(wmgr->closeWallet(wallet1));
Monero::Wallet * wallet2 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
- ASSERT_TRUE(balance1 == wallet2->balance());
- std::cout << "wallet balance: " << wallet2->balance() << std::endl;
- ASSERT_TRUE(unlockedBalance1 == wallet2->unlockedBalance());
- std::cout << "wallet unlocked balance: " << wallet2->unlockedBalance() << std::endl;
+ ASSERT_TRUE(balance1 == wallet2->balance(0));
+ std::cout << "wallet balance: " << wallet2->balance(0) << std::endl;
+ ASSERT_TRUE(unlockedBalance1 == wallet2->unlockedBalance(0));
+ std::cout << "wallet unlocked balance: " << wallet2->unlockedBalance(0) << std::endl;
ASSERT_TRUE(wmgr->closeWallet(wallet2));
}
@@ -569,7 +569,7 @@ TEST_F(WalletTest1, WalletTransaction)
// make sure testnet daemon is running
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet1->refresh());
- uint64_t balance = wallet1->balance();
+ uint64_t balance = wallet1->balance(0);
ASSERT_TRUE(wallet1->status() == Monero::PendingTransaction::Status_Ok);
std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
@@ -580,14 +580,16 @@ TEST_F(WalletTest1, WalletTransaction)
PAYMENT_ID_EMPTY,
AMOUNT_10XMR,
MIXIN_COUNT,
+ 0,
+ std::set<uint32_t>{},
Monero::PendingTransaction::Priority_Medium);
ASSERT_TRUE(transaction->status() == Monero::PendingTransaction::Status_Ok);
wallet1->refresh();
- ASSERT_TRUE(wallet1->balance() == balance);
+ ASSERT_TRUE(wallet1->balance(0) == balance);
ASSERT_TRUE(transaction->amount() == AMOUNT_10XMR);
ASSERT_TRUE(transaction->commit());
- ASSERT_FALSE(wallet1->balance() == balance);
+ ASSERT_FALSE(wallet1->balance(0) == balance);
ASSERT_TRUE(wmgr->closeWallet(wallet1));
}
@@ -611,14 +613,15 @@ TEST_F(WalletTest1, WalletTransactionWithMixin)
// make sure testnet daemon is running
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet1->refresh());
- uint64_t balance = wallet1->balance();
+ uint64_t balance = wallet1->balance(0);
ASSERT_TRUE(wallet1->status() == Monero::PendingTransaction::Status_Ok);
std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
for (auto mixin : mixins) {
std::cerr << "Transaction mixin count: " << mixin << std::endl;
+
Monero::PendingTransaction * transaction = wallet1->createTransaction(
- recepient_address, payment_id, AMOUNT_5XMR, mixin);
+ recepient_address, payment_id, AMOUNT_5XMR, mixin, 0, std::set<uint32_t>{});
std::cerr << "Transaction status: " << transaction->status() << std::endl;
std::cerr << "Transaction fee: " << Monero::Wallet::displayAmount(transaction->fee()) << std::endl;
@@ -629,7 +632,7 @@ TEST_F(WalletTest1, WalletTransactionWithMixin)
wallet1->refresh();
- ASSERT_TRUE(wallet1->balance() == balance);
+ ASSERT_TRUE(wallet1->balance(0) == balance);
ASSERT_TRUE(wmgr->closeWallet(wallet1));
}
@@ -643,7 +646,7 @@ TEST_F(WalletTest1, WalletTransactionWithPriority)
// make sure testnet daemon is running
ASSERT_TRUE(wallet1->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet1->refresh());
- uint64_t balance = wallet1->balance();
+ uint64_t balance = wallet1->balance(0);
ASSERT_TRUE(wallet1->status() == Monero::PendingTransaction::Status_Ok);
std::string recepient_address = Utils::get_wallet_address(CURRENT_DST_WALLET, TESTNET_WALLET_PASS);
@@ -658,8 +661,9 @@ TEST_F(WalletTest1, WalletTransactionWithPriority)
for (auto it = priorities.begin(); it != priorities.end(); ++it) {
std::cerr << "Transaction priority: " << *it << std::endl;
+
Monero::PendingTransaction * transaction = wallet1->createTransaction(
- recepient_address, payment_id, AMOUNT_5XMR, mixin, *it);
+ recepient_address, payment_id, AMOUNT_5XMR, mixin, 0, std::set<uint32_t>{}, *it);
std::cerr << "Transaction status: " << transaction->status() << std::endl;
std::cerr << "Transaction fee: " << Monero::Wallet::displayAmount(transaction->fee()) << std::endl;
std::cerr << "Transaction error: " << transaction->errorString() << std::endl;
@@ -669,7 +673,7 @@ TEST_F(WalletTest1, WalletTransactionWithPriority)
wallet1->disposeTransaction(transaction);
}
wallet1->refresh();
- ASSERT_TRUE(wallet1->balance() == balance);
+ ASSERT_TRUE(wallet1->balance(0) == balance);
ASSERT_TRUE(wmgr->closeWallet(wallet1));
}
@@ -715,7 +719,7 @@ TEST_F(WalletTest1, WalletTransactionAndHistory)
Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr,
PAYMENT_ID_EMPTY,
- AMOUNT_10XMR * 5, 1);
+ AMOUNT_10XMR * 5, 1, 0, std::set<uint32_t>{});
ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
ASSERT_TRUE(tx->commit());
@@ -757,7 +761,7 @@ TEST_F(WalletTest1, WalletTransactionWithPaymentId)
Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr,
payment_id,
- AMOUNT_1XMR, 1);
+ AMOUNT_1XMR, 1, 0, std::set<uint32_t>{});
ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
ASSERT_TRUE(tx->commit());
@@ -811,12 +815,12 @@ struct MyWalletListener : public Monero::WalletListener
void reset()
{
- send_triggered = receive_triggered = update_triggered = refresh_triggered = false;
+ send_triggered = receive_triggered = newblock_triggered = update_triggered = refresh_triggered = false;
}
virtual void moneySpent(const string &txId, uint64_t amount)
{
- std::cerr << "wallet: " << wallet->address() << "**** just spent money ("
+ std::cerr << "wallet: " << wallet->mainAddress() << "**** just spent money ("
<< txId << ", " << wallet->displayAmount(amount) << ")" << std::endl;
total_tx += amount;
send_triggered = true;
@@ -825,7 +829,7 @@ struct MyWalletListener : public Monero::WalletListener
virtual void moneyReceived(const string &txId, uint64_t amount)
{
- std::cout << "wallet: " << wallet->address() << "**** just received money ("
+ std::cout << "wallet: " << wallet->mainAddress() << "**** just received money ("
<< txId << ", " << wallet->displayAmount(amount) << ")" << std::endl;
total_rx += amount;
receive_triggered = true;
@@ -834,7 +838,7 @@ struct MyWalletListener : public Monero::WalletListener
virtual void unconfirmedMoneyReceived(const string &txId, uint64_t amount)
{
- std::cout << "wallet: " << wallet->address() << "**** just received unconfirmed money ("
+ std::cout << "wallet: " << wallet->mainAddress() << "**** just received unconfirmed money ("
<< txId << ", " << wallet->displayAmount(amount) << ")" << std::endl;
// Don't trigger recieve until tx is mined
// total_rx += amount;
@@ -844,7 +848,7 @@ struct MyWalletListener : public Monero::WalletListener
virtual void newBlock(uint64_t height)
{
-// std::cout << "wallet: " << wallet->address()
+// std::cout << "wallet: " << wallet->mainAddress()
// <<", new block received, blockHeight: " << height << std::endl;
static int bc_height = wallet->daemonBlockChainHeight();
std::cout << height
@@ -920,17 +924,17 @@ TEST_F(WalletTest2, WalletCallbackSent)
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet_src->refresh());
MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src);
- uint64_t balance = wallet_src->balance();
- std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance()) << std::endl;
+ uint64_t balance = wallet_src->balance(0);
+ std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance(0)) << std::endl;
Monero::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, true);
uint64_t amount = AMOUNT_1XMR * 5;
- std::cout << "** Sending " << Monero::Wallet::displayAmount(amount) << " to " << wallet_dst->address();
+ std::cout << "** Sending " << Monero::Wallet::displayAmount(amount) << " to " << wallet_dst->mainAddress();
- Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->address(),
+ Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->mainAddress(),
PAYMENT_ID_EMPTY,
- amount, 1);
+ amount, 1, 0, std::set<uint32_t>{});
std::cout << "** Committing transaction: " << Monero::Wallet::displayAmount(tx->amount())
<< " with fee: " << Monero::Wallet::displayAmount(tx->fee());
@@ -944,8 +948,8 @@ TEST_F(WalletTest2, WalletCallbackSent)
std::cerr << "TEST: send lock acquired...\n";
ASSERT_TRUE(wallet_src_listener->send_triggered);
ASSERT_TRUE(wallet_src_listener->update_triggered);
- std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance()) << std::endl;
- ASSERT_TRUE(wallet_src->balance() < balance);
+ std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance(0)) << std::endl;
+ ASSERT_TRUE(wallet_src->balance(0) < balance);
wmgr->closeWallet(wallet_src);
wmgr->closeWallet(wallet_dst);
}
@@ -958,20 +962,20 @@ TEST_F(WalletTest2, WalletCallbackReceived)
// make sure testnet daemon is running
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet_src->refresh());
- std::cout << "** Balance src1: " << wallet_src->displayAmount(wallet_src->balance()) << std::endl;
+ std::cout << "** Balance src1: " << wallet_src->displayAmount(wallet_src->balance(0)) << std::endl;
Monero::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, true);
ASSERT_TRUE(wallet_dst->init(TESTNET_DAEMON_ADDRESS, 0));
ASSERT_TRUE(wallet_dst->refresh());
- uint64_t balance = wallet_dst->balance();
- std::cout << "** Balance dst1: " << wallet_dst->displayAmount(wallet_dst->balance()) << std::endl;
+ uint64_t balance = wallet_dst->balance(0);
+ std::cout << "** Balance dst1: " << wallet_dst->displayAmount(wallet_dst->balance(0)) << std::endl;
std::unique_ptr<MyWalletListener> wallet_dst_listener (new MyWalletListener(wallet_dst));
uint64_t amount = AMOUNT_1XMR * 5;
- std::cout << "** Sending " << Monero::Wallet::displayAmount(amount) << " to " << wallet_dst->address();
- Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->address(),
+ std::cout << "** Sending " << Monero::Wallet::displayAmount(amount) << " to " << wallet_dst->mainAddress();
+ Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->mainAddress(),
PAYMENT_ID_EMPTY,
- amount, 1);
+ amount, 1, 0, std::set<uint32_t>{});
std::cout << "** Committing transaction: " << Monero::Wallet::displayAmount(tx->amount())
<< " with fee: " << Monero::Wallet::displayAmount(tx->fee());
@@ -987,10 +991,10 @@ TEST_F(WalletTest2, WalletCallbackReceived)
ASSERT_TRUE(wallet_dst_listener->receive_triggered);
ASSERT_TRUE(wallet_dst_listener->update_triggered);
- std::cout << "** Balance src2: " << wallet_dst->displayAmount(wallet_src->balance()) << std::endl;
- std::cout << "** Balance dst2: " << wallet_dst->displayAmount(wallet_dst->balance()) << std::endl;
+ std::cout << "** Balance src2: " << wallet_dst->displayAmount(wallet_src->balance(0)) << std::endl;
+ std::cout << "** Balance dst2: " << wallet_dst->displayAmount(wallet_dst->balance(0)) << std::endl;
- ASSERT_TRUE(wallet_dst->balance() > balance);
+ ASSERT_TRUE(wallet_dst->balance(0) > balance);
wmgr->closeWallet(wallet_src);
wmgr->closeWallet(wallet_dst);
@@ -1099,7 +1103,7 @@ TEST_F(WalletManagerMainnetTest, RecoverAndRefreshWalletMainNetAsync)
int SECONDS_TO_REFRESH = 120;
Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG);
std::string seed = wallet->seed();
- std::string address = wallet->address();
+ std::string address = wallet->mainAddress();
wmgr->closeWallet(wallet);
// deleting wallet files
@@ -1108,7 +1112,7 @@ TEST_F(WalletManagerMainnetTest, RecoverAndRefreshWalletMainNetAsync)
wallet = wmgr->recoveryWallet(WALLET_NAME_MAINNET, seed);
ASSERT_TRUE(wallet->status() == Monero::Wallet::Status_Ok);
- ASSERT_TRUE(wallet->address() == address);
+ ASSERT_TRUE(wallet->mainAddress() == address);
std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet));
boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH);
boost::unique_lock<boost::mutex> lock (wallet_listener->mutex);
diff --git a/tests/performance_tests/check_tx_signature.h b/tests/performance_tests/check_tx_signature.h
index 1e02bfcaa..02555fae8 100644
--- a/tests/performance_tests/check_tx_signature.h
+++ b/tests/performance_tests/check_tx_signature.h
@@ -62,10 +62,13 @@ public:
m_alice.generate();
std::vector<tx_destination_entry> destinations;
- destinations.push_back(tx_destination_entry(this->m_source_amount, m_alice.get_keys().m_account_address));
+ destinations.push_back(tx_destination_entry(this->m_source_amount, m_alice.get_keys().m_account_address, false));
crypto::secret_key tx_key;
- if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, std::vector<uint8_t>(), m_tx, 0, tx_key, rct))
+ std::vector<crypto::secret_key> additional_tx_keys;
+ std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
+ subaddresses[this->m_miners[this->real_source_idx].get_keys().m_account_address.m_spend_public_key] = {0,0};
+ if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, 0, tx_key, additional_tx_keys, rct))
return false;
get_transaction_prefix_hash(m_tx, m_tx_prefix_hash);
diff --git a/tests/performance_tests/construct_tx.h b/tests/performance_tests/construct_tx.h
index 0610c86ed..e01ee5cfa 100644
--- a/tests/performance_tests/construct_tx.h
+++ b/tests/performance_tests/construct_tx.h
@@ -43,7 +43,7 @@ class test_construct_tx : private multi_tx_test_base<a_in_count>
static_assert(0 < a_out_count, "out_count must be greater than 0");
public:
- static const size_t loop_count = (a_in_count + a_out_count < 100) ? 100 : 10;
+ static const size_t loop_count = (a_in_count + a_out_count < 10) ? (a_rct ? 10 : 200) : (a_in_count + a_out_count) < 100 ? (a_rct ? 5 : 25) : 5;
static const size_t in_count = a_in_count;
static const size_t out_count = a_out_count;
static const bool rct = a_rct;
@@ -61,7 +61,7 @@ public:
for (size_t i = 0; i < out_count; ++i)
{
- m_destinations.push_back(tx_destination_entry(this->m_source_amount / out_count, m_alice.get_keys().m_account_address));
+ m_destinations.push_back(tx_destination_entry(this->m_source_amount / out_count, m_alice.get_keys().m_account_address, false));
}
return true;
@@ -70,7 +70,10 @@ public:
bool test()
{
crypto::secret_key tx_key;
- return cryptonote::construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, m_destinations, std::vector<uint8_t>(), m_tx, 0, tx_key, rct);
+ std::vector<crypto::secret_key> additional_tx_keys;
+ std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
+ subaddresses[this->m_miners[this->real_source_idx].get_keys().m_account_address.m_spend_public_key] = {0,0};
+ return cryptonote::construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, m_destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, 0, tx_key, additional_tx_keys, rct);
}
private:
diff --git a/tests/performance_tests/derive_secret_key.h b/tests/performance_tests/derive_secret_key.h
index 1a2945a77..f97deb974 100644
--- a/tests/performance_tests/derive_secret_key.h
+++ b/tests/performance_tests/derive_secret_key.h
@@ -38,7 +38,7 @@
class test_derive_secret_key : public single_tx_test_base
{
public:
- static const size_t loop_count = 1000000;
+ static const size_t loop_count = 10000;
bool init()
{
diff --git a/tests/performance_tests/ge_frombytes_vartime.h b/tests/performance_tests/ge_frombytes_vartime.h
index 491cea097..a5e64aeb2 100644
--- a/tests/performance_tests/ge_frombytes_vartime.h
+++ b/tests/performance_tests/ge_frombytes_vartime.h
@@ -52,7 +52,7 @@ public:
m_alice.generate();
std::vector<tx_destination_entry> destinations;
- destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address));
+ destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
return construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, std::vector<uint8_t>(), m_tx, 0);
}
diff --git a/tests/performance_tests/generate_key_image_helper.h b/tests/performance_tests/generate_key_image_helper.h
index 1332e7f62..bc92303eb 100644
--- a/tests/performance_tests/generate_key_image_helper.h
+++ b/tests/performance_tests/generate_key_image_helper.h
@@ -45,6 +45,9 @@ public:
{
cryptonote::keypair in_ephemeral;
crypto::key_image ki;
- return cryptonote::generate_key_image_helper(m_bob.get_keys(), m_tx_pub_key, 0, in_ephemeral, ki);
+ std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
+ subaddresses[m_bob.get_keys().m_account_address.m_spend_public_key] = {0,0};
+ crypto::public_key out_key = boost::get<cryptonote::txout_to_key>(m_tx.vout[0].target).key;
+ return cryptonote::generate_key_image_helper(m_bob.get_keys(), subaddresses, out_key, m_tx_pub_key, m_additional_tx_pub_keys, 0, in_ephemeral, ki);
}
};
diff --git a/tests/performance_tests/is_out_to_acc.h b/tests/performance_tests/is_out_to_acc.h
index 656815db9..12ef0f79f 100644
--- a/tests/performance_tests/is_out_to_acc.h
+++ b/tests/performance_tests/is_out_to_acc.h
@@ -44,6 +44,28 @@ public:
bool test()
{
const cryptonote::txout_to_key& tx_out = boost::get<cryptonote::txout_to_key>(m_tx.vout[0].target);
- return cryptonote::is_out_to_acc(m_bob.get_keys(), tx_out, m_tx_pub_key, 0);
+ return cryptonote::is_out_to_acc(m_bob.get_keys(), tx_out, m_tx_pub_key, m_additional_tx_pub_keys, 0);
}
};
+
+class test_is_out_to_acc_precomp : public single_tx_test_base
+{
+public:
+ static const size_t loop_count = 1000;
+
+ bool init()
+ {
+ if (!single_tx_test_base::init())
+ return false;
+ crypto::generate_key_derivation(m_tx_pub_key, m_bob.get_keys().m_view_secret_key, m_derivation);
+ return true;
+ }
+ bool test()
+ {
+ const cryptonote::txout_to_key& tx_out = boost::get<cryptonote::txout_to_key>(m_tx.vout[0].target);
+ return cryptonote::is_out_to_acc_precomp(m_bob.get_keys().m_account_address.m_spend_public_key, tx_out, m_derivation, 0);
+ }
+
+private:
+ crypto::key_derivation m_derivation;
+};
diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp
index cc9fe86ef..3c0283eca 100644
--- a/tests/performance_tests/main.cpp
+++ b/tests/performance_tests/main.cpp
@@ -100,6 +100,7 @@ int main(int argc, char** argv)
TEST_PERFORMANCE2(test_check_tx_signature, 100, true);
TEST_PERFORMANCE0(test_is_out_to_acc);
+ TEST_PERFORMANCE0(test_is_out_to_acc_precomp);
TEST_PERFORMANCE0(test_generate_key_image_helper);
TEST_PERFORMANCE0(test_generate_key_derivation);
TEST_PERFORMANCE0(test_generate_key_image);
diff --git a/tests/performance_tests/single_tx_test_base.h b/tests/performance_tests/single_tx_test_base.h
index 9e38d979b..f284b4198 100644
--- a/tests/performance_tests/single_tx_test_base.h
+++ b/tests/performance_tests/single_tx_test_base.h
@@ -47,6 +47,7 @@ public:
return false;
m_tx_pub_key = get_tx_pub_key_from_extra(m_tx);
+ m_additional_tx_pub_keys = get_additional_tx_pub_keys_from_extra(m_tx);
return true;
}
@@ -54,4 +55,5 @@ protected:
cryptonote::account_base m_bob;
cryptonote::transaction m_tx;
crypto::public_key m_tx_pub_key;
+ std::vector<crypto::public_key> m_additional_tx_pub_keys;
};
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index f5e08b102..1dac92bed 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -27,6 +27,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set(unit_tests_sources
+ apply_permutation.cpp
address_from_url.cpp
ban.cpp
base58.cpp
@@ -45,6 +46,7 @@ set(unit_tests_sources
epee_utils.cpp
fee.cpp
get_xtype_from_string.cpp
+ hashchain.cpp
http.cpp
main.cpp
mnemonics.cpp
@@ -78,6 +80,7 @@ target_link_libraries(unit_tests
rpc
wallet
p2p
+ version
epee
${Boost_CHRONO_LIBRARY}
${Boost_THREAD_LIBRARY}
@@ -97,4 +100,4 @@ endif ()
add_test(
NAME unit_tests
- COMMAND unit_tests)
+ COMMAND unit_tests "${TEST_DATA_DIR}")
diff --git a/tests/unit_tests/apply_permutation.cpp b/tests/unit_tests/apply_permutation.cpp
new file mode 100644
index 000000000..a008b74ee
--- /dev/null
+++ b/tests/unit_tests/apply_permutation.cpp
@@ -0,0 +1,74 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "gtest/gtest.h"
+#include "common/apply_permutation.h"
+
+TEST(apply_permutation, empty)
+{
+ std::vector<int> v = {};
+ tools::apply_permutation({}, v);
+ ASSERT_EQ(v, std::vector<int>({}));
+}
+
+TEST(apply_permutation, reorder)
+{
+ // 0 1 2 3 4 5 6
+ std::vector<int> v = {8, 4, 6, 1, 7, 2, 4};
+ tools::apply_permutation({3, 5, 6, 1, 2, 4, 0}, v);
+ ASSERT_EQ(v, std::vector<int>({1, 2, 4, 4, 6, 7, 8}));
+}
+
+TEST(apply_permutation, bad_size)
+{
+ std::vector<int> v_large = {8, 4, 6, 1, 7, 2, 4, 9};
+ std::vector<int> v_small = {8, 4, 6, 1, 7, 2};
+ try
+ {
+ tools::apply_permutation({3, 5, 6, 1, 2, 4, 0}, v_large);
+ ASSERT_FALSE(true);
+ }
+ catch (const std::exception &e) {}
+ try
+ {
+ tools::apply_permutation({3, 5, 6, 1, 2, 4, 0}, v_small);
+ ASSERT_FALSE(true);
+ }
+ catch (const std::exception &e) {}
+}
+
+TEST(apply_permutation, bad_permutation)
+{
+ std::vector<int> v = {8, 4, 6, 1, 7, 2, 4};
+ try
+ {
+ tools::apply_permutation({3, 5, 6, 1, 2, 4, 1}, v);
+ ASSERT_FALSE(true);
+ }
+ catch (const std::exception &e) {}
+}
diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp
index 313d72e97..242e5fe1c 100644
--- a/tests/unit_tests/ban.cpp
+++ b/tests/unit_tests/ban.cpp
@@ -33,7 +33,7 @@
#include "p2p/net_node.h"
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
-#define MAKE_IPV4_ADDRESS(a,b,c,d) new epee::net_utils::ipv4_network_address(MAKE_IP(a,b,c,d),0)
+#define MAKE_IPV4_ADDRESS(a,b,c,d) epee::net_utils::ipv4_network_address{MAKE_IP(a,b,c,d),0}
namespace cryptonote {
class blockchain_storage;
@@ -51,7 +51,7 @@ public:
bool get_short_chain_history(std::list<crypto::hash>& ids) const { return true; }
bool get_stat_info(cryptonote::core_stat_info& st_inf) const {return true;}
bool have_block(const crypto::hash& id) const {return true;}
- bool get_blockchain_top(uint64_t& height, crypto::hash& top_id)const{height=0;top_id=cryptonote::null_hash;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::list<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_block(const cryptonote::blobdata& block_blob, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true) { return true; }
diff --git a/tests/unit_tests/base58.cpp b/tests/unit_tests/base58.cpp
index c9d6245cb..75a1930b5 100644
--- a/tests/unit_tests/base58.cpp
+++ b/tests/unit_tests/base58.cpp
@@ -474,43 +474,43 @@ TEST(get_account_address_as_str, works_correctly)
{
cryptonote::account_public_address addr;
ASSERT_TRUE(serialization::parse_binary(test_serialized_keys, addr));
- std::string addr_str = cryptonote::get_account_address_as_str(false, addr);
+ std::string addr_str = cryptonote::get_account_address_as_str(false, false, addr);
ASSERT_EQ(addr_str, test_keys_addr_str);
}
TEST(get_account_address_from_str, handles_valid_address)
{
- cryptonote::account_public_address addr;
- ASSERT_TRUE(cryptonote::get_account_address_from_str(addr, false, test_keys_addr_str));
+ cryptonote::address_parse_info info;
+ ASSERT_TRUE(cryptonote::get_account_address_from_str(info, false, test_keys_addr_str));
std::string blob;
- ASSERT_TRUE(serialization::dump_binary(addr, blob));
+ ASSERT_TRUE(serialization::dump_binary(info.address, blob));
ASSERT_EQ(blob, test_serialized_keys);
}
TEST(get_account_address_from_str, fails_on_invalid_address_format)
{
- cryptonote::account_public_address addr;
+ cryptonote::address_parse_info info;
std::string addr_str = test_keys_addr_str;
addr_str[0] = '0';
- ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str));
+ ASSERT_FALSE(cryptonote::get_account_address_from_str(info, false, addr_str));
}
TEST(get_account_address_from_str, fails_on_invalid_address_prefix)
{
std::string addr_str = base58::encode_addr(0, test_serialized_keys);
- cryptonote::account_public_address addr;
- ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str));
+ cryptonote::address_parse_info info;
+ ASSERT_FALSE(cryptonote::get_account_address_from_str(info, false, addr_str));
}
TEST(get_account_address_from_str, fails_on_invalid_address_content)
{
std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, test_serialized_keys.substr(1));
- cryptonote::account_public_address addr;
- ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str));
+ cryptonote::address_parse_info info;
+ ASSERT_FALSE(cryptonote::get_account_address_from_str(info, false, addr_str));
}
TEST(get_account_address_from_str, fails_on_invalid_address_spend_key)
@@ -519,8 +519,8 @@ TEST(get_account_address_from_str, fails_on_invalid_address_spend_key)
serialized_keys_copy[0] = '\0';
std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy);
- cryptonote::account_public_address addr;
- ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str));
+ cryptonote::address_parse_info info;
+ ASSERT_FALSE(cryptonote::get_account_address_from_str(info, false, addr_str));
}
TEST(get_account_address_from_str, fails_on_invalid_address_view_key)
@@ -529,12 +529,12 @@ TEST(get_account_address_from_str, fails_on_invalid_address_view_key)
serialized_keys_copy.back() = '\x01';
std::string addr_str = base58::encode_addr(config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX, serialized_keys_copy);
- cryptonote::account_public_address addr;
- ASSERT_FALSE(cryptonote::get_account_address_from_str(addr, false, addr_str));
+ cryptonote::address_parse_info info;
+ ASSERT_FALSE(cryptonote::get_account_address_from_str(info, false, addr_str));
}
TEST(get_account_address_from_str, parses_old_address_format)
{
- cryptonote::account_public_address addr;
- ASSERT_TRUE(cryptonote::get_account_address_from_str(addr, false, "002391bbbb24dea6fd95232e97594a27769d0153d053d2102b789c498f57a2b00b69cd6f2f5c529c1660f2f4a2b50178d6640c20ce71fe26373041af97c5b10236fc"));
+ cryptonote::address_parse_info info;
+ ASSERT_TRUE(cryptonote::get_account_address_from_str(info, false, "002391bbbb24dea6fd95232e97594a27769d0153d053d2102b789c498f57a2b00b69cd6f2f5c529c1660f2f4a2b50178d6640c20ce71fe26373041af97c5b10236fc"));
}
diff --git a/tests/unit_tests/checkpoints.cpp b/tests/unit_tests/checkpoints.cpp
index d3c4d3b2b..f6015db2f 100644
--- a/tests/unit_tests/checkpoints.cpp
+++ b/tests/unit_tests/checkpoints.cpp
@@ -30,7 +30,7 @@
#include "gtest/gtest.h"
-#include "cryptonote_basic/checkpoints.cpp"
+#include "checkpoints/checkpoints.cpp"
using namespace cryptonote;
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index e8ddbe3f5..f6cb0c163 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -27,6 +27,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <array>
+#include <boost/endian/conversion.hpp>
#include <boost/range/algorithm/equal.hpp>
#include <boost/range/algorithm_ext/iota.hpp>
#include <cstdint>
@@ -42,7 +43,11 @@
# include <arpa/inet.h>
#endif
+#include "boost/archive/portable_binary_iarchive.hpp"
+#include "boost/archive/portable_binary_oarchive.hpp"
#include "hex.h"
+#include "net/net_utils_base.h"
+#include "p2p/net_peerlist_boost_serialization.h"
#include "span.h"
#include "string_tools.h"
@@ -100,6 +105,40 @@ namespace
boost::range::iota(out, 0);
return out;
}
+
+ #define CHECK_EQUAL(lhs, rhs) \
+ EXPECT_TRUE( lhs == rhs ); \
+ EXPECT_TRUE( rhs == lhs ); \
+ EXPECT_FALSE( lhs != rhs ); \
+ EXPECT_FALSE( rhs != lhs ); \
+ EXPECT_FALSE( lhs < rhs ); \
+ EXPECT_FALSE( rhs < lhs ); \
+ EXPECT_TRUE( lhs <= rhs ); \
+ EXPECT_TRUE( rhs <= lhs ); \
+ EXPECT_FALSE( lhs > rhs ); \
+ EXPECT_FALSE( rhs > lhs ); \
+ EXPECT_TRUE( lhs >= rhs ); \
+ EXPECT_TRUE( rhs >= lhs )
+
+ #define CHECK_LESS(lhs, rhs) \
+ EXPECT_FALSE( lhs == rhs ); \
+ EXPECT_FALSE( rhs == lhs ); \
+ EXPECT_TRUE( lhs != rhs ); \
+ EXPECT_TRUE( rhs != lhs ); \
+ EXPECT_TRUE( lhs < rhs ); \
+ EXPECT_FALSE( rhs < lhs ); \
+ EXPECT_TRUE( lhs <= rhs ); \
+ EXPECT_FALSE( rhs <= lhs ); \
+ EXPECT_FALSE( lhs > rhs ); \
+ EXPECT_TRUE( rhs > lhs ); \
+ EXPECT_FALSE( lhs >= rhs ); \
+ EXPECT_TRUE( rhs >= lhs )
+
+ #ifdef BOOST_LITTLE_ENDIAN
+ #define CHECK_LESS_ENDIAN(lhs, rhs) CHECK_LESS( rhs , lhs )
+ #else
+ #define CHECK_LESS_ENDIAN(lhs, rhs) CHECK_LESS( lhs , rhs )
+ #endif
}
TEST(Span, Traits)
@@ -419,3 +458,195 @@ TEST(StringTools, GetIpInt32)
EXPECT_EQ(htonl(0xff0aff00), ip);
}
+TEST(NetUtils, IPv4NetworkAddress)
+{
+ const auto ip1 = boost::endian::native_to_big(0x330012FFu);
+ const auto ip_loopback = boost::endian::native_to_big(0x7F000001u);
+ const auto ip_local = boost::endian::native_to_big(0x0A000000u);
+
+ epee::net_utils::ipv4_network_address address1{ip1, 65535};
+ CHECK_EQUAL(address1, address1);
+ EXPECT_STREQ("51.0.18.255:65535", address1.str().c_str());
+ EXPECT_STREQ("51.0.18.255", address1.host_str().c_str());
+ EXPECT_FALSE(address1.is_loopback());
+ EXPECT_FALSE(address1.is_local());
+ EXPECT_EQ(epee::net_utils::ipv4_network_address::ID, address1.get_type_id());
+ EXPECT_EQ(ip1, address1.ip());
+ EXPECT_EQ(65535, address1.port());
+ EXPECT_TRUE(epee::net_utils::ipv4_network_address{std::move(address1)} == address1);
+ EXPECT_TRUE(epee::net_utils::ipv4_network_address{address1} == address1);
+
+ const epee::net_utils::ipv4_network_address loopback{ip_loopback, 0};
+ CHECK_EQUAL(loopback, loopback);
+ CHECK_LESS_ENDIAN(address1, loopback);
+ EXPECT_STREQ("127.0.0.1:0", loopback.str().c_str());
+ EXPECT_STREQ("127.0.0.1", loopback.host_str().c_str());
+ EXPECT_TRUE(loopback.is_loopback());
+ EXPECT_FALSE(loopback.is_local());
+ EXPECT_EQ(epee::net_utils::ipv4_network_address::ID, address1.get_type_id());
+ EXPECT_EQ(ip_loopback, loopback.ip());
+ EXPECT_EQ(0, loopback.port());
+
+ const epee::net_utils::ipv4_network_address local{ip_local, 8080};
+ CHECK_EQUAL(local, local);
+ CHECK_LESS(local, address1);
+ CHECK_LESS(local, loopback);
+ EXPECT_FALSE(local.is_loopback());
+ EXPECT_TRUE(local.is_local());
+
+ epee::net_utils::ipv4_network_address address2{ip1, 55};
+ CHECK_EQUAL(address2, address2);
+ CHECK_LESS_ENDIAN(address2, loopback);
+ CHECK_LESS(local, address2);
+ EXPECT_STREQ("51.0.18.255:55", address2.str().c_str());
+ EXPECT_STREQ("51.0.18.255", address2.host_str().c_str());
+
+
+ address2 = std::move(address1);
+ CHECK_EQUAL(address2, address1);
+
+ address2 = local;
+ CHECK_EQUAL(address2, local);
+ CHECK_LESS(address2, address1);
+
+ {
+ std::stringstream stream;
+ {
+ boost::archive::portable_binary_oarchive ostream{stream};
+ ostream << address1;
+ }
+ {
+ boost::archive::portable_binary_iarchive istream{stream};
+ istream >> address2;
+ }
+ }
+ CHECK_EQUAL(address1, address2);
+ EXPECT_EQ(ip1, address2.ip());
+ EXPECT_EQ(65535, address2.port());
+}
+
+TEST(NetUtils, NetworkAddress)
+{
+ const auto ip1 = boost::endian::native_to_big(0x330012FFu);
+ const auto ip_loopback = boost::endian::native_to_big(0x7F000001u);
+ const auto ip_local = boost::endian::native_to_big(0x0A000000u);
+
+ struct custom_address {
+ constexpr static bool equal(const custom_address&) noexcept { return false; }
+ constexpr static bool less(const custom_address&) noexcept { return false; }
+ constexpr static bool is_same_host(const custom_address&) noexcept { return false; }
+ constexpr static bool is_loopback() noexcept { return false; }
+ constexpr static bool is_local() noexcept { return false; }
+ static std::string str() { return {}; }
+ static std::string host_str() { return {}; }
+ constexpr static uint8_t get_type_id() noexcept { return uint8_t(-1); }
+ };
+
+ const epee::net_utils::network_address empty;
+ CHECK_EQUAL(empty, empty);
+ EXPECT_TRUE(empty.is_same_host(empty));
+ EXPECT_STREQ("<none>", empty.str().c_str());
+ EXPECT_STREQ("<none>", empty.host_str().c_str());
+ EXPECT_FALSE(empty.is_loopback());
+ EXPECT_FALSE(empty.is_local());
+ EXPECT_EQ(0, empty.get_type_id());
+ EXPECT_THROW(empty.as<custom_address>(), std::bad_cast);
+
+ epee::net_utils::network_address address1{
+ epee::net_utils::ipv4_network_address{ip1, 65535}
+ };
+ CHECK_EQUAL(address1, address1);
+ CHECK_EQUAL(epee::net_utils::network_address{address1}, address1);
+ CHECK_LESS(empty, address1);
+ EXPECT_TRUE(address1.is_same_host(address1));
+ EXPECT_FALSE(empty.is_same_host(address1));
+ EXPECT_FALSE(address1.is_same_host(empty));
+ EXPECT_STREQ("51.0.18.255:65535", address1.str().c_str());
+ EXPECT_STREQ("51.0.18.255", address1.host_str().c_str());
+ EXPECT_FALSE(address1.is_loopback());
+ EXPECT_FALSE(address1.is_local());
+ EXPECT_EQ(epee::net_utils::ipv4_network_address::ID, address1.get_type_id());
+ EXPECT_NO_THROW(address1.as<epee::net_utils::ipv4_network_address>());
+ EXPECT_THROW(address1.as<custom_address>(), std::bad_cast);
+
+ const epee::net_utils::network_address loopback{
+ epee::net_utils::ipv4_network_address{ip_loopback, 0}
+ };
+ CHECK_EQUAL(loopback, loopback);
+ CHECK_LESS(empty, loopback);
+ CHECK_LESS_ENDIAN(address1, loopback);
+ EXPECT_TRUE(loopback.is_same_host(loopback));
+ EXPECT_FALSE(loopback.is_same_host(address1));
+ EXPECT_FALSE(address1.is_same_host(loopback));
+ EXPECT_STREQ("127.0.0.1:0", loopback.str().c_str());
+ EXPECT_STREQ("127.0.0.1", loopback.host_str().c_str());
+ EXPECT_TRUE(loopback.is_loopback());
+ EXPECT_FALSE(loopback.is_local());
+ EXPECT_EQ(epee::net_utils::ipv4_network_address::ID, address1.get_type_id());
+
+ const epee::net_utils::network_address local{
+ epee::net_utils::ipv4_network_address{ip_local, 8080}
+ };
+ CHECK_EQUAL(local, local);
+ CHECK_LESS(local, loopback);
+ CHECK_LESS(local, address1);
+ EXPECT_FALSE(local.is_loopback());
+ EXPECT_TRUE(local.is_local());
+
+ epee::net_utils::network_address address2{
+ epee::net_utils::ipv4_network_address{ip1, 55}
+ };
+ CHECK_EQUAL(address2, address2);
+ CHECK_LESS(address2, address1);
+ CHECK_LESS(local, address2);
+ CHECK_LESS_ENDIAN(address2, loopback);
+ EXPECT_TRUE(address1.is_same_host(address2));
+ EXPECT_TRUE(address2.is_same_host(address1));
+ EXPECT_STREQ("51.0.18.255:55", address2.str().c_str());
+ EXPECT_STREQ("51.0.18.255", address2.host_str().c_str());
+
+ address2 = std::move(address1);
+ CHECK_EQUAL(address1, address1);
+ CHECK_EQUAL(empty, address1);
+ CHECK_LESS(address1, address2);
+ EXPECT_FALSE(address1.is_same_host(address2));
+ EXPECT_FALSE(address2.is_same_host(address1));
+ EXPECT_STREQ("51.0.18.255:65535", address2.str().c_str());
+ EXPECT_STREQ("51.0.18.255", address2.host_str().c_str());
+ EXPECT_FALSE(address1.is_loopback());
+ EXPECT_FALSE(address1.is_local());
+ EXPECT_THROW(address1.as<epee::net_utils::ipv4_network_address>(), std::bad_cast);
+ EXPECT_NO_THROW(address2.as<epee::net_utils::ipv4_network_address>());
+
+ address2 = local;
+ CHECK_EQUAL(address2, local);
+ CHECK_LESS(address1, address2);
+ EXPECT_TRUE(address2.is_same_host(local));
+ EXPECT_TRUE(local.is_same_host(address2));
+ EXPECT_FALSE(address2.is_same_host(address1));
+ EXPECT_FALSE(address1.is_same_host(address2));
+
+ {
+ std::stringstream stream;
+ {
+ boost::archive::portable_binary_oarchive ostream{stream};
+ ostream << address2;
+ }
+ {
+ boost::archive::portable_binary_iarchive istream{stream};
+ istream >> address1;
+ }
+ }
+ CHECK_EQUAL(address1, address2);
+ EXPECT_TRUE(address1.is_same_host(address2));
+ EXPECT_TRUE(address2.is_same_host(address1));
+ EXPECT_NO_THROW(address1.as<epee::net_utils::ipv4_network_address>());
+
+ address1 = custom_address{};
+ CHECK_EQUAL(address1, address1);
+ CHECK_LESS(address2, address1);
+ EXPECT_FALSE(address1.is_same_host(loopback));
+ EXPECT_FALSE(loopback.is_same_host(address1));
+ EXPECT_THROW(address1.as<epee::net_utils::ipv4_network_address>(), std::bad_cast);
+ EXPECT_NO_THROW(address1.as<custom_address>());
+}
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index c30feb461..2b0904224 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -53,7 +53,7 @@ public:
virtual std::string get_db_name() const { return std::string(); }
virtual bool lock() { return true; }
virtual void unlock() { }
- virtual bool batch_start(uint64_t batch_num_blocks=0) { return true; }
+ virtual bool batch_start(uint64_t batch_num_blocks=0, uint64_t batch_bytes=0) { return true; }
virtual void batch_stop() {}
virtual void set_batch_transactions(bool) {}
virtual void block_txn_start(bool readonly=false) {}
diff --git a/tests/unit_tests/hashchain.cpp b/tests/unit_tests/hashchain.cpp
new file mode 100644
index 000000000..0fa0f784a
--- /dev/null
+++ b/tests/unit_tests/hashchain.cpp
@@ -0,0 +1,129 @@
+// Copyright (c) 2014-2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// FIXME: move this into a full wallet2 unit test suite, if possible
+
+#include "gtest/gtest.h"
+
+#include "wallet/wallet2.h"
+
+static crypto::hash make_hash(uint64_t n)
+{
+ union
+ {
+ crypto::hash hash;
+ uint64_t n;
+ } hash;
+ hash.hash = crypto::null_hash;
+ hash.n = n;
+ return hash.hash;
+}
+
+TEST(hashchain, empty)
+{
+ tools::hashchain hashchain;
+ ASSERT_EQ(hashchain.size(), 0);
+ ASSERT_EQ(hashchain.offset(), 0);
+}
+
+TEST(hashchain, genesis)
+{
+ tools::hashchain hashchain;
+ hashchain.push_back(make_hash(1));
+ ASSERT_EQ(hashchain.size(), 1);
+ ASSERT_EQ(hashchain.genesis(), make_hash(1));
+ hashchain.push_back(make_hash(2));
+ ASSERT_EQ(hashchain.size(), 2);
+ ASSERT_EQ(hashchain.genesis(), make_hash(1));
+}
+
+TEST(hashchain, push_back)
+{
+ tools::hashchain hashchain;
+ hashchain.push_back(make_hash(1));
+ hashchain.push_back(make_hash(2));
+ hashchain.push_back(make_hash(3));
+ ASSERT_EQ(hashchain[0], make_hash(1));
+ ASSERT_EQ(hashchain[1], make_hash(2));
+ ASSERT_EQ(hashchain[2], make_hash(3));
+}
+
+TEST(hashchain, clear_empty)
+{
+ tools::hashchain hashchain;
+ ASSERT_TRUE(hashchain.empty());
+ hashchain.push_back(make_hash(1));
+ ASSERT_FALSE(hashchain.empty());
+ hashchain.push_back(make_hash(2));
+ ASSERT_FALSE(hashchain.empty());
+ hashchain.clear();
+ ASSERT_TRUE(hashchain.empty());
+}
+
+TEST(hashchain, crop)
+{
+ tools::hashchain hashchain;
+ hashchain.push_back(make_hash(1));
+ hashchain.push_back(make_hash(2));
+ hashchain.push_back(make_hash(3));
+ ASSERT_EQ(hashchain.size(), 3);
+ ASSERT_EQ(hashchain[0], make_hash(1));
+ ASSERT_EQ(hashchain[1], make_hash(2));
+ ASSERT_EQ(hashchain[2], make_hash(3));
+ hashchain.crop(3);
+ ASSERT_EQ(hashchain.size(), 3);
+ hashchain.crop(2);
+ ASSERT_EQ(hashchain.size(), 2);
+ ASSERT_EQ(hashchain[0], make_hash(1));
+ ASSERT_EQ(hashchain[1], make_hash(2));
+ ASSERT_EQ(hashchain.genesis(), make_hash(1));
+ hashchain.crop(0);
+ ASSERT_TRUE(hashchain.empty());
+ ASSERT_EQ(hashchain.size(), 0);
+ hashchain.push_back(make_hash(5));
+ ASSERT_EQ(hashchain.genesis(), make_hash(5));
+ ASSERT_EQ(hashchain.size(), 1);
+}
+
+TEST(hashchain, trim)
+{
+ tools::hashchain hashchain;
+ hashchain.push_back(make_hash(1));
+ hashchain.push_back(make_hash(2));
+ hashchain.push_back(make_hash(3));
+ ASSERT_EQ(hashchain.offset(), 0);
+ hashchain.trim(2);
+ ASSERT_EQ(hashchain.offset(), 2);
+ ASSERT_EQ(hashchain.size(), 3);
+ ASSERT_EQ(hashchain[2], make_hash(3));
+ hashchain.trim(3);
+ ASSERT_EQ(hashchain.offset(), 3);
+ ASSERT_EQ(hashchain.size(), 3);
+ ASSERT_FALSE(hashchain.empty());
+ ASSERT_EQ(hashchain.genesis(), make_hash(1));
+}
diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp
index b470249a3..b2abad942 100644
--- a/tests/unit_tests/main.cpp
+++ b/tests/unit_tests/main.cpp
@@ -30,14 +30,32 @@
#include "gtest/gtest.h"
+#include <boost/filesystem.hpp>
+
#include "include_base_utils.h"
+#include "unit_tests_utils.h"
+
+boost::filesystem::path unit_test::data_dir;
int main(int argc, char** argv)
{
- epee::string_tools::set_module_name_and_folder(argv[0]);
mlog_configure(mlog_get_default_log_path("unit_tests.log"), true);
epee::debug::get_set_enable_assert(true, false);
::testing::InitGoogleTest(&argc, argv);
+
+ // Process remaining arguments
+ if (argc == 2 && argv[1] != NULL) { // one arg: path to dir with test data
+ unit_test::data_dir = argv[1];
+ } else if (argc == 1) { // legacy: assume test binaries in 'build/release'
+ epee::string_tools::set_module_name_and_folder(argv[0]);
+ unit_test::data_dir = boost::filesystem::path(epee::string_tools::get_current_module_folder())
+ .parent_path().parent_path().parent_path().parent_path()
+ .append("tests").append("data");
+ } else {
+ std::cerr << "Usage: " << argv[0] << " [<path-to-test-data-dir>]" << std::endl;
+ return 1;
+ }
+
return RUN_ALL_TESTS();
}
diff --git a/tests/unit_tests/output_selection.cpp b/tests/unit_tests/output_selection.cpp
index ed436dffd..6ff73b107 100644
--- a/tests/unit_tests/output_selection.cpp
+++ b/tests/unit_tests/output_selection.cpp
@@ -42,7 +42,7 @@ static tools::wallet2::transfer_container make_transfers_container(size_t N)
tools::wallet2::transfer_details &td = transfers.back();
td.m_block_height = 1000;
td.m_spent = false;
- td.m_txid = cryptonote::null_hash;
+ td.m_txid = crypto::null_hash;
td.m_txid.data[0] = n & 0xff;
td.m_txid.data[1] = (n >> 8) & 0xff;
td.m_txid.data[2] = (n >> 16) & 0xff;
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp
index 6f9fe7d11..202c8718f 100644
--- a/tests/unit_tests/serialization.cpp
+++ b/tests/unit_tests/serialization.cpp
@@ -47,6 +47,7 @@
#include "serialization/binary_utils.h"
#include "wallet/wallet2.h"
#include "gtest/gtest.h"
+#include "unit_tests_utils.h"
using namespace std;
struct Struct
@@ -671,12 +672,12 @@ TEST(Serialization, portability_wallet)
const bool testnet = true;
const bool restricted = false;
tools::wallet2 w(testnet, restricted);
- string wallet_file = epee::string_tools::get_current_module_folder() + "/../../../../tests/data/wallet_9svHk1";
+ const boost::filesystem::path wallet_file = unit_test::data_dir / "wallet_9svHk1";
string password = "test";
bool r = false;
try
{
- w.load(wallet_file, password);
+ w.load(wallet_file.native(), password);
r = true;
}
catch (const exception& e)
@@ -791,9 +792,9 @@ TEST(Serialization, portability_wallet)
TEST(Serialization, portability_outputs)
{
// read file
- const std::string filename = epee::string_tools::get_current_module_folder() + "/../../../../tests/data/outputs";
+ const boost::filesystem::path filename = unit_test::data_dir / "outputs";
std::string data;
- bool r = epee::file_io_utils::load_file_to_string(filename, data);
+ bool r = epee::file_io_utils::load_file_to_string(filename.native(), data);
ASSERT_TRUE(r);
const size_t magiclen = strlen(OUTPUT_EXPORT_FILE_MAGIC);
ASSERT_FALSE(data.size() < magiclen || memcmp(data.data(), OUTPUT_EXPORT_FILE_MAGIC, magiclen));
@@ -906,10 +907,10 @@ TEST(Serialization, portability_outputs)
#define UNSIGNED_TX_PREFIX "Monero unsigned tx set\003"
TEST(Serialization, portability_unsigned_tx)
{
- const string filename = epee::string_tools::get_current_module_folder() + "/../../../../tests/data/unsigned_monero_tx";
+ const boost::filesystem::path filename = unit_test::data_dir / "unsigned_monero_tx";
std::string s;
const bool testnet = true;
- bool r = epee::file_io_utils::load_file_to_string(filename, s);
+ bool r = epee::file_io_utils::load_file_to_string(filename.native(), s);
ASSERT_TRUE(r);
const size_t magiclen = strlen(UNSIGNED_TX_PREFIX);
ASSERT_FALSE(strncmp(s.c_str(), UNSIGNED_TX_PREFIX, magiclen));
@@ -986,15 +987,15 @@ TEST(Serialization, portability_unsigned_tx)
ASSERT_TRUE(epee::string_tools::pod_to_hex(tse.mask) == "789bafff169ef206aa21219342c69ca52ce1d78d776c10b21d14bdd960fc7703");
// tcd.change_dts
ASSERT_TRUE(tcd.change_dts.amount == 9631208773403);
- ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, tcd.change_dts.addr) == "9svHk1wHPo3ULf2AZykghzcye6sitaRE4MaDjPC6uanTHCynHjJHZaiAb922PojE1GexhhRt1LVf5DC43feyrRZMLXQr3mk");
+ ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, false, tcd.change_dts.addr) == "9svHk1wHPo3ULf2AZykghzcye6sitaRE4MaDjPC6uanTHCynHjJHZaiAb922PojE1GexhhRt1LVf5DC43feyrRZMLXQr3mk");
// tcd.splitted_dsts
ASSERT_TRUE(tcd.splitted_dsts.size() == 2);
auto& splitted_dst0 = tcd.splitted_dsts[0];
auto& splitted_dst1 = tcd.splitted_dsts[1];
ASSERT_TRUE(splitted_dst0.amount == 1400000000000);
ASSERT_TRUE(splitted_dst1.amount == 9631208773403);
- ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, splitted_dst0.addr) == "9xnhrMczQkPeoGi6dyu6BgKAYX4tZsDs6KHCkyTStDBKL4M4pM1gfCR3utmTAcSaKHGa1R5o266FbdnubErmij3oMdLyYgA");
- ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, splitted_dst1.addr) == "9svHk1wHPo3ULf2AZykghzcye6sitaRE4MaDjPC6uanTHCynHjJHZaiAb922PojE1GexhhRt1LVf5DC43feyrRZMLXQr3mk");
+ ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, false, splitted_dst0.addr) == "9xnhrMczQkPeoGi6dyu6BgKAYX4tZsDs6KHCkyTStDBKL4M4pM1gfCR3utmTAcSaKHGa1R5o266FbdnubErmij3oMdLyYgA");
+ ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, false, splitted_dst1.addr) == "9svHk1wHPo3ULf2AZykghzcye6sitaRE4MaDjPC6uanTHCynHjJHZaiAb922PojE1GexhhRt1LVf5DC43feyrRZMLXQr3mk");
// tcd.selected_transfers
ASSERT_TRUE(tcd.selected_transfers.size() == 1);
ASSERT_TRUE(tcd.selected_transfers.front() == 2);
@@ -1007,7 +1008,7 @@ TEST(Serialization, portability_unsigned_tx)
ASSERT_TRUE(tcd.dests.size() == 1);
auto& dest = tcd.dests[0];
ASSERT_TRUE(dest.amount == 1400000000000);
- ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, dest.addr) == "9xnhrMczQkPeoGi6dyu6BgKAYX4tZsDs6KHCkyTStDBKL4M4pM1gfCR3utmTAcSaKHGa1R5o266FbdnubErmij3oMdLyYgA");
+ ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, false, dest.addr) == "9xnhrMczQkPeoGi6dyu6BgKAYX4tZsDs6KHCkyTStDBKL4M4pM1gfCR3utmTAcSaKHGa1R5o266FbdnubErmij3oMdLyYgA");
// transfers
ASSERT_TRUE(exported_txs.transfers.size() == 3);
auto& td0 = exported_txs.transfers[0];
@@ -1054,10 +1055,10 @@ TEST(Serialization, portability_unsigned_tx)
#define SIGNED_TX_PREFIX "Monero signed tx set\003"
TEST(Serialization, portability_signed_tx)
{
- const string filename = epee::string_tools::get_current_module_folder() + "/../../../../tests/data/signed_monero_tx";
+ const boost::filesystem::path filename = unit_test::data_dir / "signed_monero_tx";
const bool testnet = true;
std::string s;
- bool r = epee::file_io_utils::load_file_to_string(filename, s);
+ bool r = epee::file_io_utils::load_file_to_string(filename.native(), s);
ASSERT_TRUE(r);
const size_t magiclen = strlen(SIGNED_TX_PREFIX);
ASSERT_FALSE(strncmp(s.c_str(), SIGNED_TX_PREFIX, magiclen));
@@ -1100,7 +1101,7 @@ TEST(Serialization, portability_signed_tx)
ASSERT_FALSE(ptx.dust_added_to_fee);
// ptx.change.{amount, addr}
ASSERT_TRUE(ptx.change_dts.amount == 9631208773403);
- ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, ptx.change_dts.addr) == "9svHk1wHPo3ULf2AZykghzcye6sitaRE4MaDjPC6uanTHCynHjJHZaiAb922PojE1GexhhRt1LVf5DC43feyrRZMLXQr3mk");
+ ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, false, ptx.change_dts.addr) == "9svHk1wHPo3ULf2AZykghzcye6sitaRE4MaDjPC6uanTHCynHjJHZaiAb922PojE1GexhhRt1LVf5DC43feyrRZMLXQr3mk");
// ptx.selected_transfers
ASSERT_TRUE(ptx.selected_transfers.size() == 1);
ASSERT_TRUE(ptx.selected_transfers.front() == 2);
@@ -1110,7 +1111,7 @@ TEST(Serialization, portability_signed_tx)
// ptx.dests
ASSERT_TRUE(ptx.dests.size() == 1);
ASSERT_TRUE(ptx.dests[0].amount == 1400000000000);
- ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, ptx.dests[0].addr) == "9xnhrMczQkPeoGi6dyu6BgKAYX4tZsDs6KHCkyTStDBKL4M4pM1gfCR3utmTAcSaKHGa1R5o266FbdnubErmij3oMdLyYgA");
+ ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, false, ptx.dests[0].addr) == "9xnhrMczQkPeoGi6dyu6BgKAYX4tZsDs6KHCkyTStDBKL4M4pM1gfCR3utmTAcSaKHGa1R5o266FbdnubErmij3oMdLyYgA");
// ptx.construction_data
auto& tcd = ptx.construction_data;
ASSERT_TRUE(tcd.sources.size() == 1);
@@ -1141,15 +1142,15 @@ TEST(Serialization, portability_signed_tx)
ASSERT_TRUE(epee::string_tools::pod_to_hex(tse.mask) == "789bafff169ef206aa21219342c69ca52ce1d78d776c10b21d14bdd960fc7703");
// ptx.construction_data.change_dts
ASSERT_TRUE(tcd.change_dts.amount == 9631208773403);
- ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, tcd.change_dts.addr) == "9svHk1wHPo3ULf2AZykghzcye6sitaRE4MaDjPC6uanTHCynHjJHZaiAb922PojE1GexhhRt1LVf5DC43feyrRZMLXQr3mk");
+ ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, false, tcd.change_dts.addr) == "9svHk1wHPo3ULf2AZykghzcye6sitaRE4MaDjPC6uanTHCynHjJHZaiAb922PojE1GexhhRt1LVf5DC43feyrRZMLXQr3mk");
// ptx.construction_data.splitted_dsts
ASSERT_TRUE(tcd.splitted_dsts.size() == 2);
auto& splitted_dst0 = tcd.splitted_dsts[0];
auto& splitted_dst1 = tcd.splitted_dsts[1];
ASSERT_TRUE(splitted_dst0.amount == 1400000000000);
ASSERT_TRUE(splitted_dst1.amount == 9631208773403);
- ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, splitted_dst0.addr) == "9xnhrMczQkPeoGi6dyu6BgKAYX4tZsDs6KHCkyTStDBKL4M4pM1gfCR3utmTAcSaKHGa1R5o266FbdnubErmij3oMdLyYgA");
- ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, splitted_dst1.addr) == "9svHk1wHPo3ULf2AZykghzcye6sitaRE4MaDjPC6uanTHCynHjJHZaiAb922PojE1GexhhRt1LVf5DC43feyrRZMLXQr3mk");
+ ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, false, splitted_dst0.addr) == "9xnhrMczQkPeoGi6dyu6BgKAYX4tZsDs6KHCkyTStDBKL4M4pM1gfCR3utmTAcSaKHGa1R5o266FbdnubErmij3oMdLyYgA");
+ ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, false, splitted_dst1.addr) == "9svHk1wHPo3ULf2AZykghzcye6sitaRE4MaDjPC6uanTHCynHjJHZaiAb922PojE1GexhhRt1LVf5DC43feyrRZMLXQr3mk");
// ptx.construction_data.selected_transfers
ASSERT_TRUE(tcd.selected_transfers.size() == 1);
ASSERT_TRUE(tcd.selected_transfers.front() == 2);
@@ -1162,7 +1163,7 @@ TEST(Serialization, portability_signed_tx)
ASSERT_TRUE(tcd.dests.size() == 1);
auto& dest = tcd.dests[0];
ASSERT_TRUE(dest.amount == 1400000000000);
- ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, dest.addr) == "9xnhrMczQkPeoGi6dyu6BgKAYX4tZsDs6KHCkyTStDBKL4M4pM1gfCR3utmTAcSaKHGa1R5o266FbdnubErmij3oMdLyYgA");
+ ASSERT_TRUE(cryptonote::get_account_address_as_str(testnet, false, dest.addr) == "9xnhrMczQkPeoGi6dyu6BgKAYX4tZsDs6KHCkyTStDBKL4M4pM1gfCR3utmTAcSaKHGa1R5o266FbdnubErmij3oMdLyYgA");
// key_images
ASSERT_TRUE(exported_txs.key_images.size() == 3);
auto& ki0 = exported_txs.key_images[0];
diff --git a/tests/unit_tests/test_peerlist.cpp b/tests/unit_tests/test_peerlist.cpp
index 4a546b50d..849020d25 100644
--- a/tests/unit_tests/test_peerlist.cpp
+++ b/tests/unit_tests/test_peerlist.cpp
@@ -38,7 +38,7 @@ TEST(peer_list, peer_list_general)
{
nodetool::peerlist_manager plm;
plm.init(false);
-#define MAKE_IPV4_ADDRESS(a,b,c,d,e) new epee::net_utils::ipv4_network_address(MAKE_IP(a,b,c,d),e)
+#define MAKE_IPV4_ADDRESS(a,b,c,d,e) epee::net_utils::ipv4_network_address{MAKE_IP(a,b,c,d),e}
#define ADD_GRAY_NODE(addr_, id_, last_seen_) { nodetool::peerlist_entry ple; ple.last_seen=last_seen_;ple.adr = addr_; ple.id = id_;plm.append_with_peer_gray(ple);}
#define ADD_WHITE_NODE(addr_, id_, last_seen_) { nodetool::peerlist_entry ple;ple.last_seen=last_seen_; ple.adr = addr_; ple.id = id_;plm.append_with_peer_white(ple);}
diff --git a/tests/unit_tests/test_tx_utils.cpp b/tests/unit_tests/test_tx_utils.cpp
index 0ff91c247..4ce62e2f5 100644
--- a/tests/unit_tests/test_tx_utils.cpp
+++ b/tests/unit_tests/test_tx_utils.cpp
@@ -141,7 +141,7 @@ TEST(parse_and_validate_tx_extra, is_valid_tx_extra_parsed)
cryptonote::blobdata b = "dsdsdfsdfsf";
ASSERT_TRUE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, TEST_FEE, acc.get_keys().m_account_address, tx, b, 1));
crypto::public_key tx_pub_key = cryptonote::get_tx_pub_key_from_extra(tx);
- ASSERT_NE(tx_pub_key, cryptonote::null_pkey);
+ ASSERT_NE(tx_pub_key, crypto::null_pkey);
}
TEST(parse_and_validate_tx_extra, fails_on_big_extra_nonce)
{
diff --git a/tests/unit_tests/unit_tests_utils.h b/tests/unit_tests/unit_tests_utils.h
index 11230c0db..a07eaf02b 100644
--- a/tests/unit_tests/unit_tests_utils.h
+++ b/tests/unit_tests/unit_tests_utils.h
@@ -31,9 +31,12 @@
#pragma once
#include <atomic>
+#include <boost/filesystem.hpp>
namespace unit_test
{
+ extern boost::filesystem::path data_dir;
+
class call_counter
{
public: