Cleans up some gethnode arguments.
This commit is contained in:
parent
901259d0fa
commit
85ad0b414f
|
@ -7,41 +7,43 @@ namespace CodexContractsPlugin
|
|||
{
|
||||
CodexContractsDeployment Deployment { get; }
|
||||
|
||||
void MintTestTokens(IGethNode gethNode, IHasEthAddress owner, TestToken testTokens);
|
||||
void MintTestTokens(IGethNode gethNode, EthAddress ethAddress, TestToken testTokens);
|
||||
TestToken GetTestTokenBalance(IGethNode gethNode, IHasEthAddress owner);
|
||||
TestToken GetTestTokenBalance(IGethNode gethNode, EthAddress ethAddress);
|
||||
void MintTestTokens(IHasEthAddress owner, TestToken testTokens);
|
||||
void MintTestTokens(EthAddress ethAddress, TestToken testTokens);
|
||||
TestToken GetTestTokenBalance(IHasEthAddress owner);
|
||||
TestToken GetTestTokenBalance(EthAddress ethAddress);
|
||||
}
|
||||
|
||||
public class CodexContractsAccess : ICodexContracts
|
||||
{
|
||||
private readonly ILog log;
|
||||
private readonly IGethNode gethNode;
|
||||
|
||||
public CodexContractsAccess(ILog log, CodexContractsDeployment deployment)
|
||||
public CodexContractsAccess(ILog log, IGethNode gethNode, CodexContractsDeployment deployment)
|
||||
{
|
||||
this.log = log;
|
||||
this.gethNode = gethNode;
|
||||
Deployment = deployment;
|
||||
}
|
||||
|
||||
public CodexContractsDeployment Deployment { get; }
|
||||
|
||||
public void MintTestTokens(IGethNode gethNode, IHasEthAddress owner, TestToken testTokens)
|
||||
public void MintTestTokens(IHasEthAddress owner, TestToken testTokens)
|
||||
{
|
||||
MintTestTokens(gethNode, owner.EthAddress, testTokens);
|
||||
MintTestTokens(owner.EthAddress, testTokens);
|
||||
}
|
||||
|
||||
public void MintTestTokens(IGethNode gethNode, EthAddress ethAddress, TestToken testTokens)
|
||||
public void MintTestTokens(EthAddress ethAddress, TestToken testTokens)
|
||||
{
|
||||
var interaction = new ContractInteractions(log, gethNode);
|
||||
interaction.MintTestTokens(ethAddress, testTokens.Amount, Deployment.TokenAddress);
|
||||
}
|
||||
|
||||
public TestToken GetTestTokenBalance(IGethNode gethNode, IHasEthAddress owner)
|
||||
public TestToken GetTestTokenBalance(IHasEthAddress owner)
|
||||
{
|
||||
return GetTestTokenBalance(gethNode, owner.EthAddress);
|
||||
return GetTestTokenBalance(owner.EthAddress);
|
||||
}
|
||||
|
||||
public TestToken GetTestTokenBalance(IGethNode gethNode, EthAddress ethAddress)
|
||||
public TestToken GetTestTokenBalance(EthAddress ethAddress)
|
||||
{
|
||||
var interaction = new ContractInteractions(log, gethNode);
|
||||
var balance = interaction.GetBalance(Deployment.TokenAddress, ethAddress.Address);
|
||||
|
|
|
@ -35,10 +35,10 @@ namespace CodexContractsPlugin
|
|||
return starter.Deploy(ci, gethNode);
|
||||
}
|
||||
|
||||
public ICodexContracts WrapDeploy(CodexContractsDeployment deployment)
|
||||
public ICodexContracts WrapDeploy(IGethNode gethNode, CodexContractsDeployment deployment)
|
||||
{
|
||||
deployment = SerializeGate.Gate(deployment);
|
||||
return starter.Wrap(deployment);
|
||||
return starter.Wrap(gethNode, deployment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,9 +45,9 @@ namespace CodexContractsPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public ICodexContracts Wrap(CodexContractsDeployment deployment)
|
||||
public ICodexContracts Wrap(IGethNode gethNode, CodexContractsDeployment deployment)
|
||||
{
|
||||
return new CodexContractsAccess(tools.GetLog(), deployment);
|
||||
return new CodexContractsAccess(tools.GetLog(), gethNode, deployment);
|
||||
}
|
||||
|
||||
private CodexContractsDeployment DeployContract(RunningContainer container, IStartupWorkflow workflow, IGethNode gethNode)
|
||||
|
|
|
@ -10,15 +10,15 @@ namespace CodexContractsPlugin
|
|||
return Plugin(ci).DeployContracts(ci, gethNode);
|
||||
}
|
||||
|
||||
public static ICodexContracts WrapCodexContractsDeployment(this CoreInterface ci, CodexContractsDeployment deployment)
|
||||
public static ICodexContracts WrapCodexContractsDeployment(this CoreInterface ci, IGethNode gethNode, CodexContractsDeployment deployment)
|
||||
{
|
||||
return Plugin(ci).WrapDeploy(deployment);
|
||||
return Plugin(ci).WrapDeploy(gethNode, deployment);
|
||||
}
|
||||
|
||||
public static ICodexContracts StartCodexContracts(this CoreInterface ci, IGethNode gethNode)
|
||||
{
|
||||
var deployment = DeployCodexContracts(ci, gethNode);
|
||||
return WrapCodexContractsDeployment(ci, deployment);
|
||||
return WrapCodexContractsDeployment(ci, gethNode, deployment);
|
||||
}
|
||||
|
||||
private static CodexContractsPlugin Plugin(CoreInterface ci)
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace CodexPlugin
|
|||
foreach (var node in result)
|
||||
{
|
||||
mconfig.GethNode.SendEth(node, mconfig.InitialEth);
|
||||
mconfig.CodexContracts.MintTestTokens(mconfig.GethNode, node, mconfig.InitialTokens);
|
||||
mconfig.CodexContracts.MintTestTokens(node, mconfig.InitialTokens);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace CodexTests.BasicTests
|
|||
.EnableMarketplace(geth, contracts, initialEth: 10.Eth(), initialTokens: sellerInitialBalance, isValidator: true)
|
||||
.WithSimulateProofFailures(failEveryNProofs: 3));
|
||||
|
||||
AssertBalance(geth, contracts, seller, Is.EqualTo(sellerInitialBalance));
|
||||
AssertBalance(contracts, seller, Is.EqualTo(sellerInitialBalance));
|
||||
seller.Marketplace.MakeStorageAvailable(
|
||||
size: 10.GB(),
|
||||
minPriceForTotalSpace: 1.TestTokens(),
|
||||
|
@ -73,7 +73,7 @@ namespace CodexTests.BasicTests
|
|||
.WithBootstrapNode(seller)
|
||||
.EnableMarketplace(geth, contracts, initialEth: 10.Eth(), initialTokens: buyerInitialBalance));
|
||||
|
||||
AssertBalance(geth, contracts, buyer, Is.EqualTo(buyerInitialBalance));
|
||||
AssertBalance(contracts, buyer, Is.EqualTo(buyerInitialBalance));
|
||||
|
||||
var contentId = buyer.UploadFile(testFile);
|
||||
var purchaseContract = buyer.Marketplace.RequestStorage(contentId,
|
||||
|
@ -85,12 +85,12 @@ namespace CodexTests.BasicTests
|
|||
|
||||
purchaseContract.WaitForStorageContractStarted(fileSize);
|
||||
|
||||
AssertBalance(geth, contracts, seller, Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
|
||||
AssertBalance(contracts, seller, Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
|
||||
|
||||
purchaseContract.WaitForStorageContractFinished();
|
||||
|
||||
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.");
|
||||
AssertBalance(contracts, seller, Is.GreaterThan(sellerInitialBalance), "Seller was not paid for storage.");
|
||||
AssertBalance(contracts, buyer, Is.LessThan(buyerInitialBalance), "Buyer was not charged for storage.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,9 +77,9 @@ namespace CodexTests
|
|||
return onlineCodexNodes;
|
||||
}
|
||||
|
||||
public void AssertBalance(IGethNode gethNode, ICodexContracts contracts, ICodexNode codexNode, Constraint constraint, string msg = "")
|
||||
public void AssertBalance(ICodexContracts contracts, ICodexNode codexNode, Constraint constraint, string msg = "")
|
||||
{
|
||||
AssertHelpers.RetryAssert(constraint, () => contracts.GetTestTokenBalance(gethNode, codexNode), nameof(AssertBalance) + msg);
|
||||
AssertHelpers.RetryAssert(constraint, () => contracts.GetTestTokenBalance(codexNode), nameof(AssertBalance) + msg);
|
||||
}
|
||||
|
||||
protected virtual void OnCodexSetup(ICodexSetup setup)
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace BiblioTech
|
|||
var contractsDeployment = codexDeployment.CodexContractsDeployment;
|
||||
|
||||
var gethNode = ci.WrapGethDeployment(gethDeployment);
|
||||
var contracts = ci.WrapCodexContractsDeployment(contractsDeployment);
|
||||
var contracts = ci.WrapCodexContractsDeployment(gethNode, contractsDeployment);
|
||||
|
||||
await Execute(context, gethNode, contracts);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace BiblioTech.Commands
|
|||
}
|
||||
|
||||
var eth = gethNode.GetEthBalance(addr);
|
||||
var testTokens = contracts.GetTestTokenBalance(gethNode, addr);
|
||||
var testTokens = contracts.GetTestTokenBalance(addr);
|
||||
|
||||
await context.Followup($"{context.Command.User.Username} has {eth} and {testTokens}.");
|
||||
}
|
||||
|
|
|
@ -38,18 +38,18 @@ namespace BiblioTech.Commands
|
|||
var report = new List<string>();
|
||||
|
||||
var sentEth = ProcessEth(gethNode, addr, report);
|
||||
var mintedTokens = ProcessTokens(gethNode, contracts, addr, report);
|
||||
var mintedTokens = ProcessTokens(contracts, addr, report);
|
||||
|
||||
Program.UserRepo.AddMintEventForUser(userId, addr, sentEth, mintedTokens);
|
||||
|
||||
await context.Followup(string.Join(Environment.NewLine, report));
|
||||
}
|
||||
|
||||
private TestToken ProcessTokens(IGethNode gethNode, ICodexContracts contracts, EthAddress addr, List<string> report)
|
||||
private TestToken ProcessTokens(ICodexContracts contracts, EthAddress addr, List<string> report)
|
||||
{
|
||||
if (ShouldMintTestTokens(gethNode, contracts, addr))
|
||||
if (ShouldMintTestTokens(contracts, addr))
|
||||
{
|
||||
contracts.MintTestTokens(gethNode, addr, defaultTestTokensToMint);
|
||||
contracts.MintTestTokens(addr, defaultTestTokensToMint);
|
||||
report.Add($"Minted {defaultTestTokensToMint}.");
|
||||
return defaultTestTokensToMint;
|
||||
}
|
||||
|
@ -70,9 +70,9 @@ namespace BiblioTech.Commands
|
|||
return 0.Eth();
|
||||
}
|
||||
|
||||
private bool ShouldMintTestTokens(IGethNode gethNode, ICodexContracts contracts, EthAddress addr)
|
||||
private bool ShouldMintTestTokens(ICodexContracts contracts, EthAddress addr)
|
||||
{
|
||||
var testTokens = contracts.GetTestTokenBalance(gethNode, addr);
|
||||
var testTokens = contracts.GetTestTokenBalance(addr);
|
||||
return testTokens.Amount < 64m;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace CodexNetDeployer
|
|||
|
||||
Log("Geth started. Deploying Codex contracts...");
|
||||
var contractsDeployment = ci.DeployCodexContracts(gethNode);
|
||||
var contracts = ci.WrapCodexContractsDeployment(contractsDeployment);
|
||||
var contracts = ci.WrapCodexContractsDeployment(gethNode, contractsDeployment);
|
||||
Log("Codex contracts deployed.");
|
||||
|
||||
Log("Starting Codex nodes...");
|
||||
|
|
Loading…
Reference in New Issue