Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Jan 13, 2025
1 parent e2651ab commit c06b2fe
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 53 deletions.
2 changes: 1 addition & 1 deletion test/e2e/configurer/chain/commands_btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (n *NodeConfig) CreateBTCDelegation(
// broadcast stuff
cmd = append(cmd, "-b=sync", "--yes")
}
//cmd = append(cmd, fmt.Sprintf("--chain-id=%s", n.chainId), "-b=sync", "--yes", "--keyring-backend=test", "--log_format=json", "--home=/home/babylon/babylondata")
// cmd = append(cmd, fmt.Sprintf("--chain-id=%s", n.chainId), "-b=sync", "--yes", "--keyring-backend=test", "--log_format=json", "--home=/home/babylon/babylondata")
cmd = append(cmd, fmt.Sprintf("--chain-id=%s", n.chainId), "-b=sync", "--yes")
outBuff, _, err := n.containerManager.ExecCmd(n.t, n.Name, append(cmd, overallFlags...), "")

Expand Down
9 changes: 9 additions & 0 deletions wasmbinding/test/custom_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,29 +199,34 @@ func TestQueryNonExistingHeader(t *testing.T) {
require.Nil(t, resp1.HeaderInfo)
}

//nolint:unused
func setupAppWithContext(t *testing.T) (*app.BabylonApp, sdk.Context) {
return setupAppWithContextAndCustomHeight(t, 1)
}

//nolint:unused
func setupAppWithContextAndCustomHeight(t *testing.T, height int64) (*app.BabylonApp, sdk.Context) {
babylonApp := app.Setup(t, false)
ctx := babylonApp.BaseApp.NewContext(false).
WithBlockHeader(cmtproto.Header{Height: height, Time: time.Now().UTC()})
return babylonApp, ctx
}

//nolint:unused
func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) {
key := ed25519.GenPrivKey()
pub := key.PubKey()
addr := sdk.AccAddress(pub.Address())
return key, pub, addr
}

//nolint:unused
func randomAccountAddress() sdk.AccAddress {
_, _, addr := keyPubAddr()
return addr
}

//nolint:unused
func mintCoinsTo(
bankKeeper bankkeeper.Keeper,
ctx sdk.Context,
Expand All @@ -234,6 +239,7 @@ func mintCoinsTo(
return bankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, amounts)
}

//nolint:unused
func fundAccount(
t *testing.T,
ctx sdk.Context,
Expand All @@ -245,6 +251,7 @@ func fundAccount(
require.NoError(t, err)
}

//nolint:unused
func storeTestCodeCode(
t *testing.T,
ctx sdk.Context,
Expand All @@ -261,6 +268,7 @@ func storeTestCodeCode(
return id, checksum
}

//nolint:unused
func instantiateExampleContract(
t *testing.T,
ctx sdk.Context,
Expand All @@ -275,6 +283,7 @@ func instantiateExampleContract(
return addr
}

//nolint:unused
func deployTestContract(
t *testing.T,
ctx sdk.Context,
Expand Down
4 changes: 2 additions & 2 deletions wasmbinding/test/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func FundAccount(
t *testing.T,
ctx sdk.Context,
bbn *app.BabylonApp,
acc sdk.AccAddress) {

acc sdk.AccAddress,
) {
err := MintCoinsTo(bbn.BankKeeper, ctx, acc, sdk.NewCoins(
sdk.NewCoin("ubbn", math.NewInt(10000000000)),
))
Expand Down
7 changes: 4 additions & 3 deletions x/btcstaking/keeper/btc_delegators.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ func (k Keeper) getBTCDelegatorDelegations(ctx context.Context, fpBTCPK *bbn.BIP
func (k Keeper) GetFPBTCDelegations(ctx context.Context, fpBTCPK *bbn.BIP340PubKey) ([]*types.BTCDelegation, error) {
var store prefix.Store
// Determine which store to use based on the finality provider type
if k.HasFinalityProvider(ctx, *fpBTCPK) {
switch {
case k.HasFinalityProvider(ctx, *fpBTCPK):
// Babylon finality provider
store = k.btcDelegatorFpStore(ctx, fpBTCPK)
} else if k.BscKeeper.HasConsumerFinalityProvider(ctx, fpBTCPK) {
case k.BscKeeper.HasConsumerFinalityProvider(ctx, fpBTCPK):
// Consumer finality provider
store = k.btcConsumerDelegatorStore(ctx, fpBTCPK)
} else {
default:
// if not found in either store, return error
return nil, types.ErrFpNotFound
}
Expand Down
10 changes: 6 additions & 4 deletions x/btcstaking/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ func (k Keeper) FinalityProviderDelegations(ctx context.Context, req *types.Quer
btcDels []*types.BTCDelegatorDelegationsResponse
pageRes *query.PageResponse
)

if k.HasFinalityProvider(ctx, *fpPK) {
switch {
case k.HasFinalityProvider(ctx, *fpPK):
// this is a Babylon finality provider
btcDelStore := k.btcDelegatorFpStore(sdkCtx, fpPK)
pageRes, err = query.Paginate(btcDelStore, req.Pagination, func(key, value []byte) error {
Expand Down Expand Up @@ -185,13 +185,15 @@ func (k Keeper) FinalityProviderDelegations(ctx context.Context, req *types.Quer
if err != nil {
return nil, err
}
} else if k.BscKeeper.HasConsumerFinalityProvider(ctx, fpPK) {

case k.BscKeeper.HasConsumerFinalityProvider(ctx, fpPK):
// this is a consumer finality provider
btcDels, pageRes, err = k.GetBTCConsumerDelegatorDelegationsResponses(sdkCtx, fpPK, req.Pagination, currentWValue, btcHeight, covenantQuorum)
if err != nil {
return nil, err
}
} else {

default:
// the given finality provider is not found
return nil, types.ErrFpNotFound
}
Expand Down
2 changes: 1 addition & 1 deletion x/finality/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ func FuzzEquivocationEvidence(f *testing.F) {
require.ErrorContains(t, err, "empty PubRand")

// test valid case
blockHeight := activationHeight + uint64(datagen.RandomInt(r, 100))
blockHeight := activationHeight + datagen.RandomInt(r, 100)

// generate proper pub rand data
startHeight := blockHeight
Expand Down
24 changes: 12 additions & 12 deletions x/zoneconcierge/keeper/canonical_chain_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/stretchr/testify/require"
)

const consumerID = "test-consumerID"

func FuzzCanonicalChainIndexer(f *testing.F) {
datagen.AddRandomSeedsToFuzzer(f, 10)

Expand All @@ -18,27 +20,26 @@ func FuzzCanonicalChainIndexer(f *testing.F) {
babylonApp := app.Setup(t, false)
zcKeeper := babylonApp.ZoneConciergeKeeper
ctx := babylonApp.NewContext(false)
czConsumerId := "test-consumerid"

// simulate a random number of blocks
numHeaders := datagen.RandomInt(r, 100) + 1
headers := SimulateNewHeaders(ctx, r, &zcKeeper, czConsumerId, 0, numHeaders)
headers := SimulateNewHeaders(ctx, r, &zcKeeper, consumerID, 0, numHeaders)

// check if the canonical chain index is correct or not
for i := uint64(0); i < numHeaders; i++ {
header, err := zcKeeper.GetHeader(ctx, czConsumerId, i)
header, err := zcKeeper.GetHeader(ctx, consumerID, i)
require.NoError(t, err)
require.NotNil(t, header)
require.Equal(t, czConsumerId, header.ConsumerId)
require.Equal(t, consumerID, header.ConsumerId)
require.Equal(t, i, header.Height)
require.Equal(t, headers[i].Header.AppHash, header.Hash)
}

// check if the chain info is updated or not
chainInfo, err := zcKeeper.GetChainInfo(ctx, czConsumerId)
chainInfo, err := zcKeeper.GetChainInfo(ctx, consumerID)
require.NoError(t, err)
require.NotNil(t, chainInfo.LatestHeader)
require.Equal(t, czConsumerId, chainInfo.LatestHeader.ConsumerId)
require.Equal(t, consumerID, chainInfo.LatestHeader.ConsumerId)
require.Equal(t, numHeaders-1, chainInfo.LatestHeader.Height)
require.Equal(t, headers[numHeaders-1].Header.AppHash, chainInfo.LatestHeader.Hash)
})
Expand All @@ -53,17 +54,16 @@ func FuzzFindClosestHeader(f *testing.F) {
babylonApp := app.Setup(t, false)
zcKeeper := babylonApp.ZoneConciergeKeeper
ctx := babylonApp.NewContext(false)
czConsumerId := "test-consumerid"

// no header at the moment, FindClosestHeader invocation should give error
_, err := zcKeeper.FindClosestHeader(ctx, czConsumerId, 100)
_, err := zcKeeper.FindClosestHeader(ctx, consumerID, 100)
require.Error(t, err)

// simulate a random number of blocks
numHeaders := datagen.RandomInt(r, 100) + 1
headers := SimulateNewHeaders(ctx, r, &zcKeeper, czConsumerId, 0, numHeaders)
headers := SimulateNewHeaders(ctx, r, &zcKeeper, consumerID, 0, numHeaders)

header, err := zcKeeper.FindClosestHeader(ctx, czConsumerId, numHeaders)
header, err := zcKeeper.FindClosestHeader(ctx, consumerID, numHeaders)
require.NoError(t, err)
require.Equal(t, headers[len(headers)-1].Header.AppHash, header.Hash)

Expand All @@ -72,12 +72,12 @@ func FuzzFindClosestHeader(f *testing.F) {

// simulate a random number of blocks
// where the new batch of headers has a gap with the previous batch
SimulateNewHeaders(ctx, r, &zcKeeper, czConsumerId, numHeaders+gap+1, numHeaders)
SimulateNewHeaders(ctx, r, &zcKeeper, consumerID, numHeaders+gap+1, numHeaders)

// get a random height that is in this gap
randomHeightInGap := datagen.RandomInt(r, int(gap+1)) + numHeaders
// find the closest header with the given randomHeightInGap
header, err = zcKeeper.FindClosestHeader(ctx, czConsumerId, randomHeightInGap)
header, err = zcKeeper.FindClosestHeader(ctx, consumerID, randomHeightInGap)
require.NoError(t, err)
// the header should be the same as the last header in the last batch
require.Equal(t, headers[len(headers)-1].Header.AppHash, header.Hash)
Expand Down
9 changes: 5 additions & 4 deletions x/zoneconcierge/keeper/chain_info_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,19 @@ func (k Keeper) tryToUpdateLatestForkHeader(ctx context.Context, consumerId stri
return errorsmod.Wrapf(types.ErrChainInfoNotFound, "cannot insert fork header when chain info is not initialized")
}

if len(chainInfo.LatestForks.Headers) == 0 {
switch {
case len(chainInfo.LatestForks.Headers) == 0:
// no fork at the moment, add this fork header as the latest one
chainInfo.LatestForks.Headers = append(chainInfo.LatestForks.Headers, header)
} else if chainInfo.LatestForks.Headers[0].Height == header.Height {
case chainInfo.LatestForks.Headers[0].Height == header.Height:
// there exists fork headers at the same height, add this fork header to the set of latest fork headers
chainInfo.LatestForks.Headers = append(chainInfo.LatestForks.Headers, header)
} else if chainInfo.LatestForks.Headers[0].Height < header.Height {
case chainInfo.LatestForks.Headers[0].Height < header.Height:
// this fork header is newer than the previous one, replace the old fork headers with this fork header
chainInfo.LatestForks = &types.Forks{
Headers: []*types.IndexedHeader{header},
}
} else {
default:
// this fork header is older than the current latest fork, don't record this fork header in chain info
return nil
}
Expand Down
2 changes: 0 additions & 2 deletions x/zoneconcierge/keeper/epoch_chain_info_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func FuzzEpochChainInfoIndexer(f *testing.F) {
babylonApp := app.Setup(t, false)
zcKeeper := babylonApp.ZoneConciergeKeeper
ctx := babylonApp.NewContext(false)
consumerID := "test-consumerid"

hooks := zcKeeper.Hooks()

Expand Down Expand Up @@ -57,7 +56,6 @@ func FuzzGetEpochHeaders(f *testing.F) {
babylonApp := app.Setup(t, false)
zcKeeper := babylonApp.ZoneConciergeKeeper
ctx := babylonApp.NewContext(false)
consumerID := "test-consumerid"

hooks := zcKeeper.Hooks()

Expand Down
1 change: 0 additions & 1 deletion x/zoneconcierge/keeper/fork_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func FuzzForkIndexer(f *testing.F) {
babylonApp := app.Setup(t, false)
zcKeeper := babylonApp.ZoneConciergeKeeper
ctx := babylonApp.NewContext(false)
consumerID := "test-consumerid"

// invoke the hook a random number of times to simulate a random number of blocks
numHeaders := datagen.RandomInt(r, 100) + 1
Expand Down
4 changes: 0 additions & 4 deletions x/zoneconcierge/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func FuzzHeader(f *testing.F) {
babylonApp := app.Setup(t, false)
zcKeeper := babylonApp.ZoneConciergeKeeper
ctx := babylonApp.NewContext(false)
consumerID := "test-consumerid"

// invoke the hook a random number of times to simulate a random number of blocks
numHeaders := datagen.RandomInt(r, 100) + 2
Expand Down Expand Up @@ -214,7 +213,6 @@ func FuzzEpochChainsInfo(f *testing.F) {

actualHeight := epochToChainInfo[epochNum][info.ConsumerId].headerStartHeight + (epochToChainInfo[epochNum][info.ConsumerId].numHeaders - 1)
require.Equal(t, actualHeight, info.LatestHeader.Height)

}
}

Expand Down Expand Up @@ -253,7 +251,6 @@ func FuzzListHeaders(f *testing.F) {
babylonApp := app.Setup(t, false)
zcKeeper := babylonApp.ZoneConciergeKeeper
ctx := babylonApp.NewContext(false)
consumerID := "test-consumerid"

// invoke the hook a random number of times to simulate a random number of blocks
numHeaders := datagen.RandomInt(r, 100) + 1
Expand Down Expand Up @@ -287,7 +284,6 @@ func FuzzListEpochHeaders(f *testing.F) {
zcKeeper := babylonApp.ZoneConciergeKeeper
epochingKeeper := babylonApp.EpochingKeeper
ctx := babylonApp.NewContext(false)
consumerID := "test-consumerid"

hooks := zcKeeper.Hooks()

Expand Down
2 changes: 1 addition & 1 deletion x/zoneconcierge/keeper/ibc_packet_btc_timestamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func genRandomChain(
ctx context.Context,
initialHeight uint32,
chainLength uint32,
) *datagen.BTCHeaderPartialChain {
) *datagen.BTCHeaderPartialChain { //nolint:unparam // randomChain is used for test setup
initHeader := k.GetHeaderByHeight(ctx, initialHeight)
randomChain := datagen.NewBTCHeaderChainFromParentInfo(
r,
Expand Down
5 changes: 3 additions & 2 deletions x/zoneconcierge/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package zoneconcierge

import (
"context"
"cosmossdk.io/core/appmodule"
"encoding/json"
"fmt"

"cosmossdk.io/core/appmodule"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -74,7 +75,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck // either we propogate the error up the stack, or don't check here.
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck // either we propagate the error up the stack, or don't check here.
}

// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module
Expand Down
21 changes: 12 additions & 9 deletions x/zoneconcierge/types/btc_timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ func VerifyValSet(epoch *epochingtypes.Epoch, valSet *checkpointingtypes.Validat
// - The validator set is committed to the sealer_app_hash of the sealed epoch
func VerifyEpochSealed(epoch *epochingtypes.Epoch, rawCkpt *checkpointingtypes.RawCheckpoint, proof *ProofEpochSealed) error {
// nil check
if epoch == nil {
switch {
case epoch == nil:
return fmt.Errorf("epoch is nil")
} else if rawCkpt == nil {
case rawCkpt == nil:
return fmt.Errorf("rawCkpt is nil")
} else if proof == nil {
case proof == nil:
return fmt.Errorf("proof is nil")
}

Expand Down Expand Up @@ -151,11 +152,12 @@ func VerifyEpochSealed(epoch *epochingtypes.Epoch, rawCkpt *checkpointingtypes.R

func VerifyCZHeaderInEpoch(header *IndexedHeader, epoch *epochingtypes.Epoch, proof *cmtcrypto.ProofOps) error {
// nil check
if header == nil {
switch {
case header == nil:
return fmt.Errorf("header is nil")
} else if epoch == nil {
case epoch == nil:
return fmt.Errorf("epoch is nil")
} else if proof == nil {
case proof == nil:
return fmt.Errorf("proof is nil")
}

Expand Down Expand Up @@ -194,11 +196,12 @@ func VerifyCZHeaderInEpoch(header *IndexedHeader, epoch *epochingtypes.Epoch, pr
// - the raw ckpt decoded from txsInfo is same as the expected rawCkpt
func VerifyEpochSubmitted(rawCkpt *checkpointingtypes.RawCheckpoint, txsInfo []*btcctypes.TransactionInfo, btcHeaders []*wire.BlockHeader, powLimit *big.Int, babylonTag txformat.BabylonTag) error {
// basic sanity check
if rawCkpt == nil {
switch {
case rawCkpt == nil:
return fmt.Errorf("rawCkpt is nil")
} else if len(txsInfo) != txformat.NumberOfParts {
case len(txsInfo) != txformat.NumberOfParts:
return fmt.Errorf("txsInfo contains %d parts rather than %d", len(txsInfo), txformat.NumberOfParts)
} else if len(btcHeaders) != txformat.NumberOfParts {
case len(btcHeaders) != txformat.NumberOfParts:
return fmt.Errorf("btcHeaders contains %d parts rather than %d", len(btcHeaders), txformat.NumberOfParts)
}

Expand Down
Loading

0 comments on commit c06b2fe

Please sign in to comment.