diff --git a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs index 4356556a..ca619b29 100644 --- a/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs +++ b/ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs @@ -9,7 +9,7 @@ namespace CodexPlugin { private readonly MarketplaceStarter marketplaceStarter = new MarketplaceStarter(); - private const string DefaultDockerImage = "codexstorage/nim-codex:sha-ba0e7d9-dist-tests"; + private const string DefaultDockerImage = "codexstorage/nim-codex:sha-e4ddb94-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/MarketplaceAccess.cs b/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs index 82b4e3ac..411b4814 100644 --- a/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs +++ b/ProjectPlugins/CodexPlugin/MarketplaceAccess.cs @@ -84,6 +84,7 @@ namespace CodexPlugin { private readonly ILog log; private readonly CodexAccess codexAccess; + private readonly TimeSpan gracePeriod = TimeSpan.FromSeconds(10); private DateTime? contractStartUtc; public StoragePurchaseContract(ILog log, CodexAccess codexAccess, string purchaseId, StoragePurchase purchase) @@ -99,7 +100,10 @@ namespace CodexPlugin public void WaitForStorageContractStarted() { - WaitForStorageContractStarted(TimeSpan.FromSeconds(30)); + var timeout = Purchase.Expiry + gracePeriod; + + WaitForStorageContractState(timeout, "started"); + contractStartUtc = DateTime.UtcNow; } public void WaitForStorageContractFinished() @@ -108,28 +112,14 @@ namespace CodexPlugin { WaitForStorageContractStarted(); } - var gracePeriod = TimeSpan.FromSeconds(10); var currentContractTime = DateTime.UtcNow - contractStartUtc!.Value; var timeout = (Purchase.Duration - currentContractTime) + gracePeriod; WaitForStorageContractState(timeout, "finished"); } - public void WaitForStorageContractFinished(ByteSize contractFileSize) + public CodexStoragePurchase GetPurchaseStatus(string purchaseId) { - if (!contractStartUtc.HasValue) - { - WaitForStorageContractStarted(contractFileSize.ToTimeSpan()); - } - var gracePeriod = TimeSpan.FromSeconds(10); - var currentContractTime = DateTime.UtcNow - contractStartUtc!.Value; - var timeout = (Purchase.Duration - currentContractTime) + gracePeriod; - WaitForStorageContractState(timeout, "finished"); - } - - public void WaitForStorageContractStarted(TimeSpan timeout) - { - WaitForStorageContractState(timeout, "started"); - contractStartUtc = DateTime.UtcNow; + return codexAccess.GetPurchaseStatus(purchaseId); } private void WaitForStorageContractState(TimeSpan timeout, string desiredState) @@ -162,10 +152,5 @@ namespace CodexPlugin } log.Log($"Contract '{desiredState}'."); } - - public CodexStoragePurchase GetPurchaseStatus(string purchaseId) - { - return codexAccess.GetPurchaseStatus(purchaseId); - } } } diff --git a/Tests/CodexTests/BasicTests/ExampleTests.cs b/Tests/CodexTests/BasicTests/ExampleTests.cs index 473bf984..4973e2a0 100644 --- a/Tests/CodexTests/BasicTests/ExampleTests.cs +++ b/Tests/CodexTests/BasicTests/ExampleTests.cs @@ -102,7 +102,7 @@ namespace CodexTests.BasicTests var purchaseContract = buyer.Marketplace.RequestStorage(purchase); - purchaseContract.WaitForStorageContractStarted(TimeSpan.FromMinutes(4)); + purchaseContract.WaitForStorageContractStarted(); AssertBalance(contracts, seller, Is.LessThan(sellerInitialBalance), "Collateral was not placed."); @@ -116,8 +116,6 @@ namespace CodexTests.BasicTests AssertBalance(contracts, seller, Is.GreaterThan(sellerInitialBalance), "Seller was not paid for storage."); AssertBalance(contracts, buyer, Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage."); Assert.That(contracts.GetRequestState(request), Is.EqualTo(RequestState.Finished)); - - CheckLogForErrors(seller, buyer); } [Test]