aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_tests')
-rw-r--r--tests/unit_tests/CMakeLists.txt4
-rw-r--r--tests/unit_tests/account.cpp2
-rw-r--r--tests/unit_tests/address_from_url.cpp2
-rw-r--r--tests/unit_tests/aligned.cpp3
-rw-r--r--tests/unit_tests/apply_permutation.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/bootstrap_node_selector.cpp3
-rw-r--r--tests/unit_tests/bulletproofs.cpp4
-rw-r--r--tests/unit_tests/bulletproofs_plus.cpp169
-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/device.cpp3
-rw-r--r--tests/unit_tests/difficulty.cpp2
-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_serialization.cpp3
-rw-r--r--tests/unit_tests/epee_utils.cpp144
-rw-r--r--tests/unit_tests/expect.cpp3
-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.cpp3
-rw-r--r--tests/unit_tests/http.cpp2
-rw-r--r--tests/unit_tests/json_serialization.h3
-rw-r--r--tests/unit_tests/keccak.cpp3
-rw-r--r--tests/unit_tests/levin.cpp2
-rw-r--r--tests/unit_tests/lmdb.cpp2
-rw-r--r--tests/unit_tests/logging.cpp2
-rw-r--r--tests/unit_tests/long_term_block_weight.cpp2
-rw-r--r--tests/unit_tests/main.cpp2
-rw-r--r--tests/unit_tests/memwipe.cpp2
-rw-r--r--tests/unit_tests/mlocker.cpp3
-rw-r--r--tests/unit_tests/mnemonics.cpp2
-rw-r--r--tests/unit_tests/mul_div.cpp2
-rw-r--r--tests/unit_tests/multiexp.cpp3
-rw-r--r--tests/unit_tests/multisig.cpp2
-rw-r--r--tests/unit_tests/net.cpp3
-rw-r--r--tests/unit_tests/node_server.cpp2
-rw-r--r--tests/unit_tests/notify.cpp3
-rw-r--r--tests/unit_tests/output_distribution.cpp3
-rw-r--r--tests/unit_tests/output_selection.cpp2
-rw-r--r--tests/unit_tests/parse_amount.cpp2
-rw-r--r--tests/unit_tests/pruning.cpp3
-rw-r--r--tests/unit_tests/random.cpp3
-rw-r--r--tests/unit_tests/ringct.cpp2
-rw-r--r--tests/unit_tests/ringdb.cpp3
-rw-r--r--tests/unit_tests/rolling_median.cpp20
-rw-r--r--tests/unit_tests/rpc_version_str.cpp2
-rw-r--r--tests/unit_tests/scaling_2021.cpp187
-rw-r--r--tests/unit_tests/serialization.cpp2
-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_notifier.cpp3
-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/threadpool.cpp3
-rw-r--r--tests/unit_tests/tx_proof.cpp3
-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
-rw-r--r--tests/unit_tests/wipeable_string.cpp3
-rw-r--r--tests/unit_tests/zmq_rpc.cpp3
75 files changed, 546 insertions, 141 deletions
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index 556e0ec40..55818dc93 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2020, The Monero Project
+# Copyright (c) 2014-2022, The Monero Project
#
# All rights reserved.
#
@@ -36,6 +36,7 @@ set(unit_tests_sources
block_reward.cpp
bootstrap_node_selector.cpp
bulletproofs.cpp
+ bulletproofs_plus.cpp
canonical_amounts.cpp
chacha.cpp
checkpoints.cpp
@@ -76,6 +77,7 @@ set(unit_tests_sources
pruning.cpp
random.cpp
rolling_median.cpp
+ scaling_2021.cpp
serialization.cpp
sha256.cpp
slow_memmem.cpp
diff --git a/tests/unit_tests/account.cpp b/tests/unit_tests/account.cpp
index 2ab2f893a..0ca16fe24 100644
--- a/tests/unit_tests/account.cpp
+++ b/tests/unit_tests/account.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, 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 b6b205aac..d54ec6be5 100644
--- a/tests/unit_tests/address_from_url.cpp
+++ b/tests/unit_tests/address_from_url.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/aligned.cpp b/tests/unit_tests/aligned.cpp
index 2b733faf2..fadf5cc41 100644
--- a/tests/unit_tests/aligned.cpp
+++ b/tests/unit_tests/aligned.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/apply_permutation.cpp b/tests/unit_tests/apply_permutation.cpp
index 9376dc10a..61e98b892 100644
--- a/tests/unit_tests/apply_permutation.cpp
+++ b/tests/unit_tests/apply_permutation.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2020, The Monero Project
+// Copyright (c) 2017-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/base58.cpp b/tests/unit_tests/base58.cpp
index b7e9dfcf1..165c52a8e 100644
--- a/tests/unit_tests/base58.cpp
+++ b/tests/unit_tests/base58.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/block_queue.cpp b/tests/unit_tests/block_queue.cpp
index 01c742c11..ec191c636 100644
--- a/tests/unit_tests/block_queue.cpp
+++ b/tests/unit_tests/block_queue.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2020, The Monero Project
+// Copyright (c) 2017-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/block_reward.cpp b/tests/unit_tests/block_reward.cpp
index 2f0ea92f3..9d06c8e86 100644
--- a/tests/unit_tests/block_reward.cpp
+++ b/tests/unit_tests/block_reward.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/blockchain_db.cpp b/tests/unit_tests/blockchain_db.cpp
index 29cdd73b9..17828645a 100644
--- a/tests/unit_tests/blockchain_db.cpp
+++ b/tests/unit_tests/blockchain_db.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/bootstrap_node_selector.cpp b/tests/unit_tests/bootstrap_node_selector.cpp
index c609d1223..ec0fc638f 100644
--- a/tests/unit_tests/bootstrap_node_selector.cpp
+++ b/tests/unit_tests/bootstrap_node_selector.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2020, The Monero Project
+// Copyright (c) 2020-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/bulletproofs.cpp b/tests/unit_tests/bulletproofs.cpp
index ee617938c..493eb9426 100644
--- a/tests/unit_tests/bulletproofs.cpp
+++ b/tests/unit_tests/bulletproofs.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2020, The Monero Project
+// Copyright (c) 2017-2022, The Monero Project
//
// All rights reserved.
//
@@ -131,7 +131,7 @@ TEST(bulletproofs, multi_splitting)
}
rct::ctkeyV outSk;
- rct::RCTConfig rct_config { rct::RangeProofPaddedBulletproof, 0 };
+ rct::RCTConfig rct_config { rct::RangeProofPaddedBulletproof, 4 };
rct::rctSig s = rct::genRctSimple(rct::zero(), sc, destinations, inamounts, outamounts, available, mixRing, amount_keys, NULL, NULL, index, outSk, rct_config, hw::get_device("default"));
ASSERT_TRUE(rct::verRctSimple(s));
for (size_t i = 0; i < n_outputs; ++i)
diff --git a/tests/unit_tests/bulletproofs_plus.cpp b/tests/unit_tests/bulletproofs_plus.cpp
new file mode 100644
index 000000000..a64320233
--- /dev/null
+++ b/tests/unit_tests/bulletproofs_plus.cpp
@@ -0,0 +1,169 @@
+// Copyright (c) 2017-2020, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#include "gtest/gtest.h"
+
+#include "string_tools.h"
+#include "ringct/rctOps.h"
+#include "ringct/rctSigs.h"
+#include "ringct/bulletproofs_plus.h"
+#include "cryptonote_basic/blobdatatype.h"
+#include "cryptonote_basic/cryptonote_format_utils.h"
+#include "device/device.hpp"
+#include "misc_log_ex.h"
+
+TEST(bulletproofs_plus, valid_zero)
+{
+ rct::BulletproofPlus proof = bulletproof_plus_PROVE(0, rct::skGen());
+ ASSERT_TRUE(rct::bulletproof_plus_VERIFY(proof));
+}
+
+TEST(bulletproofs_plus, valid_max)
+{
+ rct::BulletproofPlus proof = bulletproof_plus_PROVE(0xffffffffffffffff, rct::skGen());
+ ASSERT_TRUE(rct::bulletproof_plus_VERIFY(proof));
+}
+
+TEST(bulletproofs_plus, valid_random)
+{
+ for (int n = 0; n < 8; ++n)
+ {
+ rct::BulletproofPlus proof = bulletproof_plus_PROVE(crypto::rand<uint64_t>(), rct::skGen());
+ ASSERT_TRUE(rct::bulletproof_plus_VERIFY(proof));
+ }
+}
+
+TEST(bulletproofs_plus, valid_multi_random)
+{
+ for (int n = 0; n < 8; ++n)
+ {
+ size_t outputs = 2 + n;
+ std::vector<uint64_t> amounts;
+ rct::keyV gamma;
+ for (size_t i = 0; i < outputs; ++i)
+ {
+ amounts.push_back(crypto::rand<uint64_t>());
+ gamma.push_back(rct::skGen());
+ }
+ rct::BulletproofPlus proof = bulletproof_plus_PROVE(amounts, gamma);
+ ASSERT_TRUE(rct::bulletproof_plus_VERIFY(proof));
+ }
+}
+
+TEST(bulletproofs_plus, valid_aggregated)
+{
+ static const size_t N_PROOFS = 8;
+ std::vector<rct::BulletproofPlus> proofs(N_PROOFS);
+ for (size_t n = 0; n < N_PROOFS; ++n)
+ {
+ size_t outputs = 2 + n;
+ std::vector<uint64_t> amounts;
+ rct::keyV gamma;
+ for (size_t i = 0; i < outputs; ++i)
+ {
+ amounts.push_back(crypto::rand<uint64_t>());
+ gamma.push_back(rct::skGen());
+ }
+ proofs[n] = bulletproof_plus_PROVE(amounts, gamma);
+ }
+ ASSERT_TRUE(rct::bulletproof_plus_VERIFY(proofs));
+}
+
+TEST(bulletproofs_plus, invalid_8)
+{
+ rct::key invalid_amount = rct::zero();
+ invalid_amount[8] = 1;
+ rct::BulletproofPlus proof = bulletproof_plus_PROVE(invalid_amount, rct::skGen());
+ ASSERT_FALSE(rct::bulletproof_plus_VERIFY(proof));
+}
+
+TEST(bulletproofs_plus, invalid_31)
+{
+ rct::key invalid_amount = rct::zero();
+ invalid_amount[31] = 1;
+ rct::BulletproofPlus proof = bulletproof_plus_PROVE(invalid_amount, rct::skGen());
+ ASSERT_FALSE(rct::bulletproof_plus_VERIFY(proof));
+}
+
+static const char * const torsion_elements[] =
+{
+ "c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa",
+ "0000000000000000000000000000000000000000000000000000000000000000",
+ "26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85",
+ "ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f",
+ "26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05",
+ "0000000000000000000000000000000000000000000000000000000000000080",
+ "c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a",
+};
+
+TEST(bulletproofs_plus, invalid_torsion)
+{
+ rct::BulletproofPlus proof = bulletproof_plus_PROVE(7329838943733, rct::skGen());
+ ASSERT_TRUE(rct::bulletproof_plus_VERIFY(proof));
+ for (const auto &xs: torsion_elements)
+ {
+ rct::key x;
+ ASSERT_TRUE(epee::string_tools::hex_to_pod(xs, x));
+ ASSERT_FALSE(rct::isInMainSubgroup(x));
+ for (auto &k: proof.V)
+ {
+ const rct::key org_k = k;
+ rct::addKeys(k, org_k, x);
+ ASSERT_FALSE(rct::bulletproof_plus_VERIFY(proof));
+ k = org_k;
+ }
+ for (auto &k: proof.L)
+ {
+ const rct::key org_k = k;
+ rct::addKeys(k, org_k, x);
+ ASSERT_FALSE(rct::bulletproof_plus_VERIFY(proof));
+ k = org_k;
+ }
+ for (auto &k: proof.R)
+ {
+ const rct::key org_k = k;
+ rct::addKeys(k, org_k, x);
+ ASSERT_FALSE(rct::bulletproof_plus_VERIFY(proof));
+ k = org_k;
+ }
+ const rct::key org_A = proof.A;
+ rct::addKeys(proof.A, org_A, x);
+ ASSERT_FALSE(rct::bulletproof_plus_VERIFY(proof));
+ proof.A = org_A;
+ const rct::key org_A1 = proof.A1;
+ rct::addKeys(proof.A1, org_A1, x);
+ ASSERT_FALSE(rct::bulletproof_plus_VERIFY(proof));
+ proof.A1 = org_A1;
+ const rct::key org_B = proof.B;
+ rct::addKeys(proof.B, org_B, x);
+ ASSERT_FALSE(rct::bulletproof_plus_VERIFY(proof));
+ proof.B = org_B;
+ }
+}
diff --git a/tests/unit_tests/canonical_amounts.cpp b/tests/unit_tests/canonical_amounts.cpp
index 5c141098b..5c2466b9e 100644
--- a/tests/unit_tests/canonical_amounts.cpp
+++ b/tests/unit_tests/canonical_amounts.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/chacha.cpp b/tests/unit_tests/chacha.cpp
index 4e434de4d..2e37f8030 100644
--- a/tests/unit_tests/chacha.cpp
+++ b/tests/unit_tests/chacha.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/checkpoints.cpp b/tests/unit_tests/checkpoints.cpp
index 26f2b51f7..3b36fa027 100644
--- a/tests/unit_tests/checkpoints.cpp
+++ b/tests/unit_tests/checkpoints.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/command_line.cpp b/tests/unit_tests/command_line.cpp
index 09c41a33c..6b9025c7c 100644
--- a/tests/unit_tests/command_line.cpp
+++ b/tests/unit_tests/command_line.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/crypto.cpp b/tests/unit_tests/crypto.cpp
index b550b35b0..7f926534a 100644
--- a/tests/unit_tests/crypto.cpp
+++ b/tests/unit_tests/crypto.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2020, The Monero Project
+// Copyright (c) 2017-2022, 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 a4c850bbe..bf0e9263f 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-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/device.cpp b/tests/unit_tests/device.cpp
index c0e8fecc1..1f0dfaf78 100644
--- a/tests/unit_tests/device.cpp
+++ b/tests/unit_tests/device.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/difficulty.cpp b/tests/unit_tests/difficulty.cpp
index 008b9a94f..4c6f06b2b 100644
--- a/tests/unit_tests/difficulty.cpp
+++ b/tests/unit_tests/difficulty.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2019-2020, The Monero Project
+// Copyright (c) 2019-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/dns_resolver.cpp b/tests/unit_tests/dns_resolver.cpp
index b0157bb0a..a6b733592 100644
--- a/tests/unit_tests/dns_resolver.cpp
+++ b/tests/unit_tests/dns_resolver.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, 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 992122dd2..54d27be1b 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-2020, The Monero Project
+// Copyright (c) 2014-2022, 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 d9de99b8b..38a18695d 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-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/epee_serialization.cpp b/tests/unit_tests/epee_serialization.cpp
index 95a2b6ecd..f46630615 100644
--- a/tests/unit_tests/epee_serialization.cpp
+++ b/tests/unit_tests/epee_serialization.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2020, The Monero Project
+// Copyright (c) 2020-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index b83a809b7..1c756e77c 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
@@ -31,6 +31,7 @@
#include <boost/endian/conversion.hpp>
#include <boost/range/algorithm/equal.hpp>
#include <boost/range/algorithm_ext/iota.hpp>
+#include <boost/range/iterator_range.hpp>
#include <cstdint>
#include <gtest/gtest.h>
#include <iterator>
@@ -1748,68 +1749,44 @@ TEST(parsing, isdigit)
TEST(parsing, number)
{
- boost::string_ref val;
- std::string s;
- std::string::const_iterator i;
+ struct match_number_test_data {
+ std::string in_str;
+ std::string expect_out_str;
+ bool expect_is_float;
+ bool expect_is_signed;
+ };
+
+ // Add test cases as needed
+ struct match_number_test_data test_data[] = {
+ { "0 ", "0", false, false },
+ { "000 ", "000", false, false },
+ { "10x", "10", false, false },
+ { "10.09/", "10.09", true, false },
+ { "-1.r", "-1.", true, true },
+ { "-49.;", "-49.", true, true },
+ { "0.78/", "0.78", true, false },
+ { "33E9$", "33E9", true, false },
+ { ".34e2=", ".34e2", true, false },
+ { "-9.34e-2=", "-9.34e-2", true, true },
+ { "+9.34e+03=", "+9.34e+03", true, false }
+ };
// the parser expects another character to end the number, and accepts things
// that aren't numbers, as it's meant as a pre-filter for strto* functions,
// so we just check that numbers get accepted, but don't test non numbers
-
- s = "0 ";
- i = s.begin();
- epee::misc_utils::parse::match_number(i, s.end(), val);
- ASSERT_EQ(val, "0");
-
- s = "000 ";
- i = s.begin();
- epee::misc_utils::parse::match_number(i, s.end(), val);
- ASSERT_EQ(val, "000");
-
- s = "10x";
- i = s.begin();
- epee::misc_utils::parse::match_number(i, s.end(), val);
- ASSERT_EQ(val, "10");
-
- s = "10.09/";
- i = s.begin();
- epee::misc_utils::parse::match_number(i, s.end(), val);
- ASSERT_EQ(val, "10.09");
-
- s = "-1.r";
- i = s.begin();
- epee::misc_utils::parse::match_number(i, s.end(), val);
- ASSERT_EQ(val, "-1.");
-
- s = "-49.;";
- i = s.begin();
- epee::misc_utils::parse::match_number(i, s.end(), val);
- ASSERT_EQ(val, "-49.");
-
- s = "0.78/";
- i = s.begin();
- epee::misc_utils::parse::match_number(i, s.end(), val);
- ASSERT_EQ(val, "0.78");
-
- s = "33E9$";
- i = s.begin();
- epee::misc_utils::parse::match_number(i, s.end(), val);
- ASSERT_EQ(val, "33E9");
-
- s = ".34e2=";
- i = s.begin();
- epee::misc_utils::parse::match_number(i, s.end(), val);
- ASSERT_EQ(val, ".34e2");
-
- s = "-9.34e-2=";
- i = s.begin();
- epee::misc_utils::parse::match_number(i, s.end(), val);
- ASSERT_EQ(val, "-9.34e-2");
-
- s = "+9.34e+03=";
- i = s.begin();
- epee::misc_utils::parse::match_number(i, s.end(), val);
- ASSERT_EQ(val, "+9.34e+03");
+ // We set is_float/signed_val to the opposite of what we expect the result to
+ // make sure that match_number2 is changing the bools as expected
+
+ for (const auto& tdata : test_data) {
+ std::string::const_iterator it = tdata.in_str.begin();
+ boost::string_ref out_val = "<unassigned>";
+ bool is_float_val = !tdata.expect_is_float;
+ bool is_signed_val = !tdata.expect_is_signed;
+ epee::misc_utils::parse::match_number2(it, tdata.in_str.end(), out_val, is_float_val, is_signed_val);
+ EXPECT_EQ(out_val, tdata.expect_out_str);
+ EXPECT_EQ(is_float_val, tdata.expect_is_float);
+ EXPECT_EQ(is_signed_val, tdata.expect_is_signed);
+ }
}
TEST(parsing, unicode)
@@ -1818,13 +1795,44 @@ TEST(parsing, unicode)
std::string s;
std::string::const_iterator si;
- s = "\"\""; si = s.begin(); ASSERT_TRUE(epee::misc_utils::parse::match_string(si, s.end(), bs)); ASSERT_EQ(bs, "");
- s = "\"\\u0000\""; si = s.begin(); ASSERT_TRUE(epee::misc_utils::parse::match_string(si, s.end(), bs)); ASSERT_EQ(bs, std::string(1, '\0'));
- s = "\"\\u0020\""; si = s.begin(); ASSERT_TRUE(epee::misc_utils::parse::match_string(si, s.end(), bs)); ASSERT_EQ(bs, " ");
- s = "\"\\u1\""; si = s.begin(); ASSERT_FALSE(epee::misc_utils::parse::match_string(si, s.end(), bs));
- s = "\"\\u12\""; si = s.begin(); ASSERT_FALSE(epee::misc_utils::parse::match_string(si, s.end(), bs));
- s = "\"\\u123\""; si = s.begin(); ASSERT_FALSE(epee::misc_utils::parse::match_string(si, s.end(), bs));
- s = "\"\\u1234\""; si = s.begin(); ASSERT_TRUE(epee::misc_utils::parse::match_string(si, s.end(), bs)); ASSERT_EQ(bs, "ሴ");
- s = "\"foo\\u1234bar\""; si = s.begin(); ASSERT_TRUE(epee::misc_utils::parse::match_string(si, s.end(), bs)); ASSERT_EQ(bs, "fooሴbar");
- s = "\"\\u3042\\u307e\\u3084\\u304b\\u3059\""; si = s.begin(); ASSERT_TRUE(epee::misc_utils::parse::match_string(si, s.end(), bs)); ASSERT_EQ(bs, "あまやかす");
+ s = "\"\"";
+ si = s.begin();
+ epee::misc_utils::parse::match_string2(si, s.end(), bs);
+ EXPECT_EQ(bs, "");
+
+ s = "\"\\u0000\"";
+ si = s.begin();
+ epee::misc_utils::parse::match_string2(si, s.end(), bs);
+ EXPECT_EQ(bs, std::string(1, '\0'));
+
+ s = "\"\\u0020\"";
+ si = s.begin();
+ epee::misc_utils::parse::match_string2(si, s.end(), bs);
+ EXPECT_EQ(bs, " ");
+
+ s = "\"\\u1\"";
+ si = s.begin();
+ EXPECT_THROW(epee::misc_utils::parse::match_string2(si, s.end(), bs), std::runtime_error);
+
+ s = "\"\\u12\"";
+ si = s.begin();
+ EXPECT_THROW(epee::misc_utils::parse::match_string2(si, s.end(), bs), std::runtime_error);
+
+ s = "\"\\u123\"";
+ si = s.begin();
+ EXPECT_THROW(epee::misc_utils::parse::match_string2(si, s.end(), bs), std::runtime_error);
+
+ s = "\"\\u1234\"";
+ si = s.begin();
+ epee::misc_utils::parse::match_string2(si, s.end(), bs);
+ EXPECT_EQ(bs, "ሴ");
+
+ s = "\"foo\\u1234bar\""; si = s.begin();
+ epee::misc_utils::parse::match_string2(si, s.end(), bs);
+ EXPECT_EQ(bs, "fooሴbar");
+
+ s = "\"\\u3042\\u307e\\u3084\\u304b\\u3059\"";
+ si = s.begin();
+ epee::misc_utils::parse::match_string2(si, s.end(), bs);
+ EXPECT_EQ(bs, "あまやかす");
}
diff --git a/tests/unit_tests/expect.cpp b/tests/unit_tests/expect.cpp
index efa843496..6162ed830 100644
--- a/tests/unit_tests/expect.cpp
+++ b/tests/unit_tests/expect.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/fee.cpp b/tests/unit_tests/fee.cpp
index d98b9e974..39f3014a2 100644
--- a/tests/unit_tests/fee.cpp
+++ b/tests/unit_tests/fee.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, 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 17492ed19..2831b65b0 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-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index 912651de4..bb2632d01 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/hashchain.cpp b/tests/unit_tests/hashchain.cpp
index 5d85e960c..1831d0504 100644
--- a/tests/unit_tests/hashchain.cpp
+++ b/tests/unit_tests/hashchain.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/hmac_keccak.cpp b/tests/unit_tests/hmac_keccak.cpp
index ec7c90dbe..e05bcca44 100644
--- a/tests/unit_tests/hmac_keccak.cpp
+++ b/tests/unit_tests/hmac_keccak.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/http.cpp b/tests/unit_tests/http.cpp
index df3088a8b..60afe788e 100644
--- a/tests/unit_tests/http.cpp
+++ b/tests/unit_tests/http.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/json_serialization.h b/tests/unit_tests/json_serialization.h
index 2d8267261..5ae97a3dd 100644
--- a/tests/unit_tests/json_serialization.h
+++ b/tests/unit_tests/json_serialization.h
@@ -1,4 +1,5 @@
-// Copyright (c) 2020, The Monero Project
+// Copyright (c) 2020-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/keccak.cpp b/tests/unit_tests/keccak.cpp
index a869fbaec..1ebe63646 100644
--- a/tests/unit_tests/keccak.cpp
+++ b/tests/unit_tests/keccak.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/levin.cpp b/tests/unit_tests/levin.cpp
index 069bc19b2..60d0079b6 100644
--- a/tests/unit_tests/levin.cpp
+++ b/tests/unit_tests/levin.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2019-2020, The Monero Project
+// Copyright (c) 2019-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/lmdb.cpp b/tests/unit_tests/lmdb.cpp
index c37c83a32..b6a0d000c 100644
--- a/tests/unit_tests/lmdb.cpp
+++ b/tests/unit_tests/lmdb.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/logging.cpp b/tests/unit_tests/logging.cpp
index b3ffb9aa6..2c10f2c0a 100644
--- a/tests/unit_tests/logging.cpp
+++ b/tests/unit_tests/logging.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2020, The Monero Project
+// Copyright (c) 2016-2022, 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 c0b057c9a..973055097 100644
--- a/tests/unit_tests/long_term_block_weight.cpp
+++ b/tests/unit_tests/long_term_block_weight.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2019-2020, The Monero Project
+// Copyright (c) 2019-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp
index ab14fee4e..12792bfe8 100644
--- a/tests/unit_tests/main.cpp
+++ b/tests/unit_tests/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/memwipe.cpp b/tests/unit_tests/memwipe.cpp
index 4f06b401e..97f003471 100644
--- a/tests/unit_tests/memwipe.cpp
+++ b/tests/unit_tests/memwipe.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2020, The Monero Project
+// Copyright (c) 2017-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/mlocker.cpp b/tests/unit_tests/mlocker.cpp
index c97dc2c1d..948909af8 100644
--- a/tests/unit_tests/mlocker.cpp
+++ b/tests/unit_tests/mlocker.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/mnemonics.cpp b/tests/unit_tests/mnemonics.cpp
index 0f9a81b46..7b778d3cf 100644
--- a/tests/unit_tests/mnemonics.cpp
+++ b/tests/unit_tests/mnemonics.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/mul_div.cpp b/tests/unit_tests/mul_div.cpp
index 07f48f088..1733a47f0 100644
--- a/tests/unit_tests/mul_div.cpp
+++ b/tests/unit_tests/mul_div.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/multiexp.cpp b/tests/unit_tests/multiexp.cpp
index 212aa0e40..8f2a3cc27 100644
--- a/tests/unit_tests/multiexp.cpp
+++ b/tests/unit_tests/multiexp.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/multisig.cpp b/tests/unit_tests/multisig.cpp
index 362a658de..deee10aed 100644
--- a/tests/unit_tests/multisig.cpp
+++ b/tests/unit_tests/multisig.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2020, The Monero Project
+// Copyright (c) 2017-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp
index 2836fd948..838f1af37 100644
--- a/tests/unit_tests/net.cpp
+++ b/tests/unit_tests/net.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp
index 7907e9a9a..134fa6ece 100644
--- a/tests/unit_tests/node_server.cpp
+++ b/tests/unit_tests/node_server.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/notify.cpp b/tests/unit_tests/notify.cpp
index 4de4a8d0a..8e76a3d78 100644
--- a/tests/unit_tests/notify.cpp
+++ b/tests/unit_tests/notify.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/output_distribution.cpp b/tests/unit_tests/output_distribution.cpp
index eec694d1e..b70fdedf8 100644
--- a/tests/unit_tests/output_distribution.cpp
+++ b/tests/unit_tests/output_distribution.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/output_selection.cpp b/tests/unit_tests/output_selection.cpp
index 20dc58e03..02619207e 100644
--- a/tests/unit_tests/output_selection.cpp
+++ b/tests/unit_tests/output_selection.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/parse_amount.cpp b/tests/unit_tests/parse_amount.cpp
index b581f8dd2..9a2a21c2b 100644
--- a/tests/unit_tests/parse_amount.cpp
+++ b/tests/unit_tests/parse_amount.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/pruning.cpp b/tests/unit_tests/pruning.cpp
index 83c35df68..3577c6924 100644
--- a/tests/unit_tests/pruning.cpp
+++ b/tests/unit_tests/pruning.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/random.cpp b/tests/unit_tests/random.cpp
index 7653453cd..926cb775a 100644
--- a/tests/unit_tests/random.cpp
+++ b/tests/unit_tests/random.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/ringct.cpp b/tests/unit_tests/ringct.cpp
index 2388d647b..f3ca2b2b4 100644
--- a/tests/unit_tests/ringct.cpp
+++ b/tests/unit_tests/ringct.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/ringdb.cpp b/tests/unit_tests/ringdb.cpp
index 0838d2bd9..b41781f51 100644
--- a/tests/unit_tests/ringdb.cpp
+++ b/tests/unit_tests/ringdb.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/rolling_median.cpp b/tests/unit_tests/rolling_median.cpp
index d415c5b95..07da0f0ef 100644
--- a/tests/unit_tests/rolling_median.cpp
+++ b/tests/unit_tests/rolling_median.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2019-2020, The Monero Project
+// Copyright (c) 2019-2022, The Monero Project
//
// All rights reserved.
//
@@ -211,3 +211,21 @@ TEST(rolling_median, size)
ASSERT_EQ(m.size(), std::min<int>(10, i + 2));
}
}
+
+TEST(rolling_median, copy)
+{
+ epee::misc_utils::rolling_median_t<uint64_t> m(100);
+
+ for (int i = 0; i < 100; ++i)
+ m.insert(rand());
+
+ epee::misc_utils::rolling_median_t<uint64_t> copy(m);
+
+ for (int i = 0; i < 5000; ++i)
+ {
+ uint64_t v = rand();
+ m.insert(v);
+ copy.insert(v);
+ ASSERT_EQ(m.median(), copy.median());
+ }
+}
diff --git a/tests/unit_tests/rpc_version_str.cpp b/tests/unit_tests/rpc_version_str.cpp
index 249d297cf..61b389a80 100644
--- a/tests/unit_tests/rpc_version_str.cpp
+++ b/tests/unit_tests/rpc_version_str.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2019-2020, The Monero Project
+// Copyright (c) 2019-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/scaling_2021.cpp b/tests/unit_tests/scaling_2021.cpp
new file mode 100644
index 000000000..9e8d15544
--- /dev/null
+++ b/tests/unit_tests/scaling_2021.cpp
@@ -0,0 +1,187 @@
+// Copyright (c) 2019-2020, 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.
+
+// References:
+// - https://github.com/ArticMine/Monero-Documents/blob/master/MoneroScaling2021.pdf
+// - https://github.com/monero-project/research-lab/issues/70
+
+#define IN_UNIT_TESTS
+
+#include "gtest/gtest.h"
+#include "cryptonote_core/blockchain.h"
+#include "cryptonote_core/tx_pool.h"
+#include "cryptonote_core/cryptonote_core.h"
+#include "blockchain_db/testdb.h"
+
+namespace
+{
+
+class TestDB: public cryptonote::BaseTestDB
+{
+public:
+ TestDB() { m_open = true; }
+};
+
+}
+
+#define PREFIX_WINDOW(hf_version,window) \
+ std::unique_ptr<cryptonote::Blockchain> bc; \
+ cryptonote::tx_memory_pool txpool(*bc); \
+ bc.reset(new cryptonote::Blockchain(txpool)); \
+ struct get_test_options { \
+ const std::pair<uint8_t, uint64_t> hard_forks[3]; \
+ const cryptonote::test_options test_options = { \
+ hard_forks, \
+ window, \
+ }; \
+ get_test_options(): hard_forks{std::make_pair(1, (uint64_t)0), std::make_pair((uint8_t)hf_version, (uint64_t)1), std::make_pair((uint8_t)0, (uint64_t)0)} {} \
+ } opts; \
+ cryptonote::Blockchain *blockchain = bc.get(); \
+ bool r = blockchain->init(new TestDB(), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL); \
+ ASSERT_TRUE(r)
+
+#define PREFIX(hf_version) PREFIX_WINDOW(hf_version, TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW)
+
+TEST(fee_2021_scaling, relay_fee_cases_from_pdf)
+{
+ PREFIX_WINDOW(HF_VERSION_2021_SCALING, CRYPTONOTE_LONG_TERM_BLOCK_WEIGHT_WINDOW_SIZE);
+
+ ASSERT_EQ(bc->get_dynamic_base_fee(1200000000000, 300000, HF_VERSION_2021_SCALING-1), 8000);
+ ASSERT_EQ(bc->get_dynamic_base_fee(1200000000000, 300000, HF_VERSION_2021_SCALING), 38000);
+ ASSERT_EQ(bc->get_dynamic_base_fee(1200000000000, 1425000, HF_VERSION_2021_SCALING-1), 1684 /*1680*/);
+ ASSERT_EQ(bc->get_dynamic_base_fee(1200000000000, 1425000, HF_VERSION_2021_SCALING), 1684 /*1680*/);
+ ASSERT_EQ(bc->get_dynamic_base_fee(1200000000000, 1500000, HF_VERSION_2021_SCALING-1), 1600);
+ ASSERT_EQ(bc->get_dynamic_base_fee(1200000000000, 1500000, HF_VERSION_2021_SCALING), 1520);
+
+ ASSERT_EQ(bc->get_dynamic_base_fee(600000000000, 300000, HF_VERSION_2021_SCALING-1), 4000);
+ ASSERT_EQ(bc->get_dynamic_base_fee(600000000000, 300000, HF_VERSION_2021_SCALING), 19000);
+ ASSERT_EQ(bc->get_dynamic_base_fee(600000000000, 1425000, HF_VERSION_2021_SCALING-1), 842 /*840*/);
+ ASSERT_EQ(bc->get_dynamic_base_fee(600000000000, 1425000, HF_VERSION_2021_SCALING), 842 /*840*/);
+ ASSERT_EQ(bc->get_dynamic_base_fee(600000000000, 1500000, HF_VERSION_2021_SCALING-1), 800);
+ ASSERT_EQ(bc->get_dynamic_base_fee(600000000000, 1500000, HF_VERSION_2021_SCALING), 760);
+}
+
+TEST(fee_2021_scaling, wallet_fee_cases_from_pdf)
+{
+ PREFIX_WINDOW(HF_VERSION_2021_SCALING, CRYPTONOTE_LONG_TERM_BLOCK_WEIGHT_WINDOW_SIZE);
+ std::vector<uint64_t> fees;
+
+ fees.clear();
+ bc->get_dynamic_base_fee_estimate_2021_scaling(10, 600000000000, 300000, 300000, fees);
+ ASSERT_EQ(fees.size(), 4);
+ ASSERT_EQ(fees[0], 20000);
+ ASSERT_EQ(fees[1], 80000);
+ ASSERT_EQ(fees[2], 320000);
+ ASSERT_EQ(fees[3], 4000000);
+
+ fees.clear();
+ bc->get_dynamic_base_fee_estimate_2021_scaling(10, 600000000000, 15000000, 300000, fees);
+ ASSERT_EQ(fees.size(), 4);
+ ASSERT_EQ(fees[0], 20000);
+ ASSERT_EQ(fees[1], 80000);
+ ASSERT_EQ(fees[2], 320000);
+ ASSERT_EQ(fees[3], 1300000);
+
+ fees.clear();
+ bc->get_dynamic_base_fee_estimate_2021_scaling(10, 600000000000, 1425000, 1425000, fees);
+ ASSERT_EQ(fees.size(), 4);
+ ASSERT_EQ(fees[0], 890);
+ ASSERT_EQ(fees[1], 3600);
+ ASSERT_EQ(fees[2], 68000);
+ ASSERT_EQ(fees[3], 850000 /* 842000 */);
+
+ fees.clear();
+ bc->get_dynamic_base_fee_estimate_2021_scaling(10, 600000000000, 1500000, 1500000, fees);
+ ASSERT_EQ(fees.size(), 4);
+ ASSERT_EQ(fees[0], 800);
+ ASSERT_EQ(fees[1], 3200);
+ ASSERT_EQ(fees[2], 64000);
+ ASSERT_EQ(fees[3], 800000);
+
+ fees.clear();
+ bc->get_dynamic_base_fee_estimate_2021_scaling(10, 600000000000, 75000000, 1500000, fees);
+ ASSERT_EQ(fees.size(), 4);
+ ASSERT_EQ(fees[0], 800);
+ ASSERT_EQ(fees[1], 3200);
+ ASSERT_EQ(fees[2], 64000);
+ ASSERT_EQ(fees[3], 260000);
+}
+
+TEST(fee_2021_scaling, rounding)
+{
+ ASSERT_EQ(cryptonote::round_money_up("27810", 3), "27900.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("37.94", 3), "38.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("0.5555", 3), "0.556000000000");
+ ASSERT_EQ(cryptonote::round_money_up("0.002342", 3), "0.002350000000");
+
+ ASSERT_EQ(cryptonote::round_money_up("27810", 2), "28000.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("37.94", 2), "38.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("0.5555", 2), "0.560000000000");
+ ASSERT_EQ(cryptonote::round_money_up("0.002342", 2), "0.002400000000");
+
+ ASSERT_EQ(cryptonote::round_money_up("0", 8), "0.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("0.0", 8), "0.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("50.0", 8), "50.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("0.002342", 8), "0.002342000000");
+ ASSERT_EQ(cryptonote::round_money_up("0.002342", 1), "0.003000000000");
+ ASSERT_EQ(cryptonote::round_money_up("12345", 8), "12345.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("45678", 1), "50000.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("1.234", 1), "2.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("1.0000001", 4), "1.001000000000");
+ ASSERT_EQ(cryptonote::round_money_up("1.0020001", 4), "1.003000000000");
+
+ ASSERT_EQ(cryptonote::round_money_up("1.999999", 1), "2.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("1.999999", 2), "2.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("1.999999", 3), "2.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("1.999999", 4), "2.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("1.999999", 5), "2.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("1.999999", 6), "2.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("1.999999", 7), "1.999999000000");
+ ASSERT_EQ(cryptonote::round_money_up("1.999999", 8), "1.999999000000");
+ ASSERT_EQ(cryptonote::round_money_up("1.999999", 9), "1.999999000000");
+
+ ASSERT_EQ(cryptonote::round_money_up("2.000001", 1), "3.000000000000");
+ ASSERT_EQ(cryptonote::round_money_up("2.000001", 2), "2.100000000000");
+ ASSERT_EQ(cryptonote::round_money_up("2.000001", 3), "2.010000000000");
+ ASSERT_EQ(cryptonote::round_money_up("2.000001", 4), "2.001000000000");
+ ASSERT_EQ(cryptonote::round_money_up("2.000001", 5), "2.000100000000");
+ ASSERT_EQ(cryptonote::round_money_up("2.000001", 6), "2.000010000000");
+ ASSERT_EQ(cryptonote::round_money_up("2.000001", 7), "2.000001000000");
+ ASSERT_EQ(cryptonote::round_money_up("2.000001", 8), "2.000001000000");
+ ASSERT_EQ(cryptonote::round_money_up("2.000001", 9), "2.000001000000");
+ ASSERT_EQ(cryptonote::round_money_up("2.000001", 4000), "2.000001000000");
+
+ ASSERT_EQ(cryptonote::round_money_up("999", 2), "1000.000000000000");
+
+ ASSERT_THROW(cryptonote::round_money_up("1.23", 0), std::runtime_error);
+ ASSERT_THROW(cryptonote::round_money_up("18446744.073709551615", 1), std::runtime_error);
+ ASSERT_THROW(cryptonote::round_money_up("18446744.073709551615", 2), std::runtime_error);
+ ASSERT_THROW(cryptonote::round_money_up("18446744.073709551615", 12), std::runtime_error);
+ ASSERT_THROW(cryptonote::round_money_up("18446744.073709551615", 19), std::runtime_error);
+ ASSERT_EQ(cryptonote::round_money_up("18446744.073709551615", 20), "18446744.073709551615");
+}
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp
index f4c73d3d5..9e8a28f7c 100644
--- a/tests/unit_tests/serialization.cpp
+++ b/tests/unit_tests/serialization.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/sha256.cpp b/tests/unit_tests/sha256.cpp
index 0232511d4..486f31c5b 100644
--- a/tests/unit_tests/sha256.cpp
+++ b/tests/unit_tests/sha256.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2020, The Monero Project
+// Copyright (c) 2017-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/slow_memmem.cpp b/tests/unit_tests/slow_memmem.cpp
index 602fdae38..aa1bea128 100644
--- a/tests/unit_tests/slow_memmem.cpp
+++ b/tests/unit_tests/slow_memmem.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/subaddress.cpp b/tests/unit_tests/subaddress.cpp
index bf24022e8..17fc0fe78 100644
--- a/tests/unit_tests/subaddress.cpp
+++ b/tests/unit_tests/subaddress.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/test_notifier.cpp b/tests/unit_tests/test_notifier.cpp
index 7fd9809c5..ffa0b3965 100644
--- a/tests/unit_tests/test_notifier.cpp
+++ b/tests/unit_tests/test_notifier.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/test_peerlist.cpp b/tests/unit_tests/test_peerlist.cpp
index 78404f9f9..98caabafd 100644
--- a/tests/unit_tests/test_peerlist.cpp
+++ b/tests/unit_tests/test_peerlist.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, 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 1a4fd30f8..78bf01d4b 100644
--- a/tests/unit_tests/test_protocol_pack.cpp
+++ b/tests/unit_tests/test_protocol_pack.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, 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 0d0dc8819..2991a143e 100644
--- a/tests/unit_tests/test_tx_utils.cpp
+++ b/tests/unit_tests/test_tx_utils.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/threadpool.cpp b/tests/unit_tests/threadpool.cpp
index 1017f04ff..c1ea722c8 100644
--- a/tests/unit_tests/threadpool.cpp
+++ b/tests/unit_tests/threadpool.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/tx_proof.cpp b/tests/unit_tests/tx_proof.cpp
index 0adb8713e..04fe7aaa2 100644
--- a/tests/unit_tests/tx_proof.cpp
+++ b/tests/unit_tests/tx_proof.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/unbound.cpp b/tests/unit_tests/unbound.cpp
index b404ca922..1cac02901 100644
--- a/tests/unit_tests/unbound.cpp
+++ b/tests/unit_tests/unbound.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2020, The Monero Project
+// Copyright (c) 2016-2022, 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 1784ffb21..6b3fe1f44 100644
--- a/tests/unit_tests/unit_tests_utils.h
+++ b/tests/unit_tests/unit_tests_utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/uri.cpp b/tests/unit_tests/uri.cpp
index 83312a3c9..0ece6d4c1 100644
--- a/tests/unit_tests/uri.cpp
+++ b/tests/unit_tests/uri.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2020, The Monero Project
+// Copyright (c) 2016-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/varint.cpp b/tests/unit_tests/varint.cpp
index a8dee677a..9bf30c5ed 100644
--- a/tests/unit_tests/varint.cpp
+++ b/tests/unit_tests/varint.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2020, The Monero Project
+// Copyright (c) 2014-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/vercmp.cpp b/tests/unit_tests/vercmp.cpp
index 90f4fdf79..627a53c3b 100644
--- a/tests/unit_tests/vercmp.cpp
+++ b/tests/unit_tests/vercmp.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2020, The Monero Project
+// Copyright (c) 2017-2022, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/wipeable_string.cpp b/tests/unit_tests/wipeable_string.cpp
index 0e0bf8906..ef6964f9e 100644
--- a/tests/unit_tests/wipeable_string.cpp
+++ b/tests/unit_tests/wipeable_string.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2022, The Monero Project
+
//
// All rights reserved.
//
diff --git a/tests/unit_tests/zmq_rpc.cpp b/tests/unit_tests/zmq_rpc.cpp
index 66a7f3ac1..c98f0011b 100644
--- a/tests/unit_tests/zmq_rpc.cpp
+++ b/tests/unit_tests/zmq_rpc.cpp
@@ -1,4 +1,5 @@
-// Copyright (c) 2020, The Monero Project
+// Copyright (c) 2020-2022, The Monero Project
+
//
// All rights reserved.
//