Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sisuresh committed Jul 5, 2024
1 parent 57d458d commit 18c96a5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/transactions/ExtendFootprintTTLOpFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ ExtendFootprintTTLOpFrame::doApplyParallel(
auto ttlKey = getTTLKey(lk);
auto ttlIter = entryMap.find(ttlKey);

// auto ttlConstLtxe = ltx.loadWithoutRecord(ttlKey);
if (ttlIter == entryMap.end() || !ttlIter->second.first ||
!isLive(*ttlIter->second.first, ledgerSeq))
{
Expand Down
43 changes: 42 additions & 1 deletion src/transactions/test/InvokeHostFunctionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4633,7 +4633,48 @@ TEST_CASE("parallel ttl", "[tx][soroban][parallelapply]")
REQUIRE(client.getTTL("key2", ContractDataDurability::PERSISTENT) ==
test.getLedgerSeq() + 5000);
}
// TODO: Add deletion test.
SECTION("Extend and delete")
{
auto i1 = client.getContract().prepareInvocation(
"del_persistent", {makeSymbolSCVal("key1")},
client.writeKeySpec("key1", ContractDataDurability::PERSISTENT));
auto tx1 = i1.withExactNonRefundableResourceFee().createTx(&a1);

auto i2 = client.getContract().prepareInvocation(
"extend_persistent",
{makeSymbolSCVal("key1"), makeU32SCVal(5000), makeU32SCVal(5000)},
client.readKeySpec("key1", ContractDataDurability::PERSISTENT));
auto tx2 = i2.withExactNonRefundableResourceFee().createTx(&a2);

LedgerTxn ltx(app.getLedgerTxnRoot());

TransactionMetaFrame tm(ltx.loadHeader().current().ledgerVersion);

std::vector<Stage> stages;
auto& stage = stages.emplace_back();

stage.resize(1);

// First thread
auto& thread1 = stage[0];
thread1.emplace_back(tx1, tx1->createSuccessResult(), tm);
thread1.emplace_back(tx2, tx2->createSuccessResult(), tm);

{
auto lmImpl = dynamic_cast<LedgerManagerImpl*>(&lm);
lmImpl->applySorobanStages(app, ltx, stages, Hash{});
ltx.commit();
}

REQUIRE(tx1->getResultCode() == txSUCCESS);
REQUIRE(tx2->getResultCode() == txFAILED);
// tx1 deleted key1, so tx2 will trap when it tries to extend key1
REQUIRE(tx2->getResult()
.result.results()[0]
.tr()
.invokeHostFunctionResult()
.code() == INVOKE_HOST_FUNCTION_TRAPPED);
}
}

TEST_CASE("parallel", "[tx][soroban][parallelapply]")
Expand Down

0 comments on commit 18c96a5

Please sign in to comment.