Merge pull request #6273

0f78b06e Various improvements to the ZMQ JSON-RPC handling: (Lee Clagett)
This commit is contained in:
Alexander Blair 2020-03-12 01:13:48 -07:00
commit 820ab9fdea
No known key found for this signature in database
GPG key ID: C64552D877C32479
12 changed files with 832 additions and 1029 deletions

View file

@ -850,6 +850,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;

View file

@ -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));