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-18 08:22:11 +00:00
private readonly MarketplaceNetwork marketplaceNetwork ;
2023-04-14 10:37:05 +00:00
private readonly GethCompanionNodeInfo companionNode ;
2023-04-14 08:51:35 +00:00
2023-04-18 08:22:11 +00:00
public MarketplaceAccess ( TestLog log , MarketplaceNetwork marketplaceNetwork , GethCompanionNodeInfo companionNode )
2023-04-14 08:51:35 +00:00
{
this . log = log ;
2023-04-18 08:22:11 +00:00
this . marketplaceNetwork = marketplaceNetwork ;
2023-04-14 10:37:05 +00:00
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-18 08:22:11 +00:00
var interaction = marketplaceNetwork . StartInteraction ( log ) ;
2023-04-14 10:37:05 +00:00
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 ( ) ;
}
}
}