From 75757e37fbd267db2395cdd89d2527c3b5c2372c Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 20 Dec 2023 10:55:29 +0100 Subject: [PATCH] Can fetch storage requests from chain --- Framework/NethereumWorkflow/BlockTimeFinder.cs | 1 - .../CodexContractsPlugin/CodexContractsAccess.cs | 15 ++++++++++----- .../CodexContractsPlugin/ContractInteractions.cs | 15 ++++++++++++++- Tests/CodexTests/BasicTests/ExampleTests.cs | 8 ++++++-- Tests/DistTestCore/DistTest.cs | 5 +++++ 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Framework/NethereumWorkflow/BlockTimeFinder.cs b/Framework/NethereumWorkflow/BlockTimeFinder.cs index 3f39c26..9f6481e 100644 --- a/Framework/NethereumWorkflow/BlockTimeFinder.cs +++ b/Framework/NethereumWorkflow/BlockTimeFinder.cs @@ -1,7 +1,6 @@ using Logging; using Nethereum.RPC.Eth.DTOs; using Nethereum.Web3; -using Org.BouncyCastle.Asn1.X509; using Utils; namespace NethereumWorkflow diff --git a/ProjectPlugins/CodexContractsPlugin/CodexContractsAccess.cs b/ProjectPlugins/CodexContractsPlugin/CodexContractsAccess.cs index b111492..d6813b4 100644 --- a/ProjectPlugins/CodexContractsPlugin/CodexContractsAccess.cs +++ b/ProjectPlugins/CodexContractsPlugin/CodexContractsAccess.cs @@ -1,4 +1,5 @@ -using GethPlugin; +using CodexContractsPlugin.Marketplace; +using GethPlugin; using Logging; using Utils; @@ -14,7 +15,7 @@ namespace CodexContractsPlugin TestToken GetTestTokenBalance(IHasEthAddress owner); TestToken GetTestTokenBalance(EthAddress ethAddress); - void GetStorageRequests(TimeRange range); + Request[] GetStorageRequests(TimeRange range); } public class CodexContractsAccess : ICodexContracts @@ -57,10 +58,14 @@ namespace CodexContractsPlugin return balance.TestTokens(); } - public void GetStorageRequests(TimeRange timeRange) + public Request[] GetStorageRequests(TimeRange timeRange) { - var events = gethNode.GetEvents(Deployment.MarketplaceAddress, timeRange); - var iii = 0; + var events = gethNode.GetEvents(Deployment.MarketplaceAddress, timeRange); + var i = StartInteraction(); + return events + .Select(e => i.GetRequest(Deployment.MarketplaceAddress, e.Event.RequestId)) + .Select(r => r.ReturnValue1) + .ToArray(); } private ContractInteractions StartInteraction() diff --git a/ProjectPlugins/CodexContractsPlugin/ContractInteractions.cs b/ProjectPlugins/CodexContractsPlugin/ContractInteractions.cs index 4af2ac6..93045db 100644 --- a/ProjectPlugins/CodexContractsPlugin/ContractInteractions.cs +++ b/ProjectPlugins/CodexContractsPlugin/ContractInteractions.cs @@ -1,7 +1,9 @@ -using GethPlugin; +using CodexContractsPlugin.Marketplace; +using GethPlugin; using Logging; using Nethereum.ABI.FunctionEncoding.Attributes; using Nethereum.Contracts; +using Nethereum.Hex.HexConvertors.Extensions; using NethereumWorkflow; using System.Numerics; @@ -59,6 +61,17 @@ namespace CodexContractsPlugin return gethNode.Call(tokenAddress, function).ToDecimal(); } + public GetRequestOutputDTO GetRequest(string marketplaceAddress, byte[] requestId) + { + + log.Debug($"({marketplaceAddress}) {requestId.ToHex(true)}"); + var func = new GetRequestFunction + { + RequestId = requestId + }; + return gethNode.Call(marketplaceAddress, func); + } + public bool IsSynced(string marketplaceAddress, string marketplaceAbi) { log.Debug(); diff --git a/Tests/CodexTests/BasicTests/ExampleTests.cs b/Tests/CodexTests/BasicTests/ExampleTests.cs index 59993dd..9b39af3 100644 --- a/Tests/CodexTests/BasicTests/ExampleTests.cs +++ b/Tests/CodexTests/BasicTests/ExampleTests.cs @@ -88,6 +88,12 @@ namespace CodexTests.BasicTests purchaseContract.WaitForStorageContractStarted(fileSize); + var requests = contracts.GetStorageRequests(GetTestRunTimeRange()); + Assert.That(requests.Length, Is.EqualTo(1)); + var request = requests.Single(); + Assert.That(request.Client, Is.EqualTo(buyer.EthAddress.Address)); + Assert.That(request.Ask.Slots, Is.EqualTo(1)); + AssertBalance(contracts, seller, Is.LessThan(sellerInitialBalance), "Collateral was not placed."); purchaseContract.WaitForStorageContractFinished(); @@ -96,8 +102,6 @@ namespace CodexTests.BasicTests AssertBalance(contracts, buyer, Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage."); //CheckLogForErrors(seller, buyer); - - contracts.GetStorageRequests(new TimeRange(Get().TestStart, DateTime.UtcNow)); } [Test] diff --git a/Tests/DistTestCore/DistTest.cs b/Tests/DistTestCore/DistTest.cs index 06014e0..5237bbc 100644 --- a/Tests/DistTestCore/DistTest.cs +++ b/Tests/DistTestCore/DistTest.cs @@ -143,6 +143,11 @@ namespace DistTestCore Stopwatch.Measure(Get().Log, name, action); } + protected TimeRange GetTestRunTimeRange() + { + return new TimeRange(Get().TestStart, DateTime.UtcNow); + } + protected virtual void Initialize(FixtureLog fixtureLog) { }