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

refactor: fix lint errors from govet #2749

Merged
merged 3 commits into from
Aug 20, 2024
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
2 changes: 1 addition & 1 deletion app/ante/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (ald AuthzLimiterDecorator) AnteHandle(
next sdk.AnteHandler,
) (newCtx sdk.Context, err error) {
if err := ald.checkDisabledMsgs(tx.GetMsgs(), false, 1); err != nil {
return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, err.Error())
return ctx, errorsmod.Wrap(errortypes.ErrUnauthorized, err.Error())
gartnera marked this conversation as resolved.
Show resolved Hide resolved
}
return next(ctx, tx, simulate)
}
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
### Refactor

* [2615](https://github.com/zeta-chain/node/pull/2615) - Refactor cleanup of outbound trackers
* [2749](https://github.com/zeta-chain/node/pull/2749) - fix all lint errors from govet

### Tests

Expand Down
2 changes: 1 addition & 1 deletion cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func start(_ *cobra.Command, _ []string) error {
startLogger.Debug().Msgf("hotkeyPk %s", hotkeyPk.String())
if len(hotkeyPk.Bytes()) != 32 {
errMsg := fmt.Sprintf("key bytes len %d != 32", len(hotkeyPk.Bytes()))
log.Error().Msgf(errMsg)
log.Error().Msg(errMsg)
return errors.New(errMsg)
}
priKey := secp256k1.PrivKey(hotkeyPk.Bytes()[:32])
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetaclientd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ var VersionCmd = &cobra.Command{
}

func Version(_ *cobra.Command, _ []string) error {
fmt.Printf(constant.Version)
fmt.Print(constant.Version)
return nil
}
3 changes: 1 addition & 2 deletions e2e/e2etests/test_message_passing_evm_to_zevm.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package e2etests

import (
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -56,7 +55,7 @@ func TestMessagePassingEVMtoZEVM(r *runner.E2ERunner, args []string) {
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, receipt.TxHash.String(), r.CctxClient, r.Logger, r.CctxTimeout)
utils.RequireCCTXStatus(r, cctx, cctxtypes.CctxStatus_OutboundMined)

r.Logger.Info(fmt.Sprintf("🔄 Cctx mined for contract call chain zevm %s", cctx.Index))
r.Logger.Info("🔄 Cctx mined for contract call chain zevm %s", cctx.Index)

// On finalization the Fungible module calls the onReceive function which in turn calls the onZetaMessage function on the destination contract
receipt, err = r.ZEVMClient.TransactionReceipt(r.Ctx, ethcommon.HexToHash(cctx.GetCurrentOutboundParam().Hash))
Expand Down
13 changes: 6 additions & 7 deletions e2e/e2etests/test_migrate_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package e2etests

import (
"context"
"fmt"
"sort"
"strconv"
"time"
Expand Down Expand Up @@ -146,9 +145,9 @@ func TestMigrateTSS(r *runner.E2ERunner, _ []string) {
btcTSSBalanceNew += utxo.Amount
}

r.Logger.Info(fmt.Sprintf("BTC Balance Old: %f", btcTSSBalanceOld*1e8))
r.Logger.Info(fmt.Sprintf("BTC Balance New: %f", btcTSSBalanceNew*1e8))
r.Logger.Info(fmt.Sprintf("Migrator amount : %s", cctxBTC.GetCurrentOutboundParam().Amount))
r.Logger.Info("BTC Balance Old: %f", btcTSSBalanceOld*1e8)
r.Logger.Info("BTC Balance New: %f", btcTSSBalanceNew*1e8)
r.Logger.Info("Migrator amount : %s", cctxBTC.GetCurrentOutboundParam().Amount)

// btcTSSBalanceNew should be less than btcTSSBalanceOld as there is some loss of funds during migration
// #nosec G701 e2eTest - always in range
Expand All @@ -165,9 +164,9 @@ func TestMigrateTSS(r *runner.E2ERunner, _ []string) {
ethTSSBalanceNew, err := r.EVMClient.BalanceAt(context.Background(), r.TSSAddress, nil)
require.NoError(r, err)

r.Logger.Info(fmt.Sprintf("TSS Balance Old: %s", ethTSSBalanceOld.String()))
r.Logger.Info(fmt.Sprintf("TSS Balance New: %s", ethTSSBalanceNew.String()))
r.Logger.Info(fmt.Sprintf("Migrator amount : %s", cctxETH.GetCurrentOutboundParam().Amount.String()))
r.Logger.Info("TSS Balance Old: %s", ethTSSBalanceOld.String())
r.Logger.Info("TSS Balance New: %s", ethTSSBalanceNew.String())
r.Logger.Info("Migrator amount : %s", cctxETH.GetCurrentOutboundParam().Amount.String())

// ethTSSBalanceNew should be less than ethTSSBalanceOld as there is some loss of funds during migration
require.Equal(r, ethTSSBalanceNew.String(), cctxETH.GetCurrentOutboundParam().Amount.String())
Expand Down
2 changes: 1 addition & 1 deletion e2e/runner/accounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (r *E2ERunner) checkZetaTSSBalance() error {
}
zetaSupply, _ := big.NewInt(0).SetString(result.Amount.Amount, 10)
if zetaLocked.Cmp(zetaSupply) < 0 {
r.Logger.Info(fmt.Sprintf("ZETA: TSS balance (%d) < ZRC20 TotalSupply (%d)", zetaLocked, zetaSupply))
r.Logger.Info("ZETA: TSS balance (%d) < ZRC20 TotalSupply (%d)", zetaLocked, zetaSupply)
} else {
r.Logger.Info("ZETA: TSS balance (%d) >= ZRC20 TotalSupply (%d)", zetaLocked, zetaSupply)
}
Expand Down
14 changes: 7 additions & 7 deletions e2e/runner/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (l *Logger) Print(message string, args ...interface{}) {

text := fmt.Sprintf(message, args...)
// #nosec G104 - we are not using user input
l.logger.Printf(l.getPrefixWithPadding() + loggerSeparator + text + "\n")
l.logger.Print(l.getPrefixWithPadding() + loggerSeparator + text + "\n")
}

// PrintNoPrefix prints a message to the logger without the prefix
Expand All @@ -67,7 +67,7 @@ func (l *Logger) PrintNoPrefix(message string, args ...interface{}) {

text := fmt.Sprintf(message, args...)
// #nosec G104 - we are not using user input
l.logger.Printf(text + "\n")
_, _ = l.logger.Print(text + "\n")
}

// Info prints a message to the logger if verbose is true
Expand All @@ -78,7 +78,7 @@ func (l *Logger) Info(message string, args ...interface{}) {
if l.verbose {
text := fmt.Sprintf(message, args...)
// #nosec G104 - we are not using user input
l.logger.Printf(l.getPrefixWithPadding() + loggerSeparator + "[INFO]" + text + "\n")
_, _ = l.logger.Print(l.getPrefixWithPadding() + loggerSeparator + "[INFO]" + text + "\n")
}
}

Expand All @@ -90,11 +90,11 @@ func (l *Logger) InfoLoud(message string, args ...interface{}) {
if l.verbose {
text := fmt.Sprintf(message, args...)
// #nosec G104 - we are not using user input
l.logger.Printf(l.getPrefixWithPadding() + loggerSeparator + "[INFO] =======================================")
l.logger.Print(l.getPrefixWithPadding() + loggerSeparator + "[INFO] =======================================")
// #nosec G104 - we are not using user input
l.logger.Printf(l.getPrefixWithPadding() + loggerSeparator + "[INFO]" + text + "\n")
l.logger.Print(l.getPrefixWithPadding() + loggerSeparator + "[INFO]" + text + "\n")
// #nosec G104 - we are not using user input
l.logger.Printf(l.getPrefixWithPadding() + loggerSeparator + "[INFO] =======================================")
l.logger.Print(l.getPrefixWithPadding() + loggerSeparator + "[INFO] =======================================")
}
}

Expand All @@ -105,7 +105,7 @@ func (l *Logger) Error(message string, args ...interface{}) {

text := fmt.Sprintf(message, args...)
// #nosec G104 - we are not using user input
l.logger.Printf(l.getPrefixWithPadding() + loggerSeparator + "[ERROR]" + text + "\n")
l.logger.Print(l.getPrefixWithPadding() + loggerSeparator + "[ERROR]" + text + "\n")
}

// CCTX prints a CCTX
Expand Down
2 changes: 1 addition & 1 deletion e2e/runner/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r *E2ERunner) PrintTestReports(tr TestReports) {
if err != nil {
r.Logger.Print("Error rendering test report: %s", err)
}
r.Logger.PrintNoPrefix(table)
r.Logger.PrintNoPrefix(table, "")
}

// NetworkReport is a struct that contains the report for the network used after running e2e tests
Expand Down
3 changes: 2 additions & 1 deletion pkg/chains/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/hex"
"fmt"

"cosmossdk.io/errors"
"github.com/btcsuite/btcd/chaincfg/chainhash"
ethcommon "github.com/ethereum/go-ethereum/common"
)
Expand Down Expand Up @@ -39,7 +40,7 @@ func ParseAddressAndData(message string) (ethcommon.Address, []byte, error) {

data, err := hex.DecodeString(message)
if err != nil {
return ethcommon.Address{}, nil, fmt.Errorf("message should be a hex encoded string: " + err.Error())
return ethcommon.Address{}, nil, errors.Wrap(err, "message should be a hex encoded string")
}

if len(data) < 20 {
Expand Down
6 changes: 3 additions & 3 deletions x/crosschain/keeper/msg_server_add_inbound_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (k msgServer) AddInboundTracker(
func verifyProofAndInboundBody(ctx sdk.Context, k msgServer, msg *types.MsgAddInboundTracker) error {
txBytes, err := k.GetLightclientKeeper().VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex)
if err != nil {
return types.ErrProofVerificationFail.Wrapf(err.Error())
return types.ErrProofVerificationFail.Wrap(err.Error())
}

// get chain params and tss addresses to verify the inTx body
Expand All @@ -72,14 +72,14 @@ func verifyProofAndInboundBody(ctx sdk.Context, k msgServer, msg *types.MsgAddIn
BitcoinChainId: msg.ChainId,
})
if err != nil {
return observertypes.ErrTssNotFound.Wrapf(err.Error())
return observertypes.ErrTssNotFound.Wrap(err.Error())
}
if tss == nil {
return observertypes.ErrTssNotFound.Wrapf("tss address nil")
}

if err := types.VerifyInboundBody(*msg, txBytes, *chainParams, *tss); err != nil {
return types.ErrTxBodyVerificationFail.Wrapf(err.Error())
return types.ErrTxBodyVerificationFail.Wrap(err.Error())
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions x/crosschain/keeper/msg_server_add_outbound_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (k msgServer) AddOutboundTracker(
func verifyProofAndOutboundBody(ctx sdk.Context, k msgServer, msg *types.MsgAddOutboundTracker) error {
txBytes, err := k.lightclientKeeper.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex)
if err != nil {
return types.ErrProofVerificationFail.Wrapf(err.Error())
return types.ErrProofVerificationFail.Wrap(err.Error())
}

// get tss address
Expand All @@ -145,14 +145,14 @@ func verifyProofAndOutboundBody(ctx sdk.Context, k msgServer, msg *types.MsgAddO
BitcoinChainId: bitcoinChainID,
})
if err != nil {
return observertypes.ErrTssNotFound.Wrapf(err.Error())
return observertypes.ErrTssNotFound.Wrap(err.Error())
}
if tss == nil {
return observertypes.ErrTssNotFound.Wrapf("tss address nil")
}

if err := types.VerifyOutboundBody(*msg, txBytes, *tss); err != nil {
return types.ErrTxBodyVerificationFail.Wrapf(err.Error())
return types.ErrTxBodyVerificationFail.Wrap(err.Error())
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/types/message_update_rate_limiter_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (msg *MsgUpdateRateLimiterFlags) ValidateBasic() error {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
if err := msg.RateLimiterFlags.Validate(); err != nil {
return errorsmod.Wrapf(ErrInvalidRateLimiterFlags, err.Error())
return errorsmod.Wrap(ErrInvalidRateLimiterFlags, err.Error())
}
return nil
}
2 changes: 1 addition & 1 deletion x/emissions/keeper/msg_server_update_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (k msgServer) UpdateParams(
ctx := sdk.UnwrapSDKContext(goCtx)
err := k.SetParams(ctx, msg.Params)
if err != nil {
return nil, errors.Wrapf(types.ErrUnableToSetParams, err.Error())
return nil, errors.Wrap(types.ErrUnableToSetParams, err.Error())
}

return &types.MsgUpdateParamsResponse{}, nil
Expand Down
18 changes: 9 additions & 9 deletions x/fungible/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@
) (*big.Int, error) {
zrc4ABI, err := zrc20.ZRC20MetaData.GetAbi()
if err != nil {
return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, err.Error())
return nil, cosmoserrors.Wrap(types.ErrABIUnpack, err.Error())

Check warning on line 576 in x/fungible/keeper/evm.go

View check run for this annotation

Codecov / codecov/patch

x/fungible/keeper/evm.go#L576

Added line #L576 was not covered by tests
gartnera marked this conversation as resolved.
Show resolved Hide resolved
}
res, err := k.CallEVM(ctx, *zrc4ABI, types.ModuleAddressEVM, contract, BigIntZero, nil, false, false, "balanceOf",
account)
Expand All @@ -583,7 +583,7 @@

unpacked, err := zrc4ABI.Unpack("balanceOf", res.Ret)
if err != nil || len(unpacked) == 0 {
return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, err.Error())
return nil, cosmoserrors.Wrap(types.ErrABIUnpack, err.Error())
}

balance, ok := unpacked[0].(*big.Int)
Expand All @@ -601,7 +601,7 @@
) (*big.Int, error) {
abi, err := zrc20.ZRC20MetaData.GetAbi()
if err != nil {
return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, err.Error())
return nil, cosmoserrors.Wrap(types.ErrABIUnpack, err.Error())

Check warning on line 604 in x/fungible/keeper/evm.go

View check run for this annotation

Codecov / codecov/patch

x/fungible/keeper/evm.go#L604

Added line #L604 was not covered by tests
}
res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, contract, BigIntZero, nil, false, false, "totalSupply")
if err != nil {
Expand All @@ -610,12 +610,12 @@

unpacked, err := abi.Unpack("totalSupply", res.Ret)
if err != nil || len(unpacked) == 0 {
return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, err.Error())
return nil, cosmoserrors.Wrap(types.ErrABIUnpack, err.Error())
}

totalSupply, ok := unpacked[0].(*big.Int)
if !ok {
return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, "failed to unpack total supply")
return nil, cosmoserrors.Wrap(types.ErrABIUnpack, "failed to unpack total supply")

Check warning on line 618 in x/fungible/keeper/evm.go

View check run for this annotation

Codecov / codecov/patch

x/fungible/keeper/evm.go#L618

Added line #L618 was not covered by tests
}

return totalSupply, nil
Expand All @@ -628,7 +628,7 @@
) (*big.Int, error) {
abi, err := zrc20.ZRC20MetaData.GetAbi()
if err != nil {
return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, err.Error())
return nil, cosmoserrors.Wrap(types.ErrABIUnpack, err.Error())

Check warning on line 631 in x/fungible/keeper/evm.go

View check run for this annotation

Codecov / codecov/patch

x/fungible/keeper/evm.go#L631

Added line #L631 was not covered by tests
}
res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, contract, BigIntZero, nil, false, false, "CHAIN_ID")
if err != nil {
Expand All @@ -637,12 +637,12 @@

unpacked, err := abi.Unpack("CHAIN_ID", res.Ret)
if err != nil || len(unpacked) == 0 {
return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, err.Error())
return nil, cosmoserrors.Wrap(types.ErrABIUnpack, err.Error())
}

chainID, ok := unpacked[0].(*big.Int)
if !ok {
return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, "failed to unpack chain ID")
return nil, cosmoserrors.Wrap(types.ErrABIUnpack, "failed to unpack chain ID")

Check warning on line 645 in x/fungible/keeper/evm.go

View check run for this annotation

Codecov / codecov/patch

x/fungible/keeper/evm.go#L645

Added line #L645 was not covered by tests
}

return chainID, nil
Expand Down Expand Up @@ -684,7 +684,7 @@
if ok {
errMes = fmt.Sprintf("%s, reason: %v", errMes, revertErr.ErrorData())
}
return resp, cosmoserrors.Wrapf(err, errMes)
return resp, cosmoserrors.Wrap(err, errMes)
}
return resp, nil
}
Expand Down
6 changes: 3 additions & 3 deletions x/fungible/keeper/gas_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (k Keeper) SetGasPrice(ctx sdk.Context, chainid *big.Int, gasPrice *big.Int
gasPrice,
)
if err != nil {
return 0, cosmoserrors.Wrapf(types.ErrContractCall, err.Error())
return 0, cosmoserrors.Wrap(types.ErrContractCall, err.Error())
}
if res.Failed() {
return res.GasUsed, cosmoserrors.Wrapf(types.ErrContractCall, "setGasPrice tx failed")
Expand Down Expand Up @@ -78,7 +78,7 @@ func (k Keeper) SetGasCoin(ctx sdk.Context, chainid *big.Int, address ethcommon.
address,
)
if err != nil {
return cosmoserrors.Wrapf(types.ErrContractCall, err.Error())
return cosmoserrors.Wrap(types.ErrContractCall, err.Error())
}
if res.Failed() {
return cosmoserrors.Wrapf(types.ErrContractCall, "setGasCoinZRC20 tx failed")
Expand Down Expand Up @@ -114,7 +114,7 @@ func (k Keeper) SetGasZetaPool(ctx sdk.Context, chainid *big.Int, pool ethcommon
pool,
)
if err != nil {
return cosmoserrors.Wrapf(types.ErrContractCall, err.Error())
return cosmoserrors.Wrap(types.ErrContractCall, err.Error())
}
if res.Failed() {
return cosmoserrors.Wrapf(types.ErrContractCall, "setGasZetaPool tx failed")
Expand Down
2 changes: 1 addition & 1 deletion x/observer/types/message_update_chain_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (msg *MsgUpdateChainParams) ValidateBasic() error {
}

if err := ValidateChainParams(msg.ChainParams); err != nil {
return cosmoserrors.Wrapf(ErrInvalidChainParams, err.Error())
return cosmoserrors.Wrap(ErrInvalidChainParams, err.Error())
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion x/observer/types/message_vote_block_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (msg *MsgVoteBlockHeader) GetSignBytes() []byte {
func (msg *MsgVoteBlockHeader) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, err.Error())
return cosmoserrors.Wrap(sdkerrors.ErrInvalidAddress, err.Error())
}

if len(msg.BlockHash) != 32 {
Expand Down
Loading