Better logging

This commit is contained in:
benbierens 2023-04-19 09:57:37 +02:00
parent 7e6de4146e
commit e4e7afd580
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
11 changed files with 57 additions and 27 deletions

View File

@ -8,6 +8,11 @@
} }
public long SizeInBytes { get; } public long SizeInBytes { get; }
public override string ToString()
{
return $"{SizeInBytes} bytes";
}
} }
public static class ByteSizeIntExtensions public static class ByteSizeIntExtensions

View File

@ -1,4 +1,5 @@
using KubernetesWorkflow; using KubernetesWorkflow;
using Newtonsoft.Json;
namespace DistTestCore.Codex namespace DistTestCore.Codex
{ {

View File

@ -5,7 +5,7 @@ namespace DistTestCore.Codex
{ {
public class CodexContainerRecipe : ContainerRecipeFactory public class CodexContainerRecipe : ContainerRecipeFactory
{ {
public const string DockerImage = "thatbenbierens/nim-codex:sha-b204837"; public const string DockerImage = "thatbenbierens/nim-codex:sha-bf5512b";
public const string MetricsPortTag = "metrics_port"; public const string MetricsPortTag = "metrics_port";
protected override string Image => DockerImage; protected override string Image => DockerImage;

View File

@ -84,7 +84,7 @@ namespace DistTestCore
{ {
if (LogLevel != null) yield return $"LogLevel={LogLevel}"; if (LogLevel != null) yield return $"LogLevel={LogLevel}";
//if (BootstrapNode != null) yield return "BootstrapNode=set-not-shown-here"; //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}";
} }
} }
} }

View File

@ -26,7 +26,7 @@ namespace DistTestCore
LogStart("Setting up initial balance..."); LogStart("Setting up initial balance...");
TransferInitialBalance(marketplaceNetwork, codexSetup.MarketplaceConfig, companionNodes); TransferInitialBalance(marketplaceNetwork, codexSetup.MarketplaceConfig, companionNodes);
LogEnd($"Initial balance of {codexSetup.MarketplaceConfig.InitialTestTokens.Amount} TestTokens set for {codexSetup.NumberOfNodes} nodes."); LogEnd($"Initial balance of {codexSetup.MarketplaceConfig.InitialTestTokens} set for {codexSetup.NumberOfNodes} nodes.");
return CreateGethStartResult(marketplaceNetwork, companionNodes); return CreateGethStartResult(marketplaceNetwork, companionNodes);
} }

View File

@ -3,6 +3,7 @@ using Logging;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Constraints; using NUnit.Framework.Constraints;
using System.Numerics; using System.Numerics;
using Utils;
namespace DistTestCore.Marketplace namespace DistTestCore.Marketplace
{ {
@ -11,7 +12,7 @@ namespace DistTestCore.Marketplace
string MakeStorageAvailable(ByteSize size, TestToken minPricePerBytePerSecond, TestToken maxCollateral, TimeSpan maxDuration); string MakeStorageAvailable(ByteSize size, TestToken minPricePerBytePerSecond, TestToken maxCollateral, TimeSpan maxDuration);
string RequestStorage(ContentId contentId, TestToken pricePerBytePerSecond, TestToken requiredCollateral, uint minRequiredNumberOfNodes, int proofProbability, TimeSpan duration); string RequestStorage(ContentId contentId, TestToken pricePerBytePerSecond, TestToken requiredCollateral, uint minRequiredNumberOfNodes, int proofProbability, TimeSpan duration);
void AssertThatBalance(IResolveConstraint constraint, string message = ""); void AssertThatBalance(IResolveConstraint constraint, string message = "");
decimal GetBalance(); TestToken GetBalance();
} }
public class MarketplaceAccess : IMarketplaceAccess public class MarketplaceAccess : IMarketplaceAccess
@ -42,23 +43,40 @@ namespace DistTestCore.Marketplace
tolerance = null, tolerance = null,
}; };
Log($"Requesting storage for: {contentId.Id}... (" +
$"pricePerBytePerSecond: {pricePerBytePerSecond}," +
$"requiredCollateral: {requiredCollateral}," +
$"minRequiredNumberOfNodes: {minRequiredNumberOfNodes}," +
$"proofProbability: {proofProbability}," +
$"duration: {Time.FormatDuration(duration)})");
var response = codexAccess.RequestStorage(request, contentId.Id); var response = codexAccess.RequestStorage(request, contentId.Id);
Log($"Storage requested successfully. PurchaseId: {response.purchaseId}");
return response.purchaseId; return response.purchaseId;
} }
public string MakeStorageAvailable(ByteSize size, TestToken minPricePerBytePerSecond, TestToken maxCollateral, TimeSpan duration) public string MakeStorageAvailable(ByteSize size, TestToken minPricePerBytePerSecond, TestToken maxCollateral, TimeSpan maxDuration)
{ {
var request = new CodexSalesAvailabilityRequest var request = new CodexSalesAvailabilityRequest
{ {
size = ToHexBigInt(size.SizeInBytes), size = ToHexBigInt(size.SizeInBytes),
duration = ToHexBigInt(duration.TotalSeconds), duration = ToHexBigInt(maxDuration.TotalSeconds),
maxCollateral = ToHexBigInt(maxCollateral), maxCollateral = ToHexBigInt(maxCollateral),
minPrice = ToHexBigInt(minPricePerBytePerSecond) minPrice = ToHexBigInt(minPricePerBytePerSecond)
}; };
Log($"Making storage available... (" +
$"size: {size}," +
$"minPricePerBytePerSecond: {minPricePerBytePerSecond}," +
$"maxCollateral: {maxCollateral}," +
$"maxDuration: {Time.FormatDuration(maxDuration)}");
var response = codexAccess.SalesAvailability(request); var response = codexAccess.SalesAvailability(request);
Log($"Storage successfully made available. Id: {response.id}");
return response.id; return response.id;
} }
@ -78,10 +96,21 @@ namespace DistTestCore.Marketplace
Assert.That(GetBalance(), constraint, message); Assert.That(GetBalance(), constraint, message);
} }
public decimal GetBalance() public TestToken GetBalance()
{ {
var interaction = marketplaceNetwork.StartInteraction(log); var interaction = marketplaceNetwork.StartInteraction(log);
return interaction.GetBalance(marketplaceNetwork.Marketplace.TokenAddress, companionNode.Account); var account = companionNode.Account;
var amount = interaction.GetBalance(marketplaceNetwork.Marketplace.TokenAddress, account);
var balance = new TestToken(amount);
Log($"Balance of {codexAccess.Container.GetName()}({account}) is {balance}.");
return balance;
}
private void Log(string msg)
{
log.Log(msg);
} }
} }
@ -104,10 +133,10 @@ namespace DistTestCore.Marketplace
Unavailable(); Unavailable();
} }
public decimal GetBalance() public TestToken GetBalance()
{ {
Unavailable(); Unavailable();
return 0; return new TestToken(0);
} }
private void Unavailable() private void Unavailable()

View File

@ -40,7 +40,7 @@ namespace DistTestCore
public string GetName() public string GetName()
{ {
return $"<{CodexAccess.Container.Recipe.Name}>"; return CodexAccess.Container.GetName();
} }
public CodexDebugResponse GetDebugInfo() public CodexDebugResponse GetDebugInfo()

View File

@ -18,6 +18,11 @@
} }
public decimal Amount { get; } public decimal Amount { get; }
public override string ToString()
{
return $"{Amount} TestTokens";
}
} }
public static class TokensIntExtensions public static class TokensIntExtensions

View File

@ -28,6 +28,11 @@
ServicePorts = servicePorts; ServicePorts = servicePorts;
} }
public string GetName()
{
return $"<{Recipe.Name}>";
}
public RunningPod Pod { get; } public RunningPod Pod { get; }
public ContainerRecipe Recipe { get; } public ContainerRecipe Recipe { get; }
public Port[] ServicePorts { get; } public Port[] ServicePorts { get; }

View File

@ -61,10 +61,7 @@ namespace NethereumWorkflow
}; };
var handler = web3.Eth.GetContractQueryHandler<GetTokenBalanceFunction>(); var handler = web3.Eth.GetContractQueryHandler<GetTokenBalanceFunction>();
var result = ToDecimal(Time.Wait(handler.QueryAsync<BigInteger>(tokenAddress, function))); return ToDecimal(Time.Wait(handler.QueryAsync<BigInteger>(tokenAddress, function)));
Log($"Balance of {account} is {result} TestTokens.");
return result;
} }
public void WaitForAllTransactions() public void WaitForAllTransactions()
@ -87,20 +84,10 @@ namespace NethereumWorkflow
return new BigInteger(amount); return new BigInteger(amount);
} }
private decimal ToDecimal(HexBigInteger hexBigInteger)
{
return (decimal)hexBigInteger.Value;
}
private decimal ToDecimal(BigInteger bigInteger) private decimal ToDecimal(BigInteger bigInteger)
{ {
return (decimal)bigInteger; return (decimal)bigInteger;
} }
private void Log(string msg)
{
log.Log(msg);
}
} }
[Function("token", "address")] [Function("token", "address")]

View File

@ -63,7 +63,6 @@ namespace Tests.BasicTests
primary.ConnectToPeer(secondary); primary.ConnectToPeer(secondary);
// Gives 503 - Persistance not enabled in current codex image.
primary.Marketplace.MakeStorageAvailable( primary.Marketplace.MakeStorageAvailable(
size: 10.GB(), size: 10.GB(),
minPricePerBytePerSecond: 1.TestTokens(), minPricePerBytePerSecond: 1.TestTokens(),
@ -73,7 +72,6 @@ namespace Tests.BasicTests
var testFile = GenerateTestFile(10.MB()); var testFile = GenerateTestFile(10.MB());
var contentId = secondary.UploadFile(testFile); var contentId = secondary.UploadFile(testFile);
// Gives 500 - Persistance not enabled in current codex image.
secondary.Marketplace.RequestStorage(contentId, secondary.Marketplace.RequestStorage(contentId,
pricePerBytePerSecond: 2.TestTokens(), pricePerBytePerSecond: 2.TestTokens(),
requiredCollateral: 10.TestTokens(), requiredCollateral: 10.TestTokens(),