Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Oct 29, 2024
1 parent d030b0b commit 4a6b8d1
Show file tree
Hide file tree
Showing 24 changed files with 187 additions and 95 deletions.
6 changes: 4 additions & 2 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (s *KeeperTestHelper) Setup() {
}

func (s *KeeperTestHelper) FundAccount(acccount sdk.AccAddress, moduleName string, coins sdk.Coins) {
s.App.BankKeeper.MintCoins(s.Ctx, moduleName, coins)
s.App.BankKeeper.SendCoinsFromModuleToAccount(s.Ctx, moduleName, acccount, coins)
err := s.App.BankKeeper.MintCoins(s.Ctx, moduleName, coins)
s.Require().NoError(err)
err = s.App.BankKeeper.SendCoinsFromModuleToAccount(s.Ctx, moduleName, acccount, coins)
s.Require().NoError(err)
}
2 changes: 1 addition & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import (
ibctransfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand Down
41 changes: 32 additions & 9 deletions cmd/reserved/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,22 @@ func initAppForTestnet(app *app.App, args valArgs) *app.App {
iterator.Close()

// Add our validator to power and last validators store
app.StakingKeeper.SetValidator(ctx, newVal)
err = app.StakingKeeper.SetValidator(ctx, newVal)
if err != nil {
tmos.Exit(err.Error())
}
err = app.StakingKeeper.SetValidatorByConsAddr(ctx, newVal)
if err != nil {
tmos.Exit(err.Error())
}
app.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal)
app.StakingKeeper.SetLastValidatorPower(ctx, validator, 0)
err = app.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal)
if err != nil {
tmos.Exit(err.Error())
}
err = app.StakingKeeper.SetLastValidatorPower(ctx, validator, 0)
if err != nil {
tmos.Exit(err.Error())
}
if err := app.StakingKeeper.Hooks().AfterValidatorCreated(ctx, validator); err != nil {
tmos.Exit(err.Error())
}
Expand All @@ -172,10 +181,22 @@ func initAppForTestnet(app *app.App, args valArgs) *app.App {
//

// Initialize records for this validator across all distribution stores
app.DistrKeeper.SetValidatorHistoricalRewards(ctx, validator, 0, distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1))
app.DistrKeeper.SetValidatorCurrentRewards(ctx, validator, distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1))
app.DistrKeeper.SetValidatorAccumulatedCommission(ctx, validator, distrtypes.InitialValidatorAccumulatedCommission())
app.DistrKeeper.SetValidatorOutstandingRewards(ctx, validator, distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}})
err = app.DistrKeeper.SetValidatorHistoricalRewards(ctx, validator, 0, distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1))
if err != nil {
tmos.Exit(err.Error())
}
err = app.DistrKeeper.SetValidatorCurrentRewards(ctx, validator, distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1))
if err != nil {
tmos.Exit(err.Error())
}
err = app.DistrKeeper.SetValidatorAccumulatedCommission(ctx, validator, distrtypes.InitialValidatorAccumulatedCommission())
if err != nil {
tmos.Exit(err.Error())
}
err = app.DistrKeeper.SetValidatorOutstandingRewards(ctx, validator, distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}})
if err != nil {
tmos.Exit(err.Error())
}

// SLASHING
//
Expand All @@ -187,8 +208,10 @@ func initAppForTestnet(app *app.App, args valArgs) *app.App {
StartHeight: app.LastBlockHeight() - 1,
Tombstoned: false,
}
app.SlashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, newValidatorSigningInfo)

err = app.SlashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, newValidatorSigningInfo)
if err != nil {
tmos.Exit(err.Error())
}
// BANK
//
bondDenom, err := app.StakingKeeper.BondDenom(ctx)
Expand Down
5 changes: 4 additions & 1 deletion x/auction/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ func (k *Keeper) BeginBlocker(ctx context.Context) error {
}

if needCleanup {
k.refundBidders(ctx, bidQueue)
err = k.refundBidders(ctx, bidQueue)
if err != nil {
return true, err
}

// clear the auction afterward
err = k.DeleteAuction(ctx, auction.AuctionId)
Expand Down
7 changes: 5 additions & 2 deletions x/auction/keeper/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ func (k Keeper) GetNewAuction(ctx context.Context,
vaultId uint64,
) (*types.Auction, bool, error) {
var newAuction *types.Auction
k.Auctions.Walk(ctx, nil, func(key uint64, value types.Auction) (stop bool, err error) {
err := k.Auctions.Walk(ctx, nil, func(key uint64, value types.Auction) (stop bool, err error) {
if value.VaultId == vaultId {
newAuction = &value
return true, nil
}
return false, nil
})
if err != nil {
return nil, false, err
}
if newAuction != nil {
return newAuction, false, nil
}
newAuction, err := k.NewAuction(ctx, startTime, initialPrice, item, targetGoal, vaultId)
newAuction, err = k.NewAuction(ctx, startTime, initialPrice, item, targetGoal, vaultId)
if err != nil {
return newAuction, true, err
}
Expand Down
8 changes: 4 additions & 4 deletions x/auction/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func (k Querier) QueryAllAuction(ctx context.Context, req *types.QueryAllAuction

allAuction := []types.Auction{}

k.k.Auctions.Walk(ctx, nil, func(key uint64, value types.Auction) (stop bool, err error) {
err := k.k.Auctions.Walk(ctx, nil, func(key uint64, value types.Auction) (stop bool, err error) {
allAuction = append(allAuction, value)
return false, nil
})

return &types.QueryAllAuctionResponse{
Auctions: allAuction,
}, nil
}, err
}

func (k Querier) QueryAllBids(ctx context.Context, req *types.QueryAllBidsRequest) (*types.QueryAllBidsResponse, error) {
Expand All @@ -53,7 +53,7 @@ func (k Querier) QueryAllBids(ctx context.Context, req *types.QueryAllBidsReques

allBids := []types.Bid{}

k.k.Bids.Walk(ctx, nil, func(key uint64, value types.BidQueue) (stop bool, err error) {
err := k.k.Bids.Walk(ctx, nil, func(key uint64, value types.BidQueue) (stop bool, err error) {
for _, bid := range value.Bids {
allBids = append(allBids, *bid)
}
Expand All @@ -62,5 +62,5 @@ func (k Querier) QueryAllBids(ctx context.Context, req *types.QueryAllBidsReques

return &types.QueryAllBidsResponse{
Bids: allBids,
}, nil
}, err
}
2 changes: 1 addition & 1 deletion x/auction/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewKeeper(
BidIdSeq: collections.NewMap(sb, types.BidIdSeqPrefix, "bid_id_sequence", collections.Uint64Key, collections.Uint64Value),
Auctions: collections.NewMap(sb, types.AuctionsPrefix, "auctions", collections.Uint64Key, codec.CollValue[types.Auction](cdc)),
Bids: collections.NewMap(sb, types.BidsPrefix, "bids", collections.Uint64Key, codec.CollValue[types.BidQueue](cdc)),
BidByAddress: collections.NewMap(sb, types.BidByAddressPrefix, "bids_by_address", collections.PairKeyCodec(collections.Uint64Key, sdk.LengthPrefixedAddressKey(sdk.AccAddressKey)), codec.CollValue[types.Bids](cdc)),
BidByAddress: collections.NewMap(sb, types.BidByAddressPrefix, "bids_by_address", collections.PairKeyCodec(collections.Uint64Key, sdk.LengthPrefixedAddressKey(sdk.AccAddressKey)), codec.CollValue[types.Bids](cdc)), //nolint:staticcheck
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/oracle/bandtesting/x/oracle/keeper/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v8/modules/core/24-host"

Expand Down
2 changes: 1 addition & 1 deletion x/oracle/bandtesting/x/oracle/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
)

Expand Down
8 changes: 4 additions & 4 deletions x/oracle/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func NewUpdateBandOracleRequestProposalTxCmd() *cobra.Command {
cmd.Flags().Uint64(flagSufficientValidatorCount, 0, "Sufficient Validator Count")
cmd.Flags().Uint64(flagMinSourceCount, 3, "Min Source Count")
cmd.Flags().String(govcli.FlagTitle, "", "title of proposal")
cmd.Flags().String(govcli.FlagDescription, "", "description of proposal")
cmd.Flags().String(govcli.FlagDescription, "", "description of proposal") //nolint:staticcheck
cmd.Flags().String(govcli.FlagDeposit, "", "deposit of proposal")

flags.AddTxFlagsToCmd(cmd)
Expand Down Expand Up @@ -182,7 +182,7 @@ func NewDeleteBandOracleRequestProposalTxCmd() *cobra.Command {
}

cmd.Flags().String(govcli.FlagTitle, "", "title of proposal")
cmd.Flags().String(govcli.FlagDescription, "", "description of proposal")
cmd.Flags().String(govcli.FlagDescription, "", "description of proposal") //nolint:staticcheck
cmd.Flags().String(govcli.FlagDeposit, "", "deposit of proposal")

flags.AddTxFlagsToCmd(cmd)
Expand All @@ -198,7 +198,7 @@ func updateBandOracleRequestProposalArgsToContent(
return nil, err
}

description, err := cmd.Flags().GetString(govcli.FlagDescription)
description, err := cmd.Flags().GetString(govcli.FlagDescription) //nolint:staticcheck
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -283,7 +283,7 @@ func deleteBandOracleRequestProposalArgsToContent(
return nil, err
}

description, err := cmd.Flags().GetString(govcli.FlagDescription)
description, err := cmd.Flags().GetString(govcli.FlagDescription) //nolint:staticcheck
if err != nil {
return nil, err
}
Expand Down
31 changes: 17 additions & 14 deletions x/oracle/keeper/band_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
runtime "github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
"github.com/onomyprotocol/reserve/x/oracle/types"
Expand Down Expand Up @@ -250,8 +250,7 @@ func (k Keeper) AddNewSymbolToBandOracleRequest(ctx context.Context, symbol stri
for _, req := range allBandOracleRequests {
if req.OracleScriptId == oracleScriptId {
req.Symbols = append(req.Symbols, symbol)
k.SetBandOracleRequest(ctx, *req)
return nil
return k.SetBandOracleRequest(ctx, *req)
}
}

Expand All @@ -269,10 +268,12 @@ func (k Keeper) AddNewSymbolToBandOracleRequest(ctx context.Context, symbol stri
MinSourceCount: bandOracleRequestParams.MinSourceCount,
}

k.SetBandOracleRequest(ctx, newBandOracleRequest)
err := k.SetBandOracleRequest(ctx, newBandOracleRequest)
if err != nil {
return err
}

k.SetBandLatestRequestID(ctx, requestID)
return nil
return k.SetBandLatestRequestID(ctx, requestID)
}

// GetPrice fetches band ibc prices for a given pair in math.LegacyDec
Expand Down Expand Up @@ -366,14 +367,15 @@ func (k *Keeper) RequestBandOraclePrices(

// Persist the sequence number and OracleRequest CallData. CallData contains list of symbols.
// This is used to map the prices/rates with the symbols upon receiving oracle response from Band IBC.
k.SetBandCallDataRecord(ctx, &types.CalldataRecord{
err = k.SetBandCallDataRecord(ctx, &types.CalldataRecord{
ClientId: clientID,
Calldata: calldata,
})
if err != nil {
return err
}

k.SetBandLatestClientID(ctx, clientID)

return
return k.SetBandLatestClientID(ctx, clientID)
}

func (k *Keeper) ProcessBandOraclePrices(
Expand Down Expand Up @@ -405,9 +407,7 @@ func (k *Keeper) ProcessBandOraclePrices(
k.updateBandPriceStates(ctx, input, output, packet, relayer, clientID)

// Delete the calldata corresponding to the sequence number
k.DeleteBandCallDataRecord(ctx, uint64(clientID))

return nil
return k.DeleteBandCallDataRecord(ctx, uint64(clientID))
}

func (k *Keeper) updateBandPriceStates(
Expand Down Expand Up @@ -508,7 +508,10 @@ func (k *Keeper) CleanUpStaleBandCalldataRecords(ctx context.Context) {
}

for _, id := range k.getPreviousRecordIDs(ctx, earliestToKeepClientID) {
k.DeleteBandCallDataRecord(ctx, id)
err := k.DeleteBandCallDataRecord(ctx, id)
if err != nil {
panic(err)
}
}
}

Expand Down
35 changes: 28 additions & 7 deletions x/oracle/module/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@ func InitGenesis(ctx context.Context, k keeper.Keeper, genState types.GenesisSta
}

for _, bandPriceState := range genState.BandPriceStates {
k.SetBandPriceState(ctx, bandPriceState.Symbol, bandPriceState)
err := k.SetBandPriceState(ctx, bandPriceState.Symbol, bandPriceState)
if err != nil {
panic(err)
}
}

for _, bandOracleRequest := range genState.BandOracleRequests {
k.SetBandOracleRequest(ctx, *bandOracleRequest)
err := k.SetBandOracleRequest(ctx, *bandOracleRequest)
if err != nil {
panic(err)
}
}

k.SetBandParams(ctx, genState.BandParams)
err := k.SetBandParams(ctx, genState.BandParams)
if err != nil {
panic(err)
}

if genState.BandParams.IbcPortId != "" {
k.SetPort(ctx, genState.BandParams.IbcPortId)
Expand All @@ -38,18 +47,30 @@ func InitGenesis(ctx context.Context, k keeper.Keeper, genState types.GenesisSta
}

if genState.BandLatestClientId != 0 {
k.SetBandLatestClientID(ctx, genState.BandLatestClientId)
err = k.SetBandLatestClientID(ctx, genState.BandLatestClientId)
if err != nil {
panic(err)
}
}

for _, record := range genState.CalldataRecords {
k.SetBandCallDataRecord(ctx, record)
err = k.SetBandCallDataRecord(ctx, record)
if err != nil {
panic(err)
}
}

if genState.BandLatestRequestId != 0 {
k.SetBandLatestRequestID(ctx, genState.BandLatestRequestId)
err = k.SetBandLatestRequestID(ctx, genState.BandLatestRequestId)
if err != nil {
panic(err)
}
}

k.SetBandOracleRequestParams(ctx, genState.BandOracleRequestParams)
err = k.SetBandOracleRequestParams(ctx, genState.BandOracleRequestParams)
if err != nil {
panic(err)
}
}

// ExportGenesis returns the module's exported genesis.
Expand Down
Loading

0 comments on commit 4a6b8d1

Please sign in to comment.