2025-02-21 13:58:27 +01:00
|
|
|
using CodexClient;
|
2025-05-30 08:59:43 +02:00
|
|
|
using CodexReleaseTests.Utils;
|
2024-11-21 15:10:53 +01:00
|
|
|
using NUnit.Framework;
|
2024-11-21 15:30:56 +01:00
|
|
|
using Utils;
|
2024-11-21 10:03:09 +01:00
|
|
|
|
|
|
|
|
namespace CodexReleaseTests.MarketTests
|
|
|
|
|
{
|
2025-05-29 10:59:10 +02:00
|
|
|
[TestFixture(5, 3, 1)]
|
2025-06-05 17:14:27 +02:00
|
|
|
[TestFixture(10, 8, 4)]
|
2025-05-30 08:59:43 +02:00
|
|
|
public class FinishTest : MarketplaceAutoBootstrapDistTest
|
2024-11-21 10:03:09 +01:00
|
|
|
{
|
2025-05-30 08:59:43 +02:00
|
|
|
public FinishTest(int hosts, int slots, int tolerance)
|
2025-04-24 12:53:08 +02:00
|
|
|
{
|
|
|
|
|
this.hosts = hosts;
|
2025-07-09 19:38:53 +02:00
|
|
|
purchaseParams = new PurchaseParams(slots, tolerance, uploadFilesize: 3.MB());
|
2025-04-24 12:53:08 +02:00
|
|
|
}
|
2024-11-21 15:30:56 +01:00
|
|
|
|
2025-01-25 14:07:15 +01:00
|
|
|
private readonly TestToken pricePerBytePerSecond = 10.TstWei();
|
2025-04-24 12:53:08 +02:00
|
|
|
private readonly int hosts;
|
2025-06-02 13:32:03 +02:00
|
|
|
private readonly PurchaseParams purchaseParams;
|
2024-11-21 15:30:56 +01:00
|
|
|
|
2025-04-24 12:53:08 +02:00
|
|
|
protected override int NumberOfHosts => hosts;
|
2024-11-22 16:09:18 +01:00
|
|
|
protected override int NumberOfClients => 1;
|
2025-06-02 13:32:03 +02:00
|
|
|
protected override ByteSize HostAvailabilitySize => purchaseParams.SlotSize.Multiply(5.1);
|
2025-06-06 10:47:54 +02:00
|
|
|
protected override TimeSpan HostAvailabilityMaxDuration => GetContractDuration() * 2;
|
2024-11-22 16:09:18 +01:00
|
|
|
|
2024-11-21 15:10:53 +01:00
|
|
|
[Test]
|
2025-05-30 09:57:21 +02:00
|
|
|
[Combinatorial]
|
|
|
|
|
public void Finish(
|
2025-06-06 09:49:55 +02:00
|
|
|
[Rerun] int rerun
|
2025-05-30 09:57:21 +02:00
|
|
|
)
|
2024-11-21 15:10:53 +01:00
|
|
|
{
|
2024-11-21 15:30:56 +01:00
|
|
|
var hosts = StartHosts();
|
2024-11-22 16:09:18 +01:00
|
|
|
var client = StartClients().Single();
|
2025-03-11 15:00:27 +01:00
|
|
|
AssertHostAvailabilitiesAreEmpty(hosts);
|
2024-11-22 16:09:18 +01:00
|
|
|
|
|
|
|
|
var request = CreateStorageRequest(client);
|
2024-11-21 15:30:56 +01:00
|
|
|
|
2024-11-22 16:09:18 +01:00
|
|
|
request.WaitForStorageContractSubmitted();
|
|
|
|
|
AssertContractIsOnChain(request);
|
2024-11-22 08:57:50 +01:00
|
|
|
|
2025-05-06 20:33:37 +02:00
|
|
|
WaitForContractStarted(request);
|
2024-11-25 15:45:09 +01:00
|
|
|
AssertContractSlotsAreFilledByHosts(request, hosts);
|
2024-11-22 08:57:50 +01:00
|
|
|
|
2025-01-16 15:13:16 +01:00
|
|
|
request.WaitForStorageContractFinished();
|
2024-11-22 08:57:50 +01:00
|
|
|
|
2025-01-25 14:07:15 +01:00
|
|
|
AssertClientHasPaidForContract(pricePerBytePerSecond, client, request, hosts);
|
|
|
|
|
AssertHostsWerePaidForContract(pricePerBytePerSecond, request, hosts);
|
2024-11-22 08:57:50 +01:00
|
|
|
AssertHostsCollateralsAreUnchanged(hosts);
|
2025-03-11 15:00:27 +01:00
|
|
|
AssertHostAvailabilitiesAreEmpty(hosts);
|
2024-11-22 08:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IStoragePurchaseContract CreateStorageRequest(ICodexNode client)
|
|
|
|
|
{
|
2025-06-02 13:32:03 +02:00
|
|
|
var cid = client.UploadFile(GenerateTestFile(purchaseParams.UploadFilesize));
|
2024-11-22 08:57:50 +01:00
|
|
|
var config = GetContracts().Deployment.Config;
|
|
|
|
|
return client.Marketplace.RequestStorage(new StoragePurchaseRequest(cid)
|
|
|
|
|
{
|
|
|
|
|
Duration = GetContractDuration(),
|
2024-11-22 16:09:18 +01:00
|
|
|
Expiry = GetContractExpiry(),
|
2025-06-02 13:32:03 +02:00
|
|
|
MinRequiredNumberOfNodes = (uint)purchaseParams.Nodes,
|
|
|
|
|
NodeFailureTolerance = (uint)purchaseParams.Tolerance,
|
2025-01-25 14:07:15 +01:00
|
|
|
PricePerBytePerSecond = pricePerBytePerSecond,
|
2024-11-22 08:57:50 +01:00
|
|
|
ProofProbability = 20,
|
2025-02-04 10:13:59 +01:00
|
|
|
CollateralPerByte = 100.TstWei()
|
2024-11-22 08:57:50 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-22 16:09:18 +01:00
|
|
|
private TimeSpan GetContractExpiry()
|
|
|
|
|
{
|
|
|
|
|
return GetContractDuration() / 2;
|
|
|
|
|
}
|
2024-11-21 15:10:53 +01:00
|
|
|
|
2024-11-22 16:09:18 +01:00
|
|
|
private TimeSpan GetContractDuration()
|
|
|
|
|
{
|
2025-06-02 18:51:36 +02:00
|
|
|
return Get8TimesConfiguredPeriodDuration();
|
2024-11-22 16:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-25 15:45:09 +01:00
|
|
|
private TimeSpan Get8TimesConfiguredPeriodDuration()
|
2024-11-22 16:09:18 +01:00
|
|
|
{
|
2024-12-17 15:54:52 +01:00
|
|
|
return GetPeriodDuration() * 8.0;
|
2024-11-21 15:10:53 +01:00
|
|
|
}
|
2024-11-21 10:03:09 +01:00
|
|
|
}
|
|
|
|
|
}
|