From 9a7946c863b9e85c4ec255ae61ba620066280abf Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 31 Jul 2023 09:16:52 +0200 Subject: [PATCH] Basic tests pass --- DistTestCore/Codex/CodexContainerRecipe.cs | 2 +- .../CodexContractsContainerRecipe.cs | 10 ++--- .../Marketplace/GethContainerRecipe.cs | 6 +-- DistTestCore/Marketplace/MarketplaceAccess.cs | 12 +++++ .../Metrics/PrometheusContainerRecipe.cs | 2 +- Tests/BasicTests/ExampleTests.cs | 45 +++++++++++++++++-- 6 files changed, 60 insertions(+), 17 deletions(-) diff --git a/DistTestCore/Codex/CodexContainerRecipe.cs b/DistTestCore/Codex/CodexContainerRecipe.cs index edf15da..4039d54 100644 --- a/DistTestCore/Codex/CodexContainerRecipe.cs +++ b/DistTestCore/Codex/CodexContainerRecipe.cs @@ -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"; diff --git a/DistTestCore/Marketplace/CodexContractsContainerRecipe.cs b/DistTestCore/Marketplace/CodexContractsContainerRecipe.cs index d34aa6f..51e62d5 100644 --- a/DistTestCore/Marketplace/CodexContractsContainerRecipe.cs +++ b/DistTestCore/Marketplace/CodexContractsContainerRecipe.cs @@ -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) diff --git a/DistTestCore/Marketplace/GethContainerRecipe.cs b/DistTestCore/Marketplace/GethContainerRecipe.cs index c94f73d..6dc62e9 100644 --- a/DistTestCore/Marketplace/GethContainerRecipe.cs +++ b/DistTestCore/Marketplace/GethContainerRecipe.cs @@ -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) diff --git a/DistTestCore/Marketplace/MarketplaceAccess.cs b/DistTestCore/Marketplace/MarketplaceAccess.cs index 8e3fa89..b179121 100644 --- a/DistTestCore/Marketplace/MarketplaceAccess.cs +++ b/DistTestCore/Marketplace/MarketplaceAccess.cs @@ -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(); diff --git a/DistTestCore/Metrics/PrometheusContainerRecipe.cs b/DistTestCore/Metrics/PrometheusContainerRecipe.cs index 50e433a..b702222 100644 --- a/DistTestCore/Metrics/PrometheusContainerRecipe.cs +++ b/DistTestCore/Metrics/PrometheusContainerRecipe.cs @@ -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) diff --git a/Tests/BasicTests/ExampleTests.cs b/Tests/BasicTests/ExampleTests.cs index 3007ae4..371e9e1 100644 --- a/Tests/BasicTests/ExampleTests.cs +++ b/Tests/BasicTests/ExampleTests.cs @@ -1,4 +1,7 @@ using DistTestCore; +using DistTestCore.Codex; +using DistTestCore.Marketplace; +using Newtonsoft.Json; using NUnit.Framework; using Utils; @@ -61,23 +64,59 @@ namespace Tests.BasicTests var buyer = SetupCodexNode(s => s .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."); + } } }