2023-04-13 07:33:10 +00:00
|
|
|
|
using DistTestCore;
|
2023-04-13 09:30:19 +00:00
|
|
|
|
using DistTestCore.Codex;
|
2023-03-17 10:43:29 +00:00
|
|
|
|
using NUnit.Framework;
|
2023-04-18 13:33:12 +00:00
|
|
|
|
using Utils;
|
2023-03-17 10:43:29 +00:00
|
|
|
|
|
2023-03-21 12:20:21 +00:00
|
|
|
|
namespace Tests.BasicTests
|
2023-03-17 10:43:29 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2023-04-14 12:53:39 +00:00
|
|
|
|
public class ExampleTests : DistTest
|
2023-03-17 10:43:29 +00:00
|
|
|
|
{
|
2023-04-13 09:30:19 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void CodexLogExample()
|
|
|
|
|
{
|
|
|
|
|
var primary = SetupCodexNodes(1)
|
|
|
|
|
.WithLogLevel(CodexLogLevel.Trace)
|
|
|
|
|
.BringOnline()[0];
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
var group = SetupCodexNodes(2)
|
|
|
|
|
.EnableMetrics()
|
|
|
|
|
.BringOnline();
|
2023-03-26 08:45:01 +00:00
|
|
|
|
|
2023-04-13 12:36:17 +00:00
|
|
|
|
var group2 = SetupCodexNodes(2)
|
|
|
|
|
.EnableMetrics()
|
|
|
|
|
.BringOnline();
|
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-03-27 08:27:08 +00:00
|
|
|
|
|
2023-04-13 12:36:17 +00:00
|
|
|
|
primary.ConnectToPeer(secondary);
|
|
|
|
|
primary2.ConnectToPeer(secondary2);
|
2023-03-31 06:39:24 +00:00
|
|
|
|
|
2023-04-19 08:42:08 +00:00
|
|
|
|
Thread.Sleep(TimeSpan.FromMinutes(2));
|
2023-03-31 06:39:24 +00:00
|
|
|
|
|
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-03-31 06:39:24 +00:00
|
|
|
|
|
2023-04-14 10:37:05 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void MarketplaceExample()
|
|
|
|
|
{
|
2023-04-18 13:33:12 +00:00
|
|
|
|
var primary = SetupCodexNodes(1)
|
2023-04-24 12:09:23 +00:00
|
|
|
|
.WithLogLevel(CodexLogLevel.Trace)
|
2023-04-19 09:23:11 +00:00
|
|
|
|
.WithStorageQuota(11.GB())
|
2023-04-18 13:33:12 +00:00
|
|
|
|
.EnableMarketplace(initialBalance: 234.TestTokens())
|
|
|
|
|
.BringOnline()[0];
|
2023-04-14 10:37:05 +00:00
|
|
|
|
|
2023-04-19 08:42:08 +00:00
|
|
|
|
primary.Marketplace.AssertThatBalance(Is.EqualTo(234.TestTokens()));
|
2023-04-14 10:37:05 +00:00
|
|
|
|
|
2023-04-18 13:33:12 +00:00
|
|
|
|
var secondary = SetupCodexNodes(1)
|
2023-04-24 12:09:23 +00:00
|
|
|
|
.WithLogLevel(CodexLogLevel.Trace)
|
|
|
|
|
.WithBootstrapNode(primary)
|
2023-04-18 13:33:12 +00:00
|
|
|
|
.EnableMarketplace(initialBalance: 1000.TestTokens())
|
|
|
|
|
.BringOnline()[0];
|
|
|
|
|
|
|
|
|
|
primary.Marketplace.MakeStorageAvailable(
|
|
|
|
|
size: 10.GB(),
|
|
|
|
|
minPricePerBytePerSecond: 1.TestTokens(),
|
|
|
|
|
maxCollateral: 20.TestTokens(),
|
|
|
|
|
maxDuration: TimeSpan.FromMinutes(3));
|
2023-04-14 10:37:05 +00:00
|
|
|
|
|
2023-04-18 13:33:12 +00:00
|
|
|
|
var testFile = GenerateTestFile(10.MB());
|
|
|
|
|
var contentId = secondary.UploadFile(testFile);
|
2023-04-14 10:37:05 +00:00
|
|
|
|
|
2023-04-18 13:33:12 +00:00
|
|
|
|
secondary.Marketplace.RequestStorage(contentId,
|
|
|
|
|
pricePerBytePerSecond: 2.TestTokens(),
|
|
|
|
|
requiredCollateral: 10.TestTokens(),
|
|
|
|
|
minRequiredNumberOfNodes: 1,
|
|
|
|
|
proofProbability: 5,
|
|
|
|
|
duration: TimeSpan.FromMinutes(2));
|
2023-04-14 10:37:05 +00:00
|
|
|
|
|
2023-04-19 09:23:11 +00:00
|
|
|
|
Time.Sleep(TimeSpan.FromMinutes(1));
|
2023-04-14 10:37:05 +00:00
|
|
|
|
|
2023-04-19 09:23:11 +00:00
|
|
|
|
primary.Marketplace.AssertThatBalance(Is.LessThan(234.TestTokens()), "Collateral was not placed.");
|
2023-04-14 10:37:05 +00:00
|
|
|
|
|
2023-04-19 09:23:11 +00:00
|
|
|
|
Time.Sleep(TimeSpan.FromMinutes(2));
|
|
|
|
|
|
|
|
|
|
primary.Marketplace.AssertThatBalance(Is.GreaterThan(234.TestTokens()), "Storer was not paid for storage.");
|
|
|
|
|
secondary.Marketplace.AssertThatBalance(Is.LessThan(1000.TestTokens()), "Contractor was not charged for storage.");
|
2023-04-14 10:37:05 +00:00
|
|
|
|
}
|
2023-03-17 10:43:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|