From 05105743e94f90100a5edae14d46d8b7e4af8b59 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Thu, 29 May 2025 12:28:09 -0400 Subject: [PATCH] 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. --- src/test/jtx/Env.h | 17 ++++++++++------- src/test/jtx/impl/Env.cpp | 7 ++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index de6b83362d..2b5397b903 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -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 meta(); diff --git a/src/test/jtx/impl/Env.cpp b/src/test/jtx/impl/Env.cpp index ac00d3eed1..e45042e310 100644 --- a/src/test/jtx/impl/Env.cpp +++ b/src/test/jtx/impl/Env.cpp @@ -446,7 +446,12 @@ Env::postconditions( std::shared_ptr 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; }