Applies blockInterval
This commit is contained in:
parent
330552563c
commit
01d6b8f227
@ -89,26 +89,9 @@ namespace NethereumWorkflow
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EventLog<TEvent>> GetEvents<TEvent>(string address, TimeRange timeRange) where TEvent : IEventDTO, new()
|
public List<EventLog<TEvent>> GetEvents<TEvent>(string address, BlockInterval blockRange) where TEvent : IEventDTO, new()
|
||||||
{
|
{
|
||||||
var wrapper = new Web3Wrapper(web3, log);
|
return GetEvents<TEvent>(address, blockRange.From, blockRange.To);
|
||||||
var blockTimeFinder = new BlockTimeFinder(blockCache, wrapper, log);
|
|
||||||
|
|
||||||
var fromBlock = blockTimeFinder.GetLowestBlockNumberAfter(timeRange.From);
|
|
||||||
var toBlock = blockTimeFinder.GetHighestBlockNumberBefore(timeRange.To);
|
|
||||||
|
|
||||||
if (!fromBlock.HasValue)
|
|
||||||
{
|
|
||||||
log.Error("Failed to find lowest block for time range: " + timeRange);
|
|
||||||
throw new Exception("Failed");
|
|
||||||
}
|
|
||||||
if (!toBlock.HasValue)
|
|
||||||
{
|
|
||||||
log.Error("Failed to find highest block for time range: " + timeRange);
|
|
||||||
throw new Exception("Failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
return GetEvents<TEvent>(address, fromBlock.Value, toBlock.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EventLog<TEvent>> GetEvents<TEvent>(string address, ulong fromBlockNumber, ulong toBlockNumber) where TEvent : IEventDTO, new()
|
public List<EventLog<TEvent>> GetEvents<TEvent>(string address, ulong fromBlockNumber, ulong toBlockNumber) where TEvent : IEventDTO, new()
|
||||||
@ -119,5 +102,24 @@ namespace NethereumWorkflow
|
|||||||
var blockFilter = Time.Wait(eventHandler.CreateFilterBlockRangeAsync(from, to));
|
var blockFilter = Time.Wait(eventHandler.CreateFilterBlockRangeAsync(from, to));
|
||||||
return Time.Wait(eventHandler.GetAllChangesAsync(blockFilter));
|
return Time.Wait(eventHandler.GetAllChangesAsync(blockFilter));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockInterval ConvertTimeRangeToBlockRange(TimeRange timeRange)
|
||||||
|
{
|
||||||
|
var wrapper = new Web3Wrapper(web3, log);
|
||||||
|
var blockTimeFinder = new BlockTimeFinder(blockCache, wrapper, log);
|
||||||
|
|
||||||
|
var fromBlock = blockTimeFinder.GetLowestBlockNumberAfter(timeRange.From);
|
||||||
|
var toBlock = blockTimeFinder.GetHighestBlockNumberBefore(timeRange.To);
|
||||||
|
|
||||||
|
if (fromBlock == null || toBlock == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Failed to convert time range to block range.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BlockInterval(
|
||||||
|
from: fromBlock.Value,
|
||||||
|
to: toBlock.Value
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
public class BlockRange
|
public class BlockInterval
|
||||||
{
|
{
|
||||||
public BlockRange(ulong from, ulong to)
|
public BlockInterval(ulong from, ulong to)
|
||||||
{
|
{
|
||||||
if (from < to)
|
if (from < to)
|
||||||
{
|
{
|
@ -19,13 +19,13 @@ namespace CodexContractsPlugin
|
|||||||
TestToken GetTestTokenBalance(IHasEthAddress owner);
|
TestToken GetTestTokenBalance(IHasEthAddress owner);
|
||||||
TestToken GetTestTokenBalance(EthAddress ethAddress);
|
TestToken GetTestTokenBalance(EthAddress ethAddress);
|
||||||
|
|
||||||
Request[] GetStorageRequests(BlockRange blockRange);
|
Request[] GetStorageRequests(BlockInterval blockRange);
|
||||||
EthAddress? GetSlotHost(Request storageRequest, decimal slotIndex);
|
EthAddress? GetSlotHost(Request storageRequest, decimal slotIndex);
|
||||||
RequestState GetRequestState(Request request);
|
RequestState GetRequestState(Request request);
|
||||||
RequestFulfilledEventDTO[] GetRequestFulfilledEvents(BlockRange blockRange);
|
RequestFulfilledEventDTO[] GetRequestFulfilledEvents(BlockInterval blockRange);
|
||||||
RequestCancelledEventDTO[] GetRequestCancelledEvents(BlockRange blockRange);
|
RequestCancelledEventDTO[] GetRequestCancelledEvents(BlockInterval blockRange);
|
||||||
SlotFilledEventDTO[] GetSlotFilledEvents(BlockRange blockRange);
|
SlotFilledEventDTO[] GetSlotFilledEvents(BlockInterval blockRange);
|
||||||
SlotFreedEventDTO[] GetSlotFreedEvents(BlockRange blockRange);
|
SlotFreedEventDTO[] GetSlotFreedEvents(BlockInterval blockRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum RequestState
|
public enum RequestState
|
||||||
@ -77,7 +77,7 @@ namespace CodexContractsPlugin
|
|||||||
return balance.TestTokens();
|
return balance.TestTokens();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request[] GetStorageRequests(BlockRange blockRange)
|
public Request[] GetStorageRequests(BlockInterval blockRange)
|
||||||
{
|
{
|
||||||
var events = gethNode.GetEvents<StorageRequestedEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
var events = gethNode.GetEvents<StorageRequestedEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
||||||
var i = StartInteraction();
|
var i = StartInteraction();
|
||||||
@ -93,7 +93,7 @@ namespace CodexContractsPlugin
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestFulfilledEventDTO[] GetRequestFulfilledEvents(BlockRange blockRange)
|
public RequestFulfilledEventDTO[] GetRequestFulfilledEvents(BlockInterval blockRange)
|
||||||
{
|
{
|
||||||
var events = gethNode.GetEvents<RequestFulfilledEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
var events = gethNode.GetEvents<RequestFulfilledEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
||||||
return events.Select(e =>
|
return events.Select(e =>
|
||||||
@ -104,7 +104,7 @@ namespace CodexContractsPlugin
|
|||||||
}).ToArray();
|
}).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestCancelledEventDTO[] GetRequestCancelledEvents(BlockRange blockRange)
|
public RequestCancelledEventDTO[] GetRequestCancelledEvents(BlockInterval blockRange)
|
||||||
{
|
{
|
||||||
var events = gethNode.GetEvents<RequestCancelledEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
var events = gethNode.GetEvents<RequestCancelledEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
||||||
return events.Select(e =>
|
return events.Select(e =>
|
||||||
@ -115,7 +115,7 @@ namespace CodexContractsPlugin
|
|||||||
}).ToArray();
|
}).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SlotFilledEventDTO[] GetSlotFilledEvents(BlockRange blockRange)
|
public SlotFilledEventDTO[] GetSlotFilledEvents(BlockInterval blockRange)
|
||||||
{
|
{
|
||||||
var events = gethNode.GetEvents<SlotFilledEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
var events = gethNode.GetEvents<SlotFilledEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
||||||
return events.Select(e =>
|
return events.Select(e =>
|
||||||
@ -127,7 +127,7 @@ namespace CodexContractsPlugin
|
|||||||
}).ToArray();
|
}).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SlotFreedEventDTO[] GetSlotFreedEvents(BlockRange blockRange)
|
public SlotFreedEventDTO[] GetSlotFreedEvents(BlockInterval blockRange)
|
||||||
{
|
{
|
||||||
var events = gethNode.GetEvents<SlotFreedEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
var events = gethNode.GetEvents<SlotFreedEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
||||||
return events.Select(e =>
|
return events.Select(e =>
|
||||||
|
@ -6,7 +6,6 @@ using Nethereum.Contracts;
|
|||||||
using Nethereum.RPC.Eth.DTOs;
|
using Nethereum.RPC.Eth.DTOs;
|
||||||
using NethereumWorkflow;
|
using NethereumWorkflow;
|
||||||
using Utils;
|
using Utils;
|
||||||
using BlockRange = Utils.BlockRange;
|
|
||||||
|
|
||||||
namespace GethPlugin
|
namespace GethPlugin
|
||||||
{
|
{
|
||||||
@ -25,9 +24,9 @@ namespace GethPlugin
|
|||||||
decimal? GetSyncedBlockNumber();
|
decimal? GetSyncedBlockNumber();
|
||||||
bool IsContractAvailable(string abi, string contractAddress);
|
bool IsContractAvailable(string abi, string contractAddress);
|
||||||
GethBootstrapNode GetBootstrapRecord();
|
GethBootstrapNode GetBootstrapRecord();
|
||||||
List<EventLog<TEvent>> GetEvents<TEvent>(string address, BlockRange blockRange) where TEvent : IEventDTO, new();
|
List<EventLog<TEvent>> GetEvents<TEvent>(string address, BlockInterval blockRange) where TEvent : IEventDTO, new();
|
||||||
List<EventLog<TEvent>> GetEvents<TEvent>(string address, TimeRange timeRange) where TEvent : IEventDTO, new();
|
List<EventLog<TEvent>> GetEvents<TEvent>(string address, TimeRange timeRange) where TEvent : IEventDTO, new();
|
||||||
BlockRange ConvertTimeRangeToBlockRange(TimeRange timeRange);
|
BlockInterval ConvertTimeRangeToBlockRange(TimeRange timeRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeploymentGethNode : BaseGethNode, IGethNode
|
public class DeploymentGethNode : BaseGethNode, IGethNode
|
||||||
@ -146,17 +145,17 @@ namespace GethPlugin
|
|||||||
return StartInteraction().IsContractAvailable(abi, contractAddress);
|
return StartInteraction().IsContractAvailable(abi, contractAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EventLog<TEvent>> GetEvents<TEvent>(string address, BlockRange blockRange) where TEvent : IEventDTO, new()
|
public List<EventLog<TEvent>> GetEvents<TEvent>(string address, BlockInterval blockRange) where TEvent : IEventDTO, new()
|
||||||
{
|
{
|
||||||
return StartInteraction().GetEvents<TEvent>(address, blockRange);
|
return StartInteraction().GetEvents<TEvent>(address, blockRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EventLog<TEvent>> GetEvents<TEvent>(string address, TimeRange timeRange) where TEvent : IEventDTO, new()
|
public List<EventLog<TEvent>> GetEvents<TEvent>(string address, TimeRange timeRange) where TEvent : IEventDTO, new()
|
||||||
{
|
{
|
||||||
return StartInteraction().GetEvents<TEvent>(address, timeRange);
|
return StartInteraction().GetEvents<TEvent>(address, ConvertTimeRangeToBlockRange(timeRange));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockRange ConvertTimeRangeToBlockRange(TimeRange timeRange)
|
public BlockInterval ConvertTimeRangeToBlockRange(TimeRange timeRange)
|
||||||
{
|
{
|
||||||
return StartInteraction().ConvertTimeRangeToBlockRange(timeRange);
|
return StartInteraction().ConvertTimeRangeToBlockRange(timeRange);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using CodexContractsPlugin;
|
using CodexContractsPlugin;
|
||||||
using CodexDiscordBotPlugin;
|
using CodexDiscordBotPlugin;
|
||||||
using CodexPlugin;
|
using CodexPlugin;
|
||||||
using DistTestCore;
|
|
||||||
using GethPlugin;
|
using GethPlugin;
|
||||||
using Nethereum.Hex.HexConvertors.Extensions;
|
using Nethereum.Hex.HexConvertors.Extensions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@ -110,9 +109,11 @@ namespace CodexTests.BasicTests
|
|||||||
|
|
||||||
AssertBalance(contracts, seller, Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
|
AssertBalance(contracts, seller, Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
|
||||||
|
|
||||||
var request = GetOnChainStorageRequest(contracts);
|
var blockRange = geth.ConvertTimeRangeToBlockRange(GetTestRunTimeRange());
|
||||||
|
|
||||||
|
var request = GetOnChainStorageRequest(contracts, blockRange);
|
||||||
AssertStorageRequest(request, purchase, contracts, buyer);
|
AssertStorageRequest(request, purchase, contracts, buyer);
|
||||||
AssertSlotFilledEvents(contracts, purchase, request, seller);
|
AssertSlotFilledEvents(contracts, purchase, request, seller, blockRange);
|
||||||
AssertContractSlot(contracts, request, 0, seller);
|
AssertContractSlot(contracts, request, 0, seller);
|
||||||
|
|
||||||
purchaseContract.WaitForStorageContractFinished();
|
purchaseContract.WaitForStorageContractFinished();
|
||||||
@ -139,15 +140,15 @@ namespace CodexTests.BasicTests
|
|||||||
Assert.That(discN, Is.LessThan(bootN));
|
Assert.That(discN, Is.LessThan(bootN));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AssertSlotFilledEvents(ICodexContracts contracts, StoragePurchaseRequest purchase, Request request, ICodexNode seller)
|
private void AssertSlotFilledEvents(ICodexContracts contracts, StoragePurchaseRequest purchase, Request request, ICodexNode seller, BlockInterval blockRange)
|
||||||
{
|
{
|
||||||
// Expect 1 fulfilled event for the purchase.
|
// Expect 1 fulfilled event for the purchase.
|
||||||
var requestFulfilledEvents = contracts.GetRequestFulfilledEvents(GetTestRunTimeRange());
|
var requestFulfilledEvents = contracts.GetRequestFulfilledEvents(blockRange);
|
||||||
Assert.That(requestFulfilledEvents.Length, Is.EqualTo(1));
|
Assert.That(requestFulfilledEvents.Length, Is.EqualTo(1));
|
||||||
CollectionAssert.AreEqual(request.RequestId, requestFulfilledEvents[0].RequestId);
|
CollectionAssert.AreEqual(request.RequestId, requestFulfilledEvents[0].RequestId);
|
||||||
|
|
||||||
// Expect 1 filled-slot event for each slot in the purchase.
|
// Expect 1 filled-slot event for each slot in the purchase.
|
||||||
var filledSlotEvents = contracts.GetSlotFilledEvents(GetTestRunTimeRange());
|
var filledSlotEvents = contracts.GetSlotFilledEvents(blockRange);
|
||||||
Assert.That(filledSlotEvents.Length, Is.EqualTo(purchase.MinRequiredNumberOfNodes));
|
Assert.That(filledSlotEvents.Length, Is.EqualTo(purchase.MinRequiredNumberOfNodes));
|
||||||
for (var i = 0; i < purchase.MinRequiredNumberOfNodes; i++)
|
for (var i = 0; i < purchase.MinRequiredNumberOfNodes; i++)
|
||||||
{
|
{
|
||||||
@ -164,9 +165,9 @@ namespace CodexTests.BasicTests
|
|||||||
Assert.That(request.Ask.Slots, Is.EqualTo(purchase.MinRequiredNumberOfNodes));
|
Assert.That(request.Ask.Slots, Is.EqualTo(purchase.MinRequiredNumberOfNodes));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Request GetOnChainStorageRequest(ICodexContracts contracts)
|
private Request GetOnChainStorageRequest(ICodexContracts contracts, BlockInterval blockRange)
|
||||||
{
|
{
|
||||||
var requests = contracts.GetStorageRequests(GetTestRunTimeRange());
|
var requests = contracts.GetStorageRequests(blockRange);
|
||||||
Assert.That(requests.Length, Is.EqualTo(1));
|
Assert.That(requests.Length, Is.EqualTo(1));
|
||||||
return requests.Single();
|
return requests.Single();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using CodexContractsPlugin;
|
using CodexContractsPlugin;
|
||||||
using CodexContractsPlugin.Marketplace;
|
using CodexContractsPlugin.Marketplace;
|
||||||
using BlockRange = Utils.BlockRange;
|
using Utils;
|
||||||
|
|
||||||
namespace TestNetRewarder
|
namespace TestNetRewarder
|
||||||
{
|
{
|
||||||
@ -8,7 +8,7 @@ namespace TestNetRewarder
|
|||||||
{
|
{
|
||||||
private readonly HistoricState historicState;
|
private readonly HistoricState historicState;
|
||||||
|
|
||||||
public ChainState(HistoricState historicState, ICodexContracts contracts, BlockRange blockRange)
|
public ChainState(HistoricState historicState, ICodexContracts contracts, BlockInterval blockRange)
|
||||||
{
|
{
|
||||||
NewRequests = contracts.GetStorageRequests(blockRange);
|
NewRequests = contracts.GetStorageRequests(blockRange);
|
||||||
historicState.ProcessNewRequests(NewRequests);
|
historicState.ProcessNewRequests(NewRequests);
|
||||||
|
@ -11,7 +11,7 @@ namespace TestNetRewarder
|
|||||||
private static readonly HistoricState historicState = new HistoricState();
|
private static readonly HistoricState historicState = new HistoricState();
|
||||||
private static readonly RewardRepo rewardRepo = new RewardRepo();
|
private static readonly RewardRepo rewardRepo = new RewardRepo();
|
||||||
private readonly ILog log;
|
private readonly ILog log;
|
||||||
private BlockRange? lastBlockRange;
|
private BlockInterval? lastBlockRange;
|
||||||
|
|
||||||
public Processor(ILog log)
|
public Processor(ILog log)
|
||||||
{
|
{
|
||||||
@ -42,7 +42,7 @@ namespace TestNetRewarder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsNewBlockRange(BlockRange blockRange)
|
private bool IsNewBlockRange(BlockInterval blockRange)
|
||||||
{
|
{
|
||||||
if (lastBlockRange == null ||
|
if (lastBlockRange == null ||
|
||||||
lastBlockRange.From != blockRange.From ||
|
lastBlockRange.From != blockRange.From ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user