Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
harish551 committed Nov 20, 2023
1 parent 1c821ea commit 48f933a
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 56 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ on:
- main
- development

env:
GO_VERSION: "1.21.3"

permissions:
contents: read

# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# This workflow makes x86_64 binaries for mac, windows, and linux.

jobs:
Expand All @@ -29,11 +41,11 @@ jobs:
targetos: [ darwin, linux ]
name: streampayd ${{ matrix.arch }} for ${{ matrix.targetos }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v1
uses: actions/setup-go@v4
with:
go-version: 1.20
go-version: ${{env.GO_VERSION}}
env:
GOOS: ${{ matrix.targetos }}
GOARCH: ${{ matrix.arch }}
Expand All @@ -44,7 +56,7 @@ jobs:
cd cmd/streampayd
go build .
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: streampayd ${{ matrix.targetos }} ${{ matrix.arch }}
path: cmd/streampayd/streampayd
20 changes: 15 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,34 @@ on:
tags:
- v*
branches:
- master
- main
pull_request:
paths:
- '**.go'

env:
GO_VERSION: '1.21.3'

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: 1.20
- uses: actions/checkout@v3.1.0
go-version: ${{env.GO_VERSION}}
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
args: --timeout 5m0s
args: --timeout 10m
7 changes: 4 additions & 3 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -26,13 +27,13 @@ type HandlerOptions struct {

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
}
if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
}
if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

sigGasConsumer := options.SigGasConsumer
Expand Down
4 changes: 3 additions & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"time"

sdkmath "cosmossdk.io/math"

"github.com/OmniFlix/streampay/v2/app"

dbm "github.com/cometbft/cometbft-db"
Expand Down Expand Up @@ -212,7 +214,7 @@ func (s *KeeperTestHelper) RunMsg(msg sdk.Msg) (*sdk.Result, error) {
}

// AllocateRewardsToValidator allocates reward tokens to a distribution module then allocates rewards to the validator address.
func (s *KeeperTestHelper) AllocateRewardsToValidator(valAddr sdk.ValAddress, rewardAmt sdk.Int) {
func (s *KeeperTestHelper) AllocateRewardsToValidator(valAddr sdk.ValAddress, rewardAmt sdkmath.Int) {
validator, found := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
s.Require().True(found)

Expand Down
38 changes: 18 additions & 20 deletions x/streampay/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import (
"fmt"
"time"

storetypes "github.com/cosmos/cosmos-sdk/store/types"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

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

errorsmod "cosmossdk.io/errors"
"github.com/OmniFlix/streampay/v2/x/streampay/types"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

type (
Expand Down Expand Up @@ -72,13 +70,13 @@ func (k Keeper) CreateStreamPayment(ctx sdk.Context,
cancellable bool,
) (string, error) {
if duration <= 0 {
return "", sdkerrors.Wrapf(
return "", errorsmod.Wrapf(
types.ErrInvalidAmount,
fmt.Sprintf("duration %s is not valid, should be a possitive value", duration.String()),
)
}
if amount.IsNil() || amount.IsNegative() || amount.IsZero() {
return "", sdkerrors.Wrapf(
return "", errorsmod.Wrapf(
types.ErrInvalidAmount,
fmt.Sprintf("amount %s is not valid format", amount.String()),
)
Expand Down Expand Up @@ -123,25 +121,25 @@ func (k Keeper) CreateStreamPayment(ctx sdk.Context,
func (k Keeper) StopStreamPayment(ctx sdk.Context, streamId string, sender sdk.AccAddress) error {
streamPayment, ok := k.GetStreamPayment(ctx, streamId)
if !ok {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
sdkerrors.ErrNotFound,
fmt.Sprintf("no stream payment found with id %s", streamId),
)
}
if sender.String() != streamPayment.Sender {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
sdkerrors.ErrUnauthorized,
fmt.Sprintf("address %s is not allowed to stop the stream payment", streamId),
)
}
if !streamPayment.Cancellable {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
sdkerrors.ErrUnauthorized,
fmt.Sprintf("stream payment %s is not cancellable", streamId),
)
}
if ctx.BlockTime().Unix() > streamPayment.EndTime.Unix() {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
sdkerrors.ErrUnauthorized,
fmt.Sprintf("ended stream payment cannot be canceled, stream payment %s", streamId),
)
Expand Down Expand Up @@ -185,26 +183,26 @@ func (k Keeper) StopStreamPayment(ctx sdk.Context, streamId string, sender sdk.A
func (k Keeper) ClaimStreamedAmount(ctx sdk.Context, streamId string, claimer sdk.AccAddress) error {
streamPayment, ok := k.GetStreamPayment(ctx, streamId)
if !ok {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
sdkerrors.ErrNotFound,
fmt.Sprintf("no stream payment found with id %s", streamId),
)
}
claimerAddr := claimer.String()
if claimerAddr != streamPayment.Recipient {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
sdkerrors.ErrUnauthorized,
fmt.Sprintf("address %s is not allowed to claim the stream payment", claimerAddr),
)
}
if ctx.BlockTime().Unix() < streamPayment.StartTime.Unix() {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
types.ErrInvalidAmount,
fmt.Sprintf("stream payment %s is not started yet", streamId),
)
}
if streamPayment.StreamedAmount.IsGTE(streamPayment.TotalAmount) {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
types.ErrInvalidAmount,
fmt.Sprintf("stream payment %s is already fully claimed", streamId),
)
Expand All @@ -224,7 +222,7 @@ func (k Keeper) ClaimStreamedAmount(ctx sdk.Context, streamId string, claimer sd
}

default:
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
types.ErrInvalidStreamPaymentType,
fmt.Sprintf("stream payment %s has invalid type", streamId),
)
Expand All @@ -234,7 +232,7 @@ func (k Keeper) ClaimStreamedAmount(ctx sdk.Context, streamId string, claimer sd

func (k Keeper) claimDelayedStreamPayment(ctx sdk.Context, streamPayment types.StreamPayment, claimer sdk.AccAddress) error {
if ctx.BlockTime().Unix() < streamPayment.EndTime.Unix() {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
types.ErrInvalidAmount,
fmt.Sprintf("stream payment %s is delayed type and not ended yet", streamPayment.Id),
)
Expand All @@ -258,7 +256,7 @@ func (k Keeper) claimContinuousStreamPayment(ctx sdk.Context, streamPayment type
amount := sdk.NewCoin(streamPayment.TotalAmount.Denom, sdk.NewInt(amountToSend))

if amount.IsZero() || amount.IsNil() {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
types.ErrInvalidAmount,
fmt.Sprintf("no valid amount to claim for stream payment %s ", streamPayment.Id),
)
Expand Down Expand Up @@ -287,7 +285,7 @@ func (k Keeper) claimPeriodicStreamPayment(ctx sdk.Context, streamPayment types.
amount := sdk.NewCoin(streamPayment.TotalAmount.Denom, sdk.NewInt(amountToSend))

if amount.IsZero() || amount.IsNil() {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
types.ErrInvalidAmount,
fmt.Sprintf("no valid amount to claim for stream payment %s ", streamPayment.Id),
)
Expand Down
18 changes: 9 additions & 9 deletions x/streampay/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package types
// DONTCOVER

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
errorsmod "cosmossdk.io/errors"
)

// x/streampay module errors
var (
ErrInvalidAmount = sdkerrors.Register(ModuleName, 2, "invalid amount")
ErrInvalidStreamPaymentType = sdkerrors.Register(ModuleName, 3, "invalid stream payment type")
ErrInvalidNextPaymentNumber = sdkerrors.Register(ModuleName, 4, "invalid next payment number")
ErrInvalidTimestamp = sdkerrors.Register(ModuleName, 5, "invalid timestamp")
ErrInvalidStreamPaymentFee = sdkerrors.Register(ModuleName, 6, "invalid stream payment fee")
ErrInvalidFee = sdkerrors.Register(ModuleName, 7, "invalid fee")
ErrInvalidPeriods = sdkerrors.Register(ModuleName, 8, "invalid periods")
ErrInvalidDuration = sdkerrors.Register(ModuleName, 9, "invalid duration")
ErrInvalidAmount = errorsmod.Register(ModuleName, 2, "invalid amount")
ErrInvalidStreamPaymentType = errorsmod.Register(ModuleName, 3, "invalid stream payment type")
ErrInvalidNextPaymentNumber = errorsmod.Register(ModuleName, 4, "invalid next payment number")
ErrInvalidTimestamp = errorsmod.Register(ModuleName, 5, "invalid timestamp")
ErrInvalidStreamPaymentFee = errorsmod.Register(ModuleName, 6, "invalid stream payment fee")
ErrInvalidFee = errorsmod.Register(ModuleName, 7, "invalid fee")
ErrInvalidPeriods = errorsmod.Register(ModuleName, 8, "invalid periods")
ErrInvalidDuration = errorsmod.Register(ModuleName, 9, "invalid duration")
)
4 changes: 2 additions & 2 deletions x/streampay/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package types
import (
"fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

var DefaultStreamPaymentFee = sdk.NewInt64Coin("uspay", 10_000_000) // 10SPAY
Expand Down Expand Up @@ -39,7 +39,7 @@ func validateStreamPaymentFee(i interface{}) error {
}

if !fee.IsValid() || fee.IsZero() {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
ErrInvalidStreamPaymentFee,
"invalid fee amount %s, only accepts positive amounts",
fee.String(),
Expand Down
24 changes: 12 additions & 12 deletions x/streampay/types/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"time"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

func validateStreamPayment(streamPayment StreamPayment) error {
Expand All @@ -30,7 +30,7 @@ func validateStreamPayment(streamPayment StreamPayment) error {

func validateAmount(amount sdk.Coin) error {
if !amount.IsValid() || amount.IsNil() || amount.Amount.LTE(sdk.ZeroInt()) {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
ErrInvalidAmount,
fmt.Sprintf("amount %s is not valid", amount.String()),
)
Expand All @@ -40,7 +40,7 @@ func validateAmount(amount sdk.Coin) error {

func validateStreamType(_type StreamType) error {
if !(_type == TypeDelayed || _type == TypeContinuous || _type == TypePeriodic) {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
ErrInvalidStreamPaymentType,
fmt.Sprintf("stream payment type %s is not valid", _type),
)
Expand All @@ -51,51 +51,51 @@ func validateStreamType(_type StreamType) error {
func ValidateNextStreamPaymentNumber(n interface{}) error {
_, ok := n.(uint64)
if !ok {
return sdkerrors.Wrapf(ErrInvalidNextPaymentNumber, "invalid value for next payment number: %v", n)
return errorsmod.Wrapf(ErrInvalidNextPaymentNumber, "invalid value for next payment number: %v", n)
}
return nil
}

func ValidateTimestamp(t interface{}) error {
_, ok := t.(time.Time)
if !ok {
return sdkerrors.Wrapf(ErrInvalidTimestamp, "invalid timestamp: %T", t)
return errorsmod.Wrapf(ErrInvalidTimestamp, "invalid timestamp: %T", t)
}
return nil
}

func ValidateDuration(d interface{}) error {
duration, ok := d.(time.Duration)
if !ok {
return sdkerrors.Wrapf(ErrInvalidDuration, "invalid duration: %v", d)
return errorsmod.Wrapf(ErrInvalidDuration, "invalid duration: %v", d)
}
if duration < 1 {
return sdkerrors.Wrapf(ErrInvalidDuration, "invalid duration: %v", duration)
return errorsmod.Wrapf(ErrInvalidDuration, "invalid duration: %v", duration)
}
return nil
}

func validatePeriods(periods []*Period, totalAmount sdk.Coin, totalDuration time.Duration) error {
if len(periods) == 0 {
return sdkerrors.Wrapf(ErrInvalidPeriods, "periods cannot be empty")
return errorsmod.Wrapf(ErrInvalidPeriods, "periods cannot be empty")
}
totalAmt := int64(0)
totalDur := int64(0)
for _, period := range periods {
if period.Amount < 1 {
return sdkerrors.Wrapf(ErrInvalidPeriods, "invalid period amount: %d", period.Amount)
return errorsmod.Wrapf(ErrInvalidPeriods, "invalid period amount: %d", period.Amount)
}
if period.Duration < 1 {
return sdkerrors.Wrapf(ErrInvalidPeriods, "invalid period duration: %d", period.Duration)
return errorsmod.Wrapf(ErrInvalidPeriods, "invalid period duration: %d", period.Duration)
}
totalAmt += period.Amount
totalDur += period.Duration
}
if totalAmt != totalAmount.Amount.Int64() {
return sdkerrors.Wrapf(ErrInvalidPeriods, "period amounts do not add up to total amount")
return errorsmod.Wrapf(ErrInvalidPeriods, "period amounts do not add up to total amount")
}
if totalDur != int64(totalDuration.Seconds()) {
return sdkerrors.Wrapf(ErrInvalidPeriods, "period durations do not add up to total duration")
return errorsmod.Wrapf(ErrInvalidPeriods, "period durations do not add up to total duration")
}
return nil
}

0 comments on commit 48f933a

Please sign in to comment.