solved sorting issue in getVoteAccounts test

This commit is contained in:
Matt Johnstone 2024-10-29 12:40:18 +02:00
parent cb8422c563
commit 7d194b72b9
No known key found for this signature in database
GPG Key ID: BE985FBB9BE7D3BB
2 changed files with 5 additions and 2 deletions

View File

@ -168,7 +168,6 @@ func (s *MockServer) getResult(method string, params ...any) (any, *RPCError) {
rewards := make([]map[string]int, len(addresses)) rewards := make([]map[string]int, len(addresses))
for i, item := range addresses { for i, item := range addresses {
address := item.(string) address := item.(string)
// TODO: make inflation rewards fetchable by epoch
rewards[i] = map[string]int{"amount": s.inflationRewards[address], "epoch": epoch} rewards[i] = map[string]int{"amount": s.inflationRewards[address], "epoch": epoch}
} }
return rewards, nil return rewards, nil

View File

@ -3,6 +3,7 @@ package rpc
import ( import (
"context" "context"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"sort"
"testing" "testing"
) )
@ -130,7 +131,10 @@ func TestMockServer_getVoteAccounts(t *testing.T) {
voteAccounts, err := client.GetVoteAccounts(ctx, CommitmentFinalized) voteAccounts, err := client.GetVoteAccounts(ctx, CommitmentFinalized)
assert.NoError(t, err) assert.NoError(t, err)
// TODO: this test sometimes (albeit rarely) fails because the ordering gets mixed up, fix! // sort the vote accounts before comparing:
sort.Slice(voteAccounts.Current, func(i, j int) bool {
return voteAccounts.Current[i].VotePubkey < voteAccounts.Current[j].VotePubkey
})
assert.Equal(t, assert.Equal(t,
VoteAccounts{ VoteAccounts{
Current: []VoteAccount{ Current: []VoteAccount{