Skip to content

Commit

Permalink
!fixup Add a test for verifying the phase format on protocol boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
dmkozh committed Dec 13, 2024
1 parent 3954df5 commit 77e922b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/herder/test/TestTxSetUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,19 @@ makeNonValidatedTxSet(std::vector<TransactionFrameBasePtr> const& txs,
std::pair<TxSetXDRFrameConstPtr, ApplicableTxSetFrameConstPtr>
makeNonValidatedGeneralizedTxSet(
std::vector<ComponentPhases> const& txsPerBaseFee, Application& app,
Hash const& previousLedgerHash)
Hash const& previousLedgerHash, std::optional<bool> useParallelSorobanPhase)
{
bool useParallelSorobanPhase = protocolVersionStartsFrom(
app.getLedgerManager().getLastClosedLedgerHeader().header.ledgerVersion,
PARALLEL_SOROBAN_PHASE_PROTOCOL_VERSION);
if (!useParallelSorobanPhase.has_value())
{
useParallelSorobanPhase =
protocolVersionStartsFrom(app.getLedgerManager()
.getLastClosedLedgerHeader()
.header.ledgerVersion,
PARALLEL_SOROBAN_PHASE_PROTOCOL_VERSION);
}

auto xdrTxSet = makeGeneralizedTxSetXDR(txsPerBaseFee, previousLedgerHash,
useParallelSorobanPhase);
*useParallelSorobanPhase);
auto txSet = TxSetXDRFrame::makeFromWire(xdrTxSet);
return std::make_pair(txSet, txSet->prepareForApply(app));
}
Expand Down
3 changes: 2 additions & 1 deletion src/herder/test/TestTxSetUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ using ComponentPhases = std::vector<
std::pair<TxSetXDRFrameConstPtr, ApplicableTxSetFrameConstPtr>
makeNonValidatedGeneralizedTxSet(
std::vector<ComponentPhases> const& txsPerBaseFee, Application& app,
Hash const& previousLedgerHash);
Hash const& previousLedgerHash,
std::optional<bool> useParallelSorobanPhase = std::nullopt);

std::pair<TxSetXDRFrameConstPtr, ApplicableTxSetFrameConstPtr>
makeNonValidatedTxSetBasedOnLedgerVersion(
Expand Down
54 changes: 54 additions & 0 deletions src/herder/test/TxSetTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,60 @@ SECTION("parallel soroban protocol version")
#endif
}

TEST_CASE("soroban phase version validation", "[txset][soroban]")
{
auto runTest = [](uint32_t protocolVersion,
bool useParallelSorobanPhase) -> bool {
VirtualClock clock;
auto cfg = getTestConfig();
cfg.LEDGER_PROTOCOL_VERSION = protocolVersion;
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION = protocolVersion;
auto app = createTestApplication(clock, cfg);
auto txSet =
testtxset::makeNonValidatedGeneralizedTxSet(
{{}, {}}, *app,
app->getLedgerManager().getLastClosedLedgerHeader().hash,
useParallelSorobanPhase)
.second;
REQUIRE(txSet);
return txSet->checkValid(*app, 0, 0);
};
SECTION("sequential phase")
{
SECTION("valid before parallel tx set protocol version")
{
REQUIRE(runTest(
static_cast<uint32_t>(PARALLEL_SOROBAN_PHASE_PROTOCOL_VERSION) -
1,
false));
}
}
#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
SECTION("sequential phase invalid at parallel tx set protocol version")
{
REQUIRE(!runTest(
static_cast<uint32_t>(PARALLEL_SOROBAN_PHASE_PROTOCOL_VERSION),
false));
}
SECTION("parallel phase")
{
SECTION("valid before parallel tx set protocol version")
{
REQUIRE(!runTest(
static_cast<uint32_t>(PARALLEL_SOROBAN_PHASE_PROTOCOL_VERSION) -
1,
true));
}
SECTION("invalid at parallel tx set protocol version")
{
REQUIRE(runTest(
static_cast<uint32_t>(PARALLEL_SOROBAN_PHASE_PROTOCOL_VERSION),
true));
}
}
#endif
}

TEST_CASE("generalized tx set with multiple txs per source account",
"[txset][soroban]")
{
Expand Down

0 comments on commit 77e922b

Please sign in to comment.