diff --git a/README.md b/README.md index b58a2ae..8bd8825 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ github: org: archway-network repo: networks dir: _IBC + testnetsDir: testnets/_IBC accounts: - address: archway1l2al7y78500h5akvgt8exwnkpmf2zmk8ky9ht3 diff --git a/config.yaml b/config.yaml index 193e8b0..bd3d6ad 100644 --- a/config.yaml +++ b/config.yaml @@ -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 diff --git a/pkg/config/config.go b/pkg/config/config.go index da0faa4..0489b23 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -3,6 +3,7 @@ package config import ( "context" "encoding/json" + "errors" "os" "strings" @@ -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"` @@ -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"` } @@ -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 != "" { @@ -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 } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index e2375fd..884c1cc 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -1,6 +1,7 @@ package config import ( + "errors" "testing" "github.com/stretchr/testify/assert" @@ -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) + } +}