Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marta-lokhova committed Dec 21, 2024
1 parent 3a4adf4 commit 7d0b178
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 40 deletions.
7 changes: 2 additions & 5 deletions src/bucket/test/BucketListTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,11 +959,8 @@ TEST_CASE_VERSIONS("eviction scan", "[bucketlist]")
auto& bm = app->getBucketManager();
auto& bl = bm.getLiveBucketList();

auto& networkCfg = [&]() -> SorobanNetworkConfig& {
LedgerTxn ltx(app->getLedgerTxnRoot());
return app->getLedgerManager().getMutableSorobanNetworkConfig();
}();

auto& networkCfg =
app->getLedgerManager().getMutableSorobanNetworkConfig();
auto& stateArchivalSettings = networkCfg.stateArchivalSettings();
auto& evictionIter = networkCfg.evictionIterator();
auto const levelToScan = 3;
Expand Down
18 changes: 6 additions & 12 deletions src/ledger/LedgerManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,26 +529,20 @@ LedgerManagerImpl::getSorobanNetworkConfig()
{
releaseAssert(hasSorobanNetworkConfig());
#ifdef BUILD_TESTS
if (mApp.getConfig().MODE_USES_IN_MEMORY_LEDGER)
{
return *mSorobanNetworkConfig;
}
else
return *mSorobanNetworkConfig;
#else
return getLastClosedLedger(mApp).getSorobanNetworkConfig().value();
#endif
return getLastClosedLedger(mApp).getSorobanNetworkConfig().value();
}

bool
LedgerManagerImpl::hasSorobanNetworkConfig() const
{
#ifdef BUILD_TESTS
if (mApp.getConfig().MODE_USES_IN_MEMORY_LEDGER)
{
return mSorobanNetworkConfig.has_value();
}
else
return mSorobanNetworkConfig.has_value();
#else
return getLastClosedLedger(mApp).getSorobanNetworkConfig().has_value();
#endif
return getLastClosedLedger(mApp).getSorobanNetworkConfig().has_value();
}

#ifdef BUILD_TESTS
Expand Down
48 changes: 25 additions & 23 deletions src/transactions/test/InvokeHostFunctionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2082,16 +2082,18 @@ TEST_CASE("state archival", "[tx][soroban]")
cfg.mWriteFee1KBBucketListLow = 20'000;
cfg.mWriteFee1KBBucketListHigh = 1'000'000;
});
auto const& stateArchivalSettings =
test.getNetworkCfg().stateArchivalSettings();

auto getArchivalSettings = [&]() {
return test.getNetworkCfg().stateArchivalSettings();
};
auto isSuccess = [](auto resultCode) {
return resultCode == INVOKE_HOST_FUNCTION_SUCCESS;
};
ContractStorageTestClient client(test);
SECTION("contract instance and Wasm archival")
{
uint32_t originalExpectedLiveUntilLedger =
test.getLCLSeq() + stateArchivalSettings.minPersistentTTL - 1;
test.getLCLSeq() + getArchivalSettings().minPersistentTTL - 1;

for (uint32_t i =
test.getApp().getLedgerManager().getLastClosedLedgerNum();
Expand Down Expand Up @@ -2121,7 +2123,7 @@ TEST_CASE("state archival", "[tx][soroban]")
40000 /* two LE-writes
*/);
auto newExpectedLiveUntilLedger =
test.getLCLSeq() + stateArchivalSettings.minPersistentTTL - 1;
test.getLCLSeq() + getArchivalSettings().minPersistentTTL - 1;

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

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

// invocation should fail
REQUIRE(client.put("temp", ContractDataDurability::TEMPORARY, 0) ==
Expand Down Expand Up @@ -2194,7 +2196,7 @@ TEST_CASE("state archival", "[tx][soroban]")
REQUIRE(isSuccess(
client.put("temp", ContractDataDurability::TEMPORARY, 0)));
auto expectedTempLiveUntilLedger =
test.getLCLSeq() + stateArchivalSettings.minTemporaryTTL - 1;
test.getLCLSeq() + getArchivalSettings().minTemporaryTTL - 1;

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

// Recreated entry should be live
REQUIRE(client.getTTL("temp", ContractDataDurability::TEMPORARY) ==
test.getLCLSeq() + stateArchivalSettings.minTemporaryTTL -
test.getLCLSeq() + getArchivalSettings().minTemporaryTTL -
1);
REQUIRE(isSuccess(
client.get("temp", ContractDataDurability::TEMPORARY, 42)));
Expand Down Expand Up @@ -2329,7 +2331,7 @@ TEST_CASE("state archival", "[tx][soroban]")
makeSymbolSCVal("persistent2"),
ContractDataDurability::PERSISTENT);
uint32_t expectedLiveUntilLedger2 =
test.getLCLSeq() + stateArchivalSettings.minPersistentTTL - 1;
test.getLCLSeq() + getArchivalSettings().minPersistentTTL - 1;
REQUIRE(client.getTTL("persistent2",
ContractDataDurability::PERSISTENT) ==
expectedLiveUntilLedger2);
Expand All @@ -2347,7 +2349,7 @@ TEST_CASE("state archival", "[tx][soroban]")
// Check value and TTL of restored entry
REQUIRE(client.getTTL("persistent",
ContractDataDurability::PERSISTENT) ==
test.getLCLSeq() + stateArchivalSettings.minPersistentTTL -
test.getLCLSeq() + getArchivalSettings().minPersistentTTL -
1);
REQUIRE(isSuccess(client.get(
"persistent", ContractDataDurability::PERSISTENT, 10)));
Expand Down Expand Up @@ -2432,12 +2434,12 @@ TEST_CASE("state archival", "[tx][soroban]")
REQUIRE(isSuccess(
client.put("key", ContractDataDurability::PERSISTENT, 0)));
uint32_t initialLiveUntilLedger =
test.getLCLSeq() + stateArchivalSettings.minPersistentTTL - 1;
test.getLCLSeq() + getArchivalSettings().minPersistentTTL - 1;
REQUIRE(client.getTTL("key", ContractDataDurability::PERSISTENT) ==
initialLiveUntilLedger);
// Try extending entry, but set the threshold 1 ledger below the
// current TTL.
uint32_t currentTTL = stateArchivalSettings.minPersistentTTL - 2;
uint32_t currentTTL = getArchivalSettings().minPersistentTTL - 2;
REQUIRE(
isSuccess(client.extend("key", ContractDataDurability::PERSISTENT,
currentTTL - 1, 50'000)));
Expand Down Expand Up @@ -2467,9 +2469,9 @@ TEST_CASE("state archival", "[tx][soroban]")
SECTION("extension op")
{
// Max TTL includes current ledger, so subtract 1
test.invokeExtendOp({lk}, stateArchivalSettings.maxEntryTTL - 1);
test.invokeExtendOp({lk}, getArchivalSettings().maxEntryTTL - 1);
REQUIRE(test.getTTL(lk) ==
test.getLCLSeq() + stateArchivalSettings.maxEntryTTL - 1);
test.getLCLSeq() + getArchivalSettings().maxEntryTTL - 1);
}

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

REQUIRE(isSuccess(client.extend(
"key", ContractDataDurability::PERSISTENT,
stateArchivalSettings.maxEntryTTL + 10,
stateArchivalSettings.maxEntryTTL + 10,
getArchivalSettings().maxEntryTTL + 10,
getArchivalSettings().maxEntryTTL + 10,
client.readKeySpec("key", ContractDataDurability::PERSISTENT)
.setRefundableResourceFee(80'000))));

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

SECTION("extend host function temp")
Expand All @@ -2498,19 +2500,19 @@ TEST_CASE("state archival", "[tx][soroban]")
makeSymbolSCVal("key"), ContractDataDurability::TEMPORARY);
uint32_t ledgerSeq = test.getLCLSeq();
REQUIRE(client.extend("key", ContractDataDurability::TEMPORARY,
stateArchivalSettings.maxEntryTTL,
stateArchivalSettings.maxEntryTTL) ==
getArchivalSettings().maxEntryTTL,
getArchivalSettings().maxEntryTTL) ==
INVOKE_HOST_FUNCTION_TRAPPED);
REQUIRE(test.getTTL(lkTemp) ==
ledgerSeq + stateArchivalSettings.minTemporaryTTL - 1);
ledgerSeq + getArchivalSettings().minTemporaryTTL - 1);

// Max TTL includes current ledger, so subtract 1
REQUIRE(isSuccess(
client.extend("key", ContractDataDurability::TEMPORARY,
stateArchivalSettings.maxEntryTTL - 1,
stateArchivalSettings.maxEntryTTL - 1)));
getArchivalSettings().maxEntryTTL - 1,
getArchivalSettings().maxEntryTTL - 1)));
REQUIRE(test.getTTL(lkTemp) ==
test.getLCLSeq() + stateArchivalSettings.maxEntryTTL - 1);
test.getLCLSeq() + getArchivalSettings().maxEntryTTL - 1);
}
}
}
Expand Down

0 comments on commit 7d0b178

Please sign in to comment.