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