Basic tests pass
This commit is contained in:
parent
10ffd29257
commit
9a7946c863
|
@ -5,7 +5,7 @@ namespace DistTestCore.Codex
|
|||
{
|
||||
public class CodexContainerRecipe : ContainerRecipeFactory
|
||||
{
|
||||
private const string DefaultDockerImage = "codexstorage/nim-codex:sha-14c5270";
|
||||
private const string DefaultDockerImage = "codexstorage/nim-codex:sha-3e80de3";
|
||||
|
||||
public const string MetricsPortTag = "metrics_port";
|
||||
public const string DiscoveryPortTag = "discovery-port";
|
||||
|
|
|
@ -4,18 +4,14 @@ namespace DistTestCore.Marketplace
|
|||
{
|
||||
public class CodexContractsContainerRecipe : ContainerRecipeFactory
|
||||
{
|
||||
public const string MarketplaceAddressFilename = "/usr/app/deployments/codexdisttestnetwork/Marketplace.json";
|
||||
public const string MarketplaceArtifactFilename = "/usr/app/artifacts/contracts/Marketplace.sol/Marketplace.json";
|
||||
public const string MarketplaceAddressFilename = "/hardhat/deployments/codexdisttestnetwork/Marketplace.json";
|
||||
public const string MarketplaceArtifactFilename = "/hardhat/artifacts/contracts/Marketplace.sol/Marketplace.json";
|
||||
|
||||
public override string Image { get; }
|
||||
|
||||
public CodexContractsContainerRecipe()
|
||||
{
|
||||
#if Arm64
|
||||
Image = "emizzle/codex-contracts-deployment:latest";
|
||||
#else
|
||||
Image = "thatbenbierens/codex-contracts-deployment:nomint2";
|
||||
#endif
|
||||
Image = "codexstorage/dist-tests-codex-contracts-eth:sha-b4e4897";
|
||||
}
|
||||
|
||||
protected override void Initialize(StartupConfig startupConfig)
|
||||
|
|
|
@ -14,11 +14,7 @@ namespace DistTestCore.Marketplace
|
|||
|
||||
public GethContainerRecipe()
|
||||
{
|
||||
#if Arm64
|
||||
Image = "emizzle/geth-confenv:latest";
|
||||
#else
|
||||
Image = "thatbenbierens/geth-confenv:onethousand";
|
||||
#endif
|
||||
Image = "codexstorage/dist-tests-geth:sha-b788a2d";
|
||||
}
|
||||
|
||||
protected override void Initialize(StartupConfig startupConfig)
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace DistTestCore.Marketplace
|
|||
string MakeStorageAvailable(ByteSize size, TestToken minPricePerBytePerSecond, TestToken maxCollateral, TimeSpan maxDuration);
|
||||
string RequestStorage(ContentId contentId, TestToken pricePerSlotPerSecond, TestToken requiredCollateral, uint minRequiredNumberOfNodes, int proofProbability, TimeSpan duration);
|
||||
void AssertThatBalance(IResolveConstraint constraint, string message = "");
|
||||
CodexStoragePurchase GetPurchaseStatus(string purchaseId);
|
||||
TestToken GetBalance();
|
||||
}
|
||||
|
||||
|
@ -102,6 +103,11 @@ namespace DistTestCore.Marketplace
|
|||
AssertHelpers.RetryAssert(constraint, GetBalance, message);
|
||||
}
|
||||
|
||||
public CodexStoragePurchase GetPurchaseStatus(string purchaseId)
|
||||
{
|
||||
return codexAccess.GetPurchaseStatus(purchaseId);
|
||||
}
|
||||
|
||||
public TestToken GetBalance()
|
||||
{
|
||||
var interaction = marketplaceNetwork.StartInteraction(lifecycle);
|
||||
|
@ -138,6 +144,12 @@ namespace DistTestCore.Marketplace
|
|||
Unavailable();
|
||||
}
|
||||
|
||||
public CodexStoragePurchase GetPurchaseStatus(string purchaseId)
|
||||
{
|
||||
Unavailable();
|
||||
return new CodexStoragePurchase();
|
||||
}
|
||||
|
||||
public TestToken GetBalance()
|
||||
{
|
||||
Unavailable();
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace DistTestCore.Metrics
|
|||
|
||||
public PrometheusContainerRecipe()
|
||||
{
|
||||
Image = "thatbenbierens/prometheus-envconf:latest";
|
||||
Image = "codexstorage/dist-tests-prometheus:sha-f97d7fd";
|
||||
}
|
||||
|
||||
protected override void Initialize(StartupConfig startupConfig)
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
using DistTestCore;
|
||||
using DistTestCore.Codex;
|
||||
using DistTestCore.Marketplace;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Utils;
|
||||
|
||||
|
@ -62,22 +65,58 @@ namespace Tests.BasicTests
|
|||
.WithBootstrapNode(seller)
|
||||
.EnableMarketplace(buyerInitialBalance));
|
||||
|
||||
buyer.Marketplace.AssertThatBalance(Is.EqualTo(buyerInitialBalance));
|
||||
|
||||
var contentId = buyer.UploadFile(testFile);
|
||||
buyer.Marketplace.RequestStorage(contentId,
|
||||
var purchaseId = buyer.Marketplace.RequestStorage(contentId,
|
||||
pricePerSlotPerSecond: 2.TestTokens(),
|
||||
requiredCollateral: 10.TestTokens(),
|
||||
minRequiredNumberOfNodes: 1,
|
||||
proofProbability: 5,
|
||||
duration: TimeSpan.FromMinutes(1));
|
||||
|
||||
Time.Sleep(TimeSpan.FromSeconds(10));
|
||||
|
||||
WaitForContractToStart(buyer.Marketplace, 10.MB(), purchaseId);
|
||||
|
||||
seller.Marketplace.AssertThatBalance(Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
|
||||
|
||||
Time.Sleep(TimeSpan.FromMinutes(1));
|
||||
Time.Sleep(TimeSpan.FromMinutes(2));
|
||||
|
||||
seller.Marketplace.AssertThatBalance(Is.GreaterThan(sellerInitialBalance), "Seller was not paid for storage.");
|
||||
buyer.Marketplace.AssertThatBalance(Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage.");
|
||||
}
|
||||
|
||||
private void WaitForContractToStart(IMarketplaceAccess access, ByteSize fileSize, string purchaseId)
|
||||
{
|
||||
var lastState = "";
|
||||
var waitStart = DateTime.UtcNow;
|
||||
var filesizeInMb = fileSize.SizeInBytes / (1024 * 1024);
|
||||
var maxWaitTime = TimeSpan.FromSeconds(filesizeInMb * 10.0);
|
||||
|
||||
Log($"{nameof(WaitForContractToStart)} for {Time.FormatDuration(maxWaitTime)}");
|
||||
while (lastState != "started")
|
||||
{
|
||||
var purchaseStatus = access.GetPurchaseStatus(purchaseId);
|
||||
var statusJson = JsonConvert.SerializeObject(purchaseStatus);
|
||||
if (purchaseStatus != null && purchaseStatus.state != lastState)
|
||||
{
|
||||
lastState = purchaseStatus.state;
|
||||
Log("Purchase status: " + statusJson);
|
||||
}
|
||||
|
||||
Thread.Sleep(2000);
|
||||
|
||||
if (lastState == "errored")
|
||||
{
|
||||
Assert.Fail("Contract start failed: " + statusJson);
|
||||
}
|
||||
|
||||
if (DateTime.UtcNow - waitStart > maxWaitTime)
|
||||
{
|
||||
Assert.Fail($"Contract was not picked up within {maxWaitTime.TotalSeconds} seconds timeout: {statusJson}");
|
||||
}
|
||||
}
|
||||
Log("Contract started.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue