Debugging and cleanin up marketplace test

This commit is contained in:
benbierens 2023-06-28 10:41:04 +02:00
parent 91a8f6a869
commit fe1ee45775
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
2 changed files with 54 additions and 26 deletions

View File

@ -11,7 +11,7 @@ namespace ContinuousTests.Tests
public class MarketplaceTest : ContinuousTest public class MarketplaceTest : ContinuousTest
{ {
public override int RequiredNumberOfNodes => 1; public override int RequiredNumberOfNodes => 1;
public override TimeSpan RunTestEvery => TimeSpan.FromDays(4); public override TimeSpan RunTestEvery => TimeSpan.FromMinutes(15);
public override TestFailMode TestFailMode => TestFailMode.StopAfterFirstFailure; public override TestFailMode TestFailMode => TestFailMode.StopAfterFirstFailure;
public const int EthereumAccountIndex = 200; // TODO: Check against all other account indices of all other tests. public const int EthereumAccountIndex = 200; // TODO: Check against all other account indices of all other tests.
@ -28,10 +28,9 @@ namespace ContinuousTests.Tests
[TestMoment(t: Zero)] [TestMoment(t: Zero)]
public void NodePostsStorageRequest() public void NodePostsStorageRequest()
{ {
var contractDuration = TimeSpan.FromDays(3) + TimeSpan.FromHours(1); var contractDuration = TimeSpan.FromMinutes(11); //TimeSpan.FromDays(3) + TimeSpan.FromHours(1);
decimal totalDurationSeconds = Convert.ToDecimal(contractDuration.TotalSeconds); decimal totalDurationSeconds = Convert.ToDecimal(contractDuration.TotalSeconds);
var expectedTotalCost = numberOfSlots * pricePerSlotPerSecond.Amount * (totalDurationSeconds + 1); var expectedTotalCost = numberOfSlots * pricePerSlotPerSecond.Amount * (totalDurationSeconds + 1) * 1000000;
Log.Log("expected total cost: " + expectedTotalCost);
file = FileManager.GenerateTestFile(fileSize); file = FileManager.GenerateTestFile(fileSize);
@ -44,7 +43,7 @@ namespace ContinuousTests.Tests
Assert.That(!string.IsNullOrEmpty(debugInfo.spr)); Assert.That(!string.IsNullOrEmpty(debugInfo.spr));
var startupConfig = new StartupConfig(); var startupConfig = new StartupConfig();
var codexStartConfig = new CodexStartupConfig(CodexLogLevel.Debug); var codexStartConfig = new CodexStartupConfig(CodexLogLevel.Trace);
codexStartConfig.MarketplaceConfig = new MarketplaceInitialConfig(0.Eth(), 0.TestTokens(), false); codexStartConfig.MarketplaceConfig = new MarketplaceInitialConfig(0.Eth(), 0.TestTokens(), false);
codexStartConfig.MarketplaceConfig.AccountIndexOverride = EthereumAccountIndex; codexStartConfig.MarketplaceConfig.AccountIndexOverride = EthereumAccountIndex;
codexStartConfig.BootstrapSpr = debugInfo.spr; codexStartConfig.BootstrapSpr = debugInfo.spr;
@ -52,7 +51,7 @@ namespace ContinuousTests.Tests
startupConfig.Add(Configuration.CodexDeployment.GethStartResult); startupConfig.Add(Configuration.CodexDeployment.GethStartResult);
var rc = flow.Start(1, Location.Unspecified, new CodexContainerRecipe(), startupConfig); var rc = flow.Start(1, Location.Unspecified, new CodexContainerRecipe(), startupConfig);
var account = Configuration.CodexDeployment.GethStartResult.MarketplaceNetwork.Bootstrap.AllAccounts.Accounts[EthereumAccountIndex]; var account = Configuration.CodexDeployment.GethStartResult.CompanionNode.Accounts[EthereumAccountIndex];
var tokenAddress = Configuration.CodexDeployment.GethStartResult.MarketplaceNetwork.Marketplace.TokenAddress; var tokenAddress = Configuration.CodexDeployment.GethStartResult.MarketplaceNetwork.Marketplace.TokenAddress;
var interaction = Configuration.CodexDeployment.GethStartResult.MarketplaceNetwork.Bootstrap.StartInteraction(lifecycle); var interaction = Configuration.CodexDeployment.GethStartResult.MarketplaceNetwork.Bootstrap.StartInteraction(lifecycle);
@ -61,15 +60,13 @@ namespace ContinuousTests.Tests
var container = rc.Containers[0]; var container = rc.Containers[0];
var marketplaceNetwork = Configuration.CodexDeployment.GethStartResult.MarketplaceNetwork; var marketplaceNetwork = Configuration.CodexDeployment.GethStartResult.MarketplaceNetwork;
var codexAccess = new CodexAccess(lifecycle, container); var codexAccess = new CodexAccess(lifecycle, container);
var myNodeInfo = codexAccess.Node.GetDebugInfo();
var marketAccess = new MarketplaceAccess(lifecycle, marketplaceNetwork, account, codexAccess); var marketAccess = new MarketplaceAccess(lifecycle, marketplaceNetwork, account, codexAccess);
cid = UploadFile(codexAccess.Node, file); cid = UploadFile(codexAccess.Node, file);
Assert.That(cid, Is.Not.Null); Assert.That(cid, Is.Not.Null);
var balance = marketAccess.GetBalance();
Log.Log("Account: " + account.Account);
Log.Log("Balance: " + balance);
purchaseId = marketAccess.RequestStorage( purchaseId = marketAccess.RequestStorage(
contentId: cid!, contentId: cid!,
pricePerSlotPerSecond: pricePerSlotPerSecond, pricePerSlotPerSecond: pricePerSlotPerSecond,
@ -78,8 +75,33 @@ namespace ContinuousTests.Tests
proofProbability: 10, proofProbability: 10,
duration: contractDuration); duration: contractDuration);
Log.Log($"PurchaseId: '{purchaseId}'"); Log($"PurchaseId: '{purchaseId}'");
Assert.That(!string.IsNullOrEmpty(purchaseId)); Assert.That(!string.IsNullOrEmpty(purchaseId));
var lastState = "";
var waitStart = DateTime.UtcNow;
var filesizeInMb = fileSize.SizeInBytes / 1024;
var maxWaitTime = TimeSpan.FromSeconds(filesizeInMb * 10.0);
while (lastState != "started")
{
var purchaseStatus = codexAccess.Node.GetPurchaseStatus(purchaseId);
if (purchaseStatus != null && purchaseStatus.state != lastState)
{
lastState = purchaseStatus.state;
}
Thread.Sleep(2000);
if (lastState == "errored")
{
Assert.Fail("Contract start failed: " + JsonConvert.SerializeObject(purchaseStatus));
}
if (DateTime.UtcNow - waitStart > maxWaitTime)
{
Assert.Fail($"Contract was not picked up within {maxWaitTime.TotalSeconds} seconds timeout: " + JsonConvert.SerializeObject(purchaseStatus));
}
}
} }
finally finally
{ {
@ -87,7 +109,7 @@ namespace ContinuousTests.Tests
} }
} }
[TestMoment(t: DayThree)] [TestMoment(t: MinuteFive * 2)]
public void StoredDataIsAvailableAfterThreeDays() public void StoredDataIsAvailableAfterThreeDays()
{ {
var (workflowCreator, lifecycle) = CreateFacilities(); var (workflowCreator, lifecycle) = CreateFacilities();
@ -135,7 +157,7 @@ namespace ContinuousTests.Tests
operationTimeout: TimeSet.K8sOperationTimeout(), operationTimeout: TimeSet.K8sOperationTimeout(),
retryDelay: TimeSet.WaitForK8sServiceDelay()); retryDelay: TimeSet.WaitForK8sServiceDelay());
var workflowCreator = new WorkflowCreator(Log, kubeFlowConfig, testNamespacePostfix: string.Empty); var workflowCreator = new WorkflowCreator(base.Log, kubeFlowConfig, testNamespacePostfix: string.Empty);
var lifecycle = new TestLifecycle(new NullLog(), lifecycleConfig, TimeSet, workflowCreator); var lifecycle = new TestLifecycle(new NullLog(), lifecycleConfig, TimeSet, workflowCreator);
return (workflowCreator, lifecycle); return (workflowCreator, lifecycle);
@ -146,5 +168,10 @@ namespace ContinuousTests.Tests
if (string.IsNullOrEmpty(kubeConfigFile) || kubeConfigFile.ToLowerInvariant() == "null") return null; if (string.IsNullOrEmpty(kubeConfigFile) || kubeConfigFile.ToLowerInvariant() == "null") return null;
return kubeConfigFile; return kubeConfigFile;
} }
private new void Log(string msg)
{
base.Log.Log(msg);
}
} }
} }

View File

@ -34,10 +34,10 @@ namespace DistTestCore.Marketplace
{ {
var request = new CodexSalesRequestStorageRequest var request = new CodexSalesRequestStorageRequest
{ {
duration = ToHexBigInt(duration.TotalSeconds), duration = ToDecInt(duration.TotalSeconds),
proofProbability = ToHexBigInt(proofProbability), proofProbability = ToDecInt(proofProbability),
reward = ToHexBigInt(pricePerSlotPerSecond), reward = ToDecInt(pricePerSlotPerSecond),
collateral = ToHexBigInt(requiredCollateral), collateral = ToDecInt(requiredCollateral),
expiry = null, expiry = null,
nodes = minRequiredNumberOfNodes, nodes = minRequiredNumberOfNodes,
tolerance = null, tolerance = null,
@ -66,10 +66,10 @@ namespace DistTestCore.Marketplace
{ {
var request = new CodexSalesAvailabilityRequest var request = new CodexSalesAvailabilityRequest
{ {
size = ToHexBigInt(size.SizeInBytes), size = ToDecInt(size.SizeInBytes),
duration = ToHexBigInt(maxDuration.TotalSeconds), duration = ToDecInt(maxDuration.TotalSeconds),
maxCollateral = ToHexBigInt(maxCollateral), maxCollateral = ToDecInt(maxCollateral),
minPrice = ToHexBigInt(minPricePerBytePerSecond) minPrice = ToDecInt(minPricePerBytePerSecond)
}; };
Log($"Making storage available... (" + Log($"Making storage available... (" +
@ -85,15 +85,16 @@ namespace DistTestCore.Marketplace
return response.id; return response.id;
} }
private string ToHexBigInt(double d) private string ToDecInt(double d)
{ {
return "0x" + string.Format("{0:X}", Convert.ToInt64(d)); var i = new BigInteger(d);
return i.ToString("D");
} }
public string ToHexBigInt(TestToken t) public string ToDecInt(TestToken t)
{ {
var bigInt = new BigInteger(t.Amount); var i = new BigInteger(t.Amount);
return "0x" + bigInt.ToString("X"); return i.ToString("D");
} }
public void AssertThatBalance(IResolveConstraint constraint, string message = "") public void AssertThatBalance(IResolveConstraint constraint, string message = "")