mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-01-05 23:13:08 +00:00
80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
using CodexContractsPlugin;
|
|
using CodexPlugin;
|
|
using GethPlugin;
|
|
using NUnit.Framework;
|
|
using Utils;
|
|
|
|
namespace CodexReleaseTests.MarketTests
|
|
{
|
|
[TestFixture]
|
|
public class ContractSuccessfulTest : MarketplaceAutoBootstrapDistTest
|
|
{
|
|
private const int FilesizeMb = 10;
|
|
|
|
protected override int NumberOfHosts => 6;
|
|
protected override int NumberOfClients => 1;
|
|
protected override ByteSize HostAvailabilitySize => (5 * FilesizeMb).MB();
|
|
protected override TimeSpan HostAvailabilityMaxDuration => Get8TimesConfiguredPeriodDuration();
|
|
private readonly TestToken pricePerSlotPerSecond = 10.TstWei();
|
|
|
|
[Test]
|
|
[Combinatorial]
|
|
public void ContractSuccessful(
|
|
[Values(0, 1, 2, 3)] int a,
|
|
[Values(0, 1, 2, 3)] int b
|
|
)
|
|
{
|
|
var hosts = StartHosts();
|
|
var client = StartClients().Single();
|
|
|
|
var request = CreateStorageRequest(client);
|
|
|
|
request.WaitForStorageContractSubmitted();
|
|
AssertContractIsOnChain(request);
|
|
|
|
request.WaitForStorageContractStarted();
|
|
AssertContractSlotsAreFilledByHosts(request, hosts);
|
|
|
|
request.WaitForStorageContractFinished(GetContracts());
|
|
|
|
AssertClientHasPaidForContract(pricePerSlotPerSecond, client, request, hosts);
|
|
AssertHostsWerePaidForContract(pricePerSlotPerSecond, request, hosts);
|
|
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(),
|
|
Expiry = GetContractExpiry(),
|
|
// TODO: this should work with NumberOfHosts, but
|
|
// an ongoing issue makes hosts sometimes not pick up slots.
|
|
// When it's resolved, we can reduce the number of hosts and slim down this test.
|
|
MinRequiredNumberOfNodes = 3,
|
|
NodeFailureTolerance = 1,
|
|
PricePerSlotPerSecond = pricePerSlotPerSecond,
|
|
ProofProbability = 20,
|
|
RequiredCollateral = 1.Tst()
|
|
});
|
|
}
|
|
|
|
private TimeSpan GetContractExpiry()
|
|
{
|
|
return GetContractDuration() / 2;
|
|
}
|
|
|
|
private TimeSpan GetContractDuration()
|
|
{
|
|
return Get8TimesConfiguredPeriodDuration() / 2;
|
|
}
|
|
|
|
private TimeSpan Get8TimesConfiguredPeriodDuration()
|
|
{
|
|
return GetPeriodDuration() * 8.0;
|
|
}
|
|
}
|
|
}
|