Skip to content

Commit

Permalink
apply gofumpt formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Apr 22, 2024
1 parent 9732e78 commit 61ac522
Show file tree
Hide file tree
Showing 52 changed files with 99 additions and 116 deletions.
1 change: 0 additions & 1 deletion api/gateway/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func hasEndpointRegistered(router *mux.Router, path string, method string) bool
}
return nil
})

if err != nil {
fmt.Println("Error walking through routes:", err)
return false
Expand Down
4 changes: 1 addition & 3 deletions api/gateway/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ const (
headerByHeightEndpoint = "/header"
)

var (
heightKey = "height"
)
var heightKey = "height"

func (h *Handler) handleHeadRequest(w http.ResponseWriter, r *http.Request) {
head, err := h.header.LocalHead(r.Context())
Expand Down
3 changes: 1 addition & 2 deletions api/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestAuthedRPC(t *testing.T) {
adminToken, err := perms.NewTokenWithPerms(signer, perms.AllPerms)
require.NoError(t, err)

var tests = []struct {
tests := []struct {
perm int
token string
}{
Expand Down Expand Up @@ -280,7 +280,6 @@ func implementsMarshaler(t *testing.T, typ reflect.Type) {
default:
return
}

}

// setupNodeWithAuthedRPC sets up a node and overrides its JWT
Expand Down
2 changes: 1 addition & 1 deletion blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestBlob(t *testing.T) {
blob, err := convertBlobs(appBlobs...)
require.NoError(t, err)

var test = []struct {
test := []struct {
name string
expectedRes func(t *testing.T)
}{
Expand Down
3 changes: 2 additions & 1 deletion blob/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type parser struct {
verifyFn func(blob *Blob) bool
}

// NOTE: passing shares here needed to detect padding shares(as we do not need this check in addShares)
// NOTE: passing shares here needed to detect padding shares(as we do not need this check in
// addShares)
func (p *parser) set(index int, shrs []shares.Share) ([]shares.Share, error) {
if len(shrs) == 0 {
return nil, errEmptyShares
Expand Down
3 changes: 1 addition & 2 deletions blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestBlobService_Get(t *testing.T) {
require.NoError(t, err)

service := createService(ctx, t, append(blobs0, blobs1...))
var test = []struct {
test := []struct {
name string
doFn func() (interface{}, error)
expectedResult func(interface{}, error)
Expand Down Expand Up @@ -305,7 +305,6 @@ func TestBlobService_Get(t *testing.T) {
assert.Empty(t, blobs)
require.Error(t, err)
require.ErrorIs(t, err, ErrBlobNotFound)

},
},
{
Expand Down
3 changes: 1 addition & 2 deletions cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

func AuthCmd(fsets ...*flag.FlagSet) *cobra.Command {
var cmd = &cobra.Command{
cmd := &cobra.Command{
Use: "auth [permission-level (e.g. read || write || admin)]",
Short: "Signs and outputs a hex-encoded JWT token with the given permissions.",
Long: "Signs and outputs a hex-encoded JWT token with the given permissions. NOTE: only use this command when " +
Expand All @@ -37,7 +37,6 @@ func AuthCmd(fsets ...*flag.FlagSet) *cobra.Command {
ks, err := newKeystore(StorePath(cmd.Context()))
if err != nil {
return err

}

key, err := ks.Get(nodemod.SecretName)
Expand Down
2 changes: 1 addition & 1 deletion core/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (f *BlockFetcher) Commit(ctx context.Context, height *int64) (*types.Commit
// ValidatorSet queries Core for the ValidatorSet from the
// block at the given height.
func (f *BlockFetcher) ValidatorSet(ctx context.Context, height *int64) (*types.ValidatorSet, error) {
var perPage = 100
perPage := 100

vals, total := make([]*types.Validator, 0), -1
for page := 1; len(vals) != total; page++ {
Expand Down
2 changes: 1 addition & 1 deletion core/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (cl *Listener) handleNewSignedBlock(ctx context.Context, b types.EventDataS
if err != nil && !errors.Is(err, context.Canceled) {
log.Errorw("listener: broadcasting data hash",
"height", b.Header.Height,
"hash", b.Header.Hash(), "err", err) //TODO: hash or datahash?
"hash", b.Header.Hash(), "err", err) // TODO: hash or datahash?
}
}

Expand Down
1 change: 0 additions & 1 deletion core/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func TestListener_DoesNotStoreHistoric(t *testing.T) {
require.NoError(t, err)
assert.False(t, has)
}

}

func createMocknetWithTwoPubsubEndpoints(ctx context.Context, t *testing.T) (*pubsub.PubSub, *pubsub.PubSub) {
Expand Down
3 changes: 2 additions & 1 deletion das/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func Test_exponentialBackoff(t *testing.T) {
4 * time.Minute,
16 * time.Minute,
64 * time.Minute,
}},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions das/daser.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ type DASer struct {
running int32
}

type listenFn func(context.Context, *header.ExtendedHeader)
type sampleFn func(context.Context, *header.ExtendedHeader) error
type (
listenFn func(context.Context, *header.ExtendedHeader)
sampleFn func(context.Context, *header.ExtendedHeader) error
)

// NewDASer creates a new DASer.
func NewDASer(
Expand Down
9 changes: 5 additions & 4 deletions das/daser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func TestDASer_SamplingWindow(t *testing.T) {
WithSamplingWindow(time.Second))
require.NoError(t, err)

var tests = []struct {
tests := []struct {
timestamp time.Time
withinWindow bool
}{
Expand All @@ -282,7 +282,6 @@ func TestDASer_SamplingWindow(t *testing.T) {
assert.Equal(t, tt.withinWindow, daser.isWithinSamplingWindow(eh))
})
}

}

// createDASerSubcomponents takes numGetter (number of headers
Expand Down Expand Up @@ -403,7 +402,8 @@ type benchGetterStub struct {

func newBenchGetter() benchGetterStub {
return benchGetterStub{header: &header.ExtendedHeader{
DAH: &share.Root{RowRoots: make([][]byte, 0)}}}
DAH: &share.Root{RowRoots: make([][]byte, 0)},
}}
}

func (m benchGetterStub) GetByHeight(context.Context, uint64) (*header.ExtendedHeader, error) {
Expand All @@ -423,7 +423,8 @@ func (m getterStub) GetByHeight(_ context.Context, height uint64) (*header.Exten
return &header.ExtendedHeader{
Commit: &types.Commit{},
RawHeader: header.RawHeader{Height: int64(height)},
DAH: &share.Root{RowRoots: make([][]byte, 0)}}, nil
DAH: &share.Root{RowRoots: make([][]byte, 0)},
}, nil
}

func (m getterStub) GetRangeByHeight(
Expand Down
6 changes: 4 additions & 2 deletions das/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ type checkpointStore struct {
func newCheckpointStore(ds datastore.Datastore) checkpointStore {
return checkpointStore{
namespace.Wrap(ds, storePrefix),
newDone("checkpoint store")}
newDone("checkpoint store"),
}
}

// load loads the DAS checkpoint from disk and returns it.
Expand Down Expand Up @@ -65,7 +66,8 @@ func (s *checkpointStore) store(ctx context.Context, cp checkpoint) error {
func (s *checkpointStore) runBackgroundStore(
ctx context.Context,
storeInterval time.Duration,
getCheckpoint func(ctx context.Context) (checkpoint, error)) {
getCheckpoint func(ctx context.Context) (checkpoint, error),
) {
defer s.indicateDone()

// runBackgroundStore could be disabled by setting storeInterval = 0
Expand Down
1 change: 1 addition & 0 deletions header/headertest/fraud/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (f *FraudMaker) MakeExtendedHeader(odsSize int, edsStore *eds.Store) header
return header.MakeExtendedHeader(h, comm, vals, eds)
}
}

func CreateFraudExtHeader(
t *testing.T,
eh *header.ExtendedHeader,
Expand Down
1 change: 0 additions & 1 deletion header/headertest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func MakeCommit(
blockID types.BlockID, height int64, round int32,
voteSet *types.VoteSet, validators []types.PrivValidator, now time.Time,
) (*types.Commit, error) {

// all sign
for i := 0; i < len(validators); i++ {
pubKey, err := validators[i].GetPubKey()
Expand Down
6 changes: 3 additions & 3 deletions libs/keystore/fs_keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type fsKeystore struct {
// NewFSKeystore creates a new Keystore over OS filesystem.
// The path must point to a directory. It is created automatically if necessary.
func NewFSKeystore(path string, ring keyring.Keyring) (Keystore, error) {
err := os.Mkdir(path, 0755)
err := os.Mkdir(path, 0o755)
if err != nil && !os.IsExist(err) {
return nil, fmt.Errorf("keystore: failed to make a dir: %w", err)
}
Expand All @@ -49,7 +49,7 @@ func (f *fsKeystore) Put(n KeyName, pk PrivKey) error {
return fmt.Errorf("keystore: failed to marshal key '%s': %w", n, err)
}

err = os.WriteFile(path, data, 0600)
err = os.WriteFile(path, data, 0o600)
if err != nil {
return fmt.Errorf("keystore: failed to write key '%s': %w", n, err)
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func (f *fsKeystore) pathTo(file string) string {
}

func checkPerms(perms os.FileMode) error {
if perms&0077 != 0 {
if perms&0o077 != 0 {
return fmt.Errorf("required: 0600, got: %#o", perms)
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions libs/utils/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestSanitizeAddr(t *testing.T) {
var tests = []struct {
tests := []struct {
addr string
want string
err error
Expand Down Expand Up @@ -39,7 +39,7 @@ func TestValidateAddr(t *testing.T) {
addr string
unresolved bool
}
var tests = []struct {
tests := []struct {
addr string
want want
}{
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func IsInit(path string) bool {
return false
}

const perms = 0755
const perms = 0o755

// initRoot initializes(creates) directory if not created and check if it is writable
func initRoot(path string) error {
Expand Down
7 changes: 3 additions & 4 deletions nodebuilder/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestLifecycle(t *testing.T) {
var test = []struct {
test := []struct {
tp node.Type
}{
{tp: node.Bridge},
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestLifecycle_WithMetrics(t *testing.T) {

otelCollectorURL := strings.ReplaceAll(url, "http://", "")

var test = []struct {
test := []struct {
tp node.Type
coreExpected bool
}{
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestEmptyBlockExists(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

var test = []struct {
test := []struct {
tp node.Type
}{
{tp: node.Bridge},
Expand All @@ -155,5 +155,4 @@ func TestEmptyBlockExists(t *testing.T) {
require.NoError(t, err)
})
}

}
7 changes: 0 additions & 7 deletions nodebuilder/p2p/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ func TestParseNetwork_emptyFlag(t *testing.T) {

_, err = ParseNetwork(cmd)
assert.Error(t, err)

}

// Set empty network flag and ensure error returned
func TestParseNetwork_emptyEnvEmptyFlag(t *testing.T) {

t.Setenv(EnvCustomNetwork, "")

cmd := createCmdWithNetworkFlag()
Expand All @@ -93,12 +91,10 @@ func TestParseNetwork_emptyEnvEmptyFlag(t *testing.T) {

_, err = ParseNetwork(cmd)
require.Error(t, err)

}

// Env overrides empty flag to take precedence
func TestParseNetwork_envOverridesEmptyFlag(t *testing.T) {

t.Setenv(EnvCustomNetwork, "custom-network")

cmd := createCmdWithNetworkFlag()
Expand All @@ -108,12 +104,10 @@ func TestParseNetwork_envOverridesEmptyFlag(t *testing.T) {
network, err := ParseNetwork(cmd)
require.NoError(t, err)
assert.Equal(t, Network("custom-network"), network)

}

// Explicitly set flag but env should still override
func TestParseNetwork_envOverridesFlag(t *testing.T) {

t.Setenv(EnvCustomNetwork, "custom-network")

cmd := createCmdWithNetworkFlag()
Expand All @@ -123,5 +117,4 @@ func TestParseNetwork_envOverridesFlag(t *testing.T) {
network, err := ParseNetwork(cmd)
require.NoError(t, err)
assert.Equal(t, Network("custom-network"), network)

}
4 changes: 2 additions & 2 deletions nodebuilder/p2p/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func testModule(tp node.Type) fx.Option {
}

func TestModuleBuild(t *testing.T) {
var test = []struct {
test := []struct {
tp node.Type
}{
{tp: node.Bridge},
Expand All @@ -49,7 +49,7 @@ func TestModuleBuild(t *testing.T) {
}

func TestModuleBuild_WithMetrics(t *testing.T) {
var test = []struct {
test := []struct {
tp node.Type
}{
{tp: node.Full},
Expand Down
4 changes: 0 additions & 4 deletions nodebuilder/share/cmd/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ var sharesAvailableCmd = &cobra.Command{
defer client.Close()

eh, err := getExtendedHeaderFromCmdArg(cmd.Context(), client, args[0])

if err != nil {
return err
}
Expand Down Expand Up @@ -80,7 +79,6 @@ var getSharesByNamespaceCmd = &cobra.Command{
defer client.Close()

eh, err := getExtendedHeaderFromCmdArg(cmd.Context(), client, args[0])

if err != nil {
return err
}
Expand All @@ -107,7 +105,6 @@ var getShare = &cobra.Command{
defer client.Close()

eh, err := getExtendedHeaderFromCmdArg(cmd.Context(), client, args[0])

if err != nil {
return err
}
Expand Down Expand Up @@ -156,7 +153,6 @@ var getEDS = &cobra.Command{
defer client.Close()

eh, err := getExtendedHeaderFromCmdArg(cmd.Context(), client, args[0])

if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 61ac522

Please sign in to comment.