85 lines
2.9 KiB
C#
Raw Permalink Normal View History

2025-01-16 15:13:16 +01:00
using CodexClient;
2025-05-30 08:59:43 +02:00
using CodexReleaseTests.Utils;
2024-11-26 14:52:24 +01:00
using NUnit.Framework;
using Utils;
2024-11-21 10:03:09 +01:00
namespace CodexReleaseTests.MarketTests
{
2025-05-30 08:59:43 +02:00
public class FailTest : MarketplaceAutoBootstrapDistTest
2024-11-21 10:03:09 +01:00
{
protected override int NumberOfHosts => 4;
2025-06-04 15:51:01 +02:00
private readonly int SlotTolerance;
protected override int NumberOfClients => 1;
protected override ByteSize HostAvailabilitySize => 1.GB();
protected override TimeSpan HostAvailabilityMaxDuration => TimeSpan.FromDays(1.0);
2025-06-04 15:51:01 +02:00
public FailTest()
{
SlotTolerance = NumberOfHosts / 2;
}
2024-11-26 14:52:24 +01:00
[Test]
[Combinatorial]
public void Fail(
2025-06-06 09:49:55 +02:00
[Rerun] int rerun
)
2024-11-26 14:52:24 +01:00
{
var hosts = StartHosts();
var client = StartClients().Single();
StartValidator();
var request = CreateStorageRequest(client);
request.WaitForStorageContractSubmitted();
AssertContractIsOnChain(request);
request.WaitForStorageContractStarted();
AssertContractSlotsAreFilledByHosts(request, hosts);
hosts.Stop(waitTillStopped: true);
WaitForSlotFreedEvents();
var config = GetContracts().Deployment.Config;
request.WaitForContractFailed(config);
}
private void WaitForSlotFreedEvents()
{
var start = DateTime.UtcNow;
var timeout = CalculateContractFailTimespan();
2024-11-26 14:52:24 +01:00
Log($"{nameof(WaitForSlotFreedEvents)} timeout: {Time.FormatDuration(timeout)}");
while (DateTime.UtcNow < start + timeout)
{
var events = GetContracts().GetEvents(GetTestRunTimeRange());
var slotFreed = events.GetSlotFreedEvents();
2025-06-04 15:51:01 +02:00
Log($"SlotFreed events: {slotFreed.Length} - Expected: {SlotTolerance}");
if (slotFreed.Length > SlotTolerance)
{
Log($"{nameof(WaitForSlotFreedEvents)} took {Time.FormatDuration(DateTime.UtcNow - start)}");
return;
}
GetContracts().WaitUntilNextPeriod();
}
Assert.Fail($"{nameof(WaitForSlotFreedEvents)} failed after {Time.FormatDuration(timeout)}");
}
private IStoragePurchaseContract CreateStorageRequest(ICodexNode client)
{
var cid = client.UploadFile(GenerateTestFile(3.MB()));
return client.Marketplace.RequestStorage(new StoragePurchaseRequest(cid)
{
Duration = HostAvailabilityMaxDuration / 2,
Expiry = TimeSpan.FromMinutes(5.0),
MinRequiredNumberOfNodes = (uint)NumberOfHosts,
2025-06-04 15:51:01 +02:00
NodeFailureTolerance = (uint)SlotTolerance,
PricePerBytePerSecond = 100.TstWei(),
ProofProbability = 1, // Require a proof every period
CollateralPerByte = 1.TstWei()
});
2024-11-26 14:52:24 +01:00
}
2024-11-21 10:03:09 +01:00
}
}