From b3ba39b2e5c75e2b5826d7614f70326a284eaf51 Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 23 Oct 2023 16:04:50 +0200 Subject: [PATCH] Debug logging for nethereum interactions --- Framework/Logging/BaseLog.cs | 6 +++--- Framework/Logging/NullLog.cs | 4 ---- Framework/NethereumWorkflow/NethereumInteraction.cs | 5 +++++ Framework/NethereumWorkflow/NethereumInteractionCreator.cs | 1 + ProjectPlugins/CodexContractsPlugin/ContractInteractions.cs | 2 ++ .../CodexContractsPlugin/ContractsContainerInfoExtractor.cs | 2 ++ 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Framework/Logging/BaseLog.cs b/Framework/Logging/BaseLog.cs index b80b007..d16a1c9 100644 --- a/Framework/Logging/BaseLog.cs +++ b/Framework/Logging/BaseLog.cs @@ -39,13 +39,12 @@ namespace Logging LogFile.Write(ApplyReplacements(message)); } - public virtual void Debug(string message = "", int skipFrames = 0) + public void Debug(string message = "", int skipFrames = 0) { if (debug) { var callerName = DebugStack.GetCallerName(skipFrames); - // We don't use Log because in the debug output we should not have any replacements. - LogFile.Write($"(debug)({callerName}) {message}"); + Log($"(debug)({callerName}) {message}"); } } @@ -73,6 +72,7 @@ namespace Logging private string ApplyReplacements(string str) { + if (debug) return str; foreach (var replacement in replacements) { str = replacement.Apply(str); diff --git a/Framework/Logging/NullLog.cs b/Framework/Logging/NullLog.cs index 997e490..bbd3214 100644 --- a/Framework/Logging/NullLog.cs +++ b/Framework/Logging/NullLog.cs @@ -17,10 +17,6 @@ { } - public override void Debug(string message = "", int skipFrames = 0) - { - } - public override void Error(string message) { Console.WriteLine("Error: " + message); diff --git a/Framework/NethereumWorkflow/NethereumInteraction.cs b/Framework/NethereumWorkflow/NethereumInteraction.cs index e3aa5bf..cbe5028 100644 --- a/Framework/NethereumWorkflow/NethereumInteraction.cs +++ b/Framework/NethereumWorkflow/NethereumInteraction.cs @@ -19,29 +19,34 @@ namespace NethereumWorkflow public void SendEth(string toAddress, decimal ethAmount) { + log.Debug(); var receipt = Time.Wait(web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(toAddress, ethAmount)); if (!receipt.Succeeded()) throw new Exception("Unable to send Eth"); } public decimal GetEthBalance() { + log.Debug(); return GetEthBalance(web3.TransactionManager.Account.Address); } public decimal GetEthBalance(string address) { + log.Debug(); var balance = Time.Wait(web3.Eth.GetBalance.SendRequestAsync(address)); return Web3.Convert.FromWei(balance.Value); } public TResult Call(string contractAddress, TFunction function) where TFunction : FunctionMessage, new() { + log.Debug(typeof(TFunction).ToString()); var handler = web3.Eth.GetContractQueryHandler(); return Time.Wait(handler.QueryAsync(contractAddress, function)); } public void SendTransaction(string contractAddress, TFunction function) where TFunction : FunctionMessage, new() { + log.Debug(); var handler = web3.Eth.GetContractTransactionHandler(); var receipt = Time.Wait(handler.SendRequestAndWaitForReceiptAsync(contractAddress, function)); if (!receipt.Succeeded()) throw new Exception("Unable to perform contract transaction."); diff --git a/Framework/NethereumWorkflow/NethereumInteractionCreator.cs b/Framework/NethereumWorkflow/NethereumInteractionCreator.cs index bad1194..8e83cc1 100644 --- a/Framework/NethereumWorkflow/NethereumInteractionCreator.cs +++ b/Framework/NethereumWorkflow/NethereumInteractionCreator.cs @@ -20,6 +20,7 @@ namespace NethereumWorkflow public NethereumInteraction CreateWorkflow() { + log.Debug("Starting interaction to " + ip + ":" + port); return new NethereumInteraction(log, CreateWeb3()); } diff --git a/ProjectPlugins/CodexContractsPlugin/ContractInteractions.cs b/ProjectPlugins/CodexContractsPlugin/ContractInteractions.cs index 719a603..753a8c7 100644 --- a/ProjectPlugins/CodexContractsPlugin/ContractInteractions.cs +++ b/ProjectPlugins/CodexContractsPlugin/ContractInteractions.cs @@ -28,6 +28,7 @@ namespace CodexContractsPlugin public void MintTestTokens(EthAddress address, decimal amount, string tokenAddress) { + log.Debug($"{amount} -> {address} (token: {tokenAddress})"); MintTokens(address.Address, amount, tokenAddress); } @@ -44,6 +45,7 @@ namespace CodexContractsPlugin public bool IsSynced(string marketplaceAddress, string marketplaceAbi) { + log.Debug(); try { return IsBlockNumberOK() && IsContractAvailable(marketplaceAddress, marketplaceAbi); diff --git a/ProjectPlugins/CodexContractsPlugin/ContractsContainerInfoExtractor.cs b/ProjectPlugins/CodexContractsPlugin/ContractsContainerInfoExtractor.cs index 78b3896..2ea164c 100644 --- a/ProjectPlugins/CodexContractsPlugin/ContractsContainerInfoExtractor.cs +++ b/ProjectPlugins/CodexContractsPlugin/ContractsContainerInfoExtractor.cs @@ -25,6 +25,7 @@ namespace CodexContractsPlugin var marketplaceAddress = Retry(FetchMarketplaceAddress); if (string.IsNullOrEmpty(marketplaceAddress)) throw new InvalidOperationException("Unable to fetch marketplace account from codex-contracts node. Test infra failure."); + log.Debug("Got MarketplaceAddress: " + marketplaceAddress); return marketplaceAddress; } @@ -34,6 +35,7 @@ namespace CodexContractsPlugin var marketplaceAbi = Retry(FetchMarketplaceAbi); if (string.IsNullOrEmpty(marketplaceAbi)) throw new InvalidOperationException("Unable to fetch marketplace artifacts from codex-contracts node. Test infra failure."); + log.Debug("Got Marketplace ABI: " + marketplaceAbi); return marketplaceAbi; }