test: wait for verified history rows before asserting on them
The funded-wallet ViewModel tests only waited for the history row to appear, but the Merkle proof can complete after sync reports idle. On the slower Windows runner the assertions on Verified and the spend tests (which need verified UTXOs) raced it and failed. Wait for the row to be verified.
This commit is contained in:
1 parent
9010ebce59
commit
ed8de06609
5 files changed
+65
-10
No files matched your search
@@ -388,7 +388,8 @@ public sealed class MainWindowViewModelTests : VmTestBase
|
||||
var vm = new MainWindowViewModel();
|
||||
|
||||
RestoreFlow(vm, Mnemonic, null, "funded");
|
||||
await Eventually(() => vm.IsConnected && !vm.IsSyncing && vm.History.Count == 1);
|
||||
await Eventually(() => vm.IsConnected && !vm.IsSyncing && vm.History.Count == 1 && vm.History[0].Verified,
|
||||
describe: () => $"connected={vm.IsConnected} syncing={vm.IsSyncing} rows={vm.History.Count} verified={vm.History.FirstOrDefault()?.Verified} status='{vm.StatusMessage}'");
|
||||
|
||||
Assert.True(vm.History[0].Verified);
|
||||
Assert.Contains("0.025", vm.BalanceText);
|
||||
@@ -412,7 +413,8 @@ public sealed class MainWindowViewModelTests : VmTestBase
|
||||
};
|
||||
var vm = new MainWindowViewModel();
|
||||
RestoreFlow(vm, Mnemonic, null, "unanch");
|
||||
await Eventually(() => vm.IsConnected && !vm.IsSyncing && vm.History.Count == 1);
|
||||
await Eventually(() => vm.IsConnected && !vm.IsSyncing && vm.History.Count == 1 && vm.History[0].Verified,
|
||||
describe: () => $"connected={vm.IsConnected} syncing={vm.IsSyncing} rows={vm.History.Count} verified={vm.History.FirstOrDefault()?.Verified} status='{vm.StatusMessage}'");
|
||||
|
||||
Assert.True(vm.History[0].Verified); // the Merkle proof checks out
|
||||
Assert.True(vm.History[0].Unanchored); // but height 100 is above the checkpoint at 50
|
||||
@@ -494,7 +496,8 @@ public sealed class MainWindowViewModelTests : VmTestBase
|
||||
_server.Handle("blockchain.estimatefee", _ => 0.00002m);
|
||||
var vm = new MainWindowViewModel();
|
||||
RestoreFlow(vm, Mnemonic, null, "fees4");
|
||||
await Eventually(() => vm.HasFeeEstimates && !vm.IsSyncing && vm.History.Count == 1);
|
||||
await Eventually(() => vm.HasFeeEstimates && !vm.IsSyncing && vm.History.Count == 1 && vm.History[0].Verified,
|
||||
describe: () => $"connected={vm.IsConnected} syncing={vm.IsSyncing} rows={vm.History.Count} verified={vm.History.FirstOrDefault()?.Verified} status='{vm.StatusMessage}'");
|
||||
|
||||
vm.SendTo = account.GetReceiveAddress(7).ToString();
|
||||
vm.SendAmount = "0.1";
|
||||
@@ -522,7 +525,8 @@ public sealed class MainWindowViewModelTests : VmTestBase
|
||||
WireFundedChain(account.GetReceiveAddress(0), 50_000_000);
|
||||
var vm = new MainWindowViewModel();
|
||||
RestoreFlow(vm, Mnemonic, null, "sender");
|
||||
await Eventually(() => !vm.IsSyncing && vm.History.Count == 1);
|
||||
await Eventually(() => !vm.IsSyncing && vm.History.Count == 1 && vm.History[0].Verified,
|
||||
describe: () => $"connected={vm.IsConnected} syncing={vm.IsSyncing} rows={vm.History.Count} verified={vm.History.FirstOrDefault()?.Verified} status='{vm.StatusMessage}'");
|
||||
// Coins need MinConfirmations (tip 200, height 100 → 101 confirmations): spendable.
|
||||
|
||||
vm.SendTo = account.GetReceiveAddress(7).ToString();
|
||||
|
||||
@@ -54,16 +54,22 @@ public abstract class VmTestBase : IDisposable
|
||||
try { Directory.Delete(_root, recursive: true); } catch { /* best effort */ }
|
||||
}
|
||||
|
||||
protected static async Task Eventually(Func<bool> condition, int timeoutMs = 10_000)
|
||||
protected async Task Eventually(Func<bool> condition, int timeoutMs = 10_000, Func<string>? describe = null)
|
||||
{
|
||||
for (var waited = 0; !condition(); waited += 20)
|
||||
{
|
||||
Assert.True(waited < timeoutMs, "condition not reached in time");
|
||||
Assert.True(waited < timeoutMs, "condition not reached in time" + (describe is null ? "" : $": {describe()}") + $" | calls: {Calls()}");
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
await Task.Delay(20);
|
||||
}
|
||||
}
|
||||
|
||||
private string Calls() => string.Join(", ", new[]
|
||||
{
|
||||
"blockchain.headers.subscribe", "blockchain.scripthash.get_history", "blockchain.transaction.get",
|
||||
"blockchain.transaction.get_merkle", "blockchain.block.header", "blockchain.block.headers",
|
||||
}.Select(m => $"{m.Split('.')[^1]}={_server.CallCount(m)}"));
|
||||
|
||||
protected static void RestoreFlow(MainWindowViewModel vm, string mnemonic, string? password, string? name = null)
|
||||
{
|
||||
vm.WizardStartRestoreCommand.Execute(null);
|
||||
|
||||
Reference in new issue
Block a user