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;
|
2024-12-17 15:54:52 +01:00
|
|
|
|
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
|
|
|
|
{
|
2024-12-17 15:54:52 +01:00
|
|
|
|
protected override int NumberOfHosts => 4;
|
2025-06-04 15:51:01 +02:00
|
|
|
|
private readonly int SlotTolerance;
|
2024-12-17 15:54:52 +01:00
|
|
|
|
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]
|
2025-05-30 09:57:21 +02:00
|
|
|
|
[Combinatorial]
|
|
|
|
|
|
public void Fail(
|
2025-06-06 09:49:55 +02:00
|
|
|
|
[Rerun] int rerun
|
2025-05-30 09:57:21 +02:00
|
|
|
|
)
|
2024-11-26 14:52:24 +01:00
|
|
|
|
{
|
2024-12-17 15:54:52 +01:00
|
|
|
|
var hosts = StartHosts();
|
|
|
|
|
|
var client = StartClients().Single();
|
|
|
|
|
|
StartValidator();
|
|
|
|
|
|
|
|
|
|
|
|
var request = CreateStorageRequest(client);
|
|
|
|
|
|
|
|
|
|
|
|
request.WaitForStorageContractSubmitted();
|
|
|
|
|
|
AssertContractIsOnChain(request);
|
|
|
|
|
|
|
|
|
|
|
|
request.WaitForStorageContractStarted();
|
|
|
|
|
|
AssertContractSlotsAreFilledByHosts(request, hosts);
|
|
|
|
|
|
|
2025-01-15 16:05:57 +01:00
|
|
|
|
hosts.Stop(waitTillStopped: true);
|
2024-12-17 15:54:52 +01:00
|
|
|
|
|
|
|
|
|
|
WaitForSlotFreedEvents();
|
|
|
|
|
|
|
2025-06-04 12:31:19 +02:00
|
|
|
|
var config = GetContracts().Deployment.Config;
|
|
|
|
|
|
request.WaitForContractFailed(config);
|
2024-12-17 15:54:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void WaitForSlotFreedEvents()
|
|
|
|
|
|
{
|
|
|
|
|
|
var start = DateTime.UtcNow;
|
|
|
|
|
|
var timeout = CalculateContractFailTimespan();
|
2024-11-26 14:52:24 +01:00
|
|
|
|
|
2025-05-30 09:57:21 +02:00
|
|
|
|
Log($"{nameof(WaitForSlotFreedEvents)} timeout: {Time.FormatDuration(timeout)}");
|
|
|
|
|
|
|
2024-12-17 15:54:52 +01:00
|
|
|
|
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)
|
2024-12-17 15:54:52 +01:00
|
|
|
|
{
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
2025-07-09 19:38:53 +02:00
|
|
|
|
var cid = client.UploadFile(GenerateTestFile(3.MB()));
|
2024-12-17 15:54:52 +01:00
|
|
|
|
return client.Marketplace.RequestStorage(new StoragePurchaseRequest(cid)
|
|
|
|
|
|
{
|
2025-05-30 09:57:21 +02:00
|
|
|
|
Duration = HostAvailabilityMaxDuration / 2,
|
|
|
|
|
|
Expiry = TimeSpan.FromMinutes(5.0),
|
2024-12-17 15:54:52 +01:00
|
|
|
|
MinRequiredNumberOfNodes = (uint)NumberOfHosts,
|
2025-06-04 15:51:01 +02:00
|
|
|
|
NodeFailureTolerance = (uint)SlotTolerance,
|
2025-05-30 09:57:21 +02:00
|
|
|
|
PricePerBytePerSecond = 100.TstWei(),
|
2024-12-17 15:54:52 +01:00
|
|
|
|
ProofProbability = 1, // Require a proof every period
|
2025-05-30 09:57:21 +02:00
|
|
|
|
CollateralPerByte = 1.TstWei()
|
2024-12-17 15:54:52 +01:00
|
|
|
|
});
|
2024-11-26 14:52:24 +01:00
|
|
|
|
}
|
2024-11-21 10:03:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|