diff --git a/api/groups/baseGroup_test.go b/api/groups/baseGroup_test.go index fc56a48b..2c955690 100644 --- a/api/groups/baseGroup_test.go +++ b/api/groups/baseGroup_test.go @@ -57,6 +57,7 @@ func TestCrudOperationsBaseGroup(t *testing.T) { assert.Equal(t, hd2.Path, bg.endpoints[2].Path) err = bg.AddEndpoint(hd4.Path, *hd4) + assert.NoError(t, err) assert.Equal(t, 4, len(bg.endpoints)) // ensure the order diff --git a/api/groups/baseProofGroup_test.go b/api/groups/baseProofGroup_test.go index 4b60178c..bb073468 100644 --- a/api/groups/baseProofGroup_test.go +++ b/api/groups/baseProofGroup_test.go @@ -50,6 +50,7 @@ func TestGetProof_FailWhenFacadeGetProofFails(t *testing.T) { ws := startProxyServer(proofGroup, "/proof") req, err := http.NewRequest("GET", "/proof/root-hash/"+rootHash+"/address/"+address, nil) + require.NoError(t, err) resp := httptest.NewRecorder() ws.ServeHTTP(resp, req) @@ -82,6 +83,7 @@ func TestGetProof(t *testing.T) { ws := startProxyServer(proofGroup, "/proof") req, err := http.NewRequest("GET", "/proof/root-hash/"+rootHash+"/address/"+address, nil) + require.NoError(t, err) resp := httptest.NewRecorder() ws.ServeHTTP(resp, req) @@ -128,6 +130,7 @@ func TestVerifyProof_FailWhenFacadeVerifyProofFails(t *testing.T) { } verifyProofBytes, _ := json.Marshal(varifyProofParams) req, err := http.NewRequest("POST", "/proof/verify", bytes.NewBuffer(verifyProofBytes)) + require.NoError(t, err) resp := httptest.NewRecorder() ws.ServeHTTP(resp, req) @@ -165,6 +168,7 @@ func TestVerifyProof(t *testing.T) { } verifyProofBytes, _ := json.Marshal(varifyProofParams) req, err := http.NewRequest("POST", "/proof/verify", bytes.NewBuffer(verifyProofBytes)) + require.NoError(t, err) resp := httptest.NewRecorder() ws.ServeHTTP(resp, req) @@ -200,6 +204,7 @@ func TestGetProofDataTrie_FailWhenFacadeGetProofFails(t *testing.T) { endpoint := fmt.Sprintf("/proof/root-hash/%s/address/%s/key/%s", rootHash, address, key) req, err := http.NewRequest("GET", endpoint, nil) + require.NoError(t, err) resp := httptest.NewRecorder() ws.ServeHTTP(resp, req) @@ -235,6 +240,7 @@ func TestGetProofDataTrie(t *testing.T) { endpoint := fmt.Sprintf("/proof/root-hash/%s/address/%s/key/%s", rootHash, address, key) req, err := http.NewRequest("GET", endpoint, nil) + require.NoError(t, err) resp := httptest.NewRecorder() ws.ServeHTTP(resp, req) diff --git a/api/groups/baseValidatorGroup_test.go b/api/groups/baseValidatorGroup_test.go index e56bdbfc..6ac7cb6e 100644 --- a/api/groups/baseValidatorGroup_test.go +++ b/api/groups/baseValidatorGroup_test.go @@ -75,7 +75,7 @@ func TestValidatorStatistics_ShouldWork(t *testing.T) { TotalNumValidatorSuccess: 6, TotalNumValidatorFailure: 7, TotalNumValidatorIgnoredSignatures: 8, - ShardID: 1, + ShardId: 1, ValidatorStatus: "ok", RatingModifier: 1.5, } diff --git a/api/groups/v_next/accountsGroupV_next.go b/api/groups/v_next/accountsGroupV_next.go index 90a2eb7a..8535b2cd 100644 --- a/api/groups/v_next/accountsGroupV_next.go +++ b/api/groups/v_next/accountsGroupV_next.go @@ -50,6 +50,9 @@ func NewAccountsGroupV_next(baseAccountsGroup data.GroupHandler, facadeHandler d Handler: ag.NewEndpoint, Method: http.MethodGet, }) + if err != nil { + return nil, err + } return ag, nil } diff --git a/api/middleware/rateLimiter_test.go b/api/middleware/rateLimiter_test.go index 6ece3f44..6c4d02d2 100644 --- a/api/middleware/rateLimiter_test.go +++ b/api/middleware/rateLimiter_test.go @@ -37,6 +37,7 @@ func TestRateLimiter_IpRestrictionRaisedAndErased(t *testing.T) { t.Parallel() rl, err := NewRateLimiter(map[string]uint64{"/address/:address": 2}, time.Millisecond) + require.NoError(t, err) facade := &mock.FacadeStub{ GetAccountHandler: func(address string, _ common.AccountQueryOptions) (*data.AccountModel, error) { @@ -81,6 +82,7 @@ func TestRateLimiter_EndpointNotLimitedShouldNotRaiseRestrictions(t *testing.T) t.Parallel() rl, err := NewRateLimiter(map[string]uint64{"/address/:address/nonce": 1}, time.Millisecond) + require.NoError(t, err) facade := &mock.FacadeStub{ GetAccountHandler: func(address string, _ common.AccountQueryOptions) (*data.AccountModel, error) { diff --git a/data/account.go b/data/account.go index 42db810d..9dae99f2 100644 --- a/data/account.go +++ b/data/account.go @@ -1,5 +1,7 @@ package data +import "github.com/multiversx/mx-chain-core-go/data/validator" + // AccountModel defines an account model (with associated information) type AccountModel struct { Account Account `json:"account"` @@ -21,23 +23,7 @@ type Account struct { } // ValidatorApiResponse represents the data which is fetched from each validator for returning it in API call -type ValidatorApiResponse struct { - TempRating float32 `json:"tempRating"` - NumLeaderSuccess uint32 `json:"numLeaderSuccess"` - NumLeaderFailure uint32 `json:"numLeaderFailure"` - NumValidatorSuccess uint32 `json:"numValidatorSuccess"` - NumValidatorFailure uint32 `json:"numValidatorFailure"` - NumValidatorIgnoredSignatures uint32 `json:"numValidatorIgnoredSignatures"` - Rating float32 `json:"rating"` - RatingModifier float32 `json:"ratingModifier"` - TotalNumLeaderSuccess uint32 `json:"totalNumLeaderSuccess"` - TotalNumLeaderFailure uint32 `json:"totalNumLeaderFailure"` - TotalNumValidatorSuccess uint32 `json:"totalNumValidatorSuccess"` - TotalNumValidatorFailure uint32 `json:"totalNumValidatorFailure"` - TotalNumValidatorIgnoredSignatures uint32 `json:"totalNumValidatorIgnoredSignatures"` - ShardID uint32 `json:"shardId"` - ValidatorStatus string `json:"validatorStatus"` -} +type ValidatorApiResponse = validator.ValidatorStatistics // ValidatorStatisticsResponse respects the format the validator statistics are received from the observers type ValidatorStatisticsResponse struct { diff --git a/go.mod b/go.mod index 2b5d36b5..fe449993 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/gin-contrib/pprof v1.4.0 github.com/gin-contrib/static v0.0.1 github.com/gin-gonic/gin v1.9.1 - github.com/multiversx/mx-chain-core-go v1.2.16 + github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592 github.com/multiversx/mx-chain-crypto-go v1.2.9 github.com/multiversx/mx-chain-es-indexer-go v1.4.13 github.com/multiversx/mx-chain-logger-go v1.0.13 diff --git a/go.sum b/go.sum index 6b5981c1..06e0a306 100644 --- a/go.sum +++ b/go.sum @@ -131,8 +131,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiversx/mx-chain-core-go v1.2.16 h1:m0hUNmZQjGJxKDLQOHoM9jSaeDfVTbyd+mqiS8+NckE= -github.com/multiversx/mx-chain-core-go v1.2.16/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592 h1:fXpqfN64mLKvJycf5doOhvFRLM06eaMi7Ag3mO1fsbg= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.9 h1:OEfF2kOQrtzUl273Z3DEcshjlTVUfPpJMd0R0SvTrlU= github.com/multiversx/mx-chain-crypto-go v1.2.9/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8= github.com/multiversx/mx-chain-es-indexer-go v1.4.13 h1:3Ayaw9bSpeNOF+Z3L/11MN1rIJH8Rc6dqtt+o4Wfdno= diff --git a/observer/baseNodeProvider.go b/observer/baseNodeProvider.go index e5c0724c..30137a28 100644 --- a/observer/baseNodeProvider.go +++ b/observer/baseNodeProvider.go @@ -50,18 +50,10 @@ func (bnp *baseNodeProvider) GetAllNodesWithSyncState() []*data.NodeData { defer bnp.mutNodes.RUnlock() nodesSlice := make([]*data.NodeData, 0) - for _, node := range bnp.syncedNodes { - nodesSlice = append(nodesSlice, node) - } - for _, node := range bnp.outOfSyncNodes { - nodesSlice = append(nodesSlice, node) - } - for _, node := range bnp.syncedFallbackNodes { - nodesSlice = append(nodesSlice, node) - } - for _, node := range bnp.outOfSyncFallbackNodes { - nodesSlice = append(nodesSlice, node) - } + nodesSlice = append(nodesSlice, bnp.syncedNodes...) + nodesSlice = append(nodesSlice, bnp.outOfSyncNodes...) + nodesSlice = append(nodesSlice, bnp.syncedFallbackNodes...) + nodesSlice = append(nodesSlice, bnp.outOfSyncFallbackNodes...) return nodesSlice } diff --git a/observer/circularQueueNodesProvider_test.go b/observer/circularQueueNodesProvider_test.go index 7f7691a0..65178d88 100644 --- a/observer/circularQueueNodesProvider_test.go +++ b/observer/circularQueueNodesProvider_test.go @@ -138,8 +138,7 @@ func TestCircularQueueObserversProvider_GetAllObservers_ConcurrentSafe(t *testin numOfTimesToCallForEachRoutine := 8 mapCalledObservers := make(map[string]int) mutMap := &sync.RWMutex{} - var observers []*data.NodeData - observers = []*data.NodeData{ + observers := []*data.NodeData{ { Address: "addr1", ShardId: 0, @@ -194,8 +193,7 @@ func TestCircularQueueObserversProvider_GetObserversByShardId_ConcurrentSafe(t * numOfTimesToCallForEachRoutine := 6 mapCalledObservers := make(map[string]int) mutMap := &sync.RWMutex{} - var observers []*data.NodeData - observers = []*data.NodeData{ + observers := []*data.NodeData{ { Address: "addr1", ShardId: shardId0, diff --git a/observer/simpleNodesProvider_test.go b/observer/simpleNodesProvider_test.go index e66cda46..ba821482 100644 --- a/observer/simpleNodesProvider_test.go +++ b/observer/simpleNodesProvider_test.go @@ -71,8 +71,7 @@ func TestSimpleObserversProvider_GetObserversByShardId_ConcurrentSafe(t *testing numOfTimesToCallForEachRoutine := 6 mapCalledObservers := make(map[string]int) mutMap := &sync.RWMutex{} - var observers []*data.NodeData - observers = []*data.NodeData{ + observers := []*data.NodeData{ { Address: "addr1", ShardId: shardId0, @@ -135,8 +134,7 @@ func TestSimpleObserversProvider_GetAllObservers_ConcurrentSafe(t *testing.T) { numOfTimesToCallForEachRoutine := 6 mapCalledObservers := make(map[string]int) mutMap := &sync.RWMutex{} - var observers []*data.NodeData - observers = []*data.NodeData{ + observers := []*data.NodeData{ { Address: "addr1", ShardId: shardId0, diff --git a/process/baseProcessor.go b/process/baseProcessor.go index 87c603d2..b5cb272b 100644 --- a/process/baseProcessor.go +++ b/process/baseProcessor.go @@ -470,11 +470,7 @@ func (bp *BaseProcessor) getNodeStatusResponseFromAPI(url string) (*proxyData.No } func parseBool(metricValue string) bool { - if strconv.FormatBool(true) == metricValue { - return true - } - - return false + return strconv.FormatBool(true) == metricValue } // IsInterfaceNil returns true if there is no value under the interface diff --git a/process/esdtSupplyProcessor.go b/process/esdtSupplyProcessor.go index 19f283e7..6f78a326 100644 --- a/process/esdtSupplyProcessor.go +++ b/process/esdtSupplyProcessor.go @@ -113,8 +113,6 @@ func addToSupply(dstSupply, sourceSupply *data.ESDTSupply) { dstSupply.Supply = sumStr(dstSupply.Supply, sourceSupply.Supply) dstSupply.Burned = sumStr(dstSupply.Burned, sourceSupply.Burned) dstSupply.Minted = sumStr(dstSupply.Minted, sourceSupply.Minted) - - return } func sumStr(s1, s2 string) string { diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 7fd8c97c..af125355 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -477,11 +477,8 @@ func checkIfMoveBalanceNotarized(tx *transaction.ApiTransactionResult) bool { return false } isMoveBalance := tx.ProcessingTypeOnSource == moveBalanceDescriptor && tx.ProcessingTypeOnDestination == moveBalanceDescriptor - if !isMoveBalance { - return false - } - return true + return isMoveBalance } func findIdentifierInLogs(logs []*transaction.ApiLogs, identifier string) bool { diff --git a/testing/testHttpServer.go b/testing/testHttpServer.go index 401f9dbe..fa133e00 100644 --- a/testing/testHttpServer.go +++ b/testing/testHttpServer.go @@ -238,7 +238,7 @@ func (ths *TestHttpServer) processRequestValidatorStatistics(rw http.ResponseWri TotalNumValidatorSuccess: 8, TotalNumValidatorFailure: 5, TotalNumValidatorIgnoredSignatures: 120, - ShardID: core.MetachainShardId, + ShardId: core.MetachainShardId, ValidatorStatus: "waiting", }, "pubkey2": { @@ -255,7 +255,7 @@ func (ths *TestHttpServer) processRequestValidatorStatistics(rw http.ResponseWri TotalNumValidatorSuccess: 78, TotalNumValidatorFailure: 25, TotalNumValidatorIgnoredSignatures: 110, - ShardID: 1, + ShardId: 1, ValidatorStatus: "eligible", }, }