Skip to content

Commit

Permalink
chore: fix linter errors and gofumpt project
Browse files Browse the repository at this point in the history
  • Loading branch information
jtieri committed Aug 21, 2024
1 parent 0d732aa commit 7c19d5b
Show file tree
Hide file tree
Showing 52 changed files with 218 additions and 185 deletions.
3 changes: 2 additions & 1 deletion client/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package client_test
import (
"testing"

"github.com/strangelove-ventures/horcrux/v3/client"
"github.com/stretchr/testify/require"

"github.com/strangelove-ventures/horcrux/v3/client"
)

func TestLeaderElectionMultiAddressDomain(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions cmd/horcrux/cmd/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import (
"fmt"
"strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/types/bech32"

"github.com/cometbft/cometbft/crypto"
cometprivval "github.com/cometbft/cometbft/privval"
"github.com/cosmos/cosmos-sdk/types/bech32"
"github.com/spf13/cobra"

"github.com/strangelove-ventures/horcrux/v3/signer"
)

Expand All @@ -28,7 +31,6 @@ func addressCmd() *cobra.Command {
SilenceUsage: true,
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {

var pubKey crypto.PubKey

chainID := args[0]
Expand Down
3 changes: 2 additions & 1 deletion cmd/horcrux/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/spf13/cobra"

"github.com/strangelove-ventures/horcrux/v3/signer"
)

Expand Down Expand Up @@ -123,7 +124,7 @@ for threshold signer mode, --cosigner flags and --threshold flag are required.
cmd.SilenceUsage = true

// create all directories up to the state directory
if err = os.MkdirAll(config.StateDir, 0755); err != nil {
if err = os.MkdirAll(config.StateDir, 0o755); err != nil {
return err
}
// create the config file
Expand Down
2 changes: 1 addition & 1 deletion cmd/horcrux/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ maxReadSize: 1048576
t.Run(tc.name, func(t *testing.T) {
tmpConfig := filepath.Join(tc.home, ".horcrux")

err := os.MkdirAll(tc.home, 0777)
err := os.MkdirAll(tc.home, 0o777)
require.NoError(t, err)

cmd := rootCmd()
Expand Down
6 changes: 3 additions & 3 deletions cmd/horcrux/cmd/leader_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (

grpcretry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"github.com/spf13/cobra"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/strangelove-ventures/horcrux/v3/client"
"github.com/strangelove-ventures/horcrux/v3/signer"
"github.com/strangelove-ventures/horcrux/v3/signer/multiresolver"
"github.com/strangelove-ventures/horcrux/v3/signer/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

func init() {
Expand Down Expand Up @@ -178,5 +179,4 @@ func getLeaderCmd() *cobra.Command {
return nil
},
}

}
6 changes: 3 additions & 3 deletions cmd/horcrux/cmd/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (

"github.com/armon/go-metrics"
gmprometheus "github.com/armon/go-metrics/prometheus"
cometlog "github.com/cometbft/cometbft/libs/log"
"github.com/prometheus/client_golang/prometheus/promhttp"

cometlog "github.com/cometbft/cometbft/libs/log"
)

func AddPrometheusMetrics(mux *http.ServeMux, out io.Writer) {
Expand All @@ -35,7 +36,7 @@ func AddPrometheusMetrics(mux *http.ServeMux, out io.Writer) {
logger.Info("Prometheus Metrics Listening", "address", config.Config.DebugAddr, "path", "/metrics")
}

// EnableDebugAndMetrics - Initialization errors are not fatal, only logged
// EnableDebugAndMetrics - Initialization errors are not fatal, only logged.
func EnableDebugAndMetrics(ctx context.Context, out io.Writer) {
logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out)).With("module", "debugserver")

Expand Down Expand Up @@ -95,5 +96,4 @@ func EnableDebugAndMetrics(ctx context.Context, out io.Writer) {
}
}
}()

}
12 changes: 7 additions & 5 deletions cmd/horcrux/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (
"os"
"path/filepath"

"github.com/spf13/cobra"
amino "github.com/tendermint/go-amino"
"gopkg.in/yaml.v2"

cometcrypto "github.com/cometbft/cometbft/crypto"
cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519"
cometcryptoencoding "github.com/cometbft/cometbft/crypto/encoding"
cometprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"
"github.com/spf13/cobra"

"github.com/strangelove-ventures/horcrux/v3/signer"
amino "github.com/tendermint/go-amino"
"gopkg.in/yaml.v2"
)

func legacyConfig() (*v2Config, error) {
Expand Down Expand Up @@ -230,7 +232,7 @@ func migrateCmd() *cobra.Command {
}

newEd25519Path := config.KeyFilePathCosigner(chainID)
if err := os.WriteFile(newEd25519Path, newEd25519KeyBz, 0600); err != nil {
if err := os.WriteFile(newEd25519Path, newEd25519KeyBz, 0o600); err != nil {
return fmt.Errorf("failed to write new Ed25519 key to %s: %w", newEd25519Path, err)
}

Expand All @@ -246,7 +248,7 @@ func migrateCmd() *cobra.Command {
}

newRSAPath := config.KeyFilePathCosignerRSA()
if err := os.WriteFile(newRSAPath, newRSAKeyBz, 0600); err != nil {
if err := os.WriteFile(newRSAPath, newRSAKeyBz, 0o600); err != nil {
return fmt.Errorf("failed to write new RSA key to %s: %w", newRSAPath, err)
}

Expand Down
33 changes: 17 additions & 16 deletions cmd/horcrux/cmd/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ import (
"path/filepath"
"testing"

"github.com/strangelove-ventures/horcrux/v3/cmd/horcrux/cmd/testdata"
"github.com/stretchr/testify/require"

"github.com/strangelove-ventures/horcrux/v3/cmd/horcrux/cmd/testdata"
)

func TestMigrateV2toV3(t *testing.T) {
tmp := t.TempDir()

configFile := filepath.Join(tmp, "config.yaml")

err := os.WriteFile(configFile, testdata.ConfigV2, 0600)
err := os.WriteFile(configFile, testdata.ConfigV2, 0o600)
require.NoError(t, err)

keyShareFile := filepath.Join(tmp, "share.json")

err = os.WriteFile(keyShareFile, testdata.CosignerKeyV2, 0600)
err = os.WriteFile(keyShareFile, testdata.CosignerKeyV2, 0o600)
require.NoError(t, err)

cmd := rootCmd()
Expand Down Expand Up @@ -57,7 +58,7 @@ func TestMigrateV2toV3(t *testing.T) {

func appendToFile(file, append string) error {
f, err := os.OpenFile(file,
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return err
}
Expand All @@ -70,20 +71,20 @@ func TestMigrateV2toV3DifferentKeyFilePath(t *testing.T) {
tmp := t.TempDir()

keyDir := filepath.Join(tmp, "keys")
err := os.Mkdir(keyDir, 0700)
err := os.Mkdir(keyDir, 0o700)
require.NoError(t, err)

configFile := filepath.Join(tmp, "config.yaml")

err = os.WriteFile(configFile, testdata.ConfigV2, 0600)
err = os.WriteFile(configFile, testdata.ConfigV2, 0o600)
require.NoError(t, err)

keyShareFile := filepath.Join(keyDir, "share.json")

err = appendToFile(configFile, fmt.Sprintf("key-file: %s", keyShareFile))
require.NoError(t, err)

err = os.WriteFile(keyShareFile, testdata.CosignerKeyV2, 0600)
err = os.WriteFile(keyShareFile, testdata.CosignerKeyV2, 0o600)
require.NoError(t, err)

cmd := rootCmd()
Expand Down Expand Up @@ -117,13 +118,13 @@ func TestMigrateV2toV3DifferentKeyFilePath(t *testing.T) {
require.Equal(t, fmt.Sprintf("keyDir: %s\n", keyDir)+testdata.ConfigMigrated, string(newConfigFileBz))
}

// Should migrate keys only if config has already been migrated
// Should migrate keys only if config has already been migrated.
func TestMigrateV2toV3KeysOnly(t *testing.T) {
tmp := t.TempDir()

keyShareFile := filepath.Join(tmp, "share.json")

err := os.WriteFile(keyShareFile, testdata.CosignerKeyV2, 0600)
err := os.WriteFile(keyShareFile, testdata.CosignerKeyV2, 0o600)
require.NoError(t, err)

cmd := rootCmd()
Expand Down Expand Up @@ -152,18 +153,18 @@ func TestMigrateV2toV3KeysOnly(t *testing.T) {
require.Equal(t, testdata.CosignerRSAKeyMigrated, string(newRSAKeyFileBz))
}

// Should not modify config that is already in v3 format
// Should not modify config that is already in v3 format.
func TestMigrateV2toV3ConfigAlreadyMigrated(t *testing.T) {
tmp := t.TempDir()

configFile := filepath.Join(tmp, "config.yaml")

err := os.WriteFile(configFile, []byte(testdata.ConfigMigrated), 0600)
err := os.WriteFile(configFile, []byte(testdata.ConfigMigrated), 0o600)
require.NoError(t, err)

keyShareFile := filepath.Join(tmp, "share.json")

err = os.WriteFile(keyShareFile, testdata.CosignerKeyV2, 0600)
err = os.WriteFile(keyShareFile, testdata.CosignerKeyV2, 0o600)
require.NoError(t, err)

cmd := rootCmd()
Expand Down Expand Up @@ -197,23 +198,23 @@ func TestMigrateV2toV3ConfigAlreadyMigrated(t *testing.T) {
require.Equal(t, testdata.ConfigMigrated, string(newConfigFileBz))
}

// Should not modify config or keys that are already in v3 format
// Should not modify config or keys that are already in v3 format.
func TestMigrateV2toV3AlreadyMigrated(t *testing.T) {
tmp := t.TempDir()

configFile := filepath.Join(tmp, "config.yaml")

err := os.WriteFile(configFile, []byte(testdata.ConfigMigrated), 0600)
err := os.WriteFile(configFile, []byte(testdata.ConfigMigrated), 0o600)
require.NoError(t, err)

ed25519KeyShardFile := filepath.Join(tmp, "test_shard.json")

err = os.WriteFile(ed25519KeyShardFile, []byte(testdata.CosignerEd25519KeyMigrated), 0600)
err = os.WriteFile(ed25519KeyShardFile, []byte(testdata.CosignerEd25519KeyMigrated), 0o600)
require.NoError(t, err)

rsaKeyShardFile := filepath.Join(tmp, "rsa_keys.json")

err = os.WriteFile(rsaKeyShardFile, []byte(testdata.CosignerRSAKeyMigrated), 0600)
err = os.WriteFile(rsaKeyShardFile, []byte(testdata.CosignerRSAKeyMigrated), 0o600)
require.NoError(t, err)

cmd := rootCmd()
Expand Down
3 changes: 2 additions & 1 deletion cmd/horcrux/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/strangelove-ventures/horcrux/v3/signer"
"gopkg.in/yaml.v2"

"github.com/strangelove-ventures/horcrux/v3/signer"
)

var config signer.RuntimeConfig
Expand Down
9 changes: 5 additions & 4 deletions cmd/horcrux/cmd/shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path/filepath"

"github.com/spf13/cobra"

"github.com/strangelove-ventures/horcrux/v3/signer"
)

Expand All @@ -31,7 +32,7 @@ func createCosignerDirectoryIfNecessary(out string, id int) (string, error) {
if !os.IsNotExist(err) {
return "", fmt.Errorf("unexpected error fetching info for cosigner directory: %w", err)
}
if err := os.Mkdir(dir, 0700); err != nil {
if err := os.Mkdir(dir, 0o700); err != nil {
return "", fmt.Errorf("failed to make directory for cosigner files: %w", err)
}
return dir, nil
Expand Down Expand Up @@ -119,7 +120,7 @@ func createCosignerEd25519ShardsCmd() *cobra.Command {

out, _ := cmd.Flags().GetString(flagOutputDir)
if out != "" {
if err := os.MkdirAll(out, 0700); err != nil {
if err := os.MkdirAll(out, 0o700); err != nil {
return err
}
}
Expand Down Expand Up @@ -177,7 +178,7 @@ func createCosignerECIESShardsCmd() *cobra.Command {

out, _ := cmd.Flags().GetString(flagOutputDir)
if out != "" {
if err := os.MkdirAll(out, 0700); err != nil {
if err := os.MkdirAll(out, 0o700); err != nil {
return err
}
}
Expand Down Expand Up @@ -225,7 +226,7 @@ func createCosignerRSAShardsCmd() *cobra.Command {

out, _ := cmd.Flags().GetString(flagOutputDir)
if out != "" {
if err := os.MkdirAll(out, 0700); err != nil {
if err := os.MkdirAll(out, 0o700); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/horcrux/cmd/shards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"path/filepath"
"testing"

"github.com/stretchr/testify/require"

"github.com/cometbft/cometbft/crypto/ed25519"
"github.com/cometbft/cometbft/privval"
"github.com/stretchr/testify/require"
)

const testChainID = "test"
Expand Down Expand Up @@ -89,7 +90,6 @@ func TestEd25519Shards(t *testing.T) {

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {

cmd := rootCmd()
cmd.SetOutput(io.Discard)
args := append([]string{"create-ed25519-shards", "--home", tmp, "--out", tmp}, tc.args...)
Expand Down
6 changes: 4 additions & 2 deletions cmd/horcrux/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"fmt"
"os"

"github.com/spf13/cobra"

cometlog "github.com/cometbft/cometbft/libs/log"
"github.com/cometbft/cometbft/libs/service"
"github.com/spf13/cobra"

"github.com/strangelove-ventures/horcrux/v3/signer"
)

Expand All @@ -30,7 +32,7 @@ func startCmd() *cobra.Command {
}

// create all directories up to the state directory
if err = os.MkdirAll(config.StateDir, 0700); err != nil {
if err = os.MkdirAll(config.StateDir, 0o700); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/horcrux/cmd/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
"time"

"github.com/spf13/cobra"
"github.com/strangelove-ventures/horcrux/v3/signer"

cometjson "github.com/cometbft/cometbft/libs/json"
cometlog "github.com/cometbft/cometbft/libs/log"

"github.com/strangelove-ventures/horcrux/v3/signer"
)

// Snippet Taken from https://raw.githubusercontent.com/cometbft/cometbft/main/privval/file.go
Expand Down Expand Up @@ -46,7 +47,6 @@ func showStateCmd() *cobra.Command {
Args: cobra.ExactArgs(1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {

chainID := args[0]

if _, err := os.Stat(config.HomeDir); os.IsNotExist(err) {
Expand Down
Loading

0 comments on commit 7c19d5b

Please sign in to comment.