This commit is contained in:
Ben 2024-03-20 13:36:06 +01:00
parent 2a5b3e0eec
commit db37143db6
No known key found for this signature in database
GPG Key ID: 541B9D8C9F1426A1
3 changed files with 9 additions and 26 deletions

View File

@ -9,7 +9,7 @@ namespace CodexPlugin
{ {
private readonly MarketplaceStarter marketplaceStarter = new MarketplaceStarter(); 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 ApiPortTag = "codex_api_port";
public const string ListenPortTag = "codex_listen_port"; public const string ListenPortTag = "codex_listen_port";
public const string MetricsPortTag = "codex_metrics_port"; public const string MetricsPortTag = "codex_metrics_port";

View File

@ -84,6 +84,7 @@ namespace CodexPlugin
{ {
private readonly ILog log; private readonly ILog log;
private readonly CodexAccess codexAccess; private readonly CodexAccess codexAccess;
private readonly TimeSpan gracePeriod = TimeSpan.FromSeconds(10);
private DateTime? contractStartUtc; private DateTime? contractStartUtc;
public StoragePurchaseContract(ILog log, CodexAccess codexAccess, string purchaseId, StoragePurchase purchase) public StoragePurchaseContract(ILog log, CodexAccess codexAccess, string purchaseId, StoragePurchase purchase)
@ -99,7 +100,10 @@ namespace CodexPlugin
public void WaitForStorageContractStarted() public void WaitForStorageContractStarted()
{ {
WaitForStorageContractStarted(TimeSpan.FromSeconds(30)); var timeout = Purchase.Expiry + gracePeriod;
WaitForStorageContractState(timeout, "started");
contractStartUtc = DateTime.UtcNow;
} }
public void WaitForStorageContractFinished() public void WaitForStorageContractFinished()
@ -108,28 +112,14 @@ namespace CodexPlugin
{ {
WaitForStorageContractStarted(); WaitForStorageContractStarted();
} }
var gracePeriod = TimeSpan.FromSeconds(10);
var currentContractTime = DateTime.UtcNow - contractStartUtc!.Value; var currentContractTime = DateTime.UtcNow - contractStartUtc!.Value;
var timeout = (Purchase.Duration - currentContractTime) + gracePeriod; var timeout = (Purchase.Duration - currentContractTime) + gracePeriod;
WaitForStorageContractState(timeout, "finished"); WaitForStorageContractState(timeout, "finished");
} }
public void WaitForStorageContractFinished(ByteSize contractFileSize) public CodexStoragePurchase GetPurchaseStatus(string purchaseId)
{ {
if (!contractStartUtc.HasValue) return codexAccess.GetPurchaseStatus(purchaseId);
{
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;
} }
private void WaitForStorageContractState(TimeSpan timeout, string desiredState) private void WaitForStorageContractState(TimeSpan timeout, string desiredState)
@ -162,10 +152,5 @@ namespace CodexPlugin
} }
log.Log($"Contract '{desiredState}'."); log.Log($"Contract '{desiredState}'.");
} }
public CodexStoragePurchase GetPurchaseStatus(string purchaseId)
{
return codexAccess.GetPurchaseStatus(purchaseId);
}
} }
} }

View File

@ -102,7 +102,7 @@ namespace CodexTests.BasicTests
var purchaseContract = buyer.Marketplace.RequestStorage(purchase); var purchaseContract = buyer.Marketplace.RequestStorage(purchase);
purchaseContract.WaitForStorageContractStarted(TimeSpan.FromMinutes(4)); purchaseContract.WaitForStorageContractStarted();
AssertBalance(contracts, seller, Is.LessThan(sellerInitialBalance), "Collateral was not placed."); 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, seller, Is.GreaterThan(sellerInitialBalance), "Seller was not paid for storage.");
AssertBalance(contracts, buyer, Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage."); AssertBalance(contracts, buyer, Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage.");
Assert.That(contracts.GetRequestState(request), Is.EqualTo(RequestState.Finished)); Assert.That(contracts.GetRequestState(request), Is.EqualTo(RequestState.Finished));
CheckLogForErrors(seller, buyer);
} }
[Test] [Test]