transaction<T> method
Executes a transaction scope.
Manages _inTransaction state and logs lifecycle events (BEGIN, COMMIT, ROLLBACK)
to history to verify transaction boundaries.
Implementation
@override
Future<T> transaction<T>(
Future<T> Function(TransactionContext txn) callback,
) async {
_inTransaction = true;
transactionHistory.clear();
history.add('BEGIN TRANSACTION');
try {
final context = MockTransactionContext(this);
final result = await callback(context);
history.add('COMMIT');
_inTransaction = false;
return result;
} catch (e) {
history.add('ROLLBACK');
_inTransaction = false;
rethrow;
}
}