aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/functional_tests/functional_tests_rpc.py33
-rwxr-xr-xtests/functional_tests/p2p.py168
-rw-r--r--tests/unit_tests/account.cpp34
-rw-r--r--tests/unit_tests/serialization.cpp40
4 files changed, 193 insertions, 82 deletions
diff --git a/tests/functional_tests/functional_tests_rpc.py b/tests/functional_tests/functional_tests_rpc.py
index 5f2a3d077..3be62c0ca 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 = ['address_book', 'bans', 'blockchain', 'cold_signing', 'daemon_info', 'get_output_distribution', 'integrated_address', 'mining', 'multisig', 'proofs', 'rpc_payment', 'sign_message', 'transfer', 'txpool', 'uri', 'validate_address', 'wallet']
+DEFAULT_TESTS = ['address_book', 'bans', 'blockchain', 'cold_signing', 'daemon_info', 'get_output_distribution', 'integrated_address', 'mining', 'multisig', 'p2p', 'proofs', 'rpc_payment', 'sign_message', 'transfer', 'txpool', 'uri', 'validate_address', 'wallet']
try:
python = sys.argv[1]
srcdir = sys.argv[2]
@@ -34,18 +34,32 @@ try:
except:
tests = DEFAULT_TESTS
-N_MONERODS = 2
-N_WALLETS = 4
+# a main offline monerod, does most of the tests
+# a restricted RPC monerod setup with RPC payment
+# two local online monerods connected to each other
+N_MONERODS = 4
+
+# 4 wallets connected to the main offline monerod
+# a wallet connected to the first local online monerod
+N_WALLETS = 5
+
WALLET_DIRECTORY = builddir + "/functional-tests-directory"
DIFFICULTY = 10
-monerod_base = [builddir + "/bin/monerod", "--regtest", "--fixed-difficulty", str(DIFFICULTY), "--offline", "--no-igd", "--p2p-bind-port", "monerod_p2p_port", "--rpc-bind-port", "monerod_rpc_port", "--zmq-rpc-bind-port", "monerod_zmq_port", "--non-interactive", "--disable-dns-checkpoints", "--check-updates", "disabled", "--rpc-ssl", "disabled", "--log-level", "1"]
+monerod_base = [builddir + "/bin/monerod", "--regtest", "--fixed-difficulty", str(DIFFICULTY), "--no-igd", "--p2p-bind-port", "monerod_p2p_port", "--rpc-bind-port", "monerod_rpc_port", "--zmq-rpc-bind-port", "monerod_zmq_port", "--non-interactive", "--disable-dns-checkpoints", "--check-updates", "disabled", "--rpc-ssl", "disabled", "--data-dir", "monerod_data_dir", "--log-level", "1"]
monerod_extra = [
- [],
- ["--rpc-payment-address", "44SKxxLQw929wRF6BA9paQ1EWFshNnKhXM3qz6Mo3JGDE2YG3xyzVutMStEicxbQGRfrYvAAYxH6Fe8rnD56EaNwUiqhcwR", "--rpc-payment-difficulty", str(DIFFICULTY), "--rpc-payment-credits", "5000", "--data-dir", builddir + "/functional-tests-directory/monerod1"],
+ ["--offline"],
+ ["--rpc-payment-address", "44SKxxLQw929wRF6BA9paQ1EWFshNnKhXM3qz6Mo3JGDE2YG3xyzVutMStEicxbQGRfrYvAAYxH6Fe8rnD56EaNwUiqhcwR", "--rpc-payment-difficulty", str(DIFFICULTY), "--rpc-payment-credits", "5000", "--offline"],
+ ["--add-exclusive-node", "127.0.0.1:18283"],
+ ["--add-exclusive-node", "127.0.0.1:18282"],
]
-wallet_base = [builddir + "/bin/monero-wallet-rpc", "--wallet-dir", WALLET_DIRECTORY, "--rpc-bind-port", "wallet_port", "--disable-rpc-login", "--rpc-ssl", "disabled", "--daemon-ssl", "disabled", "--daemon-port", "18180", "--log-level", "1"]
+wallet_base = [builddir + "/bin/monero-wallet-rpc", "--wallet-dir", WALLET_DIRECTORY, "--rpc-bind-port", "wallet_port", "--disable-rpc-login", "--rpc-ssl", "disabled", "--daemon-ssl", "disabled", "--log-level", "1"]
wallet_extra = [
+ ["--daemon-port", "18180"],
+ ["--daemon-port", "18180"],
+ ["--daemon-port", "18180"],
+ ["--daemon-port", "18180"],
+ ["--daemon-port", "18182"],
]
command_lines = []
@@ -54,7 +68,7 @@ outputs = []
ports = []
for i in range(N_MONERODS):
- command_lines.append([str(18180+i) if x == "monerod_rpc_port" else str(18280+i) if x == "monerod_p2p_port" else str(18380+i) if x == "monerod_zmq_port" else x for x in monerod_base])
+ command_lines.append([str(18180+i) if x == "monerod_rpc_port" else str(18280+i) if x == "monerod_p2p_port" else str(18380+i) if x == "monerod_zmq_port" else builddir + "/functional-tests-directory/monerod" + str(i) if x == "monerod_data_dir" else x for x in monerod_base])
if i < len(monerod_extra):
command_lines[-1] += monerod_extra[i]
outputs.append(open(builddir + '/tests/functional_tests/monerod' + str(i) + '.log', 'a+'))
@@ -109,6 +123,9 @@ if not all_open:
kill()
sys.exit(1)
+# online daemons need some time to connect to peers to be ready
+time.sleep(2)
+
PASS = []
FAIL = []
for test in tests:
diff --git a/tests/functional_tests/p2p.py b/tests/functional_tests/p2p.py
new file mode 100755
index 000000000..f36e9c0b1
--- /dev/null
+++ b/tests/functional_tests/p2p.py
@@ -0,0 +1,168 @@
+#!/usr/bin/env python3
+
+# Copyright (c) 2018 The Monero Project
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are
+# permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of
+# conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other
+# materials provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors may be
+# used to endorse or promote products derived from this software without specific
+# prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from __future__ import print_function
+import time
+
+"""Test daemon P2P
+"""
+
+from framework.daemon import Daemon
+from framework.wallet import Wallet
+
+class P2PTest():
+ def run_test(self):
+ self.reset()
+ self.create()
+ self.mine(80)
+ self.test_p2p_reorg()
+ self.test_p2p_tx_propagation()
+
+ def reset(self):
+ print('Resetting blockchain')
+ daemon = Daemon()
+ res = daemon.get_height()
+ daemon.pop_blocks(res.height - 1)
+ daemon.flush_txpool()
+
+ 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'
+ self.wallet = Wallet(idx = 4)
+ # 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)
+
+ def mine(self, blocks):
+ assert blocks >= 1
+
+ print("Generating", blocks, 'blocks')
+
+ daemon = Daemon(idx = 2)
+
+ # generate blocks
+ res_generateblocks = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', blocks)
+
+ def test_p2p_reorg(self):
+ print('Testing P2P reorg')
+ daemon2 = Daemon(idx = 2)
+ daemon3 = Daemon(idx = 3)
+
+ # give sync some time
+ time.sleep(1)
+
+ res = daemon2.get_info()
+ height = res.height
+ assert height > 0
+ top_block_hash = res.top_block_hash
+ assert len(top_block_hash) == 64
+
+ res = daemon3.get_info()
+ assert res.height == height
+ assert res.top_block_hash == top_block_hash
+
+ # disconnect daemons and mine separately on both
+ daemon2.out_peers(0)
+ daemon3.out_peers(0)
+
+ res = daemon2.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 2)
+ res = daemon3.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 3)
+
+ res = daemon2.get_info()
+ assert res.height == height + 2
+ daemon2_top_block_hash = res.top_block_hash
+ assert daemon2_top_block_hash != top_block_hash
+ res = daemon3.get_info()
+ assert res.height == height + 3
+ daemon3_top_block_hash = res.top_block_hash
+ assert daemon3_top_block_hash != top_block_hash
+ assert daemon3_top_block_hash != daemon2_top_block_hash
+
+ # reconnect, daemon2 will now switch to daemon3's chain
+ daemon2.out_peers(8)
+ daemon3.out_peers(8)
+ time.sleep(10)
+ res = daemon2.get_info()
+ assert res.height == height + 3
+ assert res.top_block_hash == daemon3_top_block_hash
+
+ # disconect, mine on daemon2 again more than daemon3
+ daemon2.out_peers(0)
+ daemon3.out_peers(0)
+
+ res = daemon2.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 3)
+ res = daemon3.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 2)
+
+ res = daemon2.get_info()
+ assert res.height == height + 6
+ daemon2_top_block_hash = res.top_block_hash
+ assert daemon2_top_block_hash != top_block_hash
+ res = daemon3.get_info()
+ assert res.height == height + 5
+ daemon3_top_block_hash = res.top_block_hash
+ assert daemon3_top_block_hash != top_block_hash
+ assert daemon3_top_block_hash != daemon2_top_block_hash
+
+ # reconnect, daemon3 will now switch to daemon2's chain
+ daemon2.out_peers(8)
+ daemon3.out_peers(8)
+ time.sleep(5)
+ res = daemon3.get_info()
+ assert res.height == height + 6
+ assert res.top_block_hash == daemon2_top_block_hash
+
+ def test_p2p_tx_propagation(self):
+ print('Testing P2P tx propagation')
+ daemon2 = Daemon(idx = 2)
+ daemon3 = Daemon(idx = 3)
+
+ for daemon in [daemon2, daemon3]:
+ res = daemon.get_transaction_pool_hashes()
+ assert not 'tx_hashes' in res or len(res.tx_hashes) == 0
+
+ self.wallet.refresh()
+ res = self.wallet.get_balance()
+
+ dst = {'address': '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'amount': 1000000000000}
+ res = self.wallet.transfer([dst])
+ assert len(res.tx_hash) == 32*2
+ txid = res.tx_hash
+
+ time.sleep(5)
+
+ for daemon in [daemon2, daemon3]:
+ res = daemon.get_transaction_pool_hashes()
+ assert len(res.tx_hashes) == 1
+ assert res.tx_hashes[0] == txid
+
+
+if __name__ == '__main__':
+ P2PTest().run_test()
diff --git a/tests/unit_tests/account.cpp b/tests/unit_tests/account.cpp
index 68bf4dce7..2ab2f893a 100644
--- a/tests/unit_tests/account.cpp
+++ b/tests/unit_tests/account.cpp
@@ -29,30 +29,14 @@
#include "gtest/gtest.h"
#include "cryptonote_basic/account.h"
-#include "ringct/rctOps.h"
-// Tests in-memory encryption of account secret keys
TEST(account, encrypt_keys)
{
- // Generate account keys and random multisig keys
cryptonote::keypair recovery_key = cryptonote::keypair::generate(hw::get_device("default"));
cryptonote::account_base account;
crypto::secret_key key = account.generate(recovery_key.sec);
-
- const size_t n_multisig = 4;
- std::vector<crypto::secret_key> multisig_keys;
- multisig_keys.reserve(n_multisig);
- multisig_keys.resize(0);
- for (size_t i = 0; i < n_multisig; ++i)
- {
- multisig_keys.push_back(rct::rct2sk(rct::skGen()));
- }
- ASSERT_TRUE(account.make_multisig(account.get_keys().m_view_secret_key, account.get_keys().m_spend_secret_key, account.get_keys().m_account_address.m_spend_public_key, multisig_keys));
-
const cryptonote::account_keys keys = account.get_keys();
- ASSERT_EQ(keys.m_multisig_keys.size(),n_multisig);
- // Encrypt and decrypt keys
ASSERT_EQ(account.get_keys().m_account_address, keys.m_account_address);
ASSERT_EQ(account.get_keys().m_spend_secret_key, keys.m_spend_secret_key);
ASSERT_EQ(account.get_keys().m_view_secret_key, keys.m_view_secret_key);
@@ -66,40 +50,22 @@ TEST(account, encrypt_keys)
ASSERT_EQ(account.get_keys().m_account_address, keys.m_account_address);
ASSERT_NE(account.get_keys().m_spend_secret_key, keys.m_spend_secret_key);
ASSERT_NE(account.get_keys().m_view_secret_key, keys.m_view_secret_key);
- ASSERT_NE(account.get_keys().m_multisig_keys, keys.m_multisig_keys);
account.decrypt_viewkey(chacha_key);
ASSERT_EQ(account.get_keys().m_account_address, keys.m_account_address);
ASSERT_NE(account.get_keys().m_spend_secret_key, keys.m_spend_secret_key);
ASSERT_EQ(account.get_keys().m_view_secret_key, keys.m_view_secret_key);
- ASSERT_NE(account.get_keys().m_multisig_keys, keys.m_multisig_keys);
account.encrypt_viewkey(chacha_key);
ASSERT_EQ(account.get_keys().m_account_address, keys.m_account_address);
ASSERT_NE(account.get_keys().m_spend_secret_key, keys.m_spend_secret_key);
ASSERT_NE(account.get_keys().m_view_secret_key, keys.m_view_secret_key);
- ASSERT_NE(account.get_keys().m_multisig_keys, keys.m_multisig_keys);
-
- account.decrypt_viewkey(chacha_key);
-
- ASSERT_EQ(account.get_keys().m_account_address, keys.m_account_address);
- ASSERT_NE(account.get_keys().m_spend_secret_key, keys.m_spend_secret_key);
- ASSERT_EQ(account.get_keys().m_view_secret_key, keys.m_view_secret_key);
- ASSERT_NE(account.get_keys().m_multisig_keys, keys.m_multisig_keys);
-
- account.encrypt_viewkey(chacha_key);
-
- ASSERT_EQ(account.get_keys().m_account_address, keys.m_account_address);
- ASSERT_NE(account.get_keys().m_spend_secret_key, keys.m_spend_secret_key);
- ASSERT_NE(account.get_keys().m_view_secret_key, keys.m_view_secret_key);
- ASSERT_NE(account.get_keys().m_multisig_keys, keys.m_multisig_keys);
account.decrypt_keys(chacha_key);
ASSERT_EQ(account.get_keys().m_account_address, keys.m_account_address);
ASSERT_EQ(account.get_keys().m_spend_secret_key, keys.m_spend_secret_key);
ASSERT_EQ(account.get_keys().m_view_secret_key, keys.m_view_secret_key);
- ASSERT_EQ(account.get_keys().m_multisig_keys, keys.m_multisig_keys);
}
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp
index ee0a7818c..e730f6867 100644
--- a/tests/unit_tests/serialization.cpp
+++ b/tests/unit_tests/serialization.cpp
@@ -616,46 +616,6 @@ TEST(Serialization, serializes_ringct_types)
ASSERT_EQ(bp0, bp1);
}
-TEST(Serialization, key_encryption_transition)
-{
- const cryptonote::network_type nettype = cryptonote::TESTNET;
- tools::wallet2 w(nettype);
- const boost::filesystem::path wallet_file = unit_test::data_dir / "wallet_9svHk1";
- const boost::filesystem::path key_file = unit_test::data_dir / "wallet_9svHk1.keys";
- const boost::filesystem::path temp_wallet_file = unit_test::data_dir / "wallet_9svHk1_temp";
- const boost::filesystem::path temp_key_file = unit_test::data_dir / "wallet_9svHk1_temp.keys";
- string password = "test";
- bool r = false;
-
- // Copy the original files for this test
- boost::filesystem::copy(wallet_file,temp_wallet_file);
- boost::filesystem::copy(key_file,temp_key_file);
-
- try
- {
- // Key transition
- w.load(temp_wallet_file.string(), password); // legacy decryption method
- ASSERT_TRUE(w.get_load_info().is_legacy_key_encryption);
- const crypto::secret_key view_secret_key = w.get_account().get_keys().m_view_secret_key;
-
- w.rewrite(temp_wallet_file.string(), password); // transition to new key format
-
- w.load(temp_wallet_file.string(), password); // new decryption method
- ASSERT_FALSE(w.get_load_info().is_legacy_key_encryption);
- ASSERT_EQ(w.get_account().get_keys().m_view_secret_key,view_secret_key);
-
- r = true;
- }
- catch (const exception& e)
- {}
-
- // Remove the temporary files
- boost::filesystem::remove(temp_wallet_file);
- boost::filesystem::remove(temp_key_file);
-
- ASSERT_TRUE(r);
-}
-
TEST(Serialization, portability_wallet)
{
const cryptonote::network_type nettype = cryptonote::TESTNET;