Skip to content

Commit

Permalink
Merge pull request #36 from HugoByte/DIVE-455-E2E-demo-Script-Refacto…
Browse files Browse the repository at this point in the history
…r-hard-coded-data

test: e2e demo script refactor hard coded data and run parallely
  • Loading branch information
Mr-Nobody21 authored Dec 21, 2023
2 parents 91a6995 + d93375c commit ed1d61a
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/archway-chain-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

jobs:
functional_test:
functional_test_archway:
name: Archway Chain Functional Testing
runs-on: "ubuntu-latest"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bridge-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

jobs:
functional_test:
functional_test_bridge:
name: Bridge Functional Testing
runs-on: "ubuntu-latest"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/eth-chain-test .yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

jobs:
functional_test:
functional_test_eth:
name: Eth Chain Functional Testing
runs-on: "ubuntu-latest"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hardhat-chain-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

jobs:
functional_test:
functional_test_hardhat:
name: Hardhat Chain Functional Testing
runs-on: "ubuntu-latest"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/icon-chain-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

jobs:
functional_test:
functional_test_icon:
name: Icon Chain Functional Testing
runs-on: "ubuntu-latest"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/misc-cmd-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

jobs:
functional_test:
functional_test_misc:
name: Misc Functional Testing
runs-on: "ubuntu-latest"

Expand Down
14 changes: 7 additions & 7 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ clean-dep:

run-smoke: BINARY
@echo "Running Smoke test cases"
@cd $(CURDIR)/functional && ginkgo --focus="Smoke Tests" -v
@cd $(CURDIR)/functional && ginkgo --focus="Smoke Tests" -v -p

run-bridge: BINARY
@echo "Running all bridge test cases"
@cd $(CURDIR)/functional && ginkgo --focus="Bridge command Test" -v -timeout=3h
@cd $(CURDIR)/functional && ginkgo --focus="Bridge command Test" -v -p -timeout=3h

run-icon: BINARY
@echo "Running icon chain commands test cases"
@cd $(CURDIR)/functional && ginkgo --focus="Icon chain commands" -v -timeout=3h
@cd $(CURDIR)/functional && ginkgo --focus="Icon chain commands" -v -p -timeout=3h

run-eth: BINARY
@echo "Running eth chain commands test cases"
@cd $(CURDIR)/functional && ginkgo --focus="Eth chain commands" -v -timeout=3h
@cd $(CURDIR)/functional && ginkgo --focus="Eth chain commands" -v -p -timeout=3h

run-hardhat: BINARY
@echo "Running hardhat chain commands test cases"
@cd $(CURDIR)/functional && ginkgo --focus="Hardhat chain commands" -v -timeout=3h
@cd $(CURDIR)/functional && ginkgo --focus="Hardhat chain commands" -v -p -timeout=3h

run-archway: BINARY
@echo "Running archway chain commands test cases"
@cd $(CURDIR)/functional && ginkgo --focus="Archway chain commands" -v -timeout=3h
@cd $(CURDIR)/functional && ginkgo --focus="Archway chain commands" -v -p -timeout=3h

run-misc: BINARY
@echo "Running other test cases"
@cd $(CURDIR)/functional && ginkgo --focus="Other commands" -v -timeout=3h
@cd $(CURDIR)/functional && ginkgo --focus="Other commands" -v -p -timeout=3h

BINARY: GINKGO
@cd $(CURDIR)/../cli && go build -o dive
Expand Down
31 changes: 31 additions & 0 deletions test/functional/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dive

const(
ICON_CONFIG0 = "../../cli/sample-jsons/config0.json"
ICON_GENESIS0 = "./config/genesis-icon-0.zip"
ICON_CONFIG0_SERVICENAME = "icon-node-0xacbc4e"

ICON_CONFIG1 = "../../cli/sample-jsons/config1.json"
ICON_GENESIS1 = "./config/genesis-icon-1.zip"
ICON_CONFIG1_SERVICENAME = "icon-node-0x42f1f3"

ARCHWAY_CONFIG0 = "../../cli/sample-jsons/archway.json"
ARCHWAY_CONFIG0_SERVICENAME = "node-service-archway-node-0"

ARCHWAY_CONFIG1 = "../../cli/sample-jsons/archway1.json"
ARCHWAY_CONFIG1_SERVICENAME = "node-service-archway-node-1"

NEUTRON_CONFIG0 = "../../cli/sample-jsons/neutron.json"
NEUTRON_CONFIG0_SERVICENAME = "neutron-node-test-chain2"

NEUTRON_CONFIG1 = "../../cli/sample-jsons/neutron1.json"
NEUTRON_CONFIG1_SERVICENAME = "neutron-node-test-chain3"

ETH_SERVICENAME = "el-1-geth-lighthouse"
HARDHAT_SERVICENAME = "hardhat-node"

DEFAULT_ARCHWAY_SERVICENAME = "node-service-constantine-3"
DEFAULT_NEUTRON_SERVICENAME = "neutron-node-test-chain1"


)
230 changes: 133 additions & 97 deletions test/functional/dive_test.go

Large diffs are not rendered by default.

131 changes: 66 additions & 65 deletions test/functional/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,68 +109,63 @@ func RunDecentralizedIconNode(enclaveName string) {

func RunDecentralizedCustomIconNode1(enclaveName string) {
cmd := GetBinaryCommand()
filepath := "../../cli/sample-jsons/config1.json"
updated_path := UpdatePublicPort(filepath)
cmd.Args = append(cmd.Args, "chain", "icon", "-c", updated_path, "-g", "./config/genesis-icon-1.zip", "-d", "--enclaveName", enclaveName)
updated_path := UpdatePublicPort(enclaveName, ICON_CONFIG1)
cmd.Args = append(cmd.Args, "chain", "icon", "-c", updated_path, "-g", ICON_GENESIS1, "-d", "--enclaveName", enclaveName)
err := cmd.Run()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

func RunCustomIconNode(enclaveName string) {
func RunCustomIconNode0(enclaveName string) {
cmd := GetBinaryCommand()
filepath := "../../cli/sample-jsons/config0.json"
updated_path := UpdatePublicPort(filepath)
cmd.Args = append(cmd.Args, "chain", "icon", "-c", updated_path, "-g", "./config/genesis-icon-0.zip", "--enclaveName", enclaveName)
updated_path := UpdatePublicPort(enclaveName, ICON_CONFIG0)
cmd.Args = append(cmd.Args, "chain", "icon", "-c", updated_path, "-g", ICON_GENESIS0, "--enclaveName", enclaveName)
err := cmd.Run()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

func RunCustomArchwayNode1(enclaveName string) {
func RunCustomIconNode1(enclaveName string) {
cmd := GetBinaryCommand()
filepath1 := "../../cli/sample-jsons/archway1.json"
updated_path1 := UpdatePublicPorts(filepath1)
cmd.Args = append(cmd.Args, "chain", "archway", "-c", updated_path1,"--enclaveName", enclaveName )
updated_path := UpdatePublicPort(enclaveName, ICON_CONFIG1)
cmd.Args = append(cmd.Args, "chain", "icon", "-c", updated_path, "-g", ICON_GENESIS1, "--enclaveName", enclaveName)
err := cmd.Run()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

func RunCustomArchwayNode0(enclaveName string) {
func RunCustomArchwayNode1(enclaveName string) {
cmd := GetBinaryCommand()
filepath1 := "../../cli/sample-jsons/archway.json"
updated_path1 := UpdatePublicPorts(filepath1)
cmd.Args = append(cmd.Args, "chain", "archway", "-c",updated_path1,"--enclaveName", enclaveName )
updated_path1 := UpdatePublicPorts(ARCHWAY_CONFIG1)
cmd.Args = append(cmd.Args, "chain", "archway", "-c", updated_path1, "--enclaveName", enclaveName)
err := cmd.Run()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

func RunCustomNeutronNode1(enclaveName string) {
func RunCustomArchwayNode0(enclaveName string) {
cmd := GetBinaryCommand()
filepath2 := "../../cli/sample-jsons/neutron1.json"
updated_path2 := UpdateNeutronPublicPorts(filepath2)
cmd.Args = append(cmd.Args, "chain", "neutron", "-c", updated_path2,"--enclaveName", enclaveName)
updated_path1 := UpdatePublicPorts(ARCHWAY_CONFIG0)
cmd.Args = append(cmd.Args, "chain", "archway", "-c", updated_path1, "--enclaveName", enclaveName)
err := cmd.Run()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

func RunCustomNeutronNode0(enclaveName string) {
func RunCustomNeutronNode1(enclaveName string) {
cmd := GetBinaryCommand()
filepath2 := "../../cli/sample-jsons/neutron.json"
updated_path2 := UpdateNeutronPublicPorts(filepath2)
cmd.Args = append(cmd.Args, "chain", "neutron", "-c", updated_path2,"--enclaveName", enclaveName)
updated_path2 := UpdateNeutronPublicPorts(NEUTRON_CONFIG1)
cmd.Args = append(cmd.Args, "chain", "neutron", "-c", updated_path2, "--enclaveName", enclaveName)
err := cmd.Run()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

func DecentralizeCustomIconNode() {
func RunCustomNeutronNode0(enclaveName string) {
cmd := GetBinaryCommand()
cmd.Args = append(cmd.Args, "chain", "icon", "decentralize", "-p", "gochain", "-k", "keystores/keystore.json", "-n", "0x101", "-e", "http://172.16.0.4:9081/api/v3/icon_dex", "-s", "icon-node-0x42f1f3", "--verbose")
updated_path2 := UpdateNeutronPublicPorts(NEUTRON_CONFIG0)
cmd.Args = append(cmd.Args, "chain", "neutron", "-c", updated_path2, "--enclaveName", enclaveName)
err := cmd.Run()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

func DecentralizeIconNode(enclaveName string) {
func DecentralizeCustomIconNode(nid string, endpoint string, serviceName string, enclaveName string) {
cmd := GetBinaryCommand()
cmd.Args = append(cmd.Args, "chain", "icon", "decentralize", "-p", "gochain", "-k", "keystores/keystore.json", "-n", "0x3", "-e", "http://172.16.0.3:9080/api/v3/icon_dex", "-s", "icon-node-0xacbc4e", "--verbose", "--enclaveName", enclaveName)
cmd.Args = append(cmd.Args, "chain", "icon", "decentralize", "-p", "gochain", "-k", "keystores/keystore.json", "-n", nid, "-e", endpoint, "-s", serviceName, "--verbose", "--enclaveName", enclaveName)
err := cmd.Run()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
Expand All @@ -191,30 +186,18 @@ func RunHardhatNode(enclaveName string) {

func RunDecentralizedCustomIconNode0(enclaveName string) {
cmd := GetBinaryCommand()
filepath := "../../cli/sample-jsons/config0.json"
updated_path := UpdatePublicPort(filepath)
cmd.Args = append(cmd.Args, "chain", "icon", "-c", updated_path, "-g", "./config/genesis-icon-0.zip", "-d", "--enclaveName", enclaveName)
err := cmd.Run()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

func RunCustomIconNode_0() {
cmd := GetBinaryCommand()
cmd.Args = append(cmd.Args, "chain", "icon", "-c", "../../cli/sample-jsons/config0.json", "-g", "./config/genesis-icon-0.zip")
err := cmd.Run()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

func DecentralizeCustomIconNode_0() {
cmd := GetBinaryCommand()
cmd.Args = append(cmd.Args, "chain", "icon", "decentralize", "-p", "gochain", "-k", "keystores/keystore.json", "-n", "0x3", "-e", "http://172.16.0.3:9080/api/v3/icon_dex", "-s", "icon-node-0xacbc4e", "--verbose")
updated_path := UpdatePublicPort(enclaveName, ICON_CONFIG0)
cmd.Args = append(cmd.Args, "chain", "icon", "-c", updated_path, "-g", ICON_GENESIS0, "-d", "--enclaveName", enclaveName)
err := cmd.Run()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

var mutex = &sync.Mutex{}
var mutex1 = &sync.Mutex{}
var mutex2 = &sync.Mutex{}
var mutex3 = &sync.Mutex{}

func UpdatePublicPort(filePath string) string {
func UpdatePublicPort(enclaveName string, filePath string) string {
mutex.Lock()
defer mutex.Unlock()
fileContent, err := os.ReadFile(filePath)
Expand All @@ -233,19 +216,12 @@ func UpdatePublicPort(filePath string) string {
panic(err)
}
config.PublicPort = availablePort
// config.CID = "0xacbc4e"
// config.P2PAddress = "8080"
// config.P2PListenAddress = "7080"
// config.PrivatePort = 9080

updatedJSON, err := json.MarshalIndent(config, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(updatedJSON))

name := GenerateRandomName()
tmpfile, err := os.Create(fmt.Sprintf("updated-config-%s.json", name))
tmpfile, err := os.Create(fmt.Sprintf("updated-config-%s.json", enclaveName))
if err != nil {
panic(err)
}
Expand All @@ -260,19 +236,11 @@ func UpdatePublicPort(filePath string) string {
return tmpfile.Name()
}

// // Write the updated JSON back to the same file
// err = os.WriteFile(filePath, updatedJSON, 0644)
// if err != nil {
// panic(err)
// }

//var mutex = &sync.Mutex{}

// Assuming Archway struct is defined as mentioned earlier

func UpdatePublicPorts(filePath1 string) string {
mutex.Lock()
defer mutex.Unlock()
mutex1.Lock()
defer mutex1.Unlock()

// Read the content of the existing JSON file
fileContent1, err := os.ReadFile(filePath1)
Expand Down Expand Up @@ -337,8 +305,8 @@ func UpdatePublicPorts(filePath1 string) string {
}

func UpdateNeutronPublicPorts(filePath2 string) string {
mutex.Lock()
defer mutex.Unlock()
mutex2.Lock()
defer mutex2.Unlock()

// Read the content of the existing JSON file
fileContent2, err := os.ReadFile(filePath2)
Expand Down Expand Up @@ -401,3 +369,36 @@ func UpdateNeutronPublicPorts(filePath2 string) string {

return tmpfile.Name()
}

type NodeInfo struct {
ServiceName string `json:"service_name"`
EndpointPublic string `json:"endpoint"`
Nid string `json:"nid"`
}

func GetServiceDetails(servicesJson string, service string) (serviceName string, endpoint string, nid string) {
var data map[string]NodeInfo
mutex3.Lock()
defer mutex3.Unlock()

fileContent2, err := os.ReadFile(servicesJson)
if err != nil {
panic(err)
}

err = json.Unmarshal(fileContent2, &data)
if err != nil {
panic(err)
}

for key, value := range data {
if key == service {
serviceName = value.ServiceName
endpoint = value.EndpointPublic
nid = value.Nid
}

}
return serviceName, endpoint, nid

}

0 comments on commit ed1d61a

Please sign in to comment.