Skip to content

Commit

Permalink
test(internal): status test
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Nov 20, 2024
1 parent a39d905 commit e2a3af5
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
32 changes: 32 additions & 0 deletions internal/status_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package internal

import (
"context"
"github.com/algorandfoundation/hack-tui/internal/test"
"strings"
"testing"
)
Expand All @@ -10,4 +12,34 @@ func Test_StatusModel(t *testing.T) {
if !strings.Contains(m.String(), "LastRound: 0") {
t.Fatal("expected \"LastRound: 0\", got ", m.String())
}

stale := true
m.Update(5, 10, &stale)

if m.LastRound != 5 {
t.Errorf("expected LastRound: 5, got %d", m.LastRound)
}
if m.State != SyncingState {
t.Errorf("expected State: %s, got %s", SyncingState, m.State)
}

m.Update(10, 0, &stale)
if m.LastRound != 10 {
t.Errorf("expected LastRound: 10, got %d", m.LastRound)
}
if m.State != StableState {
t.Errorf("expected State: %s, got %s", StableState, m.State)
}

}

func Test_StatusFetch(t *testing.T) {
m := StatusModel{LastRound: 0}
err := m.Fetch(context.Background(), test.GetClient(false))
if err != nil {
t.Error(err)
}
if m.LastRound == 0 {
t.Error("expected LastRound to be non-zero")
}
}
65 changes: 65 additions & 0 deletions internal/test/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,68 @@ func (c *Client) GenerateParticipationKeysWithResponse(ctx context.Context, addr

return &res, nil
}

func (c *Client) GetVersionWithResponse(ctx context.Context, reqEditors ...api.RequestEditorFn) (*api.GetVersionResponse, error) {
httpResponse := http.Response{StatusCode: 200}
version := api.Version{
Build: api.BuildVersion{
Branch: "test",
BuildNumber: 1,
Channel: "beta",
CommitHash: "abc",
Major: 0,
Minor: 0,
},
GenesisHashB64: nil,
GenesisId: "tui-net",
Versions: nil,
}
res := api.GetVersionResponse{
Body: nil,
HTTPResponse: &httpResponse,
JSON200: &version,
}

return &res, nil
}
func (c *Client) GetStatusWithResponse(ctx context.Context, reqEditors ...api.RequestEditorFn) (*api.GetStatusResponse, error) {
httpResponse := http.Response{StatusCode: 200}
data := new(struct {
Catchpoint *string `json:"catchpoint,omitempty"`
CatchpointAcquiredBlocks *int `json:"catchpoint-acquired-blocks,omitempty"`
CatchpointProcessedAccounts *int `json:"catchpoint-processed-accounts,omitempty"`
CatchpointProcessedKvs *int `json:"catchpoint-processed-kvs,omitempty"`
CatchpointTotalAccounts *int `json:"catchpoint-total-accounts,omitempty"`
CatchpointTotalBlocks *int `json:"catchpoint-total-blocks,omitempty"`
CatchpointTotalKvs *int `json:"catchpoint-total-kvs,omitempty"`
CatchpointVerifiedAccounts *int `json:"catchpoint-verified-accounts,omitempty"`
CatchpointVerifiedKvs *int `json:"catchpoint-verified-kvs,omitempty"`
CatchupTime int `json:"catchup-time"`
LastCatchpoint *string `json:"last-catchpoint,omitempty"`
LastRound int `json:"last-round"`
LastVersion string `json:"last-version"`
NextVersion string `json:"next-version"`
NextVersionRound int `json:"next-version-round"`
NextVersionSupported bool `json:"next-version-supported"`
StoppedAtUnsupportedRound bool `json:"stopped-at-unsupported-round"`
TimeSinceLastRound int `json:"time-since-last-round"`
UpgradeDelay *int `json:"upgrade-delay,omitempty"`
UpgradeNextProtocolVoteBefore *int `json:"upgrade-next-protocol-vote-before,omitempty"`
UpgradeNoVotes *int `json:"upgrade-no-votes,omitempty"`
UpgradeNodeVote *bool `json:"upgrade-node-vote,omitempty"`
UpgradeVoteRounds *int `json:"upgrade-vote-rounds,omitempty"`
UpgradeVotes *int `json:"upgrade-votes,omitempty"`
UpgradeVotesRequired *int `json:"upgrade-votes-required,omitempty"`
UpgradeYesVotes *int `json:"upgrade-yes-votes,omitempty"`
})
data.LastRound = 10
res := api.GetStatusResponse{
Body: nil,
HTTPResponse: &httpResponse,
JSON200: data,
JSON401: nil,
JSON500: nil,
}

return &res, nil
}

0 comments on commit e2a3af5

Please sign in to comment.