aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core_proxy/core_proxy.h3
-rw-r--r--tests/core_tests/bulletproofs.cpp1
-rw-r--r--tests/core_tests/multisig.cpp2
-rw-r--r--tests/core_tests/rct.cpp1
-rw-r--r--tests/core_tests/v2_tests.cpp1
-rwxr-xr-xtests/functional_tests/blockchain.py5
-rw-r--r--tests/functional_tests/make_test_signature.cc22
-rwxr-xr-xtests/functional_tests/rpc_payment.py40
-rwxr-xr-xtests/functional_tests/transfer.py7
-rw-r--r--tests/unit_tests/bulletproofs.cpp9
-rw-r--r--tests/unit_tests/epee_utils.cpp12
-rw-r--r--tests/unit_tests/json_serialization.cpp47
-rw-r--r--tests/unit_tests/mul_div.cpp2
-rw-r--r--tests/unit_tests/net.cpp433
-rw-r--r--tests/unit_tests/node_server.cpp3
-rw-r--r--tests/unit_tests/test_tx_utils.cpp2
-rw-r--r--tests/unit_tests/wipeable_string.cpp1
17 files changed, 517 insertions, 74 deletions
diff --git a/tests/core_proxy/core_proxy.h b/tests/core_proxy/core_proxy.h
index 8732c85cc..aad1bc962 100644
--- a/tests/core_proxy/core_proxy.h
+++ b/tests/core_proxy/core_proxy.h
@@ -73,7 +73,6 @@ namespace tests
bool init(const boost::program_options::variables_map& vm);
bool deinit(){return true;}
bool get_short_chain_history(std::list<crypto::hash>& ids);
- bool get_stat_info(cryptonote::core_stat_info& st_inf){return true;}
bool have_block(const crypto::hash& id);
void get_blockchain_top(uint64_t& height, crypto::hash& top_id);
bool handle_incoming_tx(const cryptonote::tx_blob_entry& tx_blob, cryptonote::tx_verification_context& tvc, cryptonote::relay_method tx_relay, bool relayed);
@@ -110,5 +109,7 @@ namespace tests
bool pad_transactions() const { return false; }
uint32_t get_blockchain_pruning_seed() const { return 0; }
bool prune_blockchain(uint32_t pruning_seed) const { return true; }
+ bool get_txpool_complement(const std::vector<crypto::hash> &hashes, std::vector<cryptonote::blobdata> &txes) { return false; }
+ bool get_pool_transaction_hashes(std::vector<crypto::hash>& txs, bool include_unrelayed_txes = true) const { return false; }
};
}
diff --git a/tests/core_tests/bulletproofs.cpp b/tests/core_tests/bulletproofs.cpp
index fd3f5114b..0a5b98605 100644
--- a/tests/core_tests/bulletproofs.cpp
+++ b/tests/core_tests/bulletproofs.cpp
@@ -64,7 +64,6 @@ bool gen_bp_tx_validation_base::generate_with(std::vector<test_event_entry>& eve
false, "Failed to generate block");
events.push_back(blocks[n]);
prev_block = blocks + n;
- LOG_PRINT_L0("Initial miner tx " << n << ": " << obj_to_json_str(blocks[n].miner_tx));
}
// rewind
diff --git a/tests/core_tests/multisig.cpp b/tests/core_tests/multisig.cpp
index e0c90423d..ba6e2d270 100644
--- a/tests/core_tests/multisig.cpp
+++ b/tests/core_tests/multisig.cpp
@@ -180,8 +180,6 @@ bool gen_multisig_tx_validation_base::generate_with(std::vector<test_event_entry
false, "Failed to generate block");
events.push_back(blocks[n]);
prev_block = blocks + n;
- LOG_PRINT_L0("Initial miner tx " << n << ": " << obj_to_json_str(blocks[n].miner_tx));
- LOG_PRINT_L0("in block: " << obj_to_json_str(blocks[n]));
}
// rewind
diff --git a/tests/core_tests/rct.cpp b/tests/core_tests/rct.cpp
index dc77e408f..23638f62d 100644
--- a/tests/core_tests/rct.cpp
+++ b/tests/core_tests/rct.cpp
@@ -63,7 +63,6 @@ bool gen_rct_tx_validation_base::generate_with_full(std::vector<test_event_entry
false, "Failed to generate block");
events.push_back(blocks[n]);
prev_block = blocks + n;
- LOG_PRINT_L0("Initial miner tx " << n << ": " << obj_to_json_str(blocks[n].miner_tx));
}
// rewind
diff --git a/tests/core_tests/v2_tests.cpp b/tests/core_tests/v2_tests.cpp
index 8c2b51acf..d00d9b6f4 100644
--- a/tests/core_tests/v2_tests.cpp
+++ b/tests/core_tests/v2_tests.cpp
@@ -85,7 +85,6 @@ bool gen_v2_tx_validation_base::generate_with(std::vector<test_event_entry>& eve
tx_source_entry& src = sources.back();
src.amount = blocks[0].miner_tx.vout[out_idx[out_idx_idx]].amount;
- std::cout << "using " << print_money(src.amount) << " output at index " << out_idx[out_idx_idx] << std::endl;
for (int m = 0; m <= mixin; ++m) {
int idx;
if (is_valid_decomposed_amount(src.amount))
diff --git a/tests/functional_tests/blockchain.py b/tests/functional_tests/blockchain.py
index 78e0d8952..b8f8bac1a 100755
--- a/tests/functional_tests/blockchain.py
+++ b/tests/functional_tests/blockchain.py
@@ -203,10 +203,15 @@ class BlockchainTest():
res_sum = daemon.get_coinbase_tx_sum(i, 1)
res_header = daemon.getblockheaderbyheight(i)
assert res_sum.emission_amount == res_header.block_header.reward
+ assert res_sum.emission_amount_top64 == 0
+ assert res_sum.emission_amount == int(res_sum.wide_emission_amount, 16)
+ assert res_sum.fee_amount == int(res_sum.wide_fee_amount, 16)
res = daemon.get_coinbase_tx_sum(0, 1)
assert res.emission_amount == 17592186044415
+ assert res.emission_amount_top64 == 0
assert res.fee_amount == 0
+ assert res.fee_amount_top64 == 0
sum_blocks = height + nblocks - 1
res = daemon.get_coinbase_tx_sum(0, sum_blocks)
extrapolated = 17592186044415 + 17592186044415 * 2 * (sum_blocks - 1)
diff --git a/tests/functional_tests/make_test_signature.cc b/tests/functional_tests/make_test_signature.cc
index 789523de5..6ac1a6a86 100644
--- a/tests/functional_tests/make_test_signature.cc
+++ b/tests/functional_tests/make_test_signature.cc
@@ -33,9 +33,9 @@
int main(int argc, const char **argv)
{
TRY_ENTRY();
- if (argc > 2)
+ if (argc > 3)
{
- fprintf(stderr, "usage: %s <secret_key>\n", argv[0]);
+ fprintf(stderr, "usage: %s [<secret_key> [N]]\n", argv[0]);
return 1;
}
@@ -55,8 +55,22 @@ int main(int argc, const char **argv)
fprintf(stderr, "invalid secret key\n");
return 1;
}
- std::string signature = cryptonote::make_rpc_payment_signature(skey);
- printf("%s\n", signature.c_str());
+ uint32_t count = 1;
+ if (argc == 3)
+ {
+ int i = atoi(argv[2]);
+ if (i <= 0)
+ {
+ fprintf(stderr, "invalid count\n");
+ return 1;
+ }
+ count = (uint32_t)i;
+ }
+ while (count--)
+ {
+ std::string signature = cryptonote::make_rpc_payment_signature(skey);
+ printf("%s\n", signature.c_str());
+ }
return 0;
CATCH_ENTRY_L0("main()", 1);
}
diff --git a/tests/functional_tests/rpc_payment.py b/tests/functional_tests/rpc_payment.py
index 4c777ccd7..3bf995f0c 100755
--- a/tests/functional_tests/rpc_payment.py
+++ b/tests/functional_tests/rpc_payment.py
@@ -31,6 +31,7 @@
from __future__ import print_function
import subprocess
import os
+import time
"""Test daemon RPC payment calls
"""
@@ -43,6 +44,7 @@ class RPCPaymentTest():
self.make_test_signature = os.environ['MAKE_TEST_SIGNATURE']
assert len(self.make_test_signature) > 0
self.secret_key, self.public_key = self.get_keys()
+ self.signatures = []
self.reset()
self.test_access_tracking()
self.test_access_mining()
@@ -56,8 +58,17 @@ class RPCPaymentTest():
assert len(fields) == 2
return fields
+ def refill_signatures(self):
+ signatures = subprocess.check_output([self.make_test_signature, self.secret_key, '256']).decode('utf-8')
+ for line in signatures.split():
+ self.signatures.append(line.rstrip())
+
def get_signature(self):
- return subprocess.check_output([self.make_test_signature, self.secret_key]).decode('utf-8').rstrip()
+ if len(self.signatures) == 0:
+ self.refill_signatures()
+ s = self.signatures[0]
+ self.signatures = self.signatures[1:]
+ return s
def reset(self):
print('Resetting blockchain')
@@ -143,6 +154,7 @@ class RPCPaymentTest():
found_valid = 0
found_invalid = 0
last_credits = 0
+ loop_time = time.time()
while found_valid == 0 or found_invalid == 0:
nonce += 1
try:
@@ -152,10 +164,17 @@ class RPCPaymentTest():
except Exception as e:
found_invalid += 1
res = daemon.rpc_access_info(client = self.get_signature())
+ cookie = res.cookie
+ loop_time = time.time()
assert res.credits < last_credits or res.credits == 0
assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails
last_credits = res.credits
+ if time.time() >= loop_time + 10:
+ res = daemon.rpc_access_info(client = self.get_signature())
+ cookie = res.cookie
+ loop_time = time.time()
+
# we should now have 1 valid nonce, and a number of bad ones
res = daemon.rpc_access_info(client = self.get_signature())
assert len(res.hashing_blob) > 39
@@ -176,6 +195,7 @@ class RPCPaymentTest():
assert e.nonces_dupe == 0
# Try random nonces till we find one that's valid so we get a load of credits
+ loop_time = time.time()
while last_credits == 0:
nonce += 1
try:
@@ -186,6 +206,10 @@ class RPCPaymentTest():
except:
found_invalid += 1
assert nonce < 1000 # can't find a valid none -> the RPC probably fails
+ if time.time() >= loop_time + 10:
+ res = daemon.rpc_access_info(client = self.get_signature())
+ cookie = res.cookie
+ loop_time = time.time()
# we should now have at least 5000
res = daemon.rpc_access_info(client = self.get_signature())
@@ -208,6 +232,7 @@ class RPCPaymentTest():
res = daemon.rpc_access_info(client = self.get_signature())
cookie = res.cookie
old_cookie = cookie # we keep that so can submit a stale later
+ loop_time = time.time()
while True:
nonce += 1
try:
@@ -218,6 +243,11 @@ class RPCPaymentTest():
found_invalid += 1
assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails
+ if time.time() >= loop_time + 10:
+ res = daemon.rpc_access_info(client = self.get_signature())
+ cookie = res.cookie
+ loop_time = time.time()
+
res = daemon.rpc_access_data()
assert len(res.entries) > 0
e = [x for x in res.entries if x['client'] == self.public_key]
@@ -247,14 +277,17 @@ class RPCPaymentTest():
# find stales without updating cookie, one within 5 seconds (accepted), one later (rejected)
res = daemon.rpc_access_info(client = self.get_signature())
+ cookie = res.cookie # let the daemon update its timestamp, but use old cookie
found_close_stale = 0
found_late_stale = 0
+ loop_time = time.time()
while found_close_stale == 0 or found_late_stale == 0:
nonce += 1
try:
res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature())
found_close_stale += 1
found_valid += 1
+ time.sleep(15) # now we've got an early stale, wait till they become late stales
except Exception as e:
#if e[0]['error']['code'] == -18: # stale
if "'code': -18" in str(e): # stale (ugly version, but also works with python 3)
@@ -263,6 +296,11 @@ class RPCPaymentTest():
found_invalid += 1
assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails
+ if time.time() >= loop_time + 10:
+ res = daemon.rpc_access_info(client = self.get_signature())
+ # cookie = res.cookie # let the daemon update its timestamp, but use old cookie
+ loop_time = time.time()
+
res = daemon.rpc_access_data()
assert len(res.entries) > 0
e = [x for x in res.entries if x['client'] == self.public_key]
diff --git a/tests/functional_tests/transfer.py b/tests/functional_tests/transfer.py
index 0c942f48b..c3d71aa9c 100755
--- a/tests/functional_tests/transfer.py
+++ b/tests/functional_tests/transfer.py
@@ -169,7 +169,7 @@ class TransferTest():
assert e.subaddr_indices == [{'major': 0, 'minor': 0}]
assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
assert e.double_spend_seen == False
- assert e.confirmations == 0
+ assert not 'confirmations' in e or e.confirmations == 0
running_balances[0] -= 1000000000000 + fee
@@ -256,7 +256,6 @@ class TransferTest():
assert res.too_big == False
assert res.overspend == False
assert res.fee_too_low == False
- assert res.not_rct == False
self.wallet[0].refresh()
@@ -282,7 +281,7 @@ class TransferTest():
assert e.subaddr_indices == [{'major': 0, 'minor': 0}]
assert e.address == '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW'
assert e.double_spend_seen == False
- assert e.confirmations == 0
+ assert not 'confirmations' in e or e.confirmations == 0
assert e.amount == amount
assert e.fee == fee
@@ -598,7 +597,6 @@ class TransferTest():
assert res.too_big == False
assert res.overspend == False
assert res.fee_too_low == False
- assert res.not_rct == False
res = daemon.get_transactions([txes[0][0]])
assert len(res.txs) >= 1
@@ -615,7 +613,6 @@ class TransferTest():
assert res.too_big == False
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]])
diff --git a/tests/unit_tests/bulletproofs.cpp b/tests/unit_tests/bulletproofs.cpp
index 760769551..a73b80848 100644
--- a/tests/unit_tests/bulletproofs.cpp
+++ b/tests/unit_tests/bulletproofs.cpp
@@ -179,15 +179,6 @@ TEST(bulletproofs, invalid_31)
ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
}
-TEST(bulletproofs, invalid_gamma_0)
-{
- rct::key invalid_amount = rct::zero();
- invalid_amount[8] = 1;
- rct::key gamma = rct::zero();
- rct::Bulletproof proof = bulletproof_PROVE(invalid_amount, gamma);
- ASSERT_FALSE(rct::bulletproof_VERIFY(proof));
-}
-
static const char * const torsion_elements[] =
{
"c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa",
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index 6f887afda..513c2227c 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -45,6 +45,7 @@
#include "boost/archive/portable_binary_iarchive.hpp"
#include "boost/archive/portable_binary_oarchive.hpp"
#include "byte_slice.h"
+#include "crypto/crypto.h"
#include "hex.h"
#include "net/net_utils_base.h"
#include "net/local_ip.h"
@@ -850,6 +851,17 @@ TEST(ToHex, Array)
);
}
+TEST(ToHex, ArrayFromPod)
+{
+ std::array<char, 64> expected{{'5', 'f', '2', 'b', '0', '1'}};
+ std::fill(expected.begin() + 6, expected.end(), '0');
+
+ EXPECT_EQ(
+ expected,
+ (epee::to_hex::array(crypto::ec_point{{0x5F, 0x2B, 0x01, 0x00}}))
+ );
+}
+
TEST(ToHex, Ostream)
{
std::stringstream out;
diff --git a/tests/unit_tests/json_serialization.cpp b/tests/unit_tests/json_serialization.cpp
index 53d9f84c7..6f98d854d 100644
--- a/tests/unit_tests/json_serialization.cpp
+++ b/tests/unit_tests/json_serialization.cpp
@@ -3,6 +3,8 @@
#include <boost/range/adaptor/indexed.hpp>
#include <gtest/gtest.h>
#include <rapidjson/document.h>
+#include <rapidjson/stringbuffer.h>
+#include <rapidjson/writer.h>
#include <vector>
#include "crypto/hash.h"
@@ -80,6 +82,27 @@ namespace
return tx;
}
+
+ template<typename T>
+ T test_json(const T& value)
+ {
+ rapidjson::StringBuffer buffer;
+ {
+ rapidjson::Writer<rapidjson::StringBuffer> dest{buffer};
+ cryptonote::json::toJsonValue(dest, value);
+ }
+
+ rapidjson::Document doc;
+ doc.Parse(buffer.GetString());
+ if (doc.HasParseError() || !doc.IsObject())
+ {
+ throw cryptonote::json::PARSE_FAIL();
+ }
+
+ T out{};
+ cryptonote::json::fromJsonValue(doc, out);
+ return out;
+ }
} // anonymous
TEST(JsonSerialization, MinerTransaction)
@@ -91,11 +114,7 @@ TEST(JsonSerialization, MinerTransaction)
crypto::hash tx_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(miner_tx, tx_hash));
- rapidjson::Document doc;
- cryptonote::json::toJsonValue(doc, miner_tx, doc);
-
- cryptonote::transaction miner_tx_copy;
- cryptonote::json::fromJsonValue(doc, miner_tx_copy);
+ cryptonote::transaction miner_tx_copy = test_json(miner_tx);
crypto::hash tx_copy_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(miner_tx_copy, tx_copy_hash));
@@ -126,11 +145,7 @@ TEST(JsonSerialization, RegularTransaction)
crypto::hash tx_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(tx, tx_hash));
- rapidjson::Document doc;
- cryptonote::json::toJsonValue(doc, tx, doc);
-
- cryptonote::transaction tx_copy;
- cryptonote::json::fromJsonValue(doc, tx_copy);
+ cryptonote::transaction tx_copy = test_json(tx);
crypto::hash tx_copy_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(tx_copy, tx_copy_hash));
@@ -161,11 +176,7 @@ TEST(JsonSerialization, RingctTransaction)
crypto::hash tx_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(tx, tx_hash));
- rapidjson::Document doc;
- cryptonote::json::toJsonValue(doc, tx, doc);
-
- cryptonote::transaction tx_copy;
- cryptonote::json::fromJsonValue(doc, tx_copy);
+ cryptonote::transaction tx_copy = test_json(tx);
crypto::hash tx_copy_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(tx_copy, tx_copy_hash));
@@ -196,11 +207,7 @@ TEST(JsonSerialization, BulletproofTransaction)
crypto::hash tx_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(tx, tx_hash));
- rapidjson::Document doc;
- cryptonote::json::toJsonValue(doc, tx, doc);
-
- cryptonote::transaction tx_copy;
- cryptonote::json::fromJsonValue(doc, tx_copy);
+ cryptonote::transaction tx_copy = test_json(tx);
crypto::hash tx_copy_hash{};
ASSERT_TRUE(cryptonote::get_transaction_hash(tx_copy, tx_copy_hash));
diff --git a/tests/unit_tests/mul_div.cpp b/tests/unit_tests/mul_div.cpp
index e3f7c34f3..c1a72ce51 100644
--- a/tests/unit_tests/mul_div.cpp
+++ b/tests/unit_tests/mul_div.cpp
@@ -82,7 +82,7 @@ namespace
lo = mul128(0x1111111111111111, 0x1111111111111111, &hi);
ASSERT_EQ(lo, 0x0fedcba987654321);
- ASSERT_EQ(hi, 0x0123456789abcdf0);;
+ ASSERT_EQ(hi, 0x0123456789abcdf0);
}
TEST(mul128_with_carry_1_only, multiplies_correctly)
diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp
index 262541bd2..36cb28ae0 100644
--- a/tests/unit_tests/net.cpp
+++ b/tests/unit_tests/net.cpp
@@ -53,8 +53,10 @@
#include <memory>
#include <type_traits>
+#include "crypto/crypto.h"
#include "net/dandelionpp.h"
#include "net/error.h"
+#include "net/i2p_address.h"
#include "net/net_utils_base.h"
#include "net/socks.h"
#include "net/socks_connect.h"
@@ -177,22 +179,33 @@ TEST(tor_address, valid)
EXPECT_FALSE(address2.less(*address1));
EXPECT_TRUE(address1->less(address2));
- address2 = MONERO_UNWRAP(net::tor_address::make(std::string{v3_onion} + ":", 65535));
-
- EXPECT_EQ(65535, address2.port());
- EXPECT_STREQ(v3_onion, address2.host_str());
- EXPECT_EQ(std::string{v3_onion} + ":65535", address2.str().c_str());
- EXPECT_TRUE(address2.is_blockable());
- EXPECT_FALSE(address2.equal(*address1));
- EXPECT_FALSE(address1->equal(address2));
- EXPECT_FALSE(address2 == *address1);
- EXPECT_FALSE(*address1 == address2);
- EXPECT_TRUE(address2 != *address1);
- EXPECT_TRUE(*address1 != address2);
- EXPECT_TRUE(address2.is_same_host(*address1));
- EXPECT_TRUE(address1->is_same_host(address2));
- EXPECT_FALSE(address2.less(*address1));
- EXPECT_TRUE(address1->less(address2));
+ net::tor_address address3 = MONERO_UNWRAP(net::tor_address::make(std::string{v3_onion} + ":", 65535));
+
+ EXPECT_EQ(65535, address3.port());
+ EXPECT_STREQ(v3_onion, address3.host_str());
+ EXPECT_EQ(std::string{v3_onion} + ":65535", address3.str().c_str());
+ EXPECT_TRUE(address3.is_blockable());
+ EXPECT_FALSE(address3.equal(*address1));
+ EXPECT_FALSE(address1->equal(address3));
+ EXPECT_FALSE(address3 == *address1);
+ EXPECT_FALSE(*address1 == address3);
+ EXPECT_TRUE(address3 != *address1);
+ EXPECT_TRUE(*address1 != address3);
+ EXPECT_TRUE(address3.is_same_host(*address1));
+ EXPECT_TRUE(address1->is_same_host(address3));
+ EXPECT_FALSE(address3.less(*address1));
+ EXPECT_TRUE(address1->less(address3));
+
+ EXPECT_FALSE(address3.equal(address2));
+ EXPECT_FALSE(address2.equal(address3));
+ EXPECT_FALSE(address3 == address2);
+ EXPECT_FALSE(address2 == address3);
+ EXPECT_TRUE(address3 != address2);
+ EXPECT_TRUE(address2 != address3);
+ EXPECT_FALSE(address3.is_same_host(address2));
+ EXPECT_FALSE(address2.is_same_host(address3));
+ EXPECT_TRUE(address3.less(address2));
+ EXPECT_FALSE(address2.less(address3));
}
TEST(tor_address, generic_network_address)
@@ -220,7 +233,7 @@ TEST(tor_address, generic_network_address)
namespace
{
- struct test_command
+ struct test_command_tor
{
net::tor_address tor;
@@ -234,7 +247,7 @@ TEST(tor_address, epee_serializev_v2)
{
std::string buffer{};
{
- test_command command{MONERO_UNWRAP(net::tor_address::make(v2_onion, 10))};
+ test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v2_onion, 10))};
EXPECT_FALSE(command.tor.is_unknown());
EXPECT_NE(net::tor_address{}, command.tor);
EXPECT_STREQ(v2_onion, command.tor.host_str());
@@ -245,7 +258,7 @@ TEST(tor_address, epee_serializev_v2)
EXPECT_TRUE(stg.store_to_binary(buffer));
}
- test_command command{};
+ test_command_tor command{};
{
EXPECT_TRUE(command.tor.is_unknown());
EXPECT_EQ(net::tor_address{}, command.tor);
@@ -271,7 +284,7 @@ TEST(tor_address, epee_serializev_v2)
EXPECT_EQ(std::strlen(v2_onion), host.size());
host.push_back('k');
- EXPECT_TRUE(stg.set_value("host", host, stg.open_section("tor", nullptr, false)));
+ EXPECT_TRUE(stg.set_value("host", std::move(host), stg.open_section("tor", nullptr, false)));
EXPECT_TRUE(command.load(stg)); // poor error reporting from `KV_SERIALIZE`
}
@@ -285,7 +298,7 @@ TEST(tor_address, epee_serializev_v3)
{
std::string buffer{};
{
- test_command command{MONERO_UNWRAP(net::tor_address::make(v3_onion, 10))};
+ test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v3_onion, 10))};
EXPECT_FALSE(command.tor.is_unknown());
EXPECT_NE(net::tor_address{}, command.tor);
EXPECT_STREQ(v3_onion, command.tor.host_str());
@@ -296,7 +309,7 @@ TEST(tor_address, epee_serializev_v3)
EXPECT_TRUE(stg.store_to_binary(buffer));
}
- test_command command{};
+ test_command_tor command{};
{
EXPECT_TRUE(command.tor.is_unknown());
EXPECT_EQ(net::tor_address{}, command.tor);
@@ -322,7 +335,7 @@ TEST(tor_address, epee_serializev_v3)
EXPECT_EQ(std::strlen(v3_onion), host.size());
host.push_back('k');
- EXPECT_TRUE(stg.set_value("host", host, stg.open_section("tor", nullptr, false)));
+ EXPECT_TRUE(stg.set_value("host", std::move(host), stg.open_section("tor", nullptr, false)));
EXPECT_TRUE(command.load(stg)); // poor error reporting from `KV_SERIALIZE`
}
@@ -336,7 +349,7 @@ TEST(tor_address, epee_serialize_unknown)
{
std::string buffer{};
{
- test_command command{net::tor_address::unknown()};
+ test_command_tor command{net::tor_address::unknown()};
EXPECT_TRUE(command.tor.is_unknown());
EXPECT_EQ(net::tor_address{}, command.tor);
EXPECT_STREQ(net::tor_address::unknown_str(), command.tor.host_str());
@@ -347,7 +360,7 @@ TEST(tor_address, epee_serialize_unknown)
EXPECT_TRUE(stg.store_to_binary(buffer));
}
- test_command command{};
+ test_command_tor command{};
{
EXPECT_TRUE(command.tor.is_unknown());
EXPECT_EQ(net::tor_address{}, command.tor);
@@ -373,7 +386,7 @@ TEST(tor_address, epee_serialize_unknown)
EXPECT_EQ(std::strlen(net::tor_address::unknown_str()), host.size());
host.push_back('k');
- EXPECT_TRUE(stg.set_value("host", host, stg.open_section("tor", nullptr, false)));
+ EXPECT_TRUE(stg.set_value("host", std::move(host), stg.open_section("tor", nullptr, false)));
EXPECT_TRUE(command.load(stg)); // poor error reporting from `KV_SERIALIZE`
}
@@ -513,6 +526,374 @@ TEST(get_network_address, onion)
EXPECT_EQ(net::error::invalid_port, address);
}
+namespace
+{
+ static constexpr const char b32_i2p[] =
+ "vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopn.b32.i2p";
+ static constexpr const char b32_i2p_2[] =
+ "xmrto2bturnore26xmrto2bturnore26xmrto2bturnore26xmr2.b32.i2p";
+}
+
+TEST(i2p_address, constants)
+{
+ static_assert(!net::i2p_address::is_local(), "bad is_local() response");
+ static_assert(!net::i2p_address::is_loopback(), "bad is_loopback() response");
+ static_assert(net::i2p_address::get_type_id() == epee::net_utils::address_type::i2p, "bad get_type_id() response");
+
+ EXPECT_FALSE(net::i2p_address::is_local());
+ EXPECT_FALSE(net::i2p_address::is_loopback());
+ EXPECT_EQ(epee::net_utils::address_type::i2p, net::i2p_address::get_type_id());
+ EXPECT_EQ(epee::net_utils::address_type::i2p, net::i2p_address::get_type_id());
+}
+
+TEST(i2p_address, invalid)
+{
+ EXPECT_TRUE(net::i2p_address::make("").has_error());
+ EXPECT_TRUE(net::i2p_address::make(":").has_error());
+ EXPECT_TRUE(net::i2p_address::make(".b32.i2p").has_error());
+ EXPECT_TRUE(net::i2p_address::make(".b32.i2p:").has_error());
+ EXPECT_TRUE(net::i2p_address::make(b32_i2p + 1).has_error());
+ EXPECT_TRUE(net::i2p_address::make(boost::string_ref{b32_i2p, sizeof(b32_i2p) - 2}).has_error());
+ EXPECT_TRUE(net::i2p_address::make(std::string{b32_i2p} + ":65536").has_error());
+ EXPECT_TRUE(net::i2p_address::make(std::string{b32_i2p} + ":-1").has_error());
+
+ std::string i2p{b32_i2p};
+ i2p.at(10) = 1;
+ EXPECT_TRUE(net::i2p_address::make(i2p).has_error());
+}
+
+TEST(i2p_address, unblockable_types)
+{
+ net::i2p_address i2p{};
+
+ ASSERT_NE(nullptr, i2p.host_str());
+ EXPECT_STREQ("<unknown i2p host>", i2p.host_str());
+ EXPECT_STREQ("<unknown i2p host>", i2p.str().c_str());
+ EXPECT_EQ(0u, i2p.port());
+ EXPECT_TRUE(i2p.is_unknown());
+ EXPECT_FALSE(i2p.is_local());
+ EXPECT_FALSE(i2p.is_loopback());
+ EXPECT_EQ(epee::net_utils::address_type::i2p, i2p.get_type_id());
+ EXPECT_EQ(epee::net_utils::zone::i2p, i2p.get_zone());
+
+ i2p = net::i2p_address::unknown();
+ ASSERT_NE(nullptr, i2p.host_str());
+ EXPECT_STREQ("<unknown i2p host>", i2p.host_str());
+ EXPECT_STREQ("<unknown i2p host>", i2p.str().c_str());
+ EXPECT_EQ(0u, i2p.port());
+ EXPECT_TRUE(i2p.is_unknown());
+ EXPECT_FALSE(i2p.is_local());
+ EXPECT_FALSE(i2p.is_loopback());
+ EXPECT_EQ(epee::net_utils::address_type::i2p, i2p.get_type_id());
+ EXPECT_EQ(epee::net_utils::zone::i2p, i2p.get_zone());
+
+ EXPECT_EQ(net::i2p_address{}, net::i2p_address::unknown());
+}
+
+TEST(i2p_address, valid)
+{
+ const auto address1 = net::i2p_address::make(b32_i2p);
+
+ ASSERT_TRUE(address1.has_value());
+ EXPECT_EQ(0u, address1->port());
+ EXPECT_STREQ(b32_i2p, address1->host_str());
+ EXPECT_STREQ(b32_i2p, address1->str().c_str());
+ EXPECT_TRUE(address1->is_blockable());
+
+ net::i2p_address address2{*address1};
+
+ EXPECT_EQ(0u, address2.port());
+ EXPECT_STREQ(b32_i2p, address2.host_str());
+ EXPECT_STREQ(b32_i2p, address2.str().c_str());
+ EXPECT_TRUE(address2.is_blockable());
+ EXPECT_TRUE(address2.equal(*address1));
+ EXPECT_TRUE(address1->equal(address2));
+ EXPECT_TRUE(address2 == *address1);
+ EXPECT_TRUE(*address1 == address2);
+ EXPECT_FALSE(address2 != *address1);
+ EXPECT_FALSE(*address1 != address2);
+ EXPECT_TRUE(address2.is_same_host(*address1));
+ EXPECT_TRUE(address1->is_same_host(address2));
+ EXPECT_FALSE(address2.less(*address1));
+ EXPECT_FALSE(address1->less(address2));
+
+ address2 = MONERO_UNWRAP(net::i2p_address::make(std::string{b32_i2p_2} + ":6545"));
+
+ EXPECT_EQ(6545, address2.port());
+ EXPECT_STREQ(b32_i2p_2, address2.host_str());
+ EXPECT_EQ(std::string{b32_i2p_2} + ":6545", address2.str().c_str());
+ EXPECT_TRUE(address2.is_blockable());
+ EXPECT_FALSE(address2.equal(*address1));
+ EXPECT_FALSE(address1->equal(address2));
+ EXPECT_FALSE(address2 == *address1);
+ EXPECT_FALSE(*address1 == address2);
+ EXPECT_TRUE(address2 != *address1);
+ EXPECT_TRUE(*address1 != address2);
+ EXPECT_FALSE(address2.is_same_host(*address1));
+ EXPECT_FALSE(address1->is_same_host(address2));
+ EXPECT_FALSE(address2.less(*address1));
+ EXPECT_TRUE(address1->less(address2));
+
+ net::i2p_address address3 = MONERO_UNWRAP(net::i2p_address::make(std::string{b32_i2p} + ":", 65535));
+
+ EXPECT_EQ(65535, address3.port());
+ EXPECT_STREQ(b32_i2p, address3.host_str());
+ EXPECT_EQ(std::string{b32_i2p} + ":65535", address3.str().c_str());
+ EXPECT_TRUE(address3.is_blockable());
+ EXPECT_FALSE(address3.equal(*address1));
+ EXPECT_FALSE(address1->equal(address3));
+ EXPECT_FALSE(address3 == *address1);
+ EXPECT_FALSE(*address1 == address3);
+ EXPECT_TRUE(address3 != *address1);
+ EXPECT_TRUE(*address1 != address3);
+ EXPECT_TRUE(address3.is_same_host(*address1));
+ EXPECT_TRUE(address1->is_same_host(address3));
+ EXPECT_FALSE(address3.less(*address1));
+ EXPECT_TRUE(address1->less(address3));
+
+ EXPECT_FALSE(address3.equal(address2));
+ EXPECT_FALSE(address2.equal(address3));
+ EXPECT_FALSE(address3 == address2);
+ EXPECT_FALSE(address2 == address3);
+ EXPECT_TRUE(address3 != address2);
+ EXPECT_TRUE(address2 != address3);
+ EXPECT_FALSE(address3.is_same_host(address2));
+ EXPECT_FALSE(address2.is_same_host(address3));
+ EXPECT_TRUE(address3.less(address2));
+ EXPECT_FALSE(address2.less(address3));
+}
+
+TEST(i2p_address, generic_network_address)
+{
+ const epee::net_utils::network_address i2p1{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 8080))};
+ const epee::net_utils::network_address i2p2{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 8080))};
+ const epee::net_utils::network_address ip{epee::net_utils::ipv4_network_address{100, 200}};
+
+ EXPECT_EQ(i2p1, i2p2);
+ EXPECT_NE(ip, i2p1);
+ EXPECT_LT(ip, i2p1);
+
+ EXPECT_STREQ(b32_i2p, i2p1.host_str().c_str());
+ EXPECT_EQ(std::string{b32_i2p} + ":8080", i2p1.str());
+ EXPECT_EQ(epee::net_utils::address_type::i2p, i2p1.get_type_id());
+ EXPECT_EQ(epee::net_utils::address_type::i2p, i2p2.get_type_id());
+ EXPECT_EQ(epee::net_utils::address_type::ipv4, ip.get_type_id());
+ EXPECT_EQ(epee::net_utils::zone::i2p, i2p1.get_zone());
+ EXPECT_EQ(epee::net_utils::zone::i2p, i2p2.get_zone());
+ EXPECT_EQ(epee::net_utils::zone::public_, ip.get_zone());
+ EXPECT_TRUE(i2p1.is_blockable());
+ EXPECT_TRUE(i2p2.is_blockable());
+ EXPECT_TRUE(ip.is_blockable());
+}
+
+namespace
+{
+ struct test_command_i2p
+ {
+ net::i2p_address i2p;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(i2p);
+ END_KV_SERIALIZE_MAP()
+ };
+}
+
+TEST(i2p_address, epee_serializev_b32)
+{
+ std::string buffer{};
+ {
+ test_command_i2p command{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 10))};
+ EXPECT_FALSE(command.i2p.is_unknown());
+ EXPECT_NE(net::i2p_address{}, command.i2p);
+ EXPECT_STREQ(b32_i2p, command.i2p.host_str());
+ EXPECT_EQ(10u, command.i2p.port());
+
+ epee::serialization::portable_storage stg{};
+ EXPECT_TRUE(command.store(stg));
+ EXPECT_TRUE(stg.store_to_binary(buffer));
+ }
+
+ test_command_i2p command{};
+ {
+ EXPECT_TRUE(command.i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, command.i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), command.i2p.host_str());
+ EXPECT_EQ(0u, command.i2p.port());
+
+ epee::serialization::portable_storage stg{};
+ EXPECT_TRUE(stg.load_from_binary(buffer));
+ EXPECT_TRUE(command.load(stg));
+ }
+ EXPECT_FALSE(command.i2p.is_unknown());
+ EXPECT_NE(net::i2p_address{}, command.i2p);
+ EXPECT_STREQ(b32_i2p, command.i2p.host_str());
+ EXPECT_EQ(10u, command.i2p.port());
+
+ // make sure that exceeding max buffer doesn't destroy i2p_address::_load
+ {
+ epee::serialization::portable_storage stg{};
+ stg.load_from_binary(buffer);
+
+ std::string host{};
+ ASSERT_TRUE(stg.get_value("host", host, stg.open_section("i2p", nullptr, false)));
+ EXPECT_EQ(std::strlen(b32_i2p), host.size());
+
+ host.push_back('k');
+ EXPECT_TRUE(stg.set_value("host", std::string{host}, stg.open_section("i2p", nullptr, false)));
+ EXPECT_TRUE(command.load(stg)); // poor error reporting from `KV_SERIALIZE`
+ }
+
+ EXPECT_TRUE(command.i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, command.i2p);
+ EXPECT_STRNE(b32_i2p, command.i2p.host_str());
+ EXPECT_EQ(0u, command.i2p.port());
+}
+
+TEST(i2p_address, epee_serialize_unknown)
+{
+ std::string buffer{};
+ {
+ test_command_i2p command{net::i2p_address::unknown()};
+ EXPECT_TRUE(command.i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, command.i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), command.i2p.host_str());
+ EXPECT_EQ(0u, command.i2p.port());
+
+ epee::serialization::portable_storage stg{};
+ EXPECT_TRUE(command.store(stg));
+ EXPECT_TRUE(stg.store_to_binary(buffer));
+ }
+
+ test_command_i2p command{};
+ {
+ EXPECT_TRUE(command.i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, command.i2p);
+ EXPECT_STRNE(b32_i2p, command.i2p.host_str());
+ EXPECT_EQ(0u, command.i2p.port());
+
+ epee::serialization::portable_storage stg{};
+ EXPECT_TRUE(stg.load_from_binary(buffer));
+ EXPECT_TRUE(command.load(stg));
+ }
+ EXPECT_TRUE(command.i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, command.i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), command.i2p.host_str());
+ EXPECT_EQ(0u, command.i2p.port());
+
+ // make sure that exceeding max buffer doesn't destroy i2p_address::_load
+ {
+ epee::serialization::portable_storage stg{};
+ stg.load_from_binary(buffer);
+
+ std::string host{};
+ ASSERT_TRUE(stg.get_value("host", host, stg.open_section("i2p", nullptr, false)));
+ EXPECT_EQ(std::strlen(net::i2p_address::unknown_str()), host.size());
+
+ host.push_back('k');
+ EXPECT_TRUE(stg.set_value("host", std::string{host}, stg.open_section("i2p", nullptr, false)));
+ EXPECT_TRUE(command.load(stg)); // poor error reporting from `KV_SERIALIZE`
+ }
+
+ EXPECT_TRUE(command.i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, command.i2p);
+ EXPECT_STRNE(b32_i2p, command.i2p.host_str());
+ EXPECT_EQ(0u, command.i2p.port());
+}
+
+TEST(i2p_address, boost_serialize_b32)
+{
+ std::string buffer{};
+ {
+ const net::i2p_address i2p = MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 10));
+ EXPECT_FALSE(i2p.is_unknown());
+ EXPECT_NE(net::i2p_address{}, i2p);
+ EXPECT_STREQ(b32_i2p, i2p.host_str());
+ EXPECT_EQ(10u, i2p.port());
+
+ std::ostringstream stream{};
+ {
+ boost::archive::portable_binary_oarchive archive{stream};
+ archive << i2p;
+ }
+ buffer = stream.str();
+ }
+
+ net::i2p_address i2p{};
+ {
+ EXPECT_TRUE(i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str());
+ EXPECT_EQ(0u, i2p.port());
+
+ std::istringstream stream{buffer};
+ boost::archive::portable_binary_iarchive archive{stream};
+ archive >> i2p;
+ }
+ EXPECT_FALSE(i2p.is_unknown());
+ EXPECT_NE(net::i2p_address{}, i2p);
+ EXPECT_STREQ(b32_i2p, i2p.host_str());
+ EXPECT_EQ(10u, i2p.port());
+}
+
+TEST(i2p_address, boost_serialize_unknown)
+{
+ std::string buffer{};
+ {
+ const net::i2p_address i2p{};
+ EXPECT_TRUE(i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address::unknown(), i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str());
+ EXPECT_EQ(0u, i2p.port());
+
+ std::ostringstream stream{};
+ {
+ boost::archive::portable_binary_oarchive archive{stream};
+ archive << i2p;
+ }
+ buffer = stream.str();
+ }
+
+ net::i2p_address i2p{};
+ {
+ EXPECT_TRUE(i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str());
+ EXPECT_EQ(0u, i2p.port());
+
+ std::istringstream stream{buffer};
+ boost::archive::portable_binary_iarchive archive{stream};
+ archive >> i2p;
+ }
+ EXPECT_TRUE(i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address::unknown(), i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str());
+ EXPECT_EQ(0u, i2p.port());
+}
+
+TEST(get_network_address, i2p)
+{
+ expect<epee::net_utils::network_address> address =
+ net::get_network_address("i2p", 0);
+ EXPECT_EQ(net::error::unsupported_address, address);
+
+ address = net::get_network_address(".b32.i2p", 0);
+ EXPECT_EQ(net::error::invalid_i2p_address, address);
+
+ address = net::get_network_address(b32_i2p, 1000);
+ ASSERT_TRUE(bool(address));
+ EXPECT_EQ(epee::net_utils::address_type::i2p, address->get_type_id());
+ EXPECT_STREQ(b32_i2p, address->host_str().c_str());
+ EXPECT_EQ(std::string{b32_i2p} + ":1000", address->str());
+
+ address = net::get_network_address(std::string{b32_i2p} + ":2000", 1000);
+ ASSERT_TRUE(bool(address));
+ EXPECT_EQ(epee::net_utils::address_type::i2p, address->get_type_id());
+ EXPECT_STREQ(b32_i2p, address->host_str().c_str());
+ EXPECT_EQ(std::string{b32_i2p} + ":2000", address->str());
+
+ address = net::get_network_address(std::string{b32_i2p} + ":65536", 1000);
+ EXPECT_EQ(net::error::invalid_port, address);
+}
TEST(get_network_address, ipv4)
{
diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp
index c92f70b97..b656c4858 100644
--- a/tests/unit_tests/node_server.cpp
+++ b/tests/unit_tests/node_server.cpp
@@ -54,7 +54,6 @@ public:
bool init(const boost::program_options::variables_map& vm) {return true ;}
bool deinit(){return true;}
bool get_short_chain_history(std::list<crypto::hash>& ids) const { return true; }
- bool get_stat_info(cryptonote::core_stat_info& st_inf) const {return true;}
bool have_block(const crypto::hash& id) const {return true;}
void get_blockchain_top(uint64_t& height, crypto::hash& top_id)const{height=0;top_id=crypto::null_hash;}
bool handle_incoming_tx(const cryptonote::tx_blob_entry& tx_blob, cryptonote::tx_verification_context& tvc, cryptonote::relay_method tx_relay, bool relayed) { return true; }
@@ -91,6 +90,8 @@ public:
bool prune_blockchain(uint32_t pruning_seed = 0) { return true; }
bool is_within_compiled_block_hash_area(uint64_t height) const { return false; }
bool has_block_weights(uint64_t height, uint64_t nblocks) const { return false; }
+ bool get_txpool_complement(const std::vector<crypto::hash> &hashes, std::vector<cryptonote::blobdata> &txes) { return false; }
+ bool get_pool_transaction_hashes(std::vector<crypto::hash>& txs, bool include_unrelayed_txes = true) const { return false; }
void stop() {}
};
diff --git a/tests/unit_tests/test_tx_utils.cpp b/tests/unit_tests/test_tx_utils.cpp
index d8d760b07..deb45594d 100644
--- a/tests/unit_tests/test_tx_utils.cpp
+++ b/tests/unit_tests/test_tx_utils.cpp
@@ -44,7 +44,7 @@ namespace
TEST(parse_tx_extra, handles_empty_extra)
{
- std::vector<uint8_t> extra;;
+ std::vector<uint8_t> extra;
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
ASSERT_TRUE(tx_extra_fields.empty());
diff --git a/tests/unit_tests/wipeable_string.cpp b/tests/unit_tests/wipeable_string.cpp
index 44e050c5c..9911bd6f4 100644
--- a/tests/unit_tests/wipeable_string.cpp
+++ b/tests/unit_tests/wipeable_string.cpp
@@ -182,6 +182,7 @@ TEST(wipeable_string, split)
ASSERT_TRUE(check_split(" foo bar baz ", {"foo", "bar", "baz"}));
ASSERT_TRUE(check_split(" foo bar baz", {"foo", "bar", "baz"}));
ASSERT_TRUE(check_split("foo bar baz ", {"foo", "bar", "baz"}));
+ ASSERT_TRUE(check_split("\tfoo\n bar\r\nbaz", {"foo", "bar", "baz"}));
}
TEST(wipeable_string, parse_hexstr)