cs-codex-dist-tests/Tests/BasicTests/ExampleTests.cs

86 lines
2.9 KiB
C#
Raw Normal View History

2023-04-13 07:33:10 +00:00
using DistTestCore;
using NUnit.Framework;
2023-03-21 12:20:21 +00:00
namespace Tests.BasicTests
{
[TestFixture]
2023-04-14 12:53:39 +00:00
public class ExampleTests : DistTest
{
2023-04-13 09:30:19 +00:00
[Test]
public void CodexLogExample()
{
2023-05-31 11:34:12 +00:00
var primary = SetupCodexNode();
2023-04-13 09:30:19 +00:00
primary.UploadFile(GenerateTestFile(5.MB()));
var log = primary.DownloadLog();
log.AssertLogContains("Uploaded file");
}
2023-04-13 12:36:17 +00:00
[Test]
public void TwoMetricsExample()
{
2023-04-25 10:52:11 +00:00
var group = SetupCodexNodes(2, s => s.EnableMetrics());
var group2 = SetupCodexNodes(2, s => s.EnableMetrics());
2023-03-22 13:49:01 +00:00
2023-04-13 12:36:17 +00:00
var primary = group[0];
var secondary = group[1];
var primary2 = group2[0];
var secondary2 = group2[1];
2023-04-13 12:36:17 +00:00
primary.ConnectToPeer(secondary);
primary2.ConnectToPeer(secondary2);
Thread.Sleep(TimeSpan.FromMinutes(2));
2023-04-13 12:36:17 +00:00
primary.Metrics.AssertThat("libp2p_peers", Is.EqualTo(1));
primary2.Metrics.AssertThat("libp2p_peers", Is.EqualTo(1));
}
2023-04-14 10:37:05 +00:00
[Test]
public void MarketplaceExample()
{
var sellerInitialBalance = 234.TestTokens();
var buyerInitialBalance = 1000.TestTokens();
var fileSize = 10.MB();
2023-04-14 10:37:05 +00:00
var seller = SetupCodexNode(s => s
.WithStorageQuota(11.GB())
.EnableMarketplace(sellerInitialBalance));
seller.Marketplace.AssertThatBalance(Is.EqualTo(sellerInitialBalance));
seller.Marketplace.MakeStorageAvailable(
size: 10.GB(),
minPricePerBytePerSecond: 1.TestTokens(),
maxCollateral: 20.TestTokens(),
maxDuration: TimeSpan.FromMinutes(3));
2023-04-14 10:37:05 +00:00
var testFile = GenerateTestFile(fileSize);
2023-04-14 10:37:05 +00:00
var buyer = SetupCodexNode(s => s
.WithBootstrapNode(seller)
.EnableMarketplace(buyerInitialBalance));
2023-07-31 07:16:52 +00:00
buyer.Marketplace.AssertThatBalance(Is.EqualTo(buyerInitialBalance));
var contentId = buyer.UploadFile(testFile);
var purchaseContract = buyer.Marketplace.RequestStorage(contentId,
2023-06-27 13:28:00 +00:00
pricePerSlotPerSecond: 2.TestTokens(),
requiredCollateral: 10.TestTokens(),
minRequiredNumberOfNodes: 1,
proofProbability: 5,
2023-05-03 08:21:15 +00:00
duration: TimeSpan.FromMinutes(1));
2023-04-14 10:37:05 +00:00
purchaseContract.WaitForStorageContractStarted(fileSize);
2023-04-14 10:37:05 +00:00
seller.Marketplace.AssertThatBalance(Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
2023-04-14 10:37:05 +00:00
purchaseContract.WaitForStorageContractFinished();
seller.Marketplace.AssertThatBalance(Is.GreaterThan(sellerInitialBalance), "Seller was not paid for storage.");
buyer.Marketplace.AssertThatBalance(Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage.");
2023-04-14 10:37:05 +00:00
}
}
}