From 70cce640aa5930234b88f28a80ba8b07aca23167 Mon Sep 17 00:00:00 2001 From: Davide Grilli Date: Sat, 13 Jun 2026 20:34:19 +0200 Subject: [PATCH] test(storage): add WalletLock unit tests Covers acquire/release, double-acquire returning null, and re-acquire after dispose. --- .../Storage/StorageTests.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/PalladiumWallet.Tests/Storage/StorageTests.cs b/tests/PalladiumWallet.Tests/Storage/StorageTests.cs index 1172f87..98ab989 100644 --- a/tests/PalladiumWallet.Tests/Storage/StorageTests.cs +++ b/tests/PalladiumWallet.Tests/Storage/StorageTests.cs @@ -92,4 +92,59 @@ public class StorageTests doc.Mnemonic = null; Assert.True(WalletDocument.FromJson(doc.ToJson()).IsWatchOnly); } + + [Fact] + public void WalletLock_acquisisce_e_rilascia() + { + var path = Path.Combine(Path.GetTempPath(), $"plm-lock-{Guid.NewGuid()}.wallet.json"); + try + { + using var lock1 = WalletLock.TryAcquire(path); + Assert.NotNull(lock1); + } + finally + { + File.Delete(path); + File.Delete(path + ".lock"); + } + } + + [Fact] + public void WalletLock_seconda_istanza_restituisce_null() + { + var path = Path.Combine(Path.GetTempPath(), $"plm-lock-{Guid.NewGuid()}.wallet.json"); + try + { + using var lock1 = WalletLock.TryAcquire(path); + Assert.NotNull(lock1); + + var lock2 = WalletLock.TryAcquire(path); + Assert.Null(lock2); + } + finally + { + File.Delete(path); + File.Delete(path + ".lock"); + } + } + + [Fact] + public void WalletLock_riacquisibile_dopo_rilascio() + { + var path = Path.Combine(Path.GetTempPath(), $"plm-lock-{Guid.NewGuid()}.wallet.json"); + try + { + var lock1 = WalletLock.TryAcquire(path); + Assert.NotNull(lock1); + lock1!.Dispose(); + + using var lock2 = WalletLock.TryAcquire(path); + Assert.NotNull(lock2); + } + finally + { + File.Delete(path); + File.Delete(path + ".lock"); + } + } }