restores balance asserts.
This commit is contained in:
parent
4bc225f1d9
commit
6cbf363bb1
|
@ -7,7 +7,9 @@ namespace CodexContractsPlugin
|
|||
{
|
||||
string MarketplaceAddress { get; }
|
||||
|
||||
void MintTestTokens(IGethNode gethNode, IHasEthAddress owner, TestToken testTokens);
|
||||
void MintTestTokens(IGethNode gethNode, IEthAddress ethAddress, TestToken testTokens);
|
||||
TestToken GetTestTokenBalance(IGethNode gethNode, IHasEthAddress owner);
|
||||
TestToken GetTestTokenBalance(IGethNode gethNode, IEthAddress ethAddress);
|
||||
}
|
||||
|
||||
|
@ -27,12 +29,22 @@ namespace CodexContractsPlugin
|
|||
public string Abi { 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)
|
||||
{
|
||||
var interaction = new ContractInteractions(log, gethNode);
|
||||
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)
|
||||
{
|
||||
var interaction = new ContractInteractions(log, gethNode);
|
||||
|
|
|
@ -9,12 +9,12 @@ using Utils;
|
|||
namespace Tests.BasicTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ExampleTests : DistTest
|
||||
public class ExampleTests : CodexDistTest
|
||||
{
|
||||
[Test]
|
||||
public void CodexLogExample()
|
||||
{
|
||||
var primary = Ci.SetupCodexNode();
|
||||
var primary = AddCodex();
|
||||
|
||||
primary.UploadFile(GenerateTestFile(5.MB()));
|
||||
|
||||
|
@ -26,8 +26,8 @@ namespace Tests.BasicTests
|
|||
[Test]
|
||||
public void TwoMetricsExample()
|
||||
{
|
||||
var group = Ci.SetupCodexNodes(2, s => s.EnableMetrics());
|
||||
var group2 = Ci.SetupCodexNodes(2, s => s.EnableMetrics());
|
||||
var group = AddCodex(2, s => s.EnableMetrics());
|
||||
var group2 = AddCodex(2, s => s.EnableMetrics());
|
||||
|
||||
var primary = group[0];
|
||||
var secondary = group[1];
|
||||
|
@ -48,58 +48,52 @@ namespace Tests.BasicTests
|
|||
[Test]
|
||||
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 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();
|
||||
geth.SendEth(node, 10.Eth());
|
||||
var nodeBalance = geth.GetEthBalance(node);
|
||||
AssertBalance(geth, contracts, seller, Is.EqualTo(sellerInitialBalance));
|
||||
seller.Marketplace.MakeStorageAvailable(
|
||||
size: 10.GB(),
|
||||
minPricePerBytePerSecond: 1.TestTokens(),
|
||||
maxCollateral: 20.TestTokens(),
|
||||
maxDuration: TimeSpan.FromMinutes(3));
|
||||
|
||||
contracts.MintTestTokens(geth, node.EthAddress, 100.TestTokens());
|
||||
contracts.GetTestTokenBalance(geth, node.EthAddress);
|
||||
var testFile = GenerateTestFile(fileSize);
|
||||
|
||||
//var sellerInitialBalance = 234.TestTokens();
|
||||
//var buyerInitialBalance = 1000.TestTokens();
|
||||
//var fileSize = 10.MB();
|
||||
var buyer = AddCodex(s => s
|
||||
.WithBootstrapNode(seller)
|
||||
.EnableMarketplace(geth, contracts));
|
||||
geth.SendEth(seller, 10.Eth());
|
||||
contracts.MintTestTokens(geth, seller, buyerInitialBalance);
|
||||
|
||||
//var seller = Ci.SetupCodexNode(s => s
|
||||
// .WithStorageQuota(11.GB())
|
||||
// .EnableMarketplace(sellerInitialBalance));
|
||||
AssertBalance(geth, contracts, buyer, Is.EqualTo(buyerInitialBalance));
|
||||
|
||||
//seller.Marketplace.AssertThatBalance(Is.EqualTo(sellerInitialBalance));
|
||||
//seller.Marketplace.MakeStorageAvailable(
|
||||
// size: 10.GB(),
|
||||
// minPricePerBytePerSecond: 1.TestTokens(),
|
||||
// maxCollateral: 20.TestTokens(),
|
||||
// maxDuration: TimeSpan.FromMinutes(3));
|
||||
var contentId = buyer.UploadFile(testFile);
|
||||
var purchaseContract = buyer.Marketplace.RequestStorage(contentId,
|
||||
pricePerSlotPerSecond: 2.TestTokens(),
|
||||
requiredCollateral: 10.TestTokens(),
|
||||
minRequiredNumberOfNodes: 1,
|
||||
proofProbability: 5,
|
||||
duration: TimeSpan.FromMinutes(1));
|
||||
|
||||
//var testFile = GenerateTestFile(fileSize);
|
||||
purchaseContract.WaitForStorageContractStarted(fileSize);
|
||||
|
||||
//var buyer = Ci.SetupCodexNode(s => s
|
||||
// .WithBootstrapNode(seller)
|
||||
// .EnableMarketplace(buyerInitialBalance));
|
||||
AssertBalance(geth, contracts, seller, Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
|
||||
|
||||
//buyer.Marketplace.AssertThatBalance(Is.EqualTo(buyerInitialBalance));
|
||||
purchaseContract.WaitForStorageContractFinished();
|
||||
|
||||
//var contentId = buyer.UploadFile(testFile);
|
||||
//var purchaseContract = buyer.Marketplace.RequestStorage(contentId,
|
||||
// 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.");
|
||||
AssertBalance(geth, contracts, seller, Is.GreaterThan(sellerInitialBalance), "Seller was not paid for storage.");
|
||||
AssertBalance(geth, contracts, buyer, Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
using CodexPlugin;
|
||||
using CodexContractsPlugin;
|
||||
using CodexPlugin;
|
||||
using DistTestCore;
|
||||
using DistTestCore.Helpers;
|
||||
using GethPlugin;
|
||||
using NUnit.Framework.Constraints;
|
||||
using Utils;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
|
@ -49,6 +53,11 @@ namespace Tests
|
|||
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)
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue