chore[tests]: improve env.meta usage (#5457)

This commit changes the ledger close in env.meta to be conditional on if it hasn't already been closed (i.e. the current ledger doesn't have any transactions in it). This change will make it a bit easier to use, as it will still work if you close the ledger outside of this usage. Previously, if you accidentally closed the ledger outside of the meta function, it would segfault and it was incredibly difficult to debug.
This commit is contained in:
Mayukha Vadari
2025-05-29 12:28:09 -04:00
committed by GitHub
parent 9e1fe9a85e
commit 05105743e9
2 changed files with 16 additions and 8 deletions

View File

@@ -589,13 +589,16 @@ public:
}
/** Return metadata for the last JTx.
Effects:
The open ledger is closed as if by a call
to close(). The metadata for the last
transaction ID, if any, is returned.
*/
*
* NOTE: this has a side effect of closing the open ledger.
* The ledger will only be closed if it includes transactions.
*
* Effects:
*
* The open ledger is closed as if by a call
* to close(). The metadata for the last
* transaction ID, if any, is returned.
*/
std::shared_ptr<STObject const>
meta();

View File

@@ -446,7 +446,12 @@ Env::postconditions(
std::shared_ptr<STObject const>
Env::meta()
{
close();
if (current()->txCount() != 0)
{
// close the ledger if it has not already been closed
// (metadata is not finalized until the ledger is closed)
close();
}
auto const item = closed()->txRead(txid_);
return item.second;
}