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

     1  package ethereum2
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	ethereum2v1alpha1 "github.com/kotalco/kotal/apis/ethereum2/v1alpha1"
     8  	sharedAPI "github.com/kotalco/kotal/apis/shared"
     9  	"github.com/kotalco/kotal/controllers/shared"
    10  	. "github.com/onsi/ginkgo/v2"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("Teku beacon node", func() {
    15  
    16  	node := ethereum2v1alpha1.BeaconNode{
    17  		Spec: ethereum2v1alpha1.BeaconNodeSpec{
    18  			Client:  ethereum2v1alpha1.TekuClient,
    19  			Network: "mainnet",
    20  		},
    21  	}
    22  	client, _ := NewClient(&node)
    23  
    24  	It("Should get correct command", func() {
    25  		Expect(client.Command()).To(BeNil())
    26  	})
    27  
    28  	It("Should get correct env", func() {
    29  		Expect(client.Env()).To(BeNil())
    30  	})
    31  
    32  	It("Should get correct home dir", func() {
    33  		Expect(client.HomeDir()).To(Equal(TekuHomeDir))
    34  	})
    35  
    36  	cases := []struct {
    37  		title  string
    38  		node   *ethereum2v1alpha1.BeaconNode
    39  		result []string
    40  	}{
    41  		{
    42  			title: "beacon node syncing mainnet",
    43  			node: &ethereum2v1alpha1.BeaconNode{
    44  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
    45  					Client:  ethereum2v1alpha1.TekuClient,
    46  					Network: "mainnet",
    47  					Logging: sharedAPI.ErrorLogs,
    48  				},
    49  			},
    50  			result: []string{
    51  				TekuDataPath,
    52  				TekuNetwork,
    53  				"mainnet",
    54  				TekuLogging,
    55  				strings.ToUpper(string(sharedAPI.ErrorLogs)),
    56  			},
    57  		},
    58  		{
    59  			title: "beacon node syncing mainnet with checkpoint syncing",
    60  			node: &ethereum2v1alpha1.BeaconNode{
    61  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
    62  					Client:                  ethereum2v1alpha1.TekuClient,
    63  					Network:                 "mainnet",
    64  					ExecutionEngineEndpoint: "https://localhost:8551",
    65  					JWTSecretName:           "jwt-secret",
    66  					FeeRecipient:            "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
    67  					CheckpointSyncURL:       "https://kotal.cloud/eth2/beacon/checkpoint",
    68  				},
    69  			},
    70  			result: []string{
    71  				TekuDataPath,
    72  				TekuNetwork,
    73  				"mainnet",
    74  				TekuExecutionEngineEndpoint,
    75  				"https://localhost:8551",
    76  				TekuJwtSecretFile,
    77  				fmt.Sprintf("%s/jwt.secret", shared.PathSecrets(client.HomeDir())),
    78  				TekuFeeRecipient,
    79  				"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
    80  				TekuInitialState,
    81  				"https://kotal.cloud/eth2/beacon/checkpoint",
    82  			},
    83  		},
    84  		{
    85  			title: "beacon node syncing mainnet with http enabled",
    86  			node: &ethereum2v1alpha1.BeaconNode{
    87  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
    88  					Client:                  ethereum2v1alpha1.TekuClient,
    89  					Network:                 "mainnet",
    90  					ExecutionEngineEndpoint: "https://localhost:8551",
    91  					JWTSecretName:           "jwt-secret",
    92  					REST:                    true,
    93  				},
    94  			},
    95  			result: []string{
    96  				TekuDataPath,
    97  				TekuNetwork,
    98  				"mainnet",
    99  				TekuExecutionEngineEndpoint,
   100  				"https://localhost:8551",
   101  				TekuJwtSecretFile,
   102  				fmt.Sprintf("%s/jwt.secret", shared.PathSecrets(client.HomeDir())),
   103  				TekuRestEnabled,
   104  				TekuRESTAPICorsOrigins,
   105  				"*",
   106  				TekuRESTAPIHostAllowlist,
   107  				"*",
   108  			},
   109  		},
   110  		{
   111  			title: "beacon node syncing mainnet with http enabled with port",
   112  			node: &ethereum2v1alpha1.BeaconNode{
   113  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
   114  					Client:                  ethereum2v1alpha1.TekuClient,
   115  					Network:                 "mainnet",
   116  					ExecutionEngineEndpoint: "https://localhost:8551",
   117  					JWTSecretName:           "jwt-secret",
   118  					REST:                    true,
   119  					RESTPort:                3333,
   120  				},
   121  			},
   122  			result: []string{
   123  				TekuDataPath,
   124  				TekuNetwork,
   125  				"mainnet",
   126  				TekuExecutionEngineEndpoint,
   127  				"https://localhost:8551",
   128  				TekuJwtSecretFile,
   129  				fmt.Sprintf("%s/jwt.secret", shared.PathSecrets(client.HomeDir())),
   130  				TekuRestEnabled,
   131  				TekuRestPort,
   132  				"3333",
   133  				TekuRESTAPICorsOrigins,
   134  				"*",
   135  				TekuRESTAPIHostAllowlist,
   136  				"*",
   137  			},
   138  		},
   139  		{
   140  			title: "beacon node syncing mainnet with http enabled with port and host",
   141  			node: &ethereum2v1alpha1.BeaconNode{
   142  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
   143  					Client:                  ethereum2v1alpha1.TekuClient,
   144  					Network:                 "mainnet",
   145  					ExecutionEngineEndpoint: "https://localhost:8551",
   146  					JWTSecretName:           "jwt-secret",
   147  					REST:                    true,
   148  					RESTPort:                3333,
   149  				},
   150  			},
   151  			result: []string{
   152  				TekuDataPath,
   153  				TekuNetwork,
   154  				"mainnet",
   155  				TekuExecutionEngineEndpoint,
   156  				"https://localhost:8551",
   157  				TekuJwtSecretFile,
   158  				fmt.Sprintf("%s/jwt.secret", shared.PathSecrets(client.HomeDir())),
   159  				TekuRestEnabled,
   160  				TekuRestPort,
   161  				"3333",
   162  				TekuRestHost,
   163  				"0.0.0.0",
   164  				TekuRESTAPICorsOrigins,
   165  				"*",
   166  				TekuRESTAPIHostAllowlist,
   167  				"*",
   168  			},
   169  		},
   170  		{
   171  			title: "beacon node syncing mainnet with p2p port, http enabled with port and host",
   172  			node: &ethereum2v1alpha1.BeaconNode{
   173  				Spec: ethereum2v1alpha1.BeaconNodeSpec{
   174  					Client:                  ethereum2v1alpha1.TekuClient,
   175  					P2PPort:                 7891,
   176  					Network:                 "mainnet",
   177  					ExecutionEngineEndpoint: "https://localhost:8551",
   178  					JWTSecretName:           "jwt-secret",
   179  					REST:                    true,
   180  					RESTPort:                3333,
   181  				},
   182  			},
   183  			result: []string{
   184  				TekuDataPath,
   185  				TekuP2PPort,
   186  				"7891",
   187  				TekuNetwork,
   188  				"mainnet",
   189  				TekuExecutionEngineEndpoint,
   190  				"https://localhost:8551",
   191  				TekuJwtSecretFile,
   192  				fmt.Sprintf("%s/jwt.secret", shared.PathSecrets(client.HomeDir())),
   193  				TekuRestEnabled,
   194  				TekuRestPort,
   195  				"3333",
   196  				TekuRestHost,
   197  				"0.0.0.0",
   198  				TekuRESTAPICorsOrigins,
   199  				"*",
   200  				TekuRESTAPIHostAllowlist,
   201  				"*",
   202  			},
   203  		},
   204  	}
   205  
   206  	for _, c := range cases {
   207  		func() {
   208  			cc := c
   209  			It(fmt.Sprintf("Should create correct client arguments for %s", cc.title), func() {
   210  				cc.node.Default()
   211  				client, _ := NewClient(cc.node)
   212  				args := client.Args()
   213  				Expect(args).To(ContainElements(cc.result))
   214  			})
   215  		}()
   216  	}
   217  
   218  })