aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/README.md117
-rw-r--r--tests/core_tests/block_validation.cpp4
-rw-r--r--tests/core_tests/chaingen.cpp2
-rw-r--r--tests/core_tests/double_spend.inl2
-rw-r--r--tests/core_tests/integer_overflow.cpp5
-rw-r--r--tests/core_tests/transaction_tests.cpp2
-rw-r--r--tests/core_tests/v2_tests.cpp2
-rw-r--r--tests/libwallet_api_tests/main.cpp16
-rw-r--r--tests/net_load_tests/clt.cpp9
-rw-r--r--tests/net_load_tests/net_load_tests.h5
-rw-r--r--tests/net_load_tests/srv.cpp4
-rw-r--r--tests/performance_tests/ge_frombytes_vartime.h2
-rw-r--r--tests/performance_tests/is_out_to_acc.h1
-rw-r--r--tests/unit_tests/CMakeLists.txt1
-rw-r--r--tests/unit_tests/crypto.cpp28
-rw-r--r--tests/unit_tests/epee_levin_protocol_handler_async.cpp8
-rw-r--r--tests/unit_tests/hardfork.cpp4
-rw-r--r--tests/unit_tests/sha256.cpp2
-rw-r--r--tests/unit_tests/subaddress.cpp118
19 files changed, 303 insertions, 29 deletions
diff --git a/tests/README.md b/tests/README.md
new file mode 100644
index 000000000..48a6c41a7
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,117 @@
+# Running all tests
+
+To run all tests, run:
+
+```
+cd /path/to/monero
+make [-jn] debug-test # where n is number of compiler processes
+```
+
+To test a release build, replace `debug-test` with `release-test` in the previous command.
+
+# Core tests
+
+Core tests take longer than any other Monero tests, due to the high amount of computational work involved in validating core components.
+
+Tests are located in `tests/core_tests/`, and follow a straightforward naming convention. Most cases cover core functionality (`block_reward.cpp`, `chaingen.cpp`, `rct.cpp`, etc.), while some cover basic security tests (`double_spend.cpp` & `integer_overflow.cpp`).
+
+To run only Monero's core tests (after building):
+
+```
+cd build/debug/tests/core
+ctest
+```
+
+To run the same tests on a release build, replace `debug` with `release`.
+
+
+# Crypto Tests
+
+Crypto tests are located under the `tests/crypto` directory.
+
+- `crypto-tests.h` contains test harness headers
+- `main.cpp` implements the driver for the crypto tests
+
+Tests correspond to components under `src/crypto/`. A quick comparison reveals the pattern, and new tests should continue the naming convention.
+
+To run only Monero's crypto tests (after building):
+
+```
+cd build/debug/tests/crypto
+ctest
+```
+
+To run the same tests on a release build, replace `debug` with `release`.
+
+# Daemon tests
+
+[TODO]
+
+# Functional tests
+
+[TODO]
+
+# Fuzz tests
+
+Fuzz tests are written using American Fuzzy Lop (AFL), and located under the `tests/fuzz` directory.
+
+An additional helper utility is provided `contrib/fuzz_testing/fuzz.sh`. AFL must be installed, and some additional setup may be necessary for the script to run properly.
+
+# Hash tests
+
+Hash tests exist under `tests/hash`, and include a set of target hashes in text files.
+
+To run only Monero's hash tests (after building):
+
+```
+cd build/debug/tests/hash
+ctest
+```
+
+To run the same tests on a release build, replace `debug` with `release`.
+
+# Libwallet API tests
+
+[TODO]
+
+# Net Load tests
+
+[TODO]
+
+# Performance tests
+
+Performance tests are located in `tests/performance_tests`, and test features for performance metrics on the host machine.
+
+To run only Monero's performance tests (after building):
+
+```
+cd build/debug/tests/performance_tests
+./performance_tests
+```
+
+If the `performance_tests` binary does not exist, try running `make` in the `build/debug/tests/performance_tests` directory.
+
+To run the same tests on a release build, replace `debug` with `release`.
+
+# Unit tests
+
+Unit tests are defined under the `tests/unit_tests` directory. Independent components are tested individually to ensure they work properly on their own.
+
+To run only Monero's unit tests (after building):
+
+```
+cd build/debug/tests/unit_tests
+ctest
+```
+
+To run the same tests on a release build, replace `debug` with `release`.
+
+# Writing new tests
+
+## Test hygiene
+
+When writing new tests, please implement all functions in `.cpp` or `.c` files, and only put function headers in `.h` files. This will help keep the fairly complex test suites somewhat sane going forward.
+
+## Writing fuzz tests
+
+[TODO]
diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp
index 527059141..db44cd279 100644
--- a/tests/core_tests/block_validation.cpp
+++ b/tests/core_tests/block_validation.cpp
@@ -350,7 +350,7 @@ bool gen_block_miner_tx_has_2_in::generate(std::vector<test_event_entry>& events
destinations.push_back(de);
transaction tmp_tx;
- if (!construct_tx(miner_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tmp_tx, 0))
+ if (!construct_tx(miner_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tmp_tx, 0))
return false;
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
@@ -393,7 +393,7 @@ bool gen_block_miner_tx_with_txin_to_key::generate(std::vector<test_event_entry>
destinations.push_back(de);
transaction tmp_tx;
- if (!construct_tx(miner_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tmp_tx, 0))
+ if (!construct_tx(miner_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tmp_tx, 0))
return false;
MAKE_MINER_TX_MANUALLY(miner_tx, blk_1);
diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp
index f23aa8ecb..2b713cab9 100644
--- a/tests/core_tests/chaingen.cpp
+++ b/tests/core_tests/chaingen.cpp
@@ -563,7 +563,7 @@ bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote
vector<tx_destination_entry> destinations;
fill_tx_sources_and_destinations(events, blk_head, from, to, amount, fee, nmix, sources, destinations);
- return construct_tx(from.get_keys(), sources, destinations, std::vector<uint8_t>(), tx, 0);
+ return construct_tx(from.get_keys(), sources, destinations, from.get_keys().m_account_address, std::vector<uint8_t>(), tx, 0);
}
transaction construct_tx_with_fee(std::vector<test_event_entry>& events, const block& blk_head,
diff --git a/tests/core_tests/double_spend.inl b/tests/core_tests/double_spend.inl
index 438e39e47..bf63503ae 100644
--- a/tests/core_tests/double_spend.inl
+++ b/tests/core_tests/double_spend.inl
@@ -144,7 +144,7 @@ bool gen_double_spend_in_tx<txs_keeped_by_block>::generate(std::vector<test_even
destinations.push_back(de);
cryptonote::transaction tx_1;
- if (!construct_tx(bob_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tx_1, 0))
+ if (!construct_tx(bob_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_1, 0))
return false;
SET_EVENT_VISITOR_SETT(events, event_visitor_settings::set_txs_keeped_by_block, txs_keeped_by_block);
diff --git a/tests/core_tests/integer_overflow.cpp b/tests/core_tests/integer_overflow.cpp
index 3ac55c073..5a9604fc1 100644
--- a/tests/core_tests/integer_overflow.cpp
+++ b/tests/core_tests/integer_overflow.cpp
@@ -65,6 +65,7 @@ namespace
se.real_output = 0;
se.rct = false;
se.real_out_tx_key = get_tx_pub_key_from_extra(tx);
+ se.real_out_additional_tx_keys = get_additional_tx_pub_keys_from_extra(tx);
se.real_output_in_tx_index = out_idx;
sources.push_back(se);
@@ -175,7 +176,7 @@ bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const
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))
+ if (!construct_tx(miner_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_1, 0))
return false;
events.push_back(tx_1);
@@ -201,7 +202,7 @@ bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const
destinations.push_back(de);
cryptonote::transaction tx_2;
- if (!construct_tx(bob_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tx_2, 0))
+ if (!construct_tx(bob_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_2, 0))
return false;
events.push_back(tx_2);
diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp
index dcba36e80..00c602103 100644
--- a/tests/core_tests/transaction_tests.cpp
+++ b/tests/core_tests/transaction_tests.cpp
@@ -108,7 +108,7 @@ bool test_transaction_generation_and_ring_signature()
destinations.push_back(td);
transaction tx_rc1;
- bool r = construct_tx(miner_acc2.get_keys(), sources, destinations, std::vector<uint8_t>(), tx_rc1, 0);
+ bool r = construct_tx(miner_acc2.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_rc1, 0);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
crypto::hash pref_hash = get_transaction_prefix_hash(tx_rc1);
diff --git a/tests/core_tests/v2_tests.cpp b/tests/core_tests/v2_tests.cpp
index f1256cb64..6c94ac76c 100644
--- a/tests/core_tests/v2_tests.cpp
+++ b/tests/core_tests/v2_tests.cpp
@@ -108,7 +108,7 @@ bool gen_v2_tx_validation_base::generate_with(std::vector<test_event_entry>& eve
destinations.push_back(td);
transaction tx;
- bool r = construct_tx(miner_accounts[0].get_keys(), sources, destinations, std::vector<uint8_t>(), tx, 0);
+ bool r = construct_tx(miner_accounts[0].get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx, 0);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
if (!valid)
DO_CALLBACK(events, "mark_invalid_tx");
diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp
index a3cf227de..853ad7c8d 100644
--- a/tests/libwallet_api_tests/main.cpp
+++ b/tests/libwallet_api_tests/main.cpp
@@ -580,9 +580,9 @@ TEST_F(WalletTest1, WalletTransaction)
PAYMENT_ID_EMPTY,
AMOUNT_10XMR,
MIXIN_COUNT,
+ Monero::PendingTransaction::Priority_Medium,
0,
- std::set<uint32_t>{},
- Monero::PendingTransaction::Priority_Medium);
+ std::set<uint32_t>{});
ASSERT_TRUE(transaction->status() == Monero::PendingTransaction::Status_Ok);
wallet1->refresh();
@@ -621,7 +621,7 @@ TEST_F(WalletTest1, WalletTransactionWithMixin)
std::cerr << "Transaction mixin count: " << mixin << std::endl;
Monero::PendingTransaction * transaction = wallet1->createTransaction(
- recepient_address, payment_id, AMOUNT_5XMR, mixin, 0, std::set<uint32_t>{});
+ recepient_address, payment_id, AMOUNT_5XMR, mixin, Monero::PendingTransaction::Priority_Medium, 0, std::set<uint32_t>{});
std::cerr << "Transaction status: " << transaction->status() << std::endl;
std::cerr << "Transaction fee: " << Monero::Wallet::displayAmount(transaction->fee()) << std::endl;
@@ -663,7 +663,7 @@ TEST_F(WalletTest1, WalletTransactionWithPriority)
std::cerr << "Transaction priority: " << *it << std::endl;
Monero::PendingTransaction * transaction = wallet1->createTransaction(
- recepient_address, payment_id, AMOUNT_5XMR, mixin, 0, std::set<uint32_t>{}, *it);
+ recepient_address, payment_id, AMOUNT_5XMR, mixin, *it, 0, std::set<uint32_t>{});
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;
@@ -719,7 +719,7 @@ TEST_F(WalletTest1, WalletTransactionAndHistory)
Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr,
PAYMENT_ID_EMPTY,
- AMOUNT_10XMR * 5, 1, 0, std::set<uint32_t>{});
+ AMOUNT_10XMR * 5, 1, Monero::PendingTransaction::Priority_Medium, 0, std::set<uint32_t>{});
ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
ASSERT_TRUE(tx->commit());
@@ -761,7 +761,7 @@ TEST_F(WalletTest1, WalletTransactionWithPaymentId)
Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr,
payment_id,
- AMOUNT_1XMR, 1, 0, std::set<uint32_t>{});
+ AMOUNT_1XMR, 1, Monero::PendingTransaction::Priority_Medium, 0, std::set<uint32_t>{});
ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok);
ASSERT_TRUE(tx->commit());
@@ -934,7 +934,7 @@ TEST_F(WalletTest2, WalletCallbackSent)
Monero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->mainAddress(),
PAYMENT_ID_EMPTY,
- amount, 1, 0, std::set<uint32_t>{});
+ amount, 1, Monero::PendingTransaction::Priority_Medium, 0, std::set<uint32_t>{});
std::cout << "** Committing transaction: " << Monero::Wallet::displayAmount(tx->amount())
<< " with fee: " << Monero::Wallet::displayAmount(tx->fee());
@@ -975,7 +975,7 @@ TEST_F(WalletTest2, WalletCallbackReceived)
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, 0, std::set<uint32_t>{});
+ amount, 1, Monero::PendingTransaction::Priority_Medium, 0, std::set<uint32_t>{});
std::cout << "** Committing transaction: " << Monero::Wallet::displayAmount(tx->amount())
<< " with fee: " << Monero::Wallet::displayAmount(tx->fee());
diff --git a/tests/net_load_tests/clt.cpp b/tests/net_load_tests/clt.cpp
index 376d7ee53..c930a5b57 100644
--- a/tests/net_load_tests/clt.cpp
+++ b/tests/net_load_tests/clt.cpp
@@ -193,7 +193,7 @@ namespace
{
m_thread_count = (std::max)(min_thread_count, boost::thread::hardware_concurrency() / 2);
- m_tcp_server.get_config_object().m_pcommands_handler = &m_commands_handler;
+ m_tcp_server.get_config_object().set_handler(&m_commands_handler);
m_tcp_server.get_config_object().m_invoke_timeout = CONNECTION_TIMEOUT;
ASSERT_TRUE(m_tcp_server.init_server(clt_port, "127.0.0.1"));
@@ -238,9 +238,10 @@ namespace
static void TearDownTestCase()
{
// Stop server
- test_levin_commands_handler commands_handler;
- test_tcp_server tcp_server(epee::net_utils::e_connection_type_NET);
- tcp_server.get_config_object().m_pcommands_handler = &commands_handler;
+ test_levin_commands_handler *commands_handler_ptr = new test_levin_commands_handler();
+ test_levin_commands_handler &commands_handler = *commands_handler_ptr;
+ test_tcp_server tcp_server(epee::net_utils::e_connection_type_RPC);
+ tcp_server.get_config_object().set_handler(commands_handler_ptr, [](epee::levin::levin_commands_handler<test_connection_context> *handler)->void { delete handler; });
tcp_server.get_config_object().m_invoke_timeout = CONNECTION_TIMEOUT;
if (!tcp_server.init_server(clt_port, "127.0.0.1")) return;
diff --git a/tests/net_load_tests/net_load_tests.h b/tests/net_load_tests/net_load_tests.h
index f74282683..ce9d8b6fe 100644
--- a/tests/net_load_tests/net_load_tests.h
+++ b/tests/net_load_tests/net_load_tests.h
@@ -151,6 +151,11 @@ namespace net_load_tests
bool handle_new_connection(const boost::uuids::uuid& connection_id, bool ignore_close_fails = false)
{
size_t idx = m_next_opened_conn_idx.fetch_add(1, std::memory_order_relaxed);
+ if (idx >= m_connections.size())
+ {
+ LOG_PRINT_L0("ERROR: connections overflow");
+ exit(1);
+ }
m_connections[idx] = connection_id;
size_t prev_connection_count = m_opened_connection_count.fetch_add(1, std::memory_order_relaxed);
diff --git a/tests/net_load_tests/srv.cpp b/tests/net_load_tests/srv.cpp
index e6dee1639..f0b0889ea 100644
--- a/tests/net_load_tests/srv.cpp
+++ b/tests/net_load_tests/srv.cpp
@@ -224,8 +224,8 @@ int main(int argc, char** argv)
if (!tcp_server.init_server(srv_port, "127.0.0.1"))
return 1;
- srv_levin_commands_handler commands_handler(tcp_server);
- tcp_server.get_config_object().m_pcommands_handler = &commands_handler;
+ srv_levin_commands_handler *commands_handler = new srv_levin_commands_handler(tcp_server);
+ tcp_server.get_config_object().set_handler(commands_handler, [](epee::levin::levin_commands_handler<test_connection_context> *handler) { delete handler; });
tcp_server.get_config_object().m_invoke_timeout = 10000;
//tcp_server.get_config_object().m_max_packet_size = max_packet_size;
diff --git a/tests/performance_tests/ge_frombytes_vartime.h b/tests/performance_tests/ge_frombytes_vartime.h
index a5e64aeb2..ea72fcd26 100644
--- a/tests/performance_tests/ge_frombytes_vartime.h
+++ b/tests/performance_tests/ge_frombytes_vartime.h
@@ -54,7 +54,7 @@ public:
std::vector<tx_destination_entry> destinations;
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);
+ return construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, boost::none, std::vector<uint8_t>(), m_tx, 0);
}
bool test()
diff --git a/tests/performance_tests/is_out_to_acc.h b/tests/performance_tests/is_out_to_acc.h
index 7da061c1e..c31897628 100644
--- a/tests/performance_tests/is_out_to_acc.h
+++ b/tests/performance_tests/is_out_to_acc.h
@@ -64,6 +64,7 @@ public:
{
const cryptonote::txout_to_key& tx_out = boost::get<cryptonote::txout_to_key>(m_tx.vout[0].target);
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
+ subaddresses[m_bob.get_keys().m_account_address.m_spend_public_key] = {0,0};
std::vector<crypto::key_derivation> additional_derivations;
boost::optional<cryptonote::subaddress_receive_info> info = cryptonote::is_out_to_acc_precomp(subaddresses, tx_out.key, m_derivation, additional_derivations, 0);
return (bool)info;
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index c7efcf074..e10648d20 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -55,6 +55,7 @@ set(unit_tests_sources
serialization.cpp
sha256.cpp
slow_memmem.cpp
+ subaddress.cpp
test_tx_utils.cpp
test_peerlist.cpp
test_protocol_pack.cpp
diff --git a/tests/unit_tests/crypto.cpp b/tests/unit_tests/crypto.cpp
index 3a8e787ec..51e26c2bb 100644
--- a/tests/unit_tests/crypto.cpp
+++ b/tests/unit_tests/crypto.cpp
@@ -47,6 +47,14 @@ namespace
"8b655970153799af2aeadc9ff1add0ea6c7251d54154cfa92c173a0dd39c1f94"
"6c7251d54154cfa92c173a0dd39c1f948b655970153799af2aeadc9ff1add0ea";
+ static std::uint8_t md[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+
template<typename T>
bool is_formatted()
{
@@ -61,6 +69,26 @@ namespace
out << "BEGIN" << value << "END";
return out.str() == "BEGIN<" + std::string{expected, sizeof(T) * 2} + ">END";
}
+
+ bool keccak_harness()
+ {
+ size_t inlen = sizeof(source);
+ int mdlen = (int)sizeof(md);
+ int ret = keccak(source, inlen, md, mdlen);
+
+ if (md[0] != 0x00)
+ {
+ return true;
+ }
+ else if (!ret)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
}
TEST(Crypto, Ostream)
diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
index d2aa31555..c749c2531 100644
--- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp
+++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
@@ -187,9 +187,11 @@ namespace
typedef std::unique_ptr<test_connection> test_connection_ptr;
- async_protocol_handler_test()
+ async_protocol_handler_test():
+ m_pcommands_handler(new test_levin_commands_handler()),
+ m_commands_handler(*m_pcommands_handler)
{
- m_handler_config.m_pcommands_handler = &m_commands_handler;
+ m_handler_config.set_handler(m_pcommands_handler, [](epee::levin::levin_commands_handler<test_levin_connection_context> *handler) { delete handler; });
m_handler_config.m_invoke_timeout = invoke_timeout;
m_handler_config.m_max_packet_size = max_packet_size;
}
@@ -212,7 +214,7 @@ namespace
protected:
boost::asio::io_service m_io_service;
test_levin_protocol_handler_config m_handler_config;
- test_levin_commands_handler m_commands_handler;
+ test_levin_commands_handler *m_pcommands_handler, &m_commands_handler;
};
class positive_test_connection_to_levin_protocol_handler_calls : public async_protocol_handler_test
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index 2b0904224..c235f49fd 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -115,13 +115,13 @@ public:
virtual void add_txpool_tx(const transaction &tx, const txpool_tx_meta_t& details) {}
virtual void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t& details) {}
- virtual uint64_t get_txpool_tx_count() const { return 0; }
+ virtual uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const { return 0; }
virtual bool txpool_has_tx(const crypto::hash &txid) const { return false; }
virtual void remove_txpool_tx(const crypto::hash& txid) {}
virtual txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash& txid) const { return txpool_tx_meta_t(); }
virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const { return false; }
virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const { return ""; }
- virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false) const { return false; }
+ virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false, bool include_unrelayed_txes = false) const { return false; }
virtual void add_block( const block& blk
, const size_t& block_size
diff --git a/tests/unit_tests/sha256.cpp b/tests/unit_tests/sha256.cpp
index f4ad39466..0d657a1a9 100644
--- a/tests/unit_tests/sha256.cpp
+++ b/tests/unit_tests/sha256.cpp
@@ -28,8 +28,8 @@
#include "gtest/gtest.h"
-#include "string_tools.h"
#include "common/util.h"
+#include "string_tools.h"
static bool check(const std::string &data, const char *expected_hash_hex)
{
diff --git a/tests/unit_tests/subaddress.cpp b/tests/unit_tests/subaddress.cpp
new file mode 100644
index 000000000..c304b7347
--- /dev/null
+++ b/tests/unit_tests/subaddress.cpp
@@ -0,0 +1,118 @@
+// 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.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+#include <boost/filesystem.hpp>
+#include "gtest/gtest.h"
+
+#include "include_base_utils.h"
+#include "wallet/wallet2.h"
+#include "crypto/crypto.h"
+#include "cryptonote_basic/account.h"
+#include "cryptonote_basic/cryptonote_basic_impl.h"
+#include "wallet/api/subaddress.h"
+
+class WalletSubaddress : public ::testing::Test
+{
+ protected:
+ virtual void SetUp()
+ {
+ try
+ {
+ w1.generate(wallet_name, password, recovery_key, true, false);
+ }
+ catch (const std::exception& e)
+ {
+ LOG_ERROR("failed to generate wallet: " << e.what());
+ throw e;
+ }
+
+ w1.add_subaddress_account(test_label);
+ w1.set_subaddress_label(subaddress_index, test_label);
+ }
+
+ virtual void TearDown()
+ {
+ boost::filesystem::wpath wallet_file(wallet_name);
+ boost::filesystem::wpath wallet_address_file(wallet_name + ".address.txt");
+ boost::filesystem::wpath wallet_keys_file(wallet_name + ".keys");
+
+ if ( boost::filesystem::exists(wallet_file) )
+ boost::filesystem::remove(wallet_file);
+
+ if ( boost::filesystem::exists(wallet_address_file) )
+ boost::filesystem::remove(wallet_address_file);
+
+ if ( boost::filesystem::exists(wallet_keys_file) )
+ boost::filesystem::remove(wallet_keys_file);
+ }
+
+ tools::wallet2 w1;
+ std::string path_working_dir = ".";
+ std::string path_test_wallet = "test_wallet";
+ const std::string wallet_name = path_working_dir + "/" + path_test_wallet;
+ const std::string password = "testpass";
+ crypto::secret_key recovery_key = crypto::secret_key();
+ const std::string test_label = "subaddress test label";
+
+ uint32_t major_index = 0;
+ uint32_t minor_index = 0;
+ const cryptonote::subaddress_index subaddress_index = {major_index, minor_index};
+};
+
+TEST_F(WalletSubaddress, GetSubaddressLabel)
+{
+ EXPECT_EQ(test_label, w1.get_subaddress_label(subaddress_index));
+}
+
+TEST_F(WalletSubaddress, AddSubaddress)
+{
+ std::string label = "test adding subaddress";
+ w1.add_subaddress(0, label);
+ EXPECT_EQ(label, w1.get_subaddress_label({0, 1}));
+}
+
+TEST_F(WalletSubaddress, OutOfBoundsIndexes)
+{
+ try
+ {
+ w1.get_subaddress_label({1,0});
+ }
+ catch(const std::exception& e)
+ {
+ EXPECT_STREQ("index_major is out of bound", e.what());
+ }
+ try
+ {
+ w1.get_subaddress_label({0,2});
+ }
+ catch(const std::exception& e)
+ {
+ EXPECT_STREQ("index.minor is out of bound", e.what());
+ }
+}