Skip to content

Commit 7d0b178

Browse files
committed
Update tests
1 parent 3a4adf4 commit 7d0b178

File tree

3 files changed

+33
-40
lines changed

3 files changed

+33
-40
lines changed

src/bucket/test/BucketListTests.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -959,11 +959,8 @@ TEST_CASE_VERSIONS("eviction scan", "[bucketlist]")
959959
auto& bm = app->getBucketManager();
960960
auto& bl = bm.getLiveBucketList();
961961

962-
auto& networkCfg = [&]() -> SorobanNetworkConfig& {
963-
LedgerTxn ltx(app->getLedgerTxnRoot());
964-
return app->getLedgerManager().getMutableSorobanNetworkConfig();
965-
}();
966-
962+
auto& networkCfg =
963+
app->getLedgerManager().getMutableSorobanNetworkConfig();
967964
auto& stateArchivalSettings = networkCfg.stateArchivalSettings();
968965
auto& evictionIter = networkCfg.evictionIterator();
969966
auto const levelToScan = 3;

src/ledger/LedgerManagerImpl.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -529,26 +529,20 @@ LedgerManagerImpl::getSorobanNetworkConfig()
529529
{
530530
releaseAssert(hasSorobanNetworkConfig());
531531
#ifdef BUILD_TESTS
532-
if (mApp.getConfig().MODE_USES_IN_MEMORY_LEDGER)
533-
{
534-
return *mSorobanNetworkConfig;
535-
}
536-
else
532+
return *mSorobanNetworkConfig;
533+
#else
534+
return getLastClosedLedger(mApp).getSorobanNetworkConfig().value();
537535
#endif
538-
return getLastClosedLedger(mApp).getSorobanNetworkConfig().value();
539536
}
540537

541538
bool
542539
LedgerManagerImpl::hasSorobanNetworkConfig() const
543540
{
544541
#ifdef BUILD_TESTS
545-
if (mApp.getConfig().MODE_USES_IN_MEMORY_LEDGER)
546-
{
547-
return mSorobanNetworkConfig.has_value();
548-
}
549-
else
542+
return mSorobanNetworkConfig.has_value();
543+
#else
544+
return getLastClosedLedger(mApp).getSorobanNetworkConfig().has_value();
550545
#endif
551-
return getLastClosedLedger(mApp).getSorobanNetworkConfig().has_value();
552546
}
553547

554548
#ifdef BUILD_TESTS

src/transactions/test/InvokeHostFunctionTests.cpp

+25-23
Original file line numberDiff line numberDiff line change
@@ -2082,16 +2082,18 @@ TEST_CASE("state archival", "[tx][soroban]")
20822082
cfg.mWriteFee1KBBucketListLow = 20'000;
20832083
cfg.mWriteFee1KBBucketListHigh = 1'000'000;
20842084
});
2085-
auto const& stateArchivalSettings =
2086-
test.getNetworkCfg().stateArchivalSettings();
2085+
2086+
auto getArchivalSettings = [&]() {
2087+
return test.getNetworkCfg().stateArchivalSettings();
2088+
};
20872089
auto isSuccess = [](auto resultCode) {
20882090
return resultCode == INVOKE_HOST_FUNCTION_SUCCESS;
20892091
};
20902092
ContractStorageTestClient client(test);
20912093
SECTION("contract instance and Wasm archival")
20922094
{
20932095
uint32_t originalExpectedLiveUntilLedger =
2094-
test.getLCLSeq() + stateArchivalSettings.minPersistentTTL - 1;
2096+
test.getLCLSeq() + getArchivalSettings().minPersistentTTL - 1;
20952097

20962098
for (uint32_t i =
20972099
test.getApp().getLedgerManager().getLastClosedLedgerNum();
@@ -2121,7 +2123,7 @@ TEST_CASE("state archival", "[tx][soroban]")
21212123
40000 /* two LE-writes
21222124
*/);
21232125
auto newExpectedLiveUntilLedger =
2124-
test.getLCLSeq() + stateArchivalSettings.minPersistentTTL - 1;
2126+
test.getLCLSeq() + getArchivalSettings().minPersistentTTL - 1;
21252127

21262128
// Instance should now be useable
21272129
REQUIRE(isSuccess(
@@ -2137,7 +2139,7 @@ TEST_CASE("state archival", "[tx][soroban]")
21372139
939 /* rent bump */ +
21382140
20000 /* one LE write */);
21392141
auto newExpectedLiveUntilLedger =
2140-
test.getLCLSeq() + stateArchivalSettings.minPersistentTTL - 1;
2142+
test.getLCLSeq() + getArchivalSettings().minPersistentTTL - 1;
21412143

21422144
// invocation should fail
21432145
REQUIRE(client.put("temp", ContractDataDurability::TEMPORARY, 0) ==
@@ -2155,7 +2157,7 @@ TEST_CASE("state archival", "[tx][soroban]")
21552157
943 /* rent bump */ +
21562158
20000 /* one LE write */);
21572159
auto newExpectedLiveUntilLedger =
2158-
test.getLCLSeq() + stateArchivalSettings.minPersistentTTL - 1;
2160+
test.getLCLSeq() + getArchivalSettings().minPersistentTTL - 1;
21592161

21602162
// invocation should fail
21612163
REQUIRE(client.put("temp", ContractDataDurability::TEMPORARY, 0) ==
@@ -2194,7 +2196,7 @@ TEST_CASE("state archival", "[tx][soroban]")
21942196
REQUIRE(isSuccess(
21952197
client.put("temp", ContractDataDurability::TEMPORARY, 0)));
21962198
auto expectedTempLiveUntilLedger =
2197-
test.getLCLSeq() + stateArchivalSettings.minTemporaryTTL - 1;
2199+
test.getLCLSeq() + getArchivalSettings().minTemporaryTTL - 1;
21982200

21992201
// Check for expected minimum lifetime values
22002202
REQUIRE(
@@ -2274,7 +2276,7 @@ TEST_CASE("state archival", "[tx][soroban]")
22742276

22752277
// Recreated entry should be live
22762278
REQUIRE(client.getTTL("temp", ContractDataDurability::TEMPORARY) ==
2277-
test.getLCLSeq() + stateArchivalSettings.minTemporaryTTL -
2279+
test.getLCLSeq() + getArchivalSettings().minTemporaryTTL -
22782280
1);
22792281
REQUIRE(isSuccess(
22802282
client.get("temp", ContractDataDurability::TEMPORARY, 42)));
@@ -2329,7 +2331,7 @@ TEST_CASE("state archival", "[tx][soroban]")
23292331
makeSymbolSCVal("persistent2"),
23302332
ContractDataDurability::PERSISTENT);
23312333
uint32_t expectedLiveUntilLedger2 =
2332-
test.getLCLSeq() + stateArchivalSettings.minPersistentTTL - 1;
2334+
test.getLCLSeq() + getArchivalSettings().minPersistentTTL - 1;
23332335
REQUIRE(client.getTTL("persistent2",
23342336
ContractDataDurability::PERSISTENT) ==
23352337
expectedLiveUntilLedger2);
@@ -2347,7 +2349,7 @@ TEST_CASE("state archival", "[tx][soroban]")
23472349
// Check value and TTL of restored entry
23482350
REQUIRE(client.getTTL("persistent",
23492351
ContractDataDurability::PERSISTENT) ==
2350-
test.getLCLSeq() + stateArchivalSettings.minPersistentTTL -
2352+
test.getLCLSeq() + getArchivalSettings().minPersistentTTL -
23512353
1);
23522354
REQUIRE(isSuccess(client.get(
23532355
"persistent", ContractDataDurability::PERSISTENT, 10)));
@@ -2432,12 +2434,12 @@ TEST_CASE("state archival", "[tx][soroban]")
24322434
REQUIRE(isSuccess(
24332435
client.put("key", ContractDataDurability::PERSISTENT, 0)));
24342436
uint32_t initialLiveUntilLedger =
2435-
test.getLCLSeq() + stateArchivalSettings.minPersistentTTL - 1;
2437+
test.getLCLSeq() + getArchivalSettings().minPersistentTTL - 1;
24362438
REQUIRE(client.getTTL("key", ContractDataDurability::PERSISTENT) ==
24372439
initialLiveUntilLedger);
24382440
// Try extending entry, but set the threshold 1 ledger below the
24392441
// current TTL.
2440-
uint32_t currentTTL = stateArchivalSettings.minPersistentTTL - 2;
2442+
uint32_t currentTTL = getArchivalSettings().minPersistentTTL - 2;
24412443
REQUIRE(
24422444
isSuccess(client.extend("key", ContractDataDurability::PERSISTENT,
24432445
currentTTL - 1, 50'000)));
@@ -2467,9 +2469,9 @@ TEST_CASE("state archival", "[tx][soroban]")
24672469
SECTION("extension op")
24682470
{
24692471
// Max TTL includes current ledger, so subtract 1
2470-
test.invokeExtendOp({lk}, stateArchivalSettings.maxEntryTTL - 1);
2472+
test.invokeExtendOp({lk}, getArchivalSettings().maxEntryTTL - 1);
24712473
REQUIRE(test.getTTL(lk) ==
2472-
test.getLCLSeq() + stateArchivalSettings.maxEntryTTL - 1);
2474+
test.getLCLSeq() + getArchivalSettings().maxEntryTTL - 1);
24732475
}
24742476

24752477
SECTION("extend host function persistent")
@@ -2480,14 +2482,14 @@ TEST_CASE("state archival", "[tx][soroban]")
24802482

24812483
REQUIRE(isSuccess(client.extend(
24822484
"key", ContractDataDurability::PERSISTENT,
2483-
stateArchivalSettings.maxEntryTTL + 10,
2484-
stateArchivalSettings.maxEntryTTL + 10,
2485+
getArchivalSettings().maxEntryTTL + 10,
2486+
getArchivalSettings().maxEntryTTL + 10,
24852487
client.readKeySpec("key", ContractDataDurability::PERSISTENT)
24862488
.setRefundableResourceFee(80'000))));
24872489

24882490
// Capped at max (Max TTL includes current ledger, so subtract 1)
24892491
REQUIRE(test.getTTL(lk) ==
2490-
test.getLCLSeq() + stateArchivalSettings.maxEntryTTL - 1);
2492+
test.getLCLSeq() + getArchivalSettings().maxEntryTTL - 1);
24912493
}
24922494

24932495
SECTION("extend host function temp")
@@ -2498,19 +2500,19 @@ TEST_CASE("state archival", "[tx][soroban]")
24982500
makeSymbolSCVal("key"), ContractDataDurability::TEMPORARY);
24992501
uint32_t ledgerSeq = test.getLCLSeq();
25002502
REQUIRE(client.extend("key", ContractDataDurability::TEMPORARY,
2501-
stateArchivalSettings.maxEntryTTL,
2502-
stateArchivalSettings.maxEntryTTL) ==
2503+
getArchivalSettings().maxEntryTTL,
2504+
getArchivalSettings().maxEntryTTL) ==
25032505
INVOKE_HOST_FUNCTION_TRAPPED);
25042506
REQUIRE(test.getTTL(lkTemp) ==
2505-
ledgerSeq + stateArchivalSettings.minTemporaryTTL - 1);
2507+
ledgerSeq + getArchivalSettings().minTemporaryTTL - 1);
25062508

25072509
// Max TTL includes current ledger, so subtract 1
25082510
REQUIRE(isSuccess(
25092511
client.extend("key", ContractDataDurability::TEMPORARY,
2510-
stateArchivalSettings.maxEntryTTL - 1,
2511-
stateArchivalSettings.maxEntryTTL - 1)));
2512+
getArchivalSettings().maxEntryTTL - 1,
2513+
getArchivalSettings().maxEntryTTL - 1)));
25122514
REQUIRE(test.getTTL(lkTemp) ==
2513-
test.getLCLSeq() + stateArchivalSettings.maxEntryTTL - 1);
2515+
test.getLCLSeq() + getArchivalSettings().maxEntryTTL - 1);
25142516
}
25152517
}
25162518
}

0 commit comments

Comments
 (0)