From c4b6d0153080258b8f510c615a639b08108bcdc7 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 23 Sep 2024 11:31:57 +0200 Subject: [PATCH] Adds check for usage of availabilities. --- .../CodexPlugin/CodexContainerRecipe.cs | 2 +- ProjectPlugins/CodexPlugin/Mapper.cs | 3 ++ .../CodexPlugin/MarketplaceTypes.cs | 1 + .../CodexTests/BasicTests/MarketplaceTests.cs | 47 ++----------------- 4 files changed, 10 insertions(+), 43 deletions(-) diff --git a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs index 597255c..e038030 100644 --- a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs +++ b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs @@ -7,7 +7,7 @@ namespace CodexPlugin { public class CodexContainerRecipe : ContainerRecipeFactory { - private const string DefaultDockerImage = "codexstorage/nim-codex:sha-656ce37-dist-tests"; + private const string DefaultDockerImage = "codexstorage/nim-codex:sha-cda52af-dist-tests"; public const string ApiPortTag = "codex_api_port"; public const string ListenPortTag = "codex_listen_port"; public const string MetricsPortTag = "codex_metrics_port"; diff --git a/ProjectPlugins/CodexPlugin/Mapper.cs b/ProjectPlugins/CodexPlugin/Mapper.cs index b752fe4..3f3fc5b 100644 --- a/ProjectPlugins/CodexPlugin/Mapper.cs +++ b/ProjectPlugins/CodexPlugin/Mapper.cs @@ -70,6 +70,8 @@ namespace CodexPlugin public StorageAvailability Map(SalesAvailability availability) { + var freeSize = (string)availability.AdditionalProperties["freeSize"]; + return new StorageAvailability ( ToByteSize(availability.TotalSize), @@ -79,6 +81,7 @@ namespace CodexPlugin ) { Id = availability.Id, + FreeSpace = ToByteSize(freeSize) }; } diff --git a/ProjectPlugins/CodexPlugin/MarketplaceTypes.cs b/ProjectPlugins/CodexPlugin/MarketplaceTypes.cs index f3163d2..fcbfe63 100644 --- a/ProjectPlugins/CodexPlugin/MarketplaceTypes.cs +++ b/ProjectPlugins/CodexPlugin/MarketplaceTypes.cs @@ -84,6 +84,7 @@ namespace CodexPlugin public TimeSpan MaxDuration { get; } public TestToken MinPriceForTotalSpace { get; } public TestToken MaxCollateral { get; } + public ByteSize FreeSpace { get; set; } = ByteSize.Zero; public void Log(ILog log) { diff --git a/Tests/CodexTests/BasicTests/MarketplaceTests.cs b/Tests/CodexTests/BasicTests/MarketplaceTests.cs index 39ab8c4..9bb0f6f 100644 --- a/Tests/CodexTests/BasicTests/MarketplaceTests.cs +++ b/Tests/CodexTests/BasicTests/MarketplaceTests.cs @@ -97,7 +97,11 @@ namespace CodexTests.BasicTests purchaseContract.WaitForStorageContractStarted(); - var availabilities = hosts.Select(h => h.Marketplace.GetAvailabilities()); + var availabilities = hosts.Select(h => h.Marketplace.GetAvailabilities()).ToArray(); + if (availabilities.All(h => h.All(a => a.FreeSpace.SizeInBytes == a.TotalSpace.SizeInBytes))) + { + Assert.Fail("Host availabilities were not used."); + } var request = GetOnChainStorageRequest(contracts, geth); AssertStorageRequest(request, purchase, contracts, client); @@ -109,47 +113,6 @@ namespace CodexTests.BasicTests Assert.That(contracts.GetRequestState(request), Is.EqualTo(RequestState.Finished)); } - [Test] - [Ignore("Integrated into MarketplaceExample to speed up testing.")] - public void CanDownloadContentFromContractCid() - { - var fileSize = 10.MB(); - var geth = Ci.StartGethNode(s => s.IsMiner().WithName("disttest-geth")); - var contracts = Ci.StartCodexContracts(geth); - var testFile = CreateFile(fileSize); - - var client = StartCodex(s => s - .WithName("Client") - .EnableMarketplace(geth, contracts, m => m - .WithInitial(10.Eth(), 10.Tst()))); - - var uploadCid = client.UploadFile(testFile); - - var purchase = new StoragePurchaseRequest(uploadCid) - { - PricePerSlotPerSecond = 2.TstWei(), - RequiredCollateral = 10.TstWei(), - MinRequiredNumberOfNodes = 5, - NodeFailureTolerance = 2, - ProofProbability = 5, - Duration = TimeSpan.FromMinutes(5), - Expiry = TimeSpan.FromMinutes(4) - }; - - var purchaseContract = client.Marketplace.RequestStorage(purchase); - var contractCid = purchaseContract.ContentId; - Assert.That(uploadCid.Id, Is.Not.EqualTo(contractCid.Id)); - - // Download both from client. - testFile.AssertIsEqual(client.DownloadContent(uploadCid)); - testFile.AssertIsEqual(client.DownloadContent(contractCid)); - - // Download both from another node. - var downloader = StartCodex(s => s.WithName("Downloader")); - testFile.AssertIsEqual(downloader.DownloadContent(uploadCid)); - testFile.AssertIsEqual(downloader.DownloadContent(contractCid)); - } - private TrackedFile CreateFile(ByteSize fileSize) { var segmentSize = new ByteSize(fileSize.SizeInBytes / 4);