Split unit tests to separate files

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

View File

@@ -1919,16 +1919,3 @@ std::vector<uint256> Ledger::getNeededAccountStateHashes (int max, SHAMapSyncFil
return ret;
}
BOOST_AUTO_TEST_SUITE (quality)
BOOST_AUTO_TEST_CASE ( getquality )
{
uint256 uBig ("D2DC44E5DC189318DB36EF87D2104CDF0A0FE3A4B698BEEE55038D7EA4C68000");
if (6125895493223874560 != Ledger::getQuality (uBig))
BOOST_FAIL ("Ledger::getQuality fails.");
}
BOOST_AUTO_TEST_SUITE_END ()
// vim:ts=4

View File

@@ -0,0 +1,17 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
BOOST_AUTO_TEST_SUITE (quality)
BOOST_AUTO_TEST_CASE ( getquality )
{
uint256 uBig ("D2DC44E5DC189318DB36EF87D2104CDF0A0FE3A4B698BEEE55038D7EA4C68000");
if (6125895493223874560 != Ledger::getQuality (uBig))
BOOST_FAIL ("Ledger::getQuality fails.");
}
BOOST_AUTO_TEST_SUITE_END ()

View File

@@ -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

View File

@@ -0,0 +1,52 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
#ifndef RIPPLE_PROOFOFWORKFACTORY_RIPPLEHEADER
#define RIPPLE_PROOFOFWORKFACTORY_RIPPLEHEADER
// PRIVATE HEADER
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;
};
#endif

View File

@@ -0,0 +1,65 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
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 ()

View File

@@ -1046,86 +1046,3 @@ void SHAMap::dump (bool hash)
}
}
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 )
{
// 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 ();
// vim:ts=4

View File

@@ -572,57 +572,6 @@ void SHAMap::getFetchPack (SHAMap* have, bool includeLeaves, int max,
}
}
#ifdef DEBUG
#define SMS_DEBUG
#endif
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;
}
std::list<Blob > SHAMap::getTrustedPath (uint256 const& index)
{
boost::recursive_mutex::scoped_lock sl (mLock);
@@ -644,148 +593,3 @@ std::list<Blob > SHAMap::getTrustedPath (uint256 const& index)
return path;
}
BOOST_AUTO_TEST_SUITE ( SHAMapSync )
BOOST_AUTO_TEST_CASE ( SHAMapSync_test )
{
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 ();
// vim:ts=4

View File

@@ -0,0 +1,199 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
#ifdef DEBUG
#define SMS_DEBUG
#endif
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 )
{
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 ();

View File

@@ -0,0 +1,88 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
// 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;
}
BOOST_AUTO_TEST_SUITE (SHAMap_suite)
BOOST_AUTO_TEST_CASE ( SHAMap_test )
{
// 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 ();

View File

@@ -307,50 +307,3 @@ std::string SerializedTransaction::getMetaSQL (Serializer rawTxn, uint32 inLedge
% getTransactionID ().GetHex () % getTransactionType () % getSourceAccount ().humanAccountID ()
% getSequence () % inLedger % status % rTxn % escapedMetaData);
}
BOOST_AUTO_TEST_SUITE (SerializedTransactionTS)
BOOST_AUTO_TEST_CASE ( STrans_test )
{
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 ();
// vim:ts=4

View File

@@ -0,0 +1,48 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
BOOST_AUTO_TEST_SUITE (SerializedTransactionTS)
BOOST_AUTO_TEST_CASE ( STrans_test )
{
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 ();

View File

@@ -6,8 +6,6 @@
SETUP_LOG (SqliteDatabase)
//using namespace std;
SqliteStatement::SqliteStatement (SqliteDatabase* db, const char* sql, bool aux)
{
assert (db);