85 lines
2.9 KiB
C#
Raw Normal View History

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
{
[TestFixture(5, 3, 1)]
[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)
{
this.hosts = hosts;
purchaseParams = new PurchaseParams(slots, tolerance, uploadFilesize: 3.MB());
}
2024-11-21 15:30:56 +01:00
2025-01-25 14:07:15 +01:00
private readonly TestToken pricePerBytePerSecond = 10.TstWei();
private readonly int hosts;
private readonly PurchaseParams purchaseParams;
2024-11-21 15:30:56 +01:00
protected override int NumberOfHosts => hosts;
2024-11-22 16:09:18 +01:00
protected override int NumberOfClients => 1;
protected override ByteSize HostAvailabilitySize => purchaseParams.SlotSize.Multiply(5.1);
protected override TimeSpan HostAvailabilityMaxDuration => GetContractDuration() * 2;
2024-11-22 16:09:18 +01:00
2024-11-21 15:10:53 +01:00
[Test]
[Combinatorial]
public void Finish(
2025-06-06 09:49:55 +02:00
[Rerun] int rerun
)
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
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)
{
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(),
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,
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
{
return GetPeriodDuration() * 8.0;
2024-11-21 15:10:53 +01:00
}
2024-11-21 10:03:09 +01:00
}
}