Repository: onflow/flow-cli (go)

Issue:
Update access node endpoints for Previewnet
Need to update crescendo to preview net

`access.previewnet.nodes.onflow.org:9000`

Pull request:
Add Previewnet network
Closes #1428 

## Description

______

For contributor use:

- [ ] Targeted PR against `master` branch
- [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work
- [x] Code follows the [standards mentioned here](https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md#styleguides)
- [x] Updated relevant documentation
- [x] Re-reviewed `Files changed` in the Github PR explorer
- [x] Added appropriate labels


Patch:
diff --git a/go.mod b/go.mod
index f2d945f6..036bdf21 100644
--- a/go.mod
+++ b/go.mod
@@ -16,8 +16,8 @@ require (
 	github.com/onflow/flixkit-go v1.2.1-cadence-v1-M3
 	github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240206003101-928bf99024d7
 	github.com/onflow/flow-emulator v1.0.0-M7
-	github.com/onflow/flow-go-sdk v1.0.0-M5
-	github.com/onflow/flowkit/v2 v2.0.0-stable-cadence-alpha.5
+	github.com/onflow/flow-go-sdk v1.0.0-M7
+	github.com/onflow/flowkit/v2 v2.0.0-stable-cadence-alpha.5.0.20240226193947-433a6c5a487d
 	github.com/onflowser/flowser/v3 v3.2.1-0.20240131200229-7d4d22715f48
 	github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
 	github.com/pkg/errors v0.9.1
@@ -179,7 +179,7 @@ require (
 	github.com/onflow/crypto v0.25.0 // indirect
 	github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 // indirect
 	github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20240205224107-320aa3cf09e0 // indirect
-	github.com/onflow/flow-go v0.34.0-crescendo-preview.1.0.20240222213538-3677206d445c // indirect
+	github.com/onflow/flow-go v0.34.0-crescendo-preview.4 // indirect
 	github.com/onflow/flow-nft/lib/go/contracts v1.1.1-0.20240205233530-86ee8c352fa6 // indirect
 	github.com/onflow/flow/protobuf/go/flow v0.3.7 // indirect
 	github.com/onflow/sdks v0.5.1-0.20230912225508-b35402f12bba // indirect
diff --git a/go.sum b/go.sum
index feaadaeb..ce99fcee 100644
--- a/go.sum
+++ b/go.sum
@@ -2076,18 +2076,18 @@ github.com/onflow/flow-emulator v1.0.0-M7 h1:8moFcl+KNAU1YOnEJim+x1pUGA5IRdfcBPg
 github.com/onflow/flow-emulator v1.0.0-M7/go.mod h1:S611ccJDDFLC99+VIAL8slsJx5Y9rxljFCY1aS67okU=
 github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20240205224107-320aa3cf09e0 h1:u6/YcUvO8jU0f3Evb/6agzXqeOo+VbL2a3mmj/5ifRs=
 github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20240205224107-320aa3cf09e0/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A=
-github.com/onflow/flow-go v0.34.0-crescendo-preview.1.0.20240222213538-3677206d445c h1:G3xZCm3FnckxGVTcgxUUTzrreYy3LxjsQl3PApbO1bc=
-github.com/onflow/flow-go v0.34.0-crescendo-preview.1.0.20240222213538-3677206d445c/go.mod h1:bvwbHFWiPGkASyJ+ZdSp7mZAOCqpSlCtza9JeKSmfEE=
+github.com/onflow/flow-go v0.34.0-crescendo-preview.4 h1:p0BwDm1b7qrD8roDEnPm1AeOqPU3XQr1wBXlUsoXzuU=
+github.com/onflow/flow-go v0.34.0-crescendo-preview.4/go.mod h1:IMzI9CSTnXnA7Ei15k4lUZ3+5XXJEaxJlwgcS8wxeGs=
 github.com/onflow/flow-go-sdk v1.0.0-M1/go.mod h1:TDW0MNuCs4SvqYRUzkbRnRmHQL1h4X8wURsCw9P9beo=
-github.com/onflow/flow-go-sdk v1.0.0-M5 h1:R86DQQfXS3z8O6AShAaUNbkPOM7lOwcTk06cofdVEsk=
-github.com/onflow/flow-go-sdk v1.0.0-M5/go.mod h1:aXSavLzoRlz5FiMjcI7p5QhihWScGctxydzf4dv/avo=
+github.com/onflow/flow-go-sdk v1.0.0-M7 h1:5EhtgpupjdhJZoHpu8AhA7++AroGL6BFpb8D0AYIUQw=
+github.com/onflow/flow-go-sdk v1.0.0-M7/go.mod h1:aXSavLzoRlz5FiMjcI7p5QhihWScGctxydzf4dv/avo=
 github.com/onflow/flow-nft/lib/go/contracts v1.1.1-0.20240205233530-86ee8c352fa6 h1:/2vvjKkWG/3cKP3IpgiGNqXi0yskn4GmNTjmeCwMoz8=
 github.com/onflow/flow-nft/lib/go/contracts v1.1.1-0.20240205233530-86ee8c352fa6/go.mod h1:2gpbza+uzs1k7x31hkpBPlggIRkI53Suo0n2AyA2HcE=
 github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20231121210617-52ee94b830c2/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
 github.com/onflow/flow/protobuf/go/flow v0.3.7 h1:+6sBdlE/u4ZMTVB9U1lA6Xn2Bd48lOOX96Bv9dNubsk=
 github.com/onflow/flow/protobuf/go/flow v0.3.7/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
-github.com/onflow/flowkit/v2 v2.0.0-stable-cadence-alpha.5 h1:A7M6BgzS1aed4BIb2UpZcTIZOdfk+wo2/2Qzl+X6/Yc=
-github.com/onflow/flowkit/v2 v2.0.0-stable-cadence-alpha.5/go.mod h1:dE+sqHi14wUBiJyeujA2LYVsJDTcXLzSRwiDdJJHji4=
+github.com/onflow/flowkit/v2 v2.0.0-stable-cadence-alpha.5.0.20240226193947-433a6c5a487d h1:tonfzZKX5ZZo4tzkpD7GAEF680Xas+ZxcCsLSzJ00d0=
+github.com/onflow/flowkit/v2 v2.0.0-stable-cadence-alpha.5.0.20240226193947-433a6c5a487d/go.mod h1:dE+sqHi14wUBiJyeujA2LYVsJDTcXLzSRwiDdJJHji4=
 github.com/onflow/sdks v0.5.1-0.20230912225508-b35402f12bba h1:rIehuhO6bj4FkwE4VzwEjX7MoAlOhUJENBJLqDqVxAo=
 github.com/onflow/sdks v0.5.1-0.20230912225508-b35402f12bba/go.mod h1:F0dj0EyHC55kknLkeD10js4mo14yTdMotnWMslPirrU=
 github.com/onflow/wal v0.0.0-20240208022732-d756cd497d3b h1:6O/BEmA99PDT5QVjoJgrYlGsWnpxGJTAMmsC+V9gyds=
diff --git a/internal/config/add-contract.go b/internal/config/add-contract.go
index c9a64f69..3153e2ee 100644
--- a/internal/config/add-contract.go
+++ b/internal/config/add-contract.go
@@ -95,6 +95,13 @@ func addContract(
 		)
 	}
 
+	if raw.Previewnet != "" {
+		contract.Aliases.Add(
+			config.PreviewnetNetwork.Name,
+			flow.HexToAddress(raw.Mainnet),
+		)
+	}
+
 	state.Contracts().AddOrUpdate(contract)
 
 	err = state.SaveEdited(globalFlags.ConfigPaths)
diff --git a/internal/dependencymanager/dependencyinstaller.go b/internal/dependencymanager/dependencyinstaller.go
index 09d6280b..9a42f4ff 100644
--- a/internal/dependencymanager/dependencyinstaller.go
+++ b/internal/dependencymanager/dependencyinstaller.go
@@ -65,10 +65,16 @@ func NewDependencyInstaller(logger output.Logger, state *flowkit.State) (*Depend
 		return nil, fmt.Errorf("error creating mainnet gateway: %v", err)
 	}
 
+	previewnetGateway, err := gateway.NewGrpcGateway(config.PreviewnetNetwork)
+	if err != nil {
+		return nil, fmt.Errorf("error creating previewnet gateway: %v", err)
+	}
+
 	gateways := map[string]gateway.Gateway{
-		config.EmulatorNetwork.Name: emulatorGateway,
-		config.TestnetNetwork.Name:  testnetGateway,
-		config.MainnetNetwork.Name:  mainnetGateway,
+		config.EmulatorNetwork.Name:   emulatorGateway,
+		config.TestnetNetwork.Name:    testnetGateway,
+		config.MainnetNetwork.Name:    mainnetGateway,
+		config.PreviewnetNetwork.Name: previewnetGateway,
 	}
 
 	return &DependencyInstaller{
diff --git a/internal/util/prompt.go b/internal/util/prompt.go
index 8df24f74..66eefbe0 100644
--- a/internal/util/prompt.go
+++ b/internal/util/prompt.go
@@ -341,11 +341,12 @@ func NewAccountPrompt() *AccountData {
 }
 
 type ContractData struct {
-	Name     string
-	Source   string
-	Emulator string
-	Testnet  string
-	Mainnet  string
+	Name       string
+	Source     string
+	Emulator   string
+	Testnet    string
+	Mainnet    string
+	Previewnet string
 }
 
 func NewContractPrompt() *ContractData {
@@ -611,9 +612,10 @@ func ReportCrash() bool {
 
 func CreateAccountNetworkPrompt() (string, config.Network) {
 	networkMap := map[string]config.Network{
-		"Emulator": config.EmulatorNetwork,
-		"Testnet":  config.TestnetNetwork,
-		"Mainnet":  config.MainnetNetwork,
+		"Emulator":   config.EmulatorNetwork,
+		"Testnet":    config.TestnetNetwork,
+		"Mainnet":    config.MainnetNetwork,
+		"Previewnet": config.PreviewnetNetwork,
 	}
 
 	networkPrompt := promptui.Select{
diff --git a/internal/util/util.go b/internal/util/util.go
index 0e2fce51..3c28c883 100644
--- a/internal/util/util.go
+++ b/internal/util/util.go
@@ -72,6 +72,7 @@ func GetAddressNetwork(address flowsdk.Address) (flowsdk.ChainID, error) {
 		flowsdk.Mainnet,
 		flowsdk.Testnet,
 		flowsdk.Emulator,
+		flowsdk.Previewnet,
 	}
 	for _, net := range networks {
 		if address.IsValid(net) {


Test patch:
diff --git a/internal/dependencymanager/dependencyinstaller_test.go b/internal/dependencymanager/dependencyinstaller_test.go
index cd63691f..9fd03cde 100644
--- a/internal/dependencymanager/dependencyinstaller_test.go
+++ b/internal/dependencymanager/dependencyinstaller_test.go
@@ -70,9 +70,10 @@ func TestDependencyInstallerInstall(t *testing.T) {
 
 		di := &DependencyInstaller{
 			Gateways: map[string]gateway.Gateway{
-				config.EmulatorNetwork.Name: gw.Mock,
-				config.TestnetNetwork.Name:  gw.Mock,
-				config.MainnetNetwork.Name:  gw.Mock,
+				config.EmulatorNetwork.Name:   gw.Mock,
+				config.TestnetNetwork.Name:    gw.Mock,
+				config.MainnetNetwork.Name:    gw.Mock,
+				config.PreviewnetNetwork.Name: gw.Mock,
 			},
 			Logger: logger,
 			State:  state,
@@ -112,9 +113,10 @@ func TestDependencyInstallerAdd(t *testing.T) {
 
 		di := &DependencyInstaller{
 			Gateways: map[string]gateway.Gateway{
-				config.EmulatorNetwork.Name: gw.Mock,
-				config.TestnetNetwork.Name:  gw.Mock,
-				config.MainnetNetwork.Name:  gw.Mock,
+				config.EmulatorNetwork.Name:   gw.Mock,
+				config.TestnetNetwork.Name:    gw.Mock,
+				config.MainnetNetwork.Name:    gw.Mock,
+				config.PreviewnetNetwork.Name: gw.Mock,
 			},
 			Logger: logger,
 			State:  state,