github.com/smartcontractkit/chainlink-testing-framework/libs@v0.0.0-20240227141906-ec710b4eb1a3/k8s/pkg/helm/foundry/foundry.go (about)

     1  package foundry
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/rs/zerolog/log"
     8  
     9  	"github.com/smartcontractkit/chainlink-testing-framework/libs/k8s/client"
    10  	"github.com/smartcontractkit/chainlink-testing-framework/libs/k8s/config"
    11  	"github.com/smartcontractkit/chainlink-testing-framework/libs/k8s/environment"
    12  )
    13  
    14  const (
    15  	ChartName = "foundry"
    16  )
    17  
    18  type Props struct {
    19  	NetworkName string
    20  	Values      map[string]interface{}
    21  }
    22  
    23  type Chart struct {
    24  	Name    string
    25  	Path    string
    26  	Version string
    27  	Props   *Props
    28  	Values  *map[string]any
    29  }
    30  
    31  func (m Chart) IsDeploymentNeeded() bool {
    32  	return true
    33  }
    34  
    35  func (m Chart) GetName() string {
    36  	return m.Name
    37  }
    38  
    39  func (m Chart) GetPath() string {
    40  	return m.Path
    41  }
    42  
    43  func (m Chart) GetVersion() string {
    44  	return m.Version
    45  }
    46  
    47  func (m Chart) GetProps() interface{} {
    48  	return m.Props
    49  }
    50  
    51  func (m Chart) GetValues() *map[string]interface{} {
    52  	return m.Values
    53  }
    54  
    55  func (m Chart) ExportData(e *environment.Environment) error {
    56  	podName := fmt.Sprintf("%s-%s:0", m.Props.NetworkName, ChartName)
    57  	localHttp, err := e.Fwd.FindPort(podName, ChartName, "http").As(client.LocalConnection, client.HTTP)
    58  	if err != nil {
    59  		return err
    60  	}
    61  	internalHttp, err := e.Fwd.FindPort(podName, ChartName, "http").As(client.RemoteConnection, client.HTTP)
    62  	if err != nil {
    63  		return err
    64  	}
    65  	localWs, err := e.Fwd.FindPort(podName, ChartName, "http").As(client.LocalConnection, client.WS)
    66  	if err != nil {
    67  		return err
    68  	}
    69  	internalWs, err := e.Fwd.FindPort(podName, ChartName, "http").As(client.RemoteConnection, client.WS)
    70  	if err != nil {
    71  		return err
    72  	}
    73  	if e.Cfg.InsideK8s {
    74  		e.URLs[m.Props.NetworkName] = []string{internalWs}
    75  		e.URLs[m.Props.NetworkName+"_http"] = []string{internalHttp}
    76  	} else {
    77  		e.URLs[m.Props.NetworkName] = []string{localWs}
    78  		e.URLs[m.Props.NetworkName+"_http"] = []string{localHttp}
    79  	}
    80  
    81  	// For cases like starknet we need the internalHttp address to set up the L1<>L2 interaction
    82  	e.URLs[m.Props.NetworkName+"_internal"] = []string{internalWs}
    83  	e.URLs[m.Props.NetworkName+"_internal_http"] = []string{internalHttp}
    84  
    85  	for k, v := range e.URLs {
    86  		if strings.Contains(k, m.Props.NetworkName) {
    87  			log.Info().Str("Name", k).Strs("URLs", v).Msg("Forked network")
    88  		}
    89  	}
    90  
    91  	return nil
    92  }
    93  
    94  func defaultProps() *Props {
    95  	return &Props{
    96  		NetworkName: "fork",
    97  		Values: map[string]any{
    98  			"replicaCount": "1",
    99  			"anvil": map[string]any{
   100  				"host":                      "0.0.0.0",
   101  				"port":                      "8545",
   102  				"blockTime":                 1,
   103  				"forkRetries":               "5",
   104  				"forkTimeout":               "45000",
   105  				"forkComputeUnitsPerSecond": "330",
   106  				"chainId":                   "1337",
   107  			},
   108  		},
   109  	}
   110  }
   111  
   112  func New(props Props) environment.ConnectedChart {
   113  	return NewVersioned("", props)
   114  }
   115  
   116  // NewVersioned enables choosing a specific helm chart version
   117  func NewVersioned(helmVersion string, props Props) environment.ConnectedChart {
   118  	dp := defaultProps()
   119  	config.MustMerge(dp, props)
   120  	config.MustMerge(&dp.Values, props.Values)
   121  	return Chart{
   122  		Name:    strings.ReplaceAll(strings.ToLower(props.NetworkName), " ", "-"),
   123  		Path:    "chainlink-qa/foundry",
   124  		Values:  &dp.Values,
   125  		Props:   dp,
   126  		Version: helmVersion,
   127  	}
   128  }