mirror of
https://github.com/codex-storage/cs-codex-dist-tests.git
synced 2025-02-03 15:53:31 +00:00
Debug logging for nethereum interactions
This commit is contained in:
parent
abb9560b6d
commit
b3ba39b2e5
@ -39,13 +39,12 @@ namespace Logging
|
|||||||
LogFile.Write(ApplyReplacements(message));
|
LogFile.Write(ApplyReplacements(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Debug(string message = "", int skipFrames = 0)
|
public void Debug(string message = "", int skipFrames = 0)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
var callerName = DebugStack.GetCallerName(skipFrames);
|
var callerName = DebugStack.GetCallerName(skipFrames);
|
||||||
// We don't use Log because in the debug output we should not have any replacements.
|
Log($"(debug)({callerName}) {message}");
|
||||||
LogFile.Write($"(debug)({callerName}) {message}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +72,7 @@ namespace Logging
|
|||||||
|
|
||||||
private string ApplyReplacements(string str)
|
private string ApplyReplacements(string str)
|
||||||
{
|
{
|
||||||
|
if (debug) return str;
|
||||||
foreach (var replacement in replacements)
|
foreach (var replacement in replacements)
|
||||||
{
|
{
|
||||||
str = replacement.Apply(str);
|
str = replacement.Apply(str);
|
||||||
|
@ -17,10 +17,6 @@
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Debug(string message = "", int skipFrames = 0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Error(string message)
|
public override void Error(string message)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Error: " + message);
|
Console.WriteLine("Error: " + message);
|
||||||
|
@ -19,29 +19,34 @@ namespace NethereumWorkflow
|
|||||||
|
|
||||||
public void SendEth(string toAddress, decimal ethAmount)
|
public void SendEth(string toAddress, decimal ethAmount)
|
||||||
{
|
{
|
||||||
|
log.Debug();
|
||||||
var receipt = Time.Wait(web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(toAddress, ethAmount));
|
var receipt = Time.Wait(web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(toAddress, ethAmount));
|
||||||
if (!receipt.Succeeded()) throw new Exception("Unable to send Eth");
|
if (!receipt.Succeeded()) throw new Exception("Unable to send Eth");
|
||||||
}
|
}
|
||||||
|
|
||||||
public decimal GetEthBalance()
|
public decimal GetEthBalance()
|
||||||
{
|
{
|
||||||
|
log.Debug();
|
||||||
return GetEthBalance(web3.TransactionManager.Account.Address);
|
return GetEthBalance(web3.TransactionManager.Account.Address);
|
||||||
}
|
}
|
||||||
|
|
||||||
public decimal GetEthBalance(string address)
|
public decimal GetEthBalance(string address)
|
||||||
{
|
{
|
||||||
|
log.Debug();
|
||||||
var balance = Time.Wait(web3.Eth.GetBalance.SendRequestAsync(address));
|
var balance = Time.Wait(web3.Eth.GetBalance.SendRequestAsync(address));
|
||||||
return Web3.Convert.FromWei(balance.Value);
|
return Web3.Convert.FromWei(balance.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TResult Call<TFunction, TResult>(string contractAddress, TFunction function) where TFunction : FunctionMessage, new()
|
public TResult Call<TFunction, TResult>(string contractAddress, TFunction function) where TFunction : FunctionMessage, new()
|
||||||
{
|
{
|
||||||
|
log.Debug(typeof(TFunction).ToString());
|
||||||
var handler = web3.Eth.GetContractQueryHandler<TFunction>();
|
var handler = web3.Eth.GetContractQueryHandler<TFunction>();
|
||||||
return Time.Wait(handler.QueryAsync<TResult>(contractAddress, function));
|
return Time.Wait(handler.QueryAsync<TResult>(contractAddress, function));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendTransaction<TFunction>(string contractAddress, TFunction function) where TFunction : FunctionMessage, new()
|
public void SendTransaction<TFunction>(string contractAddress, TFunction function) where TFunction : FunctionMessage, new()
|
||||||
{
|
{
|
||||||
|
log.Debug();
|
||||||
var handler = web3.Eth.GetContractTransactionHandler<TFunction>();
|
var handler = web3.Eth.GetContractTransactionHandler<TFunction>();
|
||||||
var receipt = Time.Wait(handler.SendRequestAndWaitForReceiptAsync(contractAddress, function));
|
var receipt = Time.Wait(handler.SendRequestAndWaitForReceiptAsync(contractAddress, function));
|
||||||
if (!receipt.Succeeded()) throw new Exception("Unable to perform contract transaction.");
|
if (!receipt.Succeeded()) throw new Exception("Unable to perform contract transaction.");
|
||||||
|
@ -20,6 +20,7 @@ namespace NethereumWorkflow
|
|||||||
|
|
||||||
public NethereumInteraction CreateWorkflow()
|
public NethereumInteraction CreateWorkflow()
|
||||||
{
|
{
|
||||||
|
log.Debug("Starting interaction to " + ip + ":" + port);
|
||||||
return new NethereumInteraction(log, CreateWeb3());
|
return new NethereumInteraction(log, CreateWeb3());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ namespace CodexContractsPlugin
|
|||||||
|
|
||||||
public void MintTestTokens(EthAddress address, decimal amount, string tokenAddress)
|
public void MintTestTokens(EthAddress address, decimal amount, string tokenAddress)
|
||||||
{
|
{
|
||||||
|
log.Debug($"{amount} -> {address} (token: {tokenAddress})");
|
||||||
MintTokens(address.Address, amount, tokenAddress);
|
MintTokens(address.Address, amount, tokenAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ namespace CodexContractsPlugin
|
|||||||
|
|
||||||
public bool IsSynced(string marketplaceAddress, string marketplaceAbi)
|
public bool IsSynced(string marketplaceAddress, string marketplaceAbi)
|
||||||
{
|
{
|
||||||
|
log.Debug();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return IsBlockNumberOK() && IsContractAvailable(marketplaceAddress, marketplaceAbi);
|
return IsBlockNumberOK() && IsContractAvailable(marketplaceAddress, marketplaceAbi);
|
||||||
|
@ -25,6 +25,7 @@ namespace CodexContractsPlugin
|
|||||||
var marketplaceAddress = Retry(FetchMarketplaceAddress);
|
var marketplaceAddress = Retry(FetchMarketplaceAddress);
|
||||||
if (string.IsNullOrEmpty(marketplaceAddress)) throw new InvalidOperationException("Unable to fetch marketplace account from codex-contracts node. Test infra failure.");
|
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;
|
return marketplaceAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +35,7 @@ namespace CodexContractsPlugin
|
|||||||
var marketplaceAbi = Retry(FetchMarketplaceAbi);
|
var marketplaceAbi = Retry(FetchMarketplaceAbi);
|
||||||
if (string.IsNullOrEmpty(marketplaceAbi)) throw new InvalidOperationException("Unable to fetch marketplace artifacts from codex-contracts node. Test infra failure.");
|
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;
|
return marketplaceAbi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user