aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core_tests/chaingen.cpp1
-rw-r--r--tests/core_tests/wallet_tools.cpp1
-rw-r--r--tests/difficulty/CMakeLists.txt2
-rwxr-xr-x[-rw-r--r--]tests/difficulty/gen_wide_data.py0
-rwxr-xr-xtests/functional_tests/blockchain.py20
-rwxr-xr-xtests/functional_tests/functional_tests_rpc.py2
-rwxr-xr-xtests/functional_tests/multisig.py7
-rwxr-xr-xtests/functional_tests/transfer.py4
-rwxr-xr-xtests/functional_tests/validate_address.py111
-rwxr-xr-xtests/functional_tests/wallet_address.py5
-rw-r--r--tests/unit_tests/ban.cpp38
-rw-r--r--tests/unit_tests/epee_utils.cpp17
-rw-r--r--tests/unit_tests/keccak.cpp17
-rw-r--r--tests/unit_tests/mnemonics.cpp4
-rw-r--r--tests/unit_tests/net.cpp18
-rw-r--r--tests/unit_tests/output_selection.cpp8
-rw-r--r--tests/unit_tests/rolling_median.cpp8
-rw-r--r--tests/unit_tests/test_protocol_pack.cpp1
-rw-r--r--tests/unit_tests/varint.cpp1
19 files changed, 243 insertions, 22 deletions
diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp
index 614585349..8dde1f475 100644
--- a/tests/core_tests/chaingen.cpp
+++ b/tests/core_tests/chaingen.cpp
@@ -546,6 +546,7 @@ void block_tracker::global_indices(const cryptonote::transaction *tx, std::vecto
void block_tracker::get_fake_outs(size_t num_outs, uint64_t amount, uint64_t global_index, uint64_t cur_height, std::vector<get_outs_entry> &outs){
auto & vct = m_outs[amount];
const size_t n_outs = vct.size();
+ CHECK_AND_ASSERT_THROW_MES(n_outs > 0, "n_outs is 0");
std::set<size_t> used;
std::vector<size_t> choices;
diff --git a/tests/core_tests/wallet_tools.cpp b/tests/core_tests/wallet_tools.cpp
index d9cee34c1..21a9455c0 100644
--- a/tests/core_tests/wallet_tools.cpp
+++ b/tests/core_tests/wallet_tools.cpp
@@ -163,6 +163,7 @@ bool wallet_tools::fill_tx_sources(tools::wallet2 * wallet, std::vector<cryptono
void wallet_tools::gen_tx_src(size_t mixin, uint64_t cur_height, const tools::wallet2::transfer_details & td, cryptonote::tx_source_entry & src, block_tracker &bt)
{
+ CHECK_AND_ASSERT_THROW_MES(mixin != 0, "mixin is zero");
src.amount = td.amount();
src.rct = td.is_rct();
diff --git a/tests/difficulty/CMakeLists.txt b/tests/difficulty/CMakeLists.txt
index fb0dd6b9e..c4f5a5dc0 100644
--- a/tests/difficulty/CMakeLists.txt
+++ b/tests/difficulty/CMakeLists.txt
@@ -36,7 +36,7 @@ add_executable(difficulty-tests
${difficulty_headers})
target_link_libraries(difficulty-tests
PRIVATE
- cryptonote_core
+ cryptonote_basic
${EXTRA_LIBRARIES})
set_property(TARGET difficulty-tests
PROPERTY
diff --git a/tests/difficulty/gen_wide_data.py b/tests/difficulty/gen_wide_data.py
index 64af4e208..64af4e208 100644..100755
--- a/tests/difficulty/gen_wide_data.py
+++ b/tests/difficulty/gen_wide_data.py
diff --git a/tests/functional_tests/blockchain.py b/tests/functional_tests/blockchain.py
index 644597584..2c3f34c35 100755
--- a/tests/functional_tests/blockchain.py
+++ b/tests/functional_tests/blockchain.py
@@ -74,10 +74,16 @@ class BlockchainTest():
# we should not see a block at height
ok = False
- try: daemon.getblock(height)
+ try: daemon.getblock(height = height)
except: ok = True
assert ok
+ res = daemon.get_fee_estimate()
+ assert res.fee == 234562
+ assert res.quantization_mask == 10000
+ res = daemon.get_fee_estimate(10)
+ assert res.fee <= 234562
+
# generate blocks
res_generateblocks = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', blocks)
@@ -92,7 +98,7 @@ class BlockchainTest():
# get the blocks, check they have the right height
res_getblock = []
for n in range(blocks):
- res_getblock.append(daemon.getblock(height + n))
+ res_getblock.append(daemon.getblock(height = height + n))
block_header = res_getblock[n].block_header
assert abs(block_header.timestamp - time.time()) < 10 # within 10 seconds
assert block_header.height == height + n
@@ -111,7 +117,7 @@ class BlockchainTest():
# we should not see a block after that
ok = False
- try: daemon.getblock(height + blocks)
+ try: daemon.getblock(height = height + blocks)
except: ok = True
assert ok
@@ -157,7 +163,7 @@ class BlockchainTest():
# we should not see the popped block anymore
ok = False
- try: daemon.getblock(height + blocks - 1)
+ try: daemon.getblock(height = height + blocks - 1)
except: ok = True
assert ok
@@ -229,6 +235,12 @@ class BlockchainTest():
assert res.histogram[i].unlocked_instances == 0
assert res.histogram[i].recent_instances == 0
+ res = daemon.get_fee_estimate()
+ assert res.fee == 234560
+ assert res.quantization_mask == 10000
+ res = daemon.get_fee_estimate(10)
+ assert res.fee <= 234560
+
def _test_alt_chains(self):
print('Testing alt chains')
daemon = Daemon()
diff --git a/tests/functional_tests/functional_tests_rpc.py b/tests/functional_tests/functional_tests_rpc.py
index 25ab641ab..77d0e4c4d 100755
--- a/tests/functional_tests/functional_tests_rpc.py
+++ b/tests/functional_tests/functional_tests_rpc.py
@@ -65,7 +65,7 @@ try:
for i in range(len(command_lines)):
#print('Running: ' + str(command_lines[i]))
processes.append(subprocess.Popen(command_lines[i], stdout = outputs[i]))
-except Exception, e:
+except Exception as e:
print('Error: ' + str(e))
sys.exit(1)
diff --git a/tests/functional_tests/multisig.py b/tests/functional_tests/multisig.py
index 3c8cd9c1d..b109acf91 100755
--- a/tests/functional_tests/multisig.py
+++ b/tests/functional_tests/multisig.py
@@ -43,6 +43,7 @@ class MultisigTest():
self.mine('42jSRGmmKN96V2j3B8X2DbiNThBXW1tSi1rW1uwkqbyURenq3eC3yosNm8HEMdHuWwKMFGzMUB3RCTvcTaW9kHpdRPP7p5y', 5)
self.mine('47fF32AdrmXG84FcPY697uZdd42pMMGiH5UpiTRTt3YX2pZC7t7wkzEMStEicxbQGRfrYvAAYxH6Fe8rnD56EaNwUgxRd53', 5)
self.mine('44SKxxLQw929wRF6BA9paQ1EWFshNnKhXM3qz6Mo3JGDE2YG3xyzVutMStEicxbQGRfrYvAAYxH6Fe8rnD56EaNwUiqhcwR', 5)
+ self.mine('4ADHswEU3XBUee8pudBkZQd9beJainqNo1BQKkHJujAEPJyQrLj9U4dNm8HEMdHuWwKMFGzMUB3RCTvcTaW9kHpdRUDxgjW', 5)
self.mine('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 60)
self.create_multisig_wallets(2, 2, '493DsrfJPqiN3Suv9RcRDoZEbQtKZX1sNcGPA3GhkKYEEmivk8kjQrTdRdVc4ZbmzWJuE157z9NNUKmF2VDfdYDR3CziGMk')
@@ -57,6 +58,12 @@ class MultisigTest():
self.import_multisig_info([0, 1, 2], 6)
self.check_transaction(txid)
+ self.create_multisig_wallets(3, 3, '4ADHswEU3XBUee8pudBkZQd9beJainqNo1BQKkHJujAEPJyQrLj9U4dNm8HEMdHuWwKMFGzMUB3RCTvcTaW9kHpdRUDxgjW')
+ self.import_multisig_info([2, 0, 1], 5)
+ txid = self.transfer([2, 1, 0])
+ self.import_multisig_info([0, 2, 1], 6)
+ self.check_transaction(txid)
+
self.create_multisig_wallets(3, 4, '47fF32AdrmXG84FcPY697uZdd42pMMGiH5UpiTRTt3YX2pZC7t7wkzEMStEicxbQGRfrYvAAYxH6Fe8rnD56EaNwUgxRd53')
self.import_multisig_info([0, 2, 3], 5)
txid = self.transfer([0, 2, 3])
diff --git a/tests/functional_tests/transfer.py b/tests/functional_tests/transfer.py
index 7bf0f4957..e3c01c27f 100755
--- a/tests/functional_tests/transfer.py
+++ b/tests/functional_tests/transfer.py
@@ -519,6 +519,9 @@ class TransferTest():
res = self.wallet[2].get_bulk_payments(payment_ids = ['1'*64, '1234500000012345abcde00000abcdeff1234500000012345abcde00000abcde', '2'*64])
assert len(res.payments) >= 1 # one tx was sent
+ res = self.wallet[1].get_bulk_payments(["1111111122222222"])
+ assert len(res.payments) >= 1 # we have one of these
+
def check_double_spend_detection(self):
print('Checking double spend detection')
txes = [[None, None], [None, None]]
@@ -571,6 +574,7 @@ class TransferTest():
assert res.overspend == False
assert res.fee_too_low == False
assert res.not_rct == False
+ assert res.too_few_outputs == False
res = daemon.get_transactions([txes[0][0]])
assert len(res.txs) >= 1
diff --git a/tests/functional_tests/validate_address.py b/tests/functional_tests/validate_address.py
new file mode 100755
index 000000000..58748b0a2
--- /dev/null
+++ b/tests/functional_tests/validate_address.py
@@ -0,0 +1,111 @@
+#!/usr/bin/env python3
+
+# 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.
+
+import time
+
+"""Test address validation RPC calls
+"""
+
+from framework.wallet import Wallet
+
+class AddressValidationTest():
+ def run_test(self):
+ self.create()
+ self.check_bad_addresses()
+ self.check_good_addresses()
+ self.check_openalias_addresses()
+
+ def create(self):
+ print('Creating wallet')
+ seed = 'velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted'
+ address = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
+ self.wallet = Wallet()
+ # close the wallet if any, will throw if none is loaded
+ try: self.wallet.close_wallet()
+ except: pass
+ res = self.wallet.restore_deterministic_wallet(seed = seed)
+ assert res.address == address
+ assert res.seed == seed
+
+ def check_bad_addresses(self):
+ print('Validating bad addresses')
+ bad_addresses = ['', 'a', '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWD9', ' ', '@', '42ey']
+ for address in bad_addresses:
+ res = self.wallet.validate_address(address, any_net_type = False)
+ assert not res.valid
+ res = self.wallet.validate_address(address, any_net_type = True)
+ assert not res.valid
+
+ def check_good_addresses(self):
+ print('Validating good addresses')
+ addresses = [
+ [ 'mainnet', '', '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' ],
+ [ 'mainnet', '', '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW' ],
+ [ 'testnet', '', '9ujeXrjzf7bfeK3KZdCqnYaMwZVFuXemPU8Ubw335rj2FN1CdMiWNyFV3ksEfMFvRp9L9qum5UxkP5rN9aLcPxbH1au4WAB' ],
+ [ 'stagenet', '', '53teqCAESLxeJ1REzGMAat1ZeHvuajvDiXqboEocPaDRRmqWoVPzy46GLo866qRFjbNhfkNckyhST3WEvBviDwpUDd7DSzB' ],
+ [ 'mainnet', 'i', '4BxSHvcgTwu25WooY4BVmgdcKwZu5EksVZSZkDd6ooxSVVqQ4ubxXkhLF6hEqtw96i9cf3cVfLw8UWe95bdDKfRQeYtPwLm1Jiw7AKt2LY' ],
+ [ 'mainnet', 's', '8AsN91rznfkBGTY8psSNkJBg9SZgxxGGRUhGwRptBhgr5XSQ1XzmA9m8QAnoxydecSh5aLJXdrgXwTDMMZ1AuXsN1EX5Mtm' ],
+ [ 'mainnet', 's', '86kKnBKFqzCLxtK1Jmx2BkNBDBSMDEVaRYMMyVbeURYDWs8uNGDZURKCA5yRcyMxHzPcmCf1q2fSdhQVcaKsFrtGRsdGfNk' ],
+ [ 'testnet', 'i', 'AApMA1VuhiCaHzr5X2KXi2Zc9oJ3VaGjkfChxxpRpxkyKf1NetvbRbQTbFMrGkr85DjnEH7JsBaoUFsgKwZnmtnVWnoB8MDotCsLb7eWwz' ],
+ [ 'testnet', 's', 'BdKg9udkvckC5T58a8Nmtb6BNsgRAxs7uA2D49sWNNX5HPW5Us6Wxu8QMXrnSx3xPBQQ2iu9kwEcRGAoiz6EPmcZKbF62GS' ],
+ [ 'testnet', 's', 'BcFvPa3fT4gVt5QyRDe5Vv7VtUFao9ci8NFEy3r254KF7R1N2cNB5FYhGvrHbMStv4D6VDzZ5xtxeKV8vgEPMnDcNFuwZb9' ],
+ [ 'stagenet', 'i', '5K8mwfjumVseCcQEjNbf59Um6R9NfVUNkHTLhhPCmNvgDLVS88YW5tScnm83rw9mfgYtchtDDTW5jEfMhygi27j1QYphX38hg6m4VMtN29' ],
+ [ 'stagenet', 's', '73LhUiix4DVFMcKhsPRG51QmCsv8dYYbL6GcQoLwEEFvPvkVvc7BhebfA4pnEFF9Lq66hwvLqBvpHjTcqvpJMHmmNjPPBqa' ],
+ [ 'stagenet', 's', '7A1Hr63MfgUa8pkWxueD5xBqhQczkusYiCMYMnJGcGmuQxa7aDBxN1G7iCuLCNB3VPeb2TW7U9FdxB27xKkWKfJ8VhUZthF' ],
+ ]
+ for any_net_type in [True, False]:
+ for address in addresses:
+ res = self.wallet.validate_address(address[2], any_net_type = any_net_type)
+ if any_net_type or address[0] == 'mainnet':
+ assert res.valid
+ assert res.integrated == (address[1] == 'i')
+ assert res.subaddress == (address[1] == 's')
+ assert res.nettype == address[0]
+ assert res.openalias_address == ''
+ else:
+ assert not res.valid
+
+ def check_openalias_addresses(self):
+ print('Validating openalias addresses')
+ addresses = [
+ ['donate@getmonero.org', '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A']
+ ]
+ for address in addresses:
+ res = self.wallet.validate_address(address[0])
+ assert not res.valid
+ res = self.wallet.validate_address(address[0], allow_openalias = True)
+ assert res.valid
+ assert not res.integrated
+ assert not res.subaddress
+ assert res.nettype == 'mainnet'
+ assert res.openalias_address == address[1]
+
+if __name__ == '__main__':
+ AddressValidationTest().run_test()
diff --git a/tests/functional_tests/wallet_address.py b/tests/functional_tests/wallet_address.py
index 4ff059a6f..eda52b432 100755
--- a/tests/functional_tests/wallet_address.py
+++ b/tests/functional_tests/wallet_address.py
@@ -198,8 +198,9 @@ class WalletAddressTest():
try: wallet.close_wallet()
except: pass
languages = res.languages
- for language in languages:
- print('Creating ' + str(language) + ' wallet')
+ languages_local = res.languages_local
+ for language in languages + languages_local:
+ print('Creating ' + language.encode('utf8') + ' wallet')
wallet.create_wallet(filename = '', language = language)
res = wallet.query_key('mnemonic')
wallet.close_wallet()
diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp
index 0b267172f..17fba90c6 100644
--- a/tests/unit_tests/ban.cpp
+++ b/tests/unit_tests/ban.cpp
@@ -36,6 +36,7 @@
#include "cryptonote_protocol/cryptonote_protocol_handler.inl"
#define MAKE_IPV4_ADDRESS(a,b,c,d) epee::net_utils::ipv4_network_address{MAKE_IP(a,b,c,d),0}
+#define MAKE_IPV4_SUBNET(a,b,c,d,e) epee::net_utils::ipv4_network_subnet{MAKE_IP(a,b,c,d),e}
namespace cryptonote {
class blockchain_storage;
@@ -93,11 +94,10 @@ typedef nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<test_cor
static bool is_blocked(Server &server, const epee::net_utils::network_address &address, time_t *t = NULL)
{
- const std::string host = address.host_str();
- std::map<std::string, time_t> hosts = server.get_blocked_hosts();
+ std::map<epee::net_utils::network_address, time_t> hosts = server.get_blocked_hosts();
for (auto rec: hosts)
{
- if (rec.first == host)
+ if (rec.first == address)
{
if (t)
*t = rec.second;
@@ -208,5 +208,37 @@ TEST(ban, limit)
ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4)));
}
+TEST(ban, subnet)
+{
+ time_t seconds;
+ test_core pr_core;
+ cryptonote::t_cryptonote_protocol_handler<test_core> cprotocol(pr_core, NULL);
+ Server server(cprotocol);
+ cprotocol.set_p2p_endpoint(&server);
+
+ ASSERT_TRUE(server.block_subnet(MAKE_IPV4_SUBNET(1,2,3,4,24), 10));
+ ASSERT_TRUE(server.get_blocked_subnets().size() == 1);
+ ASSERT_TRUE(server.is_host_blocked(MAKE_IPV4_ADDRESS(1,2,3,4), &seconds));
+ ASSERT_TRUE(seconds >= 9);
+ ASSERT_TRUE(server.is_host_blocked(MAKE_IPV4_ADDRESS(1,2,3,255), &seconds));
+ ASSERT_TRUE(server.is_host_blocked(MAKE_IPV4_ADDRESS(1,2,3,0), &seconds));
+ ASSERT_FALSE(server.is_host_blocked(MAKE_IPV4_ADDRESS(1,2,4,0), &seconds));
+ ASSERT_FALSE(server.is_host_blocked(MAKE_IPV4_ADDRESS(1,2,2,0), &seconds));
+ ASSERT_TRUE(server.unblock_subnet(MAKE_IPV4_SUBNET(1,2,3,8,24)));
+ ASSERT_TRUE(server.get_blocked_subnets().size() == 0);
+ ASSERT_FALSE(server.is_host_blocked(MAKE_IPV4_ADDRESS(1,2,3,255), &seconds));
+ ASSERT_FALSE(server.is_host_blocked(MAKE_IPV4_ADDRESS(1,2,3,0), &seconds));
+ ASSERT_TRUE(server.block_subnet(MAKE_IPV4_SUBNET(1,2,3,4,8), 10));
+ ASSERT_TRUE(server.get_blocked_subnets().size() == 1);
+ ASSERT_TRUE(server.is_host_blocked(MAKE_IPV4_ADDRESS(1,255,3,255), &seconds));
+ ASSERT_TRUE(server.is_host_blocked(MAKE_IPV4_ADDRESS(1,0,3,255), &seconds));
+ ASSERT_FALSE(server.unblock_subnet(MAKE_IPV4_SUBNET(1,2,3,8,24)));
+ ASSERT_TRUE(server.get_blocked_subnets().size() == 1);
+ ASSERT_TRUE(server.block_subnet(MAKE_IPV4_SUBNET(1,2,3,4,8), 10));
+ ASSERT_TRUE(server.get_blocked_subnets().size() == 1);
+ ASSERT_TRUE(server.unblock_subnet(MAKE_IPV4_SUBNET(1,255,0,0,8)));
+ ASSERT_TRUE(server.get_blocked_subnets().size() == 0);
+}
+
namespace nodetool { template class node_server<cryptonote::t_cryptonote_protocol_handler<test_core>>; }
namespace cryptonote { template class t_cryptonote_protocol_handler<test_core>; }
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index 946731826..c5f9a42d0 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -946,3 +946,20 @@ TEST(parsing, number)
epee::misc_utils::parse::match_number(i, s.end(), val);
ASSERT_EQ(val, "+9.34e+03");
}
+
+TEST(parsing, unicode)
+{
+ std::string bs;
+ 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, "あまやかす");
+}
diff --git a/tests/unit_tests/keccak.cpp b/tests/unit_tests/keccak.cpp
index 37da65d76..f4d41a8fa 100644
--- a/tests/unit_tests/keccak.cpp
+++ b/tests/unit_tests/keccak.cpp
@@ -148,3 +148,20 @@ TEST(keccak, 137_and_1_136)
TEST_KECCAK(137, chunks);
}
+TEST(keccak, alignment)
+{
+ uint8_t data[6064];
+ __attribute__ ((aligned(16))) char adata[6000];
+
+ for (size_t i = 0; i < sizeof(data) / sizeof(data[0]); ++i)
+ data[i] = i & 1;
+
+ uint8_t md[32], amd[32];
+ for (int offset = 0; offset < 64; ++offset)
+ {
+ memcpy(adata, data + offset, 6000);
+ keccak((const uint8_t*)&data[offset], 6000, md, 32);
+ keccak((const uint8_t*)adata, 6000, amd, 32);
+ ASSERT_TRUE(!memcmp(md, amd, 32));
+ }
+}
diff --git a/tests/unit_tests/mnemonics.cpp b/tests/unit_tests/mnemonics.cpp
index 16634e7a1..51feb54e4 100644
--- a/tests/unit_tests/mnemonics.cpp
+++ b/tests/unit_tests/mnemonics.cpp
@@ -82,7 +82,7 @@ namespace
crypto::secret_key randkey;
for (size_t ii = 0; ii < sizeof(randkey); ++ii)
{
- randkey.data[ii] = rand();
+ randkey.data[ii] = crypto::rand<uint8_t>();
}
crypto::ElectrumWords::bytes_to_words(randkey, w_seed, language.get_language_name());
seed = std::string(w_seed.data(), w_seed.size());
@@ -256,4 +256,4 @@ TEST(mnemonics, partial_word_tolerance)
res = crypto::ElectrumWords::words_to_bytes(seed_1, key_1, language_name_1);
ASSERT_EQ(true, res);
ASSERT_STREQ(language_name_1.c_str(), "English");
-} \ No newline at end of file
+}
diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp
index 326e63db8..3acf75f3b 100644
--- a/tests/unit_tests/net.cpp
+++ b/tests/unit_tests/net.cpp
@@ -524,6 +524,24 @@ TEST(get_network_address, ipv4)
EXPECT_STREQ("23.0.0.254:2000", address->str().c_str());
}
+TEST(get_network_address, ipv4subnet)
+{
+ expect<epee::net_utils::ipv4_network_subnet> address = net::get_ipv4_subnet_address("0.0.0.0", true);
+ EXPECT_STREQ("0.0.0.0/32", address->str().c_str());
+
+ address = net::get_ipv4_subnet_address("0.0.0.0");
+ EXPECT_TRUE(!address);
+
+ address = net::get_ipv4_subnet_address("0.0.0.0/32");
+ EXPECT_STREQ("0.0.0.0/32", address->str().c_str());
+
+ address = net::get_ipv4_subnet_address("0.0.0.0/0");
+ EXPECT_STREQ("0.0.0.0/0", address->str().c_str());
+
+ address = net::get_ipv4_subnet_address("12.34.56.78/16");
+ EXPECT_STREQ("12.34.0.0/16", address->str().c_str());
+}
+
namespace
{
using stream_type = boost::asio::ip::tcp;
diff --git a/tests/unit_tests/output_selection.cpp b/tests/unit_tests/output_selection.cpp
index 235b1c809..0724cd3e0 100644
--- a/tests/unit_tests/output_selection.cpp
+++ b/tests/unit_tests/output_selection.cpp
@@ -138,7 +138,7 @@ TEST(select_outputs, density)
static const size_t NPICKS = 1000000;
std::vector<uint64_t> offsets;
- MKOFFSETS(300000, 1 + (rand() & 0x1f));
+ MKOFFSETS(300000, 1 + (crypto::rand<size_t>() & 0x1f));
tools::gamma_picker picker(offsets);
std::vector<int> picks(/*n_outs*/offsets.size(), 0);
@@ -181,7 +181,7 @@ TEST(select_outputs, same_distribution)
static const size_t NPICKS = 1000000;
std::vector<uint64_t> offsets;
- MKOFFSETS(300000, 1 + (rand() & 0x1f));
+ MKOFFSETS(300000, 1 + (crypto::rand<size_t>() & 0x1f));
tools::gamma_picker picker(offsets);
std::vector<int> chain_picks(offsets.size(), 0);
@@ -211,10 +211,10 @@ TEST(select_outputs, same_distribution)
{
const double diff = (double)output_norm[i] - (double)chain_norm[i];
double dev = fabs(2.0 * diff / (output_norm[i] + chain_norm[i]));
- ASSERT_LT(dev, 0.1);
+ ASSERT_LT(dev, 0.15);
avg_dev += dev;
}
avg_dev /= 100;
MDEBUG("avg_dev: " << avg_dev);
- ASSERT_LT(avg_dev, 0.015);
+ ASSERT_LT(avg_dev, 0.02);
}
diff --git a/tests/unit_tests/rolling_median.cpp b/tests/unit_tests/rolling_median.cpp
index 6d6adcc7d..547fe092f 100644
--- a/tests/unit_tests/rolling_median.cpp
+++ b/tests/unit_tests/rolling_median.cpp
@@ -69,7 +69,7 @@ TEST(rolling_median, series)
v.reserve(100);
for (int i = 0; i < 10000; ++i)
{
- uint64_t r = rand();
+ uint64_t r = crypto::rand<uint64_t>();
v.push_back(r);
if (v.size() > 100)
v.erase(v.begin());
@@ -87,7 +87,7 @@ TEST(rolling_median, clear_whole)
median.reserve(10000);
for (int i = 0; i < 10000; ++i)
{
- random.push_back(rand());
+ random.push_back(crypto::rand<uint64_t>());
m.insert(random.back());
median.push_back(m.median());
}
@@ -107,7 +107,7 @@ TEST(rolling_median, clear_partway)
median.reserve(10000);
for (int i = 0; i < 10000; ++i)
{
- random.push_back(rand());
+ random.push_back(crypto::rand<uint64_t>());
m.insert(random.back());
median.push_back(m.median());
}
@@ -126,7 +126,7 @@ TEST(rolling_median, order)
random.reserve(1000);
for (int i = 0; i < 1000; ++i)
{
- random.push_back(rand());
+ random.push_back(crypto::rand<uint64_t>());
m.insert(random.back());
}
const uint64_t med = m.median();
diff --git a/tests/unit_tests/test_protocol_pack.cpp b/tests/unit_tests/test_protocol_pack.cpp
index 7329c0d23..0ae2e9c68 100644
--- a/tests/unit_tests/test_protocol_pack.cpp
+++ b/tests/unit_tests/test_protocol_pack.cpp
@@ -48,6 +48,7 @@ TEST(protocol_pack, protocol_pack_command)
cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request r2;
res = epee::serialization::load_t_from_binary(r2, buff);
+ ASSERT_TRUE(res);
ASSERT_TRUE(r.m_block_ids.size() == i);
ASSERT_TRUE(r.start_height == 1);
ASSERT_TRUE(r.total_height == 3);
diff --git a/tests/unit_tests/varint.cpp b/tests/unit_tests/varint.cpp
index ca0900682..72691d722 100644
--- a/tests/unit_tests/varint.cpp
+++ b/tests/unit_tests/varint.cpp
@@ -56,7 +56,6 @@ TEST(varint, equal)
ASSERT_TRUE (bytes > 0 && bytes <= sizeof(buf));
uint64_t idx2;
- bufptr = buf;
std::string s(buf, bytes);
int read = tools::read_varint(s.begin(), s.end(), idx2);
ASSERT_EQ (read, bytes);