Skip to content

Commit 85953cd

Browse files
committed
Adapt testsuite to fastdev
1 parent 9db3187 commit 85953cd

9 files changed

Lines changed: 267 additions & 33 deletions

File tree

common.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ if ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
4343
AM_CPPFLAGS += -DENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
4444
endif # ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
4545

46+
if ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
47+
AM_CPPFLAGS += -DENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
48+
endif # ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
49+
4650
if CAP_0083
4751
AM_CPPFLAGS += -DCAP_0083
4852
endif

src/herder/test/HerderTests.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,15 @@ TEST_CASE("txset", "[herder][txset]")
10421042
{
10431043
SECTION("generalized tx set protocol")
10441044
{
1045-
testTxSet(static_cast<uint32>(SOROBAN_PROTOCOL_VERSION));
1045+
uint32_t generalizedTxSetProtocolVersion =
1046+
static_cast<uint32>(SOROBAN_PROTOCOL_VERSION);
1047+
#ifdef ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
1048+
// Fastdev only links recent Soroban hosts, and this test just needs a
1049+
// generalized-txset-capable protocol.
1050+
generalizedTxSetProtocolVersion =
1051+
Config::CURRENT_LEDGER_PROTOCOL_VERSION - 1;
1052+
#endif
1053+
testTxSet(generalizedTxSetProtocolVersion);
10461054
}
10471055
SECTION("protocol current")
10481056
{
@@ -1450,6 +1458,12 @@ TEST_CASE("txset base fee", "[herder][txset]")
14501458
uint32_t expNotChargedAccounts = 0) {
14511459
cfg.LEDGER_PROTOCOL_VERSION = protocolVersion;
14521460
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION = protocolVersion;
1461+
if (!testutil::isTestApplicationProtocolVersionSupported(cfg))
1462+
{
1463+
SUCCEED("Skipping historical Soroban protocol test: requested "
1464+
"protocol is not linked in this build");
1465+
return;
1466+
}
14531467
VirtualClock clock;
14541468
Application::pointer app = createTestApplication(clock, cfg);
14551469

@@ -1671,7 +1685,7 @@ TEST_CASE("tx set hits overlay byte limit during construction",
16711685
{
16721686
Config cfg(getTestConfig());
16731687
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
1674-
static_cast<uint32_t>(SOROBAN_PROTOCOL_VERSION);
1688+
Config::CURRENT_LEDGER_PROTOCOL_VERSION;
16751689
auto max = std::numeric_limits<uint32_t>::max();
16761690
cfg.TESTING_UPGRADE_MAX_TX_SET_SIZE = max;
16771691
// Pre-create enough genesis accounts for the test

src/herder/test/TransactionQueueTests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,15 @@ TEST_CASE("TransactionQueue Key Filtering", "[soroban][transactionqueue]")
14301430
}
14311431
SECTION("protocol version 24")
14321432
{
1433+
auto cfg = getTestConfig();
1434+
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION = 24;
1435+
if (!testutil::isTestApplicationProtocolVersionSupported(cfg))
1436+
{
1437+
SUCCEED("Skipping historical Soroban protocol test: requested "
1438+
"protocol is not linked in this build");
1439+
return;
1440+
}
1441+
14331442
SECTION("should filter")
14341443
{
14351444
for (auto const& keyToFilter : keysToFilterP24)

src/herder/test/TxSetTests.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ testGeneralizedTxSetXDRConversion(ProtocolVersion protocolVersion)
482482
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
483483
static_cast<uint32_t>(protocolVersion);
484484
cfg.GENESIS_TEST_ACCOUNT_COUNT = 10000;
485+
if (!testutil::isTestApplicationProtocolVersionSupported(cfg))
486+
{
487+
SUCCEED("Skipping historical Soroban protocol test: requested "
488+
"protocol is not linked in this build");
489+
return;
490+
}
485491
bool isParallelSoroban = protocolVersionStartsFrom(
486492
cfg.LEDGER_PROTOCOL_VERSION, PARALLEL_SOROBAN_PHASE_PROTOCOL_VERSION);
487493

@@ -1064,6 +1070,16 @@ TEST_CASE("generalized tx set XDR conversion", "[txset]")
10641070
TEST_CASE("applicable txset validation - Soroban phase version is correct",
10651071
"[txset][soroban]")
10661072
{
1073+
auto historicalCfg = getTestConfig();
1074+
historicalCfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
1075+
static_cast<uint32_t>(PARALLEL_SOROBAN_PHASE_PROTOCOL_VERSION) - 1;
1076+
if (!testutil::isTestApplicationProtocolVersionSupported(historicalCfg))
1077+
{
1078+
SUCCEED("Skipping historical Soroban protocol test: requested "
1079+
"protocol is not linked in this build");
1080+
return;
1081+
}
1082+
10671083
auto runTest = [](uint32_t protocolVersion,
10681084
bool useParallelSorobanPhase) -> TxSetValidationResult {
10691085
VirtualClock clock;
@@ -2497,10 +2513,15 @@ runParallelTxSetBuildingTest(bool variableStageCount)
24972513

24982514
VirtualClock clock;
24992515
auto cfg = getTestConfig();
2500-
cfg.LEDGER_PROTOCOL_VERSION =
2501-
static_cast<uint32_t>(PARALLEL_SOROBAN_PHASE_PROTOCOL_VERSION);
2502-
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
2516+
uint32_t testLedgerProtocolVersion =
25032517
static_cast<uint32_t>(PARALLEL_SOROBAN_PHASE_PROTOCOL_VERSION);
2518+
#ifdef ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
2519+
// Fastdev only links recent Soroban hosts, so avoid forcing this test
2520+
// through the first historical parallel-Soroban protocol in next builds.
2521+
testLedgerProtocolVersion = Config::CURRENT_LEDGER_PROTOCOL_VERSION - 1;
2522+
#endif
2523+
cfg.LEDGER_PROTOCOL_VERSION = testLedgerProtocolVersion;
2524+
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION = testLedgerProtocolVersion;
25042525
cfg.SOROBAN_PHASE_MIN_STAGE_COUNT = variableStageCount ? 1 : STAGE_COUNT;
25052526
cfg.SOROBAN_PHASE_MAX_STAGE_COUNT = STAGE_COUNT;
25062527
// Temporary set the limits override very high in order for the upgrades

src/herder/test/UpgradesTests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,12 @@ TEST_CASE("upgrades affect in-memory Soroban state state size",
10471047
auto cfg = getTestConfig();
10481048
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION = 22;
10491049
cfg.USE_CONFIG_FOR_GENESIS = true;
1050+
if (!testutil::isTestApplicationProtocolVersionSupported(cfg))
1051+
{
1052+
SUCCEED("Skipping historical Soroban protocol test: requested "
1053+
"protocol is not linked in this build");
1054+
return;
1055+
}
10501056

10511057
uint32_t const windowSize = 15;
10521058
uint32_t const samplePeriod = 4;
@@ -3892,6 +3898,12 @@ TEST_CASE("protocol 23 upgrade sets default SCP timing values", "[upgrades]")
38923898
VirtualClock clock;
38933899
auto cfg = getTestConfig(0, Config::TESTDB_IN_MEMORY);
38943900
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION = 22;
3901+
if (!testutil::isTestApplicationProtocolVersionSupported(cfg))
3902+
{
3903+
SUCCEED("Skipping historical Soroban protocol test: requested "
3904+
"protocol is not linked in this build");
3905+
return;
3906+
}
38953907

38963908
auto app = createTestApplication(clock, cfg);
38973909
auto& lm = app->getLedgerManager();
@@ -4043,6 +4055,12 @@ TEST_CASE("p24 upgrade fixes corrupted hot archive entries",
40434055
Config cfg(getTestConfig());
40444056
cfg.USE_CONFIG_FOR_GENESIS = true;
40454057
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION = corruptedProtocolVersion;
4058+
if (!testutil::isTestApplicationProtocolVersionSupported(cfg))
4059+
{
4060+
SUCCEED("Skipping historical Soroban protocol test: requested "
4061+
"protocol is not linked in this build");
4062+
return;
4063+
}
40464064
auto app = createTestApplication(clock, cfg);
40474065
gIsProductionNetwork = true;
40484066
overrideSorobanNetworkConfigForTest(*app);

src/test/TestUtils.cpp

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "herder/TxSetFrame.h"
77
#include "ledger/ImmutableLedgerView.h"
88
#include "ledger/test/LedgerTestUtils.h"
9+
#include "rust/RustBridge.h"
910
#include "simulation/LoadGenerator.h"
1011
#include "simulation/Simulation.h"
1112
#include "test/TxTests.h"
@@ -16,12 +17,120 @@
1617
#include "work/WorkScheduler.h"
1718
#include "xdrpp/marshal.h"
1819

20+
#include <algorithm>
21+
#include <sstream>
22+
1923
namespace stellar
2024
{
2125

2226
namespace testutil
2327
{
2428

29+
bool isTestApplicationProtocolVersionSupported(Config const& cfg);
30+
31+
namespace
32+
{
33+
bool
34+
isProtocolBackedByLinkedSorobanHost(uint32_t protocolVersion,
35+
std::vector<uint32_t> const& hostProtocols)
36+
{
37+
if (protocolVersionIsBefore(protocolVersion, SOROBAN_PROTOCOL_VERSION))
38+
{
39+
return true;
40+
}
41+
42+
auto selectedHost = std::find_if(
43+
hostProtocols.begin(), hostProtocols.end(),
44+
[&](uint32_t hostProtocol) { return protocolVersion <= hostProtocol; });
45+
if (selectedHost == hostProtocols.end())
46+
{
47+
return false;
48+
}
49+
50+
// Protocol 20 is serviced by the p21 host. All later Soroban protocols
51+
// should have their own linked host in non-fastdev builds.
52+
return protocolVersion == static_cast<uint32_t>(SOROBAN_PROTOCOL_VERSION)
53+
? *selectedHost == static_cast<uint32_t>(ProtocolVersion::V_21)
54+
: *selectedHost == protocolVersion;
55+
}
56+
57+
std::string
58+
joinProtocolVersions(std::vector<uint32_t> const& protocolVersions)
59+
{
60+
std::ostringstream out;
61+
for (size_t i = 0; i < protocolVersions.size(); ++i)
62+
{
63+
if (i != 0)
64+
{
65+
out << ", ";
66+
}
67+
out << protocolVersions[i];
68+
}
69+
return out.str();
70+
}
71+
}
72+
73+
void
74+
validateTestApplicationProtocolVersion(Config const& cfg)
75+
{
76+
if (isTestApplicationProtocolVersionSupported(cfg))
77+
{
78+
return;
79+
}
80+
81+
auto const protocolVersion = cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION;
82+
std::vector<uint32_t> hostProtocols;
83+
auto rustVersions = rust_bridge::get_soroban_version_info(
84+
Config::CURRENT_LEDGER_PROTOCOL_VERSION);
85+
for (auto const& host : rustVersions)
86+
{
87+
hostProtocols.emplace_back(host.env_max_proto);
88+
}
89+
90+
std::ostringstream msg;
91+
msg << "Test application requested genesis ledger protocol "
92+
<< protocolVersion
93+
<< ", but this binary does not have the matching Soroban host linked. "
94+
<< "Linked Soroban host protocols: ["
95+
<< joinProtocolVersions(hostProtocols)
96+
<< "]. This usually means the build is using fastdev/unified Rust "
97+
<< "mode, where historical Soroban protocols are collapsed to a newer "
98+
<< "host and can fail later with opaque Soroban invocation errors. "
99+
<< "Use a linked protocol for this test, or rebuild without fastdev "
100+
<< "when testing historical Soroban protocol behavior.";
101+
throw std::runtime_error(msg.str());
102+
}
103+
104+
bool
105+
isTestApplicationProtocolVersionSupported(Config const& cfg)
106+
{
107+
if (!cfg.USE_CONFIG_FOR_GENESIS)
108+
{
109+
return true;
110+
}
111+
112+
auto const protocolVersion = cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION;
113+
if (protocolVersionIsBefore(protocolVersion, SOROBAN_PROTOCOL_VERSION))
114+
{
115+
return true;
116+
}
117+
118+
std::vector<uint32_t> hostProtocols;
119+
auto rustVersions = rust_bridge::get_soroban_version_info(
120+
Config::CURRENT_LEDGER_PROTOCOL_VERSION);
121+
for (auto const& host : rustVersions)
122+
{
123+
hostProtocols.emplace_back(host.env_max_proto);
124+
}
125+
126+
if (isProtocolBackedByLinkedSorobanHost(protocolVersion, hostProtocols))
127+
{
128+
return true;
129+
}
130+
131+
return false;
132+
}
133+
25134
void
26135
crankSome(VirtualClock& clock)
27136
{

src/test/TestUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ std::vector<Asset> getInvalidAssets(SecretKey const& issuer);
3434

3535
int32_t computeMultiplier(LedgerEntry const& le);
3636

37+
bool isTestApplicationProtocolVersionSupported(Config const& cfg);
38+
void validateTestApplicationProtocolVersion(Config const& cfg);
39+
3740
template <class BucketT> class BucketListDepthModifier
3841
{
3942
BUCKET_TYPE_ASSERT(BucketT);
@@ -90,6 +93,7 @@ std::shared_ptr<T>
9093
createTestApplication(VirtualClock& clock, Config const& cfg, Args&&... args,
9194
bool newDB = true, bool startApp = true)
9295
{
96+
testutil::validateTestApplicationProtocolVersion(cfg);
9397
Config c2(cfg);
9498
c2.adjust();
9599
auto app = Application::create<T, Args...>(

src/transactions/test/FrozenLedgerKeysTests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ TEST_CASE("frozen ledger keys config setting does not exist prior to p26",
150150
cfg.LEDGER_PROTOCOL_VERSION = static_cast<uint32_t>(ProtocolVersion::V_25);
151151
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
152152
static_cast<uint32_t>(ProtocolVersion::V_25);
153+
if (!testutil::isTestApplicationProtocolVersionSupported(cfg))
154+
{
155+
SUCCEED("Skipping historical Soroban protocol test: requested "
156+
"protocol is not linked in this build");
157+
return;
158+
}
153159
auto app = createTestApplication(clock, cfg);
154160
auto root = app->getRoot();
155161
CheckValidLedgerViewWrapper ledgerView(*app);
@@ -166,6 +172,12 @@ TEST_CASE("freeze bypass txs config setting does not exist prior to p26",
166172
cfg.LEDGER_PROTOCOL_VERSION = static_cast<uint32_t>(ProtocolVersion::V_25);
167173
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
168174
static_cast<uint32_t>(ProtocolVersion::V_25);
175+
if (!testutil::isTestApplicationProtocolVersionSupported(cfg))
176+
{
177+
SUCCEED("Skipping historical Soroban protocol test: requested "
178+
"protocol is not linked in this build");
179+
return;
180+
}
169181
auto app = createTestApplication(clock, cfg);
170182
auto root = app->getRoot();
171183
CheckValidLedgerViewWrapper ledgerView(*app);

0 commit comments

Comments
 (0)