mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-21 02:55:50 +00:00
Convert to beast UnitTest
This commit is contained in:
@@ -820,12 +820,6 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\cpp\ripple\ripple_ProofOfWorkFactoryUnitTests.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="..\..\src\cpp\ripple\ripple_RippleCalc.cpp">
|
<ClCompile Include="..\..\src\cpp\ripple\ripple_RippleCalc.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
|||||||
@@ -594,9 +594,6 @@
|
|||||||
<ClCompile Include="..\..\src\cpp\ripple\ripple_ProofOfWorkFactory.cpp">
|
<ClCompile Include="..\..\src\cpp\ripple\ripple_ProofOfWorkFactory.cpp">
|
||||||
<Filter>[1] Ripple\ripple_app\_misc</Filter>
|
<Filter>[1] Ripple\ripple_app\_misc</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\cpp\ripple\ripple_ProofOfWorkFactoryUnitTests.cpp">
|
|
||||||
<Filter>[1] Ripple\ripple_app\_misc</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\cpp\ripple\ripple_SerializedLedger.cpp">
|
<ClCompile Include="..\..\src\cpp\ripple\ripple_SerializedLedger.cpp">
|
||||||
<Filter>[1] Ripple\ripple_app\_misc</Filter>
|
<Filter>[1] Ripple\ripple_app\_misc</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
2
TODO.txt
2
TODO.txt
@@ -3,6 +3,8 @@ RIPPLE TODO
|
|||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
Vinnie's Short List (Changes day to day)
|
Vinnie's Short List (Changes day to day)
|
||||||
|
- Memory NodeStore::Backend for unit tests
|
||||||
|
- Improved Mutex to track deadlocks
|
||||||
- Convert some Ripple boost unit tests to Beast.
|
- Convert some Ripple boost unit tests to Beast.
|
||||||
- Eliminate new technical in NodeStore::Backend
|
- Eliminate new technical in NodeStore::Backend
|
||||||
- Work on KeyvaDB
|
- Work on KeyvaDB
|
||||||
|
|||||||
@@ -431,7 +431,6 @@ static DH* handleTmpDh (SSL* ssl, int is_export, int iKeyLength)
|
|||||||
#include "ledger/LedgerUnitTests.cpp"
|
#include "ledger/LedgerUnitTests.cpp"
|
||||||
#include "src/cpp/ripple/ripple_SHAMapUnitTests.cpp"
|
#include "src/cpp/ripple/ripple_SHAMapUnitTests.cpp"
|
||||||
#include "src/cpp/ripple/ripple_SHAMapSyncUnitTests.cpp"
|
#include "src/cpp/ripple/ripple_SHAMapSyncUnitTests.cpp"
|
||||||
#include "src/cpp/ripple/ripple_ProofOfWorkFactoryUnitTests.cpp" // Requires ProofOfWorkFactory.h
|
|
||||||
#include "src/cpp/ripple/ripple_SerializedTransactionUnitTests.cpp"
|
#include "src/cpp/ripple/ripple_SerializedTransactionUnitTests.cpp"
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -177,4 +177,5 @@ bool ProofOfWork::validateToken (const std::string& strToken)
|
|||||||
return boost::regex_match (strToken, smMatch, reToken);
|
return boost::regex_match (strToken, smMatch, reToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim:ts=4
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -231,3 +231,72 @@ IProofOfWorkFactory* IProofOfWorkFactory::New ()
|
|||||||
return new ProofOfWorkFactory;
|
return new ProofOfWorkFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class ProofOfWorkTests : public UnitTest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ProofOfWorkTests () : UnitTest ("ProofOfWork")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void runTest ()
|
||||||
|
{
|
||||||
|
using namespace ripple;
|
||||||
|
|
||||||
|
ProofOfWorkFactory gen;
|
||||||
|
ProofOfWork pow = gen.getProof ();
|
||||||
|
|
||||||
|
String s;
|
||||||
|
|
||||||
|
s << "solve difficulty " << String (pow.getDifficulty ());
|
||||||
|
beginTest ("solve");
|
||||||
|
|
||||||
|
uint256 solution = pow.solve (16777216);
|
||||||
|
|
||||||
|
expect (! solution.isZero (), "Should be solved");
|
||||||
|
|
||||||
|
expect (pow.checkSolution (solution), "Should be checked");
|
||||||
|
|
||||||
|
// Why is this emitted?
|
||||||
|
//WriteLog (lsDEBUG, ProofOfWork) << "A bad nonce error is expected";
|
||||||
|
|
||||||
|
POWResult r = gen.checkProof (pow.getToken (), uint256 ());
|
||||||
|
|
||||||
|
expect (r == powBADNONCE, "Should show bad nonce for empty solution");
|
||||||
|
|
||||||
|
expect (gen.checkProof (pow.getToken (), solution) == powOK, "Solution should check with issuer");
|
||||||
|
|
||||||
|
//WriteLog (lsDEBUG, ProofOfWork) << "A reused nonce error is expected";
|
||||||
|
|
||||||
|
expect (gen.checkProof (pow.getToken (), solution) == powREUSED, "Reuse solution should be detected");
|
||||||
|
|
||||||
|
#ifdef SOLVE_POWS
|
||||||
|
|
||||||
|
for (int i = 0; i < 12; ++i)
|
||||||
|
{
|
||||||
|
gen.setDifficulty (i);
|
||||||
|
ProofOfWork pow = gen.getProof ();
|
||||||
|
WriteLog (lsINFO, ProofOfWork) << "Level: " << i << ", Estimated difficulty: " << pow.getDifficulty ();
|
||||||
|
uint256 solution = pow.solve (131072);
|
||||||
|
|
||||||
|
if (solution.isZero ())
|
||||||
|
{
|
||||||
|
//WriteLog (lsINFO, ProofOfWork) << "Giving up";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//WriteLog (lsINFO, ProofOfWork) << "Solution found";
|
||||||
|
|
||||||
|
if (gen.checkProof (pow.getToken (), solution) != powOK)
|
||||||
|
{
|
||||||
|
//WriteLog (lsFATAL, ProofOfWork) << "Solution fails";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static ProofOfWorkTests proofOfWorkTests;
|
||||||
|
|||||||
@@ -4,64 +4,3 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE (ProofOfWork_suite)
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE ( ProofOfWork_test )
|
|
||||||
{
|
|
||||||
using namespace ripple;
|
|
||||||
|
|
||||||
ProofOfWorkFactory gen;
|
|
||||||
ProofOfWork pow = gen.getProof ();
|
|
||||||
WriteLog (lsINFO, ProofOfWork) << "Estimated difficulty: " << pow.getDifficulty ();
|
|
||||||
uint256 solution = pow.solve (16777216);
|
|
||||||
|
|
||||||
if (solution.isZero ())
|
|
||||||
BOOST_FAIL ("Unable to solve proof of work");
|
|
||||||
|
|
||||||
if (!pow.checkSolution (solution))
|
|
||||||
BOOST_FAIL ("Solution did not check");
|
|
||||||
|
|
||||||
WriteLog (lsDEBUG, ProofOfWork) << "A bad nonce error is expected";
|
|
||||||
POWResult r = gen.checkProof (pow.getToken (), uint256 ());
|
|
||||||
|
|
||||||
if (r != powBADNONCE)
|
|
||||||
{
|
|
||||||
Log (lsFATAL) << "POWResult = " << static_cast<int> (r);
|
|
||||||
BOOST_FAIL ("Empty solution didn't show bad nonce");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gen.checkProof (pow.getToken (), solution) != powOK)
|
|
||||||
BOOST_FAIL ("Solution did not check with issuer");
|
|
||||||
|
|
||||||
WriteLog (lsDEBUG, ProofOfWork) << "A reused nonce error is expected";
|
|
||||||
|
|
||||||
if (gen.checkProof (pow.getToken (), solution) != powREUSED)
|
|
||||||
BOOST_FAIL ("Reuse solution not detected");
|
|
||||||
|
|
||||||
#ifdef SOLVE_POWS
|
|
||||||
|
|
||||||
for (int i = 0; i < 12; ++i)
|
|
||||||
{
|
|
||||||
gen.setDifficulty (i);
|
|
||||||
ProofOfWork pow = gen.getProof ();
|
|
||||||
WriteLog (lsINFO, ProofOfWork) << "Level: " << i << ", Estimated difficulty: " << pow.getDifficulty ();
|
|
||||||
uint256 solution = pow.solve (131072);
|
|
||||||
|
|
||||||
if (solution.isZero ())
|
|
||||||
WriteLog (lsINFO, ProofOfWork) << "Giving up";
|
|
||||||
else
|
|
||||||
{
|
|
||||||
WriteLog (lsINFO, ProofOfWork) << "Solution found";
|
|
||||||
|
|
||||||
if (gen.checkProof (pow.getToken (), solution) != powOK)
|
|
||||||
{
|
|
||||||
WriteLog (lsFATAL, ProofOfWork) << "Solution fails";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END ()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user