Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Morelint #1611

Merged
merged 8 commits into from
Aug 1, 2022
Merged
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
27 changes: 11 additions & 16 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
name: Lint
# Lint runs golangci-lint over the entire gaia repository
# This workflow is run on every pull request and push to main
# The `golangci` will pass without running if no *.{go, mod, sum} files have been changed.
name: golangci-lint
on:
pull_request:
push:
tags:
- v*
branches:
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: golangci-lint
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
- uses: technote-space/get-diff-action@v6.0.1
id: git_diff
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: actions/checkout@v3
- name: golangci-lint
if: env.GIT_DIFF
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: --out-format=tab
skip-go-installation: true
8 changes: 7 additions & 1 deletion tests/e2e/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (

var (
encodingConfig params.EncodingConfig
cdc codec.Codec
cdc codec.Codec //nolint:unused // this is called during e2e tests
)

func init() {
Expand All @@ -42,12 +42,14 @@ func init() {
cdc = encodingConfig.Codec
}

//nolint:unused // this is called during e2e tests
type chain struct {
dataDir string
id string
validators []*validator
}

//nolint:unused,deadcode // this is called during e2e tests
func newChain() (*chain, error) {
tmpDir, err := ioutil.TempDir("", "gaia-e2e-testnet-")
if err != nil {
Expand All @@ -60,10 +62,12 @@ func newChain() (*chain, error) {
}, nil
}

//nolint:unused // this is called during e2e tests
func (c *chain) configDir() string {
return fmt.Sprintf("%s/%s", c.dataDir, c.id)
}

//nolint:unused // this is called during e2e tests
func (c *chain) createAndInitValidators(count int) error {
for i := 0; i < count; i++ {
node := c.createValidator(i)
Expand All @@ -90,6 +94,7 @@ func (c *chain) createAndInitValidators(count int) error {
return nil
}

//nolint:unused // this is called during e2e tests
func (c *chain) createAndInitValidatorsWithMnemonics(count int, mnemonics []string) error {
for i := 0; i < count; i++ {
// create node
Expand Down Expand Up @@ -117,6 +122,7 @@ func (c *chain) createAndInitValidatorsWithMnemonics(count int, mnemonics []stri
return nil
}

//nolint:unused // this is called during e2e tests
func (c *chain) createValidator(index int) *validator {
return &validator{
chain: c,
Expand Down
13 changes: 9 additions & 4 deletions tests/e2e/e2e_cli_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

//nolint:unused,deadcode // this is called during e2e tests
func queryGaiaTx(endpoint, txHash string) error {
resp, err := http.Get(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", endpoint, txHash))
if err != nil {
Expand All @@ -37,6 +38,7 @@ func queryGaiaTx(endpoint, txHash string) error {
return nil
}

//nolint:unused,deadcode // this is called during e2e tests
func getSpecificBalance(endpoint, addr, denom string) (amt sdk.Coin, err error) {
balances, err := queryGaiaAllBalances(endpoint, addr)
if err != nil {
Expand All @@ -51,6 +53,7 @@ func getSpecificBalance(endpoint, addr, denom string) (amt sdk.Coin, err error)
return amt, nil
}

//nolint:unused // this is called during e2e tests
func queryGaiaAllBalances(endpoint, addr string) (sdk.Coins, error) {
resp, err := http.Get(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", endpoint, addr))
if err != nil {
Expand All @@ -72,14 +75,15 @@ func queryGaiaAllBalances(endpoint, addr string) (sdk.Coins, error) {
return balancesResp.Balances, nil
}

//nolint:unused,deadcode // this is called during e2e tests
func queryGaiaDenomBalance(endpoint, addr, denom string) (sdk.Coin, error) {
var zeroCoin sdk.Coin

path := fmt.Sprintf(
"%s/cosmos/bank/v1beta1/balances/%s/by_denom?denom=%s",
endpoint, addr, denom,
)
resp, err := http.Get(path)
resp, err := http.Get(path) //nolint:gosec // this is used as a part of the e2e suite.
if err != nil {
return zeroCoin, fmt.Errorf("failed to execute HTTP request: %w", err)
}
Expand All @@ -99,11 +103,12 @@ func queryGaiaDenomBalance(endpoint, addr, denom string) (sdk.Coin, error) {
return *balanceResp.Balance, nil
}

func queryGovProposal(endpoint string, proposalId int) (govv1beta1.QueryProposalResponse, error) {
//nolint:unused,deadcode // this is called during e2e tests
func queryGovProposal(endpoint string, proposalID int) (govv1beta1.QueryProposalResponse, error) {
var emptyProp govv1beta1.QueryProposalResponse

path := fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%d", endpoint, proposalId)
resp, err := http.Get(path)
path := fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals/%d", endpoint, proposalID)
resp, err := http.Get(path) //nolint:gosec // this is only used during tests
if err != nil {
return emptyProp, fmt.Errorf("failed to execute HTTP request: %w", err)
}
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
tmtypes "github.com/tendermint/tendermint/types"
)

//nolint:unused // this is called during e2e tests
func getGenDoc(path string) (*tmtypes.GenesisDoc, error) {
serverCtx := server.NewDefaultContext()
config := serverCtx.Config
Expand All @@ -41,6 +42,7 @@ func getGenDoc(path string) (*tmtypes.GenesisDoc, error) {
return doc, nil
}

//nolint:unused,deadcode // this is called during e2e tests
func addGenesisAccount(path, moniker, amountStr string, accAddr sdk.AccAddress) error {
serverCtx := server.NewDefaultContext()
config := serverCtx.Config
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
)

//nolint:unused,deadcode // this is called during e2e tests
func copyFile(src, dst string) (int64, error) {
sourceFileStat, err := os.Stat(src)
if err != nil {
Expand All @@ -33,11 +34,12 @@ func copyFile(src, dst string) (int64, error) {
return nBytes, err
}

//nolint:unused,deadcode // this is called during e2e tests
func writeFile(path string, body []byte) error {
_, err := os.Create(path)
if err != nil {
return err
}

return ioutil.WriteFile(path, body, 0o644)
return ioutil.WriteFile(path, body, 0o644) //nolint:gosec //common cosmos issue, but does not work at 600.
}
3 changes: 3 additions & 0 deletions tests/e2e/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/cosmos/go-bip39"
)

//nolint:unused // this is called during e2e tests
func createMnemonic() (string, error) {
entropySeed, err := bip39.NewEntropy(256)
if err != nil {
Expand All @@ -22,6 +23,7 @@ func createMnemonic() (string, error) {
return mnemonic, nil
}

//nolint:unused,deadcode // this is called during e2e tests
func createMemoryKey() (mnemonic string, info *keyring.Record, err error) {
mnemonic, err = createMnemonic()
if err != nil {
Expand All @@ -36,6 +38,7 @@ func createMemoryKey() (mnemonic string, info *keyring.Record, err error) {
return mnemonic, account, nil
}

//nolint:unused // this is called during e2e tests
func createMemoryKeyFromMnemonic(mnemonic string) (*keyring.Record, error) {
kb, err := keyring.New("testnet", keyring.BackendMemory, "", nil, cdc)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
)

//nolint:unused // this is called during e2e tests
func decodeTx(txBytes []byte) (*sdktx.Tx, error) {
var raw sdktx.TxRaw

Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
gaia "github.com/cosmos/gaia/v8/app"
)

//nolint:unused
type validator struct {
chain *chain
index int
Expand All @@ -39,19 +40,23 @@ type validator struct {
nodeKey tmtypes.NodeKey
}

//nolint:unused // this is called during e2e tests
func (v *validator) instanceName() string {
return fmt.Sprintf("%s%d", v.moniker, v.index)
}

//nolint:unused // this is called during e2e tests
func (v *validator) configDir() string {
return fmt.Sprintf("%s/%s", v.chain.configDir(), v.instanceName())
}

//nolint:unused // this is called during e2e tests
func (v *validator) createConfig() error {
p := path.Join(v.configDir(), "config")
return os.MkdirAll(p, 0o755)
}

//nolint:unused // this is called during e2e tests
func (v *validator) init() error {
if err := v.createConfig(); err != nil {
return err
Expand Down Expand Up @@ -88,6 +93,7 @@ func (v *validator) init() error {
return nil
}

//nolint:unused // this is called during e2e tests
func (v *validator) createNodeKey() error {
serverCtx := server.NewDefaultContext()
config := serverCtx.Config
Expand All @@ -104,6 +110,7 @@ func (v *validator) createNodeKey() error {
return nil
}

//nolint:unused // this is called during e2e tests
func (v *validator) createConsensusKey() error {
serverCtx := server.NewDefaultContext()
config := serverCtx.Config
Expand All @@ -130,6 +137,7 @@ func (v *validator) createConsensusKey() error {
return nil
}

//nolint:unused // this is called during e2e tests
func (v *validator) createKeyFromMnemonic(name, mnemonic string) error {
dir := v.configDir()
kb, err := keyring.New(keyringAppName, keyring.BackendTest, dir, nil, cdc)
Expand Down Expand Up @@ -165,6 +173,7 @@ func (v *validator) createKeyFromMnemonic(name, mnemonic string) error {
return nil
}

//nolint:unused // this is called during e2e tests
func (v *validator) createKey(name string) error {
mnemonic, err := createMnemonic()
if err != nil {
Expand All @@ -174,6 +183,7 @@ func (v *validator) createKey(name string) error {
return v.createKeyFromMnemonic(name, mnemonic)
}

//nolint:unused // this is called during e2e tests
func (v *validator) buildCreateValidatorMsg(amount sdk.Coin) (sdk.Msg, error) {
description := stakingtypes.NewDescription(v.moniker, "", "", "", "")
commissionRates := stakingtypes.CommissionRates{
Expand Down Expand Up @@ -206,6 +216,7 @@ func (v *validator) buildCreateValidatorMsg(amount sdk.Coin) (sdk.Msg, error) {
)
}

//nolint:unused // this is called during e2e tests
func (v *validator) signMsg(msgs ...sdk.Msg) (*sdktx.Tx, error) {
txBuilder := encodingConfig.TxConfig.NewTxBuilder()

Expand Down