Split unit tests to separate files

This commit is contained in:
Vinnie Falco
2013-06-27 10:37:01 -07:00
parent 9cb0e04418
commit 905b920e99
38 changed files with 1960 additions and 1674 deletions

View File

@@ -109,6 +109,11 @@
//------------------------------------------------------------------------------
#if RIPPLE_USE_NAMESPACE
namespace ripple
{
#endif
// VFALCO NOTE The order of these includes is critical, since they do not
// include their own dependencies. This is what allows us to
// linearize the include sequence and view it in one place.
@@ -247,6 +252,17 @@
#include "src/cpp/ripple/WSHandler.h"
#include "src/cpp/ripple/WalletAddTransactor.h"
#if RIPPLE_USE_NAMESPACE
}
#endif
//------------------------------------------------------------------------------
#if RIPPLE_USE_NAMESPACE
namespace ripple
{
#endif
//------------------------------------------------------------------------------
// VFALCO TODO figure out who needs these and move to a sensible private header.
@@ -387,6 +403,7 @@ static DH* handleTmpDh (SSL* ssl, int is_export, int iKeyLength)
#include "src/cpp/ripple/ripple_PathRequest.cpp"
#include "src/cpp/ripple/ripple_PeerSet.cpp"
#include "src/cpp/ripple/ripple_ProofOfWork.cpp"
#include "src/cpp/ripple/ripple_ProofOfWorkFactory.h" // private
#include "src/cpp/ripple/ripple_ProofOfWorkFactory.cpp"
#include "src/cpp/ripple/ripple_SerializedLedger.cpp"
#include "src/cpp/ripple/ripple_SerializedTransaction.cpp"
@@ -398,6 +415,28 @@ static DH* handleTmpDh (SSL* ssl, int is_export, int iKeyLength)
//------------------------------------------------------------------------------
#if RIPPLE_USE_NAMESPACE
}
#endif
//------------------------------------------------------------------------------
#if ! defined (RIPPLE_MAIN_PART) || RIPPLE_MAIN_PART == 4
// Unit Tests
//
// These must be outside the namespace
//
// VFALCO TODO Eliminate the need for boost for unit tests.
//
#include "src/cpp/ripple/LedgerUnitTests.cpp"
#include "src/cpp/ripple/ripple_SHAMapUnitTests.cpp"
#include "src/cpp/ripple/ripple_SHAMapSyncUnitTests.cpp"
#include "src/cpp/ripple/ripple_ProofOfWorkFactoryUnitTests.cpp"
#include "src/cpp/ripple/ripple_SerializedTransactionUnitTests.cpp"
#endif
//------------------------------------------------------------------------------
#ifdef _MSC_VER

View File

@@ -6,6 +6,10 @@
SETUP_LOG (RangeSet)
// VFALCO NOTE std::min and std::max not good enough?
// NOTE Why isn't this written as a template?
// TODO Replace this with std calls.
//
inline uint32 min (uint32 x, uint32 y)
{
return (x < y) ? x : y;
@@ -180,32 +184,3 @@ void RangeSet::simplify ()
it = nit;
}
}
BOOST_AUTO_TEST_SUITE (RangeSet_suite)
BOOST_AUTO_TEST_CASE (RangeSet_test)
{
WriteLog (lsTRACE, RangeSet) << "RangeSet test begins";
RangeSet r1, r2;
r1.setRange (1, 10);
r1.clearValue (5);
r1.setRange (11, 20);
r2.setRange (1, 4);
r2.setRange (6, 10);
r2.setRange (10, 20);
if (r1.hasValue (5)) BOOST_FAIL ("RangeSet fail");
if (!r2.hasValue (9)) BOOST_FAIL ("RangeSet fail");
// TODO: Traverse functions must be tested
WriteLog (lsTRACE, RangeSet) << "RangeSet test complete";
}
BOOST_AUTO_TEST_SUITE_END ()
// vim:ts=4

View File

@@ -0,0 +1,31 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
BOOST_AUTO_TEST_SUITE (RangeSet_suite)
BOOST_AUTO_TEST_CASE (RangeSet_test)
{
WriteLog (lsTRACE, RangeSet) << "RangeSet test begins";
RangeSet r1, r2;
r1.setRange (1, 10);
r1.clearValue (5);
r1.setRange (11, 20);
r2.setRange (1, 4);
r2.setRange (6, 10);
r2.setRange (10, 20);
if (r1.hasValue (5)) BOOST_FAIL ("RangeSet fail");
if (!r2.hasValue (9)) BOOST_FAIL ("RangeSet fail");
// TODO: Traverse functions must be tested
WriteLog (lsTRACE, RangeSet) << "RangeSet test complete";
}
BOOST_AUTO_TEST_SUITE_END ()

View File

@@ -77,3 +77,7 @@ namespace ripple
#if RIPPLE_USE_NAMESPACE
}
#endif
// These must be outside the namespace (because of boost)
#include "containers/ripple_RangeSetUnitTests.cpp"
#include "utility/ripple_StringUtilitiesUnitTests.cpp"

View File

@@ -4,6 +4,8 @@
*/
//==============================================================================
// VFALCO TODO Repalce these with something more robust and without macros.
//
#if !defined(WIN32) && !defined(WIN64)
#define _vsnprintf(a,b,c,d) vsnprintf(a,b,c,d)
#endif
@@ -259,53 +261,3 @@ bool parseQuality (const std::string& strSource, uint32& uQuality)
return !!uQuality;
}
BOOST_AUTO_TEST_SUITE ( Utils)
BOOST_AUTO_TEST_CASE ( ParseUrl )
{
std::string strScheme;
std::string strDomain;
int iPort;
std::string strPath;
if (!parseUrl ("lower://domain", strScheme, strDomain, iPort, strPath))
BOOST_FAIL ("parseUrl: lower://domain failed");
if (strScheme != "lower")
BOOST_FAIL ("parseUrl: lower://domain : scheme failed");
if (strDomain != "domain")
BOOST_FAIL ("parseUrl: lower://domain : domain failed");
if (iPort != -1)
BOOST_FAIL ("parseUrl: lower://domain : port failed");
if (strPath != "")
BOOST_FAIL ("parseUrl: lower://domain : path failed");
if (!parseUrl ("UPPER://domain:234/", strScheme, strDomain, iPort, strPath))
BOOST_FAIL ("parseUrl: UPPER://domain:234/ failed");
if (strScheme != "upper")
BOOST_FAIL ("parseUrl: UPPER://domain:234/ : scheme failed");
if (iPort != 234)
BOOST_FAIL (boost::str (boost::format ("parseUrl: UPPER://domain:234/ : port failed: %d") % iPort));
if (strPath != "/")
BOOST_FAIL ("parseUrl: UPPER://domain:234/ : path failed");
if (!parseUrl ("Mixed://domain/path", strScheme, strDomain, iPort, strPath))
BOOST_FAIL ("parseUrl: Mixed://domain/path failed");
if (strScheme != "mixed")
BOOST_FAIL ("parseUrl: Mixed://domain/path tolower failed");
if (strPath != "/path")
BOOST_FAIL ("parseUrl: Mixed://domain/path path failed");
}
BOOST_AUTO_TEST_SUITE_END ()
// vim:ts=4

View File

@@ -0,0 +1,53 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
BOOST_AUTO_TEST_SUITE ( Utils)
BOOST_AUTO_TEST_CASE ( ParseUrl )
{
std::string strScheme;
std::string strDomain;
int iPort;
std::string strPath;
if (!parseUrl ("lower://domain", strScheme, strDomain, iPort, strPath))
BOOST_FAIL ("parseUrl: lower://domain failed");
if (strScheme != "lower")
BOOST_FAIL ("parseUrl: lower://domain : scheme failed");
if (strDomain != "domain")
BOOST_FAIL ("parseUrl: lower://domain : domain failed");
if (iPort != -1)
BOOST_FAIL ("parseUrl: lower://domain : port failed");
if (strPath != "")
BOOST_FAIL ("parseUrl: lower://domain : path failed");
if (!parseUrl ("UPPER://domain:234/", strScheme, strDomain, iPort, strPath))
BOOST_FAIL ("parseUrl: UPPER://domain:234/ failed");
if (strScheme != "upper")
BOOST_FAIL ("parseUrl: UPPER://domain:234/ : scheme failed");
if (iPort != 234)
BOOST_FAIL (boost::str (boost::format ("parseUrl: UPPER://domain:234/ : port failed: %d") % iPort));
if (strPath != "/")
BOOST_FAIL ("parseUrl: UPPER://domain:234/ : path failed");
if (!parseUrl ("Mixed://domain/path", strScheme, strDomain, iPort, strPath))
BOOST_FAIL ("parseUrl: Mixed://domain/path failed");
if (strScheme != "mixed")
BOOST_FAIL ("parseUrl: Mixed://domain/path tolower failed");
if (strPath != "/path")
BOOST_FAIL ("parseUrl: Mixed://domain/path path failed");
}
BOOST_AUTO_TEST_SUITE_END ()

View File

@@ -4,209 +4,7 @@
*/
//==============================================================================
class LoadManager;
class LoadFeeTrack : public ILoadFeeTrack
{
public:
LoadFeeTrack ()
: mLocalTxnLoadFee (lftNormalFee)
, mRemoteTxnLoadFee (lftNormalFee)
, raiseCount (0)
{
}
// Scale using load as well as base rate
uint64 scaleFeeLoad (uint64 fee, uint64 baseFee, uint32 referenceFeeUnits, bool bAdmin)
{
static uint64 midrange (0x00000000FFFFFFFF);
bool big = (fee > midrange);
if (big) // big fee, divide first to avoid overflow
fee /= baseFee;
else // normal fee, multiply first for accuracy
fee *= referenceFeeUnits;
uint32 feeFactor = std::max (mLocalTxnLoadFee, mRemoteTxnLoadFee);
// Let admins pay the normal fee until the local load exceeds four times the remote
if (bAdmin && (feeFactor > mRemoteTxnLoadFee) && (feeFactor < (4 * mRemoteTxnLoadFee)))
feeFactor = mRemoteTxnLoadFee;
{
boost::mutex::scoped_lock sl (mLock);
fee = mulDiv (fee, feeFactor, lftNormalFee);
}
if (big) // Fee was big to start, must now multiply
fee *= referenceFeeUnits;
else // Fee was small to start, mst now divide
fee /= baseFee;
return fee;
}
// Scale from fee units to millionths of a ripple
uint64 scaleFeeBase (uint64 fee, uint64 baseFee, uint32 referenceFeeUnits)
{
return mulDiv (fee, referenceFeeUnits, baseFee);
}
uint32 getRemoteFee ()
{
boost::mutex::scoped_lock sl (mLock);
return mRemoteTxnLoadFee;
}
uint32 getLocalFee ()
{
boost::mutex::scoped_lock sl (mLock);
return mLocalTxnLoadFee;
}
uint32 getLoadBase ()
{
return lftNormalFee;
}
uint32 getLoadFactor ()
{
boost::mutex::scoped_lock sl (mLock);
return std::max (mLocalTxnLoadFee, mRemoteTxnLoadFee);
}
bool isLoaded ()
{
boost::mutex::scoped_lock sl (mLock);
return (raiseCount != 0) || (mLocalTxnLoadFee != lftNormalFee);
}
void setRemoteFee (uint32 f)
{
boost::mutex::scoped_lock sl (mLock);
mRemoteTxnLoadFee = f;
}
bool raiseLocalFee ()
{
boost::mutex::scoped_lock sl (mLock);
if (++raiseCount < 2)
return false;
uint32 origFee = mLocalTxnLoadFee;
if (mLocalTxnLoadFee < mRemoteTxnLoadFee) // make sure this fee takes effect
mLocalTxnLoadFee = mRemoteTxnLoadFee;
mLocalTxnLoadFee += (mLocalTxnLoadFee / lftFeeIncFraction); // increment by 1/16th
if (mLocalTxnLoadFee > lftFeeMax)
mLocalTxnLoadFee = lftFeeMax;
if (origFee == mLocalTxnLoadFee)
return false;
WriteLog (lsDEBUG, LoadManager) << "Local load fee raised from " << origFee << " to " << mLocalTxnLoadFee;
return true;
}
bool lowerLocalFee ()
{
boost::mutex::scoped_lock sl (mLock);
uint32 origFee = mLocalTxnLoadFee;
raiseCount = 0;
mLocalTxnLoadFee -= (mLocalTxnLoadFee / lftFeeDecFraction ); // reduce by 1/4
if (mLocalTxnLoadFee < lftNormalFee)
mLocalTxnLoadFee = lftNormalFee;
if (origFee == mLocalTxnLoadFee)
return false;
WriteLog (lsDEBUG, LoadManager) << "Local load fee lowered from " << origFee << " to " << mLocalTxnLoadFee;
return true;
}
Json::Value getJson (uint64 baseFee, uint32 referenceFeeUnits)
{
Json::Value j (Json::objectValue);
{
boost::mutex::scoped_lock sl (mLock);
// base_fee = The cost to send a "reference" transaction under no load, in millionths of a Ripple
j["base_fee"] = Json::Value::UInt (baseFee);
// load_fee = The cost to send a "reference" transaction now, in millionths of a Ripple
j["load_fee"] = Json::Value::UInt (
mulDiv (baseFee, std::max (mLocalTxnLoadFee, mRemoteTxnLoadFee), lftNormalFee));
}
return j;
}
private:
// VFALCO TODO Move this function to some "math utilities" file
// compute (value)*(mul)/(div) - avoid overflow but keep precision
uint64 mulDiv (uint64 value, uint32 mul, uint64 div)
{
// VFALCO TODO replace with beast::literal64bitUnsigned ()
//
static uint64 boundary = (0x00000000FFFFFFFF);
if (value > boundary) // Large value, avoid overflow
return (value / div) * mul;
else // Normal value, preserve accuracy
return (value * mul) / div;
}
private:
static const int lftNormalFee = 256; // 256 is the minimum/normal load factor
static const int lftFeeIncFraction = 16; // increase fee by 1/16
static const int lftFeeDecFraction = 4; // decrease fee by 1/4
static const int lftFeeMax = lftNormalFee * 1000000;
uint32 mLocalTxnLoadFee; // Scale factor, lftNormalFee = normal fee
uint32 mRemoteTxnLoadFee; // Scale factor, lftNormalFee = normal fee
int raiseCount;
boost::mutex mLock;
};
//------------------------------------------------------------------------------
ILoadFeeTrack* ILoadFeeTrack::New ()
{
return new LoadFeeTrack;
}
//------------------------------------------------------------------------------
BOOST_AUTO_TEST_SUITE (LoadManager_test)
BOOST_AUTO_TEST_CASE (LoadFeeTrack_test)
{
WriteLog (lsDEBUG, LoadManager) << "Running load fee track test";
Config d; // get a default configuration object
LoadFeeTrack l;
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (10000, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 10000);
BOOST_REQUIRE_EQUAL (l.scaleFeeLoad (10000, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE, false), 10000);
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (1, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 1);
BOOST_REQUIRE_EQUAL (l.scaleFeeLoad (1, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE, false), 1);
// Check new default fee values give same fees as old defaults
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_DEFAULT, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 10);
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_ACCOUNT_RESERVE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 200 * SYSTEM_CURRENCY_PARTS);
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_OWNER_RESERVE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 50 * SYSTEM_CURRENCY_PARTS);
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_NICKNAME_CREATE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 1000);
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_OFFER, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 10);
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_CONTRACT_OPERATION, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 1);
}
BOOST_AUTO_TEST_SUITE_END ()

View File

@@ -0,0 +1,183 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
#ifndef RIPPLE_LOADFEETRACK_RIPPLEHEADER
#define RIPPLE_LOADFEETRACK_RIPPLEHEADER
// PRIVATE HEADER
class LoadManager;
class LoadFeeTrack : public ILoadFeeTrack
{
public:
LoadFeeTrack ()
: mLocalTxnLoadFee (lftNormalFee)
, mRemoteTxnLoadFee (lftNormalFee)
, raiseCount (0)
{
}
// Scale using load as well as base rate
uint64 scaleFeeLoad (uint64 fee, uint64 baseFee, uint32 referenceFeeUnits, bool bAdmin)
{
static uint64 midrange (0x00000000FFFFFFFF);
bool big = (fee > midrange);
if (big) // big fee, divide first to avoid overflow
fee /= baseFee;
else // normal fee, multiply first for accuracy
fee *= referenceFeeUnits;
uint32 feeFactor = std::max (mLocalTxnLoadFee, mRemoteTxnLoadFee);
// Let admins pay the normal fee until the local load exceeds four times the remote
if (bAdmin && (feeFactor > mRemoteTxnLoadFee) && (feeFactor < (4 * mRemoteTxnLoadFee)))
feeFactor = mRemoteTxnLoadFee;
{
boost::mutex::scoped_lock sl (mLock);
fee = mulDiv (fee, feeFactor, lftNormalFee);
}
if (big) // Fee was big to start, must now multiply
fee *= referenceFeeUnits;
else // Fee was small to start, mst now divide
fee /= baseFee;
return fee;
}
// Scale from fee units to millionths of a ripple
uint64 scaleFeeBase (uint64 fee, uint64 baseFee, uint32 referenceFeeUnits)
{
return mulDiv (fee, referenceFeeUnits, baseFee);
}
uint32 getRemoteFee ()
{
boost::mutex::scoped_lock sl (mLock);
return mRemoteTxnLoadFee;
}
uint32 getLocalFee ()
{
boost::mutex::scoped_lock sl (mLock);
return mLocalTxnLoadFee;
}
uint32 getLoadBase ()
{
return lftNormalFee;
}
uint32 getLoadFactor ()
{
boost::mutex::scoped_lock sl (mLock);
return std::max (mLocalTxnLoadFee, mRemoteTxnLoadFee);
}
bool isLoaded ()
{
boost::mutex::scoped_lock sl (mLock);
return (raiseCount != 0) || (mLocalTxnLoadFee != lftNormalFee);
}
void setRemoteFee (uint32 f)
{
boost::mutex::scoped_lock sl (mLock);
mRemoteTxnLoadFee = f;
}
bool raiseLocalFee ()
{
boost::mutex::scoped_lock sl (mLock);
if (++raiseCount < 2)
return false;
uint32 origFee = mLocalTxnLoadFee;
if (mLocalTxnLoadFee < mRemoteTxnLoadFee) // make sure this fee takes effect
mLocalTxnLoadFee = mRemoteTxnLoadFee;
mLocalTxnLoadFee += (mLocalTxnLoadFee / lftFeeIncFraction); // increment by 1/16th
if (mLocalTxnLoadFee > lftFeeMax)
mLocalTxnLoadFee = lftFeeMax;
if (origFee == mLocalTxnLoadFee)
return false;
WriteLog (lsDEBUG, LoadManager) << "Local load fee raised from " << origFee << " to " << mLocalTxnLoadFee;
return true;
}
bool lowerLocalFee ()
{
boost::mutex::scoped_lock sl (mLock);
uint32 origFee = mLocalTxnLoadFee;
raiseCount = 0;
mLocalTxnLoadFee -= (mLocalTxnLoadFee / lftFeeDecFraction ); // reduce by 1/4
if (mLocalTxnLoadFee < lftNormalFee)
mLocalTxnLoadFee = lftNormalFee;
if (origFee == mLocalTxnLoadFee)
return false;
WriteLog (lsDEBUG, LoadManager) << "Local load fee lowered from " << origFee << " to " << mLocalTxnLoadFee;
return true;
}
Json::Value getJson (uint64 baseFee, uint32 referenceFeeUnits)
{
Json::Value j (Json::objectValue);
{
boost::mutex::scoped_lock sl (mLock);
// base_fee = The cost to send a "reference" transaction under no load, in millionths of a Ripple
j["base_fee"] = Json::Value::UInt (baseFee);
// load_fee = The cost to send a "reference" transaction now, in millionths of a Ripple
j["load_fee"] = Json::Value::UInt (
mulDiv (baseFee, std::max (mLocalTxnLoadFee, mRemoteTxnLoadFee), lftNormalFee));
}
return j;
}
private:
// VFALCO TODO Move this function to some "math utilities" file
// compute (value)*(mul)/(div) - avoid overflow but keep precision
uint64 mulDiv (uint64 value, uint32 mul, uint64 div)
{
// VFALCO TODO replace with beast::literal64bitUnsigned ()
//
static uint64 boundary = (0x00000000FFFFFFFF);
if (value > boundary) // Large value, avoid overflow
return (value / div) * mul;
else // Normal value, preserve accuracy
return (value * mul) / div;
}
private:
static const int lftNormalFee = 256; // 256 is the minimum/normal load factor
static const int lftFeeIncFraction = 16; // increase fee by 1/16
static const int lftFeeDecFraction = 4; // decrease fee by 1/4
static const int lftFeeMax = lftNormalFee * 1000000;
uint32 mLocalTxnLoadFee; // Scale factor, lftNormalFee = normal fee
uint32 mRemoteTxnLoadFee; // Scale factor, lftNormalFee = normal fee
int raiseCount;
boost::mutex mLock;
};
#endif

View File

@@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
BOOST_AUTO_TEST_SUITE (LoadManager_test)
BOOST_AUTO_TEST_CASE (LoadFeeTrack_test)
{
WriteLog (lsDEBUG, LoadManager) << "Running load fee track test";
Config d; // get a default configuration object
LoadFeeTrack l;
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (10000, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 10000);
BOOST_REQUIRE_EQUAL (l.scaleFeeLoad (10000, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE, false), 10000);
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (1, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 1);
BOOST_REQUIRE_EQUAL (l.scaleFeeLoad (1, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE, false), 1);
// Check new default fee values give same fees as old defaults
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_DEFAULT, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 10);
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_ACCOUNT_RESERVE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 200 * SYSTEM_CURRENCY_PARTS);
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_OWNER_RESERVE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 50 * SYSTEM_CURRENCY_PARTS);
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_NICKNAME_CREATE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 1000);
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_OFFER, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 10);
BOOST_REQUIRE_EQUAL (l.scaleFeeBase (d.FEE_CONTRACT_OPERATION, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE), 1);
}
BOOST_AUTO_TEST_SUITE_END ()

View File

@@ -19,9 +19,23 @@
#include <boost/test/unit_test.hpp>
#include <boost/thread.hpp>
#if RIPPLE_USE_NAMESPACE
namespace ripple
{
#endif
#include "functional/ripple_Config.cpp"
#include "functional/ripple_LoadFeeTrack.h" // private
#include "functional/ripple_LoadFeeTrack.cpp"
#include "functional/ripple_Job.cpp"
#include "functional/ripple_JobQueue.cpp"
#include "functional/ripple_LoadEvent.cpp"
#include "functional/ripple_LoadMonitor.cpp"
#if RIPPLE_USE_NAMESPACE
}
#endif
// These must be outside the namespace
#include "functional/ripple_LoadFeeTrackUnitTests.cpp"

View File

@@ -32,6 +32,11 @@
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#if RIPPLE_USE_NAMESPACE
namespace ripple
{
#endif
// VFALCO NOTE Indentation shows dependency hierarchy
//
/**/#include "functional/ripple_Config.h"
@@ -41,4 +46,8 @@
/*.*/#include "functional/ripple_Job.h"
/**/#include "functional/ripple_JobQueue.h"
#if RIPPLE_USE_NAMESPACE
}
#endif
#endif

View File

@@ -346,38 +346,3 @@ EC_KEY* CKey::GeneratePrivateDeterministicKey (const RippleAddress& pubGen, cons
return pkey;
}
BOOST_AUTO_TEST_SUITE (DeterministicKeys_test)
BOOST_AUTO_TEST_CASE (DeterminsticKeys_test1)
{
Log (lsDEBUG) << "Beginning deterministic key test";
uint128 seed1, seed2;
seed1.SetHex ("71ED064155FFADFA38782C5E0158CB26");
seed2.SetHex ("CF0C3BE4485961858C4198515AE5B965");
CKey root1 (seed1), root2 (seed2);
uint256 priv1, priv2;
root1.GetPrivateKeyU (priv1);
root2.GetPrivateKeyU (priv2);
if (priv1.GetHex () != "7CFBA64F771E93E817E15039215430B53F7401C34931D111EAB3510B22DBB0D8")
BOOST_FAIL ("Incorrect private key for generator");
if (priv2.GetHex () != "98BC2EACB26EB021D1A6293C044D88BA2F0B6729A2772DEEBF2E21A263C1740B")
BOOST_FAIL ("Incorrect private key for generator");
RippleAddress nSeed;
nSeed.setSeed (seed1);
if (nSeed.humanSeed () != "shHM53KPZ87Gwdqarm1bAmPeXg8Tn")
BOOST_FAIL ("Incorrect human seed");
if (nSeed.humanSeed1751 () != "MAD BODY ACE MINT OKAY HUB WHAT DATA SACK FLAT DANA MATH")
BOOST_FAIL ("Incorrect 1751 seed");
}
BOOST_AUTO_TEST_SUITE_END ();
// vim:ts=4

View File

@@ -0,0 +1,37 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
BOOST_AUTO_TEST_SUITE (DeterministicKeys_test)
BOOST_AUTO_TEST_CASE (DeterminsticKeys_test1)
{
Log (lsDEBUG) << "Beginning deterministic key test";
uint128 seed1, seed2;
seed1.SetHex ("71ED064155FFADFA38782C5E0158CB26");
seed2.SetHex ("CF0C3BE4485961858C4198515AE5B965");
CKey root1 (seed1), root2 (seed2);
uint256 priv1, priv2;
root1.GetPrivateKeyU (priv1);
root2.GetPrivateKeyU (priv2);
if (priv1.GetHex () != "7CFBA64F771E93E817E15039215430B53F7401C34931D111EAB3510B22DBB0D8")
BOOST_FAIL ("Incorrect private key for generator");
if (priv2.GetHex () != "98BC2EACB26EB021D1A6293C044D88BA2F0B6729A2772DEEBF2E21A263C1740B")
BOOST_FAIL ("Incorrect private key for generator");
RippleAddress nSeed;
nSeed.setSeed (seed1);
if (nSeed.humanSeed () != "shHM53KPZ87Gwdqarm1bAmPeXg8Tn")
BOOST_FAIL ("Incorrect human seed");
if (nSeed.humanSeed1751 () != "MAD BODY ACE MINT OKAY HUB WHAT DATA SACK FLAT DANA MATH")
BOOST_FAIL ("Incorrect 1751 seed");
}
BOOST_AUTO_TEST_SUITE_END ();

View File

@@ -865,71 +865,3 @@ RippleAddress RippleAddress::createSeedGeneric (const std::string& strText)
return naNew;
}
BOOST_AUTO_TEST_SUITE (ripple_address)
BOOST_AUTO_TEST_CASE ( check_crypto )
{
// Construct a seed.
RippleAddress naSeed;
BOOST_CHECK (naSeed.setSeedGeneric ("masterpassphrase"));
BOOST_CHECK_MESSAGE (naSeed.humanSeed () == "snoPBrXtMeMyMHUVTgbuqAfg1SUTb", naSeed.humanSeed ());
// Create node public/private key pair
RippleAddress naNodePublic = RippleAddress::createNodePublic (naSeed);
RippleAddress naNodePrivate = RippleAddress::createNodePrivate (naSeed);
BOOST_CHECK_MESSAGE (naNodePublic.humanNodePublic () == "n94a1u4jAz288pZLtw6yFWVbi89YamiC6JBXPVUj5zmExe5fTVg9", naNodePublic.humanNodePublic ());
BOOST_CHECK_MESSAGE (naNodePrivate.humanNodePrivate () == "pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe", naNodePrivate.humanNodePrivate ());
// Check node signing.
Blob vucTextSrc = strCopy ("Hello, nurse!");
uint256 uHash = Serializer::getSHA512Half (vucTextSrc);
Blob vucTextSig;
naNodePrivate.signNodePrivate (uHash, vucTextSig);
BOOST_CHECK_MESSAGE (naNodePublic.verifyNodePublic (uHash, vucTextSig), "Verify failed.");
// Construct a public generator from the seed.
RippleAddress naGenerator = RippleAddress::createGeneratorPublic (naSeed);
BOOST_CHECK_MESSAGE (naGenerator.humanGenerator () == "fhuJKrhSDzV2SkjLn9qbwm5AaRmrxDPfFsHDCP6yfDZWcxDFz4mt", naGenerator.humanGenerator ());
// Create account #0 public/private key pair.
RippleAddress naAccountPublic0 = RippleAddress::createAccountPublic (naGenerator, 0);
RippleAddress naAccountPrivate0 = RippleAddress::createAccountPrivate (naGenerator, naSeed, 0);
BOOST_CHECK_MESSAGE (naAccountPublic0.humanAccountID () == "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", naAccountPublic0.humanAccountID ());
BOOST_CHECK_MESSAGE (naAccountPublic0.humanAccountPublic () == "aBQG8RQAzjs1eTKFEAQXr2gS4utcDiEC9wmi7pfUPTi27VCahwgw", naAccountPublic0.humanAccountPublic ());
BOOST_CHECK_MESSAGE (naAccountPrivate0.humanAccountPrivate () == "p9JfM6HHi64m6mvB6v5k7G2b1cXzGmYiCNJf6GHPKvFTWdeRVjh", naAccountPrivate0.humanAccountPrivate ());
// Create account #1 public/private key pair.
RippleAddress naAccountPublic1 = RippleAddress::createAccountPublic (naGenerator, 1);
RippleAddress naAccountPrivate1 = RippleAddress::createAccountPrivate (naGenerator, naSeed, 1);
BOOST_CHECK_MESSAGE (naAccountPublic1.humanAccountID () == "r4bYF7SLUMD7QgSLLpgJx38WJSY12ViRjP", naAccountPublic1.humanAccountID ());
BOOST_CHECK_MESSAGE (naAccountPublic1.humanAccountPublic () == "aBPXpTfuLy1Bhk3HnGTTAqnovpKWQ23NpFMNkAF6F1Atg5vDyPrw", naAccountPublic1.humanAccountPublic ());
BOOST_CHECK_MESSAGE (naAccountPrivate1.humanAccountPrivate () == "p9JEm822LMrzJii1k7TvdphfENTp6G5jr253Xa5rkzUWVr8ogQt", naAccountPrivate1.humanAccountPrivate ());
// Check account signing.
BOOST_CHECK_MESSAGE (naAccountPrivate0.accountPrivateSign (uHash, vucTextSig), "Signing failed.");
BOOST_CHECK_MESSAGE (naAccountPublic0.accountPublicVerify (uHash, vucTextSig), "Verify failed.");
BOOST_CHECK_MESSAGE (!naAccountPublic1.accountPublicVerify (uHash, vucTextSig), "Anti-verify failed.");
BOOST_CHECK_MESSAGE (naAccountPrivate1.accountPrivateSign (uHash, vucTextSig), "Signing failed.");
BOOST_CHECK_MESSAGE (naAccountPublic1.accountPublicVerify (uHash, vucTextSig), "Verify failed.");
BOOST_CHECK_MESSAGE (!naAccountPublic0.accountPublicVerify (uHash, vucTextSig), "Anti-verify failed.");
// Check account encryption.
Blob vucTextCipher
= naAccountPrivate0.accountPrivateEncrypt (naAccountPublic1, vucTextSrc);
Blob vucTextRecovered
= naAccountPrivate1.accountPrivateDecrypt (naAccountPublic0, vucTextCipher);
BOOST_CHECK_MESSAGE (vucTextSrc == vucTextRecovered, "Encrypt-decrypt failed.");
}
BOOST_AUTO_TEST_SUITE_END ()
// vim:ts=4

View File

@@ -0,0 +1,70 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
BOOST_AUTO_TEST_SUITE (ripple_address)
BOOST_AUTO_TEST_CASE ( check_crypto )
{
// Construct a seed.
RippleAddress naSeed;
BOOST_CHECK (naSeed.setSeedGeneric ("masterpassphrase"));
BOOST_CHECK_MESSAGE (naSeed.humanSeed () == "snoPBrXtMeMyMHUVTgbuqAfg1SUTb", naSeed.humanSeed ());
// Create node public/private key pair
RippleAddress naNodePublic = RippleAddress::createNodePublic (naSeed);
RippleAddress naNodePrivate = RippleAddress::createNodePrivate (naSeed);
BOOST_CHECK_MESSAGE (naNodePublic.humanNodePublic () == "n94a1u4jAz288pZLtw6yFWVbi89YamiC6JBXPVUj5zmExe5fTVg9", naNodePublic.humanNodePublic ());
BOOST_CHECK_MESSAGE (naNodePrivate.humanNodePrivate () == "pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe", naNodePrivate.humanNodePrivate ());
// Check node signing.
Blob vucTextSrc = strCopy ("Hello, nurse!");
uint256 uHash = Serializer::getSHA512Half (vucTextSrc);
Blob vucTextSig;
naNodePrivate.signNodePrivate (uHash, vucTextSig);
BOOST_CHECK_MESSAGE (naNodePublic.verifyNodePublic (uHash, vucTextSig), "Verify failed.");
// Construct a public generator from the seed.
RippleAddress naGenerator = RippleAddress::createGeneratorPublic (naSeed);
BOOST_CHECK_MESSAGE (naGenerator.humanGenerator () == "fhuJKrhSDzV2SkjLn9qbwm5AaRmrxDPfFsHDCP6yfDZWcxDFz4mt", naGenerator.humanGenerator ());
// Create account #0 public/private key pair.
RippleAddress naAccountPublic0 = RippleAddress::createAccountPublic (naGenerator, 0);
RippleAddress naAccountPrivate0 = RippleAddress::createAccountPrivate (naGenerator, naSeed, 0);
BOOST_CHECK_MESSAGE (naAccountPublic0.humanAccountID () == "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", naAccountPublic0.humanAccountID ());
BOOST_CHECK_MESSAGE (naAccountPublic0.humanAccountPublic () == "aBQG8RQAzjs1eTKFEAQXr2gS4utcDiEC9wmi7pfUPTi27VCahwgw", naAccountPublic0.humanAccountPublic ());
BOOST_CHECK_MESSAGE (naAccountPrivate0.humanAccountPrivate () == "p9JfM6HHi64m6mvB6v5k7G2b1cXzGmYiCNJf6GHPKvFTWdeRVjh", naAccountPrivate0.humanAccountPrivate ());
// Create account #1 public/private key pair.
RippleAddress naAccountPublic1 = RippleAddress::createAccountPublic (naGenerator, 1);
RippleAddress naAccountPrivate1 = RippleAddress::createAccountPrivate (naGenerator, naSeed, 1);
BOOST_CHECK_MESSAGE (naAccountPublic1.humanAccountID () == "r4bYF7SLUMD7QgSLLpgJx38WJSY12ViRjP", naAccountPublic1.humanAccountID ());
BOOST_CHECK_MESSAGE (naAccountPublic1.humanAccountPublic () == "aBPXpTfuLy1Bhk3HnGTTAqnovpKWQ23NpFMNkAF6F1Atg5vDyPrw", naAccountPublic1.humanAccountPublic ());
BOOST_CHECK_MESSAGE (naAccountPrivate1.humanAccountPrivate () == "p9JEm822LMrzJii1k7TvdphfENTp6G5jr253Xa5rkzUWVr8ogQt", naAccountPrivate1.humanAccountPrivate ());
// Check account signing.
BOOST_CHECK_MESSAGE (naAccountPrivate0.accountPrivateSign (uHash, vucTextSig), "Signing failed.");
BOOST_CHECK_MESSAGE (naAccountPublic0.accountPublicVerify (uHash, vucTextSig), "Verify failed.");
BOOST_CHECK_MESSAGE (!naAccountPublic1.accountPublicVerify (uHash, vucTextSig), "Anti-verify failed.");
BOOST_CHECK_MESSAGE (naAccountPrivate1.accountPrivateSign (uHash, vucTextSig), "Signing failed.");
BOOST_CHECK_MESSAGE (naAccountPublic1.accountPublicVerify (uHash, vucTextSig), "Verify failed.");
BOOST_CHECK_MESSAGE (!naAccountPublic0.accountPublicVerify (uHash, vucTextSig), "Anti-verify failed.");
// Check account encryption.
Blob vucTextCipher
= naAccountPrivate0.accountPrivateEncrypt (naAccountPublic1, vucTextSrc);
Blob vucTextRecovered
= naAccountPrivate1.accountPrivateDecrypt (naAccountPublic0, vucTextCipher);
BOOST_CHECK_MESSAGE (vucTextSrc == vucTextRecovered, "Encrypt-decrypt failed.");
}
BOOST_AUTO_TEST_SUITE_END ()

View File

@@ -1298,521 +1298,3 @@ Json::Value STAmount::getJson (int) const
setJson (elem);
return elem;
}
// For unit tests:
static STAmount serdes (const STAmount& s)
{
Serializer ser;
s.add (ser);
SerializerIterator sit (ser);
return STAmount::deserialize (sit);
}
BOOST_AUTO_TEST_SUITE (amount)
BOOST_AUTO_TEST_CASE ( setValue_test )
{
STAmount saTmp;
#if 0
// Check native floats
saTmp.setFullValue ("1^0");
BOOST_CHECK_MESSAGE (SYSTEM_CURRENCY_PARTS == saTmp.getNValue (), "float integer failed");
saTmp.setFullValue ("0^1");
BOOST_CHECK_MESSAGE (SYSTEM_CURRENCY_PARTS / 10 == saTmp.getNValue (), "float fraction failed");
saTmp.setFullValue ("0^12");
BOOST_CHECK_MESSAGE (12 * SYSTEM_CURRENCY_PARTS / 100 == saTmp.getNValue (), "float fraction failed");
saTmp.setFullValue ("1^2");
BOOST_CHECK_MESSAGE (SYSTEM_CURRENCY_PARTS + (2 * SYSTEM_CURRENCY_PARTS / 10) == saTmp.getNValue (), "float combined failed");
#endif
// Check native integer
saTmp.setFullValue ("1");
BOOST_CHECK_MESSAGE (1 == saTmp.getNValue (), "integer failed");
}
BOOST_AUTO_TEST_CASE ( NativeCurrency_test )
{
STAmount zero, one (1), hundred (100);
if (serdes (zero) != zero) BOOST_FAIL ("STAmount fail");
if (serdes (one) != one) BOOST_FAIL ("STAmount fail");
if (serdes (hundred) != hundred) BOOST_FAIL ("STAmount fail");
if (!zero.isNative ()) BOOST_FAIL ("STAmount fail");
if (!hundred.isNative ()) BOOST_FAIL ("STAmount fail");
if (!zero.isZero ()) BOOST_FAIL ("STAmount fail");
if (one.isZero ()) BOOST_FAIL ("STAmount fail");
if (hundred.isZero ()) BOOST_FAIL ("STAmount fail");
if ((zero < zero)) BOOST_FAIL ("STAmount fail");
if (! (zero < one)) BOOST_FAIL ("STAmount fail");
if (! (zero < hundred)) BOOST_FAIL ("STAmount fail");
if ((one < zero)) BOOST_FAIL ("STAmount fail");
if ((one < one)) BOOST_FAIL ("STAmount fail");
if (! (one < hundred)) BOOST_FAIL ("STAmount fail");
if ((hundred < zero)) BOOST_FAIL ("STAmount fail");
if ((hundred < one)) BOOST_FAIL ("STAmount fail");
if ((hundred < hundred)) BOOST_FAIL ("STAmount fail");
if ((zero > zero)) BOOST_FAIL ("STAmount fail");
if ((zero > one)) BOOST_FAIL ("STAmount fail");
if ((zero > hundred)) BOOST_FAIL ("STAmount fail");
if (! (one > zero)) BOOST_FAIL ("STAmount fail");
if ((one > one)) BOOST_FAIL ("STAmount fail");
if ((one > hundred)) BOOST_FAIL ("STAmount fail");
if (! (hundred > zero)) BOOST_FAIL ("STAmount fail");
if (! (hundred > one)) BOOST_FAIL ("STAmount fail");
if ((hundred > hundred)) BOOST_FAIL ("STAmount fail");
if (! (zero <= zero)) BOOST_FAIL ("STAmount fail");
if (! (zero <= one)) BOOST_FAIL ("STAmount fail");
if (! (zero <= hundred)) BOOST_FAIL ("STAmount fail");
if ((one <= zero)) BOOST_FAIL ("STAmount fail");
if (! (one <= one)) BOOST_FAIL ("STAmount fail");
if (! (one <= hundred)) BOOST_FAIL ("STAmount fail");
if ((hundred <= zero)) BOOST_FAIL ("STAmount fail");
if ((hundred <= one)) BOOST_FAIL ("STAmount fail");
if (! (hundred <= hundred)) BOOST_FAIL ("STAmount fail");
if (! (zero >= zero)) BOOST_FAIL ("STAmount fail");
if ((zero >= one)) BOOST_FAIL ("STAmount fail");
if ((zero >= hundred)) BOOST_FAIL ("STAmount fail");
if (! (one >= zero)) BOOST_FAIL ("STAmount fail");
if (! (one >= one)) BOOST_FAIL ("STAmount fail");
if ((one >= hundred)) BOOST_FAIL ("STAmount fail");
if (! (hundred >= zero)) BOOST_FAIL ("STAmount fail");
if (! (hundred >= one)) BOOST_FAIL ("STAmount fail");
if (! (hundred >= hundred)) BOOST_FAIL ("STAmount fail");
if (! (zero == zero)) BOOST_FAIL ("STAmount fail");
if ((zero == one)) BOOST_FAIL ("STAmount fail");
if ((zero == hundred)) BOOST_FAIL ("STAmount fail");
if ((one == zero)) BOOST_FAIL ("STAmount fail");
if (! (one == one)) BOOST_FAIL ("STAmount fail");
if ((one == hundred)) BOOST_FAIL ("STAmount fail");
if ((hundred == zero)) BOOST_FAIL ("STAmount fail");
if ((hundred == one)) BOOST_FAIL ("STAmount fail");
if (! (hundred == hundred)) BOOST_FAIL ("STAmount fail");
if ((zero != zero)) BOOST_FAIL ("STAmount fail");
if (! (zero != one)) BOOST_FAIL ("STAmount fail");
if (! (zero != hundred)) BOOST_FAIL ("STAmount fail");
if (! (one != zero)) BOOST_FAIL ("STAmount fail");
if ((one != one)) BOOST_FAIL ("STAmount fail");
if (! (one != hundred)) BOOST_FAIL ("STAmount fail");
if (! (hundred != zero)) BOOST_FAIL ("STAmount fail");
if (! (hundred != one)) BOOST_FAIL ("STAmount fail");
if ((hundred != hundred)) BOOST_FAIL ("STAmount fail");
if (STAmount ().getText () != "0") BOOST_FAIL ("STAmount fail");
if (STAmount (31).getText () != "31") BOOST_FAIL ("STAmount fail");
if (STAmount (310).getText () != "310") BOOST_FAIL ("STAmount fail");
BOOST_TEST_MESSAGE ("Amount NC Complete");
}
BOOST_AUTO_TEST_CASE ( CustomCurrency_test )
{
STAmount zero (CURRENCY_ONE, ACCOUNT_ONE), one (CURRENCY_ONE, ACCOUNT_ONE, 1), hundred (CURRENCY_ONE, ACCOUNT_ONE, 100);
serdes (one).getRaw ();
if (serdes (zero) != zero) BOOST_FAIL ("STAmount fail");
if (serdes (one) != one) BOOST_FAIL ("STAmount fail");
if (serdes (hundred) != hundred) BOOST_FAIL ("STAmount fail");
if (zero.isNative ()) BOOST_FAIL ("STAmount fail");
if (hundred.isNative ()) BOOST_FAIL ("STAmount fail");
if (!zero.isZero ()) BOOST_FAIL ("STAmount fail");
if (one.isZero ()) BOOST_FAIL ("STAmount fail");
if (hundred.isZero ()) BOOST_FAIL ("STAmount fail");
if ((zero < zero)) BOOST_FAIL ("STAmount fail");
if (! (zero < one)) BOOST_FAIL ("STAmount fail");
if (! (zero < hundred)) BOOST_FAIL ("STAmount fail");
if ((one < zero)) BOOST_FAIL ("STAmount fail");
if ((one < one)) BOOST_FAIL ("STAmount fail");
if (! (one < hundred)) BOOST_FAIL ("STAmount fail");
if ((hundred < zero)) BOOST_FAIL ("STAmount fail");
if ((hundred < one)) BOOST_FAIL ("STAmount fail");
if ((hundred < hundred)) BOOST_FAIL ("STAmount fail");
if ((zero > zero)) BOOST_FAIL ("STAmount fail");
if ((zero > one)) BOOST_FAIL ("STAmount fail");
if ((zero > hundred)) BOOST_FAIL ("STAmount fail");
if (! (one > zero)) BOOST_FAIL ("STAmount fail");
if ((one > one)) BOOST_FAIL ("STAmount fail");
if ((one > hundred)) BOOST_FAIL ("STAmount fail");
if (! (hundred > zero)) BOOST_FAIL ("STAmount fail");
if (! (hundred > one)) BOOST_FAIL ("STAmount fail");
if ((hundred > hundred)) BOOST_FAIL ("STAmount fail");
if (! (zero <= zero)) BOOST_FAIL ("STAmount fail");
if (! (zero <= one)) BOOST_FAIL ("STAmount fail");
if (! (zero <= hundred)) BOOST_FAIL ("STAmount fail");
if ((one <= zero)) BOOST_FAIL ("STAmount fail");
if (! (one <= one)) BOOST_FAIL ("STAmount fail");
if (! (one <= hundred)) BOOST_FAIL ("STAmount fail");
if ((hundred <= zero)) BOOST_FAIL ("STAmount fail");
if ((hundred <= one)) BOOST_FAIL ("STAmount fail");
if (! (hundred <= hundred)) BOOST_FAIL ("STAmount fail");
if (! (zero >= zero)) BOOST_FAIL ("STAmount fail");
if ((zero >= one)) BOOST_FAIL ("STAmount fail");
if ((zero >= hundred)) BOOST_FAIL ("STAmount fail");
if (! (one >= zero)) BOOST_FAIL ("STAmount fail");
if (! (one >= one)) BOOST_FAIL ("STAmount fail");
if ((one >= hundred)) BOOST_FAIL ("STAmount fail");
if (! (hundred >= zero)) BOOST_FAIL ("STAmount fail");
if (! (hundred >= one)) BOOST_FAIL ("STAmount fail");
if (! (hundred >= hundred)) BOOST_FAIL ("STAmount fail");
if (! (zero == zero)) BOOST_FAIL ("STAmount fail");
if ((zero == one)) BOOST_FAIL ("STAmount fail");
if ((zero == hundred)) BOOST_FAIL ("STAmount fail");
if ((one == zero)) BOOST_FAIL ("STAmount fail");
if (! (one == one)) BOOST_FAIL ("STAmount fail");
if ((one == hundred)) BOOST_FAIL ("STAmount fail");
if ((hundred == zero)) BOOST_FAIL ("STAmount fail");
if ((hundred == one)) BOOST_FAIL ("STAmount fail");
if (! (hundred == hundred)) BOOST_FAIL ("STAmount fail");
if ((zero != zero)) BOOST_FAIL ("STAmount fail");
if (! (zero != one)) BOOST_FAIL ("STAmount fail");
if (! (zero != hundred)) BOOST_FAIL ("STAmount fail");
if (! (one != zero)) BOOST_FAIL ("STAmount fail");
if ((one != one)) BOOST_FAIL ("STAmount fail");
if (! (one != hundred)) BOOST_FAIL ("STAmount fail");
if (! (hundred != zero)) BOOST_FAIL ("STAmount fail");
if (! (hundred != one)) BOOST_FAIL ("STAmount fail");
if ((hundred != hundred)) BOOST_FAIL ("STAmount fail");
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE).getText () != "0") BOOST_FAIL ("STAmount fail");
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31).getText () != "31") BOOST_FAIL ("STAmount fail");
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, 1).getText () != "310") BOOST_FAIL ("STAmount fail");
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, -1).getText () != "3.1") BOOST_FAIL ("STAmount fail");
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, -2).getText () != "0.31") BOOST_FAIL ("STAmount fail");
if (STAmount::multiply (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 20), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "60")
BOOST_FAIL ("STAmount multiply fail 1");
if (STAmount::multiply (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 20), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "60")
BOOST_FAIL ("STAmount multiply fail 2");
if (STAmount::multiply (STAmount (20), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "60")
BOOST_FAIL ("STAmount multiply fail 3");
if (STAmount::multiply (STAmount (20), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "60")
BOOST_FAIL ("STAmount multiply fail 4");
if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "20")
{
WriteLog (lsFATAL, STAmount) << "60/3 = " <<
STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60),
STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText ();
BOOST_FAIL ("STAmount divide fail");
}
if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "20")
BOOST_FAIL ("STAmount divide fail");
if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "20")
BOOST_FAIL ("STAmount divide fail");
if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 3), uint160 (), ACCOUNT_XRP).getText () != "20")
BOOST_FAIL ("STAmount divide fail");
STAmount a1 (CURRENCY_ONE, ACCOUNT_ONE, 60), a2 (CURRENCY_ONE, ACCOUNT_ONE, 10, -1);
if (STAmount::divide (a2, a1, CURRENCY_ONE, ACCOUNT_ONE) != STAmount::setRate (STAmount::getRate (a1, a2)))
BOOST_FAIL ("STAmount setRate(getRate) fail");
if (STAmount::divide (a1, a2, CURRENCY_ONE, ACCOUNT_ONE) != STAmount::setRate (STAmount::getRate (a2, a1)))
BOOST_FAIL ("STAmount setRate(getRate) fail");
BOOST_TEST_MESSAGE ("Amount CC Complete");
}
static bool roundTest (int n, int d, int m)
{
// check STAmount rounding
STAmount num (CURRENCY_ONE, ACCOUNT_ONE, n);
STAmount den (CURRENCY_ONE, ACCOUNT_ONE, d);
STAmount mul (CURRENCY_ONE, ACCOUNT_ONE, m);
STAmount quot = STAmount::divide (n, d, CURRENCY_ONE, ACCOUNT_ONE);
STAmount res = STAmount::multiply (quot, mul, CURRENCY_ONE, ACCOUNT_ONE);
if (res.isNative ())
BOOST_FAIL ("Product is native");
res.roundSelf ();
STAmount cmp (CURRENCY_ONE, ACCOUNT_ONE, (n * m) / d);
if (cmp.isNative ())
BOOST_FAIL ("Comparison amount is native");
if (res == cmp)
return true;
cmp.throwComparable (res);
WriteLog (lsWARNING, STAmount) << "(" << num.getText () << "/" << den.getText () << ") X " << mul.getText () << " = "
<< res.getText () << " not " << cmp.getText ();
BOOST_FAIL ("Round fail");
return false;
}
static void mulTest (int a, int b)
{
STAmount aa (CURRENCY_ONE, ACCOUNT_ONE, a);
STAmount bb (CURRENCY_ONE, ACCOUNT_ONE, b);
STAmount prod1 (STAmount::multiply (aa, bb, CURRENCY_ONE, ACCOUNT_ONE));
if (prod1.isNative ())
BOOST_FAIL ("product is native");
STAmount prod2 (CURRENCY_ONE, ACCOUNT_ONE, static_cast<uint64> (a) * static_cast<uint64> (b));
if (prod1 != prod2)
{
WriteLog (lsWARNING, STAmount) << "nn(" << aa.getFullText () << " * " << bb.getFullText () << ") = " << prod1.getFullText ()
<< " not " << prod2.getFullText ();
BOOST_WARN ("Multiplication result is not exact");
}
aa = a;
prod1 = STAmount::multiply (aa, bb, CURRENCY_ONE, ACCOUNT_ONE);
if (prod1 != prod2)
{
WriteLog (lsWARNING, STAmount) << "n(" << aa.getFullText () << " * " << bb.getFullText () << ") = " << prod1.getFullText ()
<< " not " << prod2.getFullText ();
BOOST_WARN ("Multiplication result is not exact");
}
}
BOOST_AUTO_TEST_CASE ( CurrencyMulDivTests )
{
CBigNum b;
for (int i = 0; i < 16; ++i)
{
uint64 r = rand ();
r <<= 32;
r |= rand ();
b.setuint64 (r);
if (b.getuint64 () != r)
{
WriteLog (lsFATAL, STAmount) << r << " != " << b.getuint64 () << " " << b.ToString (16);
BOOST_FAIL ("setull64/getull64 failure");
}
}
// Test currency multiplication and division operations such as
// convertToDisplayAmount, convertToInternalAmount, getRate, getClaimed, and getNeeded
if (STAmount::getRate (STAmount (1), STAmount (10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 1");
if (STAmount::getRate (STAmount (10), STAmount (1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 2");
if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 3");
if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 4");
if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1), STAmount (10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 5");
if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10), STAmount (1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 6");
if (STAmount::getRate (STAmount (1), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 7");
if (STAmount::getRate (STAmount (10), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 8");
roundTest (1, 3, 3);
roundTest (2, 3, 9);
roundTest (1, 7, 21);
roundTest (1, 2, 4);
roundTest (3, 9, 18);
roundTest (7, 11, 44);
for (int i = 0; i <= 100000; ++i)
mulTest (rand () % 10000000, rand () % 10000000);
}
BOOST_AUTO_TEST_CASE ( UnderFlowTests )
{
STAmount bigNative (STAmount::cMaxNative / 2);
STAmount bigValue (CURRENCY_ONE, ACCOUNT_ONE,
(STAmount::cMinValue + STAmount::cMaxValue) / 2, STAmount::cMaxOffset - 1);
STAmount smallValue (CURRENCY_ONE, ACCOUNT_ONE,
(STAmount::cMinValue + STAmount::cMaxValue) / 2, STAmount::cMinOffset + 1);
STAmount zero (CURRENCY_ONE, ACCOUNT_ONE, 0);
STAmount smallXsmall = STAmount::multiply (smallValue, smallValue, CURRENCY_ONE, ACCOUNT_ONE);
if (!smallXsmall.isZero ())
BOOST_FAIL ("STAmount: smallXsmall != 0");
STAmount bigDsmall = STAmount::divide (smallValue, bigValue, CURRENCY_ONE, ACCOUNT_ONE);
if (!bigDsmall.isZero ())
BOOST_FAIL ("STAmount: small/big != 0: " << bigDsmall);
bigDsmall = STAmount::divide (smallValue, bigNative, CURRENCY_ONE, uint160 ());
if (!bigDsmall.isZero ())
BOOST_FAIL ("STAmount: small/bigNative != 0: " << bigDsmall);
bigDsmall = STAmount::divide (smallValue, bigValue, uint160 (), uint160 ());
if (!bigDsmall.isZero ())
BOOST_FAIL ("STAmount: (small/big)->N != 0: " << bigDsmall);
bigDsmall = STAmount::divide (smallValue, bigNative, uint160 (), uint160 ());
if (!bigDsmall.isZero ())
BOOST_FAIL ("STAmount: (small/bigNative)->N != 0: " << bigDsmall);
// very bad offer
uint64 r = STAmount::getRate (smallValue, bigValue);
if (r != 0)
BOOST_FAIL ("STAmount: getRate(smallOut/bigIn) != 0" << r);
// very good offer
r = STAmount::getRate (bigValue, smallValue);
if (r != 0)
BOOST_FAIL ("STAmount:: getRate(smallIn/bigOUt) != 0" << r);
}
BOOST_AUTO_TEST_SUITE_END ()
// vim:ts=4

View File

@@ -4,7 +4,7 @@
*/
//==============================================================================
static void canonicalizeRound (bool isNative, uint64& value, int& offset, bool roundUp)
void STAmount::canonicalizeRound (bool isNative, uint64& value, int& offset, bool roundUp)
{
if (!roundUp) // canonicalize already rounds down
return;
@@ -298,54 +298,3 @@ STAmount STAmount::divRound (const STAmount& num, const STAmount& den,
return STAmount (uCurrencyID, uIssuerID, amount, offset, resultNegative);
}
BOOST_AUTO_TEST_SUITE (amountRound)
BOOST_AUTO_TEST_CASE ( amountRound_test )
{
uint64 value = 25000000000000000ull;
int offset = -14;
canonicalizeRound (false, value, offset, true);
STAmount one (CURRENCY_ONE, ACCOUNT_ONE, 1);
STAmount two (CURRENCY_ONE, ACCOUNT_ONE, 2);
STAmount three (CURRENCY_ONE, ACCOUNT_ONE, 3);
STAmount oneThird1 = STAmount::divRound (one, three, CURRENCY_ONE, ACCOUNT_ONE, false);
STAmount oneThird2 = STAmount::divide (one, three, CURRENCY_ONE, ACCOUNT_ONE);
STAmount oneThird3 = STAmount::divRound (one, three, CURRENCY_ONE, ACCOUNT_ONE, true);
WriteLog (lsINFO, STAmount) << oneThird1;
WriteLog (lsINFO, STAmount) << oneThird2;
WriteLog (lsINFO, STAmount) << oneThird3;
STAmount twoThird1 = STAmount::divRound (two, three, CURRENCY_ONE, ACCOUNT_ONE, false);
STAmount twoThird2 = STAmount::divide (two, three, CURRENCY_ONE, ACCOUNT_ONE);
STAmount twoThird3 = STAmount::divRound (two, three, CURRENCY_ONE, ACCOUNT_ONE, true);
WriteLog (lsINFO, STAmount) << twoThird1;
WriteLog (lsINFO, STAmount) << twoThird2;
WriteLog (lsINFO, STAmount) << twoThird3;
STAmount oneA = STAmount::mulRound (oneThird1, three, CURRENCY_ONE, ACCOUNT_ONE, false);
STAmount oneB = STAmount::multiply (oneThird2, three, CURRENCY_ONE, ACCOUNT_ONE);
STAmount oneC = STAmount::mulRound (oneThird3, three, CURRENCY_ONE, ACCOUNT_ONE, true);
WriteLog (lsINFO, STAmount) << oneA;
WriteLog (lsINFO, STAmount) << oneB;
WriteLog (lsINFO, STAmount) << oneC;
STAmount fourThirdsA = STAmount::addRound (twoThird2, twoThird2, false);
STAmount fourThirdsB = twoThird2 + twoThird2;
STAmount fourThirdsC = STAmount::addRound (twoThird2, twoThird2, true);
WriteLog (lsINFO, STAmount) << fourThirdsA;
WriteLog (lsINFO, STAmount) << fourThirdsB;
WriteLog (lsINFO, STAmount) << fourThirdsC;
STAmount dripTest1 = STAmount::mulRound (twoThird2, two, uint160 (), uint160 (), false);
STAmount dripTest2 = STAmount::multiply (twoThird2, two, uint160 (), uint160 ());
STAmount dripTest3 = STAmount::mulRound (twoThird2, two, uint160 (), uint160 (), true);
WriteLog (lsINFO, STAmount) << dripTest1;
WriteLog (lsINFO, STAmount) << dripTest2;
WriteLog (lsINFO, STAmount) << dripTest3;
}
BOOST_AUTO_TEST_SUITE_END ()
// vim:ts=4

View File

@@ -0,0 +1,583 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
// For unit tests:
static STAmount serdes (const STAmount& s)
{
Serializer ser;
s.add (ser);
SerializerIterator sit (ser);
return STAmount::deserialize (sit);
}
//------------------------------------------------------------------------------
BOOST_AUTO_TEST_SUITE (amount)
BOOST_AUTO_TEST_CASE ( setValue_test )
{
STAmount saTmp;
#if 0
// Check native floats
saTmp.setFullValue ("1^0");
BOOST_CHECK_MESSAGE (SYSTEM_CURRENCY_PARTS == saTmp.getNValue (), "float integer failed");
saTmp.setFullValue ("0^1");
BOOST_CHECK_MESSAGE (SYSTEM_CURRENCY_PARTS / 10 == saTmp.getNValue (), "float fraction failed");
saTmp.setFullValue ("0^12");
BOOST_CHECK_MESSAGE (12 * SYSTEM_CURRENCY_PARTS / 100 == saTmp.getNValue (), "float fraction failed");
saTmp.setFullValue ("1^2");
BOOST_CHECK_MESSAGE (SYSTEM_CURRENCY_PARTS + (2 * SYSTEM_CURRENCY_PARTS / 10) == saTmp.getNValue (), "float combined failed");
#endif
// Check native integer
saTmp.setFullValue ("1");
BOOST_CHECK_MESSAGE (1 == saTmp.getNValue (), "integer failed");
}
//------------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE ( NativeCurrency_test )
{
STAmount zero, one (1), hundred (100);
if (serdes (zero) != zero) BOOST_FAIL ("STAmount fail");
if (serdes (one) != one) BOOST_FAIL ("STAmount fail");
if (serdes (hundred) != hundred) BOOST_FAIL ("STAmount fail");
if (!zero.isNative ()) BOOST_FAIL ("STAmount fail");
if (!hundred.isNative ()) BOOST_FAIL ("STAmount fail");
if (!zero.isZero ()) BOOST_FAIL ("STAmount fail");
if (one.isZero ()) BOOST_FAIL ("STAmount fail");
if (hundred.isZero ()) BOOST_FAIL ("STAmount fail");
if ((zero < zero)) BOOST_FAIL ("STAmount fail");
if (! (zero < one)) BOOST_FAIL ("STAmount fail");
if (! (zero < hundred)) BOOST_FAIL ("STAmount fail");
if ((one < zero)) BOOST_FAIL ("STAmount fail");
if ((one < one)) BOOST_FAIL ("STAmount fail");
if (! (one < hundred)) BOOST_FAIL ("STAmount fail");
if ((hundred < zero)) BOOST_FAIL ("STAmount fail");
if ((hundred < one)) BOOST_FAIL ("STAmount fail");
if ((hundred < hundred)) BOOST_FAIL ("STAmount fail");
if ((zero > zero)) BOOST_FAIL ("STAmount fail");
if ((zero > one)) BOOST_FAIL ("STAmount fail");
if ((zero > hundred)) BOOST_FAIL ("STAmount fail");
if (! (one > zero)) BOOST_FAIL ("STAmount fail");
if ((one > one)) BOOST_FAIL ("STAmount fail");
if ((one > hundred)) BOOST_FAIL ("STAmount fail");
if (! (hundred > zero)) BOOST_FAIL ("STAmount fail");
if (! (hundred > one)) BOOST_FAIL ("STAmount fail");
if ((hundred > hundred)) BOOST_FAIL ("STAmount fail");
if (! (zero <= zero)) BOOST_FAIL ("STAmount fail");
if (! (zero <= one)) BOOST_FAIL ("STAmount fail");
if (! (zero <= hundred)) BOOST_FAIL ("STAmount fail");
if ((one <= zero)) BOOST_FAIL ("STAmount fail");
if (! (one <= one)) BOOST_FAIL ("STAmount fail");
if (! (one <= hundred)) BOOST_FAIL ("STAmount fail");
if ((hundred <= zero)) BOOST_FAIL ("STAmount fail");
if ((hundred <= one)) BOOST_FAIL ("STAmount fail");
if (! (hundred <= hundred)) BOOST_FAIL ("STAmount fail");
if (! (zero >= zero)) BOOST_FAIL ("STAmount fail");
if ((zero >= one)) BOOST_FAIL ("STAmount fail");
if ((zero >= hundred)) BOOST_FAIL ("STAmount fail");
if (! (one >= zero)) BOOST_FAIL ("STAmount fail");
if (! (one >= one)) BOOST_FAIL ("STAmount fail");
if ((one >= hundred)) BOOST_FAIL ("STAmount fail");
if (! (hundred >= zero)) BOOST_FAIL ("STAmount fail");
if (! (hundred >= one)) BOOST_FAIL ("STAmount fail");
if (! (hundred >= hundred)) BOOST_FAIL ("STAmount fail");
if (! (zero == zero)) BOOST_FAIL ("STAmount fail");
if ((zero == one)) BOOST_FAIL ("STAmount fail");
if ((zero == hundred)) BOOST_FAIL ("STAmount fail");
if ((one == zero)) BOOST_FAIL ("STAmount fail");
if (! (one == one)) BOOST_FAIL ("STAmount fail");
if ((one == hundred)) BOOST_FAIL ("STAmount fail");
if ((hundred == zero)) BOOST_FAIL ("STAmount fail");
if ((hundred == one)) BOOST_FAIL ("STAmount fail");
if (! (hundred == hundred)) BOOST_FAIL ("STAmount fail");
if ((zero != zero)) BOOST_FAIL ("STAmount fail");
if (! (zero != one)) BOOST_FAIL ("STAmount fail");
if (! (zero != hundred)) BOOST_FAIL ("STAmount fail");
if (! (one != zero)) BOOST_FAIL ("STAmount fail");
if ((one != one)) BOOST_FAIL ("STAmount fail");
if (! (one != hundred)) BOOST_FAIL ("STAmount fail");
if (! (hundred != zero)) BOOST_FAIL ("STAmount fail");
if (! (hundred != one)) BOOST_FAIL ("STAmount fail");
if ((hundred != hundred)) BOOST_FAIL ("STAmount fail");
if (STAmount ().getText () != "0") BOOST_FAIL ("STAmount fail");
if (STAmount (31).getText () != "31") BOOST_FAIL ("STAmount fail");
if (STAmount (310).getText () != "310") BOOST_FAIL ("STAmount fail");
BOOST_TEST_MESSAGE ("Amount NC Complete");
}
//------------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE ( CustomCurrency_test )
{
STAmount zero (CURRENCY_ONE, ACCOUNT_ONE), one (CURRENCY_ONE, ACCOUNT_ONE, 1), hundred (CURRENCY_ONE, ACCOUNT_ONE, 100);
serdes (one).getRaw ();
if (serdes (zero) != zero) BOOST_FAIL ("STAmount fail");
if (serdes (one) != one) BOOST_FAIL ("STAmount fail");
if (serdes (hundred) != hundred) BOOST_FAIL ("STAmount fail");
if (zero.isNative ()) BOOST_FAIL ("STAmount fail");
if (hundred.isNative ()) BOOST_FAIL ("STAmount fail");
if (!zero.isZero ()) BOOST_FAIL ("STAmount fail");
if (one.isZero ()) BOOST_FAIL ("STAmount fail");
if (hundred.isZero ()) BOOST_FAIL ("STAmount fail");
if ((zero < zero)) BOOST_FAIL ("STAmount fail");
if (! (zero < one)) BOOST_FAIL ("STAmount fail");
if (! (zero < hundred)) BOOST_FAIL ("STAmount fail");
if ((one < zero)) BOOST_FAIL ("STAmount fail");
if ((one < one)) BOOST_FAIL ("STAmount fail");
if (! (one < hundred)) BOOST_FAIL ("STAmount fail");
if ((hundred < zero)) BOOST_FAIL ("STAmount fail");
if ((hundred < one)) BOOST_FAIL ("STAmount fail");
if ((hundred < hundred)) BOOST_FAIL ("STAmount fail");
if ((zero > zero)) BOOST_FAIL ("STAmount fail");
if ((zero > one)) BOOST_FAIL ("STAmount fail");
if ((zero > hundred)) BOOST_FAIL ("STAmount fail");
if (! (one > zero)) BOOST_FAIL ("STAmount fail");
if ((one > one)) BOOST_FAIL ("STAmount fail");
if ((one > hundred)) BOOST_FAIL ("STAmount fail");
if (! (hundred > zero)) BOOST_FAIL ("STAmount fail");
if (! (hundred > one)) BOOST_FAIL ("STAmount fail");
if ((hundred > hundred)) BOOST_FAIL ("STAmount fail");
if (! (zero <= zero)) BOOST_FAIL ("STAmount fail");
if (! (zero <= one)) BOOST_FAIL ("STAmount fail");
if (! (zero <= hundred)) BOOST_FAIL ("STAmount fail");
if ((one <= zero)) BOOST_FAIL ("STAmount fail");
if (! (one <= one)) BOOST_FAIL ("STAmount fail");
if (! (one <= hundred)) BOOST_FAIL ("STAmount fail");
if ((hundred <= zero)) BOOST_FAIL ("STAmount fail");
if ((hundred <= one)) BOOST_FAIL ("STAmount fail");
if (! (hundred <= hundred)) BOOST_FAIL ("STAmount fail");
if (! (zero >= zero)) BOOST_FAIL ("STAmount fail");
if ((zero >= one)) BOOST_FAIL ("STAmount fail");
if ((zero >= hundred)) BOOST_FAIL ("STAmount fail");
if (! (one >= zero)) BOOST_FAIL ("STAmount fail");
if (! (one >= one)) BOOST_FAIL ("STAmount fail");
if ((one >= hundred)) BOOST_FAIL ("STAmount fail");
if (! (hundred >= zero)) BOOST_FAIL ("STAmount fail");
if (! (hundred >= one)) BOOST_FAIL ("STAmount fail");
if (! (hundred >= hundred)) BOOST_FAIL ("STAmount fail");
if (! (zero == zero)) BOOST_FAIL ("STAmount fail");
if ((zero == one)) BOOST_FAIL ("STAmount fail");
if ((zero == hundred)) BOOST_FAIL ("STAmount fail");
if ((one == zero)) BOOST_FAIL ("STAmount fail");
if (! (one == one)) BOOST_FAIL ("STAmount fail");
if ((one == hundred)) BOOST_FAIL ("STAmount fail");
if ((hundred == zero)) BOOST_FAIL ("STAmount fail");
if ((hundred == one)) BOOST_FAIL ("STAmount fail");
if (! (hundred == hundred)) BOOST_FAIL ("STAmount fail");
if ((zero != zero)) BOOST_FAIL ("STAmount fail");
if (! (zero != one)) BOOST_FAIL ("STAmount fail");
if (! (zero != hundred)) BOOST_FAIL ("STAmount fail");
if (! (one != zero)) BOOST_FAIL ("STAmount fail");
if ((one != one)) BOOST_FAIL ("STAmount fail");
if (! (one != hundred)) BOOST_FAIL ("STAmount fail");
if (! (hundred != zero)) BOOST_FAIL ("STAmount fail");
if (! (hundred != one)) BOOST_FAIL ("STAmount fail");
if ((hundred != hundred)) BOOST_FAIL ("STAmount fail");
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE).getText () != "0") BOOST_FAIL ("STAmount fail");
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31).getText () != "31") BOOST_FAIL ("STAmount fail");
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, 1).getText () != "310") BOOST_FAIL ("STAmount fail");
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, -1).getText () != "3.1") BOOST_FAIL ("STAmount fail");
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, -2).getText () != "0.31") BOOST_FAIL ("STAmount fail");
if (STAmount::multiply (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 20), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "60")
BOOST_FAIL ("STAmount multiply fail 1");
if (STAmount::multiply (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 20), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "60")
BOOST_FAIL ("STAmount multiply fail 2");
if (STAmount::multiply (STAmount (20), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "60")
BOOST_FAIL ("STAmount multiply fail 3");
if (STAmount::multiply (STAmount (20), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "60")
BOOST_FAIL ("STAmount multiply fail 4");
if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "20")
{
WriteLog (lsFATAL, STAmount) << "60/3 = " <<
STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60),
STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText ();
BOOST_FAIL ("STAmount divide fail");
}
if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "20")
BOOST_FAIL ("STAmount divide fail");
if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "20")
BOOST_FAIL ("STAmount divide fail");
if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 3), uint160 (), ACCOUNT_XRP).getText () != "20")
BOOST_FAIL ("STAmount divide fail");
STAmount a1 (CURRENCY_ONE, ACCOUNT_ONE, 60), a2 (CURRENCY_ONE, ACCOUNT_ONE, 10, -1);
if (STAmount::divide (a2, a1, CURRENCY_ONE, ACCOUNT_ONE) != STAmount::setRate (STAmount::getRate (a1, a2)))
BOOST_FAIL ("STAmount setRate(getRate) fail");
if (STAmount::divide (a1, a2, CURRENCY_ONE, ACCOUNT_ONE) != STAmount::setRate (STAmount::getRate (a2, a1)))
BOOST_FAIL ("STAmount setRate(getRate) fail");
BOOST_TEST_MESSAGE ("Amount CC Complete");
}
//------------------------------------------------------------------------------
static bool roundTest (int n, int d, int m)
{
// check STAmount rounding
STAmount num (CURRENCY_ONE, ACCOUNT_ONE, n);
STAmount den (CURRENCY_ONE, ACCOUNT_ONE, d);
STAmount mul (CURRENCY_ONE, ACCOUNT_ONE, m);
STAmount quot = STAmount::divide (n, d, CURRENCY_ONE, ACCOUNT_ONE);
STAmount res = STAmount::multiply (quot, mul, CURRENCY_ONE, ACCOUNT_ONE);
if (res.isNative ())
BOOST_FAIL ("Product is native");
res.roundSelf ();
STAmount cmp (CURRENCY_ONE, ACCOUNT_ONE, (n * m) / d);
if (cmp.isNative ())
BOOST_FAIL ("Comparison amount is native");
if (res == cmp)
return true;
cmp.throwComparable (res);
WriteLog (lsWARNING, STAmount) << "(" << num.getText () << "/" << den.getText () << ") X " << mul.getText () << " = "
<< res.getText () << " not " << cmp.getText ();
BOOST_FAIL ("Round fail");
return false;
}
static void mulTest (int a, int b)
{
STAmount aa (CURRENCY_ONE, ACCOUNT_ONE, a);
STAmount bb (CURRENCY_ONE, ACCOUNT_ONE, b);
STAmount prod1 (STAmount::multiply (aa, bb, CURRENCY_ONE, ACCOUNT_ONE));
if (prod1.isNative ())
BOOST_FAIL ("product is native");
STAmount prod2 (CURRENCY_ONE, ACCOUNT_ONE, static_cast<uint64> (a) * static_cast<uint64> (b));
if (prod1 != prod2)
{
WriteLog (lsWARNING, STAmount) << "nn(" << aa.getFullText () << " * " << bb.getFullText () << ") = " << prod1.getFullText ()
<< " not " << prod2.getFullText ();
BOOST_WARN ("Multiplication result is not exact");
}
aa = a;
prod1 = STAmount::multiply (aa, bb, CURRENCY_ONE, ACCOUNT_ONE);
if (prod1 != prod2)
{
WriteLog (lsWARNING, STAmount) << "n(" << aa.getFullText () << " * " << bb.getFullText () << ") = " << prod1.getFullText ()
<< " not " << prod2.getFullText ();
BOOST_WARN ("Multiplication result is not exact");
}
}
BOOST_AUTO_TEST_CASE ( CurrencyMulDivTests )
{
CBigNum b;
for (int i = 0; i < 16; ++i)
{
uint64 r = rand ();
r <<= 32;
r |= rand ();
b.setuint64 (r);
if (b.getuint64 () != r)
{
WriteLog (lsFATAL, STAmount) << r << " != " << b.getuint64 () << " " << b.ToString (16);
BOOST_FAIL ("setull64/getull64 failure");
}
}
// Test currency multiplication and division operations such as
// convertToDisplayAmount, convertToInternalAmount, getRate, getClaimed, and getNeeded
if (STAmount::getRate (STAmount (1), STAmount (10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 1");
if (STAmount::getRate (STAmount (10), STAmount (1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 2");
if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 3");
if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 4");
if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1), STAmount (10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 5");
if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10), STAmount (1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 6");
if (STAmount::getRate (STAmount (1), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 7");
if (STAmount::getRate (STAmount (10), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull))
BOOST_FAIL ("STAmount getRate fail 8");
roundTest (1, 3, 3);
roundTest (2, 3, 9);
roundTest (1, 7, 21);
roundTest (1, 2, 4);
roundTest (3, 9, 18);
roundTest (7, 11, 44);
for (int i = 0; i <= 100000; ++i)
mulTest (rand () % 10000000, rand () % 10000000);
}
//------------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE ( UnderFlowTests )
{
STAmount bigNative (STAmount::cMaxNative / 2);
STAmount bigValue (CURRENCY_ONE, ACCOUNT_ONE,
(STAmount::cMinValue + STAmount::cMaxValue) / 2, STAmount::cMaxOffset - 1);
STAmount smallValue (CURRENCY_ONE, ACCOUNT_ONE,
(STAmount::cMinValue + STAmount::cMaxValue) / 2, STAmount::cMinOffset + 1);
STAmount zero (CURRENCY_ONE, ACCOUNT_ONE, 0);
STAmount smallXsmall = STAmount::multiply (smallValue, smallValue, CURRENCY_ONE, ACCOUNT_ONE);
if (!smallXsmall.isZero ())
BOOST_FAIL ("STAmount: smallXsmall != 0");
STAmount bigDsmall = STAmount::divide (smallValue, bigValue, CURRENCY_ONE, ACCOUNT_ONE);
if (!bigDsmall.isZero ())
BOOST_FAIL ("STAmount: small/big != 0: " << bigDsmall);
bigDsmall = STAmount::divide (smallValue, bigNative, CURRENCY_ONE, uint160 ());
if (!bigDsmall.isZero ())
BOOST_FAIL ("STAmount: small/bigNative != 0: " << bigDsmall);
bigDsmall = STAmount::divide (smallValue, bigValue, uint160 (), uint160 ());
if (!bigDsmall.isZero ())
BOOST_FAIL ("STAmount: (small/big)->N != 0: " << bigDsmall);
bigDsmall = STAmount::divide (smallValue, bigNative, uint160 (), uint160 ());
if (!bigDsmall.isZero ())
BOOST_FAIL ("STAmount: (small/bigNative)->N != 0: " << bigDsmall);
// very bad offer
uint64 r = STAmount::getRate (smallValue, bigValue);
if (r != 0)
BOOST_FAIL ("STAmount: getRate(smallOut/bigIn) != 0" << r);
// very good offer
r = STAmount::getRate (bigValue, smallValue);
if (r != 0)
BOOST_FAIL ("STAmount:: getRate(smallIn/bigOUt) != 0" << r);
}
BOOST_AUTO_TEST_SUITE_END ()
//------------------------------------------------------------------------------
BOOST_AUTO_TEST_SUITE (amountRound)
BOOST_AUTO_TEST_CASE ( amountRound_test )
{
uint64 value = 25000000000000000ull;
int offset = -14;
STAmount::canonicalizeRound (false, value, offset, true);
STAmount one (CURRENCY_ONE, ACCOUNT_ONE, 1);
STAmount two (CURRENCY_ONE, ACCOUNT_ONE, 2);
STAmount three (CURRENCY_ONE, ACCOUNT_ONE, 3);
STAmount oneThird1 = STAmount::divRound (one, three, CURRENCY_ONE, ACCOUNT_ONE, false);
STAmount oneThird2 = STAmount::divide (one, three, CURRENCY_ONE, ACCOUNT_ONE);
STAmount oneThird3 = STAmount::divRound (one, three, CURRENCY_ONE, ACCOUNT_ONE, true);
WriteLog (lsINFO, STAmount) << oneThird1;
WriteLog (lsINFO, STAmount) << oneThird2;
WriteLog (lsINFO, STAmount) << oneThird3;
STAmount twoThird1 = STAmount::divRound (two, three, CURRENCY_ONE, ACCOUNT_ONE, false);
STAmount twoThird2 = STAmount::divide (two, three, CURRENCY_ONE, ACCOUNT_ONE);
STAmount twoThird3 = STAmount::divRound (two, three, CURRENCY_ONE, ACCOUNT_ONE, true);
WriteLog (lsINFO, STAmount) << twoThird1;
WriteLog (lsINFO, STAmount) << twoThird2;
WriteLog (lsINFO, STAmount) << twoThird3;
STAmount oneA = STAmount::mulRound (oneThird1, three, CURRENCY_ONE, ACCOUNT_ONE, false);
STAmount oneB = STAmount::multiply (oneThird2, three, CURRENCY_ONE, ACCOUNT_ONE);
STAmount oneC = STAmount::mulRound (oneThird3, three, CURRENCY_ONE, ACCOUNT_ONE, true);
WriteLog (lsINFO, STAmount) << oneA;
WriteLog (lsINFO, STAmount) << oneB;
WriteLog (lsINFO, STAmount) << oneC;
STAmount fourThirdsA = STAmount::addRound (twoThird2, twoThird2, false);
STAmount fourThirdsB = twoThird2 + twoThird2;
STAmount fourThirdsC = STAmount::addRound (twoThird2, twoThird2, true);
WriteLog (lsINFO, STAmount) << fourThirdsA;
WriteLog (lsINFO, STAmount) << fourThirdsB;
WriteLog (lsINFO, STAmount) << fourThirdsC;
STAmount dripTest1 = STAmount::mulRound (twoThird2, two, uint160 (), uint160 (), false);
STAmount dripTest2 = STAmount::multiply (twoThird2, two, uint160 (), uint160 ());
STAmount dripTest3 = STAmount::mulRound (twoThird2, two, uint160 (), uint160 (), true);
WriteLog (lsINFO, STAmount) << dripTest1;
WriteLog (lsINFO, STAmount) << dripTest2;
WriteLog (lsINFO, STAmount) << dripTest3;
}
BOOST_AUTO_TEST_SUITE_END ()

View File

@@ -1547,84 +1547,3 @@ UPTR_T<STObject> STObject::parseJson (const Json::Value& object, SField::ref inN
return UPTR_T<STObject> (new STObject (*name, data));
}
BOOST_AUTO_TEST_SUITE (SerializedObject)
BOOST_AUTO_TEST_CASE ( FieldManipulation_test )
{
if (sfGeneric.isUseful ())
BOOST_FAIL ("sfGeneric must not be useful");
SField sfTestVL (STI_VL, 255, "TestVL");
SField sfTestH256 (STI_HASH256, 255, "TestH256");
SField sfTestU32 (STI_UINT32, 255, "TestU32");
SField sfTestObject (STI_OBJECT, 255, "TestObject");
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);
if (object1.getSerializer () != object2.getSerializer ()) BOOST_FAIL ("STObject error 1");
if (object1.isFieldPresent (sfTestH256) || !object1.isFieldPresent (sfTestVL))
BOOST_FAIL ("STObject error");
object1.makeFieldPresent (sfTestH256);
if (!object1.isFieldPresent (sfTestH256)) BOOST_FAIL ("STObject Error 2");
if (object1.getFieldH256 (sfTestH256) != uint256 ()) BOOST_FAIL ("STObject error 3");
if (object1.getSerializer () == object2.getSerializer ())
{
WriteLog (lsINFO, STObject) << "O1: " << object1.getJson (0);
WriteLog (lsINFO, STObject) << "O2: " << object2.getJson (0);
BOOST_FAIL ("STObject error 4");
}
object1.makeFieldAbsent (sfTestH256);
if (object1.isFieldPresent (sfTestH256)) BOOST_FAIL ("STObject error 5");
if (object1.getFlags () != 0) BOOST_FAIL ("STObject error 6");
if (object1.getSerializer () != object2.getSerializer ()) BOOST_FAIL ("STObject error 7");
STObject copy (object1);
if (object1.isFieldPresent (sfTestH256)) BOOST_FAIL ("STObject error 8");
if (copy.isFieldPresent (sfTestH256)) BOOST_FAIL ("STObject error 9");
if (object1.getSerializer () != copy.getSerializer ()) BOOST_FAIL ("STObject error 10");
copy.setFieldU32 (sfTestU32, 1);
if (object1.getSerializer () == copy.getSerializer ()) BOOST_FAIL ("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);
if (object1.getFieldVL (sfTestVL) != j) BOOST_FAIL ("STObject error");
if (object3.getFieldVL (sfTestVL) != j) BOOST_FAIL ("STObject error");
}
}
BOOST_AUTO_TEST_SUITE_END ();
// vim:ts=4

View File

@@ -0,0 +1,84 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
BOOST_AUTO_TEST_SUITE (SerializedObject)
BOOST_AUTO_TEST_CASE ( FieldManipulation_test )
{
if (sfGeneric.isUseful ())
BOOST_FAIL ("sfGeneric must not be useful");
SField sfTestVL (STI_VL, 255, "TestVL");
SField sfTestH256 (STI_HASH256, 255, "TestH256");
SField sfTestU32 (STI_UINT32, 255, "TestU32");
SField sfTestObject (STI_OBJECT, 255, "TestObject");
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);
if (object1.getSerializer () != object2.getSerializer ()) BOOST_FAIL ("STObject error 1");
if (object1.isFieldPresent (sfTestH256) || !object1.isFieldPresent (sfTestVL))
BOOST_FAIL ("STObject error");
object1.makeFieldPresent (sfTestH256);
if (!object1.isFieldPresent (sfTestH256)) BOOST_FAIL ("STObject Error 2");
if (object1.getFieldH256 (sfTestH256) != uint256 ()) BOOST_FAIL ("STObject error 3");
if (object1.getSerializer () == object2.getSerializer ())
{
WriteLog (lsINFO, STObject) << "O1: " << object1.getJson (0);
WriteLog (lsINFO, STObject) << "O2: " << object2.getJson (0);
BOOST_FAIL ("STObject error 4");
}
object1.makeFieldAbsent (sfTestH256);
if (object1.isFieldPresent (sfTestH256)) BOOST_FAIL ("STObject error 5");
if (object1.getFlags () != 0) BOOST_FAIL ("STObject error 6");
if (object1.getSerializer () != object2.getSerializer ()) BOOST_FAIL ("STObject error 7");
STObject copy (object1);
if (object1.isFieldPresent (sfTestH256)) BOOST_FAIL ("STObject error 8");
if (copy.isFieldPresent (sfTestH256)) BOOST_FAIL ("STObject error 9");
if (object1.getSerializer () != copy.getSerializer ()) BOOST_FAIL ("STObject error 10");
copy.setFieldU32 (sfTestU32, 1);
if (object1.getSerializer () == copy.getSerializer ()) BOOST_FAIL ("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);
if (object1.getFieldVL (sfTestVL) != j) BOOST_FAIL ("STObject error");
if (object3.getFieldVL (sfTestVL) != j) BOOST_FAIL ("STObject error");
}
}
BOOST_AUTO_TEST_SUITE_END ();

View File

@@ -727,6 +727,8 @@ public:
STAmount getRound () const;
void roundSelf ();
static void canonicalizeRound (bool isNative, uint64& value, int& offset, bool roundUp);
private:
template <class Iterator>

View File

@@ -704,24 +704,3 @@ Blob SerializerIterator::getRaw (int iLength)
return mSerializer.getRaw (iPos, iLength);
}
BOOST_AUTO_TEST_SUITE (Serializer_suite)
BOOST_AUTO_TEST_CASE ( Serializer_PrefixHash_test )
{
Serializer s1;
s1.add32 (3);
s1.add256 (uint256 ());
Serializer s2;
s2.add32 (0x12345600);
s2.addRaw (s1.peekData ());
if (s1.getPrefixHash (0x12345600) != s2.getSHA512Half ())
BOOST_FAIL ("Prefix hash does not work");
}
BOOST_AUTO_TEST_SUITE_END ();
// vim:ts=4

View File

@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
BOOST_AUTO_TEST_SUITE (Serializer_suite)
BOOST_AUTO_TEST_CASE ( Serializer_PrefixHash_test )
{
Serializer s1;
s1.add32 (3);
s1.add256 (uint256 ());
Serializer s2;
s2.add32 (0x12345600);
s2.addRaw (s1.peekData ());
if (s1.getPrefixHash (0x12345600) != s2.getSHA512Half ())
BOOST_FAIL ("Prefix hash does not work");
}
BOOST_AUTO_TEST_SUITE_END ();

View File

@@ -97,6 +97,13 @@ static const uint64 tenTo17m1 = tenTo17 - 1;
}
#endif
// These must be outside the namespace because of boost
#include "crypto/ripple_CKeyDeterministicUnitTests.cpp"
#include "protocol/ripple_RippleAddressUnitTests.cpp"
#include "protocol/ripple_SerializedObjectUnitTests.cpp"
#include "protocol/ripple_SerializerUnitTests.cpp"
#include "protocol/ripple_STAmountUnitTests.cpp"
// VFALCO TODO Fix this for SConstruct
#if BEAST_MSVC
#include "ripple.pb.cc"