Esempio n. 1
0
static void
loadXdr(Config const& cfg, std::string const& bucketFile)
{
    VirtualClock clock;
    Application::pointer app = Application::create(clock, cfg, false);
    if (checkInitialized(app))
    {
        uint256 zero;
        Bucket bucket(bucketFile, zero);
        bucket.setRetain(true);
        bucket.apply(app->getDatabase());
    }
    else
    {
        LOG(INFO) << "Database is not initialized";
    }
}
Esempio n. 2
0
void
transactionTest(Application::pointer app)
{
    int a = 10, b = 0;
    int a0 = a + 1;
    int a1 = a + 2;

    auto& session = app->getDatabase().getSession();

    session << "DROP TABLE IF EXISTS test";
    session << "CREATE TABLE test (x INTEGER)";

    {
        soci::transaction tx(session);

        session << "INSERT INTO test (x) VALUES (:aa)", soci::use(a0, "aa");

        session << "SELECT x FROM test", soci::into(b);
        CHECK(a0 == b);

        {
            soci::transaction tx2(session);
            session << "UPDATE test SET x = :v", soci::use(a1, "v");
            tx2.rollback();
        }

        session << "SELECT x FROM test", soci::into(b);
        CHECK(a0 == b);

        {
            soci::transaction tx3(session);
            session << "UPDATE test SET x = :v", soci::use(a, "v");
            tx3.commit();
        }
        session << "SELECT x FROM test", soci::into(b);
        CHECK(a == b);

        tx.commit();
    }

    session << "SELECT x FROM test", soci::into(b);
    CHECK(a == b);
}
Esempio n. 3
0
void
initializeDatabase(Config& cfg)
{
    cfg.REBUILD_DB = false; // don't wipe the db until we read whether it was
                            // already initialized
    VirtualClock clock;
    Application::pointer app = Application::create(clock, cfg);

    auto wipeMsg = (app->getPersistentState().getState(
                        PersistentState::kDatabaseInitialized) == "true"
                        ? " wiped and initialized"
                        : " initialized");

    app->getDatabase().initialize();

    LOG(INFO) << "* ";
    LOG(INFO) << "* The database has been" << wipeMsg
              << ". The next launch will catchup from the";
    LOG(INFO) << "* network afresh.";
    LOG(INFO) << "* ";
}
}

TEST_CASE("Total coins change without inflation",
          "[invariant][conservationoflumens]")
{
    std::default_random_engine gen;
    Config cfg = getTestConfig(0);
    cfg.INVARIANT_CHECKS = {"ConservationOfLumens"};

    std::uniform_int_distribution<int64_t> dist(0, INT64_MAX);

    VirtualClock clock;
    Application::pointer app = createTestApplication(clock, cfg);

    LedgerHeader lh(app->getLedgerManager().getCurrentLedgerHeader());
    LedgerDelta ld(lh, app->getDatabase(), false);
    ld.getHeader().totalCoins = dist(gen);
    OperationResult res;
    REQUIRE_THROWS_AS(
        app->getInvariantManager().checkOnOperationApply({}, res, ld),
        InvariantDoesNotHold);
}

TEST_CASE("Fee pool change without inflation",
          "[invariant][conservationoflumens]")
{
    std::default_random_engine gen;
    Config cfg = getTestConfig(0);
    cfg.INVARIANT_CHECKS = {"ConservationOfLumens"};

    std::uniform_int_distribution<int64_t> dist(0, INT64_MAX);
Esempio n. 5
0
LedgerEntry
generateValidLedgerEntry()
{
    return validLedgerEntryGenerator(10);
}

TEST_CASE("Ledger entry db lifecycle", "[ledger]")
{
    Config cfg(getTestConfig());
    VirtualClock clock;
    Application::pointer app = Application::create(clock, cfg);

    app->start();
    LedgerDelta delta(app->getLedgerManager().getCurrentLedgerHeader(),
                      app->getDatabase());
    auto& db = app->getDatabase();
    for (size_t i = 0; i < 100; ++i)
    {
        auto le = EntryFrame::FromXDR(validLedgerEntryGenerator(3));
        CHECK(!EntryFrame::exists(db, le->getKey()));
        le->storeAddOrChange(delta, db);
        CHECK(EntryFrame::exists(db, le->getKey()));
        le->storeDelete(delta, db);
        CHECK(!EntryFrame::exists(db, le->getKey()));
    }
}

TEST_CASE("single ledger entry insert SQL", "[singlesql][entrysql]")
{
    Config::TestDbMode mode = Config::TESTDB_ON_DISK_SQLITE;
Esempio n. 6
0
#include <unordered_map>
#include <utility>

using namespace stellar;

namespace LedgerEntryTests
{

TEST_CASE("Ledger Entry tests", "[ledgerentry]")
{
    Config cfg(getTestConfig(0));

    VirtualClock clock;
    Application::pointer app = createTestApplication(clock, cfg);
    app->start();
    Database& db = app->getDatabase();

    SECTION("round trip with database")
    {
        std::vector<LedgerEntry> accounts(50);

        std::unordered_map<AccountID, LedgerEntry> accountsMap;

        for (auto& l : accounts)
        {
            l.data.type(ACCOUNT);
            auto& a = l.data.account();
            a = LedgerTestUtils::generateValidAccountEntry(5);
            accountsMap.insert(std::make_pair(a.accountID, l));
        }