diff --git a/Tests/CodexTests/UtilityTests/DiscordBotTests.cs b/Tests/CodexTests/UtilityTests/DiscordBotTests.cs index 29403eb..e9dba30 100644 --- a/Tests/CodexTests/UtilityTests/DiscordBotTests.cs +++ b/Tests/CodexTests/UtilityTests/DiscordBotTests.cs @@ -1,4 +1,5 @@ using CodexContractsPlugin; +using CodexContractsPlugin.Marketplace; using CodexDiscordBotPlugin; using CodexPlugin; using Core; @@ -8,6 +9,7 @@ using KubernetesWorkflow.Types; using Logging; using Newtonsoft.Json; using NUnit.Framework; +using TestNetRewarder; using Utils; namespace CodexTests.UtilityTests @@ -301,28 +303,29 @@ namespace CodexTests.UtilityTests private void ProcessLine(string line, Action log) { - // Processing chain state: ' - // NewRequests: [] - // FulfilledE: [] - // CancelledE: [] - // FilledE: [] - // FreedE: [] - // Historic: [{"Request":{"RequestId":"hvWlli4gHP5tUJoG5b8zh3tMBIr0wpcr/lHgIU/KRmU=","ClientAddress":{"Address":"0x760e722469cdeb086b78edd2b4b670621f43a923"},"Client":"0x760e722469Cdeb086b78EdD2b4b670621F43a923","Ask":{"Slots":4,"SlotSize":33554432,"Duration":360,"ProofProbability":5,"Reward":2,"Collateral":10,"MaxSlotLoss":2},"Content":{"Cid":"zDvZRwzm8DzbqdUcy7gS1wFKAsBjUHTQEUt1am1L6XGEWtsJ5U2X","MerkleRoot":"/KjFr+FezQ8m3huhdaPDy6zVgZs3ODtfE78K5eyieQo="},"Expiry":300,"Nonce":"2tANtfgVcMBuLLxe+4MbxMFWWO36Yv+l2yC4tpqdelI="},"Hosts":[{"Address":"0x0000000000000000000000000000000000000000"},{"Address":"0x0000000000000000000000000000000000000000"},{"Address":"0x0000000000000000000000000000000000000000"},{"Address":"0x0000000000000000000000000000000000000000"}],"State":"New"}] - // ' + //$"ChainState=[{JsonConvert.SerializeObject(this)}]" + + //$"HistoricState=[{historicState.EntireString()}]"; - if (!line.Contains("Processing chain state: ")) return; + var stateOpenTag = "ChainState=["; + var historicOpenTag = "]HistoricState=["; - log(Between(line, "'")); - //var tokens = state.Split("Historic: ", StringSplitOptions.RemoveEmptyEntries); - //var historics = JsonConvert.DeserializeObject(tokens[1]); + if (!line.Contains(stateOpenTag)) return; + if (!line.Contains(historicOpenTag)) return; - //log(tokens[0] + " historic: " + string.Join(",", historics!.Select(h => h.Request.RequestId + " = " + h.State))); + var stateStr = Between(line, stateOpenTag, historicOpenTag); + var historicStr = Between(line, historicOpenTag, "]"); + + var chainState = JsonConvert.DeserializeObject(stateStr); + var historicState = JsonConvert.DeserializeObject(historicStr)!; + chainState!.Set(new HistoricState(historicState)); + + log(string.Join(",", chainState!.GenerateOverview())); } - private string Between(string s, string lim) + private string Between(string s, string open, string close) { - var start = s.IndexOf(lim) + lim.Length; - var end = s.LastIndexOf(lim); + var start = s.IndexOf(open) + open.Length; + var end = s.LastIndexOf(close); return s.Substring(start, end - start); } } diff --git a/Tools/TestNetRewarder/ChainState.cs b/Tools/TestNetRewarder/ChainState.cs index 50b2501..50fa87d 100644 --- a/Tools/TestNetRewarder/ChainState.cs +++ b/Tools/TestNetRewarder/ChainState.cs @@ -8,7 +8,7 @@ namespace TestNetRewarder { public class ChainState { - private readonly HistoricState historicState; + private HistoricState historicState; private readonly string[] colorIcons = new[] { "🔴", @@ -50,9 +50,30 @@ namespace TestNetRewarder SlotFreedEvents = contracts.GetSlotFreedEvents(blockRange); } + public ChainState( + Request[] newRequests, + RequestFulfilledEventDTO[] requestFulfilledEvents, + RequestCancelledEventDTO[] requestCancelledEvents, + SlotFilledEventDTO[] slotFilledEvents, + SlotFreedEventDTO[] slotFreedEvents) + { + NewRequests = newRequests; + RequestFulfilledEvents = requestFulfilledEvents; + RequestCancelledEvents = requestCancelledEvents; + SlotFilledEvents = slotFilledEvents; + SlotFreedEvents = slotFreedEvents; + + historicState = new HistoricState(); + StartedRequests = Array.Empty(); + FinishedRequests = Array.Empty(); + } + public Request[] NewRequests { get; } + [JsonIgnore] public StorageRequest[] AllRequests => historicState.StorageRequests; + [JsonIgnore] public StorageRequest[] StartedRequests { get; private set; } + [JsonIgnore] public StorageRequest[] FinishedRequests { get; private set; } public RequestFulfilledEventDTO[] RequestFulfilledEvents { get; } public RequestCancelledEventDTO[] RequestCancelledEvents { get; } @@ -62,12 +83,13 @@ namespace TestNetRewarder public string EntireString() { return - $"NewRequests: {JsonConvert.SerializeObject(NewRequests)}" + - $"FulfilledE: {JsonConvert.SerializeObject(RequestFulfilledEvents)}" + - $"CancelledE: {JsonConvert.SerializeObject(RequestCancelledEvents)}" + - $"FilledE: {JsonConvert.SerializeObject(SlotFilledEvents)}" + - $"FreedE: {JsonConvert.SerializeObject(SlotFreedEvents)}" + - $"Historic: {historicState.EntireString()}"; + $"ChainState=[{JsonConvert.SerializeObject(this)}]" + + $"HistoricState=[{historicState.EntireString()}]"; + } + + public void Set(HistoricState h) + { + historicState = h; } public string[] GenerateOverview() diff --git a/Tools/TestNetRewarder/HistoricState.cs b/Tools/TestNetRewarder/HistoricState.cs index 3ae5882..8487aa0 100644 --- a/Tools/TestNetRewarder/HistoricState.cs +++ b/Tools/TestNetRewarder/HistoricState.cs @@ -34,6 +34,15 @@ namespace TestNetRewarder { return JsonConvert.SerializeObject(StorageRequests); } + + public HistoricState() + { + } + + public HistoricState(StorageRequest[] requests) + { + storageRequests.AddRange(requests); + } } public class StorageRequest diff --git a/Tools/TestNetRewarder/Processor.cs b/Tools/TestNetRewarder/Processor.cs index a756b93..678d4f8 100644 --- a/Tools/TestNetRewarder/Processor.cs +++ b/Tools/TestNetRewarder/Processor.cs @@ -58,7 +58,7 @@ namespace TestNetRewarder private async Task ProcessChainState(ChainState chainState) { - log.Log($"Processing chain state: '{chainState.EntireString()}'"); + log.Log(chainState.EntireString()); var outgoingRewards = new List(); foreach (var reward in rewardRepo.Rewards)