From 2155634414982d3f49d666dc0edcff6ee22d156b Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Fri, 18 Aug 2023 10:22:51 +1000 Subject: [PATCH] improve simulated proof failure test The test is mostly working, except that the node needs to be updated to call the onReservationAdded callback once availability marked unused --- DistTestCore/Tokens.cs | 10 ++++++++++ Tests/Marketplace/Proofs.cs | 31 ++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/DistTestCore/Tokens.cs b/DistTestCore/Tokens.cs index 5593ffc..102dfc3 100644 --- a/DistTestCore/Tokens.cs +++ b/DistTestCore/Tokens.cs @@ -58,6 +58,16 @@ { return $"{Amount} TestTokens"; } + + public static TestToken operator - (TestToken t1, int amount) + { + return t1 - Convert.ToDecimal(amount); + } + + public static TestToken operator - (TestToken t1, decimal amount) + { + return (t1.Amount - amount).TestTokens(); + } } public static class TokensIntExtensions diff --git a/Tests/Marketplace/Proofs.cs b/Tests/Marketplace/Proofs.cs index c59e797..86a8bb6 100644 --- a/Tests/Marketplace/Proofs.cs +++ b/Tests/Marketplace/Proofs.cs @@ -16,7 +16,7 @@ namespace Tests.BasicTests var seller = SetupCodexNode(s => s .WithLogLevel(CodexLogLevel.Trace, "marketplace", "sales", "proving", "reservations") - .WithStorageQuota(11.GB()) + .WithStorageQuota(20.GB()) .EnableMarketplace(sellerInitialBalance) .WithName("seller")); @@ -49,32 +49,49 @@ namespace Tests.BasicTests size: 10.GB(), minPricePerBytePerSecond: 1.TestTokens(), maxCollateral: 20.TestTokens(), - maxDuration: TimeSpan.FromMinutes(5)); + maxDuration: TimeSpan.FromMinutes(3)); sellerWithFailures.Marketplace.MakeStorageAvailable( size: 10.GB(), minPricePerBytePerSecond: 1.TestTokens(), maxCollateral: 20.TestTokens(), - maxDuration: TimeSpan.FromMinutes(5)); + maxDuration: TimeSpan.FromMinutes(3)); - var testFile = GenerateTestFile(10.MB()); + seller.Marketplace.MakeStorageAvailable( + size: 10.GB(), + minPricePerBytePerSecond: 1.TestTokens(), + maxCollateral: 20.TestTokens(), + maxDuration: TimeSpan.FromMinutes(3)); + + sellerWithFailures.Marketplace.MakeStorageAvailable( + size: 10.GB(), + minPricePerBytePerSecond: 1.TestTokens(), + maxCollateral: 20.TestTokens(), + maxDuration: TimeSpan.FromMinutes(3)); + + var fileSize = 10.MB(); + var testFile = GenerateTestFile(fileSize); var contentId = buyer.UploadFile(testFile); - buyer.Marketplace.RequestStorage(contentId, + var purchaseContract = buyer.Marketplace.RequestStorage( + contentId, pricePerSlotPerSecond: 2.TestTokens(), requiredCollateral: 10.TestTokens(), minRequiredNumberOfNodes: 2, proofProbability: 2, - duration: TimeSpan.FromMinutes(4)); + duration: TimeSpan.FromMinutes(3)); // Time.Sleep(TimeSpan.FromMinutes(1)); // seller.Marketplace.AssertThatBalance(Is.LessThan(sellerInitialBalance), "Collateral was not placed."); - Time.Sleep(TimeSpan.FromMinutes(3)); + purchaseContract.WaitForStorageContractStarted(fileSize); + purchaseContract.WaitForStorageContractFinished(); var sellerBalance = seller.Marketplace.GetBalance(); sellerWithFailures.Marketplace.AssertThatBalance(Is.LessThan(sellerBalance), "Seller that was slashed should have less balance than seller that was not slashed."); + + new List(){seller, sellerWithFailures, buyer, validator}.ForEach(node => node.DownloadLog()); } } }