diff --git a/Framework/Core/DownloadedLog.cs b/Framework/Core/DownloadedLog.cs index 9242d9b..923bcbc 100644 --- a/Framework/Core/DownloadedLog.cs +++ b/Framework/Core/DownloadedLog.cs @@ -4,7 +4,7 @@ namespace Core { public interface IDownloadedLog { - bool DoesLogContain(string expectedString); + string[] GetLinesContaining(string expectedString); string[] FindLinesThatContain(params string[] tags); void DeleteFile(); } @@ -18,20 +18,23 @@ namespace Core this.logFile = logFile; } - public bool DoesLogContain(string expectedString) + public string[] GetLinesContaining(string expectedString) { using var file = File.OpenRead(logFile.FullFilename); using var streamReader = new StreamReader(file); + var lines = new List(); var line = streamReader.ReadLine(); while (line != null) { - if (line.Contains(expectedString)) return true; + if (line.Contains(expectedString)) + { + lines.Add(line); + } line = streamReader.ReadLine(); } - //Assert.Fail($"{owner} Unable to find string '{expectedString}' in CodexNode log file {logFile.FullFilename}"); - return false; + return lines.ToArray(); ; } public string[] FindLinesThatContain(params string[] tags) diff --git a/Tests/CodexTests/BasicTests/ExampleTests.cs b/Tests/CodexTests/BasicTests/ExampleTests.cs index 6b46917..c910b3d 100644 --- a/Tests/CodexTests/BasicTests/ExampleTests.cs +++ b/Tests/CodexTests/BasicTests/ExampleTests.cs @@ -108,7 +108,7 @@ namespace CodexTests.BasicTests var request = GetOnChainStorageRequest(contracts); AssertStorageRequest(request, purchase, contracts, buyer); - AssertSlotFilledEvents(contracts, request, seller); + AssertSlotFilledEvents(contracts, purchase, request, seller); AssertContractSlot(contracts, request, 0, seller); purchaseContract.WaitForStorageContractFinished(); @@ -137,17 +137,23 @@ namespace CodexTests.BasicTests Assert.That(discN, Is.LessThan(bootN)); } - private void AssertSlotFilledEvents(ICodexContracts contracts, Request request, ICodexNode seller) + private void AssertSlotFilledEvents(ICodexContracts contracts, StoragePurchase purchase, Request request, ICodexNode seller) { + // Expect 1 fulfilled event for the purchase. var requestFulfilledEvents = contracts.GetRequestFulfilledEvents(GetTestRunTimeRange()); Assert.That(requestFulfilledEvents.Length, Is.EqualTo(1)); CollectionAssert.AreEqual(request.RequestId, requestFulfilledEvents[0].RequestId); + + // Expect 1 filled-slot event for each slot in the purchase. var filledSlotEvents = contracts.GetSlotFilledEvents(GetTestRunTimeRange()); - Assert.That(filledSlotEvents.Length, Is.EqualTo(1)); - var filledSlotEvent = filledSlotEvents.Single(); - Assert.That(filledSlotEvent.SlotIndex.IsZero); - Assert.That(filledSlotEvent.RequestId.ToHex(), Is.EqualTo(request.RequestId.ToHex())); - Assert.That(filledSlotEvent.Host, Is.EqualTo(seller.EthAddress)); + Assert.That(filledSlotEvents.Length, Is.EqualTo(purchase.MinRequiredNumberOfNodes)); + for (var i = 0; i < purchase.MinRequiredNumberOfNodes; i++) + { + var filledSlotEvent = filledSlotEvents[i]; + Assert.That(filledSlotEvent.SlotIndex, Is.EqualTo(i)); + Assert.That(filledSlotEvent.RequestId.ToHex(), Is.EqualTo(request.RequestId.ToHex())); + Assert.That(filledSlotEvent.Host, Is.EqualTo(seller.EthAddress)); + } } private void AssertStorageRequest(Request request, StoragePurchase purchase, ICodexContracts contracts, ICodexNode buyer) diff --git a/Tests/CodexTests/CodexDistTest.cs b/Tests/CodexTests/CodexDistTest.cs index 2711a83..0578c27 100644 --- a/Tests/CodexTests/CodexDistTest.cs +++ b/Tests/CodexTests/CodexDistTest.cs @@ -92,6 +92,7 @@ namespace CodexTests public void CheckLogForErrors(ICodexNode node) { + Log($"Checking {node.GetName()} log for errors."); var log = Ci.DownloadLog(node); log.AssertLogDoesNotContain("Block validation failed"); diff --git a/Tests/DistTestCore/DownloadedLogExtensions.cs b/Tests/DistTestCore/DownloadedLogExtensions.cs index b000439..51ee96f 100644 --- a/Tests/DistTestCore/DownloadedLogExtensions.cs +++ b/Tests/DistTestCore/DownloadedLogExtensions.cs @@ -7,7 +7,7 @@ namespace DistTestCore { public static void AssertLogContains(this IDownloadedLog log, string expectedString) { - Assert.That(log.DoesLogContain(expectedString), $"Did not find '{expectedString}' in log."); + Assert.That(log.GetLinesContaining(expectedString).Any(), $"Did not find '{expectedString}' in log."); } public static void AssertLogDoesNotContain(this IDownloadedLog log, params string[] unexpectedStrings) @@ -15,9 +15,10 @@ namespace DistTestCore var errors = new List(); foreach (var str in unexpectedStrings) { - if (log.DoesLogContain(str)) + var lines = log.GetLinesContaining(str); + foreach (var line in lines) { - errors.Add($"Did find '{str}' in log."); + errors.Add($"Found '{str}' in line '{line}'."); } } CollectionAssert.IsEmpty(errors);