From ee139aa3749c98cdb5436cfa3232d16da96680e5 Mon Sep 17 00:00:00 2001 From: dan13ram Date: Mon, 24 Jun 2024 20:41:34 +0530 Subject: [PATCH] fixed lint issues --- .github/workflows/test.yml | 4 +++- Makefile | 3 +++ config/env_test.go | 1 + cosmos/monitor.go | 1 + cosmos/signer.go | 27 ++++++++++++++------------- db/database.go | 1 + db/lock_test.go | 2 -- ethereum/monitor.go | 5 ++--- ethereum/relayer.go | 1 + ethereum/signer.go | 1 + scripts/generate_keys/main.go | 4 ++++ 11 files changed, 31 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 361b933..a977cde 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,7 +48,9 @@ jobs: fi - name: Run Static Code Analysis - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest && golangci-lint run + uses: golangci/golangci-lint-action@v6 + with: + version: v1.59 - name: Run Unit Tests run: bash coverage.sh diff --git a/Makefile b/Makefile index 14a4f2a..269b0b2 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,9 @@ clean_tmp_data :; if [ -d "/tmp/data" ]; then sudo rm -rf /tmp/data; fi .PHONY: install install :; go mod download && go mod verify +.PHONY: lint +lint :; golangci-lint run + .PHONY: test test :; go test -v ./... diff --git a/config/env_test.go b/config/env_test.go index d00db5d..fec6acb 100644 --- a/config/env_test.go +++ b/config/env_test.go @@ -155,6 +155,7 @@ NUM_ETHEREUM_NETWORKS=2 defer os.Remove(".test.env") assert.Panics(t, func() { + //nolint:errcheck loadConfigFromEnv(".test.env") }) diff --git a/cosmos/monitor.go b/cosmos/monitor.go index 72c933d..88a251f 100644 --- a/cosmos/monitor.go +++ b/cosmos/monitor.go @@ -286,6 +286,7 @@ func (x *CosmosMessageMonitorRunnable) ValidateTxAndCreate(txDoc *models.Transac logger.WithError(err).Errorf("Error locking transaction") return false } else { + //nolint:errcheck defer x.db.Unlock(lockID) } diff --git a/cosmos/signer.go b/cosmos/signer.go index 6cbe8f9..4bc8172 100644 --- a/cosmos/signer.go +++ b/cosmos/signer.go @@ -259,6 +259,7 @@ func (x *CosmosMessageSignerRunnable) SignMessage( logger.WithError(err).Error("Error locking sequence") return false } else { + //nolint:errcheck defer x.db.Unlock(lockID) } @@ -361,6 +362,7 @@ func (x *CosmosMessageSignerRunnable) ValidateEthereumTxAndSignMessage(messageDo logger.WithError(err).Error("Error locking message") return false } else { + //nolint:errcheck defer x.db.Unlock(lockID) } @@ -499,6 +501,7 @@ func (x *CosmosMessageSignerRunnable) FindMaxSequence() (uint64, error) { if err != nil { return 0, fmt.Errorf("could not lock sequences: %w", err) } + //nolint:errcheck defer x.db.Unlock(lockID) maxSequence, err := x.db.FindMaxSequence(x.chain) @@ -669,14 +672,14 @@ func (x *CosmosMessageSignerRunnable) SignRefund( update["status"] = models.RefundStatusSigned } - lockID, err := x.db.LockWriteSequence() - if err != nil { + if lockID, err := x.db.LockWriteSequence(); err != nil { logger.WithError(err).Error("Error locking sequence") return false + } else { + //nolint:errcheck + defer x.db.Unlock(lockID) } - defer x.db.Unlock(lockID) - err = x.db.UpdateRefund(refundDoc.ID, update) if err != nil { logger.WithError(err).Errorf("Error updating refund") @@ -829,14 +832,14 @@ func (x *CosmosMessageSignerRunnable) ValidateEthereumTxAndBroadcastMessage(mess return x.UpdateMessage(messageDoc, bson.M{"status": models.MessageStatusInvalid}) } - lockID, err := x.db.LockWriteMessage(messageDoc) - // lock before signing so that no other validator adds a signature at the same time - if err != nil { + if lockID, err := x.db.LockWriteMessage(messageDoc); err != nil { logger.WithError(err).Error("Error locking message") return false - } + } else { - defer x.db.Unlock(lockID) + //nolint:errcheck + defer x.db.Unlock(lockID) + } return x.BroadcastMessage(messageDoc) @@ -1144,10 +1147,8 @@ func (x *CosmosMessageSignerRunnable) SignRefunds() bool { success = x.SignRefund(txResponse, &refundDoc, result.SenderAddress, result.Amount) && success - if err = x.db.Unlock(lockID); err != nil { - logger.WithError(err).Error("Error unlocking refund") - success = false - } + //nolint:errcheck + x.db.Unlock(lockID) } return success diff --git a/db/database.go b/db/database.go index c1efb5e..9bd64c9 100644 --- a/db/database.go +++ b/db/database.go @@ -422,6 +422,7 @@ func InitDB(config models.MongoConfig) { func DisconnectDB() { if mongoDB != nil { + //nolint:errcheck mongoDB.Disconnect() } } diff --git a/db/lock_test.go b/db/lock_test.go index a41a4ad..b068283 100644 --- a/db/lock_test.go +++ b/db/lock_test.go @@ -18,8 +18,6 @@ type LockTestSuite struct { db LockDB } -var oldMongoDB Database - func (suite *LockTestSuite) SetupTest() { suite.mockDB = mocks.NewMockDatabase(suite.T()) suite.oldMongoDB = mongoDB diff --git a/ethereum/monitor.go b/ethereum/monitor.go index b929e08..b0373c5 100644 --- a/ethereum/monitor.go +++ b/ethereum/monitor.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "fmt" - "math/big" "strings" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -34,8 +33,6 @@ type EthMessageMonitorRunnable struct { chain models.Chain - minimumAmount *big.Int - logger *log.Entry db db.DB @@ -262,6 +259,7 @@ func (x *EthMessageMonitorRunnable) CreateMessagesForTx(txDoc *models.Transactio logger.WithError(err).Error("Error locking transaction") return false } else { + //nolint:errcheck defer x.db.Unlock(lockID) } @@ -270,6 +268,7 @@ func (x *EthMessageMonitorRunnable) CreateMessagesForTx(txDoc *models.Transactio for _, event := range result.Events { var messageContent models.MessageContent + //nolint:errcheck messageContent.DecodeFromBytes(event.Message) // event was validated already message, err := x.db.NewMessage(txDoc, messageContent, models.MessageStatusPending) diff --git a/ethereum/relayer.go b/ethereum/relayer.go index e432ac2..7eeb8d8 100644 --- a/ethereum/relayer.go +++ b/ethereum/relayer.go @@ -190,6 +190,7 @@ func (x *EthMessageRelayerRunnable) ConfirmMessagesForTx(txDoc *models.Transacti logger.WithError(err).Error("Error locking transaction") return false } else { + //nolint:errcheck defer x.db.Unlock(lockID) } diff --git a/ethereum/signer.go b/ethereum/signer.go index 1eaf00f..ea01f3b 100644 --- a/ethereum/signer.go +++ b/ethereum/signer.go @@ -120,6 +120,7 @@ func (x *EthMessageSignerRunnable) SignMessage(messageDoc *models.Message) bool logger.WithError(err).Errorf("Error locking message") return false } else { + //nolint:errcheck defer x.db.Unlock(lockID) } diff --git a/scripts/generate_keys/main.go b/scripts/generate_keys/main.go index 04f7f70..2df84f5 100644 --- a/scripts/generate_keys/main.go +++ b/scripts/generate_keys/main.go @@ -121,6 +121,10 @@ func main() { { // ethereum wallet, err := hdwallet.NewFromMnemonic(mnemonic) + if err != nil { + fmt.Printf("Error creating wallet: %v\n", err) + return + } path := hdwallet.MustParseDerivationPath(common.DefaultETHHDPath) account, err := wallet.Derive(path, false)