wrap up with basic ETH balance control

This commit is contained in:
benbierens 2023-04-12 08:40:23 +02:00
parent f87163acdc
commit bdd977d8a9
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
5 changed files with 44 additions and 26 deletions

View File

@ -15,16 +15,18 @@
public class GethCompanionNodeContainer
{
public GethCompanionNodeContainer(string name, int apiPort, int rpcPort, string containerPortName)
public GethCompanionNodeContainer(string name, int apiPort, int rpcPort, string containerPortName, int authRpcPort)
{
Name = name;
ApiPort = apiPort;
AuthRpcPort = authRpcPort;
RpcPort = rpcPort;
ContainerPortName = containerPortName;
}
public string Name { get; }
public int ApiPort { get; }
public int AuthRpcPort { get; }
public int RpcPort { get; }
public string ContainerPortName { get; }

View File

@ -185,7 +185,7 @@ namespace CodexDistTestCore.Marketplace
new V1EnvVar
{
Name = "GETH_ARGS",
Value = $"--port {container.ApiPort} --discovery.port {container.ApiPort} --http.port {container.RpcPort}"
Value = $"--port {container.ApiPort} --discovery.port {container.ApiPort} --authrpc.port {container.AuthRpcPort} --http.port {container.RpcPort}"
},
new V1EnvVar
{

View File

@ -8,7 +8,7 @@ namespace CodexDistTestCore.Marketplace
void MakeStorageAvailable(ByteSize size, int minPricePerBytePerSecond, float maxCollateral);
void RequestStorage(ContentId contentId, int pricePerBytePerSecond, float requiredCollateral, float minRequiredNumberOfNodes);
void AssertThatBalance(IResolveConstraint constraint, string message = "");
float GetBalance();
decimal GetBalance();
}
public class MarketplaceAccess : IMarketplaceAccess
@ -57,9 +57,9 @@ namespace CodexDistTestCore.Marketplace
throw new NotImplementedException();
}
public float GetBalance()
public decimal GetBalance()
{
throw new NotImplementedException();
return marketplaceController.GetBalance(container.Account);
}
private void EnsureAccount()
@ -96,10 +96,10 @@ namespace CodexDistTestCore.Marketplace
Unavailable();
}
public float GetBalance()
public decimal GetBalance()
{
Unavailable();
return 0.0f;
return 0;
}
private void Unavailable()

View File

@ -62,12 +62,12 @@ namespace CodexDistTestCore.Marketplace
return new GethCompanionNodeContainer(
name: $"geth-node{n}",
apiPort: numberSource.GetNextNumber(),
authRpcPort: numberSource.GetNextNumber(),
rpcPort: numberSource.GetNextNumber(),
containerPortName: $"geth-{n}"
);
}
private readonly K8sCluster k8sCluster = new K8sCluster();
public void AddToBalance(string account, decimal amount)
@ -76,30 +76,38 @@ namespace CodexDistTestCore.Marketplace
// call the bootstrap node and convince it to give 'account' 'amount' tokens somehow.
var ip = k8sCluster.GetIp();
var port = bootstrapInfo!.Spec.ServicePort;
var web3 = CreateWeb3();
//var bootstrapaccount = new ManagedAccount(bootstrapInfo.Account, "qwerty!@#$%^");
var web3 = new Web3($"http://{ip}:{port}");
//var blockNumber1 = Utils.Wait(web3.Eth.Blocks.GetBlockNumber.SendRequestAsync());
//Thread.Sleep(TimeSpan.FromSeconds(5));
//var blockNumber2 = Utils.Wait(web3.Eth.Blocks.GetBlockNumber.SendRequestAsync());
var blockNumber1 = Utils.Wait(web3.Eth.Blocks.GetBlockNumber.SendRequestAsync());
Thread.Sleep(TimeSpan.FromSeconds(5));
var blockNumber2 = Utils.Wait(web3.Eth.Blocks.GetBlockNumber.SendRequestAsync());
var bootstrapBalance = Utils.Wait(web3.Eth.GetBalance.SendRequestAsync(bootstrapInfo.Account));
var targetBalance = Utils.Wait(web3.Eth.GetBalance.SendRequestAsync(account));
//var bootstrapBalance = Utils.Wait(web3.Eth.GetBalance.SendRequestAsync(bootstrapInfo.Account));
var bigint = new BigInteger(amount);
var str = bigint.ToString("X");
var value = new Nethereum.Hex.HexTypes.HexBigInteger(str);
var aaa = Utils.Wait(web3.Eth.TransactionManager.SendTransactionAsync(bootstrapInfo.Account, account, value));
var aaa = Utils.Wait(web3.Eth.TransactionManager.SendTransactionAsync(bootstrapInfo!.Account, account, value));
var receipt = Utils.Wait(web3.Eth.TransactionManager.TransactionReceiptService.PollForReceiptAsync(aaa));
//var receipt = Utils.Wait(web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(account, amount));
//var targetBalance = Utils.Wait(web3.Eth.GetBalance.SendRequestAsync(account));
}
targetBalance = Utils.Wait(web3.Eth.GetBalance.SendRequestAsync(account));
var a = 0;
public decimal GetBalance(string account)
{
var web3 = CreateWeb3();
var bigInt = Utils.Wait(web3.Eth.GetBalance.SendRequestAsync(account));
return (decimal)bigInt.Value;
}
private Web3 CreateWeb3()
{
var ip = k8sCluster.GetIp();
var port = bootstrapInfo!.Spec.ServicePort;
//var bootstrapaccount = new ManagedAccount(bootstrapInfo.Account, "qwerty!@#$%^");
return new Web3($"http://{ip}:{port}");
}
private (string, string) ExtractAccountAndGenesisJson(PodInfo pod)

View File

@ -34,10 +34,20 @@ namespace Tests.BasicTests
[Test]
public void MarketplaceExample()
{
var primary = SetupCodexNodes(1)
var group = SetupCodexNodes(4)
.WithStorageQuota(10.GB())
.EnableMarketplace(initialBalance: 20)
.BringOnline()[0];
.BringOnline();
foreach (var node in group)
{
Assert.That(node.Marketplace.GetBalance(), Is.EqualTo(20));
}
// 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.
//var secondary = SetupCodexNodes(1)
// .EnableMarketplace(initialBalance: 1000)
@ -56,8 +66,6 @@ namespace Tests.BasicTests
//secondary.Marketplace.AssertThatBalance(Is.LessThan(1000), "Contractor was not charged for storage.");
//primary.Marketplace.AssertThatBalance(Is.GreaterThan(primaryBalance), "Storer was not paid for storage.");
var aa = 0;
}
[Test]