Skip to content

Commit

Permalink
feat: Use separate dir for testnets IBC paths (#19)
Browse files Browse the repository at this point in the history
* feat: Use separate dir for testnets IBC paths

* chore: Update docs
  • Loading branch information
kayano authored Oct 16, 2023
1 parent 4cb07d8 commit 3ed83c0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ github:
org: archway-network
repo: networks
dir: _IBC
testnetsDir: testnets/_IBC

accounts:
- address: archway1l2al7y78500h5akvgt8exwnkpmf2zmk8ky9ht3
Expand Down
10 changes: 10 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,21 @@ rpc:
- chainName: umee
chainId: umee-1
url: https://rpc-umee.mzonder.com:443
- chainName: gravitybridge
chainId: gravity-bridge-3
url: https://gravitychain.io:26657
- chainName: omniflixhub
chainId: omniflixhub-1
url: https://rpc-omniflix.mzonder.com:443
- chainName: decentr
chainId: mainnet-3
url: https://poseidon.mainnet.decentr.xyz:443

github:
org: archway-network
repo: networks
dir: _IBC
testnetsDir: testnets/_IBC

accounts:
- address: archway1l2al7y78500h5akvgt8exwnkpmf2zmk8ky9ht3
Expand Down
41 changes: 34 additions & 7 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"context"
"encoding/json"
"errors"
"os"
"strings"

Expand All @@ -18,6 +19,8 @@ import (

const ibcPathSuffix = ".json"

var ErrGitHubClient = errors.New("GitHub client not provided")

type Account struct {
Address string `yaml:"address"`
Denom string `yaml:"denom"`
Expand All @@ -35,10 +38,11 @@ type Config struct {
Accounts []Account `yaml:"accounts"`
RPCs []RPC `yaml:"rpc"`
GitHub struct {
Org string `yaml:"org"`
Repo string `yaml:"repo"`
IBCDir string `yaml:"dir"`
Token string `env:"GITHUB_TOKEN"`
Org string `yaml:"org"`
Repo string `yaml:"repo"`
IBCDir string `yaml:"dir"`
TestnetsIBCDir string `yaml:"testnetsDir"`
Token string `env:"GITHUB_TOKEN"`
} `yaml:"github"`
}

Expand Down Expand Up @@ -74,8 +78,6 @@ func (c *Config) GetRPCsMap() *map[string]RPC {
}

func (c *Config) IBCPaths() ([]*relayer.IBCdata, error) {
ctx := context.Background()

client := github.NewClient(nil)

if c.GitHub.Token != "" {
Expand All @@ -84,7 +86,32 @@ func (c *Config) IBCPaths() ([]*relayer.IBCdata, error) {
client = github.NewClient(nil).WithAuthToken(c.GitHub.Token)
}

_, ibcDir, _, err := client.Repositories.GetContents(ctx, c.GitHub.Org, c.GitHub.Repo, c.GitHub.IBCDir, nil)
paths, err := c.getPaths(c.GitHub.IBCDir, client)
if err != nil {
return nil, err
}

testnetsPaths := []*relayer.IBCdata{}
if c.GitHub.TestnetsIBCDir != "" {
testnetsPaths, err = c.getPaths(c.GitHub.TestnetsIBCDir, client)
if err != nil {
return nil, err
}
}

paths = append(paths, testnetsPaths...)

return paths, nil
}

func (c *Config) getPaths(dir string, client *github.Client) ([]*relayer.IBCdata, error) {
if client == nil {
return nil, ErrGitHubClient
}

ctx := context.Background()

_, ibcDir, _, err := client.Repositories.GetContents(ctx, c.GitHub.Org, c.GitHub.Repo, dir, nil)
if err != nil {
return nil, err
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -39,3 +40,18 @@ func TestGetRPCsMap(t *testing.T) {

assert.Equal(t, &exp, res)
}

func TestGetPaths(t *testing.T) {
cfg := Config{}

expError := ErrGitHubClient

_, err := cfg.getPaths("_IBC", nil)
if err == nil {
t.Fatalf("Expected error %q, got no error", expError)
}

if !errors.Is(err, expError) {
t.Errorf("Expected error %q, got %q", expError, err)
}
}

0 comments on commit 3ed83c0

Please sign in to comment.