github.com/kotalco/kotal@v0.3.0/clients/ethereum2/prysm_beacon_node_test.go (about)

     1  package ethereum2
     2  
     3  import (
     4  	"fmt"
     5  
     6  	ethereum2v1alpha1 "github.com/kotalco/kotal/apis/ethereum2/v1alpha1"
     7  	sharedAPI "github.com/kotalco/kotal/apis/shared"
     8  	"github.com/kotalco/kotal/controllers/shared"
     9  	. "github.com/onsi/ginkgo/v2"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("Prysm beacon node", func() {
    14  
    15  	node := ethereum2v1alpha1.BeaconNode{
    16  		Spec: ethereum2v1alpha1.BeaconNodeSpec{
    17  			Client:  ethereum2v1alpha1.PrysmClient,
    18  			Network: "mainnet",
    19  		},
    20  	}
    21  	client, _ := NewClient(&node)
    22  
    23  	It("Should get correct command", func() {
    24  		Expect(client.Command()).To(ConsistOf("beacon-chain"))
    25  	})
    26  
    27  	It("Should get correct env", func() {
    28  		Expect(client.Env()).To(BeNil())
    29  	})
    30  
    31  	It("Should get correct home dir", func() {
    32  		Expect(client.HomeDir()).To(Equal(PrysmHomeDir))
    33  	})
    34  
    35  	cases := []struct {
    36  		title  string
    37  		node   *ethereum2v1alpha1.BeaconNode
    38  		result []string
    39  	}{
    40  		{
    41  			title: "beacon node syncing mainnet",
    42  			node: &ethereum2v1alpha1.BeaconNode{
    43  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
    44  					Client:  ethereum2v1alpha1.PrysmClient,
    45  					Network: "mainnet",
    46  					RPC:     true,
    47  					Logging: sharedAPI.WarnLogs,
    48  				},
    49  			},
    50  			result: []string{
    51  				PrysmAcceptTermsOfUse,
    52  				PrysmDataDir,
    53  				"--mainnet",
    54  				PrysmLogging,
    55  				string(sharedAPI.WarnLogs),
    56  			},
    57  		},
    58  		{
    59  			title: "beacon node syncing mainnet with checkpoint sync",
    60  			node: &ethereum2v1alpha1.BeaconNode{
    61  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
    62  					Client:                  ethereum2v1alpha1.PrysmClient,
    63  					Network:                 "mainnet",
    64  					ExecutionEngineEndpoint: "https://localhost:8551",
    65  					JWTSecretName:           "jwt-secret",
    66  					FeeRecipient:            "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
    67  					RPC:                     true,
    68  					CheckpointSyncURL:       "https://kotal.cloud/eth2/beacon/checkpoint",
    69  				},
    70  			},
    71  			result: []string{
    72  				PrysmAcceptTermsOfUse,
    73  				PrysmDataDir,
    74  				"--mainnet",
    75  				PrysmExecutionEngineEndpoint,
    76  				"https://localhost:8551",
    77  				PrysmJwtSecretFile,
    78  				fmt.Sprintf("%s/jwt.secret", shared.PathSecrets(client.HomeDir())),
    79  				PrysmFeeRecipient,
    80  				"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
    81  				PrysmCheckpointSyncUrl,
    82  				"https://kotal.cloud/eth2/beacon/checkpoint",
    83  				PrysmGenesisBeaconApiUrl,
    84  				"https://kotal.cloud/eth2/beacon/checkpoint",
    85  			},
    86  		},
    87  		{
    88  			title: "beacon node syncing mainnet with rpc port",
    89  			node: &ethereum2v1alpha1.BeaconNode{
    90  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
    91  					Client:                  ethereum2v1alpha1.PrysmClient,
    92  					Network:                 "mainnet",
    93  					ExecutionEngineEndpoint: "https://localhost:8551",
    94  					JWTSecretName:           "jwt-secret",
    95  					RPC:                     true,
    96  					RPCPort:                 9976,
    97  				},
    98  			},
    99  			result: []string{
   100  				PrysmAcceptTermsOfUse,
   101  				PrysmDataDir,
   102  				"--mainnet",
   103  				PrysmExecutionEngineEndpoint,
   104  				"https://localhost:8551",
   105  				PrysmJwtSecretFile,
   106  				fmt.Sprintf("%s/jwt.secret", shared.PathSecrets(client.HomeDir())),
   107  				PrysmRPCPort,
   108  				"9976",
   109  			},
   110  		},
   111  		{
   112  			title: "beacon node syncing mainnet with rpc port and host",
   113  			node: &ethereum2v1alpha1.BeaconNode{
   114  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
   115  					Client:                  ethereum2v1alpha1.PrysmClient,
   116  					Network:                 "mainnet",
   117  					ExecutionEngineEndpoint: "https://localhost:8551",
   118  					JWTSecretName:           "jwt-secret",
   119  					RPC:                     true,
   120  					RPCPort:                 9976,
   121  				},
   122  			},
   123  			result: []string{
   124  				PrysmAcceptTermsOfUse,
   125  				PrysmDataDir,
   126  				"--mainnet",
   127  				PrysmExecutionEngineEndpoint,
   128  				"https://localhost:8551",
   129  				PrysmJwtSecretFile,
   130  				fmt.Sprintf("%s/jwt.secret", shared.PathSecrets(client.HomeDir())),
   131  				PrysmRPCPort,
   132  				"9976",
   133  				PrysmRPCHost,
   134  				"0.0.0.0",
   135  			},
   136  		},
   137  		{
   138  			title: "beacon node syncing mainnet with grpc disabled",
   139  			node: &ethereum2v1alpha1.BeaconNode{
   140  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
   141  					Client:                  ethereum2v1alpha1.PrysmClient,
   142  					Network:                 "mainnet",
   143  					ExecutionEngineEndpoint: "https://localhost:8551",
   144  					JWTSecretName:           "jwt-secret",
   145  				},
   146  			},
   147  			result: []string{
   148  				PrysmAcceptTermsOfUse,
   149  				PrysmDataDir,
   150  				"--mainnet",
   151  				PrysmExecutionEngineEndpoint,
   152  				"https://localhost:8551",
   153  				PrysmJwtSecretFile,
   154  				fmt.Sprintf("%s/jwt.secret", shared.PathSecrets(client.HomeDir())),
   155  				PrysmDisableGRPC,
   156  			},
   157  		},
   158  		{
   159  			title: "beacon node syncing mainnet with certificate and grpc with port",
   160  			node: &ethereum2v1alpha1.BeaconNode{
   161  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
   162  					Client:                  ethereum2v1alpha1.PrysmClient,
   163  					Network:                 "mainnet",
   164  					ExecutionEngineEndpoint: "https://localhost:8551",
   165  					JWTSecretName:           "jwt-secret",
   166  					GRPC:                    true,
   167  					GRPCPort:                4445,
   168  					CertSecretName:          "my-certificate",
   169  				},
   170  			},
   171  			result: []string{
   172  				PrysmAcceptTermsOfUse,
   173  				PrysmDataDir,
   174  				"--mainnet",
   175  				PrysmExecutionEngineEndpoint,
   176  				"https://localhost:8551",
   177  				PrysmJwtSecretFile,
   178  				fmt.Sprintf("%s/jwt.secret", shared.PathSecrets(client.HomeDir())),
   179  				PrysmGRPCPort,
   180  				"4445",
   181  				PrysmGRPCGatewayCorsDomains,
   182  				"*",
   183  				PrysmTLSCert,
   184  				fmt.Sprintf("%s/tls.crt", shared.PathSecrets(PrysmHomeDir)),
   185  				PrysmTLSKey,
   186  				fmt.Sprintf("%s/tls.key", shared.PathSecrets(PrysmHomeDir)),
   187  			},
   188  		},
   189  		{
   190  			title: "beacon node syncing mainnet with grpc with port and host",
   191  			node: &ethereum2v1alpha1.BeaconNode{
   192  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
   193  					Client:                  ethereum2v1alpha1.PrysmClient,
   194  					Network:                 "mainnet",
   195  					ExecutionEngineEndpoint: "https://localhost:8551",
   196  					JWTSecretName:           "jwt-secret",
   197  					GRPC:                    true,
   198  					GRPCPort:                4445,
   199  				},
   200  			},
   201  			result: []string{
   202  				PrysmAcceptTermsOfUse,
   203  				PrysmDataDir,
   204  				"--mainnet",
   205  				PrysmExecutionEngineEndpoint,
   206  				"https://localhost:8551",
   207  				PrysmJwtSecretFile,
   208  				fmt.Sprintf("%s/jwt.secret", shared.PathSecrets(client.HomeDir())),
   209  				PrysmGRPCPort,
   210  				"4445",
   211  				PrysmGRPCHost,
   212  				"0.0.0.0",
   213  				PrysmGRPCGatewayCorsDomains,
   214  				"*",
   215  			},
   216  		},
   217  		{
   218  			title: "beacon node syncing mainnet with p2p port and grpc with port and host",
   219  			node: &ethereum2v1alpha1.BeaconNode{
   220  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
   221  					Client:                  ethereum2v1alpha1.PrysmClient,
   222  					P2PPort:                 7891,
   223  					Network:                 "mainnet",
   224  					ExecutionEngineEndpoint: "https://localhost:8551",
   225  					JWTSecretName:           "jwt-secret",
   226  					GRPC:                    true,
   227  					GRPCPort:                4445,
   228  				},
   229  			},
   230  			result: []string{
   231  				PrysmAcceptTermsOfUse,
   232  				PrysmDataDir,
   233  				PrysmP2PTCPPort,
   234  				"7891",
   235  				PrysmP2PUDPPort,
   236  				"7891",
   237  				"--mainnet",
   238  				PrysmExecutionEngineEndpoint,
   239  				"https://localhost:8551",
   240  				PrysmJwtSecretFile,
   241  				fmt.Sprintf("%s/jwt.secret", shared.PathSecrets(client.HomeDir())),
   242  				PrysmGRPCPort,
   243  				"4445",
   244  				PrysmGRPCHost,
   245  				"0.0.0.0",
   246  				PrysmGRPCGatewayCorsDomains,
   247  				"*",
   248  			},
   249  		},
   250  	}
   251  
   252  	for _, c := range cases {
   253  		func() {
   254  			cc := c
   255  			It(fmt.Sprintf("Should create correct client arguments for %s", cc.title), func() {
   256  				cc.node.Default()
   257  				client, _ := NewClient(cc.node)
   258  				args := client.Args()
   259  				Expect(args).To(ContainElements(cc.result))
   260  			})
   261  		}()
   262  	}
   263  
   264  })