setting up marketplace tests

This commit is contained in:
Ben 2024-11-21 15:30:56 +01:00
parent f67e67c493
commit fd3567347b
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
2 changed files with 82 additions and 5 deletions

View File

@ -1,24 +1,45 @@
using CodexContractsPlugin;
using CodexTests;
using GethPlugin;
using CodexPlugin;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Utils;
namespace CodexReleaseTests.MarketTests
{
[TestFixture]
public class ContractSuccessfulTest : AutoBootstrapDistTest
public class ContractSuccessfulTest : MarketplaceAutoBootstrapDistTest
{
private const int NumberOfHosts = 4;
private const int FilesizeMb = 10;
[Test]
public void ContractSuccessful()
{
var geth = Ci.StartGethNode(s => s.IsMiner());
var contracts = Ci.DeployCodexContracts(geth);
var hosts = StartHosts();
var client = StartCodex(s => s.WithName("client"));
}
private ICodexNodeGroup StartHosts()
{
var hosts = StartCodex(NumberOfHosts, s => s.WithName("host"));
var config = GetContracts().Deployment.Config;
foreach (var host in hosts)
{
host.Marketplace.MakeStorageAvailable(new CodexPlugin.StorageAvailability(
totalSpace: (5 * FilesizeMb).MB(),
maxDuration: TimeSpan.FromSeconds(((double)config.Proofs.Period) * 5.0),
minPriceForTotalSpace: 1.TstWei(),
maxCollateral: 999999.Tst())
);
}
return hosts;
}
}
}

View File

@ -0,0 +1,56 @@
using CodexContractsPlugin;
using CodexPlugin;
using CodexTests;
using DistTestCore;
using GethPlugin;
namespace CodexReleaseTests.MarketTests
{
public abstract class MarketplaceAutoBootstrapDistTest : AutoBootstrapDistTest
{
private readonly Dictionary<TestLifecycle, MarketplaceHandle> handles = new Dictionary<TestLifecycle, MarketplaceHandle>();
protected const int StartingBalanceTST = 1000;
protected override void LifecycleStart(TestLifecycle lifecycle)
{
base.LifecycleStart(lifecycle);
var geth = Ci.StartGethNode(s => s.IsMiner());
var contracts = Ci.StartCodexContracts(geth);
handles.Add(lifecycle, new MarketplaceHandle(geth, contracts));
}
protected override void LifecycleStop(TestLifecycle lifecycle, DistTestResult result)
{
base.LifecycleStop(lifecycle, result);
handles.Remove(lifecycle);
}
protected override void OnCodexSetup(ICodexSetup setup)
{
base.OnCodexSetup(setup);
setup.EnableMarketplace(GetGeth(), GetContracts(), m => m.WithInitial(10.Eth(), StartingBalanceTST.Tst()));
}
protected IGethNode GetGeth()
{
return handles[Get()].Geth;
}
protected ICodexContracts GetContracts()
{
return handles[Get()].Contracts;
}
private class MarketplaceHandle
{
public MarketplaceHandle(IGethNode geth, ICodexContracts contracts)
{
Geth = geth;
Contracts = contracts;
}
public IGethNode Geth { get; }
public ICodexContracts Contracts { get; }
}
}
}