This commit is contained in:
benbierens 2024-06-21 09:18:00 +02:00
parent f9c7e18985
commit 2b7ba61543
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
2 changed files with 21 additions and 27 deletions

View File

@ -50,6 +50,7 @@ namespace CodexDiscordBotPlugin
startupConfig.Add(config);
var pod = workflow.Start(1, new DiscordBotContainerRecipe(), startupConfig).WaitForOnline();
WaitForStartupMessage(workflow, pod);
workflow.CreateCrashWatcher(pod.Containers.Single()).Start();
return pod;
}
@ -58,7 +59,9 @@ namespace CodexDiscordBotPlugin
var startupConfig = new StartupConfig();
startupConfig.NameOverride = config.Name;
startupConfig.Add(config);
return workflow.Start(1, new RewarderBotContainerRecipe(), startupConfig).WaitForOnline();
var pod = workflow.Start(1, new RewarderBotContainerRecipe(), startupConfig).WaitForOnline();
workflow.CreateCrashWatcher(pod.Containers.Single()).Start();
return pod;
}
private void WaitForStartupMessage(IStartupWorkflow workflow, RunningPod pod)

View File

@ -1,5 +1,4 @@
using CodexContractsPlugin;
using CodexContractsPlugin.ChainMonitor;
using CodexDiscordBotPlugin;
using CodexPlugin;
using Core;
@ -24,7 +23,9 @@ namespace CodexTests.UtilityTests
private readonly List<EthAccount> hostAccounts = new List<EthAccount>();
private readonly List<ulong> rewardsSeen = new List<ulong>();
private readonly TimeSpan rewarderInterval = TimeSpan.FromMinutes(1);
private readonly List<string> receivedEvents = new List<string>();
private readonly List<MarketAverage> receivedAverages = new List<MarketAverage>();
[Test]
[DontDownloadLogs]
public void BotRewardTest()
@ -39,37 +40,20 @@ namespace CodexTests.UtilityTests
StartHosts(geth, contracts);
var client = StartClient(geth, contracts);
//var chainState = new ChainState(GetTestLog(), contracts, new DoNothingChainEventHandler(), GetTestRunTimeRange().From);
//var running = true;
//var task = Task.Run(() =>
//{
// while (running)
// {
// Thread.Sleep(TimeSpan.FromMinutes(1));
// chainState.Update();
// }
//});
var apiCalls = new RewardApiCalls(GetTestLog(), Ci, botContainer);
apiCalls.Start(OnCommand);
var purchaseContract = ClientPurchasesStorage(client);
//chainState.Update();
//Assert.That(chainState.Requests.Length, Is.EqualTo(1));
purchaseContract.WaitForStorageContractStarted();
//chainState.Update();
purchaseContract.WaitForStorageContractFinished();
Thread.Sleep(rewarderInterval * 3);
//running = false;
//task.Wait();
apiCalls.Stop();
//chainState.Update();
Assert.That(receivedEvents.Count(e => e.Contains("Created as New.")), Is.EqualTo(1));
Assert.That(receivedEvents.Count(e => e.Contains("SlotFilled")), Is.EqualTo(GetNumberOfRequiredHosts()));
Assert.That(receivedEvents.Count(e => e.Contains("Transit: New -> Started")), Is.EqualTo(1));
Assert.That(receivedEvents.Count(e => e.Contains("Transit: Started -> Finished")), Is.EqualTo(1));
foreach (var r in repo.Rewards)
{
@ -90,10 +74,12 @@ namespace CodexTests.UtilityTests
private void OnCommand(string timestamp, GiveRewardsCommand call)
{
Log($"<API call {timestamp}>");
receivedAverages.AddRange(call.Averages);
foreach (var a in call.Averages)
{
Log("\tAverage: " + JsonConvert.SerializeObject(a));
}
receivedEvents.AddRange(call.EventsOverview);
foreach (var e in call.EventsOverview)
{
Log("\tEvent: " + e);
@ -122,8 +108,8 @@ namespace CodexTests.UtilityTests
MinRequiredNumberOfNodes = GetNumberOfRequiredHosts(),
NodeFailureTolerance = 2,
ProofProbability = 5,
Duration = TimeSpan.FromMinutes(6),
Expiry = TimeSpan.FromMinutes(5)
Duration = GetMinRequiredRequestDuration(),
Expiry = GetMinRequiredRequestDuration() - TimeSpan.FromMinutes(1)
};
return client.Marketplace.RequestStorage(purchase);
@ -245,6 +231,11 @@ namespace CodexTests.UtilityTests
return Convert.ToUInt32(repo.Rewards.Max(r => r.CheckConfig.MinNumberOfHosts));
}
private TimeSpan GetMinRequiredRequestDuration()
{
return repo.Rewards.Max(r => r.CheckConfig.MinDuration) + TimeSpan.FromSeconds(10);
}
private string IdentifyAccount(string address)
{
if (address == clientAccount.EthAddress.Address) return "Client";