cs-codex-dist-tests/DistTestCore/Marketplace/MarketplaceAccess.cs

80 lines
2.6 KiB
C#
Raw Normal View History

2023-04-14 08:51:35 +00:00
using Logging;
using NUnit.Framework;
using NUnit.Framework.Constraints;
namespace DistTestCore.Marketplace
{
public interface IMarketplaceAccess
{
void MakeStorageAvailable(ByteSize size, int minPricePerBytePerSecond, float maxCollateral);
void RequestStorage(ContentId contentId, int pricePerBytePerSecond, float requiredCollateral, float minRequiredNumberOfNodes);
void AssertThatBalance(IResolveConstraint constraint, string message = "");
decimal GetBalance();
}
public class MarketplaceAccess : IMarketplaceAccess
{
private readonly TestLog log;
2023-04-14 10:37:05 +00:00
private readonly GethBootstrapNodeInfo bootstrapNode;
private readonly GethCompanionNodeInfo companionNode;
2023-04-14 08:51:35 +00:00
2023-04-14 10:37:05 +00:00
public MarketplaceAccess(TestLog log, GethBootstrapNodeInfo bootstrapNode, GethCompanionNodeInfo companionNode)
2023-04-14 08:51:35 +00:00
{
this.log = log;
2023-04-14 10:37:05 +00:00
this.bootstrapNode = bootstrapNode;
this.companionNode = companionNode;
2023-04-14 08:51:35 +00:00
}
public void RequestStorage(ContentId contentId, int pricePerBytePerSecond, float requiredCollateral, float minRequiredNumberOfNodes)
{
throw new NotImplementedException();
}
public void MakeStorageAvailable(ByteSize size, int minPricePerBytePerSecond, float maxCollateral)
{
throw new NotImplementedException();
}
public void AssertThatBalance(IResolveConstraint constraint, string message = "")
{
2023-04-14 10:37:05 +00:00
Assert.That(GetBalance(), constraint, message);
2023-04-14 08:51:35 +00:00
}
public decimal GetBalance()
{
2023-04-14 10:37:05 +00:00
var interaction = bootstrapNode.StartInteraction(log);
return interaction.GetBalance(companionNode.Account);
2023-04-14 08:51:35 +00:00
}
}
public class MarketplaceUnavailable : IMarketplaceAccess
{
public void RequestStorage(ContentId contentId, int pricePerBytePerSecond, float requiredCollateral, float minRequiredNumberOfNodes)
{
Unavailable();
}
public void MakeStorageAvailable(ByteSize size, int minPricePerBytePerSecond, float maxCollateral)
{
Unavailable();
}
public void AssertThatBalance(IResolveConstraint constraint, string message = "")
{
Unavailable();
}
public decimal GetBalance()
{
Unavailable();
return 0;
}
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();
}
}
}