Skip to content

Commit

Permalink
Merge branch 'rc/v1.7.0' into recreate-trie-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
BeniaminDrasovean authored Mar 12, 2024
2 parents d055cae + 8e78d24 commit 0802c2d
Show file tree
Hide file tree
Showing 337 changed files with 26,497 additions and 9,234 deletions.
23 changes: 16 additions & 7 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
name: Build
name: Build and smoke test

on:
pull_request:
branches: [ master, rc/* ]
types: [opened, ready_for_review]
push:
branches: [master, rc/*]
workflow_dispatch:

jobs:
build:
strategy:
matrix:
runs-on: [ubuntu-latest]
runs-on: [ubuntu-latest, macos-latest, macos-13-xlarge]
runs-on: ${{ matrix.runs-on }}
name: Build
steps:
Expand All @@ -28,12 +26,23 @@ jobs:
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build
run: |
cd ${GITHUB_WORKSPACE}/cmd/node && go build .
cd ${GITHUB_WORKSPACE}/cmd/seednode && go build .
cd ${GITHUB_WORKSPACE}/cmd/keygenerator && go build .
cd ${GITHUB_WORKSPACE}/cmd/logviewer && go build .
cd ${GITHUB_WORKSPACE}/cmd/termui && go build .
# On GitHub, we only run the short tests, and we only run them for some OS/ARCH combinations.
- name: Run tests
run: |
GOOS=$(go env GOOS)
if [[ "$GOOS" == darwin ]]; then
go test -short -v ./...
fi
72 changes: 59 additions & 13 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
build:
strategy:
matrix:
runs-on: [ubuntu-latest] # TODO add macos-latest when builds are possible on macs
runs-on: [ubuntu-latest, macos-latest, macos-13-xlarge]
runs-on: ${{ matrix.runs-on }}
name: Build
steps:
Expand Down Expand Up @@ -45,21 +45,23 @@ jobs:
GOOS=$(go env GOOS)
GOARCH=$(go env GOARCH)
GOPATH=$(go env GOPATH)
ARCHIVE="multiversx_""$APP_VER_SHORT""_""$GOOS""_""$GOARCH"".tgz"
ARCHIVE="multiversx_""$APP_VER_SHORT""_""$GOOS""_""$GOARCH"".zip"
BUILD_DIR=${GITHUB_WORKSPACE}/build
WASM_VERSION=$(cat go.mod | grep mx-chain-vm-v | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')
WASMER_DIR=${GOPATH}/pkg/mod/github.com/multiversx/${WASM_VERSION}/wasmer
VM_GO_VERSION=$(cat go.mod | grep mx-chain-vm-go | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')
VM_GO_DIR=${GOPATH}/pkg/mod/github.com/multiversx/${VM_GO_VERSION}
echo "GOOS=${GOOS}" >> $GITHUB_ENV
echo "GOARCH=${GOARCH}" >> $GITHUB_ENV
echo "ARCHIVE=${ARCHIVE}" >> $GITHUB_ENV
echo "BUILD_DIR=${BUILD_DIR}" >> $GITHUB_ENV
echo "WASMER_DIR=${WASMER_DIR}" >> $GITHUB_ENV
echo "VM_GO_VERSION=${VM_GO_VERSION}" >> $GITHUB_ENV
echo "VM_GO_DIR=${VM_GO_DIR}" >> $GITHUB_ENV
- name: Build
run: |
mkdir -p ${BUILD_DIR}
cd ${GITHUB_WORKSPACE}/cmd/node && go build -o "${BUILD_DIR}/node" -a -ldflags="-X main.appVersion=${APP_VER}"
cd ${GITHUB_WORKSPACE}/cmd/seednode && go build -o "${BUILD_DIR}/seednode" -a -ldflags="-X main.appVersion=${APP_VER}"
cd ${GITHUB_WORKSPACE}/cmd/keygenerator && go build -o "${BUILD_DIR}/keygenerator" -a -ldflags="-X main.appVersion=${APP_VER}"
cd ${GITHUB_WORKSPACE}/cmd/logviewer && go build -o "${BUILD_DIR}/logviewer" -a -ldflags="-X main.appVersion=${APP_VER}"
cd ${GITHUB_WORKSPACE}/cmd/termui && go build -o "${BUILD_DIR}/termui" -a -ldflags="-X main.appVersion=${APP_VER}"
Expand All @@ -69,24 +71,68 @@ jobs:
cd ${GITHUB_WORKSPACE}
if [[ "$GOOS" == linux && "$GOARCH" == amd64 ]]; then
cp -f ${WASMER_DIR}/libwasmer_linux_amd64.so ${BUILD_DIR};
cp --verbose --no-preserve=mode,ownership ${VM_GO_DIR}/wasmer2/libvmexeccapi.so ${BUILD_DIR}/libvmexeccapi.so
cp --verbose --no-preserve=mode,ownership ${VM_GO_DIR}/wasmer/libwasmer_linux_amd64.so ${BUILD_DIR}/libwasmer_linux_amd64.so
fi
# Actually, there's no runner for this combination (as of March 2024).
if [[ "$GOOS" == linux && "$GOARCH" == arm64 ]]; then
cp -f ${WASMER_DIR}/libwasmer_linux_arm64.so ${BUILD_DIR};
cp --verbose --no-preserve=mode,ownership ${VM_GO_DIR}/wasmer2/libvmexeccapi_arm.so ${BUILD_DIR}/libvmexeccapi_arm.so
cp --verbose --no-preserve=mode,ownership ${VM_GO_DIR}/wasmer/libwasmer_linux_arm64_shim.so ${BUILD_DIR}/libwasmer_linux_arm64_shim.so
fi
if [[ "$GOOS" == darwin && "$GOARCH" == amd64 ]]; then
cp -f ${WASMER_DIR}/libwasmer_darwin_amd64.dylib ${BUILD_DIR};
cp -v ${VM_GO_DIR}/wasmer2/libvmexeccapi.dylib ${BUILD_DIR}/libvmexeccapi.dylib
cp -v ${VM_GO_DIR}/wasmer/libwasmer_darwin_amd64.dylib ${BUILD_DIR}/libwasmer_darwin_amd64.dylib
fi
if [[ "$GOOS" == darwin && "$GOARCH" == arm64 ]]; then
cp -v ${VM_GO_DIR}/wasmer2/libvmexeccapi_arm.dylib ${BUILD_DIR}/libvmexeccapi_arm.dylib
cp -v ${VM_GO_DIR}/wasmer/libwasmer_darwin_arm64_shim.dylib ${BUILD_DIR}/libwasmer_darwin_arm64_shim.dylib
fi
cd ${BUILD_DIR}
tar czvf "${GITHUB_WORKSPACE}/${ARCHIVE}" *
stat ${GITHUB_WORKSPACE}/${ARCHIVE}
if [[ "$GOOS" == linux ]]; then
patchelf --set-rpath "\$ORIGIN" ${BUILD_DIR}/node
patchelf --set-rpath "\$ORIGIN" ${BUILD_DIR}/seednode
ldd ${BUILD_DIR}/node
ldd ${BUILD_DIR}/seednode
fi
if [[ "$GOOS" == darwin ]]; then
install_name_tool -add_rpath "@loader_path" ${BUILD_DIR}/node
install_name_tool -add_rpath "@loader_path" ${BUILD_DIR}/seednode
otool -L ${BUILD_DIR}/node
otool -L ${BUILD_DIR}/seednode
fi
- name: Smoke test
run: |
# Remove all downloaded Go packages, so that we can test the binary's independence from them (think of Wasmer libraries).
sudo rm -rf ${GOPATH}/pkg/mod
# Test binaries in different current directories.
cd ${BUILD_DIR} && ./node --version
cd ${GITHUB_WORKSPACE} && ${BUILD_DIR}/node --version
cd / && ${BUILD_DIR}/node --version
cd ${BUILD_DIR} && ./seednode --version
cd ${GITHUB_WORKSPACE} && ${BUILD_DIR}/seednode --version
cd / && ${BUILD_DIR}/seednode --version
- name: Package build output
run: |
sudo chown -R $USER: ${BUILD_DIR}
chmod -R 755 ${BUILD_DIR}
ls -al ${BUILD_DIR}
zip -r -j ${ARCHIVE} ${BUILD_DIR}
- name: Save artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARCHIVE }}
path: ${{ github.workspace }}/${{ env.ARCHIVE }}
path: ${{ env.ARCHIVE }}
if-no-files-found: error

release:
Expand All @@ -113,6 +159,6 @@ jobs:
run: |
gh release create --draft --notes="Release draft from Github Actions" vNext
sleep 10
for i in $(find ./assets -name '*.tgz' -type f); do
for i in $(find ./assets -name '*.zip' -type f); do
gh release upload vNext ${i}
done
37 changes: 36 additions & 1 deletion api/groups/validatorGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import (
"github.com/multiversx/mx-chain-core-go/data/validator"
"github.com/multiversx/mx-chain-go/api/errors"
"github.com/multiversx/mx-chain-go/api/shared"
"github.com/multiversx/mx-chain-go/common"
)

const statisticsPath = "/statistics"
const (
statisticsPath = "/statistics"
auctionPath = "/auction"
)

// validatorFacadeHandler defines the methods to be implemented by a facade for validator requests
type validatorFacadeHandler interface {
ValidatorStatisticsApi() (map[string]*validator.ValidatorStatistics, error)
AuctionListApi() ([]*common.AuctionListValidatorAPIResponse, error)
IsInterfaceNil() bool
}

Expand All @@ -43,6 +48,11 @@ func NewValidatorGroup(facade validatorFacadeHandler) (*validatorGroup, error) {
Method: http.MethodGet,
Handler: ng.statistics,
},
{
Path: auctionPath,
Method: http.MethodGet,
Handler: ng.auction,
},
}
ng.endpoints = endpoints

Expand Down Expand Up @@ -74,6 +84,31 @@ func (vg *validatorGroup) statistics(c *gin.Context) {
)
}

// auction will return the list of the validators in the auction list
func (vg *validatorGroup) auction(c *gin.Context) {
valStats, err := vg.getFacade().AuctionListApi()
if err != nil {
c.JSON(
http.StatusBadRequest,
shared.GenericAPIResponse{
Data: nil,
Error: err.Error(),
Code: shared.ReturnCodeRequestError,
},
)
return
}

c.JSON(
http.StatusOK,
shared.GenericAPIResponse{
Data: gin.H{"auctionList": valStats},
Error: "",
Code: shared.ReturnCodeSuccess,
},
)
}

func (vg *validatorGroup) getFacade() validatorFacadeHandler {
vg.mutFacade.RLock()
defer vg.mutFacade.RUnlock()
Expand Down
76 changes: 71 additions & 5 deletions api/groups/validatorGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/multiversx/mx-chain-go/api/groups"
"github.com/multiversx/mx-chain-go/api/mock"
"github.com/multiversx/mx-chain-go/api/shared"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -34,11 +35,18 @@ func TestNewValidatorGroup(t *testing.T) {
}

// ValidatorStatisticsResponse is the response for the validator statistics endpoint.
type ValidatorStatisticsResponse struct {
type validatorStatisticsResponse struct {
Result map[string]*validator.ValidatorStatistics `json:"statistics"`
Error string `json:"error"`
}

type auctionListResponse struct {
Data struct {
Result []*common.AuctionListValidatorAPIResponse `json:"auctionList"`
} `json:"data"`
Error string
}

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

Expand All @@ -60,7 +68,7 @@ func TestValidatorStatistics_ErrorWhenFacadeFails(t *testing.T) {
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

response := ValidatorStatisticsResponse{}
response := validatorStatisticsResponse{}
loadResponse(resp.Body, &response)

assert.Equal(t, http.StatusBadRequest, resp.Code)
Expand Down Expand Up @@ -97,7 +105,7 @@ func TestValidatorStatistics_ReturnsSuccessfully(t *testing.T) {
response := shared.GenericAPIResponse{}
loadResponse(resp.Body, &response)

validatorStatistics := ValidatorStatisticsResponse{}
validatorStatistics := validatorStatisticsResponse{}
mapResponseData := response.Data.(map[string]interface{})
mapResponseDataBytes, _ := json.Marshal(mapResponseData)
_ = json.Unmarshal(mapResponseDataBytes, &validatorStatistics)
Expand Down Expand Up @@ -147,14 +155,13 @@ func TestValidatorGroup_UpdateFacade(t *testing.T) {
require.NoError(t, err)

ws := startWebServer(validatorGroup, "validator", getValidatorRoutesConfig())

req, _ := http.NewRequest("GET", "/validator/statistics", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

response := shared.GenericAPIResponse{}
loadResponse(resp.Body, &response)
validatorStatistics := ValidatorStatisticsResponse{}
validatorStatistics := validatorStatisticsResponse{}
mapResponseData := response.Data.(map[string]interface{})
mapResponseDataBytes, _ := json.Marshal(mapResponseData)
_ = json.Unmarshal(mapResponseDataBytes, &validatorStatistics)
Expand Down Expand Up @@ -191,12 +198,71 @@ func TestValidatorGroup_IsInterfaceNil(t *testing.T) {
require.False(t, validatorGroup.IsInterfaceNil())
}

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

errStr := "error in facade"
facade := mock.FacadeStub{
AuctionListHandler: func() ([]*common.AuctionListValidatorAPIResponse, error) {
return nil, errors.New(errStr)
},
}

validatorGroup, err := groups.NewValidatorGroup(&facade)
require.NoError(t, err)

ws := startWebServer(validatorGroup, "validator", getValidatorRoutesConfig())
req, _ := http.NewRequest("GET", "/validator/auction", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

response := auctionListResponse{}
loadResponse(resp.Body, &response)

assert.Equal(t, http.StatusBadRequest, resp.Code)
assert.Contains(t, response.Error, errStr)
}

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

auctionListToReturn := []*common.AuctionListValidatorAPIResponse{
{
Owner: "owner",
NumStakedNodes: 4,
TotalTopUp: "1234",
TopUpPerNode: "4321",
QualifiedTopUp: "4444",
},
}
facade := mock.FacadeStub{
AuctionListHandler: func() ([]*common.AuctionListValidatorAPIResponse, error) {
return auctionListToReturn, nil
},
}

validatorGroup, err := groups.NewValidatorGroup(&facade)
require.NoError(t, err)

ws := startWebServer(validatorGroup, "validator", getValidatorRoutesConfig())
req, _ := http.NewRequest("GET", "/validator/auction", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

response := auctionListResponse{}
loadResponse(resp.Body, &response)

assert.Equal(t, http.StatusOK, resp.Code)
assert.Equal(t, response.Data.Result, auctionListToReturn)
}

func getValidatorRoutesConfig() config.ApiRoutesConfig {
return config.ApiRoutesConfig{
APIPackages: map[string]config.APIPackageConfig{
"validator": {
Routes: []config.RouteConfig{
{Name: "/statistics", Open: true},
{Name: "/auction", Open: true},
},
},
},
Expand Down
Loading

0 comments on commit 0802c2d

Please sign in to comment.