restores balance asserts.

This commit is contained in:
ThatBen 2023-09-19 16:22:07 +02:00
parent 4bc225f1d9
commit 6cbf363bb1
3 changed files with 64 additions and 49 deletions

View File

@ -7,7 +7,9 @@ namespace CodexContractsPlugin
{ {
string MarketplaceAddress { get; } string MarketplaceAddress { get; }
void MintTestTokens(IGethNode gethNode, IHasEthAddress owner, TestToken testTokens);
void MintTestTokens(IGethNode gethNode, IEthAddress ethAddress, TestToken testTokens); void MintTestTokens(IGethNode gethNode, IEthAddress ethAddress, TestToken testTokens);
TestToken GetTestTokenBalance(IGethNode gethNode, IHasEthAddress owner);
TestToken GetTestTokenBalance(IGethNode gethNode, IEthAddress ethAddress); TestToken GetTestTokenBalance(IGethNode gethNode, IEthAddress ethAddress);
} }
@ -27,12 +29,22 @@ namespace CodexContractsPlugin
public string Abi { get; } public string Abi { get; }
public string TokenAddress { get; } public string TokenAddress { get; }
public void MintTestTokens(IGethNode gethNode, IHasEthAddress owner, TestToken testTokens)
{
MintTestTokens(gethNode, owner.EthAddress, testTokens);
}
public void MintTestTokens(IGethNode gethNode, IEthAddress ethAddress, TestToken testTokens) public void MintTestTokens(IGethNode gethNode, IEthAddress ethAddress, TestToken testTokens)
{ {
var interaction = new ContractInteractions(log, gethNode); var interaction = new ContractInteractions(log, gethNode);
interaction.MintTestTokens(ethAddress, testTokens.Amount, TokenAddress); interaction.MintTestTokens(ethAddress, testTokens.Amount, TokenAddress);
} }
public TestToken GetTestTokenBalance(IGethNode gethNode, IHasEthAddress owner)
{
return GetTestTokenBalance(gethNode, owner.EthAddress);
}
public TestToken GetTestTokenBalance(IGethNode gethNode, IEthAddress ethAddress) public TestToken GetTestTokenBalance(IGethNode gethNode, IEthAddress ethAddress)
{ {
var interaction = new ContractInteractions(log, gethNode); var interaction = new ContractInteractions(log, gethNode);

View File

@ -9,12 +9,12 @@ using Utils;
namespace Tests.BasicTests namespace Tests.BasicTests
{ {
[TestFixture] [TestFixture]
public class ExampleTests : DistTest public class ExampleTests : CodexDistTest
{ {
[Test] [Test]
public void CodexLogExample() public void CodexLogExample()
{ {
var primary = Ci.SetupCodexNode(); var primary = AddCodex();
primary.UploadFile(GenerateTestFile(5.MB())); primary.UploadFile(GenerateTestFile(5.MB()));
@ -26,8 +26,8 @@ namespace Tests.BasicTests
[Test] [Test]
public void TwoMetricsExample() public void TwoMetricsExample()
{ {
var group = Ci.SetupCodexNodes(2, s => s.EnableMetrics()); var group = AddCodex(2, s => s.EnableMetrics());
var group2 = Ci.SetupCodexNodes(2, s => s.EnableMetrics()); var group2 = AddCodex(2, s => s.EnableMetrics());
var primary = group[0]; var primary = group[0];
var secondary = group[1]; var secondary = group[1];
@ -48,58 +48,52 @@ namespace Tests.BasicTests
[Test] [Test]
public void MarketplaceExample() public void MarketplaceExample()
{ {
var geth = Ci.StartGethNode(s => s.IsMiner().WithName("disttest-geth")); var sellerInitialBalance = 234.TestTokens();
var buyerInitialBalance = 1000.TestTokens();
var fileSize = 10.MB();
var geth = Ci.StartGethNode(s => s.IsMiner().WithName("disttest-geth"));
var contracts = Ci.DeployCodexContracts(geth); var contracts = Ci.DeployCodexContracts(geth);
var node = Ci.SetupCodexNode(s => s.EnableMarketplace(geth, contracts)); var seller = AddCodex(s => s
.WithStorageQuota(11.GB())
.EnableMarketplace(geth, contracts));
geth.SendEth(seller, 10.Eth());
contracts.MintTestTokens(geth, seller, sellerInitialBalance);
var myBalance = geth.GetEthBalance(); AssertBalance(geth, contracts, seller, Is.EqualTo(sellerInitialBalance));
geth.SendEth(node, 10.Eth()); seller.Marketplace.MakeStorageAvailable(
var nodeBalance = geth.GetEthBalance(node); size: 10.GB(),
minPricePerBytePerSecond: 1.TestTokens(),
maxCollateral: 20.TestTokens(),
maxDuration: TimeSpan.FromMinutes(3));
contracts.MintTestTokens(geth, node.EthAddress, 100.TestTokens()); var testFile = GenerateTestFile(fileSize);
contracts.GetTestTokenBalance(geth, node.EthAddress);
//var sellerInitialBalance = 234.TestTokens(); var buyer = AddCodex(s => s
//var buyerInitialBalance = 1000.TestTokens(); .WithBootstrapNode(seller)
//var fileSize = 10.MB(); .EnableMarketplace(geth, contracts));
geth.SendEth(seller, 10.Eth());
contracts.MintTestTokens(geth, seller, buyerInitialBalance);
//var seller = Ci.SetupCodexNode(s => s AssertBalance(geth, contracts, buyer, Is.EqualTo(buyerInitialBalance));
// .WithStorageQuota(11.GB())
// .EnableMarketplace(sellerInitialBalance));
//seller.Marketplace.AssertThatBalance(Is.EqualTo(sellerInitialBalance)); var contentId = buyer.UploadFile(testFile);
//seller.Marketplace.MakeStorageAvailable( var purchaseContract = buyer.Marketplace.RequestStorage(contentId,
// size: 10.GB(), pricePerSlotPerSecond: 2.TestTokens(),
// minPricePerBytePerSecond: 1.TestTokens(), requiredCollateral: 10.TestTokens(),
// maxCollateral: 20.TestTokens(), minRequiredNumberOfNodes: 1,
// maxDuration: TimeSpan.FromMinutes(3)); proofProbability: 5,
duration: TimeSpan.FromMinutes(1));
//var testFile = GenerateTestFile(fileSize); purchaseContract.WaitForStorageContractStarted(fileSize);
//var buyer = Ci.SetupCodexNode(s => s AssertBalance(geth, contracts, seller, Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
// .WithBootstrapNode(seller)
// .EnableMarketplace(buyerInitialBalance));
//buyer.Marketplace.AssertThatBalance(Is.EqualTo(buyerInitialBalance)); purchaseContract.WaitForStorageContractFinished();
//var contentId = buyer.UploadFile(testFile); AssertBalance(geth, contracts, seller, Is.GreaterThan(sellerInitialBalance), "Seller was not paid for storage.");
//var purchaseContract = buyer.Marketplace.RequestStorage(contentId, AssertBalance(geth, contracts, buyer, Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage.");
// pricePerSlotPerSecond: 2.TestTokens(),
// requiredCollateral: 10.TestTokens(),
// minRequiredNumberOfNodes: 1,
// proofProbability: 5,
// duration: TimeSpan.FromMinutes(1));
//purchaseContract.WaitForStorageContractStarted(fileSize);
//seller.Marketplace.AssertThatBalance(Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
//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.");
} }
} }
} }

View File

@ -1,6 +1,10 @@
using CodexPlugin; using CodexContractsPlugin;
using CodexPlugin;
using DistTestCore; using DistTestCore;
using DistTestCore.Helpers; using DistTestCore.Helpers;
using GethPlugin;
using NUnit.Framework.Constraints;
using Utils;
namespace Tests namespace Tests
{ {
@ -49,6 +53,11 @@ namespace Tests
return onlineCodexNodes; return onlineCodexNodes;
} }
public void AssertBalance(IGethNode gethNode, ICodexContracts contracts, ICodexNode codexNode, Constraint constraint, string msg = "")
{
AssertHelpers.RetryAssert(constraint, () => contracts.GetTestTokenBalance(gethNode, codexNode), nameof(AssertBalance) + msg);
}
protected virtual void OnCodexSetup(ICodexSetup setup) protected virtual void OnCodexSetup(ICodexSetup setup)
{ {
} }