Skip to content

Commit

Permalink
Merge branch 'rc/v1.7.0' into merge-rc-1-7-into-staking-v4-8-jan-2024
Browse files Browse the repository at this point in the history
# Conflicts:
#	facade/mock/accountProccessorStub.go
  • Loading branch information
mariusmihaic committed Jan 8, 2024
2 parents 5f5466b + 68ad007 commit c098d53
Show file tree
Hide file tree
Showing 113 changed files with 4,708 additions and 728 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "CodeQL"

on:
pull_request:
branches: [development, rc/*]
branches: [feat/*, rc/*]
types: [opened, ready_for_review]
push:
workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Get the version
id: get_version
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Go

on:
pull_request:
branches: [development, rc/*]
branches: [feat/*, rc/*]
types: [opened, ready_for_review]
push:
workflow_dispatch:
Expand All @@ -12,14 +12,14 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
- name: Set up Go 1.20.7
uses: actions/setup-go@v2
with:
go-version: ^1.15.5
go-version: 1.20.7
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Get dependencies
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ name: Tests

on:
push:
branches: [ master, development, rc/* ]
branches: [ master, rc/*, feat/* ]
pull_request:
branches: [ master, development, rc/* ]
branches: [ master, rc/*, feat/* ]

jobs:
test:
name: Unit
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
- name: Set up Go 1.20.7
uses: actions/setup-go@v2
with:
go-version: ^1.17.6
go-version: 1.20.7
id: go

- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Get dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cmd_dir = cmd/proxy
binary = proxy

clean-test:
go clean -testcache ./...
go clean -testcache

test: clean-test
go test ./...
Expand Down
12 changes: 12 additions & 0 deletions api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ var ErrComputeShardForAddress = errors.New("compute shard ID for address error")
// ErrGetESDTTokenData signals an error in fetching an ESDT token data
var ErrGetESDTTokenData = errors.New("cannot get ESDT token data")

// ErrGetGuardianData signals an error in fetching an address guardian data
var ErrGetGuardianData = errors.New("cannot get guardian data")

// ErrGetESDTsWithRole signals an error in fetching an tokens with role for an address
var ErrGetESDTsWithRole = errors.New("cannot get ESDTs with role")

Expand Down Expand Up @@ -71,6 +74,12 @@ var ErrValidatorQueryParameterCheckSignature = errors.New("invalid query paramet
// ErrInvalidSignatureHex signals a wrong hex value was provided for the signature
var ErrInvalidSignatureHex = errors.New("invalid signature, could not decode hex value")

// ErrInvalidGuardianSignatureHex signals a wrong hex value provided for the guardian signature
var ErrInvalidGuardianSignatureHex = errors.New("invalid guardian signature, could not decode hex value")

// ErrInvalidGuardianAddress signals a wrong format for receiver address was provided
var ErrInvalidGuardianAddress = errors.New("invalid hex receiver address provided")

// ErrTxGenerationFailed signals an error generating a transaction
var ErrTxGenerationFailed = errors.New("transaction generation failed")

Expand Down Expand Up @@ -125,6 +134,9 @@ var ErrInvalidFields = errors.New("invalid fields")
// ErrOperationNotAllowed signals that the operation is not allowed
var ErrOperationNotAllowed = errors.New("operation not allowed")

// ErrIsDataTrieMigrated signals that an error occurred while trying to verify the migration status of the data trie
var ErrIsDataTrieMigrated = errors.New("could not verify the migration status of the data trie")

// ErrInvalidTxFields signals that one or more field of a transaction are invalid
type ErrInvalidTxFields struct {
Message string
Expand Down
11 changes: 11 additions & 0 deletions api/groups/baseAboutGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewAboutGroup(facadeHandler data.FacadeHandler) (*aboutGroup, error) {

baseRoutesHandlers := []*data.EndpointHandlerData{
{Path: "", Handler: ag.getAboutInfo, Method: http.MethodGet},
{Path: "/nodes-versions", Handler: ag.getNodesVersions, Method: http.MethodGet},
}
ag.baseGroup.endpoints = baseRoutesHandlers

Expand All @@ -41,3 +42,13 @@ func (ag *aboutGroup) getAboutInfo(c *gin.Context) {

c.JSON(http.StatusOK, aboutInfo)
}

func (ag *aboutGroup) getNodesVersions(c *gin.Context) {
nodesVersions, err := ag.facade.GetNodesVersions()
if err != nil {
shared.RespondWith(c, http.StatusInternalServerError, nil, err.Error(), data.ReturnCodeInternalError)
return
}

c.JSON(http.StatusOK, nodesVersions)
}
71 changes: 71 additions & 0 deletions api/groups/baseAboutGroup_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package groups_test

import (
"errors"
"net/http"
"net/http/httptest"
"testing"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-proxy-go/api/groups"
"github.com/multiversx/mx-chain-proxy-go/api/mock"
"github.com/multiversx/mx-chain-proxy-go/data"
Expand All @@ -18,6 +20,12 @@ type aboutResponse struct {
Code string `json:"code"`
}

type nodesVersionsResponse struct {
Data data.NodesVersionProxyResponseData `json:"data"`
Error string `json:"error"`
Code string `json:"code"`
}

func TestNewAboutGroup(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -69,3 +77,66 @@ func TestAboutGroup_GetAboutInfo(t *testing.T) {
assert.Equal(t, apiResp.Data.CommitID, commitID)
assert.Empty(t, apiResp.Error)
}

func TestAboutGroup_GetNodesVersions(t *testing.T) {
t.Parallel()

t.Run("facade error, should err", func(t *testing.T) {
t.Parallel()

expectedErr := errors.New("error")
facade := &mock.FacadeStub{
GetNodesVersionsCalled: func() (*data.GenericAPIResponse, error) {
return nil, expectedErr
},
}
aboutGroup, err := groups.NewAboutGroup(facade)
require.NoError(t, err)

ws := startProxyServer(aboutGroup, "/about")

req, _ := http.NewRequest("GET", "/about/nodes-versions", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

apiResp := nodesVersionsResponse{}
loadResponse(resp.Body, &apiResp)

assert.Equal(t, http.StatusInternalServerError, resp.Code)
assert.Contains(t, apiResp.Error, expectedErr.Error())
})

t.Run("should work", func(t *testing.T) {
t.Parallel()

expectedVersions := map[uint32][]string{
0: {"v1", "v2"},
1: {"v2"},
2: {"v3"},
core.MetachainShardId: {"v4"},
}
facade := &mock.FacadeStub{
GetNodesVersionsCalled: func() (*data.GenericAPIResponse, error) {
return &data.GenericAPIResponse{
Data: data.NodesVersionProxyResponseData{
Versions: expectedVersions,
},
}, nil
},
}
aboutGroup, err := groups.NewAboutGroup(facade)
require.NoError(t, err)

ws := startProxyServer(aboutGroup, "/about")

req, _ := http.NewRequest("GET", "/about/nodes-versions", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

apiResp := nodesVersionsResponse{}
loadResponse(resp.Body, &apiResp)

assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, expectedVersions, apiResp.Data.Versions)
})
}
46 changes: 46 additions & 0 deletions api/groups/baseAccountsGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func NewAccountsGroup(facadeHandler data.FacadeHandler) (*accountsGroup, error)
{Path: "/:address/esdts/roles", Handler: ag.getESDTsRoles, Method: http.MethodGet},
{Path: "/:address/registered-nfts", Handler: ag.getRegisteredNFTs, Method: http.MethodGet},
{Path: "/:address/nft/:tokenIdentifier/nonce/:nonce", Handler: ag.getESDTNftTokenData, Method: http.MethodGet},
{Path: "/:address/guardian-data", Handler: ag.getGuardianData, Method: http.MethodGet},
{Path: "/:address/is-data-trie-migrated", Handler: ag.isDataTrieMigrated, Method: http.MethodGet},
}
ag.baseGroup.endpoints = baseRoutesHandlers

Expand Down Expand Up @@ -349,6 +351,28 @@ func (group *accountsGroup) getESDTNftTokenData(c *gin.Context) {
c.JSON(http.StatusOK, esdtTokenResponse)
}

func (group *accountsGroup) getGuardianData(c *gin.Context) {
addr := c.Param("address")
if addr == "" {
shared.RespondWithValidationError(c, errors.ErrGetGuardianData, errors.ErrEmptyAddress)
return
}

options, err := parseAccountQueryOptions(c)
if err != nil {
shared.RespondWithValidationError(c, errors.ErrGetGuardianData, err)
return
}

guardianData, err := group.facade.GetGuardianData(addr, options)
if err != nil {
shared.RespondWithInternalError(c, errors.ErrGetGuardianData, err)
return
}

c.JSON(http.StatusOK, guardianData)
}

// getESDTTokens returns the tokens list from this account
func (group *accountsGroup) getESDTTokens(c *gin.Context) {
addr := c.Param("address")
Expand All @@ -370,3 +394,25 @@ func (group *accountsGroup) getESDTTokens(c *gin.Context) {

c.JSON(http.StatusOK, tokens)
}

func (group *accountsGroup) isDataTrieMigrated(c *gin.Context) {
addr := c.Param("address")
if addr == "" {
shared.RespondWithValidationError(c, errors.ErrIsDataTrieMigrated, errors.ErrEmptyAddress)
return
}

options, err := parseAccountQueryOptions(c)
if err != nil {
shared.RespondWithValidationError(c, errors.ErrIsDataTrieMigrated, err)
return
}

isMigrated, err := group.facade.IsDataTrieMigrated(addr, options)
if err != nil {
shared.RespondWithInternalError(c, errors.ErrIsDataTrieMigrated, err)
return
}

c.JSON(http.StatusOK, isMigrated)
}
Loading

0 comments on commit c098d53

Please sign in to comment.