diff --git a/DistTestCore/GethStarter.cs b/DistTestCore/GethStarter.cs index d933eaa..61d0bce 100644 --- a/DistTestCore/GethStarter.cs +++ b/DistTestCore/GethStarter.cs @@ -33,7 +33,7 @@ namespace DistTestCore private void TransferInitialBalance(MarketplaceNetwork marketplaceNetwork, MarketplaceInitialConfig marketplaceConfig, GethCompanionNodeInfo[] companionNodes) { - var interaction = marketplaceNetwork.StartInteraction(lifecycle.Log); + var interaction = marketplaceNetwork.StartInteraction(); var tokenAddress = marketplaceNetwork.Marketplace.TokenAddress; foreach (var node in companionNodes) diff --git a/DistTestCore/Marketplace/CodexContractsStarter.cs b/DistTestCore/Marketplace/CodexContractsStarter.cs index cb2c414..cbb4862 100644 --- a/DistTestCore/Marketplace/CodexContractsStarter.cs +++ b/DistTestCore/Marketplace/CodexContractsStarter.cs @@ -34,7 +34,7 @@ namespace DistTestCore.Marketplace var marketplaceAddress = extractor.ExtractMarketplaceAddress(); var abi = extractor.ExtractMarketplaceAbi(); - var interaction = bootstrapNode.StartInteraction(lifecycle.Log); + var interaction = bootstrapNode.StartInteraction(); var tokenAddress = interaction.GetTokenAddress(marketplaceAddress); LogEnd("Contracts deployed."); diff --git a/DistTestCore/Marketplace/GethBootstrapNodeInfo.cs b/DistTestCore/Marketplace/GethBootstrapNodeInfo.cs index 0ea4c69..bfc8440 100644 --- a/DistTestCore/Marketplace/GethBootstrapNodeInfo.cs +++ b/DistTestCore/Marketplace/GethBootstrapNodeInfo.cs @@ -1,5 +1,4 @@ using KubernetesWorkflow; -using Logging; using NethereumWorkflow; namespace DistTestCore.Marketplace @@ -21,14 +20,14 @@ namespace DistTestCore.Marketplace public string PrivateKey { get; } public Port DiscoveryPort { get; } - public NethereumInteraction StartInteraction(TestLog log) + public NethereumInteraction StartInteraction() { var ip = RunningContainers.RunningPod.Cluster.IP; var port = RunningContainers.Containers[0].ServicePorts[0].Number; var account = Account; var privateKey = PrivateKey; - var creator = new NethereumInteractionCreator(log, ip, port, account, privateKey); + var creator = new NethereumInteractionCreator(ip, port, account, privateKey); return creator.CreateWorkflow(); } } diff --git a/DistTestCore/Marketplace/GethCompanionNodeInfo.cs b/DistTestCore/Marketplace/GethCompanionNodeInfo.cs index 3657059..6fbcd2b 100644 --- a/DistTestCore/Marketplace/GethCompanionNodeInfo.cs +++ b/DistTestCore/Marketplace/GethCompanionNodeInfo.cs @@ -1,5 +1,4 @@ using KubernetesWorkflow; -using Logging; using NethereumWorkflow; namespace DistTestCore.Marketplace @@ -17,14 +16,14 @@ namespace DistTestCore.Marketplace public string Account { get; } public string PrivateKey { get; } - public NethereumInteraction StartInteraction(TestLog log) + public NethereumInteraction StartInteraction() { var ip = RunningContainer.Pod.Cluster.IP; var port = RunningContainer.ServicePorts[0].Number; var account = Account; var privateKey = PrivateKey; - var creator = new NethereumInteractionCreator(log, ip, port, account, privateKey); + var creator = new NethereumInteractionCreator(ip, port, account, privateKey); return creator.CreateWorkflow(); } } diff --git a/DistTestCore/Marketplace/GethCompanionNodeStarter.cs b/DistTestCore/Marketplace/GethCompanionNodeStarter.cs index ad61a9d..133bdac 100644 --- a/DistTestCore/Marketplace/GethCompanionNodeStarter.cs +++ b/DistTestCore/Marketplace/GethCompanionNodeStarter.cs @@ -43,7 +43,7 @@ namespace DistTestCore.Marketplace { try { - var interaction = node.StartInteraction(lifecycle.Log); + var interaction = node.StartInteraction(); interaction.EnsureSynced(marketplace.Marketplace.Address, marketplace.Marketplace.Abi); } catch (Exception e) diff --git a/DistTestCore/Marketplace/MarketplaceAccess.cs b/DistTestCore/Marketplace/MarketplaceAccess.cs index e77635e..42ea1f4 100644 --- a/DistTestCore/Marketplace/MarketplaceAccess.cs +++ b/DistTestCore/Marketplace/MarketplaceAccess.cs @@ -103,7 +103,7 @@ namespace DistTestCore.Marketplace public TestToken GetBalance() { - var interaction = marketplaceNetwork.StartInteraction(log); + var interaction = marketplaceNetwork.StartInteraction(); var account = companionNode.Account; var amount = interaction.GetBalance(marketplaceNetwork.Marketplace.TokenAddress, account); var balance = new TestToken(amount); diff --git a/DistTestCore/Marketplace/MarketplaceNetwork.cs b/DistTestCore/Marketplace/MarketplaceNetwork.cs index 5f43fa9..edd3fa3 100644 --- a/DistTestCore/Marketplace/MarketplaceNetwork.cs +++ b/DistTestCore/Marketplace/MarketplaceNetwork.cs @@ -1,5 +1,4 @@ -using Logging; -using NethereumWorkflow; +using NethereumWorkflow; namespace DistTestCore.Marketplace { @@ -14,9 +13,9 @@ namespace DistTestCore.Marketplace public GethBootstrapNodeInfo Bootstrap { get; } public MarketplaceInfo Marketplace { get; } - public NethereumInteraction StartInteraction(TestLog log) + public NethereumInteraction StartInteraction() { - return Bootstrap.StartInteraction(log); + return Bootstrap.StartInteraction(); } } } diff --git a/Nethereum/NethereumInteraction.cs b/Nethereum/NethereumInteraction.cs index 18823de..ba550b8 100644 --- a/Nethereum/NethereumInteraction.cs +++ b/Nethereum/NethereumInteraction.cs @@ -1,5 +1,4 @@ -using Logging; -using Nethereum.ABI.FunctionEncoding.Attributes; +using Nethereum.ABI.FunctionEncoding.Attributes; using Nethereum.Contracts; using Nethereum.Hex.HexTypes; using Nethereum.Web3; @@ -11,13 +10,11 @@ namespace NethereumWorkflow public class NethereumInteraction { private readonly List openTasks = new List(); - private readonly TestLog log; private readonly Web3 web3; private readonly string rootAccount; - internal NethereumInteraction(TestLog log, Web3 web3, string rootAccount) + internal NethereumInteraction(Web3 web3, string rootAccount) { - this.log = log; this.web3 = web3; this.rootAccount = rootAccount; } @@ -73,31 +70,30 @@ namespace NethereumWorkflow } public void EnsureSynced(string marketplaceAddress, string marketplaceAbi) + { + WaitUntilSynced(); + WaitForContract(marketplaceAddress, marketplaceAbi); + } + + private void WaitUntilSynced() { Time.WaitUntil(() => { - return !Time.Wait(web3.Eth.Syncing.SendRequestAsync()).IsSyncing; + var sync = Time.Wait(web3.Eth.Syncing.SendRequestAsync()); + var number = Time.Wait(web3.Eth.Blocks.GetBlockNumber.SendRequestAsync()); + var numberOfBlocks = ToDecimal(number); + return !sync.IsSyncing && numberOfBlocks > 256; + }, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(1)); + } - + private void WaitForContract(string marketplaceAddress, string marketplaceAbi) + { Time.WaitUntil(() => { try { var contract = web3.Eth.GetContract(marketplaceAbi, marketplaceAddress); - - if (contract != null) - { - var aaa = 0; - - var func = contract.GetFunction("myRequests"); - var input = func.CreateCallInput(); - var result = Time.Wait(func.CallAsync(input)); - - var eeee = 0; - } - - return contract != null; } catch @@ -105,8 +101,6 @@ namespace NethereumWorkflow return false; } }, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(1)); - - Thread.Sleep(TimeSpan.FromMinutes(2)); } private HexBigInteger ToHexBig(decimal amount) @@ -121,6 +115,11 @@ namespace NethereumWorkflow return new BigInteger(amount); } + private decimal ToDecimal(HexBigInteger hexBigInteger) + { + return ToDecimal(hexBigInteger.Value); + } + private decimal ToDecimal(BigInteger bigInteger) { return (decimal)bigInteger; diff --git a/Nethereum/NethereumInteractionCreator.cs b/Nethereum/NethereumInteractionCreator.cs index 3695fa1..654a0bd 100644 --- a/Nethereum/NethereumInteractionCreator.cs +++ b/Nethereum/NethereumInteractionCreator.cs @@ -1,19 +1,16 @@ -using Logging; -using Nethereum.Web3; +using Nethereum.Web3; namespace NethereumWorkflow { public class NethereumInteractionCreator { - private readonly TestLog log; private readonly string ip; private readonly int port; private readonly string rootAccount; private readonly string privateKey; - public NethereumInteractionCreator(TestLog log, string ip, int port, string rootAccount, string privateKey) + public NethereumInteractionCreator(string ip, int port, string rootAccount, string privateKey) { - this.log = log; this.ip = ip; this.port = port; this.rootAccount = rootAccount; @@ -22,7 +19,7 @@ namespace NethereumWorkflow public NethereumInteraction CreateWorkflow() { - return new NethereumInteraction(log, CreateWeb3(), rootAccount); + return new NethereumInteraction(CreateWeb3(), rootAccount); } private Web3 CreateWeb3()