From e4e7afd5802f46429e46b3cc80722fdd0757b6bc Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 19 Apr 2023 09:57:37 +0200 Subject: [PATCH] Better logging --- DistTestCore/ByteSize.cs | 5 +++ DistTestCore/Codex/CodexAccess.cs | 1 + DistTestCore/Codex/CodexContainerRecipe.cs | 2 +- DistTestCore/CodexSetup.cs | 2 +- DistTestCore/GethStarter.cs | 2 +- DistTestCore/Marketplace/MarketplaceAccess.cs | 43 ++++++++++++++++--- DistTestCore/OnlineCodexNode.cs | 2 +- DistTestCore/Tokens.cs | 5 +++ KubernetesWorkflow/RunningContainers.cs | 5 +++ Nethereum/NethereumInteraction.cs | 15 +------ Tests/BasicTests/ExampleTests.cs | 2 - 11 files changed, 57 insertions(+), 27 deletions(-) diff --git a/DistTestCore/ByteSize.cs b/DistTestCore/ByteSize.cs index 783cce9..2a41e94 100644 --- a/DistTestCore/ByteSize.cs +++ b/DistTestCore/ByteSize.cs @@ -8,6 +8,11 @@ } public long SizeInBytes { get; } + + public override string ToString() + { + return $"{SizeInBytes} bytes"; + } } public static class ByteSizeIntExtensions diff --git a/DistTestCore/Codex/CodexAccess.cs b/DistTestCore/Codex/CodexAccess.cs index ae84a91..00ac2f2 100644 --- a/DistTestCore/Codex/CodexAccess.cs +++ b/DistTestCore/Codex/CodexAccess.cs @@ -1,4 +1,5 @@ using KubernetesWorkflow; +using Newtonsoft.Json; namespace DistTestCore.Codex { diff --git a/DistTestCore/Codex/CodexContainerRecipe.cs b/DistTestCore/Codex/CodexContainerRecipe.cs index ab3dbee..01f4933 100644 --- a/DistTestCore/Codex/CodexContainerRecipe.cs +++ b/DistTestCore/Codex/CodexContainerRecipe.cs @@ -5,7 +5,7 @@ namespace DistTestCore.Codex { 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"; protected override string Image => DockerImage; diff --git a/DistTestCore/CodexSetup.cs b/DistTestCore/CodexSetup.cs index 72dc103..39020f6 100644 --- a/DistTestCore/CodexSetup.cs +++ b/DistTestCore/CodexSetup.cs @@ -84,7 +84,7 @@ namespace DistTestCore { if (LogLevel != null) yield return $"LogLevel={LogLevel}"; //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}"; } } } diff --git a/DistTestCore/GethStarter.cs b/DistTestCore/GethStarter.cs index e4b5b37..b3c782b 100644 --- a/DistTestCore/GethStarter.cs +++ b/DistTestCore/GethStarter.cs @@ -26,7 +26,7 @@ namespace DistTestCore LogStart("Setting up initial balance..."); 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); } diff --git a/DistTestCore/Marketplace/MarketplaceAccess.cs b/DistTestCore/Marketplace/MarketplaceAccess.cs index dd784c9..713081e 100644 --- a/DistTestCore/Marketplace/MarketplaceAccess.cs +++ b/DistTestCore/Marketplace/MarketplaceAccess.cs @@ -3,6 +3,7 @@ using Logging; using NUnit.Framework; using NUnit.Framework.Constraints; using System.Numerics; +using Utils; namespace DistTestCore.Marketplace { @@ -11,7 +12,7 @@ namespace DistTestCore.Marketplace string MakeStorageAvailable(ByteSize size, TestToken minPricePerBytePerSecond, TestToken maxCollateral, TimeSpan maxDuration); string RequestStorage(ContentId contentId, TestToken pricePerBytePerSecond, TestToken requiredCollateral, uint minRequiredNumberOfNodes, int proofProbability, TimeSpan duration); void AssertThatBalance(IResolveConstraint constraint, string message = ""); - decimal GetBalance(); + TestToken GetBalance(); } public class MarketplaceAccess : IMarketplaceAccess @@ -42,23 +43,40 @@ namespace DistTestCore.Marketplace 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); + Log($"Storage requested successfully. PurchaseId: {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 { size = ToHexBigInt(size.SizeInBytes), - duration = ToHexBigInt(duration.TotalSeconds), + duration = ToHexBigInt(maxDuration.TotalSeconds), maxCollateral = ToHexBigInt(maxCollateral), minPrice = ToHexBigInt(minPricePerBytePerSecond) }; + Log($"Making storage available... (" + + $"size: {size}," + + $"minPricePerBytePerSecond: {minPricePerBytePerSecond}," + + $"maxCollateral: {maxCollateral}," + + $"maxDuration: {Time.FormatDuration(maxDuration)}"); + var response = codexAccess.SalesAvailability(request); + Log($"Storage successfully made available. Id: {response.id}"); + return response.id; } @@ -78,10 +96,21 @@ namespace DistTestCore.Marketplace Assert.That(GetBalance(), constraint, message); } - public decimal GetBalance() + public TestToken GetBalance() { 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(); } - public decimal GetBalance() + public TestToken GetBalance() { Unavailable(); - return 0; + return new TestToken(0); } private void Unavailable() diff --git a/DistTestCore/OnlineCodexNode.cs b/DistTestCore/OnlineCodexNode.cs index 0750ee3..bf0dfdf 100644 --- a/DistTestCore/OnlineCodexNode.cs +++ b/DistTestCore/OnlineCodexNode.cs @@ -40,7 +40,7 @@ namespace DistTestCore public string GetName() { - return $"<{CodexAccess.Container.Recipe.Name}>"; + return CodexAccess.Container.GetName(); } public CodexDebugResponse GetDebugInfo() diff --git a/DistTestCore/Tokens.cs b/DistTestCore/Tokens.cs index 4669660..3f92852 100644 --- a/DistTestCore/Tokens.cs +++ b/DistTestCore/Tokens.cs @@ -18,6 +18,11 @@ } public decimal Amount { get; } + + public override string ToString() + { + return $"{Amount} TestTokens"; + } } public static class TokensIntExtensions diff --git a/KubernetesWorkflow/RunningContainers.cs b/KubernetesWorkflow/RunningContainers.cs index 783c6f8..27a9991 100644 --- a/KubernetesWorkflow/RunningContainers.cs +++ b/KubernetesWorkflow/RunningContainers.cs @@ -28,6 +28,11 @@ ServicePorts = servicePorts; } + public string GetName() + { + return $"<{Recipe.Name}>"; + } + public RunningPod Pod { get; } public ContainerRecipe Recipe { get; } public Port[] ServicePorts { get; } diff --git a/Nethereum/NethereumInteraction.cs b/Nethereum/NethereumInteraction.cs index adce008..735bd6f 100644 --- a/Nethereum/NethereumInteraction.cs +++ b/Nethereum/NethereumInteraction.cs @@ -61,10 +61,7 @@ namespace NethereumWorkflow }; var handler = web3.Eth.GetContractQueryHandler(); - var result = ToDecimal(Time.Wait(handler.QueryAsync(tokenAddress, function))); - - Log($"Balance of {account} is {result} TestTokens."); - return result; + return ToDecimal(Time.Wait(handler.QueryAsync(tokenAddress, function))); } public void WaitForAllTransactions() @@ -87,20 +84,10 @@ namespace NethereumWorkflow return new BigInteger(amount); } - private decimal ToDecimal(HexBigInteger hexBigInteger) - { - return (decimal)hexBigInteger.Value; - } - private decimal ToDecimal(BigInteger bigInteger) { return (decimal)bigInteger; } - - private void Log(string msg) - { - log.Log(msg); - } } [Function("token", "address")] diff --git a/Tests/BasicTests/ExampleTests.cs b/Tests/BasicTests/ExampleTests.cs index 3269225..9c43ab1 100644 --- a/Tests/BasicTests/ExampleTests.cs +++ b/Tests/BasicTests/ExampleTests.cs @@ -63,7 +63,6 @@ namespace Tests.BasicTests primary.ConnectToPeer(secondary); - // Gives 503 - Persistance not enabled in current codex image. primary.Marketplace.MakeStorageAvailable( size: 10.GB(), minPricePerBytePerSecond: 1.TestTokens(), @@ -73,7 +72,6 @@ namespace Tests.BasicTests var testFile = GenerateTestFile(10.MB()); var contentId = secondary.UploadFile(testFile); - // Gives 500 - Persistance not enabled in current codex image. secondary.Marketplace.RequestStorage(contentId, pricePerBytePerSecond: 2.TestTokens(), requiredCollateral: 10.TestTokens(),