mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
* Use nullptr (C++11) instead of NULL. * Put each file into its own namespace declaration. * Remove "using namespace" directives and add scope qualifiers. * Control when beast's implementation of std::equal (C++14) is used. * Tidy up some const declarations. Conflicts: src/ripple_app/shamap/SHAMapSync.cpp src/ripple_app/tx/TransactionEngine.cpp
233 lines
6.1 KiB
C++
233 lines
6.1 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of rippled: https://github.com/ripple/rippled
|
|
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
namespace ripple {
|
|
namespace Validators {
|
|
|
|
class Tests : public beast::UnitTest
|
|
{
|
|
public:
|
|
enum
|
|
{
|
|
numberOfTestValidators = 1000,
|
|
numberofTestSources = 50
|
|
};
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
struct Payload
|
|
{
|
|
Payload ()
|
|
{
|
|
}
|
|
};
|
|
|
|
template <class Config>
|
|
class PeerLogic : public TestOverlay::PeerLogicBase <Config>
|
|
{
|
|
public:
|
|
typedef TestOverlay::PeerLogicBase <Config> Base;
|
|
typedef typename Config::Payload Payload;
|
|
typedef typename Base::Connection Connection;
|
|
typedef typename Base::Peer Peer;
|
|
typedef typename Base::Message Message;
|
|
typedef typename Config::SizeType SizeType;
|
|
|
|
explicit PeerLogic (Peer& peer)
|
|
: TestOverlay::PeerLogicBase <Config> (peer)
|
|
{
|
|
}
|
|
|
|
~PeerLogic ()
|
|
{
|
|
}
|
|
|
|
void step ()
|
|
{
|
|
if (this->peer().id () == 1)
|
|
{
|
|
if (this->peer().network().steps() == 0)
|
|
{
|
|
this->peer().network().state().increment();
|
|
this->peer().send_all (Payload (1));
|
|
}
|
|
}
|
|
}
|
|
|
|
void receive (Connection const& c, Message const& m)
|
|
{
|
|
if (this->peer().id () != 1)
|
|
{
|
|
this->peer().network().state().increment();
|
|
this->peer().send_all_if (Message (m.id(),
|
|
m.payload().withHop ()),
|
|
typename Connection::IsNotPeer (c.peer()));
|
|
}
|
|
}
|
|
};
|
|
|
|
struct Params : TestOverlay::ConfigType <
|
|
Params,
|
|
TestOverlay::StateBase,
|
|
PeerLogic
|
|
>
|
|
{
|
|
typedef TestOverlay::PremadeInitPolicy <250, 3> InitPolicy;
|
|
};
|
|
|
|
typedef Params::Network Network;
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
struct TestSource : Source
|
|
{
|
|
TestSource (beast::String const& name, beast::uint32 start, beast::uint32 end)
|
|
: m_name (name)
|
|
, m_start (start)
|
|
, m_end (end)
|
|
{
|
|
}
|
|
|
|
std::string to_string () const
|
|
{
|
|
return uniqueID().toStdString();
|
|
}
|
|
|
|
beast::String uniqueID () const
|
|
{
|
|
using beast::String;
|
|
return String ("Test,") + m_name + "," +
|
|
String::fromNumber (m_start) + "," +
|
|
String::fromNumber (m_end);
|
|
}
|
|
|
|
beast::String createParam ()
|
|
{
|
|
return beast::String::empty;
|
|
}
|
|
|
|
void fetch (Results& results, beast::Journal)
|
|
{
|
|
results.success = true;
|
|
results.message = beast::String::empty;
|
|
results.list.reserve (numberOfTestValidators);
|
|
|
|
for (beast::uint32 i = m_start ; i < m_end; ++i)
|
|
{
|
|
Item item;;
|
|
item.publicKey = RipplePublicKey::createFromInteger (i);
|
|
item.label = beast::String::fromNumber (i);
|
|
results.list.push_back (item);
|
|
}
|
|
}
|
|
|
|
beast::String m_name;
|
|
std::size_t m_start;
|
|
std::size_t m_end;
|
|
};
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
class TestStore : public Store
|
|
{
|
|
public:
|
|
TestStore ()
|
|
{
|
|
}
|
|
|
|
~TestStore ()
|
|
{
|
|
}
|
|
|
|
void insertSourceDesc (SourceDesc& desc)
|
|
{
|
|
}
|
|
|
|
void updateSourceDesc (SourceDesc& desc)
|
|
{
|
|
}
|
|
|
|
void updateSourceDescInfo (SourceDesc& desc)
|
|
{
|
|
}
|
|
};
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
void addSources (Logic& logic)
|
|
{
|
|
for (int i = 1; i <= numberofTestSources; ++i)
|
|
{
|
|
beast::String const name (beast::String::fromNumber (i));
|
|
beast::uint32 const start = random().nextInt (numberOfTestValidators);
|
|
beast::uint32 const end = start + random().nextInt (numberOfTestValidators);
|
|
logic.add (new TestSource (name, start, end));
|
|
}
|
|
}
|
|
|
|
void testLogic ()
|
|
{
|
|
beginTestCase ("logic");
|
|
|
|
//TestStore store;
|
|
StoreSqdb storage;
|
|
|
|
beast::File const file (
|
|
beast::File::getSpecialLocation (
|
|
beast::File::userDocumentsDirectory).getChildFile (
|
|
"validators-test.sqlite"));
|
|
|
|
// Can't call this 'error' because of ADL and Journal::error
|
|
beast::Error err (storage.open (file));
|
|
|
|
unexpected (err, err.what());
|
|
|
|
Logic logic (storage, beast::Journal ());
|
|
logic.load ();
|
|
|
|
addSources (logic);
|
|
|
|
logic.fetch_one ();
|
|
|
|
ChosenList::Ptr list (logic.getChosen ());
|
|
|
|
pass ();
|
|
}
|
|
|
|
void runTest ()
|
|
{
|
|
// We need to use the same seed so we create the
|
|
// same IDs for the set of TestSource objects.
|
|
//
|
|
beast::int64 const seedValue = 10;
|
|
random().setSeed (seedValue);
|
|
|
|
testLogic ();
|
|
}
|
|
|
|
Tests () : UnitTest ("Validators", "ripple", runManual)
|
|
{
|
|
}
|
|
};
|
|
|
|
static Tests tests;
|
|
|
|
}
|
|
}
|