Can fetch storage requests from chain

This commit is contained in:
benbierens 2023-12-20 10:55:29 +01:00
parent 2be31a4d3b
commit 75757e37fb
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
5 changed files with 35 additions and 9 deletions

View File

@ -1,7 +1,6 @@
using Logging; using Logging;
using Nethereum.RPC.Eth.DTOs; using Nethereum.RPC.Eth.DTOs;
using Nethereum.Web3; using Nethereum.Web3;
using Org.BouncyCastle.Asn1.X509;
using Utils; using Utils;
namespace NethereumWorkflow namespace NethereumWorkflow

View File

@ -1,4 +1,5 @@
using GethPlugin; using CodexContractsPlugin.Marketplace;
using GethPlugin;
using Logging; using Logging;
using Utils; using Utils;
@ -14,7 +15,7 @@ namespace CodexContractsPlugin
TestToken GetTestTokenBalance(IHasEthAddress owner); TestToken GetTestTokenBalance(IHasEthAddress owner);
TestToken GetTestTokenBalance(EthAddress ethAddress); TestToken GetTestTokenBalance(EthAddress ethAddress);
void GetStorageRequests(TimeRange range); Request[] GetStorageRequests(TimeRange range);
} }
public class CodexContractsAccess : ICodexContracts public class CodexContractsAccess : ICodexContracts
@ -57,10 +58,14 @@ namespace CodexContractsPlugin
return balance.TestTokens(); return balance.TestTokens();
} }
public void GetStorageRequests(TimeRange timeRange) public Request[] GetStorageRequests(TimeRange timeRange)
{ {
var events = gethNode.GetEvents<Marketplace.StorageRequestedEventDTO>(Deployment.MarketplaceAddress, timeRange); var events = gethNode.GetEvents<StorageRequestedEventDTO>(Deployment.MarketplaceAddress, timeRange);
var iii = 0; var i = StartInteraction();
return events
.Select(e => i.GetRequest(Deployment.MarketplaceAddress, e.Event.RequestId))
.Select(r => r.ReturnValue1)
.ToArray();
} }
private ContractInteractions StartInteraction() private ContractInteractions StartInteraction()

View File

@ -1,7 +1,9 @@
using GethPlugin; using CodexContractsPlugin.Marketplace;
using GethPlugin;
using Logging; using Logging;
using Nethereum.ABI.FunctionEncoding.Attributes; using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts; using Nethereum.Contracts;
using Nethereum.Hex.HexConvertors.Extensions;
using NethereumWorkflow; using NethereumWorkflow;
using System.Numerics; using System.Numerics;
@ -59,6 +61,17 @@ namespace CodexContractsPlugin
return gethNode.Call<GetTokenBalanceFunction, BigInteger>(tokenAddress, function).ToDecimal(); return gethNode.Call<GetTokenBalanceFunction, BigInteger>(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<GetRequestFunction, GetRequestOutputDTO>(marketplaceAddress, func);
}
public bool IsSynced(string marketplaceAddress, string marketplaceAbi) public bool IsSynced(string marketplaceAddress, string marketplaceAbi)
{ {
log.Debug(); log.Debug();

View File

@ -88,6 +88,12 @@ namespace CodexTests.BasicTests
purchaseContract.WaitForStorageContractStarted(fileSize); 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."); AssertBalance(contracts, seller, Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
purchaseContract.WaitForStorageContractFinished(); purchaseContract.WaitForStorageContractFinished();
@ -96,8 +102,6 @@ namespace CodexTests.BasicTests
AssertBalance(contracts, buyer, Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage."); AssertBalance(contracts, buyer, Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage.");
//CheckLogForErrors(seller, buyer); //CheckLogForErrors(seller, buyer);
contracts.GetStorageRequests(new TimeRange(Get().TestStart, DateTime.UtcNow));
} }
[Test] [Test]

View File

@ -143,6 +143,11 @@ namespace DistTestCore
Stopwatch.Measure(Get().Log, name, action); Stopwatch.Measure(Get().Log, name, action);
} }
protected TimeRange GetTestRunTimeRange()
{
return new TimeRange(Get().TestStart, DateTime.UtcNow);
}
protected virtual void Initialize(FixtureLog fixtureLog) protected virtual void Initialize(FixtureLog fixtureLog)
{ {
} }