2025-02-21 13:58:27 +01:00
|
|
|
using CodexClient;
|
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-04-24 12:53:08 +02:00
|
|
|
[TestFixture(6, 3, 1)]
|
|
|
|
|
[TestFixture(6, 4, 2)]
|
2025-04-24 15:34:31 +02:00
|
|
|
[TestFixture(8, 5, 1)]
|
|
|
|
|
[TestFixture(8, 6, 1)]
|
2025-04-24 12:53:08 +02:00
|
|
|
[TestFixture(8, 6, 3)]
|
2024-11-21 15:30:56 +01:00
|
|
|
public class ContractSuccessfulTest : MarketplaceAutoBootstrapDistTest
|
2024-11-21 10:03:09 +01:00
|
|
|
{
|
2025-04-24 12:53:08 +02:00
|
|
|
public ContractSuccessfulTest(int hosts, int slots, int tolerance)
|
|
|
|
|
{
|
|
|
|
|
this.hosts = hosts;
|
|
|
|
|
this.slots = slots;
|
|
|
|
|
this.tolerance = tolerance;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-21 15:30:56 +01:00
|
|
|
private const int FilesizeMb = 10;
|
2025-04-24 12:53:08 +02:00
|
|
|
private readonly TestToken pricePerBytePerSecond = 10.TstWei();
|
|
|
|
|
private readonly int hosts;
|
|
|
|
|
private readonly int slots;
|
|
|
|
|
private readonly int tolerance;
|
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;
|
|
|
|
|
protected override ByteSize HostAvailabilitySize => (5 * FilesizeMb).MB();
|
2025-04-24 19:33:34 +02:00
|
|
|
protected override TimeSpan HostAvailabilityMaxDuration => Get8TimesConfiguredPeriodDuration() * 12;
|
2024-11-22 16:09:18 +01:00
|
|
|
|
2024-11-21 15:10:53 +01:00
|
|
|
[Test]
|
2024-12-18 09:28:10 +01:00
|
|
|
public void ContractSuccessful()
|
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();
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2024-11-22 16:09:18 +01:00
|
|
|
request.WaitForStorageContractStarted();
|
2024-11-25 15:45:09 +01:00
|
|
|
AssertContractSlotsAreFilledByHosts(request, hosts);
|
2024-11-22 08:57:50 +01:00
|
|
|
|
2025-04-24 19:33:34 +02:00
|
|
|
Thread.Sleep(TimeSpan.FromSeconds(12.0));
|
|
|
|
|
return;
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IStoragePurchaseContract CreateStorageRequest(ICodexNode client)
|
|
|
|
|
{
|
|
|
|
|
var cid = client.UploadFile(GenerateTestFile(FilesizeMb.MB()));
|
|
|
|
|
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-04-24 12:53:08 +02:00
|
|
|
MinRequiredNumberOfNodes = (uint)slots,
|
|
|
|
|
NodeFailureTolerance = (uint)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-04-24 19:33:34 +02:00
|
|
|
return Get8TimesConfiguredPeriodDuration() * 4;
|
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
|
|
|
}
|
|
|
|
|
}
|