From 18c96a5832ce5b92b87b0f58f2bb5a8bb97074da Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Fri, 5 Jul 2024 14:37:29 -0700 Subject: [PATCH] Add test --- .../ExtendFootprintTTLOpFrame.cpp | 1 - .../test/InvokeHostFunctionTests.cpp | 43 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/transactions/ExtendFootprintTTLOpFrame.cpp b/src/transactions/ExtendFootprintTTLOpFrame.cpp index d544778327..517b629c68 100644 --- a/src/transactions/ExtendFootprintTTLOpFrame.cpp +++ b/src/transactions/ExtendFootprintTTLOpFrame.cpp @@ -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)) { diff --git a/src/transactions/test/InvokeHostFunctionTests.cpp b/src/transactions/test/InvokeHostFunctionTests.cpp index 2579f8c55e..97700c8a90 100644 --- a/src/transactions/test/InvokeHostFunctionTests.cpp +++ b/src/transactions/test/InvokeHostFunctionTests.cpp @@ -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 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(&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]")