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

Deterministic displayer integration tests #5093

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion integrationTests/vm/staking/configDisplayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package staking
import (
"bytes"
"fmt"
"sort"
"strconv"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/display"
"github.com/multiversx/mx-chain-go/state"
)
Expand All @@ -27,6 +29,10 @@ func getAllPubKeys(validatorsMap map[uint32][][]byte) [][]byte {

func getShortPubKeysList(pubKeys [][]byte) [][]byte {
pubKeysToDisplay := pubKeys
sort.SliceStable(pubKeysToDisplay, func(i, j int) bool {
return string(pubKeysToDisplay[i]) < string(pubKeysToDisplay[j])
})

if len(pubKeys) > maxPubKeysListLen {
pubKeysToDisplay = make([][]byte, 0)
pubKeysToDisplay = append(pubKeysToDisplay, pubKeys[:maxPubKeysListLen/2]...)
Expand All @@ -49,7 +55,10 @@ func (tmp *TestMetaProcessor) displayConfig(config nodesConfig) {
allNodes := tmp.getAllNodeKeys()
_ = tmp.StakingDataProvider.PrepareStakingData(allNodes)

for shard := range config.eligible {
numShards := uint32(len(config.eligible))
for shardId := uint32(0); shardId < numShards; shardId++ {
shard := getShardId(shardId, numShards)

lines = append(lines, tmp.getDisplayableValidatorsInShard("eligible", config.eligible[shard], shard)...)
lines = append(lines, tmp.getDisplayableValidatorsInShard("waiting", config.waiting[shard], shard)...)
lines = append(lines, tmp.getDisplayableValidatorsInShard("leaving", config.leaving[shard], shard)...)
Expand All @@ -73,6 +82,14 @@ func (tmp *TestMetaProcessor) displayConfig(config nodesConfig) {
tmp.StakingDataProvider.Clean()
}

func getShardId(shardId, numShards uint32) uint32 {
if shardId == numShards-1 {
return core.MetachainShardId
}

return shardId
}

func (tmp *TestMetaProcessor) getDisplayableValidatorsInShard(list string, pubKeys [][]byte, shardID uint32) []*display.LineData {
pubKeysToDisplay := getShortPubKeysList(pubKeys)

Expand Down