2023-04-13 07:33:10 +00:00
|
|
|
|
using DistTestCore;
|
2023-04-13 09:30:19 +00:00
|
|
|
|
using DistTestCore.Codex;
|
2023-04-13 08:11:33 +00:00
|
|
|
|
using KubernetesWorkflow;
|
2023-03-17 10:43:29 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
2023-03-21 12:20:21 +00:00
|
|
|
|
namespace Tests.BasicTests
|
2023-03-17 10:43:29 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2023-03-21 12:20:21 +00:00
|
|
|
|
public class SimpleTests : DistTest
|
2023-03-17 10:43:29 +00:00
|
|
|
|
{
|
2023-03-26 08:57:54 +00:00
|
|
|
|
[Test]
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public void OneClientTest()
|
2023-03-26 08:57:54 +00:00
|
|
|
|
{
|
2023-04-13 07:33:10 +00:00
|
|
|
|
var primary = SetupCodexNodes(1).BringOnline()[0];
|
2023-03-23 11:41:34 +00:00
|
|
|
|
|
2023-04-13 09:07:36 +00:00
|
|
|
|
PerformOneClientTest(primary);
|
|
|
|
|
}
|
2023-03-22 13:49:01 +00:00
|
|
|
|
|
2023-04-13 09:07:36 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void RestartTest()
|
|
|
|
|
{
|
|
|
|
|
var group = SetupCodexNodes(1).BringOnline();
|
2023-03-24 13:16:59 +00:00
|
|
|
|
|
2023-04-13 09:07:36 +00:00
|
|
|
|
var setup = group.BringOffline();
|
2023-03-24 13:16:59 +00:00
|
|
|
|
|
2023-04-13 09:07:36 +00:00
|
|
|
|
var primary = setup.BringOnline()[0];
|
|
|
|
|
|
|
|
|
|
PerformOneClientTest(primary);
|
2023-03-26 08:57:54 +00:00
|
|
|
|
}
|
2023-03-26 08:45:01 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TwoClientsOnePodTest()
|
|
|
|
|
{
|
|
|
|
|
var group = SetupCodexNodes(2).BringOnline();
|
2023-04-12 06:40:23 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
var primary = group[0];
|
|
|
|
|
var secondary = group[1];
|
2023-04-12 06:40:23 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
PerformTwoClientTest(primary, secondary);
|
|
|
|
|
}
|
2023-04-12 06:40:23 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TwoClientsTwoPodsTest()
|
|
|
|
|
{
|
|
|
|
|
var primary = SetupCodexNodes(1).BringOnline()[0];
|
2023-04-10 07:05:27 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
var secondary = SetupCodexNodes(1).BringOnline()[0];
|
2023-04-10 07:05:27 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
PerformTwoClientTest(primary, secondary);
|
|
|
|
|
}
|
2023-04-10 12:48:16 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
[Test]
|
|
|
|
|
[Ignore("Requires Location map to be configured for k8s cluster.")]
|
|
|
|
|
public void TwoClientsTwoLocationsTest()
|
|
|
|
|
{
|
|
|
|
|
var primary = SetupCodexNodes(1)
|
|
|
|
|
.At(Location.BensLaptop)
|
|
|
|
|
.BringOnline()[0];
|
2023-04-10 07:05:27 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
var secondary = SetupCodexNodes(1)
|
|
|
|
|
.At(Location.BensOldGamingMachine)
|
|
|
|
|
.BringOnline()[0];
|
2023-04-10 07:05:27 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
PerformTwoClientTest(primary, secondary);
|
|
|
|
|
}
|
2023-04-10 07:05:27 +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-13 12:36:17 +00:00
|
|
|
|
Thread.Sleep(TimeSpan.FromMinutes(5));
|
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-13 07:33:10 +00:00
|
|
|
|
//[Test]
|
|
|
|
|
//public void MarketplaceExample()
|
|
|
|
|
//{
|
|
|
|
|
// var group = SetupCodexNodes(4)
|
|
|
|
|
// .WithStorageQuota(10.GB())
|
|
|
|
|
// .EnableMarketplace(initialBalance: 20)
|
|
|
|
|
// .BringOnline();
|
2023-03-31 06:39:24 +00:00
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
// foreach (var node in group)
|
|
|
|
|
// {
|
|
|
|
|
// Assert.That(node.Marketplace.GetBalance(), Is.EqualTo(20));
|
|
|
|
|
// }
|
2023-03-31 06:39:24 +00:00
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
// // WIP: Balance is now only ETH.
|
|
|
|
|
// // todo: All nodes should have plenty of ETH to pay for transactions.
|
|
|
|
|
// // todo: Upload our own token, use this exclusively. ETH should be invisibile to the tests.
|
2023-03-31 06:39:24 +00:00
|
|
|
|
|
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
// //var secondary = SetupCodexNodes(1)
|
|
|
|
|
// // .EnableMarketplace(initialBalance: 1000)
|
|
|
|
|
// // .BringOnline()[0];
|
2023-03-27 12:49:34 +00:00
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
// //primary.ConnectToPeer(secondary);
|
|
|
|
|
// //primary.Marketplace.MakeStorageAvailable(10.GB(), minPricePerBytePerSecond: 1, maxCollateral: 20);
|
2023-03-27 12:49:34 +00:00
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
// //var testFile = GenerateTestFile(10.MB());
|
|
|
|
|
// //var contentId = secondary.UploadFile(testFile);
|
|
|
|
|
// //secondary.Marketplace.RequestStorage(contentId, pricePerBytePerSecond: 2,
|
|
|
|
|
// // requiredCollateral: 10, minRequiredNumberOfNodes: 1);
|
2023-03-27 12:49:34 +00:00
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
// //primary.Marketplace.AssertThatBalance(Is.LessThan(20), "Collateral was not placed.");
|
|
|
|
|
// //var primaryBalance = primary.Marketplace.GetBalance();
|
2023-03-27 08:27:08 +00:00
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
// //secondary.Marketplace.AssertThatBalance(Is.LessThan(1000), "Contractor was not charged for storage.");
|
|
|
|
|
// //primary.Marketplace.AssertThatBalance(Is.GreaterThan(primaryBalance), "Storer was not paid for storage.");
|
|
|
|
|
//}
|
2023-03-19 09:49:03 +00:00
|
|
|
|
|
2023-04-13 09:07:36 +00:00
|
|
|
|
private void PerformOneClientTest(IOnlineCodexNode primary)
|
|
|
|
|
{
|
|
|
|
|
var testFile = GenerateTestFile(1.MB());
|
|
|
|
|
|
|
|
|
|
var contentId = primary.UploadFile(testFile);
|
|
|
|
|
|
|
|
|
|
var downloadedFile = primary.DownloadContent(contentId);
|
|
|
|
|
|
|
|
|
|
testFile.AssertIsEqual(downloadedFile);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
private void PerformTwoClientTest(IOnlineCodexNode primary, IOnlineCodexNode secondary)
|
|
|
|
|
{
|
|
|
|
|
primary.ConnectToPeer(secondary);
|
2023-03-19 09:49:03 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
var testFile = GenerateTestFile(1.MB());
|
2023-03-19 09:49:03 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
var contentId = primary.UploadFile(testFile);
|
2023-03-22 10:27:51 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
var downloadedFile = secondary.DownloadContent(contentId);
|
2023-04-13 07:33:10 +00:00
|
|
|
|
|
2023-04-13 08:11:33 +00:00
|
|
|
|
testFile.AssertIsEqual(downloadedFile);
|
|
|
|
|
}
|
2023-03-17 10:43:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|