From 74e3bf6ce0395d9a20dab4e133302efdbc9b808d Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Wed, 21 Feb 2024 09:07:39 +0530 Subject: [PATCH] chore: update formatting --- test/functional/helper.go | 161 ++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 83 deletions(-) diff --git a/test/functional/helper.go b/test/functional/helper.go index 0b852579..a0481694 100644 --- a/test/functional/helper.go +++ b/test/functional/helper.go @@ -4,14 +4,13 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/google/uuid" - "github.com/onsi/gomega" "os" "os/exec" "path/filepath" "sync" - //"github.com/hugobyte/dive-core/cli/common" + "github.com/google/uuid" + "github.com/onsi/gomega" ) type NodeInfo struct { @@ -150,7 +149,7 @@ func RunCustomNeutronNode1(enclaveName string) { func RunCustomNeutronNode0(enclaveName string) { cmd := GetBinaryCommand() //updated_path2 := UpdateNeutronPublicPorts(NEUTRON_CONFIG0) - cmd.Args = append(cmd.Args, "chain", "neutron", "-c",NEUTRON_CONFIG0 , "--enclaveName", enclaveName) + cmd.Args = append(cmd.Args, "chain", "neutron", "-c", NEUTRON_CONFIG0, "--enclaveName", enclaveName) err := cmd.Run() gomega.Expect(err).NotTo(gomega.HaveOccurred()) } @@ -178,7 +177,7 @@ func RunHardhatNode(enclaveName string) { func RunDecentralizedCustomIconNode0(enclaveName string) { cmd := GetBinaryCommand() - cmd.Args = append(cmd.Args, "chain", "icon", "-c",ICON_CONFIG0 , "-g", ICON_GENESIS0, "-d", "--enclaveName", enclaveName) + cmd.Args = append(cmd.Args, "chain", "icon", "-c", ICON_CONFIG0, "-g", ICON_GENESIS0, "-d", "--enclaveName", enclaveName) err := cmd.Run() gomega.Expect(err).NotTo(gomega.HaveOccurred()) } @@ -211,43 +210,43 @@ func GetServiceDetails(servicesJson string, service string) (serviceName string, } func UpdateRelayChain(filePath, newChainType, newRelayChainName, enclaveName string, newNodeType1, newNodeType2 string, relayChain string) string { - mutex.Lock() - defer mutex.Unlock() - - fileContent, err := os.ReadFile(filePath) - if err != nil { - panic(err) - } - - var local Configuration1 - err = json.Unmarshal(fileContent, &local) - if err != nil { - panic(err) - } - - // Update ChainType and RelayChain Name - local.ChainType = newChainType - local.RelayChain.Name = newRelayChainName - - // Update NodeType for RelayChain Nodes - for i := range local.RelayChain.Nodes { - if i%2 == 0 { - local.RelayChain.Nodes[i].NodeType = newNodeType1 - } else { - local.RelayChain.Nodes[i].NodeType = newNodeType2 - } - } - - // Update Prometheus for Para Nodes - for i := range local.Parachains { - if relayChain == "kusama"{ + mutex.Lock() + defer mutex.Unlock() + + fileContent, err := os.ReadFile(filePath) + if err != nil { + panic(err) + } + + var local Configuration1 + err = json.Unmarshal(fileContent, &local) + if err != nil { + panic(err) + } + + // Update ChainType and RelayChain Name + local.ChainType = newChainType + local.RelayChain.Name = newRelayChainName + + // Update NodeType for RelayChain Nodes + for i := range local.RelayChain.Nodes { + if i%2 == 0 { + local.RelayChain.Nodes[i].NodeType = newNodeType1 + } else { + local.RelayChain.Nodes[i].NodeType = newNodeType2 + } + } + + // Update Prometheus for Para Nodes + for i := range local.Parachains { + if relayChain == "kusama" { local.Parachains[i].Name = "karura" } else { local.Parachains[i].Name = "acala" } - } + } - // Remove content inside RelayChain + // Remove content inside RelayChain local.Parachains = []struct { Name string `json:"name"` Nodes []struct { @@ -257,29 +256,26 @@ func UpdateRelayChain(filePath, newChainType, newRelayChainName, enclaveName str } `json:"nodes"` }{} + updatedJSON, err := json.MarshalIndent(local, "", " ") + if err != nil { + panic(err) + } - updatedJSON, err := json.MarshalIndent(local, "", " ") - if err != nil { - panic(err) - } - - tmpfilePath := fmt.Sprintf("updated-config-%s.json", enclaveName) - tmpfile, err := os.Create(tmpfilePath) - if err != nil { - panic(err) - } - defer tmpfile.Close() + tmpfilePath := fmt.Sprintf("updated-config-%s.json", enclaveName) + tmpfile, err := os.Create(tmpfilePath) + if err != nil { + panic(err) + } + defer tmpfile.Close() - _, err = tmpfile.Write(updatedJSON) - if err != nil { - panic(err) - } + _, err = tmpfile.Write(updatedJSON) + if err != nil { + panic(err) + } - return tmpfile.Name() + return tmpfile.Name() } - - func UpdateParaChain(filePath, newChainType, newParaName string) string { mutex.Lock() defer mutex.Unlock() @@ -294,7 +290,7 @@ func UpdateParaChain(filePath, newChainType, newParaName string) string { if err != nil { panic(err) } -//update chain type + //update chain type local.ChainType = newChainType // Remove content inside RelayChain local.RelayChain = struct { @@ -316,12 +312,11 @@ func UpdateParaChain(filePath, newChainType, newParaName string) string { panic(err) } - - tmpfilePath := fmt.Sprintf("updated-local.json") - tmpfile, err := os.Create(tmpfilePath) - if err != nil { - panic(err) - } + tmpfilePath := fmt.Sprintf("updated-local.json") + tmpfile, err := os.Create(tmpfilePath) + if err != nil { + panic(err) + } defer tmpfile.Close() @@ -333,7 +328,7 @@ func UpdateParaChain(filePath, newChainType, newParaName string) string { return tmpfile.Name() } -func UpdateChainInfo(filePath, newChainType, newRelayChainName, newParaName string,newNodeType1,newNodeType2 string) string { +func UpdateChainInfo(filePath, newChainType, newRelayChainName, newParaName string, newNodeType1, newNodeType2 string) string { mutex.Lock() defer mutex.Unlock() @@ -355,16 +350,16 @@ func UpdateChainInfo(filePath, newChainType, newRelayChainName, newParaName stri // Update Name and Prometheus for Para Nodes for i := range local.Parachains { local.Parachains[i].Name = newParaName - + + } + // Update NodeType for RelayChain Nodes + for i := range local.RelayChain.Nodes { + if i%2 == 0 { + local.RelayChain.Nodes[i].NodeType = newNodeType1 + } else { + local.RelayChain.Nodes[i].NodeType = newNodeType2 + } } - // Update NodeType for RelayChain Nodes - for i := range local.RelayChain.Nodes { - if i%2 == 0 { - local.RelayChain.Nodes[i].NodeType = newNodeType1 - } else { - local.RelayChain.Nodes[i].NodeType = newNodeType2 - } - } updatedJSON, err := json.MarshalIndent(local, "", " ") if err != nil { @@ -372,10 +367,10 @@ func UpdateChainInfo(filePath, newChainType, newRelayChainName, newParaName stri } tmpfilePath := fmt.Sprintf("updated-local.json") - tmpfile, err := os.Create(tmpfilePath) - if err != nil { - panic(err) - } + tmpfile, err := os.Create(tmpfilePath) + if err != nil { + panic(err) + } defer tmpfile.Close() @@ -386,11 +381,11 @@ func UpdateChainInfo(filePath, newChainType, newRelayChainName, newParaName stri return tmpfile.Name() } -func CheckInvalidTestnet(selectedParaChain string, invalidParaChainlist []string)bool{ - for _, paraChainName := range invalidParaChainlist { - if selectedParaChain == paraChainName { - return true - } +func CheckInvalidTestnet(selectedParaChain string, invalidParaChainlist []string) bool { + for _, paraChainName := range invalidParaChainlist { + if selectedParaChain == paraChainName { + return true } - return false - } \ No newline at end of file + } + return false +}