mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Convert unit tests to beast
This commit is contained in:
@@ -289,12 +289,6 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\misc\ripple_SerializedTransactionUnitTests.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\misc\ripple_Validations.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -529,24 +523,12 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\shamap\ripple_SHAMapSyncUnitTests.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\shamap\ripple_SHAMapTreeNode.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\shamap\ripple_SHAMapUnitTests.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\tx\AccountSetTransactor.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -649,12 +631,6 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_basics\containers\ripple_RangeSetUnitTests.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_basics\containers\ripple_TaggedCache.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -716,12 +692,6 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_basics\utility\ripple_StringUtilitiesUnitTests.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_basics\utility\ripple_Sustain.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -790,12 +760,6 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_core\functional\ripple_LoadFeeTrackUnitTests.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_core\functional\ripple_LoadMonitor.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -857,12 +821,6 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\crypto\ripple_CKeyDeterministicUnitTests.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\crypto\ripple_CKeyECIES.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -899,12 +857,6 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_RippleAddressUnitTests.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_SerializedObject.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -917,12 +869,6 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_SerializedObjectUnitTests.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_SerializedTypes.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -935,12 +881,6 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_SerializerUnitTests.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_STAmount.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -953,12 +893,6 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_STAmountUnitTests.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_TER.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
|
||||
@@ -189,9 +189,6 @@
|
||||
<ClCompile Include="..\..\modules\ripple_basics\containers\ripple_RangeSet.cpp">
|
||||
<Filter>[1] Ripple\ripple_basics\containers</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_basics\containers\ripple_RangeSetUnitTests.cpp">
|
||||
<Filter>[1] Ripple\ripple_basics\containers</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_basics\containers\ripple_TaggedCache.cpp">
|
||||
<Filter>[1] Ripple\ripple_basics\containers</Filter>
|
||||
</ClCompile>
|
||||
@@ -219,9 +216,6 @@
|
||||
<ClCompile Include="..\..\modules\ripple_basics\utility\ripple_StringUtilities.cpp">
|
||||
<Filter>[1] Ripple\ripple_basics\utility</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_basics\utility\ripple_StringUtilitiesUnitTests.cpp">
|
||||
<Filter>[1] Ripple\ripple_basics\utility</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_basics\utility\ripple_Sustain.cpp">
|
||||
<Filter>[1] Ripple\ripple_basics\utility</Filter>
|
||||
</ClCompile>
|
||||
@@ -252,9 +246,6 @@
|
||||
<ClCompile Include="..\..\modules\ripple_core\functional\ripple_LoadFeeTrack.cpp">
|
||||
<Filter>[1] Ripple\ripple_core\functional</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_core\functional\ripple_LoadFeeTrackUnitTests.cpp">
|
||||
<Filter>[1] Ripple\ripple_core\functional</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_core\functional\ripple_LoadMonitor.cpp">
|
||||
<Filter>[1] Ripple\ripple_core\functional</Filter>
|
||||
</ClCompile>
|
||||
@@ -276,9 +267,6 @@
|
||||
<ClCompile Include="..\..\modules\ripple_data\crypto\ripple_CKeyDeterministic.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\crypto</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\crypto\ripple_CKeyDeterministicUnitTests.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\crypto</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\crypto\ripple_CKeyECIES.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\crypto</Filter>
|
||||
</ClCompile>
|
||||
@@ -294,36 +282,24 @@
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_RippleAddress.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_RippleAddressUnitTests.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_SerializedObject.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_SerializedObjectTemplate.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_SerializedObjectUnitTests.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_SerializedTypes.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_Serializer.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_SerializerUnitTests.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_STAmount.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_STAmountRound.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_STAmountUnitTests.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_TER.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
@@ -753,9 +729,6 @@
|
||||
<ClCompile Include="..\..\modules\ripple_app\misc\ripple_SerializedTransaction.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\misc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\misc\ripple_SerializedTransactionUnitTests.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\misc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\misc\ripple_Validations.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\misc</Filter>
|
||||
</ClCompile>
|
||||
@@ -843,15 +816,9 @@
|
||||
<ClCompile Include="..\..\modules\ripple_app\shamap\ripple_SHAMapSyncFilters.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\shamap</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\shamap\ripple_SHAMapSyncUnitTests.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\shamap</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\shamap\ripple_SHAMapTreeNode.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\shamap</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\shamap\ripple_SHAMapUnitTests.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\shamap</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\consensus\ripple_LedgerConsensus.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\consensus</Filter>
|
||||
</ClCompile>
|
||||
|
||||
@@ -1914,3 +1914,25 @@ std::vector<uint256> Ledger::getNeededAccountStateHashes (int max, SHAMapSyncFil
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class LedgerTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
LedgerTests () : UnitTest ("Ledger", "ripple")
|
||||
{
|
||||
}
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
beginTest ("uint256");
|
||||
|
||||
uint256 uBig ("D2DC44E5DC189318DB36EF87D2104CDF0A0FE3A4B698BEEE55038D7EA4C68000");
|
||||
|
||||
// VFALCO NOTE This fails in the original version as well.
|
||||
expect (6125895493223874560 == Ledger::getQuality (uBig));
|
||||
}
|
||||
};
|
||||
|
||||
static LedgerTests ledgerTests;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
BOOST_AUTO_TEST_SUITE (quality)
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( getquality )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
uint256 uBig ("D2DC44E5DC189318DB36EF87D2104CDF0A0FE3A4B698BEEE55038D7EA4C68000");
|
||||
|
||||
if (6125895493223874560 != Ledger::getQuality (uBig))
|
||||
BOOST_FAIL ("Ledger::getQuality fails.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END ()
|
||||
@@ -152,6 +152,18 @@ public:
|
||||
*/
|
||||
static void runBeastUnitTests (std::string const& individualTest = "")
|
||||
{
|
||||
// VFALCO NOTE It sucks that we have to do this but some
|
||||
// code demands the Application object exists.
|
||||
//
|
||||
// To find out who, just change the #if
|
||||
#if 1
|
||||
{
|
||||
setupConfigForUnitTests (&theConfig);
|
||||
|
||||
getApp ();
|
||||
}
|
||||
#endif
|
||||
|
||||
RippleUnitTests tr;
|
||||
|
||||
tr.setAssertOnFailure (false);
|
||||
@@ -169,23 +181,6 @@ static void runBeastUnitTests (std::string const& individualTest = "")
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Run the Boost unit tests.
|
||||
|
||||
@note These are deprecated. We want to migrate to using only
|
||||
the Beast unit testing framework. Please do not add more
|
||||
Boost based unit tests.
|
||||
*/
|
||||
// VFALCO NOTE What are argc and argv for?
|
||||
// Where does the boost unit test framework write its output?
|
||||
//
|
||||
static void runBoostUnitTests (int argc, char* argv [])
|
||||
{
|
||||
// DEPRECATED
|
||||
boost::unit_test::unit_test_main (init_unit_test, argc, argv);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int rippleMain (int argc, char** argv)
|
||||
{
|
||||
//
|
||||
@@ -247,8 +242,7 @@ int rippleMain (int argc, char** argv)
|
||||
("rpc_port", po::value <int> (), "Specify the port number for RPC command.")
|
||||
("standalone,a", "Run with no peers.")
|
||||
("testnet,t", "Run in test net mode.")
|
||||
("unittest,u", "Perform unit tests.")
|
||||
("unittest2", po::value <std::string> ()->implicit_value (""), "Perform new unit tests.")
|
||||
("unittest,u", po::value <std::string> ()->implicit_value (""), "Perform unit tests.")
|
||||
("parameters", po::value< vector<string> > (), "Specify comma separated parameters.")
|
||||
("quiet,q", "Reduce diagnotics.")
|
||||
("verbose,v", "Verbose logging.")
|
||||
@@ -341,16 +335,7 @@ int rippleMain (int argc, char** argv)
|
||||
//
|
||||
if (vm.count ("unittest"))
|
||||
{
|
||||
runBeastUnitTests ();
|
||||
|
||||
// DEPRECATED
|
||||
runBoostUnitTests (argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vm.count ("unittest2"))
|
||||
{
|
||||
std::string const test = vm ["unittest2"].as <std::string> ();
|
||||
std::string const test = vm ["unittest"].as <std::string> ();
|
||||
|
||||
runBeastUnitTests (test);
|
||||
|
||||
|
||||
@@ -287,3 +287,57 @@ std::string SerializedTransaction::getMetaSQL (Serializer rawTxn, uint32 inLedge
|
||||
% getTransactionID ().GetHex () % getTransactionType () % getSourceAccount ().humanAccountID ()
|
||||
% getSequence () % inLedger % status % rTxn % escapedMetaData);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class SerializedTransactionTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
SerializedTransactionTests () : UnitTest ("SerializedTransaction", "ripple")
|
||||
{
|
||||
}
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
beginTest ("tx");
|
||||
|
||||
RippleAddress seed;
|
||||
seed.setSeedRandom ();
|
||||
RippleAddress generator = RippleAddress::createGeneratorPublic (seed);
|
||||
RippleAddress publicAcct = RippleAddress::createAccountPublic (generator, 1);
|
||||
RippleAddress privateAcct = RippleAddress::createAccountPrivate (generator, seed, 1);
|
||||
|
||||
SerializedTransaction j (ttACCOUNT_SET);
|
||||
j.setSourceAccount (publicAcct);
|
||||
j.setSigningPubKey (publicAcct);
|
||||
j.setFieldVL (sfMessageKey, publicAcct.getAccountPublic ());
|
||||
j.sign (privateAcct);
|
||||
|
||||
if (!j.checkSign ()) fail ("Transaction fails signature test");
|
||||
|
||||
Serializer rawTxn;
|
||||
j.add (rawTxn);
|
||||
SerializerIterator sit (rawTxn);
|
||||
SerializedTransaction copy (sit);
|
||||
|
||||
if (copy != j)
|
||||
{
|
||||
Log (lsFATAL) << j.getJson (0);
|
||||
Log (lsFATAL) << copy.getJson (0);
|
||||
fail ("Transaction fails serialize/deserialize test");
|
||||
}
|
||||
|
||||
UPTR_T<STObject> new_obj = STObject::parseJson (j.getJson (0), sfGeneric);
|
||||
|
||||
if (new_obj.get () == NULL) fail ("Unable to build object from json");
|
||||
|
||||
if (STObject (j) != *new_obj)
|
||||
{
|
||||
Log (lsINFO) << "ORIG: " << j.getJson (0);
|
||||
Log (lsINFO) << "BUILT " << new_obj->getJson (0);
|
||||
fail ("Built a different transaction");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static SerializedTransactionTests serializedTransactionTests;
|
||||
@@ -1,50 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
BOOST_AUTO_TEST_SUITE (SerializedTransactionTS)
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( STrans_test )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
RippleAddress seed;
|
||||
seed.setSeedRandom ();
|
||||
RippleAddress generator = RippleAddress::createGeneratorPublic (seed);
|
||||
RippleAddress publicAcct = RippleAddress::createAccountPublic (generator, 1);
|
||||
RippleAddress privateAcct = RippleAddress::createAccountPrivate (generator, seed, 1);
|
||||
|
||||
SerializedTransaction j (ttACCOUNT_SET);
|
||||
j.setSourceAccount (publicAcct);
|
||||
j.setSigningPubKey (publicAcct);
|
||||
j.setFieldVL (sfMessageKey, publicAcct.getAccountPublic ());
|
||||
j.sign (privateAcct);
|
||||
|
||||
if (!j.checkSign ()) BOOST_FAIL ("Transaction fails signature test");
|
||||
|
||||
Serializer rawTxn;
|
||||
j.add (rawTxn);
|
||||
SerializerIterator sit (rawTxn);
|
||||
SerializedTransaction copy (sit);
|
||||
|
||||
if (copy != j)
|
||||
{
|
||||
Log (lsFATAL) << j.getJson (0);
|
||||
Log (lsFATAL) << copy.getJson (0);
|
||||
BOOST_FAIL ("Transaction fails serialize/deserialize test");
|
||||
}
|
||||
|
||||
UPTR_T<STObject> new_obj = STObject::parseJson (j.getJson (0), sfGeneric);
|
||||
|
||||
if (new_obj.get () == NULL) BOOST_FAIL ("Unable to build object from json");
|
||||
|
||||
if (STObject (j) != *new_obj)
|
||||
{
|
||||
Log (lsINFO) << "ORIG: " << j.getJson (0);
|
||||
Log (lsINFO) << "BUILT " << new_obj->getJson (0);
|
||||
BOOST_FAIL ("Built a different transaction");
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END ();
|
||||
@@ -425,19 +425,6 @@ static DH* handleTmpDh (SSL* ssl, int is_export, int iKeyLength)
|
||||
|
||||
#if ! defined (RIPPLE_MAIN_PART) || RIPPLE_MAIN_PART == 8
|
||||
|
||||
// Unit Tests
|
||||
//
|
||||
// These must be outside the namespace
|
||||
//
|
||||
// VFALCO TODO Eliminate the need for boost for unit tests.
|
||||
//
|
||||
#include "ledger/LedgerUnitTests.cpp"
|
||||
#include "shamap/ripple_SHAMapUnitTests.cpp"
|
||||
#include "shamap/ripple_SHAMapSyncUnitTests.cpp"
|
||||
#include "misc/ripple_SerializedTransactionUnitTests.cpp"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ripple
|
||||
{
|
||||
extern int rippleMain (int argc, char** argv);
|
||||
|
||||
@@ -1050,3 +1050,98 @@ void SHAMap::dump (bool hash)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class SHAMapTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
SHAMapTests () : UnitTest ("SHAMap", "ripple")
|
||||
{
|
||||
}
|
||||
|
||||
// VFALCO TODO Rename this to createFilledVector and pass an unsigned char, tidy up
|
||||
//
|
||||
static Blob IntToVUC (int v)
|
||||
{
|
||||
Blob vuc;
|
||||
|
||||
for (int i = 0; i < 32; ++i)
|
||||
vuc.push_back (static_cast<unsigned char> (v));
|
||||
|
||||
return vuc;
|
||||
}
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
beginTest ("add/traverse");
|
||||
|
||||
// h3 and h4 differ only in the leaf, same terminal node (level 19)
|
||||
uint256 h1, h2, h3, h4, h5;
|
||||
h1.SetHex ("092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
|
||||
h2.SetHex ("436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe");
|
||||
h3.SetHex ("b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
|
||||
h4.SetHex ("b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8");
|
||||
h5.SetHex ("a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
|
||||
|
||||
SHAMap sMap (smtFREE);
|
||||
SHAMapItem i1 (h1, IntToVUC (1)), i2 (h2, IntToVUC (2)), i3 (h3, IntToVUC (3)), i4 (h4, IntToVUC (4)), i5 (h5, IntToVUC (5));
|
||||
|
||||
if (!sMap.addItem (i2, true, false)) fail ("no add");
|
||||
|
||||
if (!sMap.addItem (i1, true, false)) fail ("no add");
|
||||
|
||||
SHAMapItem::pointer i;
|
||||
|
||||
i = sMap.peekFirstItem ();
|
||||
|
||||
if (!i || (*i != i1)) fail ("bad traverse");
|
||||
|
||||
i = sMap.peekNextItem (i->getTag ());
|
||||
|
||||
if (!i || (*i != i2)) fail ("bad traverse");
|
||||
|
||||
i = sMap.peekNextItem (i->getTag ());
|
||||
|
||||
if (i) fail ("bad traverse");
|
||||
|
||||
sMap.addItem (i4, true, false);
|
||||
sMap.delItem (i2.getTag ());
|
||||
sMap.addItem (i3, true, false);
|
||||
|
||||
i = sMap.peekFirstItem ();
|
||||
|
||||
if (!i || (*i != i1)) fail ("bad traverse");
|
||||
|
||||
i = sMap.peekNextItem (i->getTag ());
|
||||
|
||||
if (!i || (*i != i3)) fail ("bad traverse");
|
||||
|
||||
i = sMap.peekNextItem (i->getTag ());
|
||||
|
||||
if (!i || (*i != i4)) fail ("bad traverse");
|
||||
|
||||
i = sMap.peekNextItem (i->getTag ());
|
||||
|
||||
if (i) fail ("bad traverse");
|
||||
|
||||
|
||||
|
||||
beginTest ("snapshot");
|
||||
|
||||
uint256 mapHash = sMap.getHash ();
|
||||
SHAMap::pointer map2 = sMap.snapShot (false);
|
||||
|
||||
if (sMap.getHash () != mapHash) fail ("bad snapshot");
|
||||
|
||||
if (map2->getHash () != mapHash) fail ("bad snapshot");
|
||||
|
||||
if (!sMap.delItem (sMap.peekFirstItem ()->getTag ())) fail ("bad mod");
|
||||
|
||||
if (sMap.getHash () == mapHash) fail ("bad snapshot");
|
||||
|
||||
if (map2->getHash () != mapHash) fail ("bad snapshot");
|
||||
}
|
||||
};
|
||||
|
||||
static SHAMapTests shaMapTests;
|
||||
|
||||
@@ -590,3 +590,190 @@ std::list<Blob > SHAMap::getTrustedPath (uint256 const& index)
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef BEAST_DEBUG
|
||||
//#define SMS_DEBUG
|
||||
#endif
|
||||
|
||||
class SHAMapSyncTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
SHAMapSyncTests () : UnitTest ("SHAMapSync", "ripple")
|
||||
{
|
||||
}
|
||||
|
||||
static SHAMapItem::pointer makeRandomAS ()
|
||||
{
|
||||
Serializer s;
|
||||
|
||||
for (int d = 0; d < 3; ++d) s.add32 (rand ());
|
||||
|
||||
return boost::make_shared<SHAMapItem> (s.getRIPEMD160 ().to256 (), s.peekData ());
|
||||
}
|
||||
|
||||
static bool confuseMap (SHAMap& map, int count)
|
||||
{
|
||||
// add a bunch of random states to a map, then remove them
|
||||
// map should be the same
|
||||
uint256 beforeHash = map.getHash ();
|
||||
|
||||
std::list<uint256> items;
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
SHAMapItem::pointer item = makeRandomAS ();
|
||||
items.push_back (item->getTag ());
|
||||
|
||||
if (!map.addItem (*item, false, false))
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "Unable to add item to map";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (std::list<uint256>::iterator it = items.begin (); it != items.end (); ++it)
|
||||
{
|
||||
if (!map.delItem (*it))
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "Unable to remove item from map";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (beforeHash != map.getHash ())
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "Hashes do not match";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
beginTest ("sync");
|
||||
unsigned int seed;
|
||||
|
||||
// VFALCO TODO Replace this with beast::Random
|
||||
RAND_pseudo_bytes (reinterpret_cast<unsigned char*> (&seed), sizeof (seed));
|
||||
srand (seed);
|
||||
|
||||
SHAMap source (smtFREE), destination (smtFREE);
|
||||
|
||||
int items = 10000;
|
||||
for (int i = 0; i < items; ++i)
|
||||
source.addItem (*makeRandomAS (), false, false);
|
||||
|
||||
|
||||
|
||||
beginTest ("add/remove");
|
||||
|
||||
if (!confuseMap (source, 500)) fail ("ConfuseMap");
|
||||
|
||||
source.setImmutable ();
|
||||
|
||||
std::vector<SHAMapNode> nodeIDs, gotNodeIDs;
|
||||
std::list< Blob > gotNodes;
|
||||
std::vector<uint256> hashes;
|
||||
|
||||
std::vector<SHAMapNode>::iterator nodeIDIterator;
|
||||
std::list< Blob >::iterator rawNodeIterator;
|
||||
|
||||
int passes = 0;
|
||||
int nodes = 0;
|
||||
|
||||
destination.setSynching ();
|
||||
|
||||
if (!source.getNodeFat (SHAMapNode (), nodeIDs, gotNodes, (rand () % 2) == 0, (rand () % 2) == 0))
|
||||
{
|
||||
fail ("GetNodeFat");
|
||||
}
|
||||
|
||||
if (gotNodes.size () < 1)
|
||||
{
|
||||
fail ("NodeSize");
|
||||
}
|
||||
|
||||
if (!destination.addRootNode (*gotNodes.begin (), snfWIRE, NULL))
|
||||
{
|
||||
fail ("AddRootNode");
|
||||
}
|
||||
|
||||
nodeIDs.clear ();
|
||||
gotNodes.clear ();
|
||||
|
||||
#ifdef SMS_DEBUG
|
||||
int bytes = 0;
|
||||
#endif
|
||||
|
||||
do
|
||||
{
|
||||
++passes;
|
||||
hashes.clear ();
|
||||
|
||||
// get the list of nodes we know we need
|
||||
destination.getMissingNodes (nodeIDs, hashes, 2048, NULL);
|
||||
|
||||
if (nodeIDs.empty ()) break;
|
||||
|
||||
// get as many nodes as possible based on this information
|
||||
for (nodeIDIterator = nodeIDs.begin (); nodeIDIterator != nodeIDs.end (); ++nodeIDIterator)
|
||||
{
|
||||
if (!source.getNodeFat (*nodeIDIterator, gotNodeIDs, gotNodes, (rand () % 2) == 0, (rand () % 2) == 0))
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "GetNodeFat fails";
|
||||
fail ("GetNodeFat");
|
||||
}
|
||||
}
|
||||
|
||||
assert (gotNodeIDs.size () == gotNodes.size ());
|
||||
nodeIDs.clear ();
|
||||
hashes.clear ();
|
||||
|
||||
if (gotNodeIDs.empty ())
|
||||
{
|
||||
fail ("Got Node ID");
|
||||
}
|
||||
|
||||
for (nodeIDIterator = gotNodeIDs.begin (), rawNodeIterator = gotNodes.begin ();
|
||||
nodeIDIterator != gotNodeIDs.end (); ++nodeIDIterator, ++rawNodeIterator)
|
||||
{
|
||||
++nodes;
|
||||
#ifdef SMS_DEBUG
|
||||
bytes += rawNodeIterator->size ();
|
||||
#endif
|
||||
|
||||
if (!destination.addKnownNode (*nodeIDIterator, *rawNodeIterator, NULL))
|
||||
{
|
||||
WriteLog (lsTRACE, SHAMap) << "AddKnownNode fails";
|
||||
fail ("AddKnownNode");
|
||||
}
|
||||
}
|
||||
|
||||
gotNodeIDs.clear ();
|
||||
gotNodes.clear ();
|
||||
}
|
||||
while (true);
|
||||
|
||||
destination.clearSynching ();
|
||||
|
||||
#ifdef SMS_DEBUG
|
||||
WriteLog (lsINFO, SHAMap) << "SYNCHING COMPLETE " << items << " items, " << nodes << " nodes, " <<
|
||||
bytes / 1024 << " KB";
|
||||
#endif
|
||||
|
||||
if (!source.deepCompare (destination))
|
||||
{
|
||||
fail ("Deep Compare");
|
||||
}
|
||||
|
||||
#ifdef SMS_DEBUG
|
||||
WriteLog (lsINFO, SHAMap) << "SHAMapSync test passed: " << items << " items, " <<
|
||||
passes << " passes, " << nodes << " nodes";
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
static SHAMapSyncTests shaMapSyncTests;
|
||||
|
||||
@@ -1,206 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifdef BEAST_DEBUG
|
||||
#define SMS_DEBUG
|
||||
#endif
|
||||
|
||||
namespace ripple
|
||||
{
|
||||
|
||||
static SHAMapItem::pointer makeRandomAS ()
|
||||
{
|
||||
Serializer s;
|
||||
|
||||
for (int d = 0; d < 3; ++d) s.add32 (rand ());
|
||||
|
||||
return boost::make_shared<SHAMapItem> (s.getRIPEMD160 ().to256 (), s.peekData ());
|
||||
}
|
||||
|
||||
static bool confuseMap (SHAMap& map, int count)
|
||||
{
|
||||
// add a bunch of random states to a map, then remove them
|
||||
// map should be the same
|
||||
uint256 beforeHash = map.getHash ();
|
||||
|
||||
std::list<uint256> items;
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
SHAMapItem::pointer item = makeRandomAS ();
|
||||
items.push_back (item->getTag ());
|
||||
|
||||
if (!map.addItem (*item, false, false))
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "Unable to add item to map";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (std::list<uint256>::iterator it = items.begin (); it != items.end (); ++it)
|
||||
{
|
||||
if (!map.delItem (*it))
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "Unable to remove item from map";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (beforeHash != map.getHash ())
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "Hashes do not match";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE ( SHAMapSync )
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( SHAMapSync_test )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
WriteLog (lsTRACE, SHAMap) << "begin sync test";
|
||||
unsigned int seed;
|
||||
RAND_pseudo_bytes (reinterpret_cast<unsigned char*> (&seed), sizeof (seed));
|
||||
srand (seed);
|
||||
|
||||
WriteLog (lsTRACE, SHAMap) << "Constructing maps";
|
||||
SHAMap source (smtFREE), destination (smtFREE);
|
||||
|
||||
// add random data to the source map
|
||||
WriteLog (lsTRACE, SHAMap) << "Adding random data";
|
||||
int items = 10000;
|
||||
|
||||
for (int i = 0; i < items; ++i)
|
||||
source.addItem (*makeRandomAS (), false, false);
|
||||
|
||||
WriteLog (lsTRACE, SHAMap) << "Adding items, then removing them";
|
||||
|
||||
if (!confuseMap (source, 500)) BOOST_FAIL ("ConfuseMap");
|
||||
|
||||
source.setImmutable ();
|
||||
|
||||
WriteLog (lsTRACE, SHAMap) << "SOURCE COMPLETE, SYNCHING";
|
||||
|
||||
std::vector<SHAMapNode> nodeIDs, gotNodeIDs;
|
||||
std::list< Blob > gotNodes;
|
||||
std::vector<uint256> hashes;
|
||||
|
||||
std::vector<SHAMapNode>::iterator nodeIDIterator;
|
||||
std::list< Blob >::iterator rawNodeIterator;
|
||||
|
||||
int passes = 0;
|
||||
int nodes = 0;
|
||||
|
||||
destination.setSynching ();
|
||||
|
||||
if (!source.getNodeFat (SHAMapNode (), nodeIDs, gotNodes, (rand () % 2) == 0, (rand () % 2) == 0))
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "GetNodeFat(root) fails";
|
||||
BOOST_FAIL ("GetNodeFat");
|
||||
}
|
||||
|
||||
if (gotNodes.size () < 1)
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "Didn't get root node " << gotNodes.size ();
|
||||
BOOST_FAIL ("NodeSize");
|
||||
}
|
||||
|
||||
if (!destination.addRootNode (*gotNodes.begin (), snfWIRE, NULL))
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "AddRootNode fails";
|
||||
BOOST_FAIL ("AddRootNode");
|
||||
}
|
||||
|
||||
nodeIDs.clear ();
|
||||
gotNodes.clear ();
|
||||
|
||||
WriteLog (lsINFO, SHAMap) << "ROOT COMPLETE, INNER SYNCHING";
|
||||
#ifdef SMS_DEBUG
|
||||
int bytes = 0;
|
||||
#endif
|
||||
|
||||
do
|
||||
{
|
||||
++passes;
|
||||
hashes.clear ();
|
||||
|
||||
// get the list of nodes we know we need
|
||||
destination.getMissingNodes (nodeIDs, hashes, 2048, NULL);
|
||||
|
||||
if (nodeIDs.empty ()) break;
|
||||
|
||||
WriteLog (lsINFO, SHAMap) << nodeIDs.size () << " needed nodes";
|
||||
|
||||
// get as many nodes as possible based on this information
|
||||
for (nodeIDIterator = nodeIDs.begin (); nodeIDIterator != nodeIDs.end (); ++nodeIDIterator)
|
||||
{
|
||||
if (!source.getNodeFat (*nodeIDIterator, gotNodeIDs, gotNodes, (rand () % 2) == 0, (rand () % 2) == 0))
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "GetNodeFat fails";
|
||||
BOOST_FAIL ("GetNodeFat");
|
||||
}
|
||||
}
|
||||
|
||||
assert (gotNodeIDs.size () == gotNodes.size ());
|
||||
nodeIDs.clear ();
|
||||
hashes.clear ();
|
||||
|
||||
if (gotNodeIDs.empty ())
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "No nodes gotten";
|
||||
BOOST_FAIL ("Got Node ID");
|
||||
}
|
||||
|
||||
WriteLog (lsTRACE, SHAMap) << gotNodeIDs.size () << " found nodes";
|
||||
|
||||
for (nodeIDIterator = gotNodeIDs.begin (), rawNodeIterator = gotNodes.begin ();
|
||||
nodeIDIterator != gotNodeIDs.end (); ++nodeIDIterator, ++rawNodeIterator)
|
||||
{
|
||||
++nodes;
|
||||
#ifdef SMS_DEBUG
|
||||
bytes += rawNodeIterator->size ();
|
||||
#endif
|
||||
|
||||
if (!destination.addKnownNode (*nodeIDIterator, *rawNodeIterator, NULL))
|
||||
{
|
||||
WriteLog (lsTRACE, SHAMap) << "AddKnownNode fails";
|
||||
BOOST_FAIL ("AddKnownNode");
|
||||
}
|
||||
}
|
||||
|
||||
gotNodeIDs.clear ();
|
||||
gotNodes.clear ();
|
||||
|
||||
|
||||
}
|
||||
while (1);
|
||||
|
||||
destination.clearSynching ();
|
||||
|
||||
#ifdef SMS_DEBUG
|
||||
WriteLog (lsINFO, SHAMap) << "SYNCHING COMPLETE " << items << " items, " << nodes << " nodes, " <<
|
||||
bytes / 1024 << " KB";
|
||||
#endif
|
||||
|
||||
if (!source.deepCompare (destination))
|
||||
{
|
||||
WriteLog (lsFATAL, SHAMap) << "DeepCompare fails";
|
||||
BOOST_FAIL ("Deep Compare");
|
||||
}
|
||||
|
||||
#ifdef SMS_DEBUG
|
||||
WriteLog (lsINFO, SHAMap) << "SHAMapSync test passed: " << items << " items, " <<
|
||||
passes << " passes, " << nodes << " nodes";
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END ();
|
||||
@@ -1,93 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
// VFALCO TODO Rename this to createFilledVector and pass an unsigned char, tidy up
|
||||
//
|
||||
namespace ripple
|
||||
{
|
||||
static Blob IntToVUC (int v)
|
||||
{
|
||||
Blob vuc;
|
||||
|
||||
for (int i = 0; i < 32; ++i)
|
||||
vuc.push_back (static_cast<unsigned char> (v));
|
||||
|
||||
return vuc;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE (SHAMap_suite)
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( SHAMap_test )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
// h3 and h4 differ only in the leaf, same terminal node (level 19)
|
||||
WriteLog (lsTRACE, SHAMap) << "SHAMap test";
|
||||
uint256 h1, h2, h3, h4, h5;
|
||||
h1.SetHex ("092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
|
||||
h2.SetHex ("436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe");
|
||||
h3.SetHex ("b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
|
||||
h4.SetHex ("b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8");
|
||||
h5.SetHex ("a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
|
||||
|
||||
SHAMap sMap (smtFREE);
|
||||
SHAMapItem i1 (h1, IntToVUC (1)), i2 (h2, IntToVUC (2)), i3 (h3, IntToVUC (3)), i4 (h4, IntToVUC (4)), i5 (h5, IntToVUC (5));
|
||||
|
||||
if (!sMap.addItem (i2, true, false)) BOOST_FAIL ("no add");
|
||||
|
||||
if (!sMap.addItem (i1, true, false)) BOOST_FAIL ("no add");
|
||||
|
||||
SHAMapItem::pointer i;
|
||||
|
||||
i = sMap.peekFirstItem ();
|
||||
|
||||
if (!i || (*i != i1)) BOOST_FAIL ("bad traverse");
|
||||
|
||||
i = sMap.peekNextItem (i->getTag ());
|
||||
|
||||
if (!i || (*i != i2)) BOOST_FAIL ("bad traverse");
|
||||
|
||||
i = sMap.peekNextItem (i->getTag ());
|
||||
|
||||
if (i) BOOST_FAIL ("bad traverse");
|
||||
|
||||
sMap.addItem (i4, true, false);
|
||||
sMap.delItem (i2.getTag ());
|
||||
sMap.addItem (i3, true, false);
|
||||
|
||||
i = sMap.peekFirstItem ();
|
||||
|
||||
if (!i || (*i != i1)) BOOST_FAIL ("bad traverse");
|
||||
|
||||
i = sMap.peekNextItem (i->getTag ());
|
||||
|
||||
if (!i || (*i != i3)) BOOST_FAIL ("bad traverse");
|
||||
|
||||
i = sMap.peekNextItem (i->getTag ());
|
||||
|
||||
if (!i || (*i != i4)) BOOST_FAIL ("bad traverse");
|
||||
|
||||
i = sMap.peekNextItem (i->getTag ());
|
||||
|
||||
if (i) BOOST_FAIL ("bad traverse");
|
||||
|
||||
WriteLog (lsTRACE, SHAMap) << "SHAMap snap test";
|
||||
uint256 mapHash = sMap.getHash ();
|
||||
SHAMap::pointer map2 = sMap.snapShot (false);
|
||||
|
||||
if (sMap.getHash () != mapHash) BOOST_FAIL ("bad snapshot");
|
||||
|
||||
if (map2->getHash () != mapHash) BOOST_FAIL ("bad snapshot");
|
||||
|
||||
if (!sMap.delItem (sMap.peekFirstItem ()->getTag ())) BOOST_FAIL ("bad mod");
|
||||
|
||||
if (sMap.getHash () == mapHash) BOOST_FAIL ("bad snapshot");
|
||||
|
||||
if (map2->getHash () != mapHash) BOOST_FAIL ("bad snapshot");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END ();
|
||||
@@ -260,3 +260,36 @@ void RangeSet::checkInternalConsistency () const noexcept
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class RangeSetTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
RangeSetTests () : UnitTest ("RangeSet", "ripple")
|
||||
{
|
||||
}
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
beginTest ("membership");
|
||||
|
||||
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);
|
||||
|
||||
expect (!r1.hasValue (5));
|
||||
|
||||
expect (r2.hasValue (9));
|
||||
|
||||
// TODO: Traverse functions must be tested
|
||||
}
|
||||
};
|
||||
|
||||
static RangeSetTests rangeSetTests;
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
BOOST_AUTO_TEST_SUITE (RangeSet_suite)
|
||||
|
||||
BOOST_AUTO_TEST_CASE (RangeSet_test)
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
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 ()
|
||||
@@ -27,8 +27,6 @@
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
//#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
// VFALCO TODO Replace OpenSSL randomness with a dependency-free implementation
|
||||
// Perhaps Schneier's Fortuna or a variant. Abstract the collection of
|
||||
// entropy and provide OS-specific implementation. We can re-use the
|
||||
@@ -45,10 +43,6 @@
|
||||
#include <Winsock2.h> // for ripple_ByteOrder.cpp
|
||||
#endif
|
||||
|
||||
// This brings in the definitions for the Unit Test Framework.
|
||||
//
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
namespace ripple
|
||||
{
|
||||
|
||||
@@ -73,7 +67,3 @@ namespace ripple
|
||||
#include "types/ripple_UInt256.cpp"
|
||||
|
||||
}
|
||||
|
||||
// These must be outside the namespace (because of boost)
|
||||
#include "containers/ripple_RangeSetUnitTests.cpp"
|
||||
#include "utility/ripple_StringUtilitiesUnitTests.cpp"
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
// This is better than setting it in some Makefile or IDE Project file.
|
||||
//
|
||||
#define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
#define BOOST_TEST_NO_LIB
|
||||
#define BOOST_TEST_ALTERNATIVE_INIT_API
|
||||
#define BOOST_TEST_NO_MAIN
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
@@ -47,7 +44,6 @@
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
|
||||
@@ -309,3 +309,61 @@ StringPairArray parseDelimitedKeyValueString (String parameters, beast_wchar del
|
||||
|
||||
return keyValues;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class StringUtilitiesTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
StringUtilitiesTests () : UnitTest ("StringUtilities", "ripple")
|
||||
{
|
||||
}
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
beginTest ("parseUrl");
|
||||
|
||||
std::string strScheme;
|
||||
std::string strDomain;
|
||||
int iPort;
|
||||
std::string strPath;
|
||||
|
||||
if (!parseUrl ("lower://domain", strScheme, strDomain, iPort, strPath))
|
||||
fail ("parseUrl: lower://domain failed");
|
||||
|
||||
if (strScheme != "lower")
|
||||
fail ("parseUrl: lower://domain : scheme failed");
|
||||
|
||||
if (strDomain != "domain")
|
||||
fail ("parseUrl: lower://domain : domain failed");
|
||||
|
||||
if (iPort != -1)
|
||||
fail ("parseUrl: lower://domain : port failed");
|
||||
|
||||
if (strPath != "")
|
||||
fail ("parseUrl: lower://domain : path failed");
|
||||
|
||||
if (!parseUrl ("UPPER://domain:234/", strScheme, strDomain, iPort, strPath))
|
||||
fail ("parseUrl: UPPER://domain:234/ failed");
|
||||
|
||||
if (strScheme != "upper")
|
||||
fail ("parseUrl: UPPER://domain:234/ : scheme failed");
|
||||
|
||||
if (iPort != 234)
|
||||
fail (boost::str (boost::format ("parseUrl: UPPER://domain:234/ : port failed: %d") % iPort));
|
||||
|
||||
if (strPath != "/")
|
||||
fail ("parseUrl: UPPER://domain:234/ : path failed");
|
||||
|
||||
if (!parseUrl ("Mixed://domain/path", strScheme, strDomain, iPort, strPath))
|
||||
fail ("parseUrl: Mixed://domain/path failed");
|
||||
|
||||
if (strScheme != "mixed")
|
||||
fail ("parseUrl: Mixed://domain/path tolower failed");
|
||||
|
||||
if (strPath != "/path")
|
||||
fail ("parseUrl: Mixed://domain/path path failed");
|
||||
}
|
||||
};
|
||||
|
||||
static StringUtilitiesTests stringUtilitiesTests;
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
BOOST_AUTO_TEST_SUITE ( Utils)
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( ParseUrl )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
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 ()
|
||||
@@ -8,3 +8,35 @@ ILoadFeeTrack* ILoadFeeTrack::New ()
|
||||
{
|
||||
return new LoadFeeTrack;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class LoadFeeTrackTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
LoadFeeTrackTests () : UnitTest ("LoadFeeTrack", "ripple")
|
||||
{
|
||||
}
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
Config d; // get a default configuration object
|
||||
LoadFeeTrack l;
|
||||
|
||||
expect (l.scaleFeeBase (10000, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 10000);
|
||||
expect (l.scaleFeeLoad (10000, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE, false) == 10000);
|
||||
expect (l.scaleFeeBase (1, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 1);
|
||||
expect (l.scaleFeeLoad (1, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE, false) == 1);
|
||||
|
||||
// Check new default fee values give same fees as old defaults
|
||||
expect (l.scaleFeeBase (d.FEE_DEFAULT, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 10);
|
||||
expect (l.scaleFeeBase (d.FEE_ACCOUNT_RESERVE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 200 * SYSTEM_CURRENCY_PARTS);
|
||||
expect (l.scaleFeeBase (d.FEE_OWNER_RESERVE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 50 * SYSTEM_CURRENCY_PARTS);
|
||||
expect (l.scaleFeeBase (d.FEE_NICKNAME_CREATE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 1000);
|
||||
expect (l.scaleFeeBase (d.FEE_OFFER, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 10);
|
||||
expect (l.scaleFeeBase (d.FEE_CONTRACT_OPERATION, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static LoadFeeTrackTests loadFeeTrackTests;
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
BOOST_AUTO_TEST_SUITE (LoadManager_test)
|
||||
|
||||
BOOST_AUTO_TEST_CASE (LoadFeeTrack_test)
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
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 ()
|
||||
@@ -38,7 +38,3 @@ namespace ripple
|
||||
#include "validator/ripple_TrustedUriValidatorSource.cpp"
|
||||
|
||||
}
|
||||
|
||||
// These must be outside the namespace
|
||||
|
||||
#include "functional/ripple_LoadFeeTrackUnitTests.cpp"
|
||||
|
||||
@@ -10,4 +10,43 @@
|
||||
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
|
||||
// VFALCO TODO move inlined stuff from CKey into here
|
||||
// VFALCO TODO move inlined stuff from CKey into here
|
||||
|
||||
class CKeyTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
CKeyTests () : UnitTest ("CKey", "ripple")
|
||||
{
|
||||
}
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
beginTest ("determinism");
|
||||
|
||||
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")
|
||||
fail ("Incorrect private key for generator");
|
||||
|
||||
if (priv2.GetHex () != "98BC2EACB26EB021D1A6293C044D88BA2F0B6729A2772DEEBF2E21A263C1740B")
|
||||
fail ("Incorrect private key for generator");
|
||||
|
||||
RippleAddress nSeed;
|
||||
nSeed.setSeed (seed1);
|
||||
|
||||
if (nSeed.humanSeed () != "shHM53KPZ87Gwdqarm1bAmPeXg8Tn")
|
||||
fail ("Incorrect human seed");
|
||||
|
||||
if (nSeed.humanSeed1751 () != "MAD BODY ACE MINT OKAY HUB WHAT DATA SACK FLAT DANA MATH")
|
||||
fail ("Incorrect 1751 seed");
|
||||
}
|
||||
};
|
||||
|
||||
static CKeyTests cKeyTests;
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
BOOST_AUTO_TEST_SUITE (DeterministicKeys_test)
|
||||
|
||||
BOOST_AUTO_TEST_CASE (DeterminsticKeys_test1)
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
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 ();
|
||||
@@ -865,3 +865,79 @@ RippleAddress RippleAddress::createSeedGeneric (const std::string& strText)
|
||||
|
||||
return naNew;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class RippleAddressTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
RippleAddressTests () : UnitTest ("RippleAddress", "ripple")
|
||||
{
|
||||
}
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
beginTest ("public/private");
|
||||
|
||||
// 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), "Verify failed.");
|
||||
|
||||
// Construct a public generator from the seed.
|
||||
RippleAddress naGenerator = RippleAddress::createGeneratorPublic (naSeed);
|
||||
|
||||
expect (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);
|
||||
|
||||
expect (naAccountPublic0.humanAccountID () == "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", naAccountPublic0.humanAccountID ());
|
||||
expect (naAccountPublic0.humanAccountPublic () == "aBQG8RQAzjs1eTKFEAQXr2gS4utcDiEC9wmi7pfUPTi27VCahwgw", naAccountPublic0.humanAccountPublic ());
|
||||
expect (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);
|
||||
|
||||
expect (naAccountPublic1.humanAccountID () == "r4bYF7SLUMD7QgSLLpgJx38WJSY12ViRjP", naAccountPublic1.humanAccountID ());
|
||||
expect (naAccountPublic1.humanAccountPublic () == "aBPXpTfuLy1Bhk3HnGTTAqnovpKWQ23NpFMNkAF6F1Atg5vDyPrw", naAccountPublic1.humanAccountPublic ());
|
||||
expect (naAccountPrivate1.humanAccountPrivate () == "p9JEm822LMrzJii1k7TvdphfENTp6G5jr253Xa5rkzUWVr8ogQt", naAccountPrivate1.humanAccountPrivate ());
|
||||
|
||||
// Check account signing.
|
||||
expect (naAccountPrivate0.accountPrivateSign (uHash, vucTextSig), "Signing failed.");
|
||||
expect (naAccountPublic0.accountPublicVerify (uHash, vucTextSig), "Verify failed.");
|
||||
expect (!naAccountPublic1.accountPublicVerify (uHash, vucTextSig), "Anti-verify failed.");
|
||||
|
||||
expect (naAccountPrivate1.accountPrivateSign (uHash, vucTextSig), "Signing failed.");
|
||||
expect (naAccountPublic1.accountPublicVerify (uHash, vucTextSig), "Verify failed.");
|
||||
expect (!naAccountPublic0.accountPublicVerify (uHash, vucTextSig), "Anti-verify failed.");
|
||||
|
||||
// Check account encryption.
|
||||
Blob vucTextCipher
|
||||
= naAccountPrivate0.accountPrivateEncrypt (naAccountPublic1, vucTextSrc);
|
||||
Blob vucTextRecovered
|
||||
= naAccountPrivate1.accountPrivateDecrypt (naAccountPublic0, vucTextCipher);
|
||||
|
||||
expect (vucTextSrc == vucTextRecovered, "Encrypt-decrypt failed.");
|
||||
}
|
||||
};
|
||||
|
||||
static RippleAddressTests rippleAddressTests;
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
BOOST_AUTO_TEST_SUITE (ripple_address)
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( check_crypto )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
// 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 ()
|
||||
@@ -890,9 +890,11 @@ STAmount operator- (const STAmount& v1, const STAmount& v2)
|
||||
|
||||
STAmount STAmount::divide (const STAmount& num, const STAmount& den, const uint160& uCurrencyID, const uint160& uIssuerID)
|
||||
{
|
||||
if (den.isZero ()) throw std::runtime_error ("division by zero");
|
||||
if (den.isZero ())
|
||||
throw std::runtime_error ("division by zero");
|
||||
|
||||
if (num.isZero ()) return STAmount (uCurrencyID, uIssuerID);
|
||||
if (num.isZero ())
|
||||
return STAmount (uCurrencyID, uIssuerID);
|
||||
|
||||
uint64 numVal = num.mValue, denVal = den.mValue;
|
||||
int numOffset = num.mOffset, denOffset = den.mOffset;
|
||||
@@ -1298,3 +1300,607 @@ Json::Value STAmount::getJson (int) const
|
||||
setJson (elem);
|
||||
return elem;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class STAmountTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
STAmountTests () : UnitTest ("STAmount", "ripple")
|
||||
{
|
||||
}
|
||||
|
||||
static STAmount serializeAndDeserialize (const STAmount& s)
|
||||
{
|
||||
Serializer ser;
|
||||
|
||||
s.add (ser);
|
||||
|
||||
SerializerIterator sit (ser);
|
||||
|
||||
return STAmount::deserialize (sit);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
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);
|
||||
|
||||
expect (! res.isNative (), "Product should not be native");
|
||||
|
||||
res.roundSelf ();
|
||||
|
||||
STAmount cmp (CURRENCY_ONE, ACCOUNT_ONE, (n * m) / d);
|
||||
|
||||
expect (! cmp.isNative (), "Comparison amount should not be native");
|
||||
|
||||
if (res != cmp)
|
||||
{
|
||||
cmp.throwComparable (res);
|
||||
|
||||
WriteLog (lsWARNING, STAmount) << "(" << num.getText () << "/" << den.getText () << ") X " << mul.getText () << " = "
|
||||
<< res.getText () << " not " << cmp.getText ();
|
||||
|
||||
fail ("Rounding");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
expect (! prod1.isNative ());
|
||||
|
||||
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 ();
|
||||
|
||||
fail ("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 ();
|
||||
fail ("Multiplication result is not exact");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void testSetValue ()
|
||||
{
|
||||
beginTest ("set value");
|
||||
|
||||
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");
|
||||
expect (1 == saTmp.getNValue (), "should be equal");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void testNativeCurrency ()
|
||||
{
|
||||
beginTest ("native currency");
|
||||
|
||||
STAmount zero, one (1), hundred (100);
|
||||
|
||||
if (serializeAndDeserialize (zero) != zero) fail ("STAmount fail");
|
||||
|
||||
if (serializeAndDeserialize (one) != one) fail ("STAmount fail");
|
||||
|
||||
if (serializeAndDeserialize (hundred) != hundred) fail ("STAmount fail");
|
||||
|
||||
if (!zero.isNative ()) fail ("STAmount fail");
|
||||
|
||||
if (!hundred.isNative ()) fail ("STAmount fail");
|
||||
|
||||
if (!zero.isZero ()) fail ("STAmount fail");
|
||||
|
||||
if (one.isZero ()) fail ("STAmount fail");
|
||||
|
||||
if (hundred.isZero ()) fail ("STAmount fail");
|
||||
|
||||
if ((zero < zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero < one)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero < hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((one < zero)) fail ("STAmount fail");
|
||||
|
||||
if ((one < one)) fail ("STAmount fail");
|
||||
|
||||
if (! (one < hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred < zero)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred < one)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred < hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((zero > zero)) fail ("STAmount fail");
|
||||
|
||||
if ((zero > one)) fail ("STAmount fail");
|
||||
|
||||
if ((zero > hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (one > zero)) fail ("STAmount fail");
|
||||
|
||||
if ((one > one)) fail ("STAmount fail");
|
||||
|
||||
if ((one > hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred > zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred > one)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred > hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero <= zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero <= one)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero <= hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((one <= zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (one <= one)) fail ("STAmount fail");
|
||||
|
||||
if (! (one <= hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred <= zero)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred <= one)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred <= hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero >= zero)) fail ("STAmount fail");
|
||||
|
||||
if ((zero >= one)) fail ("STAmount fail");
|
||||
|
||||
if ((zero >= hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (one >= zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (one >= one)) fail ("STAmount fail");
|
||||
|
||||
if ((one >= hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred >= zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred >= one)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred >= hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero == zero)) fail ("STAmount fail");
|
||||
|
||||
if ((zero == one)) fail ("STAmount fail");
|
||||
|
||||
if ((zero == hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((one == zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (one == one)) fail ("STAmount fail");
|
||||
|
||||
if ((one == hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred == zero)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred == one)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred == hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((zero != zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero != one)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero != hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (one != zero)) fail ("STAmount fail");
|
||||
|
||||
if ((one != one)) fail ("STAmount fail");
|
||||
|
||||
if (! (one != hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred != zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred != one)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred != hundred)) fail ("STAmount fail");
|
||||
|
||||
if (STAmount ().getText () != "0") fail ("STAmount fail");
|
||||
|
||||
if (STAmount (31).getText () != "31") fail ("STAmount fail");
|
||||
|
||||
if (STAmount (310).getText () != "310") fail ("STAmount fail");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void testCustomCurrency ()
|
||||
{
|
||||
beginTest ("custom currency");
|
||||
|
||||
STAmount zero (CURRENCY_ONE, ACCOUNT_ONE), one (CURRENCY_ONE, ACCOUNT_ONE, 1), hundred (CURRENCY_ONE, ACCOUNT_ONE, 100);
|
||||
|
||||
serializeAndDeserialize (one).getRaw ();
|
||||
|
||||
if (serializeAndDeserialize (zero) != zero) fail ("STAmount fail");
|
||||
|
||||
if (serializeAndDeserialize (one) != one) fail ("STAmount fail");
|
||||
|
||||
if (serializeAndDeserialize (hundred) != hundred) fail ("STAmount fail");
|
||||
|
||||
if (zero.isNative ()) fail ("STAmount fail");
|
||||
|
||||
if (hundred.isNative ()) fail ("STAmount fail");
|
||||
|
||||
if (!zero.isZero ()) fail ("STAmount fail");
|
||||
|
||||
if (one.isZero ()) fail ("STAmount fail");
|
||||
|
||||
if (hundred.isZero ()) fail ("STAmount fail");
|
||||
|
||||
if ((zero < zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero < one)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero < hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((one < zero)) fail ("STAmount fail");
|
||||
|
||||
if ((one < one)) fail ("STAmount fail");
|
||||
|
||||
if (! (one < hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred < zero)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred < one)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred < hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((zero > zero)) fail ("STAmount fail");
|
||||
|
||||
if ((zero > one)) fail ("STAmount fail");
|
||||
|
||||
if ((zero > hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (one > zero)) fail ("STAmount fail");
|
||||
|
||||
if ((one > one)) fail ("STAmount fail");
|
||||
|
||||
if ((one > hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred > zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred > one)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred > hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero <= zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero <= one)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero <= hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((one <= zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (one <= one)) fail ("STAmount fail");
|
||||
|
||||
if (! (one <= hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred <= zero)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred <= one)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred <= hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero >= zero)) fail ("STAmount fail");
|
||||
|
||||
if ((zero >= one)) fail ("STAmount fail");
|
||||
|
||||
if ((zero >= hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (one >= zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (one >= one)) fail ("STAmount fail");
|
||||
|
||||
if ((one >= hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred >= zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred >= one)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred >= hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero == zero)) fail ("STAmount fail");
|
||||
|
||||
if ((zero == one)) fail ("STAmount fail");
|
||||
|
||||
if ((zero == hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((one == zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (one == one)) fail ("STAmount fail");
|
||||
|
||||
if ((one == hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred == zero)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred == one)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred == hundred)) fail ("STAmount fail");
|
||||
|
||||
if ((zero != zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero != one)) fail ("STAmount fail");
|
||||
|
||||
if (! (zero != hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (one != zero)) fail ("STAmount fail");
|
||||
|
||||
if ((one != one)) fail ("STAmount fail");
|
||||
|
||||
if (! (one != hundred)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred != zero)) fail ("STAmount fail");
|
||||
|
||||
if (! (hundred != one)) fail ("STAmount fail");
|
||||
|
||||
if ((hundred != hundred)) fail ("STAmount fail");
|
||||
|
||||
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE).getText () != "0") fail ("STAmount fail");
|
||||
|
||||
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31).getText () != "31") fail ("STAmount fail");
|
||||
|
||||
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, 1).getText () != "310") fail ("STAmount fail");
|
||||
|
||||
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, -1).getText () != "3.1") fail ("STAmount fail");
|
||||
|
||||
if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, -2).getText () != "0.31") fail ("STAmount fail");
|
||||
|
||||
if (STAmount::multiply (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 20), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "60")
|
||||
fail ("STAmount multiply fail 1");
|
||||
|
||||
if (STAmount::multiply (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 20), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "60")
|
||||
fail ("STAmount multiply fail 2");
|
||||
|
||||
if (STAmount::multiply (STAmount (20), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "60")
|
||||
fail ("STAmount multiply fail 3");
|
||||
|
||||
if (STAmount::multiply (STAmount (20), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "60")
|
||||
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 ();
|
||||
fail ("STAmount divide fail");
|
||||
}
|
||||
|
||||
if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "20")
|
||||
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")
|
||||
fail ("STAmount divide fail");
|
||||
|
||||
if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 3), uint160 (), ACCOUNT_XRP).getText () != "20")
|
||||
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)))
|
||||
fail ("STAmount setRate(getRate) fail");
|
||||
|
||||
if (STAmount::divide (a1, a2, CURRENCY_ONE, ACCOUNT_ONE) != STAmount::setRate (STAmount::getRate (a2, a1)))
|
||||
fail ("STAmount setRate(getRate) fail");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void testArithmetic ()
|
||||
{
|
||||
beginTest ("arithmetic");
|
||||
|
||||
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);
|
||||
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))
|
||||
fail ("STAmount getRate fail 1");
|
||||
|
||||
if (STAmount::getRate (STAmount (10), STAmount (1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull))
|
||||
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))
|
||||
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))
|
||||
fail ("STAmount getRate fail 4");
|
||||
|
||||
if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1), STAmount (10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull))
|
||||
fail ("STAmount getRate fail 5");
|
||||
|
||||
if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10), STAmount (1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull))
|
||||
fail ("STAmount getRate fail 6");
|
||||
|
||||
if (STAmount::getRate (STAmount (1), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull))
|
||||
fail ("STAmount getRate fail 7");
|
||||
|
||||
if (STAmount::getRate (STAmount (10), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull))
|
||||
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);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void testUnderflow ()
|
||||
{
|
||||
beginTest ("underflow");
|
||||
|
||||
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);
|
||||
|
||||
expect (smallXsmall.isZero (), "smallXsmall != 0");
|
||||
|
||||
STAmount bigDsmall = STAmount::divide (smallValue, bigValue, CURRENCY_ONE, ACCOUNT_ONE);
|
||||
|
||||
expect (bigDsmall.isZero (), String ("small/big != 0: ") + bigDsmall.getText ());
|
||||
|
||||
bigDsmall = STAmount::divide (smallValue, bigNative, CURRENCY_ONE, uint160 ());
|
||||
|
||||
expect (bigDsmall.isZero (), String ("small/bigNative != 0: ") + bigDsmall.getText ());
|
||||
|
||||
bigDsmall = STAmount::divide (smallValue, bigValue, uint160 (), uint160 ());
|
||||
|
||||
expect (bigDsmall.isZero (), String ("(small/big)->N != 0: ") + bigDsmall.getText ());
|
||||
|
||||
bigDsmall = STAmount::divide (smallValue, bigNative, uint160 (), uint160 ());
|
||||
|
||||
expect (bigDsmall.isZero (), String ("(small/bigNative)->N != 0: ") + bigDsmall.getText ());
|
||||
|
||||
// very bad offer
|
||||
uint64 r = STAmount::getRate (smallValue, bigValue);
|
||||
|
||||
expect (r == 0, "getRate(smallOut/bigIn) != 0");
|
||||
|
||||
// very good offer
|
||||
r = STAmount::getRate (bigValue, smallValue);
|
||||
|
||||
expect (r == 0, "getRate(smallIn/bigOUt) != 0");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void testRounding ()
|
||||
{
|
||||
// VFALCO TODO There are no actual tests here, just printed output?
|
||||
// Change this to actually do something.
|
||||
|
||||
#if 0
|
||||
beginTest ("rounding ");
|
||||
|
||||
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;
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
testSetValue ();
|
||||
testNativeCurrency ();
|
||||
testCustomCurrency ();
|
||||
testArithmetic ();
|
||||
testUnderflow ();
|
||||
testRounding ();
|
||||
}
|
||||
};
|
||||
|
||||
static STAmountTests stAmountTests;
|
||||
|
||||
@@ -1,600 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
// For unit tests:
|
||||
namespace ripple
|
||||
{
|
||||
|
||||
static STAmount serdes (const STAmount& s)
|
||||
{
|
||||
Serializer ser;
|
||||
|
||||
s.add (ser);
|
||||
|
||||
SerializerIterator sit (ser);
|
||||
|
||||
return STAmount::deserialize (sit);
|
||||
}
|
||||
|
||||
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_SUITE (amount)
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( setValue_test )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
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 )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
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 )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( CurrencyMulDivTests )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
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 )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
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 )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
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 ()
|
||||
@@ -1560,3 +1560,92 @@ UPTR_T<STObject> STObject::parseJson (const Json::Value& object, SField::ref inN
|
||||
|
||||
return UPTR_T<STObject> (new STObject (*name, data));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class SerializedObjectTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
SerializedObjectTests () : UnitTest ("SerializedObject", "ripple")
|
||||
{
|
||||
}
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
beginTest ("serialization");
|
||||
|
||||
if (sfGeneric.isUseful ())
|
||||
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 ()) fail ("STObject error 1");
|
||||
|
||||
if (object1.isFieldPresent (sfTestH256) || !object1.isFieldPresent (sfTestVL))
|
||||
fail ("STObject error");
|
||||
|
||||
object1.makeFieldPresent (sfTestH256);
|
||||
|
||||
if (!object1.isFieldPresent (sfTestH256)) fail ("STObject Error 2");
|
||||
|
||||
if (object1.getFieldH256 (sfTestH256) != uint256 ()) fail ("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");
|
||||
}
|
||||
|
||||
object1.makeFieldAbsent (sfTestH256);
|
||||
|
||||
if (object1.isFieldPresent (sfTestH256)) fail ("STObject error 5");
|
||||
|
||||
if (object1.getFlags () != 0) fail ("STObject error 6");
|
||||
|
||||
if (object1.getSerializer () != object2.getSerializer ()) fail ("STObject error 7");
|
||||
|
||||
STObject copy (object1);
|
||||
|
||||
if (object1.isFieldPresent (sfTestH256)) fail ("STObject error 8");
|
||||
|
||||
if (copy.isFieldPresent (sfTestH256)) fail ("STObject error 9");
|
||||
|
||||
if (object1.getSerializer () != copy.getSerializer ()) fail ("STObject error 10");
|
||||
|
||||
copy.setFieldU32 (sfTestU32, 1);
|
||||
|
||||
if (object1.getSerializer () == copy.getSerializer ()) 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) fail ("STObject error");
|
||||
|
||||
if (object3.getFieldVL (sfTestVL) != j) fail ("STObject error");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static SerializedObjectTests serializedObjectTests;
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
BOOST_AUTO_TEST_SUITE (SerializedObject)
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( FieldManipulation_test )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
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 ();
|
||||
@@ -704,3 +704,32 @@ Blob SerializerIterator::getRaw (int iLength)
|
||||
|
||||
return mSerializer.getRaw (iPos, iLength);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class SerializerTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
SerializerTests () : UnitTest ("Serializer", "ripple")
|
||||
{
|
||||
}
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
beginTest ("hash");
|
||||
|
||||
Serializer s1;
|
||||
s1.add32 (3);
|
||||
s1.add256 (uint256 ());
|
||||
|
||||
Serializer s2;
|
||||
s2.add32 (0x12345600);
|
||||
s2.addRaw (s1.peekData ());
|
||||
|
||||
expect (s1.getPrefixHash (0x12345600) == s2.getSHA512Half ());
|
||||
}
|
||||
};
|
||||
|
||||
static SerializerTests serializerTests;
|
||||
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
BOOST_AUTO_TEST_SUITE (Serializer_suite)
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( Serializer_PrefixHash_test )
|
||||
{
|
||||
using namespace ripple;
|
||||
|
||||
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 ();
|
||||
@@ -91,13 +91,6 @@ static const uint64 tenTo17m1 = tenTo17 - 1;
|
||||
|
||||
}
|
||||
|
||||
// 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"
|
||||
|
||||
Reference in New Issue
Block a user