Skip to content

Commit

Permalink
chore: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed May 5, 2024
1 parent 9b66a67 commit 8bf31df
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
21 changes: 16 additions & 5 deletions pkg/fetchers/test_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
)

type TestFetcher struct {
WithProposals bool
WithProposalsError bool
WithVote bool
WithVoteError bool
WithProposals bool
WithPassedProposals bool
WithProposalsError bool
WithVote bool
WithVoteError bool
}

func (f *TestFetcher) GetAllProposals(
Expand All @@ -21,10 +22,20 @@ func (f *TestFetcher) GetAllProposals(
}
}

if f.WithPassedProposals {
return []types.Proposal{
{
ID: "1",
Status: types.ProposalStatusPassed,
},
}, 123, nil
}

if f.WithProposals {
return []types.Proposal{
{
ID: "1",
ID: "1",
Status: types.ProposalStatusVoting,
},
}, 123, nil
}
Expand Down
22 changes: 21 additions & 1 deletion pkg/state/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,27 @@ func TestReportGeneratorProcessChain(t *testing.T) {
Logger: *log,
Chains: chains,
Fetchers: map[string]fetchers.Fetcher{
"chain": &fetchers.TestFetcher{},
"chain": &fetchers.TestFetcher{WithPassedProposals: true},
},
}

oldState := NewState()
newState := generator.GetState(oldState)
assert.Len(t, newState.ChainInfos, 1)
}

func TestReportGeneratorProcessProposalsWithPassed(t *testing.T) {
t.Parallel()

log := logger.GetNopLogger()
chain := &types.Chain{Name: "chain", Type: "cosmos"}
chains := types.Chains{chain}

generator := Generator{
Logger: *log,
Chains: chains,
Fetchers: map[string]fetchers.Fetcher{
"chain": &fetchers.TestFetcher{WithPassedProposals: true},
},
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,23 @@ func TestHasVotedWithWalletVotePresent(t *testing.T) {
voted := state.HasVoted("chain", "proposal", "wallet")
assert.True(t, voted, "There should be a vote!")
}

func TestSetProposal(t *testing.T) {
t.Parallel()

state := NewState()
proposal := types.Proposal{ID: "id"}
chain := &types.Chain{Name: "chain"}
assert.Empty(t, state.ChainInfos)

state.SetProposal(chain, proposal)
assert.NotEmpty(t, state.ChainInfos)

chainInfo, ok := state.ChainInfos["chain"]
assert.True(t, ok)
assert.NotNil(t, chainInfo)

proposalInfo, ok := chainInfo.ProposalVotes["id"]
assert.True(t, ok)
assert.NotNil(t, proposalInfo)
}

0 comments on commit 8bf31df

Please sign in to comment.