Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed Jul 1, 2024
1 parent 8385cae commit aafeaec
Show file tree
Hide file tree
Showing 71 changed files with 249 additions and 304 deletions.
2 changes: 1 addition & 1 deletion e2e/farm/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (s *QueryTestSuite) TestQueryCmd() {

_, err = s.WaitForHeight(startHeight)
s.Require().NoError(err)
s.WaitForNextBlock()
s.Require().NoError(s.WaitForNextBlock())

lpToken := sdk.NewCoin(lpTokenDenom, sdk.NewInt(100))
txResult = StakeExec(
Expand Down
3 changes: 3 additions & 0 deletions e2e/htlc/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func (s *TxTestSuite) TestTxCmd() {
testCases[0].args.secret.String(),
args...,
)
s.Require().EqualValues(0, txResult.Code)

respType = QueryHTLCExec(
s.T(),
Expand Down Expand Up @@ -373,6 +374,7 @@ func (s *TxTestSuite) TestTxCmd() {
testCases[1].args.secret.String(),
args...,
)
s.Require().EqualValues(0, txResult.Code)

respType = QueryHTLCExec(
s.T(),
Expand Down Expand Up @@ -476,6 +478,7 @@ func (s *TxTestSuite) TestTxCmd() {
testCases[2].args.secret.String(),
args...,
)
s.Require().EqualValues(0, txResult.Code)

respType = QueryHTLCExec(
s.T(),
Expand Down
2 changes: 1 addition & 1 deletion e2e/oracle/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (s *TxTestSuite) TestTxCmd() {
var requestIds []string
var requestsBz []byte
for _, attribute := range event.Attributes {
if string(attribute.Key) == servicetypes.AttributeKeyRequests {
if attribute.Key == servicetypes.AttributeKeyRequests {
requestsBz = []byte(attribute.GetValue())
found = true
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/random/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s *QueryTestSuite) TestQueryCmd() {
s.Require().Len(qrrResp.Requests, 1)

// ------get service request-------------
requestHeight = requestHeight + 1
requestHeight ++
_, err = s.Network.WaitForHeightWithTimeout(
requestHeight,
time.Duration(int64(blockInterval+2)*int64(s.Network.TimeoutCommit)),
Expand All @@ -145,7 +145,7 @@ func (s *QueryTestSuite) TestQueryCmd() {
var requestIds []string
var requestsBz []byte
for _, attribute := range event.Attributes {
if string(attribute.Key) == servicetypes.AttributeKeyRequests {
if attribute.Key == servicetypes.AttributeKeyRequests {
requestsBz = []byte(attribute.Value)
found = true
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/random/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *TxTestSuite) TestTxCmd() {
s.Require().Len(qrrResp.Requests, 1)

// ------get service request-------------
requestHeight = requestHeight + 1
requestHeight ++
_, err := s.WaitForHeightWithTimeout(
requestHeight,
time.Duration(int64(blockInterval+5)*int64(s.TimeoutCommit)),
Expand All @@ -140,7 +140,7 @@ func (s *TxTestSuite) TestTxCmd() {
var requestIds []string
var requestsBz []byte
for _, attribute := range event.Attributes {
if string(attribute.Key) == servicetypes.AttributeKeyRequests {
if attribute.Key == servicetypes.AttributeKeyRequests {
requestsBz = []byte(attribute.GetValue())
found = true
}
Expand Down
9 changes: 4 additions & 5 deletions e2e/service/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"mods.irisnet.org/e2e"
servicecli "mods.irisnet.org/modules/service/client/cli"
"mods.irisnet.org/modules/service/types"
servicetypes "mods.irisnet.org/modules/service/types"
"mods.irisnet.org/simapp"
)
Expand All @@ -32,8 +31,8 @@ func (s *QueryTestSuite) SetupSuite() {
var serviceGenesisState servicetypes.GenesisState
cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[servicetypes.ModuleName], &serviceGenesisState)

serviceGenesisState.Params.ArbitrationTimeLimit = time.Duration(time.Second)
serviceGenesisState.Params.ComplaintRetrospect = time.Duration(time.Second)
serviceGenesisState.Params.ArbitrationTimeLimit = time.Second
serviceGenesisState.Params.ComplaintRetrospect = time.Second
cfg.GenesisState[servicetypes.ModuleName] = cfg.Codec.MustMarshalJSON(&serviceGenesisState)
cfg.NumValidators = 1
})
Expand Down Expand Up @@ -308,10 +307,10 @@ func (s *QueryTestSuite) TestQueryCmd() {
var requests []servicetypes.CompactRequest
var requestsBz []byte
for _, attribute := range event.Attributes {
if string(attribute.Key) == types.AttributeKeyRequests {
if string(attribute.Key) == servicetypes.AttributeKeyRequests {
requestsBz = []byte(attribute.Value)
}
if string(attribute.Key) == types.AttributeKeyRequestContextID &&
if string(attribute.Key) == servicetypes.AttributeKeyRequestContextID &&
string(attribute.GetValue()) == requestContextId {
found = true
}
Expand Down
11 changes: 5 additions & 6 deletions e2e/service/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"mods.irisnet.org/e2e"
servicecli "mods.irisnet.org/modules/service/client/cli"
"mods.irisnet.org/modules/service/types"
servicetypes "mods.irisnet.org/modules/service/types"
"mods.irisnet.org/simapp"
)
Expand All @@ -32,8 +31,8 @@ func (s *TxTestSuite) SetupSuite() {
var serviceGenesisState servicetypes.GenesisState
cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[servicetypes.ModuleName], &serviceGenesisState)

serviceGenesisState.Params.ArbitrationTimeLimit = time.Duration(time.Second)
serviceGenesisState.Params.ComplaintRetrospect = time.Duration(time.Second)
serviceGenesisState.Params.ArbitrationTimeLimit = time.Second
serviceGenesisState.Params.ComplaintRetrospect = time.Second
cfg.GenesisState[servicetypes.ModuleName] = cfg.Codec.MustMarshalJSON(&serviceGenesisState)
cfg.NumValidators = 1
})
Expand Down Expand Up @@ -314,11 +313,11 @@ func (s *TxTestSuite) TestQueryCmd() {
var requests []servicetypes.CompactRequest
var requestsBz []byte
for _, attribute := range event.Attributes {
if string(attribute.Key) == types.AttributeKeyRequests {
if attribute.Key == servicetypes.AttributeKeyRequests {
requestsBz = []byte(attribute.GetValue())
}
if string(attribute.Key) == types.AttributeKeyRequestContextID &&
string(attribute.GetValue()) == requestContextId {
if attribute.Key == servicetypes.AttributeKeyRequestContextID &&
attribute.GetValue() == requestContextId {
found = true
}
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/token/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (s *TxTestSuite) TestTxCmd() {
from.String(),
symbol,
)
exceptedAmount = exceptedAmount - burnAmount
exceptedAmount -= burnAmount
s.Require().Equal(exceptedAmount, balance.Amount.Int64())

//------test GetCmdEditToken()-------------
Expand Down
6 changes: 4 additions & 2 deletions modules/coinswap/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
// InitGenesis initializes the coinswap module's state from a given genesis state.
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
if err := types.ValidateGenesis(genState); err != nil {
panic(fmt.Errorf("panic for ValidateGenesis,%v", err))
panic(fmt.Errorf("panic for ValidateGenesis,%w", err))
}
if err := k.SetParams(ctx, genState.Params); err != nil {
panic(fmt.Errorf("panic for SetParams,%w", err))
}
k.SetParams(ctx, genState.Params)
k.SetStandardDenom(ctx, genState.StandardDenom)
k.setSequence(ctx, genState.Sequence)
for _, pool := range genState.Pool {
Expand Down
3 changes: 2 additions & 1 deletion modules/coinswap/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ func (suite *TestSuite) TestParams() {
{types.DefaultParams()},
}
for _, tc := range cases {
suite.keeper.SetParams(suite.ctx, tc.params)
suite.NoError(suite.keeper.SetParams(suite.ctx, tc.params), "set params failed")

feeParam := suite.keeper.GetParams(suite.ctx)
suite.Equal(tc.params.Fee, feeParam.Fee)
}
}

func setupWithGenesisAccounts(t *testing.T, keeper *keeper.Keeper) *simapp.SimApp {
t.Helper()
amountInitStandard, _ := sdkmath.NewIntFromString("30000000000000000000")
amountInitBTC, _ := sdkmath.NewIntFromString("3000000000")

Expand Down
7 changes: 7 additions & 0 deletions modules/coinswap/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,13 @@ func SimulateMsgRemoveUnilateralLiquidity(
}

balances, err := k.GetPoolBalances(ctx, pool.EscrowAddress)
if err != nil {
return simtypes.NoOpMsg(
types.ModuleName,
types.TypeMsgRemoveUnilateralLiquidity,
"pool balances not found",
), nil, err
}

lptDenom := pool.LptDenom
targetTokenDenom := targetToken.Denom
Expand Down
4 changes: 3 additions & 1 deletion modules/farm/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) {
k.SetEscrowInfo(ctx, info)
}
k.SetSequence(ctx, data.Sequence)
k.SetParams(ctx, data.Params)
if err := k.SetParams(ctx, data.Params); err != nil {
panic(err)
}
}

// ExportGenesis outputs the genesis state
Expand Down
7 changes: 4 additions & 3 deletions modules/farm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
"testing"

"cosmossdk.io/math"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -57,7 +58,7 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.cdc = codec.NewAminoCodec(app.LegacyAmino())
suite.ctx = app.BaseApp.NewContext(isCheckTx, tmproto.Header{Height: 1})
suite.app = app
suite.keeper.SetParams(suite.ctx, types.DefaultParams())
suite.Require().NoError(suite.keeper.SetParams(suite.ctx, types.DefaultParams()), "set params failed")
suite.setTestAddrs()
}

Expand Down Expand Up @@ -247,7 +248,7 @@ func (suite *KeeperTestSuite) TestStake() {
type args struct {
height int64
stakeCoin sdk.Coin
locked sdk.Int
locked math.Int
expectReward sdk.Coins
debt sdk.Coins
rewardPerShare sdk.Dec
Expand Down Expand Up @@ -447,7 +448,7 @@ func (suite *KeeperTestSuite) AssertStake(
poolID string,
height int64,
stakeCoin sdk.Coin,
locked sdk.Int,
locked math.Int,
expectReward, debt sdk.Coins,
rewardPerShare sdk.Dec,
) {
Expand Down
2 changes: 1 addition & 1 deletion modules/farm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (m msgServer) CreatePool(

ctx := sdk.UnwrapSDKContext(goCtx)
// check valid begin height
if ctx.BlockHeight() > int64(msg.StartHeight) {
if ctx.BlockHeight() > msg.StartHeight {
return nil, errorsmod.Wrapf(
types.ErrExpiredHeight,
"The current block height[%d] is greater than StartHeight[%d]",
Expand Down
2 changes: 1 addition & 1 deletion modules/farm/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (k Keeper) TaxRate(ctx sdk.Context) sdk.Dec {
// GetParams sets the farm module parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get([]byte(types.ParamsKey))
bz := store.Get(types.ParamsKey)
if bz == nil {
return params
}
Expand Down
17 changes: 9 additions & 8 deletions modules/farm/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

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

Expand Down Expand Up @@ -63,20 +64,20 @@ func (k Keeper) DestroyPool(ctx sdk.Context, poolId string, creator sdk.AccAddre
// AdjustPool adjusts farm pool parameters
func (k Keeper) AdjustPool(
ctx sdk.Context,
poolId string,
poolID string,
reward sdk.Coins,
rewardPerBlock sdk.Coins,
creator sdk.AccAddress,
) (err error) {
pool, exist := k.GetPool(ctx, poolId)
pool, exist := k.GetPool(ctx, poolID)
// check if the liquidity pool exists
if !exist {
return errorsmod.Wrapf(types.ErrPoolNotFound, poolId)
return errorsmod.Wrapf(types.ErrPoolNotFound, poolID)
}

if !pool.Editable {
return errorsmod.Wrapf(
types.ErrInvalidOperate, "pool [%s] is not editable", poolId)
types.ErrInvalidOperate, "pool [%s] is not editable", poolID)
}

// check permissions
Expand All @@ -88,7 +89,7 @@ func (k Keeper) AdjustPool(
if k.Expired(ctx, pool) {
return errorsmod.Wrapf(types.ErrPoolExpired,
"pool [%s] has expired at height[%d], current [%d]",
poolId,
poolID,
pool.EndHeight,
ctx.BlockHeight(),
)
Expand Down Expand Up @@ -144,7 +145,7 @@ func (k Keeper) AdjustPool(
availableReward = remainingReward.Add(reward...)
}

pool.Rules = types.RewardRules(rules).UpdateWith(rewardPerBlock)
pool.Rules = rules.UpdateWith(rewardPerBlock)
k.SetRewardRules(ctx, pool.Id, pool.Rules)

// expiredHeight = [(srcEndHeight-beginPoint)*srcRewardPerBlock +appendReward]/RewardPerBlock + beginPoint
Expand Down Expand Up @@ -224,7 +225,7 @@ func (k Keeper) createPool(
func (k Keeper) updatePool(
ctx sdk.Context,
pool types.FarmPool,
amount sdk.Int,
amount math.Int,
isDestroy bool,
) (types.FarmPool, sdk.Coins, error) {
height := ctx.BlockHeight()
Expand All @@ -246,7 +247,7 @@ func (k Keeper) updatePool(
pool.TotalLptLocked.Amount.GT(sdk.ZeroInt()) {
blockInterval := height - pool.LastHeightDistrRewards
for i := range rules {
rewardCollected := rules[i].RewardPerBlock.MulRaw(int64(blockInterval))
rewardCollected := rules[i].RewardPerBlock.MulRaw(blockInterval)
coinCollected := sdk.NewCoin(rules[i].Reward, rewardCollected)
if rules[i].RemainingReward.LT(rewardCollected) {
k.Logger(ctx).Error(
Expand Down
3 changes: 2 additions & 1 deletion modules/farm/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

Expand All @@ -19,7 +20,7 @@ const (
// RandomizedGenState generates a random GenesisState for farm
func RandomizedGenState(simState *module.SimulationState) {
var (
createPoolFee sdk.Int
createPoolFee math.Int
taxRate sdk.Dec
maxRewardCategoryN uint32
)
Expand Down
14 changes: 7 additions & 7 deletions modules/farm/spec/01_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ type FarmPool struct {

type RewardRule struct {
Reward string
TotalReward sdk.Int
RemainingReward sdk.Int
RewardPerBlock sdk.Int
TotalReward math.Int
RemainingReward math.Int
RewardPerBlock math.Int
RewardPerShare sdk.Dec
}
```
Expand All @@ -62,9 +62,9 @@ type RewardRule struct {
```go
type RewardRule struct {
Reward string
TotalReward sdk.Int
RemainingReward sdk.Int
RewardPerBlock sdk.Int
TotalReward math.Int
RemainingReward math.Int
RewardPerBlock math.Int
RewardPerShare sdk.Dec
}
```
Expand All @@ -83,7 +83,7 @@ type RewardRule struct {
type FarmInfo struct {
PoolId string
Address string
Locked sdk.Int
Locked math.Int
RewardDebt sdks.Coins
}
```
Expand Down
3 changes: 2 additions & 1 deletion modules/farm/types/farm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
math "math"

errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand All @@ -26,7 +27,7 @@ func (pool FarmPool) ExpiredHeight() (int64, error) {
return pool.StartHeight + targetInteval, nil
}

func (pool FarmPool) CaclRewards(farmInfo FarmInfo, deltaAmt sdk.Int) (rewards, rewardDebt sdk.Coins) {
func (pool FarmPool) CaclRewards(farmInfo FarmInfo, deltaAmt sdkmath.Int) (rewards, rewardDebt sdk.Coins) {
for _, r := range pool.Rules {
if farmInfo.Locked.GT(sdk.ZeroInt()) {
pendingRewardTotal := r.RewardPerShare.MulInt(farmInfo.Locked).TruncateInt()
Expand Down
Loading

0 comments on commit aafeaec

Please sign in to comment.