2
0
mirror of synced 2025-01-29 01:36:16 +00:00

74 lines
2.5 KiB
C#
Raw Normal View History

2024-11-21 15:10:53 +01:00
using CodexContractsPlugin;
2024-11-21 15:30:56 +01:00
using CodexPlugin;
2024-11-22 08:57:50 +01:00
using GethPlugin;
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
{
2024-11-21 15:10:53 +01:00
[TestFixture]
2024-11-21 15:30:56 +01:00
public class ContractSuccessfulTest : MarketplaceAutoBootstrapDistTest
2024-11-21 10:03:09 +01:00
{
2024-11-21 15:30:56 +01:00
private const int FilesizeMb = 10;
2024-11-22 16:09:18 +01:00
protected override int NumberOfHosts => 4;
protected override int NumberOfClients => 1;
protected override ByteSize HostAvailabilitySize => (5 * FilesizeMb).MB();
2024-11-25 15:45:09 +01:00
protected override TimeSpan HostAvailabilityMaxDuration => Get8TimesConfiguredPeriodDuration();
2024-11-25 16:10:17 +01:00
private readonly TestToken pricePerSlotPerSecond = 10.TstWei();
2024-11-22 16:09:18 +01:00
2024-11-21 15:10:53 +01:00
[Test]
public void ContractSuccessful()
{
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
2024-11-25 15:45:09 +01:00
request.WaitForStorageContractFinished(GetContracts());
2024-11-22 08:57:50 +01:00
2024-11-25 16:10:17 +01:00
AssertClientHasPaidForContract(pricePerSlotPerSecond, client, request, hosts);
AssertHostsWerePaidForContract(pricePerSlotPerSecond, 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)NumberOfHosts,
NodeFailureTolerance = (uint)(NumberOfHosts / 2),
2024-11-25 16:10:17 +01:00
PricePerSlotPerSecond = pricePerSlotPerSecond,
2024-11-22 08:57:50 +01:00
ProofProbability = 20,
RequiredCollateral = 1.Tst()
});
}
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()
{
2024-11-25 15:45:09 +01:00
return Get8TimesConfiguredPeriodDuration() / 2;
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-11-21 15:30:56 +01:00
var config = GetContracts().Deployment.Config;
2024-11-22 16:09:18 +01:00
return TimeSpan.FromSeconds(((double)config.Proofs.Period) * 8.0);
2024-11-21 15:10:53 +01:00
}
2024-11-21 10:03:09 +01:00
}
}