Skip to content

Commit 3ed83c0

Browse files
authored
feat: Use separate dir for testnets IBC paths (#19)
* feat: Use separate dir for testnets IBC paths * chore: Update docs
1 parent 4cb07d8 commit 3ed83c0

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ github:
2222
org: archway-network
2323
repo: networks
2424
dir: _IBC
25+
testnetsDir: testnets/_IBC
2526

2627
accounts:
2728
- address: archway1l2al7y78500h5akvgt8exwnkpmf2zmk8ky9ht3

config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,21 @@ rpc:
5151
- chainName: umee
5252
chainId: umee-1
5353
url: https://rpc-umee.mzonder.com:443
54+
- chainName: gravitybridge
55+
chainId: gravity-bridge-3
56+
url: https://gravitychain.io:26657
57+
- chainName: omniflixhub
58+
chainId: omniflixhub-1
59+
url: https://rpc-omniflix.mzonder.com:443
60+
- chainName: decentr
61+
chainId: mainnet-3
62+
url: https://poseidon.mainnet.decentr.xyz:443
5463

5564
github:
5665
org: archway-network
5766
repo: networks
5867
dir: _IBC
68+
testnetsDir: testnets/_IBC
5969

6070
accounts:
6171
- address: archway1l2al7y78500h5akvgt8exwnkpmf2zmk8ky9ht3

pkg/config/config.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"os"
78
"strings"
89

@@ -18,6 +19,8 @@ import (
1819

1920
const ibcPathSuffix = ".json"
2021

22+
var ErrGitHubClient = errors.New("GitHub client not provided")
23+
2124
type Account struct {
2225
Address string `yaml:"address"`
2326
Denom string `yaml:"denom"`
@@ -35,10 +38,11 @@ type Config struct {
3538
Accounts []Account `yaml:"accounts"`
3639
RPCs []RPC `yaml:"rpc"`
3740
GitHub struct {
38-
Org string `yaml:"org"`
39-
Repo string `yaml:"repo"`
40-
IBCDir string `yaml:"dir"`
41-
Token string `env:"GITHUB_TOKEN"`
41+
Org string `yaml:"org"`
42+
Repo string `yaml:"repo"`
43+
IBCDir string `yaml:"dir"`
44+
TestnetsIBCDir string `yaml:"testnetsDir"`
45+
Token string `env:"GITHUB_TOKEN"`
4246
} `yaml:"github"`
4347
}
4448

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

7680
func (c *Config) IBCPaths() ([]*relayer.IBCdata, error) {
77-
ctx := context.Background()
78-
7981
client := github.NewClient(nil)
8082

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

87-
_, ibcDir, _, err := client.Repositories.GetContents(ctx, c.GitHub.Org, c.GitHub.Repo, c.GitHub.IBCDir, nil)
89+
paths, err := c.getPaths(c.GitHub.IBCDir, client)
90+
if err != nil {
91+
return nil, err
92+
}
93+
94+
testnetsPaths := []*relayer.IBCdata{}
95+
if c.GitHub.TestnetsIBCDir != "" {
96+
testnetsPaths, err = c.getPaths(c.GitHub.TestnetsIBCDir, client)
97+
if err != nil {
98+
return nil, err
99+
}
100+
}
101+
102+
paths = append(paths, testnetsPaths...)
103+
104+
return paths, nil
105+
}
106+
107+
func (c *Config) getPaths(dir string, client *github.Client) ([]*relayer.IBCdata, error) {
108+
if client == nil {
109+
return nil, ErrGitHubClient
110+
}
111+
112+
ctx := context.Background()
113+
114+
_, ibcDir, _, err := client.Repositories.GetContents(ctx, c.GitHub.Org, c.GitHub.Repo, dir, nil)
88115
if err != nil {
89116
return nil, err
90117
}

pkg/config/config_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config
22

33
import (
4+
"errors"
45
"testing"
56

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

4041
assert.Equal(t, &exp, res)
4142
}
43+
44+
func TestGetPaths(t *testing.T) {
45+
cfg := Config{}
46+
47+
expError := ErrGitHubClient
48+
49+
_, err := cfg.getPaths("_IBC", nil)
50+
if err == nil {
51+
t.Fatalf("Expected error %q, got no error", expError)
52+
}
53+
54+
if !errors.Is(err, expError) {
55+
t.Errorf("Expected error %q, got %q", expError, err)
56+
}
57+
}

0 commit comments

Comments
 (0)