88 lines
2.9 KiB
C#
Raw Normal View History

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
{
[TestFixture(6, 3, 1)]
[TestFixture(6, 4, 2)]
[TestFixture(8, 5, 1)]
[TestFixture(8, 6, 1)]
[TestFixture(8, 6, 3)]
2024-11-21 15:30:56 +01:00
public class ContractSuccessfulTest : MarketplaceAutoBootstrapDistTest
2024-11-21 10:03:09 +01: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;
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
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]
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(),
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,
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
{
return GetPeriodDuration() * 8.0;
2024-11-21 15:10:53 +01:00
}
2024-11-21 10:03:09 +01:00
}
}