aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/README.md4
-rw-r--r--tests/block_weight/CMakeLists.txt2
-rw-r--r--tests/block_weight/block_weight.cpp12
-rwxr-xr-xtests/block_weight/block_weight.py2
-rwxr-xr-xtests/block_weight/compare.py15
-rw-r--r--tests/core_proxy/CMakeLists.txt2
-rw-r--r--tests/core_proxy/core_proxy.cpp2
-rw-r--r--tests/core_proxy/core_proxy.h2
-rw-r--r--tests/core_tests/CMakeLists.txt2
-rw-r--r--tests/core_tests/block_reward.cpp2
-rw-r--r--tests/core_tests/block_reward.h2
-rw-r--r--tests/core_tests/block_validation.cpp2
-rw-r--r--tests/core_tests/block_validation.h2
-rw-r--r--tests/core_tests/bulletproofs.cpp2
-rw-r--r--tests/core_tests/bulletproofs.h2
-rw-r--r--tests/core_tests/chain_split_1.cpp2
-rw-r--r--tests/core_tests/chain_split_1.h2
-rw-r--r--tests/core_tests/chain_switch_1.cpp2
-rw-r--r--tests/core_tests/chain_switch_1.h2
-rw-r--r--tests/core_tests/chaingen.cpp2
-rw-r--r--tests/core_tests/chaingen.h11
-rw-r--r--tests/core_tests/chaingen001.cpp2
-rw-r--r--tests/core_tests/chaingen_main.cpp2
-rw-r--r--tests/core_tests/chaingen_tests_list.h2
-rw-r--r--tests/core_tests/double_spend.cpp2
-rw-r--r--tests/core_tests/double_spend.h2
-rw-r--r--tests/core_tests/double_spend.inl2
-rw-r--r--tests/core_tests/integer_overflow.cpp2
-rw-r--r--tests/core_tests/integer_overflow.h2
-rw-r--r--tests/core_tests/multisig.cpp2
-rw-r--r--tests/core_tests/multisig.h2
-rw-r--r--tests/core_tests/rct.cpp2
-rw-r--r--tests/core_tests/rct.h2
-rw-r--r--tests/core_tests/ring_signature_1.cpp2
-rw-r--r--tests/core_tests/ring_signature_1.h2
-rw-r--r--tests/core_tests/transaction_tests.cpp2
-rw-r--r--tests/core_tests/transaction_tests.h2
-rw-r--r--tests/core_tests/tx_validation.cpp2
-rw-r--r--tests/core_tests/tx_validation.h2
-rw-r--r--tests/core_tests/v2_tests.cpp2
-rw-r--r--tests/core_tests/v2_tests.h2
-rw-r--r--tests/core_tests/wallet_tools.cpp1
-rw-r--r--tests/crypto/CMakeLists.txt3
-rw-r--r--tests/crypto/crypto-ops-data.c2
-rw-r--r--tests/crypto/crypto-ops.c2
-rw-r--r--tests/crypto/crypto-tests.h2
-rw-r--r--tests/crypto/crypto.cpp2
-rw-r--r--tests/crypto/hash.c2
-rw-r--r--tests/crypto/main.cpp2
-rw-r--r--tests/crypto/random.c2
-rw-r--r--tests/cryptolib.pl2
-rw-r--r--tests/cryptotest.pl2
-rw-r--r--tests/daemon_tests/CMakeLists.txt2
-rw-r--r--tests/daemon_tests/transfers.cpp2
-rw-r--r--tests/difficulty/CMakeLists.txt5
-rw-r--r--tests/difficulty/difficulty.cpp66
-rw-r--r--tests/difficulty/gen_wide_data.py47
-rwxr-xr-xtests/difficulty/generate-data2
-rwxr-xr-xtests/difficulty/wide_difficulty.py22
-rw-r--r--tests/functional_tests/CMakeLists.txt2
-rw-r--r--tests/functional_tests/main.cpp2
-rw-r--r--tests/functional_tests/transactions_flow_test.cpp2
-rw-r--r--tests/functional_tests/transactions_flow_test.h2
-rw-r--r--tests/functional_tests/transactions_generation_from_blockchain.cpp2
-rw-r--r--tests/functional_tests/transactions_generation_from_blockchain.h2
-rw-r--r--tests/fuzz/CMakeLists.txt2
-rw-r--r--tests/fuzz/base58.cpp2
-rw-r--r--tests/fuzz/block.cpp2
-rw-r--r--tests/fuzz/bulletproof.cpp2
-rw-r--r--tests/fuzz/cold-outputs.cpp4
-rw-r--r--tests/fuzz/cold-transaction.cpp4
-rw-r--r--tests/fuzz/fuzzer.cpp2
-rw-r--r--tests/fuzz/fuzzer.h2
-rw-r--r--tests/fuzz/http-client.cpp2
-rw-r--r--tests/fuzz/levin.cpp2
-rw-r--r--tests/fuzz/load_from_binary.cpp2
-rw-r--r--tests/fuzz/load_from_json.cpp2
-rw-r--r--tests/fuzz/parse_url.cpp2
-rw-r--r--tests/fuzz/signature.cpp4
-rw-r--r--tests/fuzz/transaction.cpp2
-rw-r--r--tests/gtest/include/gtest/internal/gtest-port-arch.h2
-rw-r--r--tests/gtest/include/gtest/internal/gtest-port.h3
-rw-r--r--tests/hash-target.cpp14
-rw-r--r--tests/hash/CMakeLists.txt2
-rw-r--r--tests/hash/main.cpp2
-rw-r--r--tests/io.h2
-rw-r--r--tests/libwallet_api_tests/CMakeLists.txt2
-rw-r--r--tests/libwallet_api_tests/main.cpp2
-rw-r--r--tests/net_load_tests/CMakeLists.txt2
-rw-r--r--tests/net_load_tests/clt.cpp2
-rw-r--r--tests/net_load_tests/net_load_tests.h2
-rw-r--r--tests/net_load_tests/srv.cpp2
-rw-r--r--tests/performance_tests/CMakeLists.txt3
-rw-r--r--tests/performance_tests/bulletproof.h2
-rw-r--r--tests/performance_tests/check_hash.h66
-rw-r--r--tests/performance_tests/check_tx_signature.h2
-rw-r--r--tests/performance_tests/cn_fast_hash.h2
-rw-r--r--tests/performance_tests/cn_slow_hash.h2
-rw-r--r--tests/performance_tests/construct_tx.h2
-rw-r--r--tests/performance_tests/crypto_ops.h2
-rw-r--r--tests/performance_tests/derive_public_key.h2
-rw-r--r--tests/performance_tests/derive_secret_key.h2
-rw-r--r--tests/performance_tests/equality.h2
-rw-r--r--tests/performance_tests/ge_frombytes_vartime.h2
-rw-r--r--tests/performance_tests/ge_tobytes.h2
-rw-r--r--tests/performance_tests/generate_key_derivation.h2
-rw-r--r--tests/performance_tests/generate_key_image.h2
-rw-r--r--tests/performance_tests/generate_key_image_helper.h2
-rw-r--r--tests/performance_tests/generate_keypair.h2
-rw-r--r--tests/performance_tests/is_out_to_acc.h2
-rw-r--r--tests/performance_tests/main.cpp11
-rw-r--r--tests/performance_tests/multi_tx_test_base.h2
-rw-r--r--tests/performance_tests/performance_tests.h2
-rw-r--r--tests/performance_tests/performance_utils.h6
-rw-r--r--tests/performance_tests/range_proof.h2
-rw-r--r--tests/performance_tests/rct_mlsag.h2
-rw-r--r--tests/performance_tests/sc_reduce32.h2
-rw-r--r--tests/performance_tests/signature.h2
-rw-r--r--tests/performance_tests/single_tx_test_base.h2
-rw-r--r--tests/performance_tests/subaddress_expand.h2
-rw-r--r--tests/trezor/CMakeLists.txt13
-rw-r--r--tests/trezor/daemon.cpp368
-rw-r--r--tests/trezor/daemon.h154
-rw-r--r--tests/trezor/tools.cpp56
-rw-r--r--tests/trezor/tools.h61
-rw-r--r--tests/trezor/trezor_tests.cpp553
-rw-r--r--tests/trezor/trezor_tests.h109
-rw-r--r--tests/unit_tests/CMakeLists.txt6
-rw-r--r--tests/unit_tests/account.cpp2
-rw-r--r--tests/unit_tests/address_from_url.cpp2
-rw-r--r--tests/unit_tests/apply_permutation.cpp2
-rw-r--r--tests/unit_tests/ban.cpp2
-rw-r--r--tests/unit_tests/base58.cpp2
-rw-r--r--tests/unit_tests/block_queue.cpp2
-rw-r--r--tests/unit_tests/block_reward.cpp2
-rw-r--r--tests/unit_tests/blockchain_db.cpp2
-rw-r--r--tests/unit_tests/bulletproofs.cpp2
-rw-r--r--tests/unit_tests/canonical_amounts.cpp2
-rw-r--r--tests/unit_tests/chacha.cpp2
-rw-r--r--tests/unit_tests/checkpoints.cpp2
-rw-r--r--tests/unit_tests/command_line.cpp2
-rw-r--r--tests/unit_tests/crypto.cpp2
-rw-r--r--tests/unit_tests/decompose_amount_into_digits.cpp2
-rw-r--r--tests/unit_tests/difficulty.cpp68
-rw-r--r--tests/unit_tests/dns_resolver.cpp2
-rw-r--r--tests/unit_tests/epee_boosted_tcp_server.cpp2
-rw-r--r--tests/unit_tests/epee_levin_protocol_handler_async.cpp2
-rw-r--r--tests/unit_tests/epee_utils.cpp2
-rw-r--r--tests/unit_tests/fee.cpp2
-rw-r--r--tests/unit_tests/get_xtype_from_string.cpp2
-rw-r--r--tests/unit_tests/hardfork.cpp2
-rw-r--r--tests/unit_tests/hashchain.cpp2
-rw-r--r--tests/unit_tests/hmac_keccak.cpp152
-rw-r--r--tests/unit_tests/http.cpp2
-rw-r--r--tests/unit_tests/lmdb.cpp404
-rw-r--r--tests/unit_tests/logging.cpp2
-rw-r--r--tests/unit_tests/long_term_block_weight.cpp12
-rw-r--r--tests/unit_tests/main.cpp2
-rw-r--r--tests/unit_tests/memwipe.cpp2
-rw-r--r--tests/unit_tests/mnemonics.cpp2
-rw-r--r--tests/unit_tests/mul_div.cpp2
-rw-r--r--tests/unit_tests/multisig.cpp4
-rw-r--r--tests/unit_tests/net.cpp90
-rw-r--r--tests/unit_tests/output_selection.cpp2
-rw-r--r--tests/unit_tests/parse_amount.cpp2
-rw-r--r--tests/unit_tests/ringct.cpp2
-rw-r--r--tests/unit_tests/serialization.cpp25
-rw-r--r--tests/unit_tests/sha256.cpp2
-rw-r--r--tests/unit_tests/slow_memmem.cpp2
-rw-r--r--tests/unit_tests/subaddress.cpp2
-rw-r--r--tests/unit_tests/test_peerlist.cpp2
-rw-r--r--tests/unit_tests/test_protocol_pack.cpp2
-rw-r--r--tests/unit_tests/test_tx_utils.cpp2
-rw-r--r--tests/unit_tests/unbound.cpp2
-rw-r--r--tests/unit_tests/unit_tests_utils.h2
-rw-r--r--tests/unit_tests/uri.cpp2
-rw-r--r--tests/unit_tests/varint.cpp2
-rw-r--r--tests/unit_tests/vercmp.cpp2
179 files changed, 2402 insertions, 264 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 4adfba876..bbb0bc051 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/README.md b/tests/README.md
index 001ab6154..053dd2244 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -18,7 +18,7 @@ Tests are located in `tests/core_tests/`, and follow a straightforward naming co
To run only Monero's core tests (after building):
```
-cd build/debug/tests/core
+cd build/debug/tests/core_tests
ctest
```
@@ -103,6 +103,8 @@ cd build/debug/tests/performance_tests
./performance_tests
```
+The path may be build/Linux/master/debug (adapt as necessary for your platform).
+
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`.
diff --git a/tests/block_weight/CMakeLists.txt b/tests/block_weight/CMakeLists.txt
index b0d716ea0..a59c9c1fc 100644
--- a/tests/block_weight/CMakeLists.txt
+++ b/tests/block_weight/CMakeLists.txt
@@ -42,4 +42,4 @@ target_link_libraries(block_weight
add_test(
NAME block_weight
- COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/compare.py ${CMAKE_CURRENT_SOURCE_DIR}/block_weight.py ${CMAKE_CURRENT_BINARY_DIR}/block_weight)
+ COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/compare.py ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/block_weight.py ${CMAKE_CURRENT_BINARY_DIR}/block_weight)
diff --git a/tests/block_weight/block_weight.cpp b/tests/block_weight/block_weight.cpp
index 57fcb497e..1e8974b78 100644
--- a/tests/block_weight/block_weight.cpp
+++ b/tests/block_weight/block_weight.cpp
@@ -72,6 +72,18 @@ public:
virtual uint64_t height() const override { return blocks.size(); }
virtual size_t get_block_weight(const uint64_t &h) const override { return blocks[h].weight; }
virtual uint64_t get_block_long_term_weight(const uint64_t &h) const override { return blocks[h].long_term_weight; }
+ virtual std::vector<uint64_t> get_block_weights(uint64_t start_height, size_t count) const override {
+ std::vector<uint64_t> ret;
+ ret.reserve(count);
+ while (count-- && start_height < blocks.size()) ret.push_back(blocks[start_height++].weight);
+ return ret;
+ }
+ virtual std::vector<uint64_t> get_long_term_block_weights(uint64_t start_height, size_t count) const override {
+ std::vector<uint64_t> ret;
+ ret.reserve(count);
+ while (count-- && start_height < blocks.size()) ret.push_back(blocks[start_height++].long_term_weight);
+ return ret;
+ }
virtual crypto::hash top_block_hash(uint64_t *block_height = NULL) const override {
uint64_t h = height();
crypto::hash top = crypto::null_hash;
diff --git a/tests/block_weight/block_weight.py b/tests/block_weight/block_weight.py
index 06aaabb02..d6fd494e3 100755
--- a/tests/block_weight/block_weight.py
+++ b/tests/block_weight/block_weight.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# Simulate a maximal block attack on the Monero network
# This uses the scheme proposed by ArticMine
# Written by Sarang Nother
diff --git a/tests/block_weight/compare.py b/tests/block_weight/compare.py
index c6be05206..e058a7079 100755
--- a/tests/block_weight/compare.py
+++ b/tests/block_weight/compare.py
@@ -3,10 +3,17 @@
import sys
import subprocess
-print 'running: ', sys.argv[1]
-S0 = subprocess.check_output(sys.argv[1], stderr=subprocess.STDOUT)
-print 'running: ', sys.argv[2]
-S1 = subprocess.check_output(sys.argv[2], stderr=subprocess.STDOUT)
+if len(sys.argv) == 4:
+ first = [sys.argv[1], sys.argv[2]]
+ second = [sys.argv[3]]
+else:
+ first = [sys.argv[1]]
+ second = [sys.argv[2]]
+
+print 'running: ', first
+S0 = subprocess.check_output(first, stderr=subprocess.STDOUT)
+print 'running: ', second
+S1 = subprocess.check_output(second, stderr=subprocess.STDOUT)
print 'comparing'
if S0 != S1:
sys.exit(1)
diff --git a/tests/core_proxy/CMakeLists.txt b/tests/core_proxy/CMakeLists.txt
index 105c20d22..9818d35d7 100644
--- a/tests/core_proxy/CMakeLists.txt
+++ b/tests/core_proxy/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp
index 583111517..388808269 100644
--- a/tests/core_proxy/core_proxy.cpp
+++ b/tests/core_proxy/core_proxy.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_proxy/core_proxy.h b/tests/core_proxy/core_proxy.h
index 33a5b4d13..6c8b3ccb6 100644
--- a/tests/core_proxy/core_proxy.h
+++ b/tests/core_proxy/core_proxy.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/CMakeLists.txt b/tests/core_tests/CMakeLists.txt
index 205353416..f93cbf3ad 100644
--- a/tests/core_tests/CMakeLists.txt
+++ b/tests/core_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/core_tests/block_reward.cpp b/tests/core_tests/block_reward.cpp
index e55378439..17fc762ec 100644
--- a/tests/core_tests/block_reward.cpp
+++ b/tests/core_tests/block_reward.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/block_reward.h b/tests/core_tests/block_reward.h
index b7eb7c98e..6234bb9c5 100644
--- a/tests/core_tests/block_reward.h
+++ b/tests/core_tests/block_reward.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp
index 760cc4328..566ec1440 100644
--- a/tests/core_tests/block_validation.cpp
+++ b/tests/core_tests/block_validation.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/block_validation.h b/tests/core_tests/block_validation.h
index d229e4530..4a65b029e 100644
--- a/tests/core_tests/block_validation.h
+++ b/tests/core_tests/block_validation.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/bulletproofs.cpp b/tests/core_tests/bulletproofs.cpp
index 3e2db2e29..fd3f5114b 100644
--- a/tests/core_tests/bulletproofs.cpp
+++ b/tests/core_tests/bulletproofs.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/bulletproofs.h b/tests/core_tests/bulletproofs.h
index b0289f355..efc751df7 100644
--- a/tests/core_tests/bulletproofs.h
+++ b/tests/core_tests/bulletproofs.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chain_split_1.cpp b/tests/core_tests/chain_split_1.cpp
index d78e793bb..c51accb67 100644
--- a/tests/core_tests/chain_split_1.cpp
+++ b/tests/core_tests/chain_split_1.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chain_split_1.h b/tests/core_tests/chain_split_1.h
index 75602d1b0..503c3da19 100644
--- a/tests/core_tests/chain_split_1.h
+++ b/tests/core_tests/chain_split_1.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chain_switch_1.cpp b/tests/core_tests/chain_switch_1.cpp
index 18a813b19..0554fd676 100644
--- a/tests/core_tests/chain_switch_1.cpp
+++ b/tests/core_tests/chain_switch_1.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chain_switch_1.h b/tests/core_tests/chain_switch_1.h
index 989b6df11..c084de262 100644
--- a/tests/core_tests/chain_switch_1.h
+++ b/tests/core_tests/chain_switch_1.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp
index 0800de938..09bc10ea8 100644
--- a/tests/core_tests/chaingen.cpp
+++ b/tests/core_tests/chaingen.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h
index aa409b985..f2bcb7787 100644
--- a/tests/core_tests/chaingen.h
+++ b/tests/core_tests/chaingen.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -754,7 +754,7 @@ struct get_test_options {
};
//--------------------------------------------------------------------------
template<class t_test_class>
-inline bool do_replay_events_get_core(std::vector<test_event_entry>& events, cryptonote::core **core)
+inline bool do_replay_events_get_core(std::vector<test_event_entry>& events, cryptonote::core *core)
{
boost::program_options::options_description desc("Allowed options");
cryptonote::core::init_options(desc);
@@ -768,8 +768,7 @@ inline bool do_replay_events_get_core(std::vector<test_event_entry>& events, cry
if (!r)
return false;
- *core = new cryptonote::core(nullptr);
- auto & c = **core;
+ auto & c = *core;
// FIXME: make sure that vm has arg_testnet_on set to true or false if
// this test needs for it to be so.
@@ -825,9 +824,9 @@ inline bool replay_events_through_core_validate(std::vector<test_event_entry>& e
template<class t_test_class>
inline bool do_replay_events(std::vector<test_event_entry>& events)
{
- cryptonote::core * core;
+ cryptonote::core core(nullptr);
bool ret = do_replay_events_get_core<t_test_class>(events, &core);
- core->deinit();
+ core.deinit();
return ret;
}
//--------------------------------------------------------------------------
diff --git a/tests/core_tests/chaingen001.cpp b/tests/core_tests/chaingen001.cpp
index a76cf1592..b313f4821 100644
--- a/tests/core_tests/chaingen001.cpp
+++ b/tests/core_tests/chaingen001.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp
index 71b8c4463..cb35cfde2 100644
--- a/tests/core_tests/chaingen_main.cpp
+++ b/tests/core_tests/chaingen_main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chaingen_tests_list.h b/tests/core_tests/chaingen_tests_list.h
index c12e97f95..cf20c725c 100644
--- a/tests/core_tests/chaingen_tests_list.h
+++ b/tests/core_tests/chaingen_tests_list.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/double_spend.cpp b/tests/core_tests/double_spend.cpp
index c60ea885e..afd212b27 100644
--- a/tests/core_tests/double_spend.cpp
+++ b/tests/core_tests/double_spend.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/double_spend.h b/tests/core_tests/double_spend.h
index 276e74853..70d9f84b9 100644
--- a/tests/core_tests/double_spend.h
+++ b/tests/core_tests/double_spend.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/double_spend.inl b/tests/core_tests/double_spend.inl
index d02147065..600899b6f 100644
--- a/tests/core_tests/double_spend.inl
+++ b/tests/core_tests/double_spend.inl
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/integer_overflow.cpp b/tests/core_tests/integer_overflow.cpp
index e7e1ac9ca..42df4aa3b 100644
--- a/tests/core_tests/integer_overflow.cpp
+++ b/tests/core_tests/integer_overflow.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/integer_overflow.h b/tests/core_tests/integer_overflow.h
index eaca268e4..75a60eb15 100644
--- a/tests/core_tests/integer_overflow.h
+++ b/tests/core_tests/integer_overflow.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/multisig.cpp b/tests/core_tests/multisig.cpp
index 37fda6643..e0c90423d 100644
--- a/tests/core_tests/multisig.cpp
+++ b/tests/core_tests/multisig.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/multisig.h b/tests/core_tests/multisig.h
index e0d227840..1e8226d26 100644
--- a/tests/core_tests/multisig.h
+++ b/tests/core_tests/multisig.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/rct.cpp b/tests/core_tests/rct.cpp
index bb7dd013b..248354177 100644
--- a/tests/core_tests/rct.cpp
+++ b/tests/core_tests/rct.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/rct.h b/tests/core_tests/rct.h
index 641f3dd5e..72460d98e 100644
--- a/tests/core_tests/rct.h
+++ b/tests/core_tests/rct.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/ring_signature_1.cpp b/tests/core_tests/ring_signature_1.cpp
index 8b2b943cc..eb5ee48ec 100644
--- a/tests/core_tests/ring_signature_1.cpp
+++ b/tests/core_tests/ring_signature_1.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/ring_signature_1.h b/tests/core_tests/ring_signature_1.h
index 7ff6cfd96..256f5732b 100644
--- a/tests/core_tests/ring_signature_1.h
+++ b/tests/core_tests/ring_signature_1.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp
index 810dec6fc..14028b5be 100644
--- a/tests/core_tests/transaction_tests.cpp
+++ b/tests/core_tests/transaction_tests.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/transaction_tests.h b/tests/core_tests/transaction_tests.h
index 9500c66f6..eac2c3479 100644
--- a/tests/core_tests/transaction_tests.h
+++ b/tests/core_tests/transaction_tests.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp
index f0a385ee5..232c86482 100644
--- a/tests/core_tests/tx_validation.cpp
+++ b/tests/core_tests/tx_validation.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/tx_validation.h b/tests/core_tests/tx_validation.h
index 01a258a20..8d457cdb5 100644
--- a/tests/core_tests/tx_validation.h
+++ b/tests/core_tests/tx_validation.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/v2_tests.cpp b/tests/core_tests/v2_tests.cpp
index b96c744b3..8c2b51acf 100644
--- a/tests/core_tests/v2_tests.cpp
+++ b/tests/core_tests/v2_tests.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/v2_tests.h b/tests/core_tests/v2_tests.h
index cd2bcb839..71b0f0e83 100644
--- a/tests/core_tests/v2_tests.h
+++ b/tests/core_tests/v2_tests.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/wallet_tools.cpp b/tests/core_tests/wallet_tools.cpp
index ff7ce3a34..616774d18 100644
--- a/tests/core_tests/wallet_tools.cpp
+++ b/tests/core_tests/wallet_tools.cpp
@@ -17,7 +17,6 @@ void wallet_accessor_test::set_account(tools::wallet2 * wallet, cryptonote::acco
{
wallet->clear();
wallet->m_account = account;
- wallet->m_nettype = MAINNET;
wallet->m_key_device_type = account.get_device().get_type();
wallet->m_account_public_address = account.get_keys().m_account_address;
diff --git a/tests/crypto/CMakeLists.txt b/tests/crypto/CMakeLists.txt
index 8789cb552..883efb3b0 100644
--- a/tests/crypto/CMakeLists.txt
+++ b/tests/crypto/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -56,7 +56,6 @@ add_test(
add_executable(cnv4-jit-tests cnv4-jit.c)
target_link_libraries(cnv4-jit-tests
PRIVATE
- crypto
common
${EXTRA_LIBRARIES})
set_property(TARGET cnv4-jit-tests
diff --git a/tests/crypto/crypto-ops-data.c b/tests/crypto/crypto-ops-data.c
index 9bdd6b88f..63fedff07 100644
--- a/tests/crypto/crypto-ops-data.c
+++ b/tests/crypto/crypto-ops-data.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/crypto/crypto-ops.c b/tests/crypto/crypto-ops.c
index 476de786a..9b1ccfcee 100644
--- a/tests/crypto/crypto-ops.c
+++ b/tests/crypto/crypto-ops.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/crypto/crypto-tests.h b/tests/crypto/crypto-tests.h
index d910a845c..be8d5a2e1 100644
--- a/tests/crypto/crypto-tests.h
+++ b/tests/crypto/crypto-tests.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/crypto/crypto.cpp b/tests/crypto/crypto.cpp
index 6a1dd1b29..160e0a23f 100644
--- a/tests/crypto/crypto.cpp
+++ b/tests/crypto/crypto.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/crypto/hash.c b/tests/crypto/hash.c
index 6b865abd9..d65f13f11 100644
--- a/tests/crypto/hash.c
+++ b/tests/crypto/hash.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/crypto/main.cpp b/tests/crypto/main.cpp
index cc3b53b83..3cdef4ce7 100644
--- a/tests/crypto/main.cpp
+++ b/tests/crypto/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/crypto/random.c b/tests/crypto/random.c
index e9464d457..7a17cbccc 100644
--- a/tests/crypto/random.c
+++ b/tests/crypto/random.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/cryptolib.pl b/tests/cryptolib.pl
index 3d4cb638b..d26ce601c 100644
--- a/tests/cryptolib.pl
+++ b/tests/cryptolib.pl
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/cryptotest.pl b/tests/cryptotest.pl
index 13f8db09e..57f6e2c5a 100644
--- a/tests/cryptotest.pl
+++ b/tests/cryptotest.pl
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/daemon_tests/CMakeLists.txt b/tests/daemon_tests/CMakeLists.txt
index bc1dce2cc..a32f26584 100644
--- a/tests/daemon_tests/CMakeLists.txt
+++ b/tests/daemon_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/daemon_tests/transfers.cpp b/tests/daemon_tests/transfers.cpp
index 726f11dfb..e20e6b280 100644
--- a/tests/daemon_tests/transfers.cpp
+++ b/tests/daemon_tests/transfers.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/difficulty/CMakeLists.txt b/tests/difficulty/CMakeLists.txt
index 3cb8af8d5..fb0dd6b9e 100644
--- a/tests/difficulty/CMakeLists.txt
+++ b/tests/difficulty/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -45,3 +45,6 @@ set_property(TARGET difficulty-tests
add_test(
NAME difficulty
COMMAND difficulty-tests "${CMAKE_CURRENT_SOURCE_DIR}/data.txt")
+add_test(
+ NAME wide_difficulty
+ COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/wide_difficulty.py" "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/gen_wide_data.py" "${CMAKE_CURRENT_BINARY_DIR}/difficulty-tests" "${CMAKE_CURRENT_BINARY_DIR}/wide_data.txt")
diff --git a/tests/difficulty/difficulty.cpp b/tests/difficulty/difficulty.cpp
index 996913a19..9985b8710 100644
--- a/tests/difficulty/difficulty.cpp
+++ b/tests/difficulty/difficulty.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -43,16 +43,62 @@ using namespace std;
#define DEFAULT_TEST_DIFFICULTY_TARGET 120
+static int test_wide_difficulty(const char *filename)
+{
+ std::vector<uint64_t> timestamps;
+ std::vector<cryptonote::difficulty_type> cumulative_difficulties;
+ fstream data(filename, fstream::in);
+ data.exceptions(fstream::badbit);
+ data.clear(data.rdstate());
+ uint64_t timestamp;
+ cryptonote::difficulty_type difficulty, cumulative_difficulty = 0;
+ size_t n = 0;
+ while (data >> timestamp >> difficulty) {
+ size_t begin, end;
+ if (n < DIFFICULTY_WINDOW + DIFFICULTY_LAG) {
+ begin = 0;
+ end = min(n, (size_t) DIFFICULTY_WINDOW);
+ } else {
+ end = n - DIFFICULTY_LAG;
+ begin = end - DIFFICULTY_WINDOW;
+ }
+ cryptonote::difficulty_type res = cryptonote::next_difficulty(
+ std::vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end),
+ std::vector<cryptonote::difficulty_type>(cumulative_difficulties.begin() + begin, cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET);
+ if (res != difficulty) {
+ cerr << "Wrong wide difficulty for block " << n << endl
+ << "Expected: " << difficulty << endl
+ << "Found: " << res << endl;
+ return 1;
+ }
+ timestamps.push_back(timestamp);
+ cumulative_difficulties.push_back(cumulative_difficulty += difficulty);
+ ++n;
+ }
+ if (!data.eof()) {
+ data.clear(fstream::badbit);
+ }
+ return 0;
+}
+
int main(int argc, char *argv[]) {
- if (argc != 2) {
+ if (argc < 2) {
cerr << "Wrong arguments" << endl;
return 1;
}
+ if (argc == 3 && strcmp(argv[1], "--wide") == 0)
+ {
+ return test_wide_difficulty(argv[2]);
+ }
+
vector<uint64_t> timestamps, cumulative_difficulties;
+ std::vector<cryptonote::difficulty_type> wide_cumulative_difficulties;
fstream data(argv[1], fstream::in);
data.exceptions(fstream::badbit);
data.clear(data.rdstate());
- uint64_t timestamp, difficulty, cumulative_difficulty = 0;
+ uint64_t timestamp;
+ uint64_t difficulty, cumulative_difficulty = 0;
+ cryptonote::difficulty_type wide_cumulative_difficulty = 0;
size_t n = 0;
while (data >> timestamp >> difficulty) {
size_t begin, end;
@@ -63,17 +109,27 @@ int main(int argc, char *argv[]) {
end = n - DIFFICULTY_LAG;
begin = end - DIFFICULTY_WINDOW;
}
- uint64_t res = cryptonote::next_difficulty(
+ uint64_t res = cryptonote::next_difficulty_64(
vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end),
- vector<uint64_t>(cumulative_difficulties.begin() + begin, cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET);
+ std::vector<uint64_t>(cumulative_difficulties.begin() + begin, cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET);
if (res != difficulty) {
cerr << "Wrong difficulty for block " << n << endl
<< "Expected: " << difficulty << endl
<< "Found: " << res << endl;
return 1;
}
+ cryptonote::difficulty_type wide_res = cryptonote::next_difficulty(
+ std::vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end),
+ std::vector<cryptonote::difficulty_type>(wide_cumulative_difficulties.begin() + begin, wide_cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET);
+ if (wide_res.convert_to<uint64_t>() != res) {
+ cerr << "Wrong wide difficulty for block " << n << endl
+ << "Expected: " << res << endl
+ << "Found: " << wide_res << endl;
+ return 1;
+ }
timestamps.push_back(timestamp);
cumulative_difficulties.push_back(cumulative_difficulty += difficulty);
+ wide_cumulative_difficulties.push_back(wide_cumulative_difficulty += difficulty);
++n;
}
if (!data.eof()) {
diff --git a/tests/difficulty/gen_wide_data.py b/tests/difficulty/gen_wide_data.py
new file mode 100644
index 000000000..64af4e208
--- /dev/null
+++ b/tests/difficulty/gen_wide_data.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+
+from __future__ import print_function
+import random
+
+DIFFICULTY_TARGET = 120
+DIFFICULTY_WINDOW = 720
+DIFFICULTY_LAG = 15
+DIFFICULTY_CUT = 60
+
+def difficulty():
+ times = []
+ diffs = []
+ while True:
+ if len(times) <= 1:
+ diff = 1
+ else:
+ begin = max(len(times) - DIFFICULTY_WINDOW - DIFFICULTY_LAG, 0)
+ end = min(begin + DIFFICULTY_WINDOW, len(times))
+ length = end - begin
+ assert length >= 2
+ if length <= DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT:
+ cut_begin = 0
+ cut_end = length
+ else:
+ excess = length - (DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT)
+ cut_begin = (excess + 1) // 2
+ cut_end = length - excess // 2
+ assert cut_begin + 2 <= cut_end
+ wnd = times[begin:end]
+ wnd.sort()
+ dtime = wnd[cut_end - 1] - wnd[cut_begin]
+ dtime = max(dtime, 1)
+ ddiff = sum(diffs[begin + cut_begin + 1:begin + cut_end])
+ diff = (ddiff * DIFFICULTY_TARGET + dtime - 1) // dtime
+ times.append((yield diff))
+ diffs.append(diff)
+
+random.seed(1)
+time = 1000
+gen = difficulty()
+diff = next(gen)
+for i in range(100000):
+ power = 100 if i < 10000 else 100000000 if i < 500 else 1000000000000 if i < 1000 else 1000000000000000 if i < 2000 else 10000000000000000000 if i < 4000 else 1000000000000000000000000
+ time += random.randint(-diff // power - 10, 3 * diff // power + 10)
+ print(time, diff)
+ diff = gen.send(time)
diff --git a/tests/difficulty/generate-data b/tests/difficulty/generate-data
index c41ce025d..3a9976e05 100755
--- a/tests/difficulty/generate-data
+++ b/tests/difficulty/generate-data
@@ -1,6 +1,6 @@
#!/usr/bin/python3
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/difficulty/wide_difficulty.py b/tests/difficulty/wide_difficulty.py
new file mode 100755
index 000000000..41a2a632d
--- /dev/null
+++ b/tests/difficulty/wide_difficulty.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+from __future__ import print_function
+import sys
+import subprocess
+
+python = sys.argv[1]
+py = sys.argv[2]
+c = sys.argv[3]
+data = sys.argv[4]
+
+first = python + " " + py + " > " + data
+second = [c, '--wide', data]
+
+try:
+ print('running: ', first)
+ subprocess.check_call(first, shell=True)
+ print('running: ', second)
+ subprocess.check_call(second)
+except:
+ sys.exit(1)
+
diff --git a/tests/functional_tests/CMakeLists.txt b/tests/functional_tests/CMakeLists.txt
index 7a2a7fbd1..2e3519994 100644
--- a/tests/functional_tests/CMakeLists.txt
+++ b/tests/functional_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/functional_tests/main.cpp b/tests/functional_tests/main.cpp
index b9a686dbc..c6869f755 100644
--- a/tests/functional_tests/main.cpp
+++ b/tests/functional_tests/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp
index 7e5b73415..32b601d7a 100644
--- a/tests/functional_tests/transactions_flow_test.cpp
+++ b/tests/functional_tests/transactions_flow_test.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/functional_tests/transactions_flow_test.h b/tests/functional_tests/transactions_flow_test.h
index 78135b9c0..530400df8 100644
--- a/tests/functional_tests/transactions_flow_test.h
+++ b/tests/functional_tests/transactions_flow_test.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/functional_tests/transactions_generation_from_blockchain.cpp b/tests/functional_tests/transactions_generation_from_blockchain.cpp
index 92dc00f2d..b9c43e0e9 100644
--- a/tests/functional_tests/transactions_generation_from_blockchain.cpp
+++ b/tests/functional_tests/transactions_generation_from_blockchain.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/functional_tests/transactions_generation_from_blockchain.h b/tests/functional_tests/transactions_generation_from_blockchain.h
index b684f7c7a..cb5f94f80 100644
--- a/tests/functional_tests/transactions_generation_from_blockchain.h
+++ b/tests/functional_tests/transactions_generation_from_blockchain.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt
index fdb745699..a6ef139f5 100644
--- a/tests/fuzz/CMakeLists.txt
+++ b/tests/fuzz/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/fuzz/base58.cpp b/tests/fuzz/base58.cpp
index a4857bdd1..5f909a5d9 100644
--- a/tests/fuzz/base58.cpp
+++ b/tests/fuzz/base58.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/block.cpp b/tests/fuzz/block.cpp
index eed3b94b2..850c58890 100644
--- a/tests/fuzz/block.cpp
+++ b/tests/fuzz/block.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/bulletproof.cpp b/tests/fuzz/bulletproof.cpp
index 2f3a2f8d1..e9a6ded7d 100644
--- a/tests/fuzz/bulletproof.cpp
+++ b/tests/fuzz/bulletproof.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/cold-outputs.cpp b/tests/fuzz/cold-outputs.cpp
index 29b3ed267..f4050c948 100644
--- a/tests/fuzz/cold-outputs.cpp
+++ b/tests/fuzz/cold-outputs.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -53,7 +53,7 @@ int ColdOutputsFuzzer::init()
try
{
- wallet.init("");
+ wallet.init("", boost::none, boost::asio::ip::tcp::endpoint{}, 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
wallet.set_subaddress_lookahead(1, 1);
wallet.generate("", "", spendkey, true, false);
}
diff --git a/tests/fuzz/cold-transaction.cpp b/tests/fuzz/cold-transaction.cpp
index fa3041ba3..08117281b 100644
--- a/tests/fuzz/cold-transaction.cpp
+++ b/tests/fuzz/cold-transaction.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -54,7 +54,7 @@ int ColdTransactionFuzzer::init()
try
{
- wallet.init("");
+ wallet.init("", boost::none, boost::asio::ip::tcp::endpoint{}, 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
wallet.set_subaddress_lookahead(1, 1);
wallet.generate("", "", spendkey, true, false);
}
diff --git a/tests/fuzz/fuzzer.cpp b/tests/fuzz/fuzzer.cpp
index ab14e2b79..24db5ee05 100644
--- a/tests/fuzz/fuzzer.cpp
+++ b/tests/fuzz/fuzzer.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/fuzzer.h b/tests/fuzz/fuzzer.h
index 2bf01914a..5cbd1abc2 100644
--- a/tests/fuzz/fuzzer.h
+++ b/tests/fuzz/fuzzer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/http-client.cpp b/tests/fuzz/http-client.cpp
index 909325832..1750838ae 100644
--- a/tests/fuzz/http-client.cpp
+++ b/tests/fuzz/http-client.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/levin.cpp b/tests/fuzz/levin.cpp
index 573abd1d3..fe9ef418e 100644
--- a/tests/fuzz/levin.cpp
+++ b/tests/fuzz/levin.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/load_from_binary.cpp b/tests/fuzz/load_from_binary.cpp
index 89f122902..85b7361e5 100644
--- a/tests/fuzz/load_from_binary.cpp
+++ b/tests/fuzz/load_from_binary.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/load_from_json.cpp b/tests/fuzz/load_from_json.cpp
index 083555f7e..3ba98050b 100644
--- a/tests/fuzz/load_from_json.cpp
+++ b/tests/fuzz/load_from_json.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/parse_url.cpp b/tests/fuzz/parse_url.cpp
index fb5754a70..3db78f9d9 100644
--- a/tests/fuzz/parse_url.cpp
+++ b/tests/fuzz/parse_url.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/signature.cpp b/tests/fuzz/signature.cpp
index f82ada8b4..038378ae2 100644
--- a/tests/fuzz/signature.cpp
+++ b/tests/fuzz/signature.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -54,7 +54,7 @@ int SignatureFuzzer::init()
try
{
- wallet.init("");
+ wallet.init("", boost::none, boost::asio::ip::tcp::endpoint{}, 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
wallet.set_subaddress_lookahead(1, 1);
wallet.generate("", "", spendkey, true, false);
diff --git a/tests/fuzz/transaction.cpp b/tests/fuzz/transaction.cpp
index 934bd4685..0f62888a1 100644
--- a/tests/fuzz/transaction.cpp
+++ b/tests/fuzz/transaction.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/gtest/include/gtest/internal/gtest-port-arch.h b/tests/gtest/include/gtest/internal/gtest-port-arch.h
index 74ab94905..83022c82c 100644
--- a/tests/gtest/include/gtest/internal/gtest-port-arch.h
+++ b/tests/gtest/include/gtest/internal/gtest-port-arch.h
@@ -88,6 +88,8 @@
# define GTEST_OS_OPENBSD 1
#elif defined __QNX__
# define GTEST_OS_QNX 1
+#elif defined(__NetBSD__)
+# define GTEST_OS_NETBSD 1
#endif // __CYGWIN__
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
diff --git a/tests/gtest/include/gtest/internal/gtest-port.h b/tests/gtest/include/gtest/internal/gtest-port.h
index cb0639b4b..2896dfe64 100644
--- a/tests/gtest/include/gtest/internal/gtest-port.h
+++ b/tests/gtest/include/gtest/internal/gtest-port.h
@@ -790,7 +790,8 @@ using ::std::tuple_size;
(GTEST_OS_MAC && !GTEST_OS_IOS) || \
(GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
- GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD)
+ GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD || \
+ GTEST_OS_NETBSD)
# define GTEST_HAS_DEATH_TEST 1
#endif
diff --git a/tests/hash-target.cpp b/tests/hash-target.cpp
index 2737ae30e..12acc5a67 100644
--- a/tests/hash-target.cpp
+++ b/tests/hash-target.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -40,7 +40,7 @@ using cryptonote::check_hash;
int main(int argc, char *argv[]) {
crypto::hash h;
- for (uint64_t diff = 1;; diff += 1 + (diff >> 8)) {
+ for (cryptonote::difficulty_type diff = 1;; diff += 1 + (diff >> 8)) {
for (uint16_t b = 0; b < 256; b++) {
memset(&h, b, sizeof(crypto::hash));
if (check_hash(h, diff) != (b == 0 || diff <= 255 / b)) {
@@ -50,7 +50,7 @@ int main(int argc, char *argv[]) {
memset(&h, 0, sizeof(crypto::hash));
((char *) &h)[31] = b;
if (check_hash(h, diff) != (diff <= 255 / b)) {
- return 1;
+ return 2;
}
}
}
@@ -58,11 +58,11 @@ int main(int argc, char *argv[]) {
uint64_t val = 0;
for (int i = 31; i >= 0; i--) {
val = val * 256 + 255;
- ((char *) &h)[i] = static_cast<char>(val / diff);
- val %= diff;
+ ((char *) &h)[i] = static_cast<char>(static_cast<uint64_t>(val / diff));
+ val %= diff.convert_to<uint64_t>();
}
if (check_hash(h, diff) != true) {
- return 1;
+ return 3;
}
if (diff > 1) {
for (int i = 0;; i++) {
@@ -74,7 +74,7 @@ int main(int argc, char *argv[]) {
}
}
if (check_hash(h, diff) != false) {
- return 1;
+ return 4;
}
}
}
diff --git a/tests/hash/CMakeLists.txt b/tests/hash/CMakeLists.txt
index 105cf2c13..a0c78bfdc 100644
--- a/tests/hash/CMakeLists.txt
+++ b/tests/hash/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/hash/main.cpp b/tests/hash/main.cpp
index acfd99e96..adf1bd9c4 100644
--- a/tests/hash/main.cpp
+++ b/tests/hash/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/io.h b/tests/io.h
index ec5a9ee60..0f65ed297 100644
--- a/tests/io.h
+++ b/tests/io.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/libwallet_api_tests/CMakeLists.txt b/tests/libwallet_api_tests/CMakeLists.txt
index 1a9cbc5a6..cb1d563b0 100644
--- a/tests/libwallet_api_tests/CMakeLists.txt
+++ b/tests/libwallet_api_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp
index fe31541df..02faae50d 100644
--- a/tests/libwallet_api_tests/main.cpp
+++ b/tests/libwallet_api_tests/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/net_load_tests/CMakeLists.txt b/tests/net_load_tests/CMakeLists.txt
index 1407bbf70..40b5561a7 100644
--- a/tests/net_load_tests/CMakeLists.txt
+++ b/tests/net_load_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/net_load_tests/clt.cpp b/tests/net_load_tests/clt.cpp
index 77cce2be7..fc2280f23 100644
--- a/tests/net_load_tests/clt.cpp
+++ b/tests/net_load_tests/clt.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/net_load_tests/net_load_tests.h b/tests/net_load_tests/net_load_tests.h
index 6c4f7cb76..cdc2d267a 100644
--- a/tests/net_load_tests/net_load_tests.h
+++ b/tests/net_load_tests/net_load_tests.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/net_load_tests/srv.cpp b/tests/net_load_tests/srv.cpp
index 092c6955c..fe32ec5cb 100644
--- a/tests/net_load_tests/srv.cpp
+++ b/tests/net_load_tests/srv.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/CMakeLists.txt b/tests/performance_tests/CMakeLists.txt
index 5cd054d86..b36df10dc 100644
--- a/tests/performance_tests/CMakeLists.txt
+++ b/tests/performance_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -31,6 +31,7 @@ set(performance_tests_sources
set(performance_tests_headers
check_tx_signature.h
+ check_hash.h
cn_slow_hash.h
construct_tx.h
derive_public_key.h
diff --git a/tests/performance_tests/bulletproof.h b/tests/performance_tests/bulletproof.h
index 7bb702c3d..7136fbbfe 100644
--- a/tests/performance_tests/bulletproof.h
+++ b/tests/performance_tests/bulletproof.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2017, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/check_hash.h b/tests/performance_tests/check_hash.h
new file mode 100644
index 000000000..d24001903
--- /dev/null
+++ b/tests/performance_tests/check_hash.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2019, 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.
+
+#pragma once
+
+#include "string_tools.h"
+#include "cryptonote_basic/difficulty.h"
+
+template<uint64_t hash_target_high, uint64_t hash_target_low, uint64_t difficulty_high, uint64_t difficulty_low>
+class test_check_hash
+{
+public:
+ static const size_t loop_count = 100000;
+
+ bool init()
+ {
+ cryptonote::difficulty_type hash_target = hash_target_high;
+ hash_target = (hash_target << 64) | hash_target_low;
+ difficulty = difficulty_high;
+ difficulty = (difficulty << 64) | difficulty_low;
+ boost::multiprecision::uint256_t hash_value = std::numeric_limits<boost::multiprecision::uint256_t>::max() / hash_target;
+ ((uint64_t*)&hash)[0] = (hash_value << 64 >> 64).convert_to<uint64_t>();
+ hash_value >>= 64;
+ ((uint64_t*)&hash)[1] = (hash_value << 64 >> 64).convert_to<uint64_t>();
+ hash_value >>= 64;
+ ((uint64_t*)&hash)[2] = (hash_value << 64 >> 64).convert_to<uint64_t>();
+ hash_value >>= 64;
+ ((uint64_t*)&hash)[3] = (hash_value << 64 >> 64).convert_to<uint64_t>();
+ return true;
+ }
+
+ bool test()
+ {
+ cryptonote::check_hash_128(hash, difficulty);
+ return true;
+ }
+
+private:
+ crypto::hash hash;
+ cryptonote::difficulty_type difficulty;
+};
diff --git a/tests/performance_tests/check_tx_signature.h b/tests/performance_tests/check_tx_signature.h
index 755d8f941..329714c56 100644
--- a/tests/performance_tests/check_tx_signature.h
+++ b/tests/performance_tests/check_tx_signature.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/cn_fast_hash.h b/tests/performance_tests/cn_fast_hash.h
index 2ddaef269..63b2c5bee 100644
--- a/tests/performance_tests/cn_fast_hash.h
+++ b/tests/performance_tests/cn_fast_hash.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/cn_slow_hash.h b/tests/performance_tests/cn_slow_hash.h
index 79ebb8778..4f410d62d 100644
--- a/tests/performance_tests/cn_slow_hash.h
+++ b/tests/performance_tests/cn_slow_hash.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/construct_tx.h b/tests/performance_tests/construct_tx.h
index 71d42073d..ebfe46edf 100644
--- a/tests/performance_tests/construct_tx.h
+++ b/tests/performance_tests/construct_tx.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/crypto_ops.h b/tests/performance_tests/crypto_ops.h
index 3ebb6f470..5b215cef4 100644
--- a/tests/performance_tests/crypto_ops.h
+++ b/tests/performance_tests/crypto_ops.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2017, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/derive_public_key.h b/tests/performance_tests/derive_public_key.h
index 35c4ff062..ad0b3b55f 100644
--- a/tests/performance_tests/derive_public_key.h
+++ b/tests/performance_tests/derive_public_key.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/derive_secret_key.h b/tests/performance_tests/derive_secret_key.h
index c478a2a99..ba01b57c0 100644
--- a/tests/performance_tests/derive_secret_key.h
+++ b/tests/performance_tests/derive_secret_key.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/equality.h b/tests/performance_tests/equality.h
index 8d24d7da7..5788ebec8 100644
--- a/tests/performance_tests/equality.h
+++ b/tests/performance_tests/equality.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/ge_frombytes_vartime.h b/tests/performance_tests/ge_frombytes_vartime.h
index 3f7d55182..1a0601c74 100644
--- a/tests/performance_tests/ge_frombytes_vartime.h
+++ b/tests/performance_tests/ge_frombytes_vartime.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/ge_tobytes.h b/tests/performance_tests/ge_tobytes.h
index 3d46f4838..66e6fce38 100644
--- a/tests/performance_tests/ge_tobytes.h
+++ b/tests/performance_tests/ge_tobytes.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/generate_key_derivation.h b/tests/performance_tests/generate_key_derivation.h
index 3f6238265..1f0066589 100644
--- a/tests/performance_tests/generate_key_derivation.h
+++ b/tests/performance_tests/generate_key_derivation.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/generate_key_image.h b/tests/performance_tests/generate_key_image.h
index 5155e64a5..df39d7088 100644
--- a/tests/performance_tests/generate_key_image.h
+++ b/tests/performance_tests/generate_key_image.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/generate_key_image_helper.h b/tests/performance_tests/generate_key_image_helper.h
index ede48b6ca..d4d83c07d 100644
--- a/tests/performance_tests/generate_key_image_helper.h
+++ b/tests/performance_tests/generate_key_image_helper.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/generate_keypair.h b/tests/performance_tests/generate_keypair.h
index 91c830166..cf28f7f58 100644
--- a/tests/performance_tests/generate_keypair.h
+++ b/tests/performance_tests/generate_keypair.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/is_out_to_acc.h b/tests/performance_tests/is_out_to_acc.h
index 9f81995ac..8b4516843 100644
--- a/tests/performance_tests/is_out_to_acc.h
+++ b/tests/performance_tests/is_out_to_acc.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp
index 22a86cb59..c32e0df20 100644
--- a/tests/performance_tests/main.cpp
+++ b/tests/performance_tests/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -38,6 +38,7 @@
// tests
#include "construct_tx.h"
#include "check_tx_signature.h"
+#include "check_hash.h"
#include "cn_slow_hash.h"
#include "derive_public_key.h"
#include "derive_secret_key.h"
@@ -181,6 +182,14 @@ int main(int argc, char** argv)
TEST_PERFORMANCE4(filter, p, test_check_tx_signature_aggregated_bulletproofs, 2, 2, 56, 16);
TEST_PERFORMANCE4(filter, p, test_check_tx_signature_aggregated_bulletproofs, 10, 2, 56, 16);
+ TEST_PERFORMANCE4(filter, p, test_check_hash, 0, 1, 0, 1);
+ TEST_PERFORMANCE4(filter, p, test_check_hash, 0, 0xffffffffffffffff, 0, 0xffffffffffffffff);
+ TEST_PERFORMANCE4(filter, p, test_check_hash, 0, 0xffffffffffffffff, 0, 1);
+ TEST_PERFORMANCE4(filter, p, test_check_hash, 1, 0, 1, 0);
+ TEST_PERFORMANCE4(filter, p, test_check_hash, 1, 0, 0, 1);
+ TEST_PERFORMANCE4(filter, p, test_check_hash, 0xffffffffffffffff, 0xffffffffffffffff, 0, 1);
+ TEST_PERFORMANCE4(filter, p, test_check_hash, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff);
+
TEST_PERFORMANCE0(filter, p, test_is_out_to_acc);
TEST_PERFORMANCE0(filter, p, test_is_out_to_acc_precomp);
TEST_PERFORMANCE0(filter, p, test_generate_key_image_helper);
diff --git a/tests/performance_tests/multi_tx_test_base.h b/tests/performance_tests/multi_tx_test_base.h
index ae9d6ea7a..bdbbee37d 100644
--- a/tests/performance_tests/multi_tx_test_base.h
+++ b/tests/performance_tests/multi_tx_test_base.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/performance_tests.h b/tests/performance_tests/performance_tests.h
index 17d16b0f6..606c5980f 100644
--- a/tests/performance_tests/performance_tests.h
+++ b/tests/performance_tests/performance_tests.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/performance_utils.h b/tests/performance_tests/performance_utils.h
index e46a7bce4..8a45bea90 100644
--- a/tests/performance_tests/performance_utils.h
+++ b/tests/performance_tests/performance_utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -40,7 +40,7 @@
void set_process_affinity(int core)
{
-#if defined (__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun)
+#if defined (__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__sun)
return;
#elif defined(BOOST_WINDOWS)
DWORD_PTR mask = 1;
@@ -62,7 +62,7 @@ void set_process_affinity(int core)
void set_thread_high_priority()
{
-#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(_NetBSD_) || defined(__sun)
return;
#elif defined(BOOST_WINDOWS)
::SetPriorityClass(::GetCurrentProcess(), HIGH_PRIORITY_CLASS);
diff --git a/tests/performance_tests/range_proof.h b/tests/performance_tests/range_proof.h
index 0ce962cd9..548237814 100644
--- a/tests/performance_tests/range_proof.h
+++ b/tests/performance_tests/range_proof.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2017, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/rct_mlsag.h b/tests/performance_tests/rct_mlsag.h
index 888f4b260..0141710f7 100644
--- a/tests/performance_tests/rct_mlsag.h
+++ b/tests/performance_tests/rct_mlsag.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2017, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/sc_reduce32.h b/tests/performance_tests/sc_reduce32.h
index fc5606414..8db1ca70a 100644
--- a/tests/performance_tests/sc_reduce32.h
+++ b/tests/performance_tests/sc_reduce32.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/signature.h b/tests/performance_tests/signature.h
index 21110b525..63c63ea46 100644
--- a/tests/performance_tests/signature.h
+++ b/tests/performance_tests/signature.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/single_tx_test_base.h b/tests/performance_tests/single_tx_test_base.h
index 365d25444..52fbf5f80 100644
--- a/tests/performance_tests/single_tx_test_base.h
+++ b/tests/performance_tests/single_tx_test_base.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/subaddress_expand.h b/tests/performance_tests/subaddress_expand.h
index 2a13ff5c2..61fcb41f3 100644
--- a/tests/performance_tests/subaddress_expand.h
+++ b/tests/performance_tests/subaddress_expand.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/trezor/CMakeLists.txt b/tests/trezor/CMakeLists.txt
index 67c2f8438..15ed5668d 100644
--- a/tests/trezor/CMakeLists.txt
+++ b/tests/trezor/CMakeLists.txt
@@ -27,11 +27,15 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set(trezor_tests_sources
+ tools.cpp
+ daemon.cpp
trezor_tests.cpp
../core_tests/chaingen.cpp
../core_tests/wallet_tools.cpp)
set(trezor_tests_headers
+ tools.h
+ daemon.h
trezor_tests.h
../core_tests/chaingen.h
../core_tests/wallet_tools.h)
@@ -50,6 +54,15 @@ target_link_libraries(trezor_tests
device
device_trezor
wallet
+ wallet_api
+ rpc
+ cryptonote_protocol
+ daemon_rpc_server
+ ${Boost_CHRONO_LIBRARY}
+ ${Boost_FILESYSTEM_LIBRARY}
+ ${Boost_PROGRAM_OPTIONS_LIBRARY}
+ ${Boost_SYSTEM_LIBRARY}
+ ${ZMQ_LIB}
${CMAKE_THREAD_LIBS_INIT}
${EXTRA_LIBRARIES})
diff --git a/tests/trezor/daemon.cpp b/tests/trezor/daemon.cpp
new file mode 100644
index 000000000..5e987793a
--- /dev/null
+++ b/tests/trezor/daemon.cpp
@@ -0,0 +1,368 @@
+// Copyright (c) 2014-2018, 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 "daemon.h"
+#include <common/command_line.h>
+
+using namespace std;
+using namespace daemonize;
+namespace po = boost::program_options;
+
+bool mock_rpc_daemon::on_send_raw_tx_2(const cryptonote::COMMAND_RPC_SEND_RAW_TX::request& req, cryptonote::COMMAND_RPC_SEND_RAW_TX::response& res, const cryptonote::core_rpc_server::connection_context *ctx)
+{
+ cryptonote::COMMAND_RPC_SEND_RAW_TX::request req2(req);
+ req2.do_not_relay = true; // Do not relay in test setup, only one daemon running.
+ return cryptonote::core_rpc_server::on_send_raw_tx(req2, res, ctx);
+}
+
+void mock_daemon::init_options(boost::program_options::options_description & option_spec)
+{
+ cryptonote::core::init_options(option_spec);
+ t_node_server::init_options(option_spec);
+ cryptonote::core_rpc_server::init_options(option_spec);
+
+ command_line::add_arg(option_spec, daemon_args::arg_zmq_rpc_bind_ip);
+ command_line::add_arg(option_spec, daemon_args::arg_zmq_rpc_bind_port);
+}
+
+void mock_daemon::default_options(boost::program_options::variables_map & vm)
+{
+ std::vector<std::string> exclusive_nodes{"127.0.0.1:65525"};
+ tools::options::set_option(vm, nodetool::arg_p2p_add_exclusive_node, po::variable_value(exclusive_nodes, false));
+
+ tools::options::set_option(vm, nodetool::arg_p2p_bind_ip, po::variable_value(std::string("127.0.0.1"), false));
+ tools::options::set_option(vm, nodetool::arg_no_igd, po::variable_value(true, false));
+ tools::options::set_option(vm, cryptonote::arg_offline, po::variable_value(true, false));
+ tools::options::set_option(vm, "disable-dns-checkpoints", po::variable_value(true, false));
+
+ const char *test_mainnet = getenv("TEST_MAINNET");
+ if (!test_mainnet || atoi(test_mainnet) == 0)
+ {
+ tools::options::set_option(vm, cryptonote::arg_testnet_on, po::variable_value(true, false));
+ }
+
+ // By default pick non-standard ports to avoid confusion with possibly locally running daemons (mainnet/testnet)
+ const char *test_p2p_port = getenv("TEST_P2P_PORT");
+ auto p2p_port = std::string(test_p2p_port && strlen(test_p2p_port) > 0 ? test_p2p_port : "61340");
+ tools::options::set_option(vm, nodetool::arg_p2p_bind_port, po::variable_value(p2p_port, false));
+
+ const char *test_rpc_port = getenv("TEST_RPC_PORT");
+ auto rpc_port = std::string(test_rpc_port && strlen(test_rpc_port) > 0 ? test_rpc_port : "61341");
+ tools::options::set_option(vm, cryptonote::core_rpc_server::arg_rpc_bind_port, po::variable_value(rpc_port, false));
+
+ const char *test_zmq_port = getenv("TEST_ZMQ_PORT");
+ auto zmq_port = std::string(test_zmq_port && strlen(test_zmq_port) > 0 ? test_zmq_port : "61342");
+ tools::options::set_option(vm, daemon_args::arg_zmq_rpc_bind_port, po::variable_value(zmq_port, false));
+
+ po::notify(vm);
+}
+
+void mock_daemon::set_ports(boost::program_options::variables_map & vm, unsigned initial_port)
+{
+ CHECK_AND_ASSERT_THROW_MES(initial_port < 65535-2, "Invalid port number");
+ tools::options::set_option(vm, nodetool::arg_p2p_bind_port, po::variable_value(std::to_string(initial_port), false));
+ tools::options::set_option(vm, cryptonote::core_rpc_server::arg_rpc_bind_port, po::variable_value(std::to_string(initial_port + 1), false));
+ tools::options::set_option(vm, daemon_args::arg_zmq_rpc_bind_port, po::variable_value(std::to_string(initial_port + 2), false));
+ po::notify(vm);
+}
+
+void mock_daemon::load_params(boost::program_options::variables_map const & vm)
+{
+ m_p2p_bind_port = command_line::get_arg(vm, nodetool::arg_p2p_bind_port);
+ m_rpc_bind_port = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_port);
+ m_zmq_bind_port = command_line::get_arg(vm, daemon_args::arg_zmq_rpc_bind_port);
+ m_network_type = command_line::get_arg(vm, cryptonote::arg_testnet_on) ? cryptonote::TESTNET : cryptonote::MAINNET;
+}
+
+mock_daemon::~mock_daemon()
+{
+ if (!m_terminated)
+ {
+ try
+ {
+ stop();
+ }
+ catch (...)
+ {
+ MERROR("Failed to stop");
+ }
+ }
+
+ if (!m_deinitalized)
+ {
+ deinit();
+ }
+}
+
+void mock_daemon::init()
+{
+ m_deinitalized = false;
+ const auto main_rpc_port = command_line::get_arg(m_vm, cryptonote::core_rpc_server::arg_rpc_bind_port);
+ m_rpc_server.nettype(m_network_type);
+
+ CHECK_AND_ASSERT_THROW_MES(m_protocol.init(m_vm), "Failed to initialize cryptonote protocol.");
+ CHECK_AND_ASSERT_THROW_MES(m_rpc_server.init(m_vm, false, main_rpc_port), "Failed to initialize RPC server.");
+
+ if (m_start_p2p)
+ CHECK_AND_ASSERT_THROW_MES(m_server.init(m_vm), "Failed to initialize p2p server.");
+
+ if(m_http_client.is_connected())
+ m_http_client.disconnect();
+
+ CHECK_AND_ASSERT_THROW_MES(m_http_client.set_server(rpc_addr(), boost::none), "RPC client init fail");
+}
+
+void mock_daemon::deinit()
+{
+ try
+ {
+ m_rpc_server.deinit();
+ }
+ catch (...)
+ {
+ MERROR("Failed to deinitialize RPC server...");
+ }
+
+ if (m_start_p2p)
+ {
+ try
+ {
+ m_server.deinit();
+ }
+ catch (...)
+ {
+ MERROR("Failed to deinitialize p2p...");
+ }
+ }
+
+ try
+ {
+ m_protocol.deinit();
+ m_protocol.set_p2p_endpoint(nullptr);
+ }
+ catch (...)
+ {
+ MERROR("Failed to stop cryptonote protocol!");
+ }
+
+ m_deinitalized = true;
+}
+
+void mock_daemon::init_and_run()
+{
+ init();
+ run();
+}
+
+void mock_daemon::stop_and_deinit()
+{
+ stop();
+ deinit();
+}
+
+void mock_daemon::try_init_and_run(boost::optional<unsigned> initial_port)
+{
+ const unsigned max_attempts = 3;
+ for(unsigned attempts=0; attempts < max_attempts; ++attempts)
+ {
+ if (initial_port)
+ {
+ set_ports(m_vm, initial_port.get());
+ load_params(m_vm);
+ MDEBUG("Ports changed, RPC: " << rpc_addr());
+ }
+
+ try
+ {
+ init_and_run();
+ return;
+ }
+ catch(const std::exception &e)
+ {
+ MWARNING("Could not init and start, attempt: " << attempts << ", reason: " << e.what());
+ if (attempts + 1 >= max_attempts)
+ {
+ throw;
+ }
+ }
+ }
+}
+
+void mock_daemon::run()
+{
+ m_run_thread = boost::thread(boost::bind(&mock_daemon::run_main, this));
+}
+
+bool mock_daemon::run_main()
+{
+ CHECK_AND_ASSERT_THROW_MES(!m_terminated, "Can't run stopped daemon");
+ CHECK_AND_ASSERT_THROW_MES(!m_start_zmq || m_start_p2p, "ZMQ requires P2P");
+ boost::thread stop_thread = boost::thread([this] {
+ while (!this->m_stopped)
+ epee::misc_utils::sleep_no_w(100);
+ this->stop_p2p();
+ });
+
+ epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){
+ m_stopped = true;
+ stop_thread.join();
+ });
+
+ try
+ {
+ CHECK_AND_ASSERT_THROW_MES(m_rpc_server.run(2, false), "Failed to start RPC");
+ cryptonote::rpc::DaemonHandler rpc_daemon_handler(*m_core, m_server);
+ cryptonote::rpc::ZmqServer zmq_server(rpc_daemon_handler);
+
+ if (m_start_zmq)
+ {
+ if (!zmq_server.addTCPSocket("127.0.0.1", m_zmq_bind_port))
+ {
+ MERROR("Failed to add TCP Socket (127.0.0.1:" << m_zmq_bind_port << ") to ZMQ RPC Server");
+
+ stop_rpc();
+ return false;
+ }
+
+ MINFO("Starting ZMQ server...");
+ zmq_server.run();
+
+ MINFO("ZMQ server started at 127.0.0.1: " << m_zmq_bind_port);
+ }
+
+ if (m_start_p2p)
+ {
+ m_server.run(); // blocks until p2p goes down
+ }
+ else
+ {
+ while (!this->m_stopped)
+ epee::misc_utils::sleep_no_w(100);
+ }
+
+ if (m_start_zmq)
+ zmq_server.stop();
+
+ stop_rpc();
+ return true;
+ }
+ catch (std::exception const & ex)
+ {
+ MFATAL("Uncaught exception! " << ex.what());
+ return false;
+ }
+ catch (...)
+ {
+ MFATAL("Uncaught exception!");
+ return false;
+ }
+}
+
+void mock_daemon::stop()
+{
+ CHECK_AND_ASSERT_THROW_MES(!m_terminated, "Can't stop stopped daemon");
+ m_stopped = true;
+ m_terminated = true;
+ m_run_thread.join();
+}
+
+void mock_daemon::stop_rpc()
+{
+ m_rpc_server.send_stop_signal();
+ m_rpc_server.timed_wait_server_stop(5000);
+}
+
+void mock_daemon::stop_p2p()
+{
+ if (m_start_p2p)
+ m_server.send_stop_signal();
+}
+
+void mock_daemon::mine_blocks(size_t num_blocks, const std::string &miner_address)
+{
+ bool blocks_mined = false;
+ const uint64_t start_height = get_height();
+ const auto mining_timeout = std::chrono::seconds(30);
+ MDEBUG("Current height before mining: " << start_height);
+
+ start_mining(miner_address);
+ auto mining_started = std::chrono::system_clock::now();
+
+ while(true) {
+ epee::misc_utils::sleep_no_w(100);
+ const uint64_t cur_height = get_height();
+
+ if (cur_height - start_height >= num_blocks)
+ {
+ MDEBUG("Cur blocks: " << cur_height << " start: " << start_height);
+ blocks_mined = true;
+ break;
+ }
+
+ auto current_time = std::chrono::system_clock::now();
+ if (mining_timeout < current_time - mining_started)
+ {
+ break;
+ }
+ }
+
+ stop_mining();
+ CHECK_AND_ASSERT_THROW_MES(blocks_mined, "Mining failed in the time limit");
+}
+
+constexpr const std::chrono::seconds mock_daemon::rpc_timeout;
+
+void mock_daemon::start_mining(const std::string &miner_address, uint64_t threads_count, bool do_background_mining, bool ignore_battery)
+{
+ cryptonote::COMMAND_RPC_START_MINING::request req;
+ req.miner_address = miner_address;
+ req.threads_count = threads_count;
+ req.do_background_mining = do_background_mining;
+ req.ignore_battery = ignore_battery;
+
+ cryptonote::COMMAND_RPC_START_MINING::response resp;
+ bool r = epee::net_utils::invoke_http_json("/start_mining", req, resp, m_http_client, rpc_timeout);
+ CHECK_AND_ASSERT_THROW_MES(r, "RPC error - start mining");
+ CHECK_AND_ASSERT_THROW_MES(resp.status != CORE_RPC_STATUS_BUSY, "Daemon busy");
+ CHECK_AND_ASSERT_THROW_MES(resp.status == CORE_RPC_STATUS_OK, "Daemon response invalid: " << resp.status);
+}
+
+void mock_daemon::stop_mining()
+{
+ cryptonote::COMMAND_RPC_STOP_MINING::request req;
+ cryptonote::COMMAND_RPC_STOP_MINING::response resp;
+ bool r = epee::net_utils::invoke_http_json("/stop_mining", req, resp, m_http_client, rpc_timeout);
+ CHECK_AND_ASSERT_THROW_MES(r, "RPC error - stop mining");
+ CHECK_AND_ASSERT_THROW_MES(resp.status != CORE_RPC_STATUS_BUSY, "Daemon busy");
+ CHECK_AND_ASSERT_THROW_MES(resp.status == CORE_RPC_STATUS_OK, "Daemon response invalid: " << resp.status);
+}
+
+uint64_t mock_daemon::get_height()
+{
+ return m_core->get_blockchain_storage().get_current_blockchain_height();
+}
diff --git a/tests/trezor/daemon.h b/tests/trezor/daemon.h
new file mode 100644
index 000000000..046b09a5d
--- /dev/null
+++ b/tests/trezor/daemon.h
@@ -0,0 +1,154 @@
+// Copyright (c) 2014-2018, 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.
+
+#pragma once
+
+#include "misc_log_ex.h"
+#include "daemon/daemon.h"
+#include "rpc/daemon_handler.h"
+#include "rpc/zmq_server.h"
+#include "common/password.h"
+#include "common/util.h"
+#include "daemon/core.h"
+#include "daemon/p2p.h"
+#include "daemon/protocol.h"
+#include "daemon/rpc.h"
+#include "daemon/command_server.h"
+#include "daemon/command_server.h"
+#include "daemon/command_line_args.h"
+#include "version.h"
+#include "tools.h"
+
+
+class mock_rpc_daemon : public cryptonote::core_rpc_server {
+public:
+ mock_rpc_daemon(
+ cryptonote::core& cr
+ , nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& p2p
+ ): cryptonote::core_rpc_server(cr, p2p) {}
+
+ static void init_options(boost::program_options::options_description& desc){ cryptonote::core_rpc_server::init_options(desc); }
+ cryptonote::network_type nettype() const { return m_network_type; }
+ void nettype(cryptonote::network_type nettype) { m_network_type = nettype; }
+
+ CHAIN_HTTP_TO_MAP2(cryptonote::core_rpc_server::connection_context); //forward http requests to uri map
+ BEGIN_URI_MAP2()
+ MAP_URI_AUTO_JON2("/send_raw_transaction", on_send_raw_tx_2, cryptonote::COMMAND_RPC_SEND_RAW_TX)
+ MAP_URI_AUTO_JON2("/sendrawtransaction", on_send_raw_tx_2, cryptonote::COMMAND_RPC_SEND_RAW_TX)
+ else { // Default to parent for non-overriden callbacks
+ return cryptonote::core_rpc_server::handle_http_request_map(query_info, response_info, m_conn_context);
+ }
+ END_URI_MAP2()
+
+ bool on_send_raw_tx_2(const cryptonote::COMMAND_RPC_SEND_RAW_TX::request& req, cryptonote::COMMAND_RPC_SEND_RAW_TX::response& res, const cryptonote::core_rpc_server::connection_context *ctx);
+
+protected:
+ cryptonote::network_type m_network_type;
+};
+
+class mock_daemon {
+public:
+ typedef cryptonote::t_cryptonote_protocol_handler<cryptonote::core> t_protocol_raw;
+ typedef nodetool::node_server<t_protocol_raw> t_node_server;
+
+ static constexpr const std::chrono::seconds rpc_timeout = std::chrono::seconds(60);
+
+ cryptonote::core * m_core;
+ t_protocol_raw m_protocol;
+ mock_rpc_daemon m_rpc_server;
+ t_node_server m_server;
+ cryptonote::network_type m_network_type;
+ epee::net_utils::http::http_simple_client m_http_client;
+
+ bool m_start_p2p;
+ bool m_start_zmq;
+ boost::program_options::variables_map m_vm;
+
+ std::string m_p2p_bind_port;
+ std::string m_rpc_bind_port;
+ std::string m_zmq_bind_port;
+
+ std::atomic<bool> m_stopped;
+ std::atomic<bool> m_terminated;
+ std::atomic<bool> m_deinitalized;
+ boost::thread m_run_thread;
+
+ mock_daemon(
+ cryptonote::core * core,
+ boost::program_options::variables_map const & vm
+ )
+ : m_core(core)
+ , m_vm(vm)
+ , m_start_p2p(false)
+ , m_start_zmq(false)
+ , m_terminated(false)
+ , m_deinitalized(false)
+ , m_stopped(false)
+ , m_protocol{*core, nullptr, command_line::get_arg(vm, cryptonote::arg_offline)}
+ , m_server{m_protocol}
+ , m_rpc_server{*core, m_server}
+ {
+ // Handle circular dependencies
+ m_protocol.set_p2p_endpoint(&m_server);
+ m_core->set_cryptonote_protocol(&m_protocol);
+ load_params(vm);
+ }
+
+ virtual ~mock_daemon();
+
+ static void init_options(boost::program_options::options_description & option_spec);
+ static void default_options(boost::program_options::variables_map & vm);
+ static void set_ports(boost::program_options::variables_map & vm, unsigned initial_port);
+
+ mock_daemon * set_start_p2p(bool fl) { m_start_p2p = fl; return this; }
+ mock_daemon * set_start_zmq(bool fl) { m_start_zmq = fl; return this; }
+
+ void init();
+ void deinit();
+ void run();
+ bool run_main();
+ void stop();
+ void stop_p2p();
+ void stop_rpc();
+ void init_and_run();
+ void stop_and_deinit();
+ void try_init_and_run(boost::optional<unsigned> initial_port=boost::none);
+
+ void mine_blocks(size_t num_blocks, const std::string &miner_address);
+ void start_mining(const std::string &miner_address, uint64_t threads_count=1, bool do_background_mining=false, bool ignore_battery=true);
+ void stop_mining();
+ uint64_t get_height();
+
+ void load_params(boost::program_options::variables_map const & vm);
+
+ std::string zmq_addr() const { return std::string("127.0.0.1:") + m_zmq_bind_port; }
+ std::string rpc_addr() const { return std::string("127.0.0.1:") + m_rpc_bind_port; }
+ std::string p2p_addr() const { return std::string("127.0.0.1:") + m_p2p_bind_port; }
+ cryptonote::network_type nettype() const { return m_network_type; }
+ cryptonote::core * core() const { return m_core; }
+};
diff --git a/tests/trezor/tools.cpp b/tests/trezor/tools.cpp
new file mode 100644
index 000000000..432350cf6
--- /dev/null
+++ b/tests/trezor/tools.cpp
@@ -0,0 +1,56 @@
+// Copyright (c) 2014-2018, 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 "tools.h"
+
+namespace tools {
+
+namespace po = boost::program_options;
+
+void options::set_option(boost::program_options::variables_map &vm, const std::string & key, const po::variable_value &pv)
+{
+ auto it = vm.find(key);
+ if (it == vm.end())
+ {
+ vm.insert(std::make_pair(key, pv));
+ }
+ else
+ {
+ it->second = pv;
+ }
+}
+
+void options::build_options(boost::program_options::variables_map & vm, const po::options_description & desc_params)
+{
+ const char *argv[2] = {nullptr};
+ po::store(po::parse_command_line(1, argv, desc_params), vm);
+ po::notify(vm);
+}
+
+}
+
diff --git a/tests/trezor/tools.h b/tests/trezor/tools.h
new file mode 100644
index 000000000..d348a5137
--- /dev/null
+++ b/tests/trezor/tools.h
@@ -0,0 +1,61 @@
+// Copyright (c) 2014-2018, 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.
+
+#pragma once
+
+#include "misc_log_ex.h"
+#include "daemon/daemon.h"
+#include "rpc/daemon_handler.h"
+#include "rpc/zmq_server.h"
+#include "common/password.h"
+#include "common/util.h"
+#include "daemon/core.h"
+#include "daemon/p2p.h"
+#include "daemon/protocol.h"
+#include "daemon/rpc.h"
+#include "daemon/command_server.h"
+#include "daemon/command_server.h"
+#include "daemon/command_line_args.h"
+#include "version.h"
+
+namespace tools {
+
+class options {
+public:
+ static void set_option(boost::program_options::variables_map &vm, const std::string &key, const boost::program_options::variable_value &pv);
+ static void build_options(boost::program_options::variables_map & vm, const boost::program_options::options_description & desc_params);
+
+ template<typename T, bool required, bool dependent, int NUM_DEPS>
+ static void set_option(boost::program_options::variables_map &vm, const command_line::arg_descriptor<T, required, dependent, NUM_DEPS> &arg, const boost::program_options::variable_value &pv)
+ {
+ set_option(vm, arg.name, pv);
+ }
+};
+
+};
+
diff --git a/tests/trezor/trezor_tests.cpp b/tests/trezor/trezor_tests.cpp
index c2b46f698..310fa45f1 100644
--- a/tests/trezor/trezor_tests.cpp
+++ b/tests/trezor/trezor_tests.cpp
@@ -41,6 +41,7 @@ using namespace cryptonote;
#include "common/util.h"
#include "common/command_line.h"
#include "trezor_tests.h"
+#include "tools.h"
#include "device/device_cold.hpp"
#include "device_trezor/device_trezor.hpp"
@@ -57,7 +58,7 @@ namespace
const command_line::arg_descriptor<bool> arg_fix_chain = {"fix_chain", "If chain_patch is given and file cannot be used, it is ignored and overwriten", false};
}
-
+#define HW_TREZOR_NAME "Trezor"
#define TREZOR_ACCOUNT_ORDERING &m_miner_account, &m_alice_account, &m_bob_account, &m_eve_account
#define TREZOR_COMMON_TEST_CASE(genclass, CORE, BASE) \
rollback_chain(CORE, BASE.head_block()); \
@@ -70,14 +71,17 @@ namespace
#define TREZOR_SETUP_CHAIN(NAME) do { \
++tests_count; \
try { \
- setup_chain(&core, trezor_base, chain_path, fix_chain); \
+ setup_chain(core, trezor_base, chain_path, fix_chain, vm_core); \
} catch (const std::exception& ex) { \
failed_tests.emplace_back("gen_trezor_base " #NAME); \
} \
} while(0)
+
+static device_trezor_test *trezor_device = nullptr;
+static device_trezor_test *ensure_trezor_test_device();
static void rollback_chain(cryptonote::core * core, const cryptonote::block & head);
-static void setup_chain(cryptonote::core ** core, gen_trezor_base & trezor_base, std::string chain_path, bool fix_chain);
+static void setup_chain(cryptonote::core * core, gen_trezor_base & trezor_base, std::string chain_path, bool fix_chain, const po::variables_map & vm_core);
int main(int argc, char* argv[])
{
@@ -123,38 +127,76 @@ int main(int argc, char* argv[])
const bool heavy_tests = command_line::get_arg(vm, arg_heavy_tests);
const bool fix_chain = command_line::get_arg(vm, arg_fix_chain);
- hw::trezor::register_all();
+ hw::register_device(HW_TREZOR_NAME, ensure_trezor_test_device());
+ // hw::trezor::register_all(); // We use our shim instead.
// Bootstrapping common chain & accounts
- cryptonote::core * core = nullptr;
+ const uint8_t initial_hf = 9;
+ const uint8_t max_hf = 10;
+
+ cryptonote::core core_obj(nullptr);
+ cryptonote::core * const core = &core_obj;
+ std::shared_ptr<mock_daemon> daemon = nullptr;
gen_trezor_base trezor_base;
trezor_base.setup_args(trezor_path, heavy_tests);
- trezor_base.rct_config({rct::RangeProofPaddedBulletproof, 1}); // HF9 tests
+ trezor_base.set_hard_fork(initial_hf);
- TREZOR_SETUP_CHAIN("HF9");
-
- // Individual test cases using shared pre-generated blockchain.
- TREZOR_COMMON_TEST_CASE(gen_trezor_ki_sync, core, trezor_base);
+ // Arguments for core & daemon
+ po::variables_map vm_core;
+ po::options_description desc_params_core("Core");
+ mock_daemon::init_options(desc_params_core);
+ tools::options::build_options(vm_core, desc_params_core);
+ mock_daemon::default_options(vm_core);
// Transaction tests
- TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo, core, trezor_base);
- TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo_paymentid_short, core, trezor_base);
- TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo_paymentid_short_integrated, core, trezor_base);
- TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo_paymentid_long, core, trezor_base);
- TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo, core, trezor_base);
- TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_acc1, core, trezor_base);
- TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_sub, core, trezor_base);
- TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_2sub, core, trezor_base);
- TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_1norm_2sub, core, trezor_base);
- TREZOR_COMMON_TEST_CASE(gen_trezor_2utxo_sub_acc_to_1norm_2sub, core, trezor_base);
- TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_7outs, core, trezor_base);
+ for(uint8_t hf=initial_hf; hf <= max_hf; ++hf)
+ {
+ MDEBUG("Transaction tests for HF " << (int)hf);
+ if (hf > initial_hf)
+ {
+ daemon->stop_and_deinit();
+ daemon = nullptr;
+ trezor_base.daemon(nullptr);
+ }
+
+ trezor_base.set_hard_fork(hf);
+ TREZOR_SETUP_CHAIN(std::string("HF") + std::to_string((int)hf));
+
+ daemon = std::make_shared<mock_daemon>(core, vm_core);
+ CHECK_AND_ASSERT_THROW_MES(daemon->nettype() == trezor_base.nettype(), "Serialized chain network type does not match");
+
+ daemon->try_init_and_run();
+ trezor_base.daemon(daemon);
+
+ // Hard-fork independent tests
+ if (hf == initial_hf)
+ {
+ TREZOR_COMMON_TEST_CASE(gen_trezor_ki_sync_without_refresh, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_live_refresh, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_ki_sync_with_refresh, core, trezor_base);
+ }
+
+ TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo_paymentid_short, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo_paymentid_short_integrated, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo_paymentid_long, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_acc1, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_sub, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_2sub, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_1norm_2sub, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_2utxo_sub_acc_to_1norm_2sub, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_7outs, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(wallet_api_tests, core, trezor_base);
+ }
if (trezor_base.heavy_tests())
{
TREZOR_COMMON_TEST_CASE(gen_trezor_many_utxo, core, trezor_base);
}
+ daemon->stop();
core->deinit();
el::Level level = (failed_tests.empty() ? el::Level::Info : el::Level::Error);
MLOG(level, "\nREPORT:");
@@ -243,7 +285,36 @@ static bool serialize_chain_to_file(std::vector<test_event_entry>& events, gen_t
CATCH_ENTRY_L0("serialize_chain_to_file", false);
}
-static void setup_chain(cryptonote::core ** core, gen_trezor_base & trezor_base, std::string chain_path, bool fix_chain)
+template<class t_test_class>
+static bool init_core_replay_events(std::vector<test_event_entry>& events, cryptonote::core * core, const po::variables_map & vm_core)
+{
+ // this test needs for it to be so.
+ get_test_options<t_test_class> gto;
+
+ // Hardforks can be specified in events.
+ v_hardforks_t hardforks;
+ cryptonote::test_options test_options_tmp{};
+ const cryptonote::test_options * test_options_ = &gto.test_options;
+ if (extract_hard_forks(events, hardforks)){
+ hardforks.push_back(std::make_pair((uint8_t)0, (uint64_t)0)); // terminator
+ test_options_tmp.hard_forks = hardforks.data();
+ test_options_ = &test_options_tmp;
+ }
+
+ core->deinit();
+ CHECK_AND_ASSERT_THROW_MES(core->init(vm_core, test_options_), "Core init failed");
+ core->get_blockchain_storage().get_db().set_batch_transactions(true);
+
+ // start with a clean pool
+ std::vector<crypto::hash> pool_txs;
+ CHECK_AND_ASSERT_THROW_MES(core->get_pool_transaction_hashes(pool_txs), "Failed to flush txpool");
+ core->get_blockchain_storage().flush_txes_from_pool(pool_txs);
+
+ t_test_class validator;
+ return replay_events_through_core<t_test_class>(*core, events, validator);
+}
+
+static void setup_chain(cryptonote::core * core, gen_trezor_base & trezor_base, std::string chain_path, bool fix_chain, const po::variables_map & vm_core)
{
std::vector<test_event_entry> events;
const bool do_serialize = !chain_path.empty();
@@ -272,6 +343,7 @@ static void setup_chain(cryptonote::core ** core, gen_trezor_base & trezor_base,
{
try
{
+ trezor_base.clear();
generated = trezor_base.generate(events);
if (generated && !loaded && do_serialize)
@@ -287,7 +359,7 @@ static void setup_chain(cryptonote::core ** core, gen_trezor_base & trezor_base,
}
trezor_base.fix_hf(events);
- if (generated && do_replay_events_get_core<gen_trezor_base>(events, core))
+ if (generated && init_core_replay_events<gen_trezor_base>(events, core, vm_core))
{
MGINFO_GREEN("#TEST-chain-init# Succeeded ");
}
@@ -298,6 +370,14 @@ static void setup_chain(cryptonote::core ** core, gen_trezor_base & trezor_base,
}
}
+static device_trezor_test *ensure_trezor_test_device(){
+ if (!trezor_device) {
+ trezor_device = new device_trezor_test();
+ trezor_device->set_name(HW_TREZOR_NAME);
+ }
+ return trezor_device;
+}
+
static void add_hforks(std::vector<test_event_entry>& events, const v_hardforks_t& hard_forks)
{
event_replay_settings repl_set;
@@ -483,8 +563,20 @@ static std::vector<tools::wallet2*> vct_wallets(tools::wallet2* w1=nullptr, tool
return res;
}
+static uint64_t get_available_funds(tools::wallet2* wallet, uint32_t account=0)
+{
+ tools::wallet2::transfer_container transfers;
+ wallet->get_transfers(transfers);
+ uint64_t sum = 0;
+ for(const auto & cur : transfers)
+ {
+ sum += !cur.m_spent && cur.m_subaddr_index.major == account ? cur.amount() : 0;
+ }
+ return sum;
+}
+
// gen_trezor_base
-const uint64_t gen_trezor_base::m_ts_start = 1338224400;
+const uint64_t gen_trezor_base::m_ts_start = 1397862000; // As default wallet timestamp is 1397516400
const uint64_t gen_trezor_base::m_wallet_ts = m_ts_start - 60*60*24*4;
const std::string gen_trezor_base::m_device_name = "Trezor:udp";
const std::string gen_trezor_base::m_master_seed_str = "14821d0bc5659b24cafbc889dc4fc60785ee08b65d71c525f81eeaba4f3a570f";
@@ -494,12 +586,16 @@ const std::string gen_trezor_base::m_alice_view_private = "a6ccd4ac344a295d1387f
gen_trezor_base::gen_trezor_base(){
m_rct_config = {rct::RangeProofPaddedBulletproof, 1};
+ m_test_get_tx_key = true;
+ m_network_type = cryptonote::TESTNET;
}
gen_trezor_base::gen_trezor_base(const gen_trezor_base &other):
m_generator(other.m_generator), m_bt(other.m_bt), m_miner_account(other.m_miner_account),
m_bob_account(other.m_bob_account), m_alice_account(other.m_alice_account), m_eve_account(other.m_eve_account),
- m_hard_forks(other.m_hard_forks), m_trezor(other.m_trezor), m_rct_config(other.m_rct_config)
+ m_hard_forks(other.m_hard_forks), m_trezor(other.m_trezor), m_rct_config(other.m_rct_config),
+ m_heavy_tests(other.m_heavy_tests), m_test_get_tx_key(other.m_test_get_tx_key), m_live_refresh_enabled(other.m_live_refresh_enabled),
+ m_network_type(other.m_network_type), m_daemon(other.m_daemon)
{
}
@@ -513,33 +609,27 @@ void gen_trezor_base::setup_args(const std::string & trezor_path, bool heavy_tes
void gen_trezor_base::setup_trezor()
{
hw::device &hwdev = hw::get_device(m_trezor_path);
- m_trezor = dynamic_cast<hw::trezor::device_trezor *>(&hwdev);
- CHECK_AND_ASSERT_THROW_MES(m_trezor, "Dynamic cast failed");
-
- m_trezor->set_debug(true); // debugging commands on Trezor (auto-confirm transactions)
-
- CHECK_AND_ASSERT_THROW_MES(m_trezor->set_name(m_trezor_path), "Could not set device name " << m_trezor_path);
- m_trezor->set_network_type(MAINNET);
- m_trezor->set_derivation_path(""); // empty derivation path
+ auto trezor = dynamic_cast<device_trezor_test *>(&hwdev);
+ CHECK_AND_ASSERT_THROW_MES(trezor, "Dynamic cast failed");
- CHECK_AND_ASSERT_THROW_MES(m_trezor->init(), "Could not initialize the device " << m_trezor_path);
- CHECK_AND_ASSERT_THROW_MES(m_trezor->connect(), "Could not connect to the device " << m_trezor_path);
- m_trezor->wipe_device();
- m_trezor->load_device(m_device_seed);
- m_trezor->release();
- m_trezor->disconnect();
+ trezor->setup_for_tests(m_trezor_path, m_device_seed, m_network_type);
+ m_trezor = trezor;
}
void gen_trezor_base::fork(gen_trezor_base & other)
{
other.m_generator = m_generator;
other.m_bt = m_bt;
+ other.m_network_type = m_network_type;
+ other.m_daemon = m_daemon;
other.m_events = m_events;
other.m_head = m_head;
other.m_hard_forks = m_hard_forks;
other.m_trezor_path = m_trezor_path;
other.m_heavy_tests = m_heavy_tests;
other.m_rct_config = m_rct_config;
+ other.m_test_get_tx_key = m_test_get_tx_key;
+ other.m_live_refresh_enabled = m_live_refresh_enabled;
other.m_miner_account = m_miner_account;
other.m_bob_account = m_bob_account;
@@ -577,10 +667,22 @@ void gen_trezor_base::init_fields()
m_alice_account.set_createtime(m_wallet_ts);
}
+void gen_trezor_base::update_client_settings()
+{
+ auto dev_trezor = dynamic_cast<::hw::trezor::device_trezor*>(m_trezor);
+ CHECK_AND_ASSERT_THROW_MES(dev_trezor, "Could not cast to device_trezor");
+
+ dev_trezor->set_live_refresh_enabled(m_live_refresh_enabled);
+}
+
bool gen_trezor_base::generate(std::vector<test_event_entry>& events)
{
init_fields();
setup_trezor();
+
+ m_live_refresh_enabled = false;
+ update_client_settings();
+
m_alice_account.create_from_device(*m_trezor);
m_alice_account.set_createtime(m_wallet_ts);
@@ -589,7 +691,7 @@ bool gen_trezor_base::generate(std::vector<test_event_entry>& events)
cryptonote::block blk_gen;
std::vector<size_t> block_weights;
- generate_genesis_block(blk_gen, get_config(MAINNET).GENESIS_TX, get_config(MAINNET).GENESIS_NONCE);
+ generate_genesis_block(blk_gen, get_config(m_network_type).GENESIS_TX, get_config(m_network_type).GENESIS_NONCE);
events.push_back(blk_gen);
generator.add_block(blk_gen, 0, block_weights, 0);
@@ -644,8 +746,8 @@ bool gen_trezor_base::generate(std::vector<test_event_entry>& events)
MDEBUG("Hardfork height: " << hardfork_height << " at block: " << get_block_hash(blk_4r));
// RCT transactions, wallets have to be used, wallet init
- m_wl_alice.reset(new tools::wallet2(MAINNET, 1, true));
- m_wl_bob.reset(new tools::wallet2(MAINNET, 1, true));
+ m_wl_alice.reset(new tools::wallet2(m_network_type, 1, true));
+ m_wl_bob.reset(new tools::wallet2(m_network_type, 1, true));
wallet_accessor_test::set_account(m_wl_alice.get(), m_alice_account);
wallet_accessor_test::set_account(m_wl_bob.get(), m_bob_account);
@@ -659,7 +761,7 @@ bool gen_trezor_base::generate(std::vector<test_event_entry>& events)
auto addr_alice_sub_1_2 = m_wl_alice->get_subaddress({1, 2});
// Miner -> Bob, RCT funds
- MAKE_TX_LIST_START_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(5), 10, blk_4);
+ MAKE_TX_LIST_START_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(50), 10, blk_4);
const size_t target_rct = m_heavy_tests ? 105 : 15;
for(size_t i = 0; i < target_rct; ++i)
@@ -688,9 +790,9 @@ bool gen_trezor_base::generate(std::vector<test_event_entry>& events)
// Simple RCT transactions
MAKE_TX_MIX_LIST_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(7), 10, blk_4);
- MAKE_TX_MIX_LIST_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(1), 10, blk_4);
- MAKE_TX_MIX_LIST_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(3), 10, blk_4);
- MAKE_TX_MIX_LIST_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(4), 10, blk_4);
+ MAKE_TX_MIX_LIST_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(10), 10, blk_4);
+ MAKE_TX_MIX_LIST_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(30), 10, blk_4);
+ MAKE_TX_MIX_LIST_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(40), 10, blk_4);
MAKE_NEXT_BLOCK_TX_LIST_HF(events, blk_5, blk_4r, m_miner_account, txs_blk_5, CUR_HF);
// Simple transaction check
@@ -704,6 +806,8 @@ bool gen_trezor_base::generate(std::vector<test_event_entry>& events)
// RCT transactions, wallets have to be used
wallet_tools::process_transactions(m_wl_alice.get(), events, blk_5r, m_bt);
wallet_tools::process_transactions(m_wl_bob.get(), events, blk_5r, m_bt);
+ MDEBUG("Available funds on Alice: " << get_available_funds(m_wl_alice.get()));
+ MDEBUG("Available funds on Bob: " << get_available_funds(m_wl_bob.get()));
// Send Alice -> Bob, manually constructed. Simple TX test, precondition.
cryptonote::transaction tx_1;
@@ -768,18 +872,21 @@ void gen_trezor_base::load(std::vector<test_event_entry>& events)
m_eve_account.set_createtime(m_wallet_ts);
setup_trezor();
+ update_client_settings();
m_alice_account.create_from_device(*m_trezor);
m_alice_account.set_createtime(m_wallet_ts);
- m_wl_alice.reset(new tools::wallet2(MAINNET, 1, true));
- m_wl_bob.reset(new tools::wallet2(MAINNET, 1, true));
- m_wl_eve.reset(new tools::wallet2(MAINNET, 1, true));
+ m_wl_alice.reset(new tools::wallet2(m_network_type, 1, true));
+ m_wl_bob.reset(new tools::wallet2(m_network_type, 1, true));
+ m_wl_eve.reset(new tools::wallet2(m_network_type, 1, true));
wallet_accessor_test::set_account(m_wl_alice.get(), m_alice_account);
wallet_accessor_test::set_account(m_wl_bob.get(), m_bob_account);
wallet_accessor_test::set_account(m_wl_eve.get(), m_eve_account);
wallet_tools::process_transactions(m_wl_alice.get(), events, m_head, m_bt);
wallet_tools::process_transactions(m_wl_bob.get(), events, m_head, m_bt);
+ MDEBUG("Available funds on Alice: " << get_available_funds(m_wl_alice.get()));
+ MDEBUG("Available funds on Bob: " << get_available_funds(m_wl_bob.get()));
}
void gen_trezor_base::fix_hf(std::vector<test_event_entry>& events)
@@ -804,12 +911,14 @@ void gen_trezor_base::test_setup(std::vector<test_event_entry>& events)
add_shared_events(events);
setup_trezor();
+ update_client_settings();
+
m_alice_account.create_from_device(*m_trezor);
m_alice_account.set_createtime(m_wallet_ts);
- m_wl_alice.reset(new tools::wallet2(MAINNET, 1, true));
- m_wl_bob.reset(new tools::wallet2(MAINNET, 1, true));
- m_wl_eve.reset(new tools::wallet2(MAINNET, 1, true));
+ m_wl_alice.reset(new tools::wallet2(m_network_type, 1, true));
+ m_wl_bob.reset(new tools::wallet2(m_network_type, 1, true));
+ m_wl_eve.reset(new tools::wallet2(m_network_type, 1, true));
wallet_accessor_test::set_account(m_wl_alice.get(), m_alice_account);
wallet_accessor_test::set_account(m_wl_bob.get(), m_bob_account);
wallet_accessor_test::set_account(m_wl_eve.get(), m_eve_account);
@@ -818,13 +927,11 @@ void gen_trezor_base::test_setup(std::vector<test_event_entry>& events)
wallet_tools::process_transactions(m_wl_eve.get(), events, m_head, m_bt);
}
-void gen_trezor_base::test_trezor_tx(std::vector<test_event_entry>& events, std::vector<tools::wallet2::pending_tx>& ptxs, std::vector<cryptonote::address_parse_info>& dsts_info, test_generator &generator, std::vector<tools::wallet2*> wallets, bool is_sweep)
+void gen_trezor_base::add_transactions_to_events(
+ std::vector<test_event_entry>& events,
+ test_generator &generator,
+ const std::vector<cryptonote::transaction> &txs)
{
- // Construct pending transaction for signature in the Trezor.
- const uint64_t height_pre = num_blocks(events) - 1;
- cryptonote::block head_block = get_head_block(events);
- const crypto::hash head_hash = get_block_hash(head_block);
-
// If current test requires higher hard-fork, move it up
const auto current_hf = m_hard_forks.back().first;
const uint8_t tx_hf = m_rct_config.bp_version == 2 ? 10 : 9;
@@ -832,8 +939,28 @@ void gen_trezor_base::test_trezor_tx(std::vector<test_event_entry>& events, std:
throw std::runtime_error("Too late for HF change");
}
- tools::wallet2::unsigned_tx_set txs;
std::list<cryptonote::transaction> tx_list;
+ for(const auto & tx : txs)
+ {
+ events.push_back(tx);
+ tx_list.push_back(tx);
+ }
+
+ MAKE_NEXT_BLOCK_TX_LIST_HF(events, blk_new, m_head, m_miner_account, tx_list, tx_hf);
+ MDEBUG("New tsx: " << (num_blocks(events) - 1) << " at block: " << get_block_hash(blk_new));
+
+ m_head = blk_new;
+}
+
+void gen_trezor_base::test_trezor_tx(std::vector<test_event_entry>& events, std::vector<tools::wallet2::pending_tx>& ptxs, std::vector<cryptonote::address_parse_info>& dsts_info, test_generator &generator, std::vector<tools::wallet2*> wallets, bool is_sweep)
+{
+ // Construct pending transaction for signature in the Trezor.
+ const uint64_t height_pre = num_blocks(events) - 1;
+ cryptonote::block head_block = get_head_block(events);
+ const crypto::hash head_hash = get_block_hash(head_block);
+
+ tools::wallet2::unsigned_tx_set txs;
+ std::vector<cryptonote::transaction> tx_list;
for(auto &ptx : ptxs) {
txs.txes.push_back(get_construction_data_with_decrypted_short_payment_id(ptx, *m_trezor));
@@ -848,6 +975,7 @@ void gen_trezor_base::test_trezor_tx(std::vector<test_event_entry>& events, std:
hw::wallet_shim wallet_shim;
setup_shim(&wallet_shim);
aux_data.tx_recipients = dsts_info;
+ aux_data.bp_version = m_rct_config.bp_version;
dev_cold->tx_sign(&wallet_shim, txs, exported_txs, aux_data);
MDEBUG("Signed tx data from hw: " << exported_txs.ptx.size() << " transactions");
@@ -865,13 +993,11 @@ void gen_trezor_base::test_trezor_tx(std::vector<test_event_entry>& events, std:
CHECK_AND_ASSERT_THROW_MES(resx, "Trezor tx_1 semantics failed");
CHECK_AND_ASSERT_THROW_MES(resy, "Trezor tx_1 Nonsemantics failed");
- events.push_back(c_ptx.tx);
tx_list.push_back(c_ptx.tx);
MDEBUG("Transaction: " << dump_data(c_ptx.tx));
}
- MAKE_NEXT_BLOCK_TX_LIST_HF(events, blk_7, m_head, m_miner_account, tx_list, tx_hf);
- MDEBUG("Trezor tsx: " << (num_blocks(events) - 1) << " at block: " << get_block_hash(blk_7));
+ add_transactions_to_events(events, generator, tx_list);
// TX receive test
uint64_t sum_in = 0;
@@ -909,7 +1035,7 @@ void gen_trezor_base::test_trezor_tx(std::vector<test_event_entry>& events, std:
const bool sender = widx == 0;
tools::wallet2 *wl = wallets[widx];
- wallet_tools::process_transactions(wl, events, blk_7, m_bt, boost::make_optional(head_hash));
+ wallet_tools::process_transactions(wl, events, m_head, m_bt, boost::make_optional(head_hash));
tools::wallet2::transfer_container m_trans;
tools::wallet2::transfer_container m_trans_txid;
@@ -972,6 +1098,120 @@ void gen_trezor_base::test_trezor_tx(std::vector<test_event_entry>& events, std:
}
CHECK_AND_ASSERT_THROW_MES(sum_in == sum_out, "Tx amount mismatch");
+
+ // Test get_tx_key feature for stored private tx keys
+ test_get_tx(events, wallets, exported_txs.ptx, aux_data.tx_device_aux);
+}
+
+bool gen_trezor_base::verify_tx_key(const ::crypto::secret_key & tx_priv, const ::crypto::public_key & tx_pub, const subaddresses_t & subs)
+{
+ ::crypto::public_key tx_pub_c;
+ ::crypto::secret_key_to_public_key(tx_priv, tx_pub_c);
+ if (tx_pub == tx_pub_c)
+ return true;
+
+ for(const auto & elem : subs)
+ {
+ tx_pub_c = rct::rct2pk(rct::scalarmultKey(rct::pk2rct(elem.first), rct::sk2rct(tx_priv)));
+ if (tx_pub == tx_pub_c)
+ return true;
+ }
+ return false;
+}
+
+void gen_trezor_base::test_get_tx(
+ std::vector<test_event_entry>& events,
+ std::vector<tools::wallet2*> wallets,
+ const std::vector<tools::wallet2::pending_tx> &ptxs,
+ const std::vector<std::string> &aux_tx_info)
+{
+ if (!m_test_get_tx_key)
+ {
+ return;
+ }
+
+ auto dev_cold = dynamic_cast<::hw::device_cold*>(m_trezor);
+ CHECK_AND_ASSERT_THROW_MES(dev_cold, "Device does not implement cold signing interface");
+
+ if (!dev_cold->is_get_tx_key_supported())
+ {
+ MERROR("Get TX key is not supported by the connected Trezor");
+ return;
+ }
+
+ subaddresses_t all_subs;
+ for(tools::wallet2 * wlt : wallets)
+ {
+ wlt->expand_subaddresses({10, 20});
+
+ const subaddresses_t & cur_sub = wallet_accessor_test::get_subaddresses(wlt);
+ all_subs.insert(cur_sub.begin(), cur_sub.end());
+ }
+
+ for(size_t txid = 0; txid < ptxs.size(); ++txid)
+ {
+ const auto &c_ptx = ptxs[txid];
+ const auto &c_tx = c_ptx.tx;
+ const ::crypto::hash tx_prefix_hash = cryptonote::get_transaction_prefix_hash(c_tx);
+
+ auto tx_pub = cryptonote::get_tx_pub_key_from_extra(c_tx.extra);
+ auto additional_pub_keys = cryptonote::get_additional_tx_pub_keys_from_extra(c_tx.extra);
+
+ hw::device_cold:: tx_key_data_t tx_key_data;
+ std::vector<::crypto::secret_key> tx_keys;
+
+ dev_cold->load_tx_key_data(tx_key_data, aux_tx_info[txid]);
+ CHECK_AND_ASSERT_THROW_MES(std::string(tx_prefix_hash.data, 32) == tx_key_data.tx_prefix_hash, "TX prefix mismatch");
+
+ dev_cold->get_tx_key(tx_keys, tx_key_data, m_alice_account.get_keys().m_view_secret_key);
+ CHECK_AND_ASSERT_THROW_MES(!tx_keys.empty(), "Empty TX keys");
+ CHECK_AND_ASSERT_THROW_MES(verify_tx_key(tx_keys[0], tx_pub, all_subs), "Tx pub mismatch");
+ CHECK_AND_ASSERT_THROW_MES(additional_pub_keys.size() == tx_keys.size() - 1, "Invalid additional keys count");
+
+ for(size_t i = 0; i < additional_pub_keys.size(); ++i)
+ {
+ CHECK_AND_ASSERT_THROW_MES(verify_tx_key(tx_keys[i + 1], additional_pub_keys[i], all_subs), "Tx pub mismatch");
+ }
+ }
+}
+
+void gen_trezor_base::mine_and_test(std::vector<test_event_entry>& events)
+{
+ cryptonote::core * core = daemon()->core();
+ const uint64_t height_before_mining = daemon()->get_height();
+
+ const auto miner_address = cryptonote::get_account_address_as_str(FAKECHAIN, false, get_address(m_miner_account));
+ daemon()->mine_blocks(1, miner_address);
+
+ const uint64_t cur_height = daemon()->get_height();
+ CHECK_AND_ASSERT_THROW_MES(height_before_mining < cur_height, "Mining fail");
+
+ const crypto::hash top_hash = core->get_blockchain_storage().get_block_id_by_height(height_before_mining);
+ cryptonote::block top_block{};
+ CHECK_AND_ASSERT_THROW_MES(core->get_blockchain_storage().get_block_by_hash(top_hash, top_block), "Block fetch fail");
+ CHECK_AND_ASSERT_THROW_MES(!top_block.tx_hashes.empty(), "Mined block is empty");
+
+ std::vector<cryptonote::transaction> txs_found;
+ std::vector<crypto::hash> txs_missed;
+ bool r = core->get_blockchain_storage().get_transactions(top_block.tx_hashes, txs_found, txs_missed);
+ CHECK_AND_ASSERT_THROW_MES(r, "Transaction lookup fail");
+ CHECK_AND_ASSERT_THROW_MES(!txs_found.empty(), "Transaction lookup fail");
+
+ // Transaction is not expanded, but mining verified it.
+ events.push_back(txs_found[0]);
+ events.push_back(top_block);
+}
+
+void gen_trezor_base::set_hard_fork(uint8_t hf)
+{
+ m_top_hard_fork = hf;
+ if (hf < 9){
+ throw std::runtime_error("Minimal supported Hardfork is 9");
+ } else if (hf == 9){
+ rct_config({rct::RangeProofPaddedBulletproof, 1});
+ } else {
+ rct_config({rct::RangeProofPaddedBulletproof, 2});
+ }
}
#define TREZOR_TEST_PREFIX() \
@@ -1182,6 +1422,48 @@ std::vector<tools::wallet2::pending_tx> tsx_builder::build()
return m_ptxs;
}
+device_trezor_test::device_trezor_test(): m_tx_sign_ctr(0), m_compute_key_image_ctr(0) {}
+
+void device_trezor_test::clear_test_counters(){
+ m_tx_sign_ctr = 0;
+ m_compute_key_image_ctr = 0;
+}
+
+void device_trezor_test::setup_for_tests(const std::string & trezor_path, const std::string & seed, cryptonote::network_type network_type){
+ this->clear_test_counters();
+ this->set_callback(nullptr);
+ this->set_debug(true); // debugging commands on Trezor (auto-confirm transactions)
+
+ CHECK_AND_ASSERT_THROW_MES(this->set_name(trezor_path), "Could not set device name " << trezor_path);
+ this->set_network_type(network_type);
+ this->set_derivation_path(""); // empty derivation path
+
+ CHECK_AND_ASSERT_THROW_MES(this->init(), "Could not initialize the device " << trezor_path);
+ CHECK_AND_ASSERT_THROW_MES(this->connect(), "Could not connect to the device " << trezor_path);
+ this->wipe_device();
+ this->load_device(seed);
+ this->release();
+ this->disconnect();
+}
+
+bool device_trezor_test::compute_key_image(const ::cryptonote::account_keys &ack, const ::crypto::public_key &out_key,
+ const ::crypto::key_derivation &recv_derivation, size_t real_output_index,
+ const ::cryptonote::subaddress_index &received_index,
+ ::cryptonote::keypair &in_ephemeral, ::crypto::key_image &ki) {
+
+ bool res = device_trezor::compute_key_image(ack, out_key, recv_derivation, real_output_index, received_index,
+ in_ephemeral, ki);
+ m_compute_key_image_ctr += res;
+ return res;
+}
+
+void
+device_trezor_test::tx_sign(hw::wallet_shim *wallet, const ::tools::wallet2::unsigned_tx_set &unsigned_tx, size_t idx,
+ hw::tx_aux_data &aux_data, std::shared_ptr<hw::trezor::protocol::tx::Signer> &signer) {
+ m_tx_sign_ctr += 1;
+ device_trezor::tx_sign(wallet, unsigned_tx, idx, aux_data, signer);
+}
+
bool gen_trezor_ki_sync::generate(std::vector<test_event_entry>& events)
{
test_generator generator(m_generator);
@@ -1207,6 +1489,92 @@ bool gen_trezor_ki_sync::generate(std::vector<test_event_entry>& events)
uint64_t spent = 0, unspent = 0;
m_wl_alice->import_key_images(ski, 0, spent, unspent, false);
+
+ auto dev_trezor_test = dynamic_cast<device_trezor_test*>(m_trezor);
+ CHECK_AND_ASSERT_THROW_MES(dev_cold, "Device does not implement test interface");
+ if (!m_live_refresh_enabled)
+ CHECK_AND_ASSERT_THROW_MES(dev_trezor_test->m_compute_key_image_ctr == 0, "Live refresh should not happen: " << dev_trezor_test->m_compute_key_image_ctr);
+ else
+ CHECK_AND_ASSERT_THROW_MES(dev_trezor_test->m_compute_key_image_ctr == ski.size(), "Live refresh counts invalid");
+
+ return true;
+}
+
+bool gen_trezor_ki_sync_with_refresh::generate(std::vector<test_event_entry>& events)
+{
+ m_live_refresh_enabled = true;
+ return gen_trezor_ki_sync::generate(events);
+}
+
+bool gen_trezor_ki_sync_without_refresh::generate(std::vector<test_event_entry>& events)
+{
+ m_live_refresh_enabled = false;
+ return gen_trezor_ki_sync::generate(events);
+}
+
+bool gen_trezor_live_refresh::generate(std::vector<test_event_entry>& events)
+{
+ test_generator generator(m_generator);
+ test_setup(events);
+
+ auto dev_cold = dynamic_cast<::hw::device_cold*>(m_trezor);
+ CHECK_AND_ASSERT_THROW_MES(dev_cold, "Device does not implement cold signing interface");
+
+ if (!dev_cold->is_live_refresh_supported()){
+ MDEBUG("Trezor does not support live refresh");
+ return true;
+ }
+
+ hw::device & sw_device = hw::get_device("default");
+
+ dev_cold->live_refresh_start();
+ for(unsigned i=0; i<50; ++i)
+ {
+ cryptonote::subaddress_index subaddr = {0, i};
+
+ ::crypto::secret_key r;
+ ::crypto::public_key R;
+ ::crypto::key_derivation D;
+ ::crypto::public_key pub_ver;
+ ::crypto::key_image ki;
+
+ ::crypto::random32_unbiased((unsigned char*)r.data);
+ ::crypto::secret_key_to_public_key(r, R);
+ memcpy(D.data, rct::scalarmultKey(rct::pk2rct(R), rct::sk2rct(m_alice_account.get_keys().m_view_secret_key)).bytes, 32);
+
+ ::crypto::secret_key scalar_step1;
+ ::crypto::secret_key scalar_step2;
+ ::crypto::derive_secret_key(D, i, m_alice_account.get_keys().m_spend_secret_key, scalar_step1);
+ if (i == 0)
+ {
+ scalar_step2 = scalar_step1;
+ }
+ else
+ {
+ ::crypto::secret_key subaddr_sk = sw_device.get_subaddress_secret_key(m_alice_account.get_keys().m_view_secret_key, subaddr);
+ sw_device.sc_secret_add(scalar_step2, scalar_step1, subaddr_sk);
+ }
+
+ ::crypto::secret_key_to_public_key(scalar_step2, pub_ver);
+ ::crypto::generate_key_image(pub_ver, scalar_step2, ki);
+
+ cryptonote::keypair in_ephemeral;
+ ::crypto::key_image ki2;
+
+ dev_cold->live_refresh(
+ m_alice_account.get_keys().m_view_secret_key,
+ pub_ver,
+ D,
+ i,
+ subaddr,
+ in_ephemeral,
+ ki2
+ );
+
+ CHECK_AND_ASSERT_THROW_MES(ki == ki2, "Key image inconsistent");
+ }
+
+ dev_cold->live_refresh_finish();
return true;
}
@@ -1407,3 +1775,62 @@ bool gen_trezor_many_utxo::generate(std::vector<test_event_entry>& events)
TREZOR_TEST_SUFFIX();
}
+void wallet_api_tests::init()
+{
+ m_wallet_dir = boost::filesystem::unique_path();
+ boost::filesystem::create_directories(m_wallet_dir);
+}
+
+wallet_api_tests::~wallet_api_tests()
+{
+ try
+ {
+ if (!m_wallet_dir.empty() && boost::filesystem::exists(m_wallet_dir))
+ {
+ boost::filesystem::remove_all(m_wallet_dir);
+ }
+ }
+ catch(...)
+ {
+ MERROR("Could not remove wallet directory");
+ }
+}
+
+bool wallet_api_tests::generate(std::vector<test_event_entry>& events)
+{
+ init();
+ test_setup(events);
+ const std::string wallet_path = (m_wallet_dir / "wallet").string();
+ const auto api_net_type = m_network_type == TESTNET ? Monero::TESTNET : Monero::MAINNET;
+
+ Monero::WalletManager *wmgr = Monero::WalletManagerFactory::getWalletManager();
+ std::unique_ptr<Monero::Wallet> w{wmgr->createWalletFromDevice(wallet_path, "", api_net_type, m_trezor_path, 1)};
+ CHECK_AND_ASSERT_THROW_MES(w->init(daemon()->rpc_addr(), 0), "Wallet init fail");
+ CHECK_AND_ASSERT_THROW_MES(w->refresh(), "Refresh fail");
+ uint64_t balance = w->balance(0);
+ MINFO("Balance: " << balance);
+ CHECK_AND_ASSERT_THROW_MES(w->status() == Monero::PendingTransaction::Status_Ok, "Status nok");
+
+ auto addr = get_address(m_eve_account);
+ auto recepient_address = cryptonote::get_account_address_as_str(m_network_type, false, addr);
+ Monero::PendingTransaction * transaction = w->createTransaction(recepient_address,
+ "",
+ MK_COINS(10),
+ TREZOR_TEST_MIXIN,
+ Monero::PendingTransaction::Priority_Medium,
+ 0,
+ std::set<uint32_t>{});
+ CHECK_AND_ASSERT_THROW_MES(transaction->status() == Monero::PendingTransaction::Status_Ok, "Status nok");
+ w->refresh();
+
+ CHECK_AND_ASSERT_THROW_MES(w->balance(0) == balance, "Err");
+ CHECK_AND_ASSERT_THROW_MES(transaction->amount() == MK_COINS(10), "Err");
+ CHECK_AND_ASSERT_THROW_MES(transaction->commit(), "Err");
+ CHECK_AND_ASSERT_THROW_MES(w->balance(0) != balance, "Err");
+ CHECK_AND_ASSERT_THROW_MES(wmgr->closeWallet(w.get()), "Err");
+ (void)w.release();
+
+ mine_and_test(events);
+ return true;
+}
+
diff --git a/tests/trezor/trezor_tests.h b/tests/trezor/trezor_tests.h
index 41db1cce5..bed49fec4 100644
--- a/tests/trezor/trezor_tests.h
+++ b/tests/trezor/trezor_tests.h
@@ -31,6 +31,8 @@
#pragma once
#include <device_trezor/device_trezor.hpp>
+#include <wallet/api/wallet2_api.h>
+#include "daemon.h"
#include "../core_tests/chaingen.h"
#include "../core_tests/wallet_tools.h"
@@ -50,29 +52,48 @@ public:
gen_trezor_base(const gen_trezor_base &other);
virtual ~gen_trezor_base() {};
- void setup_args(const std::string & trezor_path, bool heavy_tests=false);
+ virtual void setup_args(const std::string & trezor_path, bool heavy_tests=false);
virtual bool generate(std::vector<test_event_entry>& events);
virtual void load(std::vector<test_event_entry>& events); // load events, init test obj
- void fix_hf(std::vector<test_event_entry>& events);
- void update_trackers(std::vector<test_event_entry>& events);
+ virtual void fix_hf(std::vector<test_event_entry>& events);
+ virtual void update_trackers(std::vector<test_event_entry>& events);
- void fork(gen_trezor_base & other); // fork generated chain to another test
- void clear(); // clears m_events, bt, generator, hforks
- void add_shared_events(std::vector<test_event_entry>& events); // m_events -> events
- void test_setup(std::vector<test_event_entry>& events); // init setup env, wallets
+ virtual void fork(gen_trezor_base & other); // fork generated chain to another test
+ virtual void clear(); // clears m_events, bt, generator, hforks
+ virtual void add_shared_events(std::vector<test_event_entry>& events); // m_events -> events
+ virtual void test_setup(std::vector<test_event_entry>& events); // init setup env, wallets
- void test_trezor_tx(std::vector<test_event_entry>& events,
+ virtual void add_transactions_to_events(
+ std::vector<test_event_entry>& events,
+ test_generator &generator,
+ const std::vector<cryptonote::transaction> &txs);
+
+ virtual void test_trezor_tx(
+ std::vector<test_event_entry>& events,
std::vector<tools::wallet2::pending_tx>& ptxs,
std::vector<cryptonote::address_parse_info>& dsts_info,
test_generator &generator,
std::vector<tools::wallet2*> wallets,
bool is_sweep=false);
- crypto::hash head_hash() { return get_block_hash(m_head); }
- cryptonote::block head_block() { return m_head; }
- bool heavy_tests() { return m_heavy_tests; }
+ virtual void test_get_tx(
+ std::vector<test_event_entry>& events,
+ std::vector<tools::wallet2*> wallets,
+ const std::vector<tools::wallet2::pending_tx> &ptxs,
+ const std::vector<std::string> &aux_tx_info);
+
+ virtual void mine_and_test(std::vector<test_event_entry>& events);
+
+ virtual void set_hard_fork(uint8_t hf);
+
+ crypto::hash head_hash() const { return get_block_hash(m_head); }
+ cryptonote::block head_block() const { return m_head; }
+ bool heavy_tests() const { return m_heavy_tests; }
void rct_config(rct::RCTConfig rct_config) { m_rct_config = rct_config; }
- uint8_t cur_hf(){ return m_hard_forks.size() > 0 ? m_hard_forks.back().first : 0; }
+ uint8_t cur_hf() const { return m_hard_forks.size() > 0 ? m_hard_forks.back().first : 0; }
+ cryptonote::network_type nettype() const { return m_network_type; }
+ std::shared_ptr<mock_daemon> daemon() const { return m_daemon; }
+ void daemon(std::shared_ptr<mock_daemon> daemon){ m_daemon = std::move(daemon); }
// Static configuration
static const uint64_t m_ts_start;
@@ -84,19 +105,26 @@ public:
static const std::string m_alice_view_private;
protected:
- void setup_trezor();
- void init_fields();
+ virtual void setup_trezor();
+ virtual void init_fields();
+ virtual void update_client_settings();
+ virtual bool verify_tx_key(const ::crypto::secret_key & tx_priv, const ::crypto::public_key & tx_pub, const subaddresses_t & subs);
test_generator m_generator;
block_tracker m_bt;
+ cryptonote::network_type m_network_type;
+ std::shared_ptr<mock_daemon> m_daemon;
+ uint8_t m_top_hard_fork;
v_hardforks_t m_hard_forks;
cryptonote::block m_head;
std::vector<test_event_entry> m_events;
std::string m_trezor_path;
bool m_heavy_tests;
+ bool m_test_get_tx_key;
rct::RCTConfig m_rct_config;
+ bool m_live_refresh_enabled;
cryptonote::account_base m_miner_account;
cryptonote::account_base m_bob_account;
@@ -113,6 +141,7 @@ protected:
void serialize(Archive & ar, const unsigned int /*version*/)
{
ar & m_generator;
+ ar & m_network_type;
}
};
@@ -169,12 +198,52 @@ protected:
rct::RCTConfig m_rct_config;
};
+// Trezor device ship to track actual method calls.
+class device_trezor_test : public hw::trezor::device_trezor {
+public:
+ size_t m_tx_sign_ctr;
+ size_t m_compute_key_image_ctr;
+
+ device_trezor_test();
+
+ void clear_test_counters();
+ void setup_for_tests(const std::string & trezor_path, const std::string & seed, cryptonote::network_type network_type);
+
+ bool compute_key_image(const ::cryptonote::account_keys &ack, const ::crypto::public_key &out_key,
+ const ::crypto::key_derivation &recv_derivation, size_t real_output_index,
+ const ::cryptonote::subaddress_index &received_index, ::cryptonote::keypair &in_ephemeral,
+ ::crypto::key_image &ki) override;
+
+protected:
+ void tx_sign(hw::wallet_shim *wallet, const ::tools::wallet2::unsigned_tx_set &unsigned_tx, size_t idx,
+ hw::tx_aux_data &aux_data, std::shared_ptr<hw::trezor::protocol::tx::Signer> &signer) override;
+};
+
+// Tests
class gen_trezor_ki_sync : public gen_trezor_base
{
public:
bool generate(std::vector<test_event_entry>& events) override;
};
+class gen_trezor_ki_sync_with_refresh : public gen_trezor_ki_sync
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_ki_sync_without_refresh : public gen_trezor_ki_sync
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_live_refresh : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
class gen_trezor_1utxo : public gen_trezor_base
{
public:
@@ -246,3 +315,15 @@ class gen_trezor_many_utxo : public gen_trezor_base
public:
bool generate(std::vector<test_event_entry>& events) override;
};
+
+// Wallet::API tests
+class wallet_api_tests : public gen_trezor_base
+{
+public:
+ virtual ~wallet_api_tests();
+ void init();
+ bool generate(std::vector<test_event_entry>& events) override;
+
+protected:
+ boost::filesystem::path m_wallet_dir;
+}; \ No newline at end of file
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index aea82ede2..56a1f8c4d 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -43,6 +43,7 @@ set(unit_tests_sources
crypto.cpp
decompose_amount_into_digits.cpp
device.cpp
+ difficulty.cpp
dns_resolver.cpp
epee_boosted_tcp_server.cpp
epee_levin_protocol_handler_async.cpp
@@ -52,10 +53,12 @@ set(unit_tests_sources
json_serialization.cpp
get_xtype_from_string.cpp
hashchain.cpp
+ hmac_keccak.cpp
http.cpp
keccak.cpp
logging.cpp
long_term_block_weight.cpp
+ lmdb.cpp
main.cpp
memwipe.cpp
mlocker.cpp
@@ -101,6 +104,7 @@ target_link_libraries(unit_tests
cryptonote_protocol
cryptonote_core
blockchain_db
+ lmdb_lib
rpc
net
serialization
diff --git a/tests/unit_tests/account.cpp b/tests/unit_tests/account.cpp
index 113622b5e..7073ab3e8 100644
--- a/tests/unit_tests/account.cpp
+++ b/tests/unit_tests/account.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/address_from_url.cpp b/tests/unit_tests/address_from_url.cpp
index f6c0ad105..4b06c6487 100644
--- a/tests/unit_tests/address_from_url.cpp
+++ b/tests/unit_tests/address_from_url.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/apply_permutation.cpp b/tests/unit_tests/apply_permutation.cpp
index e2420eb45..76d10c8ff 100644
--- a/tests/unit_tests/apply_permutation.cpp
+++ b/tests/unit_tests/apply_permutation.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp
index ccfcfc15a..eb1ee8932 100644
--- a/tests/unit_tests/ban.cpp
+++ b/tests/unit_tests/ban.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/base58.cpp b/tests/unit_tests/base58.cpp
index 7edb28e62..1996afd04 100644
--- a/tests/unit_tests/base58.cpp
+++ b/tests/unit_tests/base58.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/block_queue.cpp b/tests/unit_tests/block_queue.cpp
index f7b7c63fd..0cba7c443 100644
--- a/tests/unit_tests/block_queue.cpp
+++ b/tests/unit_tests/block_queue.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/block_reward.cpp b/tests/unit_tests/block_reward.cpp
index a897e4140..1dd9072b9 100644
--- a/tests/unit_tests/block_reward.cpp
+++ b/tests/unit_tests/block_reward.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/blockchain_db.cpp b/tests/unit_tests/blockchain_db.cpp
index f9a6adf03..4fbc21ddc 100644
--- a/tests/unit_tests/blockchain_db.cpp
+++ b/tests/unit_tests/blockchain_db.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/bulletproofs.cpp b/tests/unit_tests/bulletproofs.cpp
index 4f07415b0..9ac0df45b 100644
--- a/tests/unit_tests/bulletproofs.cpp
+++ b/tests/unit_tests/bulletproofs.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/canonical_amounts.cpp b/tests/unit_tests/canonical_amounts.cpp
index 227a64a7f..74fcc9548 100644
--- a/tests/unit_tests/canonical_amounts.cpp
+++ b/tests/unit_tests/canonical_amounts.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/chacha.cpp b/tests/unit_tests/chacha.cpp
index 699890522..e06081f8f 100644
--- a/tests/unit_tests/chacha.cpp
+++ b/tests/unit_tests/chacha.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/checkpoints.cpp b/tests/unit_tests/checkpoints.cpp
index ec09c596b..90229a0b8 100644
--- a/tests/unit_tests/checkpoints.cpp
+++ b/tests/unit_tests/checkpoints.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/command_line.cpp b/tests/unit_tests/command_line.cpp
index 327fceefe..6d5afb708 100644
--- a/tests/unit_tests/command_line.cpp
+++ b/tests/unit_tests/command_line.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/crypto.cpp b/tests/unit_tests/crypto.cpp
index e09ec7f7a..7100c8013 100644
--- a/tests/unit_tests/crypto.cpp
+++ b/tests/unit_tests/crypto.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/decompose_amount_into_digits.cpp b/tests/unit_tests/decompose_amount_into_digits.cpp
index 11c6189e5..5049dd83d 100644
--- a/tests/unit_tests/decompose_amount_into_digits.cpp
+++ b/tests/unit_tests/decompose_amount_into_digits.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/difficulty.cpp b/tests/unit_tests/difficulty.cpp
new file mode 100644
index 000000000..090fecc84
--- /dev/null
+++ b/tests/unit_tests/difficulty.cpp
@@ -0,0 +1,68 @@
+// Copyright (c) 2019, 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 "cryptonote_basic/difficulty.h"
+
+static cryptonote::difficulty_type MKDIFF(uint64_t high, uint64_t low)
+{
+ cryptonote::difficulty_type d = high;
+ d = (d << 64) | low;
+ return d;
+}
+
+static crypto::hash MKHASH(uint64_t high, uint64_t low)
+{
+ cryptonote::difficulty_type hash_target = high;
+ hash_target = (hash_target << 64) | low;
+ boost::multiprecision::uint256_t hash_value = std::numeric_limits<boost::multiprecision::uint256_t>::max() / hash_target;
+ crypto::hash h;
+ ((uint64_t*)&h)[0] = hash_value.convert_to<uint64_t>();
+ hash_value >>= 64;
+ ((uint64_t*)&h)[1] = hash_value.convert_to<uint64_t>();
+ hash_value >>= 64;
+ ((uint64_t*)&h)[2] = hash_value.convert_to<uint64_t>();
+ hash_value >>= 64;
+ ((uint64_t*)&h)[3] = hash_value.convert_to<uint64_t>();
+ return h;
+}
+
+TEST(difficulty, check_hash)
+{
+ ASSERT_TRUE(cryptonote::check_hash(MKHASH(0, 1), MKDIFF(0, 1)));
+ ASSERT_FALSE(cryptonote::check_hash(MKHASH(0, 1), MKDIFF(0, 2)));
+
+ ASSERT_TRUE(cryptonote::check_hash(MKHASH(0, 0xffffffffffffffff), MKDIFF(0, 0xffffffffffffffff)));
+ ASSERT_FALSE(cryptonote::check_hash(MKHASH(0, 0xffffffffffffffff), MKDIFF(1, 0)));
+
+ ASSERT_TRUE(cryptonote::check_hash(MKHASH(1, 1), MKDIFF(1, 1)));
+ ASSERT_FALSE(cryptonote::check_hash(MKHASH(1, 1), MKDIFF(1, 2)));
+
+ ASSERT_TRUE(cryptonote::check_hash(MKHASH(0xffffffffffffffff, 1), MKDIFF(0xffffffffffffffff, 1)));
+ ASSERT_FALSE(cryptonote::check_hash(MKHASH(0xffffffffffffffff, 1), MKDIFF(0xffffffffffffffff, 2)));
+}
diff --git a/tests/unit_tests/dns_resolver.cpp b/tests/unit_tests/dns_resolver.cpp
index 2b3627f02..6bffc01d8 100644
--- a/tests/unit_tests/dns_resolver.cpp
+++ b/tests/unit_tests/dns_resolver.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/epee_boosted_tcp_server.cpp b/tests/unit_tests/epee_boosted_tcp_server.cpp
index 41554f948..32989f545 100644
--- a/tests/unit_tests/epee_boosted_tcp_server.cpp
+++ b/tests/unit_tests/epee_boosted_tcp_server.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
index 9ea71875b..697845f60 100644
--- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp
+++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index 9a32d149a..946731826 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/fee.cpp b/tests/unit_tests/fee.cpp
index 8ccb38fc9..3b0bc1f09 100644
--- a/tests/unit_tests/fee.cpp
+++ b/tests/unit_tests/fee.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/get_xtype_from_string.cpp b/tests/unit_tests/get_xtype_from_string.cpp
index 54ba473a6..75452894a 100644
--- a/tests/unit_tests/get_xtype_from_string.cpp
+++ b/tests/unit_tests/get_xtype_from_string.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index 12dfde1bc..bb26b5533 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/hashchain.cpp b/tests/unit_tests/hashchain.cpp
index df87f5df2..d07dfdb7a 100644
--- a/tests/unit_tests/hashchain.cpp
+++ b/tests/unit_tests/hashchain.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/hmac_keccak.cpp b/tests/unit_tests/hmac_keccak.cpp
new file mode 100644
index 000000000..cb35d272a
--- /dev/null
+++ b/tests/unit_tests/hmac_keccak.cpp
@@ -0,0 +1,152 @@
+// Copyright (c) 2018, 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 "../io.h"
+
+extern "C" {
+#include "crypto/hmac-keccak.h"
+}
+
+#define KECCAK_BLOCKLEN 136
+
+static const struct {
+ const char *key;
+ const char *inp;
+ const char *res;
+} keccak_hmac_vectors[] = {
+ {"",
+ "",
+ "042186ec4e98680a0866091d6fb89b60871134b44327f8f467c14e9841d3e97b",
+ },
+ {"00",
+ "",
+ "042186ec4e98680a0866091d6fb89b60871134b44327f8f467c14e9841d3e97b",
+ },
+ {"00000000000000000000000000000000",
+ "",
+ "042186ec4e98680a0866091d6fb89b60871134b44327f8f467c14e9841d3e97b",
+ },
+ {"",
+ "00",
+ "402541d5d678ad30217023a12efbd2f367388dc0253ccddb8f915d187e03d414",
+ },
+ {"0000000000000000000000000000000000000000000000000000000000000000",
+ "0000000000000000000000000000000000000000000000000000000000000000",
+ "d164c38ca454176281b3c09dc83cf70bd00290835ff5490356993d368cde0577",
+ },
+ {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+ "0000000000000000000000000000000000000000000000000000000000000000",
+ "d52c9100301a9546d8c97d7f32e8178fd5f4b0a7646ab761db9e0f503f8b0542",
+ },
+ {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+ "d52c9100301a9546d8c97d7f32e8178fd5f4b0a7646ab761db9e0f503f8b0542",
+ "5b9d98c5d3249176230d70fdb215ee2f93e4783064c9564384ddc396e63c18cb",
+ },
+ {"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
+ "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
+ "98d033ba0c95bb3aaf5709733443cbedba20f6451b710ccba4118fc5523013c8",
+ },
+ {"65768798a9bacbdcedfe0f2031425364758697a8b9cadbecfd0e1f30415263748596a7b8c9daebfc0d1e2f405162738495a6b7c8d9eafb0c1d2e3f5061728394a5b6c7d8e9fa0b1c2d3e4f60718293a4b5c6d7e8f90a1b2c3d4e5f708192a3b4c5d6e7f8091a2b3c4d5e6f8091a2b3c4d5e6f708192a3b4c5d6e7f90a1b2c3d4e5f60718293a4b5c6d7e8fa0b1c2d3e4f5061728394a5b6c7d8e9fb0c1d2e3f405162738495a6b7c8d9eafc0d1e2f30415263748596a7b8c9daebfd0e1f2031425364758697a8b9cadbecfe0f102132435465768798a9bacbdcedff00112233445566778899aabbccddeef00112233445566778899aabbccddeeff102132435465768798a9bacbdcedfe0f2031425364758697a8b9cadbecfd0e1f30415263748596a7b8c9daebfc0d1e2f405162738495a6b7c8d9eafb0c1d2e3f5061728394",
+ "7b8895a2afbcc9d6e3f0fd0a1724313e4b5865727f8c99a6b3c0cddae7f4010e1b2835424f5c697683909daab7c4d1deebf805121f2c394653606d7a8794a1aebbc8d5e2effc091623303d4a5764717e8b98a5b2bfccd9e6f3000d1a2734414e5b6875828f9ca9b6c3d0ddeaf704111e2b3845525f6c798693a0adbac7d4e1eefb0815222f3c495663707d8a97a4b1becbd8e5f2ff0c192633404d5a6774818e9ba8b5c2cfdce9f603101d2a3744515e6b7885929facb9c6d3e0edfa0714212e3b4855626f7c8996a3b0bdcad7e4f1fe0b1825323f4c596673808d9aa7b4c1cedbe8f5020f1c293643505d6a7784919eabb8c5d2dfecf90613202d3a4754616e7b8895a2afbcc9d6e3f0fd0a1724313e4b5865727f8c99a6b3c0cddae7f4010e1b2835424f5c697683909daab7c4d1deebf805121f2c394653606d7a8794a1ae",
+ "117b60a7f474fd2245adff82a69429367de8f5263fa96c411986009a743b0e70",
+ },
+ {"00112233445566778899aabbccddeeff102132435465768798a9bacbdcedfe0f",
+ "000d1a2734414e5b6875828f9ca9b6c3d0ddeaf704111e2b3845525f6c798693a0adbac7d4e1eefb0815222f3c495663707d8a97a4b1becbd8e5f2ff0c192633404d5a6774818e9ba8b5c2cfdce9f603101d2a3744515e6b7885929facb9c6d3e0edfa0714212e3b4855626f7c8996a3b0bdcad7e4f1fe0b1825323f4c596673808d9aa7b4c1cedbe8f5020f1c293643505d6a7784919eabb8c5d2dfecf90613202d3a4754616e7b8895a2afbcc9d6e3f0fd0a1724313e4b5865727f8c99a6b3c0cddae7f4010e1b",
+ "cbe3ca627c6432c9a66f07c6411fccca894c9b083b55d0773152460142a676ed",
+ },
+};
+
+static void test_keccak_hmac(const size_t * chunks)
+{
+ uint8_t inp_buff[1024];
+ uint8_t key_buff[1024];
+ uint8_t res_exp[32];
+ uint8_t res_comp[32];
+ const size_t len_chunks = chunks ? sizeof(chunks) / sizeof(*chunks) : 0;
+
+ for (size_t i = 0; i < (sizeof(keccak_hmac_vectors) / sizeof(*keccak_hmac_vectors)); i++)
+ {
+ const size_t inp_len = strlen(keccak_hmac_vectors[i].inp)/2;
+ const size_t key_len = strlen(keccak_hmac_vectors[i].key)/2;
+ ASSERT_TRUE(hexdecode(keccak_hmac_vectors[i].inp, inp_len, inp_buff));
+ ASSERT_TRUE(hexdecode(keccak_hmac_vectors[i].key, key_len, key_buff));
+ ASSERT_TRUE(hexdecode(keccak_hmac_vectors[i].res, 32, res_exp));
+ if (len_chunks == 0)
+ {
+ hmac_keccak_hash(res_comp, key_buff, key_len, inp_buff, inp_len);
+ }
+ else
+ {
+ hmac_keccak_state S;
+ hmac_keccak_init(&S, key_buff, key_len);
+ size_t inp_passed = 0;
+ size_t chunk_size = 0;
+ while(inp_passed < inp_len){
+ const size_t to_pass = std::min(inp_len - inp_passed, chunks[chunk_size]);
+ hmac_keccak_update(&S, inp_buff + inp_passed, to_pass);
+
+ inp_passed += to_pass;
+ chunk_size = (chunk_size + 1) % len_chunks;
+ }
+
+ hmac_keccak_finish(&S, res_comp);
+ }
+ ASSERT_EQ(memcmp(res_exp, res_comp, 32), 0);
+ }
+}
+
+
+TEST(keccak_hmac, )
+{
+ test_keccak_hmac({});
+}
+
+TEST(keccak_hmac, 1)
+{
+ static const size_t chunks[] = {1};
+ test_keccak_hmac(chunks);
+}
+
+TEST(keccak_hmac, 1_20)
+{
+ static const size_t chunks[] = {1, 20};
+ test_keccak_hmac(chunks);
+}
+
+TEST(keccak_hmac, 136_1)
+{
+ static const size_t chunks[] = {136, 1};
+ test_keccak_hmac(chunks);
+}
+
+TEST(keccak_hmac, 137_1)
+{
+ static const size_t chunks[] = {137, 1};
+ test_keccak_hmac(chunks);
+}
diff --git a/tests/unit_tests/http.cpp b/tests/unit_tests/http.cpp
index 372448764..938f444d7 100644
--- a/tests/unit_tests/http.cpp
+++ b/tests/unit_tests/http.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/lmdb.cpp b/tests/unit_tests/lmdb.cpp
new file mode 100644
index 000000000..c37c83a32
--- /dev/null
+++ b/tests/unit_tests/lmdb.cpp
@@ -0,0 +1,404 @@
+// Copyright (c) 2014-2018, 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 <boost/range/algorithm_ext/iota.hpp>
+#include <boost/range/algorithm/equal.hpp>
+#include <gtest/gtest.h>
+
+#include "lmdb/database.h"
+#include "lmdb/table.h"
+#include "lmdb/transaction.h"
+#include "lmdb/util.h"
+
+namespace
+{
+ enum class choice : unsigned {};
+ enum class big_choice : unsigned long {};
+
+ struct bytes {
+ char data[16];
+ };
+
+ MONERO_CURSOR(test_cursor);
+
+ template<typename T>
+ int run_compare(T left, T right, MDB_cmp_func* cmp)
+ {
+ MDB_val left_val = lmdb::to_val(left);
+ MDB_val right_val = lmdb::to_val(right);
+ return (*cmp)(&left_val, &right_val);
+ }
+}
+
+TEST(LMDB, Traits)
+{
+ EXPECT_TRUE((std::is_same<void, lmdb::identity<void>::type>()));
+ EXPECT_TRUE((std::is_same<unsigned, lmdb::identity<unsigned>::type>()));
+
+ EXPECT_TRUE((std::is_same<void, lmdb::native_type<void>>()));
+ EXPECT_TRUE((std::is_same<unsigned, lmdb::native_type<unsigned>>()));
+ EXPECT_TRUE((std::is_same<unsigned, lmdb::native_type<choice>>()));
+ EXPECT_TRUE((std::is_same<unsigned long, lmdb::native_type<big_choice>>()));
+}
+
+TEST(LMDB, ToNative)
+{
+ enum class negative_choice : int {};
+
+ EXPECT_TRUE((std::is_same<unsigned, decltype(lmdb::to_native(choice(0)))>()));
+ EXPECT_TRUE(
+ (std::is_same<unsigned long, decltype(lmdb::to_native(big_choice(0)))>())
+ );
+ EXPECT_TRUE(
+ (std::is_same<int, decltype(lmdb::to_native(negative_choice(0)))>())
+ );
+
+ EXPECT_EQ(unsigned(0), lmdb::to_native(choice(0)));
+ EXPECT_EQ(unsigned(0xffffffff), lmdb::to_native(choice(0xffffffff)));
+ EXPECT_EQ(-1, lmdb::to_native(negative_choice(-1)));
+
+ // test constexpr
+ static_assert(100 == lmdb::to_native(choice(100)), "to_native failed");
+ static_assert(-100 == lmdb::to_native(negative_choice(-100)), "to_native failed");
+}
+
+TEST(LMDB, Conversions)
+{
+ struct one
+ {
+ big_choice i;
+ choice j;
+ };
+
+ const one test{big_choice(100), choice(95)};
+ one test2{big_choice(1000), choice(950)};
+
+ EXPECT_EQ(&test, lmdb::to_val(test).mv_data);
+ EXPECT_NE(&test2, lmdb::to_val(test).mv_data);
+ EXPECT_EQ(
+ &test,
+ static_cast<const void*>(lmdb::to_byte_span(lmdb::to_val(test)).begin())
+ );
+ EXPECT_EQ(sizeof(test), lmdb::to_val(test).mv_size);
+ EXPECT_EQ(sizeof(test), lmdb::to_byte_span(lmdb::to_val(test)).size());
+
+ EXPECT_EQ(&test2, lmdb::to_val(test2).mv_data);
+ EXPECT_NE(&test, lmdb::to_val(test2).mv_data);
+ EXPECT_EQ(
+ &test2,
+ static_cast<const void*>(lmdb::to_byte_span(lmdb::to_val(test2)).begin())
+ );
+ EXPECT_EQ(sizeof(test2), lmdb::to_val(test2).mv_size);
+ EXPECT_EQ(sizeof(test2), lmdb::to_byte_span(lmdb::to_val(test2)).size());
+}
+
+TEST(LMDB, LessSort)
+{
+ struct one
+ {
+ unsigned i;
+ unsigned j;
+ };
+
+ struct two
+ {
+ unsigned i;
+ choice j;
+ };
+
+ EXPECT_EQ(0, run_compare(0u, 0u, &lmdb::less<unsigned>));
+ EXPECT_EQ(-1, run_compare(0u, 1u, &lmdb::less<unsigned>));
+ EXPECT_EQ(1, run_compare(1u, 0u, &lmdb::less<unsigned>));
+
+ EXPECT_EQ(0, run_compare<one>({0, 1}, {0, 1}, &lmdb::less<unsigned, sizeof(unsigned)>));
+ EXPECT_EQ(-1, run_compare<one>({0, 0}, {0, 1}, &lmdb::less<unsigned, sizeof(unsigned)>));
+ EXPECT_EQ(1, run_compare<one>({0, 1}, {0, 0}, &lmdb::less<unsigned, sizeof(unsigned)>));
+
+ EXPECT_EQ(0, run_compare<one>({0, 1}, {0, 1}, MONERO_SORT_BY(one, j)));
+ EXPECT_EQ(-1, run_compare<one>({0, 0}, {0, 1}, MONERO_SORT_BY(one, j)));
+ EXPECT_EQ(1, run_compare<one>({0, 1}, {0, 0}, MONERO_SORT_BY(one, j)));
+
+ EXPECT_EQ(0, run_compare<two>({0, choice(1)}, {0, choice(1)}, MONERO_SORT_BY(two, j)));
+ EXPECT_EQ(-1, run_compare<two>({0, choice(0)}, {0, choice(1)}, MONERO_SORT_BY(two, j)));
+ EXPECT_EQ(1, run_compare<two>({0, choice(1)}, {0, choice(0)}, MONERO_SORT_BY(two, j)));
+
+ // compare function addresses
+ EXPECT_EQ((MONERO_SORT_BY(one, i)), (MONERO_SORT_BY(two, i)));
+ EXPECT_EQ((MONERO_SORT_BY(one, j)), (MONERO_SORT_BY(two, j)));
+ EXPECT_NE((MONERO_SORT_BY(one, i)), (MONERO_SORT_BY(two, j)));
+ EXPECT_NE((MONERO_SORT_BY(one, j)), (MONERO_SORT_BY(two, i)));
+}
+
+TEST(LMDB, SortCompare)
+{
+ struct one
+ {
+ unsigned i;
+ bytes j;
+ };
+
+ one test{55};
+ boost::iota(test.j.data, 10);
+
+ const one test2 = test;
+
+ EXPECT_EQ(0, run_compare(test, test2, MONERO_COMPARE(one, j)));
+
+ test.j.data[15] = 1;
+ EXPECT_GT(0, run_compare(test, test2, MONERO_COMPARE(one, j)));
+
+ test.j.data[15] = 100;
+ EXPECT_LT(0, run_compare(test, test2, MONERO_COMPARE(one, j)));
+}
+
+TEST(LMDB, Table)
+{
+ struct one
+ {
+ bytes i;
+ bytes j;
+ };
+
+ constexpr lmdb::basic_table<choice, bytes> test{"foo"};
+
+ EXPECT_STREQ("foo", test.name);
+ static_assert(test.flags == 0, "bad flags");
+ static_assert(&lmdb::less<unsigned> == test.key_cmp, "bad key_cmp");
+ static_assert(test.value_cmp == nullptr, "bad value_cmp");
+ EXPECT_TRUE(test.get_value<bytes>(MDB_val{}).matches(std::errc::invalid_argument));
+
+ lmdb::basic_table<big_choice, one> test2{
+ "foo2", MDB_DUPSORT, &lmdb::compare<one>
+ };
+
+ EXPECT_STREQ("foo2", test2.name);
+ EXPECT_EQ((MDB_DUPSORT | MDB_DUPFIXED), test2.flags);
+ EXPECT_EQ(&lmdb::less<unsigned long>, test2.key_cmp);
+ EXPECT_EQ(&lmdb::compare<one>, test2.value_cmp);
+ EXPECT_TRUE(test2.get_value<one>(MDB_val{}).matches(std::errc::invalid_argument));
+
+ one record{};
+ boost::iota(record.i.data, 0);
+ boost::iota(record.i.data, 20);
+
+ const one record_copy = MONERO_UNWRAP(test2.get_value<one>(lmdb::to_val(record)));
+ EXPECT_TRUE(boost::equal(record.i.data, record_copy.i.data));
+ EXPECT_TRUE(boost::equal(record.j.data, record_copy.j.data));
+
+ const bytes j_copy = MONERO_UNWRAP(
+ test2.get_value<MONERO_FIELD(one, j)>(lmdb::to_val(record))
+ );
+ EXPECT_TRUE(boost::equal(record.j.data, j_copy.data));
+
+ EXPECT_TRUE(
+ test.get_key_stream(test_cursor{}).matches(std::errc::invalid_argument)
+ );
+ EXPECT_TRUE(
+ test2.get_key_stream(test_cursor{}).matches(std::errc::invalid_argument)
+ );
+
+
+ EXPECT_TRUE(
+ test.get_value_stream(choice(0), test_cursor{}).matches(std::errc::invalid_argument)
+ );
+ EXPECT_TRUE(
+ test2.get_value_stream(big_choice(0), test_cursor{}).matches(std::errc::invalid_argument)
+ );
+}
+
+TEST(LMDB, InvalidDatabase)
+{
+ lmdb::database test{lmdb::environment{}};
+
+ EXPECT_TRUE(test.resize().matches(std::errc::invalid_argument));
+ EXPECT_TRUE(test.create_read_txn().matches(std::errc::invalid_argument));
+ EXPECT_TRUE(test.reset_txn(lmdb::read_txn{}).matches(std::errc::invalid_argument));
+ EXPECT_TRUE(test.create_write_txn().matches(std::errc::invalid_argument));
+ EXPECT_TRUE(test.commit(lmdb::write_txn{}).matches(std::errc::invalid_argument));
+
+ EXPECT_TRUE(
+ test.try_write( [](MDB_txn&) { return success(); } ).matches(std::errc::invalid_argument)
+ );
+}
+
+TEST(LMDB, InvalidValueStream)
+{
+ struct one
+ {
+ choice i;
+ choice j;
+ bytes k;
+ };
+
+ lmdb::value_stream<one, close_test_cursor> test{test_cursor{}};
+
+ EXPECT_TRUE((std::is_same<one, decltype(*(test.make_iterator()))>()));
+ EXPECT_TRUE((std::is_same<one, decltype(*(test.make_range().begin()))>()));
+ EXPECT_TRUE(
+ (std::is_same<bytes, decltype(*(test.make_iterator<MONERO_FIELD(one, k)>()))>())
+ );
+ EXPECT_TRUE(
+ (std::is_same<bytes, decltype(*(test.make_range<MONERO_FIELD(one, k)>().begin()))>())
+ );
+
+ EXPECT_NO_THROW(test.reset());
+ EXPECT_EQ(0u, test.count());
+ EXPECT_TRUE(test.make_iterator().is_end());
+ EXPECT_TRUE(test.make_range().empty());
+ EXPECT_EQ(nullptr, test.give_cursor());
+
+ EXPECT_EQ(0u, test.count());
+ EXPECT_TRUE(test.make_iterator().is_end());
+ EXPECT_TRUE(test.make_range().empty());
+ EXPECT_EQ(nullptr, test.give_cursor());
+}
+
+TEST(LMDB, InvalidValueIterator)
+{
+ struct one
+ {
+ choice i;
+ choice j;
+ bytes k;
+ };
+
+ lmdb::value_iterator<one> test1{};
+
+ EXPECT_TRUE((std::is_same<one, decltype(*test1)>()));
+ EXPECT_TRUE(
+ (std::is_same<bytes, decltype(test1.get_value<MONERO_FIELD(one, k)>())>())
+ );
+
+ EXPECT_TRUE(test1.is_end());
+ EXPECT_NO_THROW(++test1);
+ EXPECT_NO_THROW(test1++);
+ EXPECT_TRUE(test1.is_end());
+
+ lmdb::value_iterator<one> test2{nullptr};
+
+ EXPECT_TRUE(test2.is_end());
+ EXPECT_NO_THROW(++test2);
+ EXPECT_NO_THROW(test2++);
+ EXPECT_TRUE(test2.is_end());
+
+ EXPECT_TRUE(test1.equal(test2));
+ EXPECT_TRUE(test2.equal(test1));
+ EXPECT_TRUE(test1 == test2);
+ EXPECT_TRUE(test2 == test1);
+ EXPECT_FALSE(test1 != test2);
+ EXPECT_FALSE(test2 != test1);
+
+ lmdb::value_iterator<MONERO_FIELD(one, k)> test3{};
+
+ EXPECT_TRUE((std::is_same<bytes, decltype(*test3)>()));
+ EXPECT_TRUE((std::is_same<one, decltype(test3.get_value<one>())>()));
+ EXPECT_TRUE(
+ (std::is_same<choice, decltype(test1.get_value<MONERO_FIELD(one, j)>())>())
+ );
+
+ EXPECT_TRUE(test3.is_end());
+ EXPECT_NO_THROW(++test3);
+ EXPECT_NO_THROW(test3++);
+ EXPECT_TRUE(test3.is_end());
+}
+
+TEST(LMDB, InvalidKeyStream)
+{
+ struct one
+ {
+ choice i;
+ choice j;
+ bytes k;
+ };
+
+ using record = std::pair<choice, boost::iterator_range<lmdb::value_iterator<one>>>;
+
+ lmdb::key_stream<choice, one, close_test_cursor> test{test_cursor{}};
+
+ EXPECT_TRUE((std::is_same<record, decltype(*(test.make_iterator()))>()));
+ EXPECT_TRUE((std::is_same<record, decltype(*(test.make_range().begin()))>()));
+
+ EXPECT_NO_THROW(test.reset());
+ EXPECT_TRUE(test.make_iterator().is_end());
+ EXPECT_TRUE(test.make_range().empty());
+ EXPECT_EQ(nullptr, test.give_cursor());
+
+ EXPECT_TRUE(test.make_iterator().is_end());
+ EXPECT_TRUE(test.make_range().empty());
+ EXPECT_EQ(nullptr, test.give_cursor());
+}
+
+TEST(LMDB, InvalidKeyIterator)
+{
+ struct one
+ {
+ choice i;
+ choice j;
+ bytes k;
+ };
+
+ using record = std::pair<choice, boost::iterator_range<lmdb::value_iterator<one>>>;
+
+ lmdb::key_iterator<choice, one> test1{};
+
+ EXPECT_TRUE((std::is_same<record, decltype(*test1)>()));
+ EXPECT_TRUE((std::is_same<choice, decltype(test1.get_key())>()));
+ EXPECT_TRUE((std::is_same<one, decltype(*(test1.make_value_iterator()))>()));
+ EXPECT_TRUE((std::is_same<one, decltype(*(test1.make_value_range().begin()))>()));
+ EXPECT_TRUE(
+ (std::is_same<bytes, decltype(*(test1.make_value_iterator<MONERO_FIELD(one, k)>()))>())
+ );
+ EXPECT_TRUE(
+ (std::is_same<bytes, decltype(*(test1.make_value_range<MONERO_FIELD(one, k)>().begin()))>())
+ );
+
+ EXPECT_TRUE(test1.is_end());
+ EXPECT_NO_THROW(++test1);
+ EXPECT_NO_THROW(test1++);
+ EXPECT_TRUE(test1.is_end());
+ EXPECT_TRUE(test1.make_value_iterator().is_end());
+ EXPECT_TRUE(test1.make_value_range().empty());
+
+ lmdb::key_iterator<choice, one> test2{nullptr};
+
+ EXPECT_TRUE(test2.is_end());
+ EXPECT_NO_THROW(++test2);
+ EXPECT_NO_THROW(test2++);
+ EXPECT_TRUE(test2.is_end());
+ EXPECT_TRUE(test2.make_value_iterator().is_end());
+ EXPECT_TRUE(test2.make_value_range().empty());
+
+ EXPECT_TRUE(test1.equal(test2));
+ EXPECT_TRUE(test2.equal(test1));
+ EXPECT_TRUE(test1 == test2);
+ EXPECT_TRUE(test2 == test1);
+ EXPECT_FALSE(test1 != test2);
+ EXPECT_FALSE(test2 != test1);
+}
+
+
diff --git a/tests/unit_tests/logging.cpp b/tests/unit_tests/logging.cpp
index 476e92bef..12d49e2fb 100644
--- a/tests/unit_tests/logging.cpp
+++ b/tests/unit_tests/logging.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/long_term_block_weight.cpp b/tests/unit_tests/long_term_block_weight.cpp
index f37b608b6..ce6ff3551 100644
--- a/tests/unit_tests/long_term_block_weight.cpp
+++ b/tests/unit_tests/long_term_block_weight.cpp
@@ -64,6 +64,18 @@ public:
virtual uint64_t height() const override { return blocks.size(); }
virtual size_t get_block_weight(const uint64_t &h) const override { return blocks[h].weight; }
virtual uint64_t get_block_long_term_weight(const uint64_t &h) const override { return blocks[h].long_term_weight; }
+ virtual std::vector<uint64_t> get_block_weights(uint64_t start_height, size_t count) const override {
+ std::vector<uint64_t> ret;
+ ret.reserve(count);
+ while (count-- && start_height < blocks.size()) ret.push_back(blocks[start_height++].weight);
+ return ret;
+ }
+ virtual std::vector<uint64_t> get_long_term_block_weights(uint64_t start_height, size_t count) const override {
+ std::vector<uint64_t> ret;
+ ret.reserve(count);
+ while (count-- && start_height < blocks.size()) ret.push_back(blocks[start_height++].long_term_weight);
+ return ret;
+ }
virtual crypto::hash top_block_hash(uint64_t *block_height = NULL) const override {
uint64_t h = height();
crypto::hash top = crypto::null_hash;
diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp
index f7251a09e..76d17f2ad 100644
--- a/tests/unit_tests/main.cpp
+++ b/tests/unit_tests/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/memwipe.cpp b/tests/unit_tests/memwipe.cpp
index dd98b8142..e0f5ada20 100644
--- a/tests/unit_tests/memwipe.cpp
+++ b/tests/unit_tests/memwipe.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/mnemonics.cpp b/tests/unit_tests/mnemonics.cpp
index 59642828d..16634e7a1 100644
--- a/tests/unit_tests/mnemonics.cpp
+++ b/tests/unit_tests/mnemonics.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/mul_div.cpp b/tests/unit_tests/mul_div.cpp
index 768b95d4b..b11f715cd 100644
--- a/tests/unit_tests/mul_div.cpp
+++ b/tests/unit_tests/mul_div.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/multisig.cpp b/tests/unit_tests/multisig.cpp
index eb3196863..c5917200e 100644
--- a/tests/unit_tests/multisig.cpp
+++ b/tests/unit_tests/multisig.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -71,7 +71,7 @@ static void make_wallet(unsigned int idx, tools::wallet2 &wallet)
try
{
- wallet.init("");
+ wallet.init("", boost::none, boost::asio::ip::tcp::endpoint{}, 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
wallet.set_subaddress_lookahead(1, 1);
wallet.generate("", "", spendkey, true, false);
ASSERT_TRUE(test_addresses[idx].address == wallet.get_account().get_public_address_str(cryptonote::TESTNET));
diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp
index a38ecfe81..77fb71d96 100644
--- a/tests/unit_tests/net.cpp
+++ b/tests/unit_tests/net.cpp
@@ -33,6 +33,7 @@
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/read.hpp>
+#include <boost/asio/steady_timer.hpp>
#include <boost/asio/write.hpp>
#include <boost/endian/conversion.hpp>
#include <boost/system/error_code.hpp>
@@ -45,6 +46,7 @@
#include "net/error.h"
#include "net/net_utils_base.h"
#include "net/socks.h"
+#include "net/socks_connect.h"
#include "net/parse.h"
#include "net/tor_address.h"
#include "p2p/net_peerlist_boost_serialization.h"
@@ -742,4 +744,92 @@ TEST(socks_client, resolve_command)
while (test_client->called_ == 1);
}
+TEST(socks_connector, host)
+{
+ io_thread io{};
+ boost::asio::steady_timer timeout{io.io_service};
+ timeout.expires_from_now(std::chrono::seconds{5});
+
+ boost::unique_future<boost::asio::ip::tcp::socket> sock =
+ net::socks::connector{io.acceptor.local_endpoint()}("example.com", "8080", timeout);
+
+ while (!io.connected);
+ const std::uint8_t expected_bytes[] = {
+ 4, 1, 0x1f, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00,
+ 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', 0x00
+ };
+
+ std::uint8_t actual_bytes[sizeof(expected_bytes)];
+ boost::asio::read(io.server, boost::asio::buffer(actual_bytes));
+ EXPECT_TRUE(std::memcmp(expected_bytes, actual_bytes, sizeof(actual_bytes)) == 0);
+
+ const std::uint8_t reply_bytes[] = {0, 90, 0, 0, 0, 0, 0, 0};
+ boost::asio::write(io.server, boost::asio::buffer(reply_bytes));
+
+ ASSERT_EQ(boost::future_status::ready, sock.wait_for(boost::chrono::seconds{3}));
+ EXPECT_TRUE(sock.get().is_open());
+}
+
+TEST(socks_connector, ipv4)
+{
+ io_thread io{};
+ boost::asio::steady_timer timeout{io.io_service};
+ timeout.expires_from_now(std::chrono::seconds{5});
+
+ boost::unique_future<boost::asio::ip::tcp::socket> sock =
+ net::socks::connector{io.acceptor.local_endpoint()}("250.88.125.99", "8080", timeout);
+
+ while (!io.connected);
+ const std::uint8_t expected_bytes[] = {
+ 4, 1, 0x1f, 0x90, 0xfa, 0x58, 0x7d, 0x63, 0x00
+ };
+
+ std::uint8_t actual_bytes[sizeof(expected_bytes)];
+ boost::asio::read(io.server, boost::asio::buffer(actual_bytes));
+ EXPECT_TRUE(std::memcmp(expected_bytes, actual_bytes, sizeof(actual_bytes)) == 0);
+
+ const std::uint8_t reply_bytes[] = {0, 90, 0, 0, 0, 0, 0, 0};
+ boost::asio::write(io.server, boost::asio::buffer(reply_bytes));
+
+ ASSERT_EQ(boost::future_status::ready, sock.wait_for(boost::chrono::seconds{3}));
+ EXPECT_TRUE(sock.get().is_open());
+}
+
+TEST(socks_connector, error)
+{
+ io_thread io{};
+ boost::asio::steady_timer timeout{io.io_service};
+ timeout.expires_from_now(std::chrono::seconds{5});
+
+ boost::unique_future<boost::asio::ip::tcp::socket> sock =
+ net::socks::connector{io.acceptor.local_endpoint()}("250.88.125.99", "8080", timeout);
+
+ while (!io.connected);
+ const std::uint8_t expected_bytes[] = {
+ 4, 1, 0x1f, 0x90, 0xfa, 0x58, 0x7d, 0x63, 0x00
+ };
+
+ std::uint8_t actual_bytes[sizeof(expected_bytes)];
+ boost::asio::read(io.server, boost::asio::buffer(actual_bytes));
+ EXPECT_TRUE(std::memcmp(expected_bytes, actual_bytes, sizeof(actual_bytes)) == 0);
+
+ const std::uint8_t reply_bytes[] = {0, 91, 0, 0, 0, 0, 0, 0};
+ boost::asio::write(io.server, boost::asio::buffer(reply_bytes));
+
+ ASSERT_EQ(boost::future_status::ready, sock.wait_for(boost::chrono::seconds{3}));
+ EXPECT_THROW(sock.get().is_open(), boost::system::system_error);
+}
+
+TEST(socks_connector, timeout)
+{
+ io_thread io{};
+ boost::asio::steady_timer timeout{io.io_service};
+ timeout.expires_from_now(std::chrono::milliseconds{10});
+
+ boost::unique_future<boost::asio::ip::tcp::socket> sock =
+ net::socks::connector{io.acceptor.local_endpoint()}("250.88.125.99", "8080", timeout);
+
+ ASSERT_EQ(boost::future_status::ready, sock.wait_for(boost::chrono::seconds{3}));
+ EXPECT_THROW(sock.get().is_open(), boost::system::system_error);
+}
diff --git a/tests/unit_tests/output_selection.cpp b/tests/unit_tests/output_selection.cpp
index fecd547f7..a528679e4 100644
--- a/tests/unit_tests/output_selection.cpp
+++ b/tests/unit_tests/output_selection.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/parse_amount.cpp b/tests/unit_tests/parse_amount.cpp
index eb8c925b1..f4f57f90f 100644
--- a/tests/unit_tests/parse_amount.cpp
+++ b/tests/unit_tests/parse_amount.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/ringct.cpp b/tests/unit_tests/ringct.cpp
index 3f302cb83..e239154cf 100644
--- a/tests/unit_tests/ringct.cpp
+++ b/tests/unit_tests/ringct.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp
index 343a11c37..27b14ffff 100644
--- a/tests/unit_tests/serialization.cpp
+++ b/tests/unit_tests/serialization.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -1187,3 +1187,26 @@ TEST(Serialization, portability_signed_tx)
ASSERT_TRUE(epee::string_tools::pod_to_hex(ki1) == "d54cbd435a8d636ad9b01b8d4f3eb13bd0cf1ce98eddf53ab1617f9b763e66c0");
ASSERT_TRUE(epee::string_tools::pod_to_hex(ki2) == "6c3cd6af97c4070a7aef9b1344e7463e29c7cd245076fdb65da447a34da3ca76");
}
+
+TEST(Serialization, difficulty_type)
+{
+ std::vector<cryptonote::difficulty_type> v_original;
+
+ for(int i = 0; i != 100; i++)
+ {
+ v_original.push_back(cryptonote::difficulty_type("117868131154734361989189100"));
+ if(v_original.size() > 1)
+ v_original.back() *= v_original[v_original.size()-2];
+ }
+
+ std::stringstream ss;
+ boost::archive::portable_binary_oarchive a(ss);
+ a << v_original;
+
+ std::vector<cryptonote::difficulty_type> v_unserialized;
+
+ boost::archive::portable_binary_iarchive a2(ss);
+ a2 >> v_unserialized;
+
+ ASSERT_EQ(v_original, v_unserialized);
+}
diff --git a/tests/unit_tests/sha256.cpp b/tests/unit_tests/sha256.cpp
index 0d1788f3e..898c9e4b3 100644
--- a/tests/unit_tests/sha256.cpp
+++ b/tests/unit_tests/sha256.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/slow_memmem.cpp b/tests/unit_tests/slow_memmem.cpp
index 436259bee..4f13e00e6 100644
--- a/tests/unit_tests/slow_memmem.cpp
+++ b/tests/unit_tests/slow_memmem.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/subaddress.cpp b/tests/unit_tests/subaddress.cpp
index 67802d736..385a2a8ab 100644
--- a/tests/unit_tests/subaddress.cpp
+++ b/tests/unit_tests/subaddress.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/test_peerlist.cpp b/tests/unit_tests/test_peerlist.cpp
index 03aa48ea0..dbb3aaf96 100644
--- a/tests/unit_tests/test_peerlist.cpp
+++ b/tests/unit_tests/test_peerlist.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/test_protocol_pack.cpp b/tests/unit_tests/test_protocol_pack.cpp
index d385bbc42..7329c0d23 100644
--- a/tests/unit_tests/test_protocol_pack.cpp
+++ b/tests/unit_tests/test_protocol_pack.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/test_tx_utils.cpp b/tests/unit_tests/test_tx_utils.cpp
index 55c76c3b6..d8d760b07 100644
--- a/tests/unit_tests/test_tx_utils.cpp
+++ b/tests/unit_tests/test_tx_utils.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/unbound.cpp b/tests/unit_tests/unbound.cpp
index 3676e88f0..d122b2ad2 100644
--- a/tests/unit_tests/unbound.cpp
+++ b/tests/unit_tests/unbound.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/unit_tests_utils.h b/tests/unit_tests/unit_tests_utils.h
index ecd97e3d5..5944bd55a 100644
--- a/tests/unit_tests/unit_tests_utils.h
+++ b/tests/unit_tests/unit_tests_utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/uri.cpp b/tests/unit_tests/uri.cpp
index 999c117c2..df1dbc130 100644
--- a/tests/unit_tests/uri.cpp
+++ b/tests/unit_tests/uri.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/varint.cpp b/tests/unit_tests/varint.cpp
index db675c888..ca0900682 100644
--- a/tests/unit_tests/varint.cpp
+++ b/tests/unit_tests/varint.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/vercmp.cpp b/tests/unit_tests/vercmp.cpp
index 43045979e..77399fa89 100644
--- a/tests/unit_tests/vercmp.cpp
+++ b/tests/unit_tests/vercmp.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//