aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/README.md16
-rw-r--r--tests/difficulty/difficulty.cpp2
-rwxr-xr-xtests/functional_tests/bans.py3
-rwxr-xr-xtests/functional_tests/blockchain.py20
-rwxr-xr-xtests/functional_tests/cold_signing.py16
-rwxr-xr-xtests/functional_tests/daemon_info.py1
-rwxr-xr-xtests/functional_tests/functional_tests_rpc.py3
-rwxr-xr-xtests/functional_tests/get_output_distribution.py225
-rwxr-xr-xtests/functional_tests/integrated_address.py13
-rwxr-xr-xtests/functional_tests/mining.py12
-rwxr-xr-xtests/functional_tests/multisig.py9
-rwxr-xr-xtests/functional_tests/proofs.py9
-rwxr-xr-xtests/functional_tests/sign_message.py6
-rwxr-xr-xtests/functional_tests/speed.py2
-rwxr-xr-xtests/functional_tests/transfer.py16
-rwxr-xr-xtests/functional_tests/txpool.py24
-rwxr-xr-xtests/functional_tests/wallet_address.py23
-rw-r--r--tests/gtest/README.md98
-rw-r--r--tests/hash-target.cpp2
-rw-r--r--tests/performance_tests/check_hash.h8
-rw-r--r--tests/unit_tests/CMakeLists.txt1
-rw-r--r--tests/unit_tests/ban.cpp38
-rw-r--r--tests/unit_tests/difficulty.cpp8
-rw-r--r--tests/unit_tests/keccak.cpp17
-rw-r--r--tests/unit_tests/logging.cpp3
-rw-r--r--tests/unit_tests/net.cpp18
-rw-r--r--tests/unit_tests/output_distribution.cpp36
-rw-r--r--tests/unit_tests/output_selection.cpp2
-rw-r--r--tests/unit_tests/rolling_median.cpp202
-rw-r--r--tests/unit_tests/uri.cpp4
31 files changed, 726 insertions, 112 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index bbb0bc051..afc69ee88 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -66,6 +66,7 @@ else ()
# Emulate the FindGTest module's variable.
set(GTEST_LIBRARIES gtest gtest_main)
+ set(GTEST_BOTH_LIBRARIES gtest gtest_main)
include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/gtest/include")
endif (GTest_FOUND)
diff --git a/tests/README.md b/tests/README.md
index 053dd2244..f6dd25ead 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -2,7 +2,7 @@
To run all tests, run:
-```
+```bash
cd /path/to/monero
make [-jn] debug-test # where n is number of compiler processes
```
@@ -17,7 +17,7 @@ Tests are located in `tests/core_tests/`, and follow a straightforward naming co
To run only Monero's core tests (after building):
-```
+```bash
cd build/debug/tests/core_tests
ctest
```
@@ -36,7 +36,7 @@ Tests correspond to components under `src/crypto/`. A quick comparison reveals t
To run only Monero's crypto tests (after building):
-```
+```bash
cd build/debug/tests/crypto
ctest
```
@@ -53,13 +53,13 @@ To run the same tests on a release build, replace `debug` with `release`.
Functional tests are located under the `tests/functional` directory.
First, run a regtest daemon in the offline mode and with a fixed difficulty:
-```
+```bash
monerod --regtest --offline --fixed-difficulty 1
```
Alternatively, you can run multiple daemons and let them connect with each other by using `--add-exclusive-node`. In this case, make sure that the same fixed difficulty is given to all the daemons.
Next, restore a mainnet wallet with the following seed and restore height 0 (the file path doesn't matter):
-```
+```bash
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
```
@@ -77,7 +77,7 @@ Hash tests exist under `tests/hash`, and include a set of target hashes in text
To run only Monero's hash tests (after building):
-```
+```bash
cd build/debug/tests/hash
ctest
```
@@ -98,7 +98,7 @@ Performance tests are located in `tests/performance_tests`, and test features fo
To run only Monero's performance tests (after building):
-```
+```bash
cd build/debug/tests/performance_tests
./performance_tests
```
@@ -115,7 +115,7 @@ Unit tests are defined under the `tests/unit_tests` directory. Independent compo
To run only Monero's unit tests (after building):
-```
+```bash
cd build/debug/tests/unit_tests
ctest
```
diff --git a/tests/difficulty/difficulty.cpp b/tests/difficulty/difficulty.cpp
index 11ce0bd73..18f1d0030 100644
--- a/tests/difficulty/difficulty.cpp
+++ b/tests/difficulty/difficulty.cpp
@@ -124,7 +124,7 @@ int main(int argc, char *argv[]) {
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) {
+ if ((wide_res & 0xffffffffffffffff).convert_to<uint64_t>() != res) {
cerr << "Wrong wide difficulty for block " << n << endl
<< "Expected: " << res << endl
<< "Found: " << wide_res << endl;
diff --git a/tests/functional_tests/bans.py b/tests/functional_tests/bans.py
index bb3051a6a..e859e58c9 100755
--- a/tests/functional_tests/bans.py
+++ b/tests/functional_tests/bans.py
@@ -28,6 +28,7 @@
# 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.
+from __future__ import print_function
import time
"""Test peer baning RPC calls
@@ -42,7 +43,7 @@ from framework.daemon import Daemon
class BanTest():
def run_test(self):
- print 'Testing bans'
+ print('Testing bans')
daemon = Daemon()
res = daemon.get_bans()
diff --git a/tests/functional_tests/blockchain.py b/tests/functional_tests/blockchain.py
index ee84d84bc..2bd7672c0 100755
--- a/tests/functional_tests/blockchain.py
+++ b/tests/functional_tests/blockchain.py
@@ -28,6 +28,7 @@
# 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.
+from __future__ import print_function
import time
"""Test daemon blockchain RPC calls
@@ -45,13 +46,20 @@ from framework.daemon import Daemon
class BlockchainTest():
def run_test(self):
+ self.reset()
self._test_generateblocks(5)
self._test_alt_chains()
+ def reset(self):
+ print('Resetting blockchain')
+ daemon = Daemon()
+ daemon.pop_blocks(1000)
+ daemon.flush_txpool()
+
def _test_generateblocks(self, blocks):
assert blocks >= 2
- print "Test generating", blocks, 'blocks'
+ print("Test generating", blocks, 'blocks')
daemon = Daemon()
@@ -175,14 +183,14 @@ class BlockchainTest():
for idx in tx.output_indices:
assert idx == running_output_index
running_output_index += 1
- res_out = daemon.get_outs([{'amount': 0, 'index': i} for i in tx.output_indices], get_txid = True)
+ res_out = daemon.get_outs([{'amount': 0, 'index': idx} for idx in tx.output_indices], get_txid = True)
assert len(res_out.outs) == len(tx.output_indices)
for out in res_out.outs:
assert len(out.key) == 64
assert len(out.mask) == 64
assert not out.unlocked
- assert out.height == i + 1
- assert out.txid == txids[i + 1]
+ assert out.height == i
+ assert out.txid == txids[i]
for i in range(height + nblocks - 1):
res_sum = daemon.get_coinbase_tx_sum(i, 1)
@@ -248,7 +256,7 @@ class BlockchainTest():
alt_blocks[i] = txid
nonce += 1
- print 'mining 3 on 1'
+ print('mining 3 on 1')
# three more on [1]
chain1 = []
res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 3, prev_block = alt_blocks[1], starting_nonce = nonce)
@@ -268,7 +276,7 @@ class BlockchainTest():
for txid in alt_blocks:
assert txid in res.blks_hashes or txid == alt_blocks[1]
- print 'mining 4 on 3'
+ print('mining 4 on 3')
# 4 more on [3], the chain will reorg when we mine the 4th
top_block_hash = blk_hash
prev_block = alt_blocks[3]
diff --git a/tests/functional_tests/cold_signing.py b/tests/functional_tests/cold_signing.py
index e5430f87c..a722d8927 100755
--- a/tests/functional_tests/cold_signing.py
+++ b/tests/functional_tests/cold_signing.py
@@ -28,22 +28,28 @@
# 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 cold tx signing
"""
+from __future__ import print_function
from framework.daemon import Daemon
from framework.wallet import Wallet
class ColdSigningTest():
def run_test(self):
+ self.reset()
self.create(0)
self.mine()
self.transfer()
+ def reset(self):
+ print('Resetting blockchain')
+ daemon = Daemon()
+ daemon.pop_blocks(1000)
+ daemon.flush_txpool()
+
def create(self, idx):
- print 'Creating hot and cold wallet'
+ print('Creating hot and cold wallet')
self.hot_wallet = Wallet(idx = 0)
# close the wallet if any, will throw if none is loaded
@@ -109,7 +115,7 @@ class ColdSigningTest():
assert len(res.unsigned_txset) > 0
unsigned_txset = res.unsigned_txset
- print 'Signing transaction with cold wallet'
+ print('Signing transaction with cold wallet')
res = self.cold_wallet.describe_transfer(unsigned_txset = unsigned_txset)
assert len(res.desc) == 1
desc = res.desc[0]
@@ -133,7 +139,7 @@ class ColdSigningTest():
txid = res.tx_hash_list[0]
assert len(txid) == 64
- print 'Submitting transaction with hot wallet'
+ print('Submitting transaction with hot wallet')
res = self.hot_wallet.submit_transfer(signed_txset)
assert len(res.tx_hash_list) > 0
assert res.tx_hash_list[0] == txid
diff --git a/tests/functional_tests/daemon_info.py b/tests/functional_tests/daemon_info.py
index bd3528c3f..4fa768b03 100755
--- a/tests/functional_tests/daemon_info.py
+++ b/tests/functional_tests/daemon_info.py
@@ -36,6 +36,7 @@ Test the following RPCs:
"""
+from __future__ import print_function
from framework.daemon import Daemon
class DaemonGetInfoTest():
diff --git a/tests/functional_tests/functional_tests_rpc.py b/tests/functional_tests/functional_tests_rpc.py
index 83b75a088..25ab641ab 100755
--- a/tests/functional_tests/functional_tests_rpc.py
+++ b/tests/functional_tests/functional_tests_rpc.py
@@ -10,7 +10,7 @@ import string
import os
USAGE = 'usage: functional_tests_rpc.py <python> <srcdir> <builddir> [<tests-to-run> | all]'
-DEFAULT_TESTS = ['daemon_info', 'blockchain', 'wallet_address', 'integrated_address', 'mining', 'transfer', 'txpool', 'multisig', 'cold_signing', 'sign_message', 'proofs']
+DEFAULT_TESTS = ['bans', 'daemon_info', 'blockchain', 'wallet_address', 'integrated_address', 'mining', 'transfer', 'txpool', 'multisig', 'cold_signing', 'sign_message', 'proofs', 'get_output_distribution']
try:
python = sys.argv[1]
srcdir = sys.argv[2]
@@ -98,6 +98,7 @@ FAIL = []
for test in tests:
try:
print('[TEST STARTED] ' + test)
+ sys.stdout.flush()
cmd = [python, srcdir + '/' + test + ".py"]
subprocess.check_call(cmd)
PASS.append(test)
diff --git a/tests/functional_tests/get_output_distribution.py b/tests/functional_tests/get_output_distribution.py
new file mode 100755
index 000000000..93822e90a
--- /dev/null
+++ b/tests/functional_tests/get_output_distribution.py
@@ -0,0 +1,225 @@
+#!/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.
+
+"""Test get_output_distribution RPC
+"""
+
+from __future__ import print_function
+from framework.daemon import Daemon
+from framework.wallet import Wallet
+
+class GetOutputDistributionTest():
+ def run_test(self):
+ self.reset()
+ self.create()
+ self.test_get_output_distribution()
+
+ def reset(self):
+ print('Resetting blockchain')
+ daemon = Daemon()
+ daemon.pop_blocks(1000)
+ daemon.flush_txpool()
+
+ def create(self):
+ 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 = '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')
+
+ def test_get_output_distribution(self):
+ print("Test get_output_distribution")
+
+ daemon = Daemon()
+
+ res = daemon.get_output_distribution([0], 0, 0)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 0
+ assert d.base == 0
+ assert d.binary == False
+ assert len(d.distribution) == 1
+ assert d.distribution[0] == 0
+
+ res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
+
+ res = daemon.get_output_distribution([0], 0, 0)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 0
+ assert d.base == 0
+ assert d.binary == False
+ assert len(d.distribution) == 2
+ assert d.distribution[0] == 0
+ assert d.distribution[1] == 1
+
+ res = daemon.pop_blocks(1)
+
+ res = daemon.get_output_distribution([0], 0, 0)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 0
+ assert d.base == 0
+ assert d.binary == False
+ assert len(d.distribution) == 1
+ assert d.distribution[0] == 0
+
+ res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 3)
+
+ res = daemon.get_output_distribution([0], 0, 0, cumulative = True)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 0
+ assert d.base == 0
+ assert d.binary == False
+ assert len(d.distribution) == 4
+ assert d.distribution[0] == 0
+ assert d.distribution[1] == 1
+ assert d.distribution[2] == 2
+ assert d.distribution[3] == 3
+
+ # extend
+ res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80)
+
+ res = daemon.get_output_distribution([0], 0, 0, cumulative = True)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 0
+ assert d.base == 0
+ assert d.binary == False
+ assert len(d.distribution) == 84
+ for h in range(len(d.distribution)):
+ assert d.distribution[h] == h
+
+ # pop and replace, this will do through the "trim and extend" path
+ res = daemon.pop_blocks(2)
+ self.wallet.refresh()
+ dst = {'address': '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'amount': 1000000000000}
+ self.wallet.transfer([dst])
+ res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
+ for step in range(3): # the second will be cached, the third will also be cached, but we get it in non-cumulative mode
+ res = daemon.get_output_distribution([0], 0, 0, cumulative = step < 3)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 0
+ assert d.base == 0
+ assert d.binary == False
+ assert len(d.distribution) == 83
+ for h in range(len(d.distribution)):
+ assert d.distribution[h] == (h if step < 3 else 1) + (2 if h == len(d.distribution) - 1 else 0)
+
+ # start at 0, end earlier
+ res = daemon.get_output_distribution([0], 0, 40, cumulative = True)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 0
+ assert d.base == 0
+ assert d.binary == False
+ assert len(d.distribution) == 41
+ for h in range(len(d.distribution)):
+ assert d.distribution[h] == h
+
+ # start after 0, end earlier
+ res = daemon.get_output_distribution([0], 10, 20, cumulative = True)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 0
+ assert d.base == 9
+ assert d.binary == False
+ assert len(d.distribution) == 11
+ for h in range(len(d.distribution)):
+ assert d.distribution[h] == 10 + h
+
+ # straddling up
+ res = daemon.get_output_distribution([0], 15, 25, cumulative = True)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 0
+ assert d.base == 14
+ assert d.binary == False
+ assert len(d.distribution) == 11
+ for h in range(len(d.distribution)):
+ assert d.distribution[h] == 15 + h
+
+ # straddling down
+ res = daemon.get_output_distribution([0], 8, 18, cumulative = True)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 0
+ assert d.base == 7
+ assert d.binary == False
+ assert len(d.distribution) == 11
+ for h in range(len(d.distribution)):
+ assert d.distribution[h] == 8 + h
+
+ # encompassing
+ res = daemon.get_output_distribution([0], 5, 20, cumulative = True)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 0
+ assert d.base == 4
+ assert d.binary == False
+ assert len(d.distribution) == 16
+ for h in range(len(d.distribution)):
+ assert d.distribution[h] == 5 + h
+
+ # single
+ res = daemon.get_output_distribution([0], 2, 2, cumulative = True)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 0
+ assert d.base == 1
+ assert d.binary == False
+ assert len(d.distribution) == 1
+ assert d.distribution[0] == 2
+
+ # a non existent amount
+ res = daemon.get_output_distribution([1], 0, 0)
+ assert len(res.distributions) == 1
+ d = res.distributions[0]
+ assert d.amount == 1
+ assert d.base == 0
+ assert d.binary == False
+ assert len(d.distribution) == 83
+ for h in range(len(d.distribution)):
+ assert d.distribution[h] == 0
+
+
+class Guard:
+ def __enter__(self):
+ for i in range(4):
+ Wallet(idx = i).auto_refresh(False)
+ def __exit__(self, exc_type, exc_value, traceback):
+ for i in range(4):
+ Wallet(idx = i).auto_refresh(True)
+
+if __name__ == '__main__':
+ with Guard() as guard:
+ GetOutputDistributionTest().run_test()
diff --git a/tests/functional_tests/integrated_address.py b/tests/functional_tests/integrated_address.py
index 338dd14ae..4e42261a6 100755
--- a/tests/functional_tests/integrated_address.py
+++ b/tests/functional_tests/integrated_address.py
@@ -28,8 +28,6 @@
# 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 integrated address RPC calls
Test the following RPCs:
@@ -38,6 +36,7 @@ Test the following RPCs:
"""
+from __future__ import print_function
from framework.wallet import Wallet
class IntegratedAddressTest():
@@ -46,7 +45,7 @@ class IntegratedAddressTest():
self.check()
def create(self):
- print 'Creating wallet'
+ print('Creating wallet')
wallet = Wallet()
# close the wallet if any, will throw if none is loaded
try: wallet.close_wallet()
@@ -59,7 +58,7 @@ class IntegratedAddressTest():
def check(self):
wallet = Wallet()
- print 'Checking local address'
+ print('Checking local address')
res = wallet.make_integrated_address(payment_id = '0123456789abcdef')
assert res.integrated_address == '4CMe2PUhs4J4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfSbLRB61BQVATzerHGj'
assert res.payment_id == '0123456789abcdef'
@@ -67,7 +66,7 @@ class IntegratedAddressTest():
assert res.standard_address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
assert res.payment_id == '0123456789abcdef'
- print 'Checking different address'
+ print('Checking different address')
res = wallet.make_integrated_address(standard_address = '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', payment_id = '1122334455667788')
assert res.integrated_address == '4GYjoMG9Y2BBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCVSs1ZojwrDCGS5rUuo'
assert res.payment_id == '1122334455667788'
@@ -75,7 +74,7 @@ class IntegratedAddressTest():
assert res.standard_address == '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK'
assert res.payment_id == '1122334455667788'
- print 'Checking bad payment id'
+ print('Checking bad payment id')
fails = 0
try: wallet.make_integrated_address(standard_address = '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', payment_id = '11223344556677880')
except: fails += 1
@@ -89,7 +88,7 @@ class IntegratedAddressTest():
except: fails += 1
assert fails == 5
- print 'Checking bad standard address'
+ print('Checking bad standard address')
fails = 0
try: wallet.make_integrated_address(standard_address = '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerr', payment_id = '1122334455667788')
except: fails += 1
diff --git a/tests/functional_tests/mining.py b/tests/functional_tests/mining.py
index 1b189beb2..5c14d34fd 100755
--- a/tests/functional_tests/mining.py
+++ b/tests/functional_tests/mining.py
@@ -28,6 +28,7 @@
# 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.
+from __future__ import print_function
import time
"""Test daemon mining RPC calls
@@ -43,11 +44,18 @@ from framework.wallet import Wallet
class MiningTest():
def run_test(self):
+ self.reset()
self.create()
self.mine()
+ def reset(self):
+ print('Resetting blockchain')
+ daemon = Daemon()
+ daemon.pop_blocks(1000)
+ daemon.flush_txpool()
+
def create(self):
- print 'Creating wallet'
+ print('Creating wallet')
wallet = Wallet()
# close the wallet if any, will throw if none is loaded
try: wallet.close_wallet()
@@ -55,7 +63,7 @@ class MiningTest():
res = wallet.restore_deterministic_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')
def mine(self):
- print "Test mining"
+ print("Test mining")
daemon = Daemon()
wallet = Wallet()
diff --git a/tests/functional_tests/multisig.py b/tests/functional_tests/multisig.py
index a61f30001..3c8cd9c1d 100755
--- a/tests/functional_tests/multisig.py
+++ b/tests/functional_tests/multisig.py
@@ -28,7 +28,7 @@
# 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
+from __future__ import print_function
"""Test multisig transfers
"""
@@ -38,6 +38,7 @@ from framework.wallet import Wallet
class MultisigTest():
def run_test(self):
+ self.reset()
self.mine('493DsrfJPqiN3Suv9RcRDoZEbQtKZX1sNcGPA3GhkKYEEmivk8kjQrTdRdVc4ZbmzWJuE157z9NNUKmF2VDfdYDR3CziGMk', 5)
self.mine('42jSRGmmKN96V2j3B8X2DbiNThBXW1tSi1rW1uwkqbyURenq3eC3yosNm8HEMdHuWwKMFGzMUB3RCTvcTaW9kHpdRPP7p5y', 5)
self.mine('47fF32AdrmXG84FcPY697uZdd42pMMGiH5UpiTRTt3YX2pZC7t7wkzEMStEicxbQGRfrYvAAYxH6Fe8rnD56EaNwUgxRd53', 5)
@@ -68,6 +69,12 @@ class MultisigTest():
self.import_multisig_info([0, 1, 2, 3], 6)
self.check_transaction(txid)
+ def reset(self):
+ print('Resetting blockchain')
+ daemon = Daemon()
+ daemon.pop_blocks(1000)
+ daemon.flush_txpool()
+
def mine(self, address, blocks):
print("Mining some blocks")
daemon = Daemon()
diff --git a/tests/functional_tests/proofs.py b/tests/functional_tests/proofs.py
index 0a0b6304d..243929dc3 100755
--- a/tests/functional_tests/proofs.py
+++ b/tests/functional_tests/proofs.py
@@ -28,7 +28,7 @@
# 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
+from __future__ import print_function
"""Test misc proofs (tx key, send, receive, reserve)
"""
@@ -38,6 +38,7 @@ from framework.wallet import Wallet
class ProofsTest():
def run_test(self):
+ self.reset()
self.mine('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80)
self.create_wallets()
txid, tx_key, amount = self.transfer()
@@ -45,6 +46,12 @@ class ProofsTest():
self.check_tx_proof(txid, amount)
self.check_reserve_proof()
+ def reset(self):
+ print('Resetting blockchain')
+ daemon = Daemon()
+ daemon.pop_blocks(1000)
+ daemon.flush_txpool()
+
def mine(self, address, blocks):
print("Mining some blocks")
daemon = Daemon()
diff --git a/tests/functional_tests/sign_message.py b/tests/functional_tests/sign_message.py
index 4c3ec3588..de8f0cee2 100755
--- a/tests/functional_tests/sign_message.py
+++ b/tests/functional_tests/sign_message.py
@@ -28,7 +28,7 @@
# 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
+from __future__ import print_function
"""Test message signing/verification RPC calls
@@ -46,7 +46,7 @@ class MessageSigningTest():
self.check_signing()
def create(self):
- print 'Creating wallets'
+ print('Creating wallets')
seeds = [
'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',
'peeled mixture ionic radar utopia puddle buying illness nuns gadget river spout cavernous bounced paradise drunk looking cottage jump tequila melting went winter adjust spout',
@@ -66,7 +66,7 @@ class MessageSigningTest():
assert res.seed == seeds[i]
def check_signing(self):
- print 'Signing/verifing messages'
+ print('Signing/verifing messages')
messages = ['foo', '']
for message in messages:
res = self.wallet[0].sign(message)
diff --git a/tests/functional_tests/speed.py b/tests/functional_tests/speed.py
index bd8892df8..ed1e332e9 100755
--- a/tests/functional_tests/speed.py
+++ b/tests/functional_tests/speed.py
@@ -40,7 +40,7 @@ Test the following RPCs:
import time
from time import sleep
-from decimal import Decimal
+from __future__ import print_function
from framework.daemon import Daemon
from framework.wallet import Wallet
diff --git a/tests/functional_tests/transfer.py b/tests/functional_tests/transfer.py
index bc2f5472b..d9a6e592e 100755
--- a/tests/functional_tests/transfer.py
+++ b/tests/functional_tests/transfer.py
@@ -28,7 +28,7 @@
# 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
+from __future__ import print_function
import json
"""Test simple transfers
@@ -39,6 +39,7 @@ from framework.wallet import Wallet
class TransferTest():
def run_test(self):
+ self.reset()
self.create()
self.mine()
self.transfer()
@@ -46,8 +47,14 @@ class TransferTest():
self.check_double_spend_detection()
self.sweep_single()
+ def reset(self):
+ print('Resetting blockchain')
+ daemon = Daemon()
+ daemon.pop_blocks(1000)
+ daemon.flush_txpool()
+
def create(self):
- print 'Creating wallets'
+ print('Creating wallets')
seeds = [
'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',
'peeled mixture ionic radar utopia puddle buying illness nuns gadget river spout cavernous bounced paradise drunk looking cottage jump tequila melting went winter adjust spout',
@@ -290,7 +297,7 @@ class TransferTest():
assert res.unlocked_balance <= res.balance
assert res.blocks_to_unlock == 9
- print 'Creating multi out transfer'
+ print('Creating multi out transfer')
self.wallet[0].refresh()
@@ -512,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]]
diff --git a/tests/functional_tests/txpool.py b/tests/functional_tests/txpool.py
index 71109c9e5..b6af4c84f 100755
--- a/tests/functional_tests/txpool.py
+++ b/tests/functional_tests/txpool.py
@@ -28,7 +28,7 @@
# 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
+from __future__ import print_function
"""Test txpool
"""
@@ -38,12 +38,19 @@ from framework.wallet import Wallet
class TransferTest():
def run_test(self):
+ self.reset()
self.create()
self.mine()
self.check_txpool()
+ def reset(self):
+ print('Resetting blockchain')
+ daemon = Daemon()
+ daemon.pop_blocks(1000)
+ daemon.flush_txpool()
+
def create(self):
- print 'Creating wallet'
+ print('Creating wallet')
wallet = Wallet()
# close the wallet if any, will throw if none is loaded
try: wallet.close_wallet()
@@ -107,15 +114,16 @@ class TransferTest():
assert sorted(res.tx_hashes) == sorted(txes.keys())
print('Flushing 2 transactions')
- daemon.flush_txpool([txes.keys()[1], txes.keys()[3]])
+ txes_keys = list(txes.keys())
+ daemon.flush_txpool([txes_keys[1], txes_keys[3]])
res = daemon.get_transaction_pool()
assert len(res.transactions) == txpool_size - 2
- assert len([x for x in res.transactions if x.id_hash == txes.keys()[1]]) == 0
- assert len([x for x in res.transactions if x.id_hash == txes.keys()[3]]) == 0
+ assert len([x for x in res.transactions if x.id_hash == txes_keys[1]]) == 0
+ assert len([x for x in res.transactions if x.id_hash == txes_keys[3]]) == 0
- new_keys = txes.keys()
- new_keys.remove(txes.keys()[1])
- new_keys.remove(txes.keys()[3])
+ new_keys = list(txes.keys())
+ new_keys.remove(txes_keys[1])
+ new_keys.remove(txes_keys[3])
res = daemon.get_transaction_pool_hashes()
assert sorted(res.tx_hashes) == sorted(new_keys)
diff --git a/tests/functional_tests/wallet_address.py b/tests/functional_tests/wallet_address.py
index cb9c52e7a..4ff059a6f 100755
--- a/tests/functional_tests/wallet_address.py
+++ b/tests/functional_tests/wallet_address.py
@@ -29,8 +29,6 @@
# 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 transaction creation RPC calls
Test the following RPCs:
@@ -38,10 +36,13 @@ Test the following RPCs:
"""
+from __future__ import print_function
from framework.wallet import Wallet
+from framework.daemon import Daemon
class WalletAddressTest():
def run_test(self):
+ self.reset()
self.create()
self.check_main_address()
self.check_keys()
@@ -49,8 +50,14 @@ class WalletAddressTest():
self.open_close()
self.languages()
+ def reset(self):
+ print('Resetting blockchain')
+ daemon = Daemon()
+ daemon.pop_blocks(1000)
+ daemon.flush_txpool()
+
def create(self):
- print 'Creating wallet'
+ print('Creating wallet')
wallet = Wallet()
# close the wallet if any, will throw if none is loaded
try: wallet.close_wallet()
@@ -61,7 +68,7 @@ class WalletAddressTest():
assert res.seed == seed
def check_main_address(self):
- print 'Getting address'
+ print('Getting address')
wallet = Wallet()
res = wallet.get_address()
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', res
@@ -71,7 +78,7 @@ class WalletAddressTest():
assert res.addresses[0].used == False
def check_keys(self):
- print 'Checking keys'
+ print('Checking keys')
wallet = Wallet()
res = wallet.query_key('view_key')
assert res.key == '49774391fa5e8d249fc2c5b45dadef13534bf2483dede880dac88f061e809100'
@@ -81,7 +88,7 @@ class WalletAddressTest():
assert res.key == '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'
def create_subaddresses(self):
- print 'Creating subaddresses'
+ print('Creating subaddresses')
wallet = Wallet()
res = wallet.create_account("idx1")
assert res.account_index == 1, res
@@ -152,7 +159,7 @@ class WalletAddressTest():
assert res.index == {'major': 1, 'minor': 0}
def open_close(self):
- print 'Testing open/close'
+ print('Testing open/close')
wallet = Wallet()
res = wallet.get_address()
@@ -192,7 +199,7 @@ class WalletAddressTest():
except: pass
languages = res.languages
for language in languages:
- print 'Creating ' + str(language) + ' wallet'
+ print('Creating ' + str(language) + ' wallet')
wallet.create_wallet(filename = '', language = language)
res = wallet.query_key('mnemonic')
wallet.close_wallet()
diff --git a/tests/gtest/README.md b/tests/gtest/README.md
index e0ea1b0f3..43a16bde0 100644
--- a/tests/gtest/README.md
+++ b/tests/gtest/README.md
@@ -14,15 +14,19 @@ Suppose you put Google Test in directory `${GTEST_DIR}`. To build it,
create a library build target (or a project as called by Visual Studio
and Xcode) to compile
- ${GTEST_DIR}/src/gtest-all.cc
+```bash
+${GTEST_DIR}/src/gtest-all.cc
+```
with `${GTEST_DIR}/include` in the system header search path and `${GTEST_DIR}`
in the normal header search path. Assuming a Linux-like system and gcc,
something like the following will do:
- g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
- -pthread -c ${GTEST_DIR}/src/gtest-all.cc
- ar -rv libgtest.a gtest-all.o
+```bash
+g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
+ -pthread -c ${GTEST_DIR}/src/gtest-all.cc
+ar -rv libgtest.a gtest-all.o
+```
(We need `-pthread` as Google Test uses threads.)
@@ -30,8 +34,10 @@ Next, you should compile your test source file with
`${GTEST_DIR}/include` in the system header search path, and link it
with gtest and any other necessary libraries:
- g++ -isystem ${GTEST_DIR}/include -pthread path/to/your_test.cc libgtest.a \
- -o your_test
+```bash
+g++ -isystem ${GTEST_DIR}/include -pthread path/to/your_test.cc libgtest.a \
+ -o your_test
+```
As an example, the make/ directory contains a Makefile that you can
use to build Google Test on systems where GNU make is available
@@ -43,9 +49,11 @@ script.
If the default settings are correct for your environment, the
following commands should succeed:
- cd ${GTEST_DIR}/make
- make
- ./sample1_unittest
+```bash
+cd ${GTEST_DIR}/make
+make
+./sample1_unittest
+```
If you see errors, try to tweak the contents of `make/Makefile` to make
them go away. There are instructions in `make/Makefile` on how to do
@@ -62,14 +70,18 @@ CMake works by generating native makefiles or build projects that can
be used in the compiler environment of your choice. The typical
workflow starts with:
- mkdir mybuild # Create a directory to hold the build output.
- cd mybuild
- cmake ${GTEST_DIR} # Generate native build scripts.
+```bash
+mkdir mybuild # Create a directory to hold the build output.
+cd mybuild
+cmake ${GTEST_DIR} # Generate native build scripts.
+```
If you want to build Google Test's samples, you should replace the
last command with
- cmake -Dgtest_build_samples=ON ${GTEST_DIR}
+```bash
+cmake -Dgtest_build_samples=ON ${GTEST_DIR}
+```
If you are on a \*nix system, you should now see a Makefile in the
current directory. Just type 'make' to build gtest.
@@ -108,7 +120,9 @@ end up in your selected build directory (selected in the Xcode
"Preferences..." -> "Building" pane and defaults to xcode/build).
Alternatively, at the command line, enter:
- xcodebuild
+```bash
+xcodebuild
+```
This will build the "Release" configuration of gtest.framework in your
default build location. See the "xcodebuild" man page for more
@@ -152,18 +166,24 @@ tell Google Test to use the same TR1 tuple library the rest of your
project uses, or the two tuple implementations will clash. To do
that, add
- -DGTEST_USE_OWN_TR1_TUPLE=0
+```bash
+-DGTEST_USE_OWN_TR1_TUPLE=0
+```
to the compiler flags while compiling Google Test and your tests. If
you want to force Google Test to use its own tuple library, just add
- -DGTEST_USE_OWN_TR1_TUPLE=1
+```bash
+-DGTEST_USE_OWN_TR1_TUPLE=1
+```
to the compiler flags instead.
If you don't want Google Test to use tuple at all, add
- -DGTEST_HAS_TR1_TUPLE=0
+```bash
+-DGTEST_HAS_TR1_TUPLE=0
+```
and all features using tuple will be disabled.
@@ -177,11 +197,15 @@ macro to see whether this is the case (yes if the macro is `#defined` to
If Google Test doesn't correctly detect whether pthread is available
in your environment, you can force it with
- -DGTEST_HAS_PTHREAD=1
+```bash
+-DGTEST_HAS_PTHREAD=1
+```
or
- -DGTEST_HAS_PTHREAD=0
+```bash
+-DGTEST_HAS_PTHREAD=0
+```
When Google Test uses pthread, you may need to add flags to your
compiler and/or linker to select the pthread library, or you'll get
@@ -198,7 +222,9 @@ as a shared library (known as a DLL on Windows) if you prefer.
To compile *gtest* as a shared library, add
- -DGTEST_CREATE_SHARED_LIBRARY=1
+```bash
+-DGTEST_CREATE_SHARED_LIBRARY=1
+```
to the compiler flags. You'll also need to tell the linker to produce
a shared library instead - consult your linker's manual for how to do
@@ -206,7 +232,9 @@ it.
To compile your *tests* that use the gtest shared library, add
- -DGTEST_LINKED_AS_SHARED_LIBRARY=1
+```bash
+-DGTEST_LINKED_AS_SHARED_LIBRARY=1
+```
to the compiler flags.
@@ -229,18 +257,24 @@ conflict.
Specifically, if both Google Test and some other code define macro
FOO, you can add
- -DGTEST_DONT_DEFINE_FOO=1
+```bash
+-DGTEST_DONT_DEFINE_FOO=1
+```
to the compiler flags to tell Google Test to change the macro's name
from `FOO` to `GTEST_FOO`. Currently `FOO` can be `FAIL`, `SUCCEED`,
or `TEST`. For example, with `-DGTEST_DONT_DEFINE_TEST=1`, you'll
need to write
- GTEST_TEST(SomeTest, DoesThis) { ... }
+```c++
+GTEST_TEST(SomeTest, DoesThis) { ... }
+```
instead of
- TEST(SomeTest, DoesThis) { ... }
+```c++
+TEST(SomeTest, DoesThis) { ... }
+```
in order to define a test.
@@ -254,9 +288,11 @@ To make sure your changes work as intended and don't break existing
functionality, you'll want to compile and run Google Test's own tests.
For that you can use CMake:
- mkdir mybuild
- cd mybuild
- cmake -Dgtest_build_tests=ON ${GTEST_DIR}
+```bash
+mkdir mybuild
+cd mybuild
+cmake -Dgtest_build_tests=ON ${GTEST_DIR}
+```
Make sure you have Python installed, as some of Google Test's tests
are written in Python. If the cmake command complains about not being
@@ -264,12 +300,16 @@ able to find Python (`Could NOT find PythonInterp (missing:
PYTHON_EXECUTABLE)`), try telling it explicitly where your Python
executable can be found:
- cmake -DPYTHON_EXECUTABLE=path/to/python -Dgtest_build_tests=ON ${GTEST_DIR}
+```bash
+cmake -DPYTHON_EXECUTABLE=path/to/python -Dgtest_build_tests=ON ${GTEST_DIR}
+```
Next, you can build Google Test and all of its own tests. On \*nix,
this is usually done by 'make'. To run the tests, do
- make test
+```bash
+make test
+```
All tests should pass.
diff --git a/tests/hash-target.cpp b/tests/hash-target.cpp
index 1e988c302..e95475cac 100644
--- a/tests/hash-target.cpp
+++ b/tests/hash-target.cpp
@@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
for (int i = 31; i >= 0; i--) {
val = val * 256 + 255;
((char *) &h)[i] = static_cast<char>(static_cast<uint64_t>(val / diff));
- val %= diff.convert_to<uint64_t>();
+ val %= (diff & 0xffffffffffffffff).convert_to<uint64_t>();
}
if (check_hash(h, diff) != true) {
return 3;
diff --git a/tests/performance_tests/check_hash.h b/tests/performance_tests/check_hash.h
index d24001903..53746fec4 100644
--- a/tests/performance_tests/check_hash.h
+++ b/tests/performance_tests/check_hash.h
@@ -44,13 +44,13 @@ public:
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>();
+ ((uint64_t*)&hash)[0] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
hash_value >>= 64;
- ((uint64_t*)&hash)[1] = (hash_value << 64 >> 64).convert_to<uint64_t>();
+ ((uint64_t*)&hash)[1] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
hash_value >>= 64;
- ((uint64_t*)&hash)[2] = (hash_value << 64 >> 64).convert_to<uint64_t>();
+ ((uint64_t*)&hash)[2] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
hash_value >>= 64;
- ((uint64_t*)&hash)[3] = (hash_value << 64 >> 64).convert_to<uint64_t>();
+ ((uint64_t*)&hash)[3] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
return true;
}
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index 56a1f8c4d..1c4c4384c 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -72,6 +72,7 @@ set(unit_tests_sources
parse_amount.cpp
pruning.cpp
random.cpp
+ rolling_median.cpp
serialization.cpp
sha256.cpp
slow_memmem.cpp
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/difficulty.cpp b/tests/unit_tests/difficulty.cpp
index 090fecc84..a732e6969 100644
--- a/tests/unit_tests/difficulty.cpp
+++ b/tests/unit_tests/difficulty.cpp
@@ -42,13 +42,13 @@ static crypto::hash MKHASH(uint64_t high, uint64_t low)
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>();
+ ((uint64_t*)&h)[0] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
hash_value >>= 64;
- ((uint64_t*)&h)[1] = hash_value.convert_to<uint64_t>();
+ ((uint64_t*)&h)[1] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
hash_value >>= 64;
- ((uint64_t*)&h)[2] = hash_value.convert_to<uint64_t>();
+ ((uint64_t*)&h)[2] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
hash_value >>= 64;
- ((uint64_t*)&h)[3] = hash_value.convert_to<uint64_t>();
+ ((uint64_t*)&h)[3] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
return h;
}
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/logging.cpp b/tests/unit_tests/logging.cpp
index 12d49e2fb..056eae604 100644
--- a/tests/unit_tests/logging.cpp
+++ b/tests/unit_tests/logging.cpp
@@ -44,7 +44,10 @@ static void init()
static void cleanup()
{
+ // windows does not let files be deleted if still in use, so leave droppings there
+#ifndef _WIN32
boost::filesystem::remove(log_filename);
+#endif
}
static size_t nlines(const std::string &str)
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_distribution.cpp b/tests/unit_tests/output_distribution.cpp
index 45f2c135b..38f442c59 100644
--- a/tests/unit_tests/output_distribution.cpp
+++ b/tests/unit_tests/output_distribution.cpp
@@ -62,6 +62,13 @@ public:
return d;
}
+ std::vector<uint64_t> get_block_weights(uint64_t start_offset, size_t count) const override
+ {
+ std::vector<uint64_t> weights;
+ while (count--) weights.push_back(1);
+ return weights;
+ }
+
uint64_t blockchain_height;
};
@@ -84,36 +91,43 @@ bool get_output_distribution(uint64_t amount, uint64_t from, uint64_t to, uint64
return r && bc->get_output_distribution(amount, from, to, start_height, distribution, base);
}
+crypto::hash get_block_hash(uint64_t height)
+{
+ crypto::hash hash;
+ *((uint64_t*)&hash) = height;
+ return hash;
+}
+
TEST(output_distribution, extend)
{
boost::optional<cryptonote::rpc::output_distribution_data> res;
- res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 28, 29, false);
+ res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 28, 29, ::get_block_hash, false, test_distribution_size);
ASSERT_TRUE(res != boost::none);
ASSERT_EQ(res->distribution.size(), 2);
ASSERT_EQ(res->distribution, std::vector<uint64_t>({5, 0}));
- res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 28, 29, true);
+ res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 28, 29, ::get_block_hash, true, test_distribution_size);
ASSERT_TRUE(res != boost::none);
ASSERT_EQ(res->distribution.size(), 2);
ASSERT_EQ(res->distribution, std::vector<uint64_t>({55, 55}));
- res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 28, 30, false);
+ res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 28, 30, ::get_block_hash, false, test_distribution_size);
ASSERT_TRUE(res != boost::none);
ASSERT_EQ(res->distribution.size(), 3);
ASSERT_EQ(res->distribution, std::vector<uint64_t>({5, 0, 2}));
- res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 28, 30, true);
+ res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 28, 30, ::get_block_hash, true, test_distribution_size);
ASSERT_TRUE(res != boost::none);
ASSERT_EQ(res->distribution.size(), 3);
ASSERT_EQ(res->distribution, std::vector<uint64_t>({55, 55, 57}));
- res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 28, 31, false);
+ res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 28, 31, ::get_block_hash, false, test_distribution_size);
ASSERT_TRUE(res != boost::none);
ASSERT_EQ(res->distribution.size(), 4);
ASSERT_EQ(res->distribution, std::vector<uint64_t>({5, 0, 2, 3}));
- res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 28, 31, true);
+ res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 28, 31, ::get_block_hash, true, test_distribution_size);
ASSERT_TRUE(res != boost::none);
ASSERT_EQ(res->distribution.size(), 4);
ASSERT_EQ(res->distribution, std::vector<uint64_t>({55, 55, 57, 60}));
@@ -123,7 +137,7 @@ TEST(output_distribution, one)
{
boost::optional<cryptonote::rpc::output_distribution_data> res;
- res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 0, 0, false);
+ res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 0, 0, ::get_block_hash, false, test_distribution_size);
ASSERT_TRUE(res != boost::none);
ASSERT_EQ(res->distribution.size(), 1);
ASSERT_EQ(res->distribution.back(), 0);
@@ -133,7 +147,7 @@ TEST(output_distribution, full_cumulative)
{
boost::optional<cryptonote::rpc::output_distribution_data> res;
- res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 0, 31, true);
+ res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 0, 31, ::get_block_hash, true, test_distribution_size);
ASSERT_TRUE(res != boost::none);
ASSERT_EQ(res->distribution.size(), 32);
ASSERT_EQ(res->distribution.back(), 60);
@@ -143,7 +157,7 @@ TEST(output_distribution, full_noncumulative)
{
boost::optional<cryptonote::rpc::output_distribution_data> res;
- res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 0, 31, false);
+ res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 0, 31, ::get_block_hash, false, test_distribution_size);
ASSERT_TRUE(res != boost::none);
ASSERT_EQ(res->distribution.size(), 32);
for (size_t i = 0; i < 32; ++i)
@@ -154,7 +168,7 @@ TEST(output_distribution, part_cumulative)
{
boost::optional<cryptonote::rpc::output_distribution_data> res;
- res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 4, 8, true);
+ res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 4, 8, ::get_block_hash, true, test_distribution_size);
ASSERT_TRUE(res != boost::none);
ASSERT_EQ(res->distribution.size(), 5);
ASSERT_EQ(res->distribution, std::vector<uint64_t>({0, 1, 6, 7, 11}));
@@ -164,7 +178,7 @@ TEST(output_distribution, part_noncumulative)
{
boost::optional<cryptonote::rpc::output_distribution_data> res;
- res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 4, 8, false);
+ res = cryptonote::rpc::RpcHandler::get_output_distribution(::get_output_distribution, 0, 4, 8, ::get_block_hash, false, test_distribution_size);
ASSERT_TRUE(res != boost::none);
ASSERT_EQ(res->distribution.size(), 5);
ASSERT_EQ(res->distribution, std::vector<uint64_t>({0, 1, 5, 1, 4}));
diff --git a/tests/unit_tests/output_selection.cpp b/tests/unit_tests/output_selection.cpp
index 0094fc765..235b1c809 100644
--- a/tests/unit_tests/output_selection.cpp
+++ b/tests/unit_tests/output_selection.cpp
@@ -172,7 +172,7 @@ TEST(select_outputs, density)
float chain_ratio = count_chain / (float)n_outs;
MDEBUG(count_selected << "/" << NPICKS << " outputs selected in blocks of density " << d << ", " << 100.0f * selected_ratio << "%");
MDEBUG(count_chain << "/" << offsets.size() << " outputs in blocks of density " << d << ", " << 100.0f * chain_ratio << "%");
- ASSERT_LT(fabsf(selected_ratio - chain_ratio), 0.02f);
+ ASSERT_LT(fabsf(selected_ratio - chain_ratio), 0.025f);
}
}
diff --git a/tests/unit_tests/rolling_median.cpp b/tests/unit_tests/rolling_median.cpp
new file mode 100644
index 000000000..6d6adcc7d
--- /dev/null
+++ b/tests/unit_tests/rolling_median.cpp
@@ -0,0 +1,202 @@
+// 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 <random>
+#include "gtest/gtest.h"
+#include "misc_language.h"
+#include "rolling_median.h"
+#include "crypto/crypto.h"
+
+TEST(rolling_median, one)
+{
+ epee::misc_utils::rolling_median_t<uint64_t> m(1);
+ m.insert(42);
+ ASSERT_EQ(m.median(), 42);
+ m.insert(18);
+ ASSERT_EQ(m.median(), 18);
+ m.insert(7483);
+ ASSERT_EQ(m.median(), 7483);
+}
+
+TEST(rolling_median, two)
+{
+ epee::misc_utils::rolling_median_t<uint64_t> m(2);
+ m.insert(42);
+ ASSERT_EQ(m.median(), 42);
+ m.insert(45);
+ ASSERT_EQ(m.median(), 43);
+ m.insert(49);
+ ASSERT_EQ(m.median(), 47);
+ m.insert(41);
+ ASSERT_EQ(m.median(), 45);
+ m.insert(43);
+ ASSERT_EQ(m.median(), 42);
+ m.insert(40);
+ ASSERT_EQ(m.median(), 41);
+ m.insert(41);
+ ASSERT_EQ(m.median(), 40);
+}
+
+TEST(rolling_median, series)
+{
+ epee::misc_utils::rolling_median_t<uint64_t> m(100);
+ std::vector<uint64_t> v;
+ v.reserve(100);
+ for (int i = 0; i < 10000; ++i)
+ {
+ uint64_t r = rand();
+ v.push_back(r);
+ if (v.size() > 100)
+ v.erase(v.begin());
+ m.insert(r);
+ std::vector<uint64_t> vcopy = v;
+ ASSERT_EQ(m.median(), epee::misc_utils::median(vcopy));
+ }
+}
+
+TEST(rolling_median, clear_whole)
+{
+ epee::misc_utils::rolling_median_t<uint64_t> m(100);
+ std::vector<uint64_t> random, median;
+ random.reserve(10000);
+ median.reserve(10000);
+ for (int i = 0; i < 10000; ++i)
+ {
+ random.push_back(rand());
+ m.insert(random.back());
+ median.push_back(m.median());
+ }
+ m.clear();
+ for (int i = 0; i < 10000; ++i)
+ {
+ m.insert(random[i]);
+ ASSERT_EQ(median[i], m.median());
+ }
+}
+
+TEST(rolling_median, clear_partway)
+{
+ epee::misc_utils::rolling_median_t<uint64_t> m(100);
+ std::vector<uint64_t> random, median;
+ random.reserve(10000);
+ median.reserve(10000);
+ for (int i = 0; i < 10000; ++i)
+ {
+ random.push_back(rand());
+ m.insert(random.back());
+ median.push_back(m.median());
+ }
+ m.clear();
+ for (int i = 10000 - 100; i < 10000; ++i)
+ {
+ m.insert(random[i]);
+ }
+ ASSERT_EQ(median[10000-1], m.median());
+}
+
+TEST(rolling_median, order)
+{
+ epee::misc_utils::rolling_median_t<uint64_t> m(1000);
+ std::vector<uint64_t> random;
+ random.reserve(1000);
+ for (int i = 0; i < 1000; ++i)
+ {
+ random.push_back(rand());
+ m.insert(random.back());
+ }
+ const uint64_t med = m.median();
+
+ std::sort(random.begin(), random.end(), [](uint64_t a, uint64_t b) { return a < b; });
+ m.clear();
+ for (int i = 0; i < 1000; ++i)
+ m.insert(random[i]);
+ ASSERT_EQ(med, m.median());
+
+ std::sort(random.begin(), random.end(), [](uint64_t a, uint64_t b) { return a > b; });
+ m.clear();
+ for (int i = 0; i < 1000; ++i)
+ m.insert(random[i]);
+ ASSERT_EQ(med, m.median());
+
+ std::shuffle(random.begin(), random.end(), std::default_random_engine(crypto::rand<unsigned>()));
+ m.clear();
+ for (int i = 0; i < 1000; ++i)
+ m.insert(random[i]);
+ ASSERT_EQ(med, m.median());
+}
+
+TEST(rolling_median, history_blind)
+{
+ epee::misc_utils::rolling_median_t<uint64_t> m(10);
+
+ uint64_t median = 0;
+ for (int i = 0; i < 1000; ++i)
+ {
+ m.clear();
+ int history_length = 743723 % (i+1);
+ while (history_length--)
+ m.insert(743284 % (i+1));
+ for (int j = 0; j < 10; ++j)
+ m.insert(8924829384 % (j+1));
+ if (i == 0)
+ median = m.median();
+ else
+ ASSERT_EQ(median, m.median());
+ }
+}
+
+TEST(rolling_median, size)
+{
+ epee::misc_utils::rolling_median_t<uint64_t> m(10);
+
+ ASSERT_EQ(m.size(), 0);
+ m.insert(1);
+ ASSERT_EQ(m.size(), 1);
+ m.insert(2);
+ ASSERT_EQ(m.size(), 2);
+ m.clear();
+ ASSERT_EQ(m.size(), 0);
+ for (int i = 0; i < 10; ++i)
+ {
+ m.insert(80 % (i + 1));
+ ASSERT_EQ(m.size(), i + 1);
+ }
+ m.insert(1);
+ ASSERT_EQ(m.size(), 10);
+ m.insert(2);
+ ASSERT_EQ(m.size(), 10);
+ m.clear();
+ ASSERT_EQ(m.size(), 0);
+ m.insert(4);
+ ASSERT_EQ(m.size(), 1);
+ for (int i = 0; i < 1000; ++i)
+ {
+ m.insert(80 % (i + 1));
+ ASSERT_EQ(m.size(), std::min<int>(10, i + 2));
+ }
+}
diff --git a/tests/unit_tests/uri.cpp b/tests/unit_tests/uri.cpp
index df1dbc130..04d935751 100644
--- a/tests/unit_tests/uri.cpp
+++ b/tests/unit_tests/uri.cpp
@@ -144,9 +144,7 @@ TEST(uri, bad_payment_id)
TEST(uri, short_payment_id)
{
- PARSE_URI("monero:" TEST_ADDRESS"?tx_payment_id=1234567890123456", true);
- ASSERT_EQ(address, TEST_ADDRESS);
- ASSERT_EQ(payment_id, "1234567890123456");
+ PARSE_URI("monero:" TEST_ADDRESS"?tx_payment_id=1234567890123456", false);
}
TEST(uri, long_payment_id)