Setting up test interface for marketplace
This commit is contained in:
parent
a3ccd07254
commit
adbcfb9974
|
@ -1,4 +1,6 @@
|
||||||
namespace CodexDistTestCore
|
using CodexDistTestCore.Metrics;
|
||||||
|
|
||||||
|
namespace CodexDistTestCore
|
||||||
{
|
{
|
||||||
public interface IK8sManager
|
public interface IK8sManager
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using CodexDistTestCore.Config;
|
using CodexDistTestCore.Config;
|
||||||
|
using CodexDistTestCore.Metrics;
|
||||||
using k8s;
|
using k8s;
|
||||||
using k8s.KubeConfigModels;
|
using k8s.KubeConfigModels;
|
||||||
using k8s.Models;
|
using k8s.Models;
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NUnit.Framework.Constraints;
|
||||||
|
|
||||||
|
namespace CodexDistTestCore.Marketplace
|
||||||
|
{
|
||||||
|
public interface IMarketplaceAccess
|
||||||
|
{
|
||||||
|
void AdvertiseStorage(ByteSize size, float pricePerMBPerSecond, float collateral);
|
||||||
|
void AdvertiseContract(ContentId contentId, float maxPricePerMBPerSecond, float minRequiredCollateral, float minRequiredNumberOfDuplicates);
|
||||||
|
void AssertThatBalance(IResolveConstraint constraint, string message = "");
|
||||||
|
float GetBalance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MarketplaceAccess : IMarketplaceAccess
|
||||||
|
{
|
||||||
|
public void AdvertiseContract(ContentId contentId, float maxPricePerMBPerSecond, float minRequiredCollateral, float minRequiredNumberOfDuplicates)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AdvertiseStorage(ByteSize size, float pricePerMBPerSecond, float collateral)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AssertThatBalance(IResolveConstraint constraint, string message = "")
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetBalance()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MarketplaceUnavailable : IMarketplaceAccess
|
||||||
|
{
|
||||||
|
public void AdvertiseContract(ContentId contentId, float maxPricePerMBPerSecond, float minRequiredCollateral, float minRequiredNumberOfDuplicates)
|
||||||
|
{
|
||||||
|
Unavailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AdvertiseStorage(ByteSize size, float pricePerMBPerSecond, float collateral)
|
||||||
|
{
|
||||||
|
Unavailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AssertThatBalance(IResolveConstraint constraint, string message = "")
|
||||||
|
{
|
||||||
|
Unavailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetBalance()
|
||||||
|
{
|
||||||
|
Unavailable();
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Unavailable()
|
||||||
|
{
|
||||||
|
Assert.Fail("Incorrect test setup: Marketplace was not enabled for this group of Codex nodes. Add 'EnableMarketplace(...)' after 'SetupCodexNodes()' to enable it.");
|
||||||
|
throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
namespace CodexDistTestCore.Marketplace
|
||||||
|
{
|
||||||
|
public class MarketplaceInitialConfig
|
||||||
|
{
|
||||||
|
public MarketplaceInitialConfig(int initialBalance)
|
||||||
|
{
|
||||||
|
InitialBalance = initialBalance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int InitialBalance { get; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
using CodexDistTestCore.Config;
|
using CodexDistTestCore.Config;
|
||||||
using k8s.Models;
|
using k8s.Models;
|
||||||
|
|
||||||
namespace CodexDistTestCore
|
namespace CodexDistTestCore.Metrics
|
||||||
{
|
{
|
||||||
public class K8sPrometheusSpecs
|
public class K8sPrometheusSpecs
|
||||||
{
|
{
|
|
@ -1,7 +1,7 @@
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NUnit.Framework.Constraints;
|
using NUnit.Framework.Constraints;
|
||||||
|
|
||||||
namespace CodexDistTestCore
|
namespace CodexDistTestCore.Metrics
|
||||||
{
|
{
|
||||||
public interface IMetricsAccess
|
public interface IMetricsAccess
|
||||||
{
|
{
|
|
@ -1,7 +1,7 @@
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace CodexDistTestCore
|
namespace CodexDistTestCore.Metrics
|
||||||
{
|
{
|
||||||
public class MetricsAggregator
|
public class MetricsAggregator
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,7 @@ namespace CodexDistTestCore
|
||||||
|
|
||||||
log.Log("Metrics service started.");
|
log.Log("Metrics service started.");
|
||||||
|
|
||||||
foreach(var node in nodes)
|
foreach (var node in nodes)
|
||||||
{
|
{
|
||||||
node.Metrics = new MetricsAccess(query, node);
|
node.Metrics = new MetricsAccess(query, node);
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
||||||
namespace CodexDistTestCore
|
namespace CodexDistTestCore.Metrics
|
||||||
{
|
{
|
||||||
public class MetricsDownloader
|
public class MetricsDownloader
|
||||||
{
|
{
|
|
@ -1,7 +1,7 @@
|
||||||
using CodexDistTestCore.Config;
|
using CodexDistTestCore.Config;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
||||||
namespace CodexDistTestCore
|
namespace CodexDistTestCore.Metrics
|
||||||
{
|
{
|
||||||
public class MetricsQuery
|
public class MetricsQuery
|
||||||
{
|
{
|
|
@ -1,4 +1,6 @@
|
||||||
namespace CodexDistTestCore
|
using CodexDistTestCore.Marketplace;
|
||||||
|
|
||||||
|
namespace CodexDistTestCore
|
||||||
{
|
{
|
||||||
public interface IOfflineCodexNodes
|
public interface IOfflineCodexNodes
|
||||||
{
|
{
|
||||||
|
@ -7,6 +9,7 @@
|
||||||
IOfflineCodexNodes WithBootstrapNode(IOnlineCodexNode node);
|
IOfflineCodexNodes WithBootstrapNode(IOnlineCodexNode node);
|
||||||
IOfflineCodexNodes WithStorageQuota(ByteSize storageQuota);
|
IOfflineCodexNodes WithStorageQuota(ByteSize storageQuota);
|
||||||
IOfflineCodexNodes EnableMetrics();
|
IOfflineCodexNodes EnableMetrics();
|
||||||
|
IOfflineCodexNodes EnableMarketplace(int initialBalance);
|
||||||
ICodexNodeGroup BringOnline();
|
ICodexNodeGroup BringOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +39,7 @@
|
||||||
public IOnlineCodexNode? BootstrapNode { get; private set; }
|
public IOnlineCodexNode? BootstrapNode { get; private set; }
|
||||||
public ByteSize? StorageQuota { get; private set; }
|
public ByteSize? StorageQuota { get; private set; }
|
||||||
public bool MetricsEnabled { get; private set; }
|
public bool MetricsEnabled { get; private set; }
|
||||||
|
public MarketplaceInitialConfig? MarketplaceConfig { get; private set; }
|
||||||
|
|
||||||
public OfflineCodexNodes(IK8sManager k8SManager, int numberOfNodes)
|
public OfflineCodexNodes(IK8sManager k8SManager, int numberOfNodes)
|
||||||
{
|
{
|
||||||
|
@ -80,6 +84,12 @@
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IOfflineCodexNodes EnableMarketplace(int initialBalance)
|
||||||
|
{
|
||||||
|
MarketplaceConfig = new MarketplaceInitialConfig(initialBalance);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public string Describe()
|
public string Describe()
|
||||||
{
|
{
|
||||||
var args = string.Join(',', DescribeArgs());
|
var args = string.Join(',', DescribeArgs());
|
||||||
|
@ -89,7 +99,7 @@
|
||||||
private IEnumerable<string> DescribeArgs()
|
private IEnumerable<string> DescribeArgs()
|
||||||
{
|
{
|
||||||
if (LogLevel != null) yield return ($"LogLevel={LogLevel}");
|
if (LogLevel != null) yield return ($"LogLevel={LogLevel}");
|
||||||
if (BootstrapNode != null) yield return ("BootstrapNode=set");
|
if (BootstrapNode != null) yield return ("BootstrapNode=set-not-shown-here");
|
||||||
if (StorageQuota != null) yield return ($"StorageQuote={StorageQuota.SizeInBytes}");
|
if (StorageQuota != null) yield return ($"StorageQuote={StorageQuota.SizeInBytes}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using CodexDistTestCore.Config;
|
using CodexDistTestCore.Config;
|
||||||
|
using CodexDistTestCore.Marketplace;
|
||||||
|
using CodexDistTestCore.Metrics;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace CodexDistTestCore
|
namespace CodexDistTestCore
|
||||||
|
@ -11,6 +13,7 @@ namespace CodexDistTestCore
|
||||||
void ConnectToPeer(IOnlineCodexNode node);
|
void ConnectToPeer(IOnlineCodexNode node);
|
||||||
ICodexNodeLog DownloadLog();
|
ICodexNodeLog DownloadLog();
|
||||||
IMetricsAccess Metrics { get; }
|
IMetricsAccess Metrics { get; }
|
||||||
|
IMarketplaceAccess Marketplace { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class OnlineCodexNode : IOnlineCodexNode
|
public class OnlineCodexNode : IOnlineCodexNode
|
||||||
|
@ -32,6 +35,7 @@ namespace CodexDistTestCore
|
||||||
public CodexNodeContainer Container { get; }
|
public CodexNodeContainer Container { get; }
|
||||||
public CodexNodeGroup Group { get; internal set; } = null!;
|
public CodexNodeGroup Group { get; internal set; } = null!;
|
||||||
public IMetricsAccess Metrics { get; set; } = new MetricsUnavailable();
|
public IMetricsAccess Metrics { get; set; } = new MetricsUnavailable();
|
||||||
|
public IMarketplaceAccess Marketplace { set; get; } = new MarketplaceUnavailable();
|
||||||
|
|
||||||
public string GetName()
|
public string GetName()
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace CodexDistTestCore
|
||||||
public class TryContract
|
public class TryContract
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
|
[Ignore("aaa")]
|
||||||
public void DoThing()
|
public void DoThing()
|
||||||
{
|
{
|
||||||
var url = "http://testchain.nethereum.com:8545";
|
var url = "http://testchain.nethereum.com:8545";
|
||||||
|
|
|
@ -39,6 +39,32 @@ namespace Tests.BasicTests
|
||||||
primary2.Metrics.AssertThat("libp2p_peers", Is.EqualTo(1));
|
primary2.Metrics.AssertThat("libp2p_peers", Is.EqualTo(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void MarketplaceExample()
|
||||||
|
{
|
||||||
|
var primary = SetupCodexNodes(1)
|
||||||
|
.WithStorageQuota(10.GB())
|
||||||
|
.EnableMarketplace(initialBalance: 20)
|
||||||
|
.BringOnline()[0];
|
||||||
|
|
||||||
|
var secondary = SetupCodexNodes(1)
|
||||||
|
.EnableMarketplace(initialBalance: 1000)
|
||||||
|
.BringOnline()[0];
|
||||||
|
|
||||||
|
primary.ConnectToPeer(secondary);
|
||||||
|
primary.Marketplace.AdvertiseStorage(10.GB(), pricePerMBPerSecond: 0.01f, collateral: 20);
|
||||||
|
|
||||||
|
var testFile = GenerateTestFile(10.MB());
|
||||||
|
var contentId = secondary.UploadFile(testFile);
|
||||||
|
secondary.Marketplace.AdvertiseContract(contentId, maxPricePerMBPerSecond: 0.02f, minRequiredCollateral: 10, minRequiredNumberOfDuplicates: 1);
|
||||||
|
|
||||||
|
primary.Marketplace.AssertThatBalance(Is.LessThan(20), "Collateral was not placed.");
|
||||||
|
var primaryBalance = primary.Marketplace.GetBalance();
|
||||||
|
|
||||||
|
secondary.Marketplace.AssertThatBalance(Is.LessThan(1000), "Contractor was not charged for storage.");
|
||||||
|
primary.Marketplace.AssertThatBalance(Is.GreaterThan(primaryBalance), "Storer was not paid for storage.");
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void OneClientTest()
|
public void OneClientTest()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue