Skip to content

Commit

Permalink
Merge pull request #3362 from sisuresh/test-refactor
Browse files Browse the repository at this point in the history
Test case refactor

Reviewed-by: MonsieurNicolas
  • Loading branch information
latobarita authored Mar 25, 2022
2 parents 22c84a7 + c542beb commit a4bcabb
Show file tree
Hide file tree
Showing 94 changed files with 374,420 additions and 322,735 deletions.
16 changes: 9 additions & 7 deletions src/bucket/test/BucketListTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ binarySearchForLedger(uint32_t lbound, uint32_t ubound,

using namespace BucketListTests;

TEST_CASE("bucket list", "[bucket][bucketlist]")
TEST_CASE_VERSIONS("bucket list", "[bucket][bucketlist]")
{
VirtualClock clock;
Config const& cfg = getTestConfig();
Expand Down Expand Up @@ -171,7 +171,8 @@ TEST_CASE("bucket list", "[bucket][bucketlist]")
}
}

TEST_CASE("bucket list shadowing pre/post proto 12", "[bucket][bucketlist]")
TEST_CASE_VERSIONS("bucket list shadowing pre/post proto 12",
"[bucket][bucketlist]")
{
VirtualClock clock;
Config const& cfg = getTestConfig();
Expand Down Expand Up @@ -265,8 +266,8 @@ TEST_CASE("bucket list shadowing pre/post proto 12", "[bucket][bucketlist]")
});
}

TEST_CASE("bucket tombstones expire at bottom level",
"[bucket][bucketlist][tombstones]")
TEST_CASE_VERSIONS("bucket tombstones expire at bottom level",
"[bucket][bucketlist][tombstones]")
{
VirtualClock clock;
Config const& cfg = getTestConfig();
Expand Down Expand Up @@ -330,8 +331,8 @@ TEST_CASE("bucket tombstones expire at bottom level",
});
}

TEST_CASE("bucket tombstones mutually-annihilate init entries",
"[bucket][bucketlist][bl-initentry]")
TEST_CASE_VERSIONS("bucket tombstones mutually-annihilate init entries",
"[bucket][bucketlist][bl-initentry]")
{
VirtualClock clock;
Config const& cfg = getTestConfig();
Expand Down Expand Up @@ -404,7 +405,8 @@ TEST_CASE("bucket tombstones mutually-annihilate init entries",
});
}

TEST_CASE("single entry bubbling up", "[bucket][bucketlist][bucketbubble]")
TEST_CASE_VERSIONS("single entry bubbling up",
"[bucket][bucketlist][bucketbubble]")
{
VirtualClock clock;
Config const& cfg = getTestConfig();
Expand Down
17 changes: 10 additions & 7 deletions src/bucket/test/BucketManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ TEST_CASE("skip list", "[bucket][bucketmanager]")
btest.test();
}

TEST_CASE("bucketmanager ownership", "[bucket][bucketmanager]")
TEST_CASE_VERSIONS("bucketmanager ownership", "[bucket][bucketmanager]")
{
VirtualClock clock;
Config cfg = getTestConfig();
Expand Down Expand Up @@ -389,7 +389,8 @@ TEST_CASE("bucketmanager missing buckets fail", "[bucket][bucketmanager]")
}
}

TEST_CASE("bucketmanager reattach to finished merge", "[bucket][bucketmanager]")
TEST_CASE_VERSIONS("bucketmanager reattach to finished merge",
"[bucket][bucketmanager]")
{
VirtualClock clock;
Config cfg(getTestConfig(0, Config::TESTDB_IN_MEMORY_SQLITE));
Expand Down Expand Up @@ -449,7 +450,8 @@ TEST_CASE("bucketmanager reattach to finished merge", "[bucket][bucketmanager]")
});
}

TEST_CASE("bucketmanager reattach to running merge", "[bucket][bucketmanager]")
TEST_CASE_VERSIONS("bucketmanager reattach to running merge",
"[bucket][bucketmanager]")
{
VirtualClock clock;
Config cfg(getTestConfig(0, Config::TESTDB_IN_MEMORY_SQLITE));
Expand Down Expand Up @@ -591,8 +593,9 @@ TEST_CASE("bucketmanager do not leak empty-merge futures",
REQUIRE(bmRefBuckets.size() == bmDirBuckets.size());
}

TEST_CASE("bucketmanager reattach HAS from publish queue to finished merge",
"[bucket][bucketmanager]")
TEST_CASE_VERSIONS(
"bucketmanager reattach HAS from publish queue to finished merge",
"[bucket][bucketmanager]")
{
Config cfg(getTestConfig());
cfg.MANUAL_CLOSE = false;
Expand Down Expand Up @@ -1385,8 +1388,8 @@ TEST_CASE("bucket persistence over app restart with initentry - extended",
}
}

TEST_CASE("bucket persistence over app restart",
"[bucket][bucketmanager][bucketpersist]")
TEST_CASE_VERSIONS("bucket persistence over app restart",
"[bucket][bucketmanager][bucketpersist]")
{
std::vector<stellar::LedgerKey> emptySet;
std::vector<stellar::LedgerEntry> emptySetEntry;
Expand Down
13 changes: 7 additions & 6 deletions src/bucket/test/BucketTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ countEntries(std::shared_ptr<Bucket> bucket)

using namespace BucketTests;

TEST_CASE("file backed buckets", "[bucket][bucketbench]")
TEST_CASE_VERSIONS("file backed buckets", "[bucket][bucketbench]")
{
VirtualClock clock;
Config const& cfg = getTestConfig();
Expand Down Expand Up @@ -172,7 +172,7 @@ TEST_CASE("file backed buckets", "[bucket][bucketbench]")
});
}

TEST_CASE("merging bucket entries", "[bucket]")
TEST_CASE_VERSIONS("merging bucket entries", "[bucket]")
{
VirtualClock clock;
Config const& cfg = getTestConfig();
Expand Down Expand Up @@ -508,7 +508,8 @@ TEST_CASE("bucket output iterator rejects wrong-version entries",
REQUIRE_THROWS_AS(out.put(metaEntry), std::runtime_error);
}

TEST_CASE("merging bucket entries with initentry", "[bucket][initentry]")
TEST_CASE_VERSIONS("merging bucket entries with initentry",
"[bucket][initentry]")
{
VirtualClock clock;
Config const& cfg = getTestConfig();
Expand Down Expand Up @@ -696,8 +697,8 @@ TEST_CASE("merging bucket entries with initentry", "[bucket][initentry]")
});
}

TEST_CASE("merging bucket entries with initentry with shadows",
"[bucket][initentry]")
TEST_CASE_VERSIONS("merging bucket entries with initentry with shadows",
"[bucket][initentry]")
{
VirtualClock clock;
Config const& cfg = getTestConfig();
Expand Down Expand Up @@ -965,7 +966,7 @@ TEST_CASE("merging bucket entries with initentry with shadows",
});
}

TEST_CASE("bucket apply", "[bucket]")
TEST_CASE_VERSIONS("bucket apply", "[bucket]")
{
VirtualClock clock;
Config cfg(getTestConfig());
Expand Down
31 changes: 20 additions & 11 deletions src/herder/test/HerderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ using namespace stellar;
using namespace stellar::txbridge;
using namespace stellar::txtest;

TEST_CASE("standalone", "[herder][acceptance]")
TEST_CASE_VERSIONS("standalone", "[herder][acceptance]")
{
SIMULATION_CREATE_NODE(0);

Expand Down Expand Up @@ -274,8 +274,7 @@ testTxSet(uint32 protocolVersion)
int64_t amountPop =
nbTransactions * app->getLedgerManager().getLastTxFee() + minBalance0;

TxSetFramePtr txSet = std::make_shared<TxSetFrame>(
app->getLedgerManager().getLastClosedLedgerHeader().hash);
TxSetFramePtr txSet = std::make_shared<TxSetFrame>(Hash{});

auto genTx = [&](int nbTxs) {
std::string accountName = fmt::format("A{}", accounts.size());
Expand All @@ -293,13 +292,18 @@ testTxSet(uint32 protocolVersion)
genTx(nbTransactions);
}

txSet->previousLedgerHash() =
app->getLedgerManager().getLastClosedLedgerHeader().hash;

SECTION("too many txs")
{
while (txSet->mTransactions.size() <=
cfg.TESTING_UPGRADE_MAX_TX_SET_SIZE)
{
genTx(1);
}
txSet->previousLedgerHash() =
app->getLedgerManager().getLastClosedLedgerHeader().hash;
txSet->sortForHash();
REQUIRE(!txSet->checkValid(*app, 0, 0));
}
Expand Down Expand Up @@ -446,14 +450,14 @@ testTxSetWithFeeBumps(uint32 protocolVersion)
auto const minBalance0 = app->getLedgerManager().getLastMinBalance(0);
auto const minBalance2 = app->getLedgerManager().getLastMinBalance(2);

auto txSet = std::make_shared<TxSetFrame>(
app->getLedgerManager().getLastClosedLedgerHeader().hash);

auto root = TestAccount::createRoot(*app);
auto account1 = root.create("a1", minBalance2);
auto account2 = root.create("a2", minBalance2);
auto account3 = root.create("a3", minBalance2);

auto txSet = std::make_shared<TxSetFrame>(
app->getLedgerManager().getLastClosedLedgerHeader().hash);

auto checkTrimCheck = [&](std::vector<TransactionFrameBasePtr> const& txs) {
txSet->sortForHash();
REQUIRE(!txSet->checkValid(*app, 0, 0));
Expand Down Expand Up @@ -688,8 +692,7 @@ TEST_CASE("txset base fee", "[herder][txset]")

auto accounts = std::vector<TestAccount>{};

TxSetFramePtr txSet = std::make_shared<TxSetFrame>(
app->getLedgerManager().getLastClosedLedgerHeader().hash);
TxSetFramePtr txSet = std::make_shared<TxSetFrame>(Hash{});

for (uint32 i = 0; i < nbTransactions; i++)
{
Expand All @@ -713,6 +716,9 @@ TEST_CASE("txset base fee", "[herder][txset]")

REQUIRE(txSet->size(lhCopy) == lim);
REQUIRE(extraAccounts >= 2);

txSet->previousLedgerHash() =
app->getLedgerManager().getLastClosedLedgerHeader().hash;
txSet->sortForHash();
REQUIRE(txSet->checkValid(*app, 0, 0));

Expand All @@ -727,7 +733,7 @@ TEST_CASE("txset base fee", "[herder][txset]")
auto balancesBefore = getBalances();

// apply this
closeLedgerOn(*app, 2, 1, 1, 2020, txSet->mTransactions);
closeLedger(*app, txSet->mTransactions);

auto balancesAfter = getBalances();
int64_t lowFee = INT64_MAX, highFee = 0;
Expand Down Expand Up @@ -2490,8 +2496,11 @@ externalize(SecretKey const& sk, LedgerManager& lm, HerderImpl& herder,
herder.getPendingEnvelopes().putTxSet(txSet->getContentsHash(), ledgerSeq,
txSet);

StellarValue sv = herder.makeStellarValue(
txSet->getContentsHash(), 2, xdr::xvector<UpgradeType, 6>{}, sk);
auto lastCloseTime = lcl.header.scpValue.closeTime;

StellarValue sv =
herder.makeStellarValue(txSet->getContentsHash(), lastCloseTime,
xdr::xvector<UpgradeType, 6>{}, sk);
herder.getHerderSCPDriver().valueExternalized(ledgerSeq,
xdr::xdr_to_opaque(sv));
}
Expand Down
17 changes: 10 additions & 7 deletions src/herder/test/TransactionQueueTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,12 +893,14 @@ TEST_CASE("transaction queue starting sequence boundary",
auto root = TestAccount::createRoot(*app);
auto acc1 = root.create("a1", minBalance2);

closeLedgerOn(*app, 2, 1, 1, 2020);
closeLedgerOn(*app, 3, 1, 1, 2020);
closeLedger(*app);
closeLedger(*app);

auto nextLedgerSeq = app->getLedgerManager().getLastClosedLedgerNum();

SECTION("check a single transaction")
{
int64_t startingSeq = static_cast<int64_t>(4) << 32;
int64_t startingSeq = static_cast<int64_t>(nextLedgerSeq) << 32;
REQUIRE(acc1.loadSequenceNumber() < startingSeq);
acc1.bumpSequence(startingSeq - 1);
REQUIRE(acc1.loadSequenceNumber() == startingSeq - 1);
Expand All @@ -921,7 +923,7 @@ TEST_CASE("transaction queue starting sequence boundary",

SECTION("check a chain of transactions")
{
int64_t startingSeq = static_cast<int64_t>(4) << 32;
int64_t startingSeq = static_cast<int64_t>(nextLedgerSeq) << 32;
REQUIRE(acc1.loadSequenceNumber() < startingSeq);
acc1.bumpSequence(startingSeq - 3);
REQUIRE(acc1.loadSequenceNumber() == startingSeq - 3);
Expand Down Expand Up @@ -1435,9 +1437,10 @@ TEST_CASE("remove applied", "[herder][transactionqueue]")
herder.getPendingEnvelopes().putTxSet(txSet->getContentsHash(),
ledgerSeq, txSet);

StellarValue sv = herder.makeStellarValue(txSet->getContentsHash(), 2,
emptyUpgradeSteps,
app->getConfig().NODE_SEED);
auto lastCloseTime = lcl.header.scpValue.closeTime;
StellarValue sv = herder.makeStellarValue(
txSet->getContentsHash(), lastCloseTime, emptyUpgradeSteps,
app->getConfig().NODE_SEED);
herder.getHerderSCPDriver().valueExternalized(ledgerSeq,
xdr::xdr_to_opaque(sv));
}
Expand Down
56 changes: 28 additions & 28 deletions src/herder/test/UpgradesTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1673,15 +1673,11 @@ TEST_CASE("upgrade to version 13", "[upgrades]")
}
}

TEST_CASE("upgrade base reserve", "[upgrades]")
TEST_CASE_VERSIONS("upgrade base reserve", "[upgrades]")
{
VirtualClock clock;
auto cfg = getTestConfig(0);

// Do our setup in version 0 so that for_versions_* below do not
// try to downgrade us from >0 to 0.
cfg.USE_CONFIG_FOR_GENESIS = false;

auto app = createTestApplication(clock, cfg);

auto& lm = app->getLedgerManager();
Expand Down Expand Up @@ -2224,11 +2220,9 @@ TEST_CASE("simulate upgrades", "[herder][upgrades][acceptance]")
}
}

TEST_CASE("upgrade invalid during ledger close", "[upgrades]")
TEST_CASE_VERSIONS("upgrade invalid during ledger close", "[upgrades]")
{
VirtualClock clock;
// Do our setup in version 0 so that for_versions_* below do not
// try to downgrade us from >0 to 0.
auto cfg = getTestConfig();
cfg.USE_CONFIG_FOR_GENESIS = false;

Expand All @@ -2249,27 +2243,36 @@ TEST_CASE("upgrade invalid during ledger close", "[upgrades]")
*app, makeProtocolVersionUpgrade(
Config::CURRENT_LEDGER_PROTOCOL_VERSION - 1)));
}
SECTION("Invalid flags")
{
// Base Fee / Base Reserve to 0
REQUIRE_THROWS(executeUpgrade(*app, makeBaseFeeUpgrade(0)));
REQUIRE_THROWS(executeUpgrade(*app, makeBaseReserveUpgrade(0)));

// Base Fee / Base Reserve to 0
REQUIRE_THROWS(executeUpgrade(*app, makeBaseFeeUpgrade(0)));
REQUIRE_THROWS(executeUpgrade(*app, makeBaseReserveUpgrade(0)));
if (cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION > 0)
{
executeUpgrade(*app,
makeProtocolVersionUpgrade(
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION));
}

for_versions_to(17, *app, [&] {
REQUIRE_THROWS(executeUpgrade(*app, makeFlagsUpgrade(1)));
});
for_versions_to(17, *app, [&] {
REQUIRE_THROWS(executeUpgrade(*app, makeFlagsUpgrade(1)));
});

for_versions_from(18, *app, [&] {
auto allFlags = DISABLE_LIQUIDITY_POOL_TRADING_FLAG |
DISABLE_LIQUIDITY_POOL_DEPOSIT_FLAG |
DISABLE_LIQUIDITY_POOL_WITHDRAWAL_FLAG;
REQUIRE(allFlags == MASK_LEDGER_HEADER_FLAGS);
for_versions_from(18, *app, [&] {
auto allFlags = DISABLE_LIQUIDITY_POOL_TRADING_FLAG |
DISABLE_LIQUIDITY_POOL_DEPOSIT_FLAG |
DISABLE_LIQUIDITY_POOL_WITHDRAWAL_FLAG;
REQUIRE(allFlags == MASK_LEDGER_HEADER_FLAGS);

REQUIRE_THROWS(executeUpgrade(
*app, makeFlagsUpgrade(MASK_LEDGER_HEADER_FLAGS + 1)));
REQUIRE_THROWS(executeUpgrade(
*app, makeFlagsUpgrade(MASK_LEDGER_HEADER_FLAGS + 1)));

// success
executeUpgrade(*app, makeFlagsUpgrade(MASK_LEDGER_HEADER_FLAGS));
});
// success
executeUpgrade(*app, makeFlagsUpgrade(MASK_LEDGER_HEADER_FLAGS));
});
}
}

TEST_CASE("validate upgrade expiration logic", "[upgrades]")
Expand Down Expand Up @@ -2362,13 +2365,10 @@ TEST_CASE("upgrade from cpp14 serialized data", "[upgrades]")
REQUIRE(!up.mBaseReserve.has_value());
}

TEST_CASE("upgrade flags", "[upgrades][liquiditypool]")
TEST_CASE_VERSIONS("upgrade flags", "[upgrades][liquiditypool]")
{
VirtualClock clock;
// Do our setup in version 0 so that for_versions_* below do not
// try to downgrade us from >0 to 0.
auto cfg = getTestConfig();
cfg.USE_CONFIG_FOR_GENESIS = false;

auto app = createTestApplication(clock, cfg);

Expand Down
4 changes: 2 additions & 2 deletions src/history/test/HistoryTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,8 +1111,8 @@ TEST_CASE("Publish catchup via s3", "[!hide][s3]")
REQUIRE(catchupSimulation.catchupOnline(app, checkpointLedger, 5));
}

TEST_CASE("HAS in publishqueue remains in pristine state until publish",
"[history]")
TEST_CASE_VERSIONS(
"HAS in publishqueue remains in pristine state until publish", "[history]")
{
// In this test we generate some buckets and cause a checkpoint to be
// published, checking that the (cached) set of buckets referenced by the
Expand Down
Loading

0 comments on commit a4bcabb

Please sign in to comment.