Configures geth bootstrap node to mine blocks

This commit is contained in:
benbierens 2023-04-11 16:13:39 +02:00
parent 1512bd2716
commit de16ba3e36
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 41 additions and 18 deletions

View File

@ -14,7 +14,7 @@ namespace CodexDistTestCore.Marketplace
{
public const string ContainerName = "dtest-gethb";
private const string portName = "gethb";
private const string genesisJsonBase64 = "ewogICAgImNvbmZpZyI6IHsKICAgICAgImNoYWluSWQiOiAxMjM0NSwKICAgICAgImhvbWVzdGVhZEJsb2NrIjogMCwKICAgICAgImVpcDE1MEJsb2NrIjogMCwKICAgICAgImVpcDE1NUJsb2NrIjogMCwKICAgICAgImVpcDE1OEJsb2NrIjogMCwKICAgICAgImJ5emFudGl1bUJsb2NrIjogMCwKICAgICAgImNvbnN0YW50aW5vcGxlQmxvY2siOiAwLAogICAgICAicGV0ZXJzYnVyZ0Jsb2NrIjogMCwKICAgICAgImlzdGFuYnVsQmxvY2siOiAwLAogICAgICAibXVpckdsYWNpZXJCbG9jayI6IDAsCiAgICAgICJiZXJsaW5CbG9jayI6IDAsCiAgICAgICJsb25kb25CbG9jayI6IDAsCiAgICAgICJhcnJvd0dsYWNpZXJCbG9jayI6IDAsCiAgICAgICJncmF5R2xhY2llckJsb2NrIjogMCwKICAgICAgImNsaXF1ZSI6IHsKICAgICAgICAicGVyaW9kIjogNSwKICAgICAgICAiZXBvY2giOiAzMDAwMAogICAgICB9CiAgICB9LAogICAgImRpZmZpY3VsdHkiOiAiMSIsCiAgICAiZ2FzTGltaXQiOiAiODAwMDAwMDAwIiwKICAgICJleHRyYWRhdGEiOiAiMHgwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwN2RmOWE4NzVhMTc0YjNiYzU2NWU2NDI0YTAwNTBlYmMxYjJkMWQ4MjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLAogICAgImFsbG9jIjogewogICAgICAiQUNDT1VOVF9IRVJFIjogeyAiYmFsYW5jZSI6ICI1MDAwMDAiIH0KICAgIH0KICB9";
private const string genesisJsonBase64 = "ewogICAgImNvbmZpZyI6IHsKICAgICAgImNoYWluSWQiOiA3ODk5ODgsCiAgICAgICJob21lc3RlYWRCbG9jayI6IDAsCiAgICAgICJlaXAxNTBCbG9jayI6IDAsCiAgICAgICJlaXAxNTVCbG9jayI6IDAsCiAgICAgICJlaXAxNThCbG9jayI6IDAsCiAgICAgICJieXphbnRpdW1CbG9jayI6IDAsCiAgICAgICJjb25zdGFudGlub3BsZUJsb2NrIjogMCwKICAgICAgInBldGVyc2J1cmdCbG9jayI6IDAsCiAgICAgICJpc3RhbmJ1bEJsb2NrIjogMCwKICAgICAgIm11aXJHbGFjaWVyQmxvY2siOiAwLAogICAgICAiYmVybGluQmxvY2siOiAwLAogICAgICAibG9uZG9uQmxvY2siOiAwLAogICAgICAiYXJyb3dHbGFjaWVyQmxvY2siOiAwLAogICAgICAiZ3JheUdsYWNpZXJCbG9jayI6IDAsCiAgICAgICJjbGlxdWUiOiB7CiAgICAgICAgInBlcmlvZCI6IDUsCiAgICAgICAgImVwb2NoIjogMzAwMDAKICAgICAgfQogICAgfSwKICAgICJkaWZmaWN1bHR5IjogIjEiLAogICAgImdhc0xpbWl0IjogIjgwMDAwMDAwMCIsCiAgICAiZXh0cmFkYXRhIjogIjB4MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMEFDQ09VTlRfSEVSRTAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLAogICAgImFsbG9jIjogewogICAgICAiMHhBQ0NPVU5UX0hFUkUiOiB7ICJiYWxhbmNlIjogIjUwMDAwMCIgfQogICAgfQogIH0=";
public K8sGethBoostrapSpecs(int servicePort)
{
@ -68,7 +68,7 @@ namespace CodexDistTestCore.Marketplace
{
new V1ContainerPort
{
ContainerPort = 9090,
ContainerPort = 8545,
Name = portName
}
},
@ -77,7 +77,7 @@ namespace CodexDistTestCore.Marketplace
//new V1EnvVar
//{
// Name = "GETH_ARGS",
// Value = "--qwerty"
// Value = ""
//},
new V1EnvVar
{
@ -120,7 +120,7 @@ namespace CodexDistTestCore.Marketplace
{
Name = "gethb-service",
Protocol = "TCP",
Port = 9090,
Port = 8545,
TargetPort = portName,
NodePort = ServicePort
}
@ -185,7 +185,7 @@ namespace CodexDistTestCore.Marketplace
new V1EnvVar
{
Name = "GETH_ARGS",
Value = $"--port {container.ApiPort} --discovery.port {container.ApiPort} --authrpc.port {container.RpcPort}"
Value = $"--port {container.ApiPort} --discovery.port {container.ApiPort} --http.port {container.RpcPort}"
},
new V1EnvVar
{

View File

@ -75,7 +75,7 @@ namespace CodexDistTestCore.Marketplace
private void FetchAccount()
{
container.Account = k8sManager.ExecuteCommand(group.PodInfo!, container.Name, "cat", GethDockerImage.AccountFilename);
container.Account = k8sManager.ExecuteCommand(group.GethCompanionGroup!.Pod!, container.Name, "cat", GethDockerImage.AccountFilename);
}
}

View File

@ -1,4 +1,8 @@
using NUnit.Framework;
using CodexDistTestCore.Config;
using Nethereum.Web3;
using Nethereum.Web3.Accounts;
using Nethereum.Web3.Accounts.Managed;
using NUnit.Framework;
using System.Text;
namespace CodexDistTestCore.Marketplace
@ -39,7 +43,7 @@ namespace CodexDistTestCore.Marketplace
log.Log("Starting Geth bootstrap node...");
var spec = k8sManager.CreateGethBootstrapNodeSpec();
var pod = k8sManager.BringOnlineGethBootstrapNode(spec);
var (account, genesisJson) = ExtractAccountAndGenesisJson();
var (account, genesisJson) = ExtractAccountAndGenesisJson(pod);
bootstrapInfo = new GethBootstrapInfo(spec, pod, account, genesisJson);
log.Log($"Geth boothstrap node started.");
}
@ -62,21 +66,40 @@ namespace CodexDistTestCore.Marketplace
);
}
public void AddToBalance(string account, int amount)
private readonly K8sCluster k8sCluster = new K8sCluster();
public void AddToBalance(string account, decimal amount)
{
if (amount < 1 || string.IsNullOrEmpty(account)) Assert.Fail("Invalid arguments for AddToBalance");
// call the bootstrap node and convince it to give 'account' 'amount' tokens somehow.
throw new NotImplementedException();
var ip = k8sCluster.GetIp();
var port = bootstrapInfo!.Spec.ServicePort;
var bootstrapaccount = new ManagedAccount(bootstrapInfo.Account, "qwerty!@#$%^");
var web3 = new Web3(bootstrapaccount, $"http://{ip}:{port}");
var blockNumber1 = Utils.Wait(web3.Eth.Blocks.GetBlockNumber.SendRequestAsync());
Thread.Sleep(TimeSpan.FromSeconds(12));
var blockNumber2 = Utils.Wait(web3.Eth.Blocks.GetBlockNumber.SendRequestAsync());
var receipt = Utils.Wait(web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(account, amount));
var a = 0;
}
private (string, string) ExtractAccountAndGenesisJson()
private (string, string) ExtractAccountAndGenesisJson(PodInfo pod)
{
var (account, genesisJson) = FetchAccountAndGenesisJson();
var (account, genesisJson) = FetchAccountAndGenesisJson(pod);
if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(genesisJson))
{
Thread.Sleep(TimeSpan.FromSeconds(15));
(account, genesisJson) = FetchAccountAndGenesisJson();
(account, genesisJson) = FetchAccountAndGenesisJson(pod);
}
Assert.That(account, Is.Not.Empty, "Unable to fetch account for geth bootstrap node. Test infra failure.");
@ -88,16 +111,16 @@ namespace CodexDistTestCore.Marketplace
return (account, encoded);
}
private (string, string) FetchAccountAndGenesisJson()
private (string, string) FetchAccountAndGenesisJson(PodInfo pod)
{
var bootstrapAccount = ExecuteCommand("cat", GethDockerImage.AccountFilename);
var bootstrapGenesisJson = ExecuteCommand("cat", GethDockerImage.GenesisFilename);
var bootstrapAccount = ExecuteCommand(pod, "cat", GethDockerImage.AccountFilename);
var bootstrapGenesisJson = ExecuteCommand(pod, "cat", GethDockerImage.GenesisFilename);
return (bootstrapAccount, bootstrapGenesisJson);
}
private string ExecuteCommand(string command, params string[] arguments)
private string ExecuteCommand(PodInfo pod, string command, params string[] arguments)
{
return k8sManager.ExecuteCommand(bootstrapInfo!.Pod, K8sGethBoostrapSpecs.ContainerName, command, arguments);
return k8sManager.ExecuteCommand(pod, K8sGethBoostrapSpecs.ContainerName, command, arguments);
}
}