-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Phase 1]: Tunnel offchain relayer #1
Changes from all commits
1f24209
c824ff7
b58a5b7
cb8f4c9
606b71e
0bf1e63
dbf889d
fa2e916
0d83598
7006d68
ee89bbd
31f55df
c2aa43f
f654a3c
791cfb6
8ae13de
ef044eb
4717cd6
c9c4d16
f72ba8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
name: Tests | ||
on: pull_request | ||
|
||
env: | ||
GOPRIVATE: github.com/bandprotocol/private-chain | ||
|
||
jobs: | ||
falcon-test: | ||
runs-on: ubuntu-latest | ||
|
@@ -13,6 +16,11 @@ jobs: | |
with: | ||
go-version: "1.22.3" | ||
|
||
- name: Configure git for private modules | ||
env: | ||
TOKEN: ${{ secrets.SHIBA_TOKEN }} | ||
run: git config --global url."https://nkitlabs:${TOKEN}@github.com".insteadOf "https://github.com" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. next time, better to use band bot account token for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RogerKSI fix leoi2 mee kon notice leaw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bandbot somehow is not working for this case. think can open PR later to remove it after public. |
||
|
||
- name: Check go mod cache | ||
uses: actions/cache@v4 | ||
with: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
name: Golangci-lint | ||
on: pull_request | ||
|
||
env: | ||
GOPRIVATE: github.com/bandprotocol/private-chain | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22.3 | ||
|
||
- name: Configure git for private modules | ||
env: | ||
TOKEN: ${{ secrets.SHIBA_TOKEN }} | ||
run: git config --global url."https://nkitlabs:${TOKEN}@github.com".insteadOf "https://github.com" | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
version: v1.60 | ||
version: v1.61 | ||
args: --timeout=5m0s |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/bandprotocol/falcon/relayer" | ||
) | ||
|
||
// chainsCmd returns a command that manages chain configurations. | ||
func chainsCmd(app *relayer.App) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "chains", | ||
Aliases: []string{"ch"}, | ||
Short: "Manage chain configurations", | ||
} | ||
|
||
cmd.AddCommand( | ||
chainsAddCmd(app), | ||
chainsDeleteCmd(app), | ||
chainsListCmd(app), | ||
chainsShowCmd(app), | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
// chainsListCmd returns a command that lists all chains that are currently configured. | ||
// NOTE: this command only show the list of registered chainIDs, to see the configuration | ||
// please see `chains show`. | ||
func chainsListCmd(app *relayer.App) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Aliases: []string{"l"}, | ||
Short: "Return list of chain names that are currently configured", | ||
Args: withUsage(cobra.NoArgs), | ||
Example: strings.TrimSpace(fmt.Sprintf(` | ||
$ %s chains list | ||
$ %s ch l`, appName, appName)), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
_ = app | ||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
// chainsShowCmd returns a command that shows a chain's configuration data. | ||
func chainsShowCmd(app *relayer.App) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "show [chain_name]", | ||
Aliases: []string{"s"}, | ||
Short: "Return a chain's configuration data", | ||
Args: withUsage(cobra.ExactArgs(1)), | ||
Example: strings.TrimSpace(fmt.Sprintf(` | ||
$ %s ch s eth | ||
$ %s chains show eth --yaml`, appName, appName)), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
_ = app | ||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
// chainsAddCmd returns a command that adds a new chain configuration. | ||
func chainsAddCmd(app *relayer.App) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "add [chain_type] [chain_name]", | ||
Aliases: []string{"a"}, | ||
Short: "Add a new chain to the configuration file by passing a configuration file (-f)", | ||
Args: withUsage(cobra.ExactArgs(2)), | ||
Example: strings.TrimSpace(fmt.Sprintf(` | ||
$ %s ch a evm eth --file chains/eth.toml | ||
$ %s chains add evm eth --file chains/eth.toml`, appName, appName)), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
_ = app | ||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
// chainsDeleteCmd returns a command that deletes a chain configuration. | ||
func chainsDeleteCmd(app *relayer.App) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "delete [chain_name]", | ||
Aliases: []string{"d"}, | ||
Short: "Remove chain from config based on chain_name", | ||
Args: withUsage(cobra.ExactArgs(1)), | ||
Example: strings.TrimSpace(fmt.Sprintf(` | ||
$ %s chains delete eth | ||
$ %s ch d eth`, appName, appName)), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
_ = app | ||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/pelletier/go-toml/v2" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/bandprotocol/falcon/relayer" | ||
) | ||
|
||
// configCmd returns a command that manages global configuration file | ||
func configCmd(app *relayer.App) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "config", | ||
Aliases: []string{"cfg"}, | ||
Short: "Manage global configuration file", | ||
} | ||
|
||
cmd.AddCommand( | ||
configShowCmd(app), | ||
configInitCmd(app), | ||
) | ||
return cmd | ||
} | ||
|
||
// configShowCmd returns the commands that prints current configuration | ||
func configShowCmd(app *relayer.App) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "show", | ||
Aliases: []string{"s", "list", "l"}, | ||
Short: "Prints current configuration", | ||
Args: withUsage(cobra.NoArgs), | ||
Example: strings.TrimSpace(fmt.Sprintf(` | ||
$ %s config show --home %s | ||
$ %s cfg list`, appName, defaultHome, appName)), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if app.Config == nil { | ||
return fmt.Errorf("config does not exist: %s", app.HomePath) | ||
} | ||
|
||
b, err := toml.Marshal(app.Config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintln(cmd.OutOrStdout(), string(b)) | ||
return nil | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
// configInitCmd returns the commands that for initializing an empty config at the --home location | ||
func configInitCmd(app *relayer.App) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "init", | ||
Aliases: []string{"i"}, | ||
Short: "Create a default configuration at home directory path defined by --home", | ||
Args: withUsage(cobra.NoArgs), | ||
Example: strings.TrimSpace(fmt.Sprintf(` | ||
$ %s config init --home %s | ||
$ %s cfg i`, appName, defaultHome, appName)), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
home, err := cmd.Flags().GetString(flagHome) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
file, err := cmd.Flags().GetString(flagFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return app.InitConfigFile(home, file) | ||
}, | ||
} | ||
cmd.Flags().StringP(flagFile, "f", "", "fetch toml data from specified file") | ||
return cmd | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/bandprotocol/falcon/internal/relayertest" | ||
) | ||
|
||
func TestShowConfigCmd(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
res := sys.RunWithInput(t, "config", "init") | ||
require.NoError(t, res.Err) | ||
|
||
res = sys.RunWithInput(t, "config", "show") | ||
require.NoError(t, res.Err) | ||
|
||
actual := res.Stdout.String() | ||
require.Equal(t, relayertest.DefaultCfgText+"\n", actual) | ||
} | ||
|
||
func TestShowConfigCmdNotInit(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
res := sys.RunWithInput(t, "config", "show") | ||
require.ErrorContains(t, res.Err, "config does not exist:") | ||
} | ||
|
||
func TestInitCmdDefault(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
res := sys.RunWithInput(t, "config", "init") | ||
require.NoError(t, res.Err) | ||
|
||
cfgPath := path.Join(sys.HomeDir, "config", "config.toml") | ||
require.FileExists(t, cfgPath) | ||
|
||
// read the file | ||
actualBytes, err := os.ReadFile(cfgPath) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, relayertest.DefaultCfgText, string(actualBytes)) | ||
} | ||
|
||
func TestInitCmdWithFileShortFlag(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
customCfgPath := path.Join(sys.HomeDir, "custom.toml") | ||
err := os.WriteFile(customCfgPath, []byte(relayertest.CustomCfgText), 0o600) | ||
require.NoError(t, err) | ||
|
||
res := sys.RunWithInput(t, "config", "init", "-f", customCfgPath) | ||
require.NoError(t, res.Err) | ||
|
||
cfgPath := path.Join(sys.HomeDir, "config", "config.toml") | ||
require.FileExists(t, cfgPath) | ||
|
||
// read the file | ||
actualBytes, err := os.ReadFile(cfgPath) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, relayertest.CustomCfgText, string(actualBytes)) | ||
} | ||
|
||
func TestInitCmdWithFileLongFlag(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
customCfgPath := path.Join(sys.HomeDir, "custom.toml") | ||
err := os.WriteFile(customCfgPath, []byte(relayertest.CustomCfgText), 0o600) | ||
require.NoError(t, err) | ||
|
||
res := sys.RunWithInput(t, "config", "init", "--file", customCfgPath) | ||
require.NoError(t, res.Err) | ||
|
||
cfgPath := path.Join(sys.HomeDir, "config", "config.toml") | ||
require.FileExists(t, cfgPath) | ||
|
||
actualBytes, err := os.ReadFile(cfgPath) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, relayertest.CustomCfgText, string(actualBytes)) | ||
} | ||
|
||
func TestInitCmdWithFileTimeString(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
customCfgPath := path.Join(sys.HomeDir, "custom.toml") | ||
err := os.WriteFile(customCfgPath, []byte(relayertest.CustomCfgTextWithTimeStr), 0o600) | ||
require.NoError(t, err) | ||
|
||
res := sys.RunWithInput(t, "config", "init", "--file", customCfgPath) | ||
require.NoError(t, res.Err) | ||
|
||
cfgPath := path.Join(sys.HomeDir, "config", "config.toml") | ||
require.FileExists(t, cfgPath) | ||
|
||
actualBytes, err := os.ReadFile(cfgPath) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, relayertest.CustomCfgText, string(actualBytes)) | ||
} | ||
|
||
func TestInitCmdInvalidFile(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
customCfgPath := path.Join(sys.HomeDir, "custom.toml") | ||
err := os.WriteFile(customCfgPath, []byte(`[band]][]]`), 0o600) | ||
require.NoError(t, err) | ||
|
||
res := sys.RunWithInput(t, "config", "init", "--file", customCfgPath) | ||
require.ErrorContains(t, res.Err, "error toml: expected newline") | ||
} | ||
|
||
func TestInitCmdNoCustomFile(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
customCfgPath := path.Join(sys.HomeDir, "custom.toml") | ||
res := sys.RunWithInput(t, "config", "init", "--file", customCfgPath) | ||
require.ErrorContains(t, res.Err, "no such file or directory") | ||
} | ||
|
||
func TestInitCmdAlreadyExist(t *testing.T) { | ||
sys := relayertest.NewSystem(t) | ||
|
||
res := sys.RunWithInput(t, "config", "init") | ||
require.NoError(t, res.Err) | ||
|
||
cfgPath := path.Join(sys.HomeDir, "config", "config.toml") | ||
require.FileExists(t, cfgPath) | ||
|
||
res = sys.RunWithInput(t, "config", "init") | ||
require.ErrorContains(t, res.Err, "config already exists") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why shiba haha?