mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Normalize files containing unit test code:
Source files are split to place all unit test code into translation
units ending in .test.cpp with no other business logic in the same file,
and in directories named "test".
A new target is added to the SConstruct, invoked by:
scons count
This prints the total number of source code lines occupied by unit tests,
in rippled specific code and excluding library subtrees.
This commit is contained in:
@@ -154,96 +154,4 @@ to_packed (ProtocolVersion const& p)
|
||||
return (static_cast<std::uint32_t> (p.first) << 16) + p.second;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class BuildInfo_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void testVersion ()
|
||||
{
|
||||
testcase ("version");
|
||||
|
||||
beast::SemanticVersion v;
|
||||
|
||||
expect (v.parse (BuildInfo::getRawVersionString ()));
|
||||
}
|
||||
|
||||
|
||||
ProtocolVersion
|
||||
from_version (std::uint16_t major, std::uint16_t minor)
|
||||
{
|
||||
return ProtocolVersion (major, minor);
|
||||
}
|
||||
|
||||
void testValues ()
|
||||
{
|
||||
testcase ("comparison");
|
||||
|
||||
expect (from_version (1,2) == from_version (1,2));
|
||||
expect (from_version (3,4) >= from_version (3,4));
|
||||
expect (from_version (5,6) <= from_version (5,6));
|
||||
expect (from_version (7,8) > from_version (6,7));
|
||||
expect (from_version (7,8) < from_version (8,9));
|
||||
expect (from_version (65535,0) < from_version (65535,65535));
|
||||
expect (from_version (65535,65535) >= from_version (65535,65535));
|
||||
}
|
||||
|
||||
void testStringVersion ()
|
||||
{
|
||||
testcase ("string version");
|
||||
|
||||
for (std::uint16_t major = 0; major < 8; major++)
|
||||
{
|
||||
for (std::uint16_t minor = 0; minor < 8; minor++)
|
||||
{
|
||||
expect (to_string (from_version (major, minor)) ==
|
||||
std::to_string (major) + "." + std::to_string (minor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testVersionPacking ()
|
||||
{
|
||||
testcase ("version packing");
|
||||
|
||||
expect (to_packed (from_version (0, 0)) == 0);
|
||||
expect (to_packed (from_version (0, 1)) == 1);
|
||||
expect (to_packed (from_version (0, 255)) == 255);
|
||||
expect (to_packed (from_version (0, 65535)) == 65535);
|
||||
|
||||
expect (to_packed (from_version (1, 0)) == 65536);
|
||||
expect (to_packed (from_version (1, 1)) == 65537);
|
||||
expect (to_packed (from_version (1, 255)) == 65791);
|
||||
expect (to_packed (from_version (1, 65535)) == 131071);
|
||||
|
||||
expect (to_packed (from_version (255, 0)) == 16711680);
|
||||
expect (to_packed (from_version (255, 1)) == 16711681);
|
||||
expect (to_packed (from_version (255, 255)) == 16711935);
|
||||
expect (to_packed (from_version (255, 65535)) == 16777215);
|
||||
|
||||
expect (to_packed (from_version (65535, 0)) == 4294901760);
|
||||
expect (to_packed (from_version (65535, 1)) == 4294901761);
|
||||
expect (to_packed (from_version (65535, 255)) == 4294902015);
|
||||
expect (to_packed (from_version (65535, 65535)) == 4294967295);
|
||||
}
|
||||
|
||||
void run ()
|
||||
{
|
||||
testVersion ();
|
||||
testValues ();
|
||||
testStringVersion ();
|
||||
testVersionPacking ();
|
||||
|
||||
auto const current_protocol = BuildInfo::getCurrentProtocol ();
|
||||
auto const minimum_protocol = BuildInfo::getMinimumProtocol ();
|
||||
|
||||
expect (current_protocol >= minimum_protocol);
|
||||
|
||||
log << " Ripple Version: " << BuildInfo::getVersionString();
|
||||
log << " Protocol Version: " << to_string (current_protocol);
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(BuildInfo,ripple_data,ripple);
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -1,493 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/UnorderedContainers.h>
|
||||
#include <ripple/protocol/Book.h>
|
||||
#include <ripple/protocol/Issue.h>
|
||||
#include <beast/unit_test/suite.h>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <typeinfo>
|
||||
#include <unordered_set>
|
||||
|
||||
#if BEAST_MSVC
|
||||
# define STL_SET_HAS_EMPLACE 1
|
||||
#else
|
||||
# define STL_SET_HAS_EMPLACE 0
|
||||
#endif
|
||||
|
||||
#ifndef RIPPLE_ASSETS_ENABLE_STD_HASH
|
||||
# if BEAST_MAC || BEAST_IOS
|
||||
# define RIPPLE_ASSETS_ENABLE_STD_HASH 0
|
||||
# else
|
||||
# define RIPPLE_ASSETS_ENABLE_STD_HASH 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class Issue_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
// Comparison, hash tests for uint60 (via base_uint)
|
||||
template <typename Unsigned>
|
||||
void testUnsigned ()
|
||||
{
|
||||
Unsigned const u1 (1);
|
||||
Unsigned const u2 (2);
|
||||
Unsigned const u3 (3);
|
||||
|
||||
expect (u1 != u2);
|
||||
expect (u1 < u2);
|
||||
expect (u1 <= u2);
|
||||
expect (u2 <= u2);
|
||||
expect (u2 == u2);
|
||||
expect (u2 >= u2);
|
||||
expect (u3 >= u2);
|
||||
expect (u3 > u2);
|
||||
|
||||
std::hash <Unsigned> hash;
|
||||
|
||||
expect (hash (u1) == hash (u1));
|
||||
expect (hash (u2) == hash (u2));
|
||||
expect (hash (u3) == hash (u3));
|
||||
expect (hash (u1) != hash (u2));
|
||||
expect (hash (u1) != hash (u3));
|
||||
expect (hash (u2) != hash (u3));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
// Comparison, hash tests for IssueType
|
||||
template <class Issue>
|
||||
void testIssueType ()
|
||||
{
|
||||
Currency const c1 (1); Account const i1 (1);
|
||||
Currency const c2 (2); Account const i2 (2);
|
||||
Currency const c3 (3); Account const i3 (3);
|
||||
|
||||
expect (Issue (c1, i1) != Issue (c2, i1));
|
||||
expect (Issue (c1, i1) < Issue (c2, i1));
|
||||
expect (Issue (c1, i1) <= Issue (c2, i1));
|
||||
expect (Issue (c2, i1) <= Issue (c2, i1));
|
||||
expect (Issue (c2, i1) == Issue (c2, i1));
|
||||
expect (Issue (c2, i1) >= Issue (c2, i1));
|
||||
expect (Issue (c3, i1) >= Issue (c2, i1));
|
||||
expect (Issue (c3, i1) > Issue (c2, i1));
|
||||
expect (Issue (c1, i1) != Issue (c1, i2));
|
||||
expect (Issue (c1, i1) < Issue (c1, i2));
|
||||
expect (Issue (c1, i1) <= Issue (c1, i2));
|
||||
expect (Issue (c1, i2) <= Issue (c1, i2));
|
||||
expect (Issue (c1, i2) == Issue (c1, i2));
|
||||
expect (Issue (c1, i2) >= Issue (c1, i2));
|
||||
expect (Issue (c1, i3) >= Issue (c1, i2));
|
||||
expect (Issue (c1, i3) > Issue (c1, i2));
|
||||
|
||||
std::hash <Issue> hash;
|
||||
|
||||
expect (hash (Issue (c1, i1)) == hash (Issue (c1, i1)));
|
||||
expect (hash (Issue (c1, i2)) == hash (Issue (c1, i2)));
|
||||
expect (hash (Issue (c1, i3)) == hash (Issue (c1, i3)));
|
||||
expect (hash (Issue (c2, i1)) == hash (Issue (c2, i1)));
|
||||
expect (hash (Issue (c2, i2)) == hash (Issue (c2, i2)));
|
||||
expect (hash (Issue (c2, i3)) == hash (Issue (c2, i3)));
|
||||
expect (hash (Issue (c3, i1)) == hash (Issue (c3, i1)));
|
||||
expect (hash (Issue (c3, i2)) == hash (Issue (c3, i2)));
|
||||
expect (hash (Issue (c3, i3)) == hash (Issue (c3, i3)));
|
||||
expect (hash (Issue (c1, i1)) != hash (Issue (c1, i2)));
|
||||
expect (hash (Issue (c1, i1)) != hash (Issue (c1, i3)));
|
||||
expect (hash (Issue (c1, i1)) != hash (Issue (c2, i1)));
|
||||
expect (hash (Issue (c1, i1)) != hash (Issue (c2, i2)));
|
||||
expect (hash (Issue (c1, i1)) != hash (Issue (c2, i3)));
|
||||
expect (hash (Issue (c1, i1)) != hash (Issue (c3, i1)));
|
||||
expect (hash (Issue (c1, i1)) != hash (Issue (c3, i2)));
|
||||
expect (hash (Issue (c1, i1)) != hash (Issue (c3, i3)));
|
||||
}
|
||||
|
||||
template <class Set>
|
||||
void testIssueSet ()
|
||||
{
|
||||
Currency const c1 (1);
|
||||
Account const i1 (1);
|
||||
Currency const c2 (2);
|
||||
Account const i2 (2);
|
||||
IssueRef const a1 (c1, i1);
|
||||
IssueRef const a2 (c2, i2);
|
||||
|
||||
{
|
||||
Set c;
|
||||
|
||||
c.insert (a1);
|
||||
if (! expect (c.size () == 1)) return;
|
||||
c.insert (a2);
|
||||
if (! expect (c.size () == 2)) return;
|
||||
|
||||
if (! expect (c.erase (Issue (c1, i2)) == 0)) return;
|
||||
if (! expect (c.erase (Issue (c1, i1)) == 1)) return;
|
||||
if (! expect (c.erase (Issue (c2, i2)) == 1)) return;
|
||||
if (! expect (c.empty ())) return;
|
||||
}
|
||||
|
||||
{
|
||||
Set c;
|
||||
|
||||
c.insert (a1);
|
||||
if (! expect (c.size () == 1)) return;
|
||||
c.insert (a2);
|
||||
if (! expect (c.size () == 2)) return;
|
||||
|
||||
if (! expect (c.erase (IssueRef (c1, i2)) == 0)) return;
|
||||
if (! expect (c.erase (IssueRef (c1, i1)) == 1)) return;
|
||||
if (! expect (c.erase (IssueRef (c2, i2)) == 1)) return;
|
||||
if (! expect (c.empty ())) return;
|
||||
|
||||
#if STL_SET_HAS_EMPLACE
|
||||
c.emplace (c1, i1);
|
||||
if (! expect (c.size() == 1)) return;
|
||||
c.emplace (c2, i2);
|
||||
if (! expect (c.size() == 2)) return;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template <class Map>
|
||||
void testIssueMap ()
|
||||
{
|
||||
Currency const c1 (1);
|
||||
Account const i1 (1);
|
||||
Currency const c2 (2);
|
||||
Account const i2 (2);
|
||||
IssueRef const a1 (c1, i1);
|
||||
IssueRef const a2 (c2, i2);
|
||||
|
||||
{
|
||||
Map c;
|
||||
|
||||
c.insert (std::make_pair (a1, 1));
|
||||
if (! expect (c.size () == 1)) return;
|
||||
c.insert (std::make_pair (a2, 2));
|
||||
if (! expect (c.size () == 2)) return;
|
||||
|
||||
if (! expect (c.erase (Issue (c1, i2)) == 0)) return;
|
||||
if (! expect (c.erase (Issue (c1, i1)) == 1)) return;
|
||||
if (! expect (c.erase (Issue (c2, i2)) == 1)) return;
|
||||
if (! expect (c.empty ())) return;
|
||||
}
|
||||
|
||||
{
|
||||
Map c;
|
||||
|
||||
c.insert (std::make_pair (a1, 1));
|
||||
if (! expect (c.size () == 1)) return;
|
||||
c.insert (std::make_pair (a2, 2));
|
||||
if (! expect (c.size () == 2)) return;
|
||||
|
||||
if (! expect (c.erase (IssueRef (c1, i2)) == 0)) return;
|
||||
if (! expect (c.erase (IssueRef (c1, i1)) == 1)) return;
|
||||
if (! expect (c.erase (IssueRef (c2, i2)) == 1)) return;
|
||||
if (! expect (c.empty ())) return;
|
||||
}
|
||||
}
|
||||
|
||||
void testIssueSets ()
|
||||
{
|
||||
testcase ("std::set <Issue>");
|
||||
testIssueSet <std::set <Issue>> ();
|
||||
|
||||
testcase ("std::set <IssueRef>");
|
||||
testIssueSet <std::set <IssueRef>> ();
|
||||
|
||||
#if RIPPLE_ASSETS_ENABLE_STD_HASH
|
||||
testcase ("std::unordered_set <Issue>");
|
||||
testIssueSet <std::unordered_set <Issue>> ();
|
||||
|
||||
testcase ("std::unordered_set <IssueRef>");
|
||||
testIssueSet <std::unordered_set <IssueRef>> ();
|
||||
#endif
|
||||
|
||||
testcase ("hash_set <Issue>");
|
||||
testIssueSet <hash_set <Issue>> ();
|
||||
|
||||
testcase ("hash_set <IssueRef>");
|
||||
testIssueSet <hash_set <IssueRef>> ();
|
||||
}
|
||||
|
||||
void testIssueMaps ()
|
||||
{
|
||||
testcase ("std::map <Issue, int>");
|
||||
testIssueMap <std::map <Issue, int>> ();
|
||||
|
||||
testcase ("std::map <IssueRef, int>");
|
||||
testIssueMap <std::map <IssueRef, int>> ();
|
||||
|
||||
#if RIPPLE_ASSETS_ENABLE_STD_HASH
|
||||
testcase ("std::unordered_map <Issue, int>");
|
||||
testIssueMap <std::unordered_map <Issue, int>> ();
|
||||
|
||||
testcase ("std::unordered_map <IssueRef, int>");
|
||||
testIssueMap <std::unordered_map <IssueRef, int>> ();
|
||||
|
||||
testcase ("hash_map <Issue, int>");
|
||||
testIssueMap <hash_map <Issue, int>> ();
|
||||
|
||||
testcase ("hash_map <IssueRef, int>");
|
||||
testIssueMap <hash_map <IssueRef, int>> ();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
// Comparison, hash tests for BookType
|
||||
template <class Book>
|
||||
void testBook ()
|
||||
{
|
||||
Currency const c1 (1); Account const i1 (1);
|
||||
Currency const c2 (2); Account const i2 (2);
|
||||
Currency const c3 (3); Account const i3 (3);
|
||||
|
||||
Issue a1 (c1, i1);
|
||||
Issue a2 (c1, i2);
|
||||
Issue a3 (c2, i2);
|
||||
Issue a4 (c3, i2);
|
||||
|
||||
expect (Book (a1, a2) != Book (a2, a3));
|
||||
expect (Book (a1, a2) < Book (a2, a3));
|
||||
expect (Book (a1, a2) <= Book (a2, a3));
|
||||
expect (Book (a2, a3) <= Book (a2, a3));
|
||||
expect (Book (a2, a3) == Book (a2, a3));
|
||||
expect (Book (a2, a3) >= Book (a2, a3));
|
||||
expect (Book (a3, a4) >= Book (a2, a3));
|
||||
expect (Book (a3, a4) > Book (a2, a3));
|
||||
|
||||
std::hash <Book> hash;
|
||||
|
||||
// log << std::hex << hash (Book (a1, a2));
|
||||
// log << std::hex << hash (Book (a1, a2));
|
||||
//
|
||||
// log << std::hex << hash (Book (a1, a3));
|
||||
// log << std::hex << hash (Book (a1, a3));
|
||||
//
|
||||
// log << std::hex << hash (Book (a1, a4));
|
||||
// log << std::hex << hash (Book (a1, a4));
|
||||
//
|
||||
// log << std::hex << hash (Book (a2, a3));
|
||||
// log << std::hex << hash (Book (a2, a3));
|
||||
//
|
||||
// log << std::hex << hash (Book (a2, a4));
|
||||
// log << std::hex << hash (Book (a2, a4));
|
||||
//
|
||||
// log << std::hex << hash (Book (a3, a4));
|
||||
// log << std::hex << hash (Book (a3, a4));
|
||||
|
||||
expect (hash (Book (a1, a2)) == hash (Book (a1, a2)));
|
||||
expect (hash (Book (a1, a3)) == hash (Book (a1, a3)));
|
||||
expect (hash (Book (a1, a4)) == hash (Book (a1, a4)));
|
||||
expect (hash (Book (a2, a3)) == hash (Book (a2, a3)));
|
||||
expect (hash (Book (a2, a4)) == hash (Book (a2, a4)));
|
||||
expect (hash (Book (a3, a4)) == hash (Book (a3, a4)));
|
||||
|
||||
expect (hash (Book (a1, a2)) != hash (Book (a1, a3)));
|
||||
expect (hash (Book (a1, a2)) != hash (Book (a1, a4)));
|
||||
expect (hash (Book (a1, a2)) != hash (Book (a2, a3)));
|
||||
expect (hash (Book (a1, a2)) != hash (Book (a2, a4)));
|
||||
expect (hash (Book (a1, a2)) != hash (Book (a3, a4)));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
template <class Set>
|
||||
void testBookSet ()
|
||||
{
|
||||
Currency const c1 (1);
|
||||
Account const i1 (1);
|
||||
Currency const c2 (2);
|
||||
Account const i2 (2);
|
||||
IssueRef const a1 (c1, i1);
|
||||
IssueRef const a2 (c2, i2);
|
||||
BookRef const b1 (a1, a2);
|
||||
BookRef const b2 (a2, a1);
|
||||
|
||||
{
|
||||
Set c;
|
||||
|
||||
c.insert (b1);
|
||||
if (! expect (c.size () == 1)) return;
|
||||
c.insert (b2);
|
||||
if (! expect (c.size () == 2)) return;
|
||||
|
||||
if (! expect (c.erase (Book (a1, a1)) == 0)) return;
|
||||
if (! expect (c.erase (Book (a1, a2)) == 1)) return;
|
||||
if (! expect (c.erase (Book (a2, a1)) == 1)) return;
|
||||
if (! expect (c.empty ())) return;
|
||||
}
|
||||
|
||||
{
|
||||
Set c;
|
||||
|
||||
c.insert (b1);
|
||||
if (! expect (c.size () == 1)) return;
|
||||
c.insert (b2);
|
||||
if (! expect (c.size () == 2)) return;
|
||||
|
||||
if (! expect (c.erase (BookRef (a1, a1)) == 0)) return;
|
||||
if (! expect (c.erase (BookRef (a1, a2)) == 1)) return;
|
||||
if (! expect (c.erase (BookRef (a2, a1)) == 1)) return;
|
||||
if (! expect (c.empty ())) return;
|
||||
|
||||
#if STL_SET_HAS_EMPLACE
|
||||
c.emplace (a1, a2);
|
||||
if (! expect (c.size() == 1)) return;
|
||||
c.emplace (a2, a1);
|
||||
if (! expect (c.size() == 2)) return;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template <class Map>
|
||||
void testBookMap ()
|
||||
{
|
||||
Currency const c1 (1);
|
||||
Account const i1 (1);
|
||||
Currency const c2 (2);
|
||||
Account const i2 (2);
|
||||
IssueRef const a1 (c1, i1);
|
||||
IssueRef const a2 (c2, i2);
|
||||
BookRef const b1 (a1, a2);
|
||||
BookRef const b2 (a2, a1);
|
||||
|
||||
//typename Map::value_type value_type;
|
||||
//std::pair <BookRef const, int> value_type;
|
||||
|
||||
{
|
||||
Map c;
|
||||
|
||||
//c.insert (value_type (b1, 1));
|
||||
c.insert (std::make_pair (b1, 1));
|
||||
if (! expect (c.size () == 1)) return;
|
||||
//c.insert (value_type (b2, 2));
|
||||
c.insert (std::make_pair (b2, 1));
|
||||
if (! expect (c.size () == 2)) return;
|
||||
|
||||
if (! expect (c.erase (Book (a1, a1)) == 0)) return;
|
||||
if (! expect (c.erase (Book (a1, a2)) == 1)) return;
|
||||
if (! expect (c.erase (Book (a2, a1)) == 1)) return;
|
||||
if (! expect (c.empty ())) return;
|
||||
}
|
||||
|
||||
{
|
||||
Map c;
|
||||
|
||||
//c.insert (value_type (b1, 1));
|
||||
c.insert (std::make_pair (b1, 1));
|
||||
if (! expect (c.size () == 1)) return;
|
||||
//c.insert (value_type (b2, 2));
|
||||
c.insert (std::make_pair (b2, 1));
|
||||
if (! expect (c.size () == 2)) return;
|
||||
|
||||
if (! expect (c.erase (BookRef (a1, a1)) == 0)) return;
|
||||
if (! expect (c.erase (BookRef (a1, a2)) == 1)) return;
|
||||
if (! expect (c.erase (BookRef (a2, a1)) == 1)) return;
|
||||
if (! expect (c.empty ())) return;
|
||||
}
|
||||
}
|
||||
|
||||
void testBookSets ()
|
||||
{
|
||||
testcase ("std::set <Book>");
|
||||
testBookSet <std::set <Book>> ();
|
||||
|
||||
testcase ("std::set <BookRef>");
|
||||
testBookSet <std::set <BookRef>> ();
|
||||
|
||||
#if RIPPLE_ASSETS_ENABLE_STD_HASH
|
||||
testcase ("std::unordered_set <Book>");
|
||||
testBookSet <std::unordered_set <Book>> ();
|
||||
|
||||
testcase ("std::unordered_set <BookRef>");
|
||||
testBookSet <std::unordered_set <BookRef>> ();
|
||||
#endif
|
||||
|
||||
testcase ("hash_set <Book>");
|
||||
testBookSet <hash_set <Book>> ();
|
||||
|
||||
testcase ("hash_set <BookRef>");
|
||||
testBookSet <hash_set <BookRef>> ();
|
||||
}
|
||||
|
||||
void testBookMaps ()
|
||||
{
|
||||
testcase ("std::map <Book, int>");
|
||||
testBookMap <std::map <Book, int>> ();
|
||||
|
||||
testcase ("std::map <BookRef, int>");
|
||||
testBookMap <std::map <BookRef, int>> ();
|
||||
|
||||
#if RIPPLE_ASSETS_ENABLE_STD_HASH
|
||||
testcase ("std::unordered_map <Book, int>");
|
||||
testBookMap <std::unordered_map <Book, int>> ();
|
||||
|
||||
testcase ("std::unordered_map <BookRef, int>");
|
||||
testBookMap <std::unordered_map <BookRef, int>> ();
|
||||
|
||||
testcase ("hash_map <Book, int>");
|
||||
testBookMap <hash_map <Book, int>> ();
|
||||
|
||||
testcase ("hash_map <BookRef, int>");
|
||||
testBookMap <hash_map <BookRef, int>> ();
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void run()
|
||||
{
|
||||
testcase ("Currency");
|
||||
testUnsigned <Currency> ();
|
||||
|
||||
testcase ("Account");
|
||||
testUnsigned <Account> ();
|
||||
|
||||
// ---
|
||||
|
||||
testcase ("Issue");
|
||||
testIssueType <Issue> ();
|
||||
|
||||
testcase ("IssueRef");
|
||||
testIssueType <IssueRef> ();
|
||||
|
||||
testIssueSets ();
|
||||
testIssueMaps ();
|
||||
|
||||
// ---
|
||||
|
||||
testcase ("Book");
|
||||
testBook <Book> ();
|
||||
|
||||
testcase ("BookRef");
|
||||
testBook <BookRef> ();
|
||||
|
||||
testBookSets ();
|
||||
testBookMaps ();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(Issue,types,ripple);
|
||||
|
||||
}
|
||||
@@ -868,115 +868,4 @@ RippleAddress RippleAddress::createSeedGeneric (std::string const& strText)
|
||||
return naNew;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class RippleAddress_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void run()
|
||||
{
|
||||
// Construct a seed.
|
||||
RippleAddress naSeed;
|
||||
|
||||
expect (naSeed.setSeedGeneric ("masterpassphrase"));
|
||||
expect (naSeed.humanSeed () == "snoPBrXtMeMyMHUVTgbuqAfg1SUTb", naSeed.humanSeed ());
|
||||
|
||||
// Create node public/private key pair
|
||||
RippleAddress naNodePublic = RippleAddress::createNodePublic (naSeed);
|
||||
RippleAddress naNodePrivate = RippleAddress::createNodePrivate (naSeed);
|
||||
|
||||
expect (naNodePublic.humanNodePublic () == "n94a1u4jAz288pZLtw6yFWVbi89YamiC6JBXPVUj5zmExe5fTVg9", naNodePublic.humanNodePublic ());
|
||||
expect (naNodePrivate.humanNodePrivate () == "pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe", naNodePrivate.humanNodePrivate ());
|
||||
|
||||
// Check node signing.
|
||||
Blob vucTextSrc = strCopy ("Hello, nurse!");
|
||||
uint256 uHash = Serializer::getSHA512Half (vucTextSrc);
|
||||
Blob vucTextSig;
|
||||
|
||||
naNodePrivate.signNodePrivate (uHash, vucTextSig);
|
||||
expect (naNodePublic.verifyNodePublic (uHash, vucTextSig, ECDSA::strict), "Verify failed.");
|
||||
|
||||
// Construct a public generator from the seed.
|
||||
RippleAddress generator = RippleAddress::createGeneratorPublic (naSeed);
|
||||
|
||||
expect (generator.humanGenerator () == "fhuJKrhSDzV2SkjLn9qbwm5AaRmrxDPfFsHDCP6yfDZWcxDFz4mt", generator.humanGenerator ());
|
||||
|
||||
// Create account #0 public/private key pair.
|
||||
RippleAddress naAccountPublic0 = RippleAddress::createAccountPublic (generator, 0);
|
||||
RippleAddress naAccountPrivate0 = RippleAddress::createAccountPrivate (generator, naSeed, 0);
|
||||
|
||||
expect (naAccountPublic0.humanAccountID () == "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", naAccountPublic0.humanAccountID ());
|
||||
expect (naAccountPublic0.humanAccountPublic () == "aBQG8RQAzjs1eTKFEAQXr2gS4utcDiEC9wmi7pfUPTi27VCahwgw", naAccountPublic0.humanAccountPublic ());
|
||||
|
||||
// Create account #1 public/private key pair.
|
||||
RippleAddress naAccountPublic1 = RippleAddress::createAccountPublic (generator, 1);
|
||||
RippleAddress naAccountPrivate1 = RippleAddress::createAccountPrivate (generator, naSeed, 1);
|
||||
|
||||
expect (naAccountPublic1.humanAccountID () == "r4bYF7SLUMD7QgSLLpgJx38WJSY12ViRjP", naAccountPublic1.humanAccountID ());
|
||||
expect (naAccountPublic1.humanAccountPublic () == "aBPXpTfuLy1Bhk3HnGTTAqnovpKWQ23NpFMNkAF6F1Atg5vDyPrw", naAccountPublic1.humanAccountPublic ());
|
||||
|
||||
// Check account signing.
|
||||
expect (naAccountPrivate0.accountPrivateSign (uHash, vucTextSig), "Signing failed.");
|
||||
expect (naAccountPublic0.accountPublicVerify (uHash, vucTextSig, ECDSA::strict), "Verify failed.");
|
||||
expect (!naAccountPublic1.accountPublicVerify (uHash, vucTextSig, ECDSA::not_strict), "Anti-verify failed.");
|
||||
expect (!naAccountPublic1.accountPublicVerify (uHash, vucTextSig, ECDSA::strict), "Anti-verify failed.");
|
||||
|
||||
expect (naAccountPrivate1.accountPrivateSign (uHash, vucTextSig), "Signing failed.");
|
||||
expect (naAccountPublic1.accountPublicVerify (uHash, vucTextSig, ECDSA::strict), "Verify failed.");
|
||||
expect (!naAccountPublic0.accountPublicVerify (uHash, vucTextSig, ECDSA::not_strict), "Anti-verify failed.");
|
||||
expect (!naAccountPublic0.accountPublicVerify (uHash, vucTextSig, ECDSA::strict), "Anti-verify failed.");
|
||||
|
||||
// Check account encryption.
|
||||
Blob vucTextCipher
|
||||
= naAccountPrivate0.accountPrivateEncrypt (naAccountPublic1, vucTextSrc);
|
||||
Blob vucTextRecovered
|
||||
= naAccountPrivate1.accountPrivateDecrypt (naAccountPublic0, vucTextCipher);
|
||||
|
||||
expect (vucTextSrc == vucTextRecovered, "Encrypt-decrypt failed.");
|
||||
|
||||
{
|
||||
RippleAddress nSeed;
|
||||
uint128 seed1, seed2;
|
||||
seed1.SetHex ("71ED064155FFADFA38782C5E0158CB26");
|
||||
nSeed.setSeed (seed1);
|
||||
expect (nSeed.humanSeed() == "shHM53KPZ87Gwdqarm1bAmPeXg8Tn",
|
||||
"Incorrect human seed");
|
||||
expect (nSeed.humanSeed1751() == "MAD BODY ACE MINT OKAY HUB WHAT DATA SACK FLAT DANA MATH",
|
||||
"Incorrect 1751 seed");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class RippleIdentifier_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void run ()
|
||||
{
|
||||
testcase ("Seed");
|
||||
RippleAddress seed;
|
||||
expect (seed.setSeedGeneric ("masterpassphrase"));
|
||||
expect (seed.humanSeed () == "snoPBrXtMeMyMHUVTgbuqAfg1SUTb", seed.humanSeed ());
|
||||
|
||||
testcase ("RipplePublicKey");
|
||||
RippleAddress deprecatedPublicKey (RippleAddress::createNodePublic (seed));
|
||||
expect (deprecatedPublicKey.humanNodePublic () ==
|
||||
"n94a1u4jAz288pZLtw6yFWVbi89YamiC6JBXPVUj5zmExe5fTVg9",
|
||||
deprecatedPublicKey.humanNodePublic ());
|
||||
RipplePublicKey publicKey = deprecatedPublicKey.toPublicKey();
|
||||
expect (publicKey.to_string() == deprecatedPublicKey.humanNodePublic(),
|
||||
publicKey.to_string());
|
||||
|
||||
testcase ("Generator");
|
||||
RippleAddress generator (RippleAddress::createGeneratorPublic (seed));
|
||||
expect (generator.humanGenerator () ==
|
||||
"fhuJKrhSDzV2SkjLn9qbwm5AaRmrxDPfFsHDCP6yfDZWcxDFz4mt",
|
||||
generator.humanGenerator ());
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(RippleAddress,ripple_data,ripple);
|
||||
BEAST_DEFINE_TESTSUITE(RippleIdentifier,ripple_data,ripple);
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <ripple/protocol/STObject.h>
|
||||
#include <ripple/protocol/STParsedJSON.h>
|
||||
#include <beast/module/core/text/LexicalCast.h>
|
||||
#include <beast/unit_test/suite.h>
|
||||
#include <beast/cxx14/memory.h> // <memory>
|
||||
|
||||
namespace ripple {
|
||||
@@ -906,171 +905,4 @@ bool STObject::operator== (const STObject& obj) const
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class SerializedObject_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void run()
|
||||
{
|
||||
testSerialization();
|
||||
testParseJSONArray();
|
||||
testParseJSONArrayWithInvalidChildrenObjects();
|
||||
}
|
||||
|
||||
bool parseJSONString (std::string const& json, Json::Value& to)
|
||||
{
|
||||
Json::Reader reader;
|
||||
return (reader.parse(json, to) &&
|
||||
!to.isNull() &&
|
||||
to.isObject());
|
||||
}
|
||||
|
||||
void testParseJSONArrayWithInvalidChildrenObjects ()
|
||||
{
|
||||
testcase ("parse json array invalid children");
|
||||
try
|
||||
{
|
||||
/*
|
||||
|
||||
STArray/STObject constructs don't really map perfectly to json
|
||||
arrays/objects.
|
||||
|
||||
STObject is an associative container, mapping fields to value, but
|
||||
an STObject may also have a Field as it's name, stored outside the
|
||||
associative structure. The name is important, so to maintain
|
||||
fidelity, it will take TWO json objects to represent them.
|
||||
|
||||
*/
|
||||
std::string faulty ("{\"Template\":[{"
|
||||
"\"ModifiedNode\":{\"Sequence\":1}, "
|
||||
"\"DeletedNode\":{\"Sequence\":1}"
|
||||
"}]}");
|
||||
|
||||
std::unique_ptr<STObject> so;
|
||||
Json::Value faultyJson;
|
||||
bool parsedOK (parseJSONString(faulty, faultyJson));
|
||||
unexpected(!parsedOK, "failed to parse");
|
||||
STParsedJSONObject parsed ("test", faultyJson);
|
||||
expect (parsed.object.get() == nullptr,
|
||||
"It should have thrown. "
|
||||
"Immediate children of STArray encoded as json must "
|
||||
"have one key only.");
|
||||
}
|
||||
catch(std::runtime_error& e)
|
||||
{
|
||||
std::string what(e.what());
|
||||
unexpected (what.find("First level children of `Template`") != 0);
|
||||
}
|
||||
}
|
||||
|
||||
void testParseJSONArray ()
|
||||
{
|
||||
testcase ("parse json array");
|
||||
std::string const json (
|
||||
"{\"Template\":[{\"ModifiedNode\":{\"Sequence\":1}}]}\n");
|
||||
|
||||
Json::Value jsonObject;
|
||||
bool parsedOK (parseJSONString(json, jsonObject));
|
||||
if (parsedOK)
|
||||
{
|
||||
STParsedJSONObject parsed ("test", jsonObject);
|
||||
std::string const& serialized (
|
||||
to_string (parsed.object->getJson(0)));
|
||||
expect (serialized == json, serialized + " should equal: " + json);
|
||||
}
|
||||
else
|
||||
{
|
||||
fail ("Couldn't parse json: " + json);
|
||||
}
|
||||
}
|
||||
|
||||
void testSerialization ()
|
||||
{
|
||||
testcase ("serialization");
|
||||
|
||||
unexpected (sfGeneric.isUseful (), "sfGeneric must not be useful");
|
||||
|
||||
SField const& sfTestVL = SField::getField (STI_VL, 255);
|
||||
SField const& sfTestH256 = SField::getField (STI_HASH256, 255);
|
||||
SField const& sfTestU32 = SField::getField (STI_UINT32, 255);
|
||||
SField const& sfTestObject = SField::getField (STI_OBJECT, 255);
|
||||
|
||||
SOTemplate elements;
|
||||
elements.push_back (SOElement (sfFlags, SOE_REQUIRED));
|
||||
elements.push_back (SOElement (sfTestVL, SOE_REQUIRED));
|
||||
elements.push_back (SOElement (sfTestH256, SOE_OPTIONAL));
|
||||
elements.push_back (SOElement (sfTestU32, SOE_REQUIRED));
|
||||
|
||||
STObject object1 (elements, sfTestObject);
|
||||
STObject object2 (object1);
|
||||
|
||||
unexpected (object1.getSerializer () != object2.getSerializer (),
|
||||
"STObject error 1");
|
||||
|
||||
unexpected (object1.isFieldPresent (sfTestH256) ||
|
||||
!object1.isFieldPresent (sfTestVL), "STObject error");
|
||||
|
||||
object1.makeFieldPresent (sfTestH256);
|
||||
|
||||
unexpected (!object1.isFieldPresent (sfTestH256), "STObject Error 2");
|
||||
|
||||
unexpected (object1.getFieldH256 (sfTestH256) != uint256 (),
|
||||
"STObject error 3");
|
||||
|
||||
if (object1.getSerializer () == object2.getSerializer ())
|
||||
{
|
||||
WriteLog (lsINFO, STObject) << "O1: " << object1.getJson (0);
|
||||
WriteLog (lsINFO, STObject) << "O2: " << object2.getJson (0);
|
||||
fail ("STObject error 4");
|
||||
}
|
||||
else
|
||||
{
|
||||
pass ();
|
||||
}
|
||||
|
||||
object1.makeFieldAbsent (sfTestH256);
|
||||
|
||||
unexpected (object1.isFieldPresent (sfTestH256), "STObject error 5");
|
||||
|
||||
unexpected (object1.getFlags () != 0, "STObject error 6");
|
||||
|
||||
unexpected (object1.getSerializer () != object2.getSerializer (),
|
||||
"STObject error 7");
|
||||
|
||||
STObject copy (object1);
|
||||
|
||||
unexpected (object1.isFieldPresent (sfTestH256), "STObject error 8");
|
||||
|
||||
unexpected (copy.isFieldPresent (sfTestH256), "STObject error 9");
|
||||
|
||||
unexpected (object1.getSerializer () != copy.getSerializer (),
|
||||
"STObject error 10");
|
||||
|
||||
copy.setFieldU32 (sfTestU32, 1);
|
||||
|
||||
unexpected (object1.getSerializer () == copy.getSerializer (),
|
||||
"STObject error 11");
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
Blob j (i, 2);
|
||||
|
||||
object1.setFieldVL (sfTestVL, j);
|
||||
|
||||
Serializer s;
|
||||
object1.add (s);
|
||||
SerializerIterator it (s);
|
||||
|
||||
STObject object3 (elements, it, sfTestObject);
|
||||
|
||||
unexpected (object1.getFieldVL (sfTestVL) != j, "STObject error");
|
||||
|
||||
unexpected (object3.getFieldVL (sfTestVL) != j, "STObject error");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(SerializedObject,ripple_data,ripple);
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -349,63 +349,4 @@ bool passesLocalChecks (STObject const& st)
|
||||
return passesLocalChecks (st, reason);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class STTx_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void run()
|
||||
{
|
||||
RippleAddress seed;
|
||||
seed.setSeedRandom ();
|
||||
RippleAddress generator = RippleAddress::createGeneratorPublic (seed);
|
||||
RippleAddress publicAcct = RippleAddress::createAccountPublic (generator, 1);
|
||||
RippleAddress privateAcct = RippleAddress::createAccountPrivate (generator, seed, 1);
|
||||
|
||||
STTx j (ttACCOUNT_SET);
|
||||
j.setSourceAccount (publicAcct);
|
||||
j.setSigningPubKey (publicAcct);
|
||||
j.setFieldVL (sfMessageKey, publicAcct.getAccountPublic ());
|
||||
j.sign (privateAcct);
|
||||
|
||||
unexpected (!j.checkSign (), "Transaction fails signature test");
|
||||
|
||||
Serializer rawTxn;
|
||||
j.add (rawTxn);
|
||||
SerializerIterator sit (rawTxn);
|
||||
STTx copy (sit);
|
||||
|
||||
if (copy != j)
|
||||
{
|
||||
log << j.getJson (0);
|
||||
log << copy.getJson (0);
|
||||
fail ("Transaction fails serialize/deserialize test");
|
||||
}
|
||||
else
|
||||
{
|
||||
pass ();
|
||||
}
|
||||
|
||||
STParsedJSONObject parsed ("test", j.getJson (0));
|
||||
std::unique_ptr <STObject> new_obj (std::move (parsed.object));
|
||||
|
||||
if (new_obj.get () == nullptr)
|
||||
fail ("Unable to build object from json");
|
||||
|
||||
if (STObject (j) != *new_obj)
|
||||
{
|
||||
log << "ORIG: " << j.getJson (0);
|
||||
log << "BUILT " << new_obj->getJson (0);
|
||||
fail ("Built a different transaction");
|
||||
}
|
||||
else
|
||||
{
|
||||
pass ();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(STTx,ripple_app,ripple);
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/protocol/Serializer.h>
|
||||
#include <beast/unit_test/suite.h>
|
||||
#include <openssl/ripemd.h>
|
||||
#include <openssl/pem.h>
|
||||
|
||||
@@ -648,25 +647,4 @@ Blob SerializerIterator::getRaw (int iLength)
|
||||
return mSerializer.getRaw (iPos, iLength);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class Serializer_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void run ()
|
||||
{
|
||||
Serializer s1;
|
||||
s1.add32 (3);
|
||||
s1.add256 (uint256 ());
|
||||
|
||||
Serializer s2;
|
||||
s2.add32 (0x12345600);
|
||||
s2.addRaw (s1.peekData ());
|
||||
|
||||
expect (s1.getPrefixHash (0x12345600) == s2.getSHA512Half ());
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(Serializer,ripple_data,ripple);
|
||||
|
||||
} // ripple
|
||||
|
||||
Reference in New Issue
Block a user