Add proofs test using pre-refactor code (needs to be updated)

This commit is contained in:
Eric 2023-11-14 12:40:18 +11:00
parent 496f8fa370
commit 9e3be4ba11
No known key found for this signature in database
2 changed files with 92 additions and 2 deletions

View File

@ -9,7 +9,7 @@ namespace CodexPlugin
{
private readonly MarketplaceStarter marketplaceStarter = new MarketplaceStarter();
private const string DefaultDockerImage = "codexstorage/nim-codex:latest-dist-tests";
private const string DefaultDockerImage = "codexstorage/nim-codex:sha-0f33ef8-dist-tests";
public const string ApiPortTag = "codex_api_port";
public const string ListenPortTag = "codex_listen_port";
public const string MetricsPortTag = "codex_metrics_port";
@ -26,7 +26,7 @@ namespace CodexPlugin
protected override void Initialize(StartupConfig startupConfig)
{
SetResourcesRequest(milliCPUs: 100, memory: 100.MB());
// SetResourcesRequest(milliCPUs: 100, memory: 100.MB());
//SetResourceLimits(milliCPUs: 4000, memory: 12.GB());
var config = startupConfig.Get<CodexStartupConfig>();

View File

@ -0,0 +1,90 @@
using CodexPlugin;
using NUnit.Framework;
using CodexContractsPlugin;
using Utils;
namespace CodexTests.MarketplaceTests
{
[TestFixture]
public class InvalidProofsTests : CodexDistTest
{
[Test]
public void HostThatMissesProofsIsPaidOutLessThanHostThatDoesNotMissProofs()
{
var sellerInitialBalance = 234.TestTokens();
var buyerInitialBalance = 1000.TestTokens();
Log("deploying seller...");
var seller = SetupCodexNode(s => s
.WithLogLevel(CodexLogLevel.Trace, "marketplace", "sales", "proving", "reservations", "node", "JSONRPC-HTTP-CLIENT", "JSONRPC-WS-CLIENT", "ethers", "clock")
.WithStorageQuota(20.GB())
.EnableMarketplace(sellerInitialBalance)
.WithName("seller"));
Log("seller deployed");
var sellerWithFailures = SetupCodexNode(s => s
.WithLogLevel(CodexLogLevel.Trace, "marketplace", "sales", "proving", "reservations", "node", "JSONRPC-HTTP-CLIENT", "JSONRPC-WS-CLIENT", "ethers", "clock")
.WithStorageQuota(20.GB())
.WithBootstrapNode(seller)
.WithSimulateProofFailures(2)
.EnableMarketplace(sellerInitialBalance)
.WithName("seller-with-failures"));
Log("seller with failures deployed");
var buyer = SetupCodexNode(s => s
.WithLogLevel(CodexLogLevel.Trace, "marketplace", "purchasing", "node", "restapi")
.WithBootstrapNode(seller)
.EnableMarketplace(buyerInitialBalance)
.WithName("buyer"));
Log("buyer deployed");
var validator = SetupCodexNode(s => s
.WithLogLevel(CodexLogLevel.Trace, "validator")
.WithBootstrapNode(seller)
// .WithValidator()
.EnableMarketplace(0.TestTokens(), 2.Eth(), true)
.WithName("validator"));
Log("validator deployed");
seller.Marketplace.AssertThatBalance(Is.EqualTo(sellerInitialBalance));
sellerWithFailures.Marketplace.AssertThatBalance(Is.EqualTo(sellerInitialBalance));
buyer.Marketplace.AssertThatBalance(Is.EqualTo(buyerInitialBalance));
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);
var purchaseContract = buyer.Marketplace.RequestStorage(
contentId,
pricePerSlotPerSecond: 2.TestTokens(),
requiredCollateral: 10.TestTokens(),
minRequiredNumberOfNodes: 2,
proofProbability: 2,
duration: TimeSpan.FromMinutes(3));
// sleep only to build up the geth logs
Time.Sleep(TimeSpan.FromMinutes(3));
new List<IOnlineCodexNode>(){seller, sellerWithFailures}.ForEach(node => node.DownloadGethLog());
// seller.Marketplace.AssertThatBalance(Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
purchaseContract.WaitForStorageContractFinished(fileSize);
// var sellerBalance = seller.Marketplace.GetBalance();
sellerWithFailures.Marketplace.AssertThatBalance(Is.LessThan(seller.Marketplace.GetBalance()), "Seller that was slashed should have less balance than seller that was not slashed.");
new List<IOnlineCodexNode>(){seller, sellerWithFailures, buyer, validator}.ForEach(node => node.DownloadLog());
}
}
}