Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo committed May 7, 2024
1 parent bf6dbde commit 7904449
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
8 changes: 4 additions & 4 deletions listener/internal/api/validation/GetActiveValidators.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ func GetActiveValidators(requestsDecoded []types.SignatureRequestDecoded, beacon
// iterate over the networks available in the beaconNodeUrls map
for network, url := range beaconNodeUrls {
// prepare request body, get the list of ids from the requestsDecoded for the current network
idss := make([]string, 0, len(requestsDecoded))
ids := make([]string, 0, len(requestsDecoded))
for _, req := range requestsDecoded {
if req.Network == network {
idss = append(idss, req.DecodedPayload.Pubkey)
ids = append(ids, req.DecodedPayload.Pubkey)
}
}
// if there are no ids for the current network, log and skip it
if len(idss) == 0 {
if len(ids) == 0 {
fmt.Printf("no ids for network %s\n", network)
continue
}
Expand All @@ -39,7 +39,7 @@ func GetActiveValidators(requestsDecoded []types.SignatureRequestDecoded, beacon
Ids []string `json:"ids"`
Statuses []string `json:"statuses"`
}{
Ids: idss,
Ids: ids,
Statuses: []string{"active_ongoing"},
})
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions listener/internal/api/validation/GetActiveValidators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,43 @@ package validation

import (
"testing"

"github.com/dappnode/validator-monitoring/listener/internal/api/types"
)

func TestGetActiveValidators(t *testing.T) {
// Setup the input data
beaconNodeUrls := map[string]string{
"holesky": "https://holesky.infura.io/v3/e6c920580178424bbdf6dde266bfb5bd",
}

requestsDecoded := []types.SignatureRequestDecoded{
{
Network: "holesky",
DecodedPayload: types.DecodedPayload{
Pubkey: "0xa685beb5a1f317f5a01ecd6dade42113aad945b2ab53fb1b356334ab441323e538feadd2889894b17f8fa2babe1989ca",
},
},
{
Network: "holesky",
DecodedPayload: types.DecodedPayload{
Pubkey: "0xab31efdd97f32087e96d3262f6fb84a4480411d391689be0dfc931fd8a5c16c3f51f10b127040b1cb65eb955f2b78a63",
},
},
{
Network: "holesky",
DecodedPayload: types.DecodedPayload{
Pubkey: "0xa24a030d7d8ca3c5e1f5824760d0f4157a7a89bcca6414377cca97e6e63445bef0e1b63761ee35a0fc46bb317e31b34b",
},
},
}

// Call the function
result := GetActiveValidators(requestsDecoded, beaconNodeUrls)

// You may need to mock the server's response or adjust the expected values here according to your actual setup
expectedNumValidators := 3 // This should match the number of mock validators that are "active"
if len(result) != expectedNumValidators {
t.Errorf("Expected %d active validators, got %d", expectedNumValidators, len(result))
}
}

0 comments on commit 7904449

Please sign in to comment.