From 7d194b72b9abf9d8ce49ef47d2860061b32be08b Mon Sep 17 00:00:00 2001 From: Matt Johnstone Date: Tue, 29 Oct 2024 12:40:18 +0200 Subject: [PATCH] solved sorting issue in getVoteAccounts test --- pkg/rpc/mock.go | 1 - pkg/rpc/mock_test.go | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/rpc/mock.go b/pkg/rpc/mock.go index 085543c..2b061c8 100644 --- a/pkg/rpc/mock.go +++ b/pkg/rpc/mock.go @@ -168,7 +168,6 @@ func (s *MockServer) getResult(method string, params ...any) (any, *RPCError) { rewards := make([]map[string]int, len(addresses)) for i, item := range addresses { address := item.(string) - // TODO: make inflation rewards fetchable by epoch rewards[i] = map[string]int{"amount": s.inflationRewards[address], "epoch": epoch} } return rewards, nil diff --git a/pkg/rpc/mock_test.go b/pkg/rpc/mock_test.go index 5aa0b92..cebd31f 100644 --- a/pkg/rpc/mock_test.go +++ b/pkg/rpc/mock_test.go @@ -3,6 +3,7 @@ package rpc import ( "context" "github.com/stretchr/testify/assert" + "sort" "testing" ) @@ -130,7 +131,10 @@ func TestMockServer_getVoteAccounts(t *testing.T) { voteAccounts, err := client.GetVoteAccounts(ctx, CommitmentFinalized) 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, VoteAccounts{ Current: []VoteAccount{