Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 45 additions & 48 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,66 @@
version: "2"
run:
tests: true
timeout: 10m
sort-results: true
allow-parallel-runners: true
exclude-dir: testutil/testdata

linters:
disable-all: true
default: none
enable:
- dogsled
- exportloopref
- goconst
- gocritic
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- nolintlint
- staticcheck
- stylecheck
- thelper
- typecheck
- unconvert
- unused

settings:
dogsled:
max-blank-identifiers: 3
nolintlint:
require-explanation: false
require-specific: false
allow-unused: false
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- gosec
text: Use of weak random number generator
- linters:
- staticcheck
text: 'ST1003:'
- linters:
- staticcheck
text: 'ST1016:'
- linters:
- staticcheck
path: migrations
text: 'SA1019:'
paths:
- third_party$
- builtin$
- examples$
issues:
exclude-rules:
- text: "Use of weak random number generator"
linters:
- gosec
- text: "ST1003:"
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: "ST1016:"
linters:
- stylecheck
- path: "migrations"
text: "SA1019:"
linters:
- staticcheck
- text: "leading space"
linters:
- nolintlint

max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
gofumpt:
# Choose whether to use the extra rules.
module-path: github.com/notional-labs/composable-centauri
# Default: false
extra-rules: true
dogsled:
max-blank-identifiers: 3
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
formatters:
enable:
- gofumpt
settings:
extra-rules: true
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func NewComposableApp(

app.mm = module.NewManager(
genutil.NewAppModule(
app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx,
app.AccountKeeper, app.StakingKeeper, app.DeliverTx,
encodingConfig.TxConfig,
),
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
Expand Down Expand Up @@ -692,12 +692,12 @@ func (app *ComposableApp) RegisterAPIRoutes(apiSvr *api.Server, _ config.APIConf

// RegisterTxService implements the Application.RegisterTxService method.
func (app *ComposableApp) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
authtx.RegisterTxService(app.GRPCQueryRouter(), clientCtx, app.Simulate, app.interfaceRegistry)
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *ComposableApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(clientCtx, app.BaseApp.GRPCQueryRouter(), app.interfaceRegistry, app.Query)
tmservice.RegisterTendermintService(clientCtx, app.GRPCQueryRouter(), app.interfaceRegistry, app.Query)
}

// RegisterNodeService registers the node gRPC Query service.
Expand Down
7 changes: 2 additions & 5 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (app *ComposableApp) ExportAppStateAndValidators(
AppState: appState,
Validators: validators,
Height: height,
ConsensusParams: app.BaseApp.GetConsensusParams(ctx),
ConsensusParams: app.GetConsensusParams(ctx),
}, nil
}

Expand All @@ -52,12 +52,9 @@ func (app *ComposableApp) ExportAppStateAndValidators(
//
// in favour of export at a block height
func (app *ComposableApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false
applyAllowedAddrs := len(jailAllowedAddrs) > 0

// check if there is a allowed address list
if len(jailAllowedAddrs) > 0 {
applyAllowedAddrs = true
}

allowedAddrsMap := make(map[string]bool)

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type EmptyAppOptions struct{}
func (EmptyAppOptions) Get(_ string) interface{} { return nil }

func NewContextForApp(app composable.ComposableApp) sdk.Context {
ctx := app.BaseApp.NewContext(false, tmproto.Header{
ctx := app.NewContext(false, tmproto.Header{
ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)),
Height: 1,
})
Expand Down
40 changes: 37 additions & 3 deletions app/ibctesting/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"crypto/sha256"
"fmt"
"math"
"os"
"testing"
"time"
Expand Down Expand Up @@ -184,9 +185,16 @@ func (chain *TestChain) QueryProof(key []byte) ([]byte, clienttypes.Height) {
return chain.QueryProofAtHeight(key, chain.App.LastBlockHeight())
}

// QueryProof performs an abci query with the given key and returns the proto encoded merkle proof
// QueryProofAtHeight performs an abci query with the given key and returns the proto encoded merkle proof
// for the query and the height at which the proof will succeed on a tendermint verifier.
func (chain *TestChain) QueryProofAtHeight(key []byte, height int64) ([]byte, clienttypes.Height) {
if height <= 0 {
panic("height must be positive")
}
if height-1 < 0 {
panic("height-1 must not be negative")
}

res := chain.App.Query(abci.RequestQuery{
Path: fmt.Sprintf("store/%s/key", exported.StoreKey),
Height: height - 1,
Expand All @@ -202,15 +210,31 @@ func (chain *TestChain) QueryProofAtHeight(key []byte, height int64) ([]byte, cl

revision := clienttypes.ParseChainID(chain.ChainID)

// Ensure height is non-negative before converting to uint64
if res.Height < 0 {
panic("negative height not allowed")
}

// proof height + 1 is returned as the proof created corresponds to the height the proof
// was created in the IAVL tree. Tendermint and subsequently the clients that rely on it
// have heights 1 above the IAVL tree. Thus we return proof height + 1
return proof, clienttypes.NewHeight(revision, uint64(res.Height)+1)
if res.Height >= math.MaxInt64 {
panic("height exceeds maximum int64 value")
}
return proof, clienttypes.NewHeight(revision, uint64(res.Height+1))
}

// QueryUpgradeProof performs an abci query with the given key and returns the proto encoded merkle proof
// for the query and the height at which the proof will succeed on a tendermint verifier.
func (chain *TestChain) QueryUpgradeProof(key []byte, height uint64) ([]byte, clienttypes.Height) {
// Ensure height is not zero and can be safely converted to int64
if height == 0 {
panic("height cannot be zero")
}
if height > uint64(math.MaxInt64) {
panic("height exceeds maximum int64 value")
}

res := chain.App.Query(abci.RequestQuery{
Path: "store/upgrade/key",
Height: int64(height - 1),
Expand All @@ -226,6 +250,13 @@ func (chain *TestChain) QueryUpgradeProof(key []byte, height uint64) ([]byte, cl

revision := clienttypes.ParseChainID(chain.ChainID)

// Ensure height is non-negative before converting to uint64
if res.Height < 0 {
panic("negative height not allowed")
}
if res.Height >= math.MaxInt64 {
panic("height exceeds maximum int64 value")
}
// proof height + 1 is returned as the proof created corresponds to the height the proof
// was created in the IAVL tree. Tendermint and subsequently the clients that rely on it
// have heights 1 above the IAVL tree. Thus we return proof height + 1
Expand Down Expand Up @@ -412,7 +443,7 @@ func (chain *TestChain) ConstructUpdateTMClientHeader(counterparty *TestChain, c
return chain.ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty, clientID, clienttypes.ZeroHeight())
}

// ConstructUpdateTMClientHeader will construct a valid 07-tendermint Header to update the
// ConstructUpdateTMClientHeaderWithTrustedHeight will construct a valid 07-tendermint Header to update the
// light client on the source chain.
func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty *TestChain, clientID string, trustedHeight clienttypes.Height) (*ibctmtypes.Header, error) {
header := counterparty.LastHeader
Expand All @@ -434,6 +465,9 @@ func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterpa
// since the last trusted validators for a header at height h
// is the NextValidators at h+1 committed to in header h by
// NextValidatorsHash
if trustedHeight.RevisionHeight >= math.MaxInt64-1 {
return nil, errors.Wrapf(ibctmtypes.ErrInvalidHeaderHeight, "trusted height revision height exceeds maximum int64 value")
}
tmTrustedVals, ok = counterparty.GetValsAtHeight(int64(trustedHeight.RevisionHeight + 1))
if !ok {
return nil, errors.Wrapf(ibctmtypes.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight)
Expand Down
6 changes: 5 additions & 1 deletion app/ibctesting/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ibctesting

import (
"fmt"
"math"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -45,7 +46,10 @@ func (endpoint *Endpoint) QueryProof(key []byte) ([]byte, clienttypes.Height) {
// QueryProofAtHeight queries proof associated with this endpoint using the proof height
// providied
func (endpoint *Endpoint) QueryProofAtHeight(key []byte, height uint64) ([]byte, clienttypes.Height) {
// query proof on the counterparty using the latest height of the IBC client
// Ensure height can be safely converted to int64
if height > uint64(math.MaxInt64) {
panic("height exceeds maximum int64 value")
}
return endpoint.Chain.QueryProofAtHeight(key, int64(height))
}

Expand Down
6 changes: 3 additions & 3 deletions app/ibctesting/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func NewSimApp(
app.mm = module.NewManager(
// SDK app modules
genutil.NewAppModule(
app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx,
app.AccountKeeper, app.StakingKeeper, app.DeliverTx,
encodingConfig.TxConfig,
),
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
Expand Down Expand Up @@ -887,14 +887,14 @@ func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICon

// RegisterTxService implements the Application.RegisterTxService method.
func (app *SimApp) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
authtx.RegisterTxService(app.GRPCQueryRouter(), clientCtx, app.Simulate, app.interfaceRegistry)
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *SimApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(
clientCtx,
app.BaseApp.GRPCQueryRouter(),
app.GRPCQueryRouter(),
app.interfaceRegistry,
app.Query,
)
Expand Down
7 changes: 2 additions & 5 deletions app/ibctesting/simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,17 @@ func (app *SimApp) ExportAppStateAndValidators(
AppState: appState,
Validators: validators,
Height: height,
ConsensusParams: app.BaseApp.GetConsensusParams(ctx),
ConsensusParams: app.GetConsensusParams(ctx),
}, err
}

// prepare for fresh start at zero height
// NOTE zero height genesis is a temporary feature which will be deprecated
// in favour of export at a block height
func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false
applyAllowedAddrs := len(jailAllowedAddrs) > 0

// check if there is a allowed address list
if len(jailAllowedAddrs) > 0 {
applyAllowedAddrs = true
}

allowedAddrsMap := make(map[string]bool)

Expand Down
4 changes: 2 additions & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ type KeeperTestHelper struct {
func (s *KeeperTestHelper) Setup(_ *testing.T) {
t := s.T()
s.App = SetupApp(t)
s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "", Time: time.Now().UTC()})
s.Ctx = s.App.NewContext(false, tmproto.Header{Height: 1, ChainID: "", Time: time.Now().UTC()})
s.QueryHelper = &baseapp.QueryServiceTestHelper{
GRPCQueryRouter: s.App.GRPCQueryRouter(),
Ctx: s.Ctx,
}
s.TestAccs = createRandomAccounts(10)

s.StakingHelper = stakinghelper.NewHelper(s.Suite.T(), s.Ctx, &s.App.StakingKeeper.Keeper)
s.StakingHelper = stakinghelper.NewHelper(s.T(), s.Ctx, &s.App.StakingKeeper.Keeper)
s.StakingHelper.Denom = "stake"
}

Expand Down
Loading