Fixes bot test contract
This commit is contained in:
parent
00fd2cebf9
commit
69aa3a998f
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
public class RewarderBotStartupConfig
|
public class RewarderBotStartupConfig
|
||||||
{
|
{
|
||||||
public RewarderBotStartupConfig(string discordBotHost, int discordBotPort, string intervalMinutes, DateTime historyStartUtc, DiscordBotGethInfo gethInfo, string? dataPath)
|
public RewarderBotStartupConfig(string discordBotHost, int discordBotPort, int intervalMinutes, DateTime historyStartUtc, DiscordBotGethInfo gethInfo, string? dataPath)
|
||||||
{
|
{
|
||||||
DiscordBotHost = discordBotHost;
|
DiscordBotHost = discordBotHost;
|
||||||
DiscordBotPort = discordBotPort;
|
DiscordBotPort = discordBotPort;
|
||||||
@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
public string DiscordBotHost { get; }
|
public string DiscordBotHost { get; }
|
||||||
public int DiscordBotPort { get; }
|
public int DiscordBotPort { get; }
|
||||||
public string IntervalMinutes { get; }
|
public int IntervalMinutes { get; }
|
||||||
public DateTime HistoryStartUtc { get; }
|
public DateTime HistoryStartUtc { get; }
|
||||||
public DiscordBotGethInfo GethInfo { get; }
|
public DiscordBotGethInfo GethInfo { get; }
|
||||||
public string? DataPath { get; set; }
|
public string? DataPath { get; set; }
|
||||||
|
@ -17,7 +17,7 @@ namespace CodexDiscordBotPlugin
|
|||||||
|
|
||||||
AddEnvVar("DISCORDBOTHOST", config.DiscordBotHost);
|
AddEnvVar("DISCORDBOTHOST", config.DiscordBotHost);
|
||||||
AddEnvVar("DISCORDBOTPORT", config.DiscordBotPort.ToString());
|
AddEnvVar("DISCORDBOTPORT", config.DiscordBotPort.ToString());
|
||||||
AddEnvVar("INTERVALMINUTES", config.IntervalMinutes);
|
AddEnvVar("INTERVALMINUTES", config.IntervalMinutes.ToString());
|
||||||
var offset = new DateTimeOffset(config.HistoryStartUtc);
|
var offset = new DateTimeOffset(config.HistoryStartUtc);
|
||||||
AddEnvVar("CHECKHISTORY", offset.ToUnixTimeSeconds().ToString());
|
AddEnvVar("CHECKHISTORY", offset.ToUnixTimeSeconds().ToString());
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ namespace CodexPlugin
|
|||||||
CrashWatcher CrashWatcher { get; }
|
CrashWatcher CrashWatcher { get; }
|
||||||
PodInfo GetPodInfo();
|
PodInfo GetPodInfo();
|
||||||
ITransferSpeeds TransferSpeeds { get; }
|
ITransferSpeeds TransferSpeeds { get; }
|
||||||
|
EthAccount EthAccount { get; }
|
||||||
void Stop(bool waitTillStopped);
|
void Stop(bool waitTillStopped);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,13 +31,13 @@ namespace CodexPlugin
|
|||||||
{
|
{
|
||||||
private const string UploadFailedMessage = "Unable to store block";
|
private const string UploadFailedMessage = "Unable to store block";
|
||||||
private readonly IPluginTools tools;
|
private readonly IPluginTools tools;
|
||||||
private readonly EthAddress? ethAddress;
|
private readonly EthAccount? ethAccount;
|
||||||
private readonly TransferSpeeds transferSpeeds;
|
private readonly TransferSpeeds transferSpeeds;
|
||||||
|
|
||||||
public CodexNode(IPluginTools tools, CodexAccess codexAccess, CodexNodeGroup group, IMarketplaceAccess marketplaceAccess, EthAddress? ethAddress)
|
public CodexNode(IPluginTools tools, CodexAccess codexAccess, CodexNodeGroup group, IMarketplaceAccess marketplaceAccess, EthAccount? ethAccount)
|
||||||
{
|
{
|
||||||
this.tools = tools;
|
this.tools = tools;
|
||||||
this.ethAddress = ethAddress;
|
this.ethAccount = ethAccount;
|
||||||
CodexAccess = codexAccess;
|
CodexAccess = codexAccess;
|
||||||
Group = group;
|
Group = group;
|
||||||
Marketplace = marketplaceAccess;
|
Marketplace = marketplaceAccess;
|
||||||
@ -66,8 +67,17 @@ namespace CodexPlugin
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (ethAddress == null) throw new Exception("Marketplace is not enabled for this Codex node. Please start it with the option '.EnableMarketplace(...)' to enable it.");
|
EnsureMarketplace();
|
||||||
return ethAddress;
|
return ethAccount!.EthAddress;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public EthAccount EthAccount
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
EnsureMarketplace();
|
||||||
|
return ethAccount!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,6 +207,11 @@ namespace CodexPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void EnsureMarketplace()
|
||||||
|
{
|
||||||
|
if (ethAccount == null) throw new Exception("Marketplace is not enabled for this Codex node. Please start it with the option '.EnableMarketplace(...)' to enable it.");
|
||||||
|
}
|
||||||
|
|
||||||
private void Log(string msg)
|
private void Log(string msg)
|
||||||
{
|
{
|
||||||
tools.GetLog().Log($"{GetName()}: {msg}");
|
tools.GetLog().Log($"{GetName()}: {msg}");
|
||||||
|
@ -22,22 +22,22 @@ namespace CodexPlugin
|
|||||||
|
|
||||||
public CodexNode CreateOnlineCodexNode(CodexAccess access, CodexNodeGroup group)
|
public CodexNode CreateOnlineCodexNode(CodexAccess access, CodexNodeGroup group)
|
||||||
{
|
{
|
||||||
var ethAddress = GetEthAddress(access);
|
var ethAccount = GetEthAccount(access);
|
||||||
var marketplaceAccess = GetMarketplaceAccess(access, ethAddress);
|
var marketplaceAccess = GetMarketplaceAccess(access, ethAccount);
|
||||||
return new CodexNode(tools, access, group, marketplaceAccess, ethAddress);
|
return new CodexNode(tools, access, group, marketplaceAccess, ethAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IMarketplaceAccess GetMarketplaceAccess(CodexAccess codexAccess, EthAddress? ethAddress)
|
private IMarketplaceAccess GetMarketplaceAccess(CodexAccess codexAccess, EthAccount? ethAccount)
|
||||||
{
|
{
|
||||||
if (ethAddress == null) return new MarketplaceUnavailable();
|
if (ethAccount == null) return new MarketplaceUnavailable();
|
||||||
return new MarketplaceAccess(tools.GetLog(), codexAccess);
|
return new MarketplaceAccess(tools.GetLog(), codexAccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
private EthAddress? GetEthAddress(CodexAccess access)
|
private EthAccount? GetEthAccount(CodexAccess access)
|
||||||
{
|
{
|
||||||
var ethAccount = access.Container.Containers.Single().Recipe.Additionals.Get<EthAccount>();
|
var ethAccount = access.Container.Containers.Single().Recipe.Additionals.Get<EthAccount>();
|
||||||
if (ethAccount == null) return null;
|
if (ethAccount == null) return null;
|
||||||
return ethAccount.EthAddress;
|
return ethAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CrashWatcher CreateCrashWatcher(RunningContainer c)
|
public CrashWatcher CreateCrashWatcher(RunningContainer c)
|
||||||
|
@ -65,8 +65,8 @@ namespace CodexTests.BasicTests
|
|||||||
MinRequiredNumberOfNodes = 5,
|
MinRequiredNumberOfNodes = 5,
|
||||||
NodeFailureTolerance = 2,
|
NodeFailureTolerance = 2,
|
||||||
ProofProbability = 5,
|
ProofProbability = 5,
|
||||||
Duration = TimeSpan.FromMinutes(5),
|
Duration = TimeSpan.FromMinutes(6),
|
||||||
Expiry = TimeSpan.FromMinutes(4)
|
Expiry = TimeSpan.FromMinutes(5)
|
||||||
};
|
};
|
||||||
|
|
||||||
var purchaseContract = client.Marketplace.RequestStorage(purchase);
|
var purchaseContract = client.Marketplace.RequestStorage(purchase);
|
||||||
|
@ -19,7 +19,7 @@ namespace CodexTests.UtilityTests
|
|||||||
private readonly TestToken hostInitialBalance = 3000000.TstWei();
|
private readonly TestToken hostInitialBalance = 3000000.TstWei();
|
||||||
private readonly TestToken clientInitialBalance = 1000000000.TstWei();
|
private readonly TestToken clientInitialBalance = 1000000000.TstWei();
|
||||||
private readonly EthAccount clientAccount = EthAccount.GenerateNew();
|
private readonly EthAccount clientAccount = EthAccount.GenerateNew();
|
||||||
private readonly EthAccount hostAccount = EthAccount.GenerateNew();
|
private readonly List<EthAccount> hostAccounts = new List<EthAccount>();
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void BotRewardTest()
|
public void BotRewardTest()
|
||||||
@ -44,28 +44,27 @@ namespace CodexTests.UtilityTests
|
|||||||
var apiCalls = new RewardApiCalls(Ci, botContainer);
|
var apiCalls = new RewardApiCalls(Ci, botContainer);
|
||||||
apiCalls.Start(OnCommand);
|
apiCalls.Start(OnCommand);
|
||||||
|
|
||||||
Thread.Sleep(TimeSpan.FromMinutes(10));
|
purchaseContract.WaitForStorageContractFinished();
|
||||||
|
|
||||||
apiCalls.Stop();
|
apiCalls.Stop();
|
||||||
monitor.Stop();
|
monitor.Stop();
|
||||||
|
|
||||||
|
Log("Done!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCommand(GiveRewardsCommand call)
|
private void OnCommand(GiveRewardsCommand call)
|
||||||
{
|
{
|
||||||
var line = "";
|
if (call.Averages.Any()) Log($"{call.Averages.Length} average.");
|
||||||
if (call.Averages.Any()) line += $"{call.Averages.Length} average. ";
|
if (call.EventsOverview.Any()) Log($"{call.EventsOverview.Length} events.");
|
||||||
if (call.EventsOverview.Any()) line += $"{call.EventsOverview.Length} events. ";
|
|
||||||
foreach (var r in call.Rewards)
|
foreach (var r in call.Rewards)
|
||||||
{
|
{
|
||||||
var reward = repo.Rewards.Single(a => a.RoleId == r.RewardId);
|
var reward = repo.Rewards.Single(a => a.RoleId == r.RewardId);
|
||||||
var isClient = r.UserAddresses.Any(a => a == clientAccount.EthAddress.Address);
|
foreach (var address in r.UserAddresses)
|
||||||
var isHost = r.UserAddresses.Any(a => a == hostAccount.EthAddress.Address);
|
{
|
||||||
if (isHost && isClient) throw new Exception("what?");
|
var user = IdentifyAccount(address);
|
||||||
var name = isClient ? "Client" : "Host";
|
Log(user + ": " + reward.Message);
|
||||||
|
}
|
||||||
line += name + " = " + reward.Message;
|
|
||||||
}
|
}
|
||||||
Log(line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private StoragePurchaseContract ClientPurchasesStorage(ICodexNode client)
|
private StoragePurchaseContract ClientPurchasesStorage(ICodexNode client)
|
||||||
@ -88,11 +87,14 @@ namespace CodexTests.UtilityTests
|
|||||||
|
|
||||||
private ICodexNode StartClient(IGethNode geth, ICodexContracts contracts)
|
private ICodexNode StartClient(IGethNode geth, ICodexContracts contracts)
|
||||||
{
|
{
|
||||||
return StartCodex(s => s
|
var node = StartCodex(s => s
|
||||||
.WithName("Client")
|
.WithName("Client")
|
||||||
.EnableMarketplace(geth, contracts, m => m
|
.EnableMarketplace(geth, contracts, m => m
|
||||||
.WithAccount(clientAccount)
|
.WithAccount(clientAccount)
|
||||||
.WithInitial(10.Eth(), clientInitialBalance)));
|
.WithInitial(10.Eth(), clientInitialBalance)));
|
||||||
|
|
||||||
|
Log($"Client {node.EthAccount.EthAddress}");
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartRewarderBot(DiscordBotGethInfo gethInfo, RunningContainer botContainer)
|
private void StartRewarderBot(DiscordBotGethInfo gethInfo, RunningContainer botContainer)
|
||||||
@ -100,7 +102,7 @@ namespace CodexTests.UtilityTests
|
|||||||
Ci.DeployRewarderBot(new RewarderBotStartupConfig(
|
Ci.DeployRewarderBot(new RewarderBotStartupConfig(
|
||||||
discordBotHost: botContainer.GetInternalAddress(DiscordBotContainerRecipe.RewardsPort).Host,
|
discordBotHost: botContainer.GetInternalAddress(DiscordBotContainerRecipe.RewardsPort).Host,
|
||||||
discordBotPort: botContainer.GetInternalAddress(DiscordBotContainerRecipe.RewardsPort).Port,
|
discordBotPort: botContainer.GetInternalAddress(DiscordBotContainerRecipe.RewardsPort).Port,
|
||||||
intervalMinutes: "10",
|
intervalMinutes: 1,
|
||||||
historyStartUtc: DateTime.UtcNow,
|
historyStartUtc: DateTime.UtcNow,
|
||||||
gethInfo: gethInfo,
|
gethInfo: gethInfo,
|
||||||
dataPath: null
|
dataPath: null
|
||||||
@ -142,23 +144,27 @@ namespace CodexTests.UtilityTests
|
|||||||
{
|
{
|
||||||
ContractClock = CodexLogLevel.Trace,
|
ContractClock = CodexLogLevel.Trace,
|
||||||
})
|
})
|
||||||
.WithStorageQuota(GetFileSizePlus(50))
|
.WithStorageQuota(Mult(GetMinFileSizePlus(50), GetNumberOfLiveHosts()))
|
||||||
.EnableMarketplace(geth, contracts, m => m
|
.EnableMarketplace(geth, contracts, m => m
|
||||||
.WithAccount(hostAccount)
|
|
||||||
.WithInitial(10.Eth(), hostInitialBalance)
|
.WithInitial(10.Eth(), hostInitialBalance)
|
||||||
.AsStorageNode()
|
.AsStorageNode()
|
||||||
.AsValidator()));
|
.AsValidator()));
|
||||||
|
|
||||||
var availability = new StorageAvailability(
|
var availability = new StorageAvailability(
|
||||||
totalSpace: GetFileSizePlus(5),
|
totalSpace: Mult(GetMinFileSize(), GetNumberOfLiveHosts()),
|
||||||
maxDuration: TimeSpan.FromMinutes(30),
|
maxDuration: TimeSpan.FromMinutes(30),
|
||||||
minPriceForTotalSpace: 1.TstWei(),
|
minPriceForTotalSpace: 1.TstWei(),
|
||||||
maxCollateral: hostInitialBalance
|
maxCollateral: hostInitialBalance
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
foreach (var host in hosts)
|
foreach (var host in hosts)
|
||||||
{
|
{
|
||||||
|
hostAccounts.Add(host.EthAccount);
|
||||||
host.Marketplace.MakeStorageAvailable(availability);
|
host.Marketplace.MakeStorageAvailable(availability);
|
||||||
|
|
||||||
|
Log($"Host{i} {host.EthAccount.EthAddress}");
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +173,12 @@ namespace CodexTests.UtilityTests
|
|||||||
return Convert.ToInt32(GetNumberOfRequiredHosts()) + 3;
|
return Convert.ToInt32(GetNumberOfRequiredHosts()) + 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ByteSize GetFileSizePlus(int plusMb)
|
private ByteSize Mult(ByteSize size, int mult)
|
||||||
|
{
|
||||||
|
return new ByteSize(size.SizeInBytes * mult);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ByteSize GetMinFileSizePlus(int plusMb)
|
||||||
{
|
{
|
||||||
return new ByteSize(GetMinFileSize().SizeInBytes + plusMb.MB().SizeInBytes);
|
return new ByteSize(GetMinFileSize().SizeInBytes + plusMb.MB().SizeInBytes);
|
||||||
}
|
}
|
||||||
@ -184,7 +195,7 @@ namespace CodexTests.UtilityTests
|
|||||||
if (h > minNumHosts) minNumHosts = h;
|
if (h > minNumHosts) minNumHosts = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
var minFileSize = (minSlotSize * minNumHosts) + 1024;
|
var minFileSize = ((minSlotSize + 1024) * minNumHosts);
|
||||||
return new ByteSize(Convert.ToInt64(minFileSize));
|
return new ByteSize(Convert.ToInt64(minFileSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +204,20 @@ namespace CodexTests.UtilityTests
|
|||||||
return Convert.ToUInt32(repo.Rewards.Max(r => r.CheckConfig.MinNumberOfHosts));
|
return Convert.ToUInt32(repo.Rewards.Max(r => r.CheckConfig.MinNumberOfHosts));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string IdentifyAccount(string address)
|
||||||
|
{
|
||||||
|
if (address == clientAccount.EthAddress.Address) return "Client";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var index = hostAccounts.FindIndex(a => a.EthAddress.Address == address);
|
||||||
|
return "Host" + index;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class RewardApiCalls
|
public class RewardApiCalls
|
||||||
{
|
{
|
||||||
private readonly CoreInterface ci;
|
private readonly CoreInterface ci;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user