mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Split unit tests to separate files
This commit is contained in:
@@ -4,46 +4,6 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
class ProofOfWorkFactory : public IProofOfWorkFactory
|
||||
{
|
||||
public:
|
||||
ProofOfWorkFactory ();
|
||||
|
||||
ProofOfWork getProof ();
|
||||
POWResult checkProof (const std::string& token, uint256 const& solution);
|
||||
uint64 getDifficulty ()
|
||||
{
|
||||
return ProofOfWork::getDifficulty (mTarget, mIterations);
|
||||
}
|
||||
void setDifficulty (int i);
|
||||
|
||||
void loadHigh ();
|
||||
void loadLow ();
|
||||
void sweep (void);
|
||||
|
||||
uint256 const& getSecret () const
|
||||
{
|
||||
return mSecret;
|
||||
}
|
||||
void setSecret (uint256 const& secret)
|
||||
{
|
||||
mSecret = secret;
|
||||
}
|
||||
|
||||
static int getPowEntry (uint256 const& target, int iterations);
|
||||
|
||||
private:
|
||||
uint256 mSecret;
|
||||
int mIterations;
|
||||
uint256 mTarget;
|
||||
time_t mLastDifficultyChange;
|
||||
int mValidTime;
|
||||
int mPowEntry;
|
||||
|
||||
powMap_t mSolvedChallenges;
|
||||
boost::mutex mLock;
|
||||
};
|
||||
|
||||
ProofOfWorkFactory::ProofOfWorkFactory () : mValidTime (180)
|
||||
{
|
||||
setDifficulty (1);
|
||||
@@ -271,64 +231,3 @@ IProofOfWorkFactory* IProofOfWorkFactory::New ()
|
||||
return new ProofOfWorkFactory;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE (ProofOfWork_suite)
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( ProofOfWork_test )
|
||||
{
|
||||
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 ()
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
Reference in New Issue
Block a user