Skip to content

Commit

Permalink
feat: add zetae2e serve-addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Jun 27, 2024
1 parent ef8470c commit 2a4ba05
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmd/zetae2e/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func NewRootCmd() *cobra.Command {
NewStressTestCmd(),
NewInitCmd(),
NewSetupBitcoinCmd(),
NewServeAddressesCmd(),
)

return cmd
Expand Down
108 changes: 108 additions & 0 deletions cmd/zetae2e/serve_addresses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package main

import (
"encoding/json"
"fmt"
"net/http"
"os"

"github.com/ethereum/go-ethereum/log"
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/e2e/config"
)

type v1AddressItem struct {
Address string `json:"address"`
Category string `json:"category"`
ChainID int `json:"chain_id"`
ChainName string `json:"chain_name"`
Type string `json:"type"`
}

func NewServeAddressesCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "serve-addresses",
Short: "Serve addresses of deployed contracts from config file",
RunE: runServeAddresses,
}
cmd.Flags().StringVarP(&configFile, flagConfig, "c", "", "path to the configuration file")
if err := cmd.MarkFlagRequired(flagConfig); err != nil {
fmt.Println("Error marking flag as required")
os.Exit(1)
}
chainName, ok := os.LookupEnv("CHAIN_NAME")
if !ok {
chainName = "localnet"
}
cmd.Flags().String("chain-name", chainName, "name of the chain to return in results")
return cmd
}

func runServeAddresses(cmd *cobra.Command, args []string) error {

Check failure on line 41 in cmd/zetae2e/serve_addresses.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 41 in cmd/zetae2e/serve_addresses.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 41 in cmd/zetae2e/serve_addresses.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive)
// read the config file
configPath, err := cmd.Flags().GetString(flagConfig)
if err != nil {
return err
}
chainName, err := cmd.Flags().GetString("chain-name")
if err != nil {
return err
}

ethChainName := fmt.Sprintf("eth_%s", chainName)
zetaChainName := fmt.Sprintf("zeta_%s", chainName)

// we load the config file in the request because it may not be populated on start

http.HandleFunc("/v1/addresses", func(w http.ResponseWriter, r *http.Request) {

Check failure on line 57 in cmd/zetae2e/serve_addresses.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 57 in cmd/zetae2e/serve_addresses.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 57 in cmd/zetae2e/serve_addresses.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
conf, err := config.ReadConfig(configPath)
if err != nil {
log.Error("unable to read config: %v", err)
w.WriteHeader(500)
return
}

// TODO: pull TSS addresses, ZRC20 addresses from zetacored
res := []v1AddressItem{
// eth
{
Address: conf.Contracts.EVM.ConnectorEthAddr.String(),
Category: "messaging",
ChainID: 1337,
ChainName: ethChainName,
Type: "connector",
},
{
Address: conf.Contracts.EVM.CustodyAddr.String(),
Category: "omnichain",
ChainID: 1337,
ChainName: ethChainName,
Type: "erc20Custody",
},
// zeta
{
Address: conf.Contracts.ZEVM.ConnectorZEVMAddr.String(),
Category: "messaging",
ChainID: 101,
ChainName: zetaChainName,
Type: "connector",
},
{
Address: conf.Contracts.ZEVM.SystemContractAddr.String(),
Category: "omnichain",
ChainID: 101,
ChainName: zetaChainName,
Type: "systemContract",
},
}

err = json.NewEncoder(w).Encode(res)
if err != nil {
log.Error("unable to read config: %v", err)
w.WriteHeader(500)
return
}
})

return http.ListenAndServe(":9991", nil)

Check failure on line 107 in cmd/zetae2e/serve_addresses.go

View workflow job for this annotation

GitHub Actions / lint

G114: Use of net/http serve function that has no support for setting timeouts (gosec)

Check failure on line 107 in cmd/zetae2e/serve_addresses.go

View workflow job for this annotation

GitHub Actions / lint

G114: Use of net/http serve function that has no support for setting timeouts (gosec)

Check failure on line 107 in cmd/zetae2e/serve_addresses.go

View workflow job for this annotation

GitHub Actions / lint

G114: Use of net/http serve function that has no support for setting timeouts (gosec)
}
17 changes: 16 additions & 1 deletion contrib/localnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ services:
- UPGRADE_HEIGHT=${UPGRADE_HEIGHT}
volumes:
- ssh:/root/.ssh
- config:/config
address-server:
image: orchestrator:latest
container_name: address-server
hostname: address-server
ports:
- "9991:9991"
networks:
mynetwork:
ipv4_address: 172.20.0.3
entrypoint: ["zetae2e", "serve-addresses", "--config=/config/deployed.yml"]
volumes:
- ssh:/root/.ssh
- config:/config
volumes:
ssh:
preparams:
preparams:
config:
14 changes: 7 additions & 7 deletions contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ if [ "$LOCALNET_MODE" == "upgrade" ]; then
UPGRADE_HEIGHT=${UPGRADE_HEIGHT:=225}

if [[ ! -f deployed.yml ]]; then
zetae2e local $E2E_ARGS --setup-only --config config.yml --config-out deployed.yml --skip-header-proof
zetae2e local $E2E_ARGS --setup-only --config config.yml --config-out /config/deployed.yml --skip-header-proof
if [ $? -ne 0 ]; then
echo "e2e setup failed"
exit 1
Expand All @@ -101,7 +101,7 @@ if [ "$LOCALNET_MODE" == "upgrade" ]; then
echo "running E2E command to setup the networks and populate the state..."

# Use light flag to ensure tests can complete before the upgrade height
zetae2e local $E2E_ARGS --skip-setup --config deployed.yml --light --skip-header-proof
zetae2e local $E2E_ARGS --skip-setup --config /config/deployed.yml --light --skip-header-proof
if [ $? -ne 0 ]; then
echo "first e2e failed"
exit 1
Expand Down Expand Up @@ -143,9 +143,9 @@ if [ "$LOCALNET_MODE" == "upgrade" ]; then
# When the upgrade height is greater than 100 for upgrade test, the Bitcoin tests have been run once, therefore the Bitcoin wallet is already set up
# Use light flag to skip advanced tests
if [ "$UPGRADE_HEIGHT" -lt 100 ]; then
zetae2e local $E2E_ARGS --skip-setup --config deployed.yml --light --skip-header-proof
zetae2e local $E2E_ARGS --skip-setup --config /config/deployed.yml --light --skip-header-proof
else
zetae2e local $E2E_ARGS --skip-setup --config deployed.yml --skip-bitcoin-setup --light --skip-header-proof
zetae2e local $E2E_ARGS --skip-setup --config /config/deployed.yml --skip-bitcoin-setup --light --skip-header-proof
fi

ZETAE2E_EXIT_CODE=$?
Expand All @@ -162,8 +162,8 @@ else
# Run the e2e tests normally
echo "running e2e setup..."

if [[ ! -f deployed.yml ]]; then
zetae2e local $E2E_ARGS --config config.yml --setup-only --config-out deployed.yml
if [[ ! -f /config/deployed.yml ]]; then
zetae2e local $E2E_ARGS --config config.yml --setup-only --config-out /config/deployed.yml
if [ $? -ne 0 ]; then
echo "e2e setup failed"
exit 1
Expand All @@ -178,7 +178,7 @@ else

echo "running e2e tests..."

zetae2e local $E2E_ARGS --skip-setup --config deployed.yml
zetae2e local $E2E_ARGS --skip-setup --config /config/deployed.yml
ZETAE2E_EXIT_CODE=$?

# if e2e passed, exit with 0, otherwise exit with 1
Expand Down

0 comments on commit 2a4ba05

Please sign in to comment.