Skip to content

Commit b489ce9

Browse files
authored
[PRODCRE-1671] Remove env_artifact (#20773)
* working version * clean go mod * add copilot's suggestion
1 parent 7062214 commit b489ce9

13 files changed

Lines changed: 116 additions & 618 deletions

File tree

core/scripts/cre/environment/environment/environment.go

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,15 @@ func startCmd() *cobra.Command {
477477
fmt.Print(libformat.PurpleText("\nEnvironment setup completed successfully in %.2f seconds\n\n", time.Since(provisioningStartTime).Seconds()))
478478
fmt.Print("To terminate execute:`go run . env stop`\n\n")
479479

480+
addresses, aErr := output.CreEnvironment.CldfEnvironment.DataStore.Addresses().Fetch()
481+
if aErr != nil {
482+
return errors.Wrap(aErr, "failed to fetch addresses from datastore")
483+
}
484+
485+
stErr := in.SetAddresses(addresses)
486+
if stErr != nil {
487+
return errors.Wrap(stErr, "failed to set addresses on Config")
488+
}
480489
storeErr := in.Store(envconfig.MustLocalCREStateFileAbsPath(relativePathToRepoRoot))
481490
if storeErr != nil {
482491
return errors.Wrap(storeErr, "failed to store local CRE state")
@@ -641,14 +650,6 @@ func stopCmd() *cobra.Command {
641650
} else {
642651
framework.L.Info().Msgf("removed local CRE state file: %s", creStateFile)
643652
}
644-
645-
envArtifactFile := creenv.MustEnvArtifactAbsPath(relativePathToRepoRoot)
646-
eErr := os.Remove(envArtifactFile)
647-
if eErr != nil {
648-
framework.L.Warn().Msgf("failed to remove local CRE environment artifact file: %s", eErr)
649-
} else {
650-
framework.L.Info().Msgf("removed local CRE environment artifact file: %s", envArtifactFile)
651-
}
652653
}
653654

654655
fmt.Println("Environment stopped successfully")
@@ -745,26 +746,6 @@ func StartCLIEnvironment(
745746
return nil, fmt.Errorf("failed to setup test environment: %w", setupErr)
746747
}
747748

748-
capabilitiesContractFactoryFunctions := []cre.CapabilityRegistryConfigFn{}
749-
for _, cap := range capabilities {
750-
capabilitiesContractFactoryFunctions = append(capabilitiesContractFactoryFunctions, cap.CapabilityRegistryV1ConfigFn())
751-
}
752-
753-
artifactPath, artifactErr := creenv.DumpArtifact(
754-
creenv.MustEnvArtifactAbsPath(relativePathToRepoRoot),
755-
*universalSetupOutput.Dons,
756-
universalSetupOutput.CreEnvironment,
757-
*in.JD.Out,
758-
in.NodeSets,
759-
capabilitiesContractFactoryFunctions,
760-
)
761-
762-
if artifactErr != nil {
763-
testLogger.Error().Err(artifactErr).Msg("failed to generate env artifact")
764-
} else {
765-
testLogger.Info().Msgf("Environment artifact saved to %s", artifactPath)
766-
}
767-
768749
return universalSetupOutput, nil
769750
}
770751

core/scripts/cre/environment/environment/examples.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func deployAndVerifyExampleWorkflowCmd() *cobra.Command {
5555
workflowRegistryAddress = workflowRegistryAddressFlag
5656
contractsVersion = semver.MustParse(contractsVersionFlag)
5757
} else {
58-
addrRef, addrErr := addressRefFromStateFile(keystone_changeset.WorkflowRegistry.String())
58+
addrRef, addrErr := addressRefFromStateFile(keystone_changeset.WorkflowRegistry)
5959
if addrErr != nil {
6060
return errors.Wrap(addrErr, "❌ failed to get workflow registry address from state file")
6161
}

core/scripts/cre/environment/environment/swap.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,15 @@ func swapCapability(ctx context.Context, capabilityFlag, binaryPath string, forc
103103
return errors.Wrap(setErr, "failed to set CTF_CONFIGS environment variable")
104104
}
105105

106-
config, loadErr := framework.Load[envconfig.Config](nil)
106+
config := &envconfig.Config{}
107+
loadErr := config.Load(os.Getenv("CTF_CONFIGS"))
107108
if loadErr != nil {
108109
return errors.Wrap(loadErr, "failed to load CTF config")
109110
}
110111

111-
envArtifact, artErr := creenv.ReadEnvArtifact(creenv.MustEnvArtifactAbsPath(relativePathToRepoRoot))
112-
if artErr != nil {
113-
return errors.Wrap(artErr, "failed to read environment artifact")
114-
}
115-
116112
cldLogger := cldlogger.NewSingleFileLogger(nil)
117113

118-
creEnvironment, dons, loadErr := creenv.BuildFromSavedState(ctx, cldLogger, config, envArtifact)
114+
creEnvironment, dons, loadErr := creenv.BuildFromSavedState(ctx, cldLogger, config)
119115
if loadErr != nil {
120116
return errors.Wrap(loadErr, "failed to load environment")
121117
}
@@ -447,8 +443,4 @@ func envIsRunningPreRunFunc(cmd *cobra.Command, args []string) {
447443
if !envconfig.LocalCREStateFileExists(relativePathToRepoRoot) {
448444
framework.L.Fatal().Str("Expected location", envconfig.MustLocalCREStateFileAbsPath(relativePathToRepoRoot)).Msg("Local CRE state file does not exist. Please start the environment first.")
449445
}
450-
451-
if !creenv.EnvArtifactFileExists(relativePathToRepoRoot) {
452-
framework.L.Fatal().Str("Expected location", creenv.MustEnvArtifactAbsPath(relativePathToRepoRoot)).Msg("Environment artifact file does not exist. Please start the environment first.")
453-
}
454446
}

core/scripts/cre/environment/environment/workflow.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import (
1717
"github.com/spf13/cobra"
1818

1919
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
20+
"github.com/smartcontractkit/chainlink-deployments-framework/deployment"
2021
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
2122
"github.com/smartcontractkit/chainlink-testing-framework/seth"
2223

2324
keystone_changeset "github.com/smartcontractkit/chainlink/deployment/keystone/changeset"
24-
"github.com/smartcontractkit/chainlink/system-tests/lib/cre/contracts"
2525
"github.com/smartcontractkit/chainlink/system-tests/lib/cre/environment"
26+
envconfig "github.com/smartcontractkit/chainlink/system-tests/lib/cre/environment/config"
2627
creworkflow "github.com/smartcontractkit/chainlink/system-tests/lib/cre/workflow"
2728
)
2829

@@ -166,7 +167,7 @@ func deployWorkflowCmd() *cobra.Command {
166167
if workflowRegistryAddressFlag != "" {
167168
workflowRegistryAddress = workflowRegistryAddressFlag
168169
} else {
169-
addrRef, addrErr := addressRefFromStateFile(keystone_changeset.WorkflowRegistry.String())
170+
addrRef, addrErr := addressRefFromStateFile(keystone_changeset.WorkflowRegistry)
170171
if addrErr != nil {
171172
return errors.Wrap(addrErr, "❌ failed to get workflow registry address from state file")
172173
}
@@ -179,7 +180,7 @@ func deployWorkflowCmd() *cobra.Command {
179180
if capabilitiesRegistryAddressFlag != "" {
180181
capabilitiesRegistryAddress = capabilitiesRegistryAddressFlag
181182
} else {
182-
addrRef, addrErr := addressRefFromStateFile(keystone_changeset.CapabilitiesRegistry.String())
183+
addrRef, addrErr := addressRefFromStateFile(keystone_changeset.CapabilitiesRegistry)
183184
if addrErr != nil {
184185
return errors.Wrap(addrErr, "❌ failed to get capabilities registry address from state file")
185186
}
@@ -259,7 +260,7 @@ func deleteWorkflowCmd() *cobra.Command {
259260
workflowRegistryAddress = workflowRegistryAddressFlag
260261
contractsVersion = semver.MustParse(contractsVersionFlag)
261262
} else {
262-
addrRef, addrErr := addressRefFromStateFile(keystone_changeset.WorkflowRegistry.String())
263+
addrRef, addrErr := addressRefFromStateFile(keystone_changeset.WorkflowRegistry)
263264
if addrErr != nil {
264265
return errors.Wrap(addrErr, "❌ failed to get workflow registry address from state file")
265266
}
@@ -340,7 +341,7 @@ func deleteAllWorkflowsCmd() *cobra.Command {
340341
workflowRegistryAddress = workflowRegistryAddressFlag
341342
contractsVersion = semver.MustParse(contractsVersionFlag)
342343
} else {
343-
addrRef, addrErr := addressRefFromStateFile(keystone_changeset.WorkflowRegistry.String())
344+
addrRef, addrErr := addressRefFromStateFile(keystone_changeset.WorkflowRegistry)
344345
if addrErr != nil {
345346
return errors.Wrap(addrErr, "❌ failed to get workflow registry address from state file")
346347
}
@@ -541,24 +542,23 @@ func isBase64Content(content string) bool {
541542
return err == nil
542543
}
543544

544-
func addressRefFromStateFile(contractType string) (datastore.AddressRef, error) {
545-
envArtifact, artErr := environment.ReadEnvArtifact(environment.MustEnvArtifactAbsPath(relativePathToRepoRoot))
546-
if artErr != nil {
547-
return datastore.AddressRef{}, errors.Wrap(artErr, "failed to read environment artifact")
545+
func addressRefFromStateFile(contractType deployment.ContractType) (*datastore.AddressRef, error) {
546+
in := &envconfig.Config{}
547+
err := in.Load(envconfig.MustLocalCREStateFileAbsPath(relativePathToRepoRoot))
548+
if err != nil {
549+
return nil, errors.Wrap(err, "failed to load state file")
548550
}
549551

550-
ds := datastore.NewMemoryDataStore()
551-
for _, addrRef := range envArtifact.AddressRefs {
552-
addErr := ds.AddressRefStore.Add(addrRef)
553-
if addErr != nil {
554-
return datastore.AddressRef{}, fmt.Errorf("failed to add address ref to datastore %v: %w", addrRef, addErr)
555-
}
552+
addresses, aErr := in.GetAddresses()
553+
if aErr != nil {
554+
return nil, errors.Wrap(aErr, "failed to get addresses from cached input")
556555
}
557556

558-
contractVersion, ok := envArtifact.ContractVersions[contractType]
559-
if !ok {
560-
return datastore.AddressRef{}, fmt.Errorf("no contract version for contract type %s found in environment artifact", contractType)
557+
for _, addrRef := range addresses {
558+
if datastore.ContractType(contractType) == addrRef.Type {
559+
return &addrRef, nil
560+
}
561561
}
562562

563-
return contracts.MustGetAddressRefFromDataStore(ds.Seal(), envArtifact.RegistryChainSelector, contractType, contractVersion, ""), nil
563+
return nil, fmt.Errorf("did not find any address for %s contract", contractType)
564564
}

system-tests/lib/cre/environment/config/config.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"maps"
67
"os"
@@ -14,6 +15,7 @@ import (
1415
"github.com/pelletier/go-toml/v2"
1516
"github.com/pkg/errors"
1617

18+
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
1719
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1820
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
1921
billingplatformservice "github.com/smartcontractkit/chainlink-testing-framework/framework/components/dockercompose/billing_platform_service"
@@ -27,6 +29,33 @@ import (
2729
"github.com/smartcontractkit/chainlink/system-tests/lib/infra"
2830
)
2931

32+
// GetAddresses returns the addresses as datastore.AddressRef slice
33+
func (c *Config) GetAddresses() ([]datastore.AddressRef, error) {
34+
addresses := make([]datastore.AddressRef, len(c.Addresses))
35+
for i, addr := range c.Addresses {
36+
in := []byte(addr)
37+
var addrRef datastore.AddressRef
38+
if err := json.Unmarshal(in, &addrRef); err != nil {
39+
return nil, fmt.Errorf("failed to unmarshal address at index %d: %w", i, err)
40+
}
41+
addresses[i] = addrRef
42+
}
43+
return addresses, nil
44+
}
45+
46+
// SetAddresses sets the addresses from datastore.AddressRef slice
47+
func (c *Config) SetAddresses(refs []datastore.AddressRef) error {
48+
c.Addresses = make([]string, len(refs))
49+
for i, ref := range refs {
50+
asBytes, err := json.Marshal(ref)
51+
if err != nil {
52+
return fmt.Errorf("failed to marshal address at index %d: %w", i, err)
53+
}
54+
c.Addresses[i] = string(asBytes)
55+
}
56+
return nil
57+
}
58+
3059
type Config struct {
3160
Blockchains []*blockchain.Input `toml:"blockchains" validate:"required"`
3261
NodeSets []*cre.NodeSet `toml:"nodesets" validate:"required"`
@@ -36,6 +65,7 @@ type Config struct {
3665
FakeHTTP *fake.Input `toml:"fake_http" validate:"required"`
3766
S3ProviderInput *s3provider.Input `toml:"s3provider"`
3867
CapabilityConfigs map[string]cre.CapabilityConfig `toml:"capability_configs"` // capability flag -> capability config
68+
Addresses []string `toml:"addresses"`
3969

4070
mu sync.Mutex
4171
loaded bool

0 commit comments

Comments
 (0)