75 lines
2.6 KiB
C#
Raw 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;
protected override int NumberOfClients => 1;
protected override ByteSize HostAvailabilitySize => 1.GB();
protected override TimeSpan HostAvailabilityMaxDuration => TimeSpan.FromDays(1.0);
2025-01-25 14:07:15 +01:00
private readonly TestToken pricePerBytePerSecond = 10.TstWei();
2024-11-26 14:52:24 +01:00
[Test]
2025-05-30 08:59:43 +02:00
public void Fail()
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();
request.WaitForContractFailed();
}
private void WaitForSlotFreedEvents()
{
Log(nameof(WaitForSlotFreedEvents));
var start = DateTime.UtcNow;
var timeout = CalculateContractFailTimespan();
2024-11-26 14:52:24 +01:00
while (DateTime.UtcNow < start + timeout)
{
var events = GetContracts().GetEvents(GetTestRunTimeRange());
var slotFreed = events.GetSlotFreedEvents();
if (slotFreed.Length == NumberOfHosts)
{
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(5.MB()));
return client.Marketplace.RequestStorage(new StoragePurchaseRequest(cid)
{
Duration = TimeSpan.FromHours(1.0),
Expiry = TimeSpan.FromHours(0.2),
MinRequiredNumberOfNodes = (uint)NumberOfHosts,
NodeFailureTolerance = (uint)(NumberOfHosts / 2),
2025-01-25 14:07:15 +01:00
PricePerBytePerSecond = pricePerBytePerSecond,
ProofProbability = 1, // Require a proof every period
2025-01-25 14:07:15 +01:00
CollateralPerByte = 1.Tst()
});
2024-11-26 14:52:24 +01:00
}
2024-11-21 10:03:09 +01:00
}
}