Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add version to /help #50

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cmd/cosmos-proposals-checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/spf13/cobra"
)

func Execute(configPath string) {
app := pkg.NewApp(configPath)
app.Start()
}

var (
version = "unknown"
)

func Execute(configPath string) {
app := pkg.NewApp(configPath, version)
app.Start()
}

func main() {
var ConfigPath string

Expand Down
4 changes: 2 additions & 2 deletions pkg/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type App struct {
Reporters []reportersPkg.Reporter
}

func NewApp(configPath string) *App {
func NewApp(configPath string, version string) *App {
config, err := configPkg.GetConfig(configPath)
if err != nil {
logger.GetDefaultLogger().Fatal().Err(err).Msg("Could not load config")
Expand All @@ -50,7 +50,7 @@ func NewApp(configPath string) *App {
StateGenerator: stateGenerator,
Reporters: []reportersPkg.Reporter{
pagerduty.NewPagerDutyReporter(config.PagerDutyConfig, log),
telegram.NewTelegramReporter(config.TelegramConfig, mutesManager, stateGenerator, log),
telegram.NewTelegramReporter(config.TelegramConfig, mutesManager, stateGenerator, log, version),
},
}
}
Expand Down
38 changes: 20 additions & 18 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package config
import (
"testing"

"github.com/stretchr/testify/require"

configTypes "main/pkg/config/types"

"github.com/stretchr/testify/assert"
Expand All @@ -16,7 +18,7 @@ func TestValidateChainWithEmptyName(t *testing.T) {
}

err := chain.Validate()
assert.NotEqual(t, err, nil, "Error should be presented!")
require.Error(t, err, nil, "Error should be presented!")
}

func TestValidateChainWithoutEndpoints(t *testing.T) {
Expand All @@ -28,7 +30,7 @@ func TestValidateChainWithoutEndpoints(t *testing.T) {
}

err := chain.Validate()
assert.NotEqual(t, err, nil, "Error should be presented!")
require.Error(t, err, nil, "Error should be presented!")
}

func TestValidateChainWithoutWallets(t *testing.T) {
Expand All @@ -41,7 +43,7 @@ func TestValidateChainWithoutWallets(t *testing.T) {
}

err := chain.Validate()
assert.NotEqual(t, err, nil, "Error should be presented!")
require.Error(t, err, nil, "Error should be presented!")
}

func TestValidateChainWithValidConfig(t *testing.T) {
Expand All @@ -55,7 +57,7 @@ func TestValidateChainWithValidConfig(t *testing.T) {
}

err := chain.Validate()
assert.Equal(t, err, nil, "Error should not be presented!")
require.NoError(t, err, "Error should not be presented!")
}

func TestChainGetNameWithoutPrettyName(t *testing.T) {
Expand All @@ -66,8 +68,8 @@ func TestChainGetNameWithoutPrettyName(t *testing.T) {
PrettyName: "",
}

err := chain.GetName()
assert.Equal(t, err, "chain", "Chain name should match!")
name := chain.GetName()
assert.Equal(t, "chain", name, "Chain name should match!")
}

func TestChainGetNameWithPrettyName(t *testing.T) {
Expand All @@ -79,7 +81,7 @@ func TestChainGetNameWithPrettyName(t *testing.T) {
}

err := chain.GetName()
assert.Equal(t, err, "chain-pretty", "Chain name should match!")
assert.Equal(t, "chain-pretty", err, "Chain name should match!")
}

func TestValidateConfigNoChains(t *testing.T) {
Expand All @@ -89,7 +91,7 @@ func TestValidateConfigNoChains(t *testing.T) {
Chains: []*configTypes.Chain{},
}
err := config.Validate()
assert.NotEqual(t, err, nil, "Error should be presented!")
require.Error(t, err, nil, "Error should be presented!")
}

func TestValidateConfigInvalidChain(t *testing.T) {
Expand All @@ -103,7 +105,7 @@ func TestValidateConfigInvalidChain(t *testing.T) {
},
}
err := config.Validate()
assert.NotEqual(t, err, nil, "Error should be presented!")
require.Error(t, err, nil, "Error should be presented!")
}

func TestValidateConfigWrongProposalType(t *testing.T) {
Expand All @@ -120,7 +122,7 @@ func TestValidateConfigWrongProposalType(t *testing.T) {
},
}
err := config.Validate()
assert.NotEqual(t, err, nil, "Error should be presented!")
require.Error(t, err, nil, "Error should be presented!")
}

func TestValidateConfigValidChain(t *testing.T) {
Expand All @@ -137,7 +139,7 @@ func TestValidateConfigValidChain(t *testing.T) {
},
}
err := config.Validate()
assert.Equal(t, err, nil, "Error should not be presented!")
require.NoError(t, err, "Error should not be presented!")
}

func TestFindChainByNameIfPresent(t *testing.T) {
Expand All @@ -149,7 +151,7 @@ func TestFindChainByNameIfPresent(t *testing.T) {
}

chain := chains.FindByName("chain2")
assert.NotEqual(t, chain, nil, "Chain should be presented!")
assert.NotNil(t, chain, "Chain should be presented!")
}

func TestFindChainByNameIfNotPresent(t *testing.T) {
Expand All @@ -170,7 +172,7 @@ func TestGetLinksEmpty(t *testing.T) {
chain := configTypes.Chain{}
links := chain.GetExplorerProposalsLinks("test")

assert.Equal(t, len(links), 0, "Expected 0 links")
assert.Empty(t, links, "Expected 0 links")
}

func TestGetLinksPresent(t *testing.T) {
Expand All @@ -184,9 +186,9 @@ func TestGetLinksPresent(t *testing.T) {
}
links := chain.GetExplorerProposalsLinks("test")

assert.Equal(t, len(links), 2, "Expected 2 links")
assert.Equal(t, links[0].Name, "Keplr", "Expected Keplr link")
assert.Equal(t, links[0].Href, "https://wallet.keplr.app/#/chain/governance?detailId=test", "Wrong Keplr link")
assert.Equal(t, links[1].Name, "Explorer", "Expected Explorer link")
assert.Equal(t, links[1].Href, "example.com/proposal/test", "Wrong explorer link")
assert.Len(t, links, 2, "Expected 2 links")
assert.Equal(t, "Keplr", links[0].Name, "Expected Keplr link")
assert.Equal(t, "https://wallet.keplr.app/#/chain/governance?detailId=test", links[0].Href, "Wrong Keplr link")
assert.Equal(t, "Explorer", links[1].Name, "Expected Explorer link")
assert.Equal(t, "example.com/proposal/test", links[1].Href, "Wrong explorer link")
}
28 changes: 14 additions & 14 deletions pkg/mutes/mutes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,39 @@ func TestMuteMatchesNoParams(t *testing.T) {

mute := &Mute{}
muted := mute.Matches("chain", "proposal")
assert.Equal(t, muted, true, "Mute should match!")
assert.True(t, muted, "Mute should match!")
}

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

mute := &Mute{Chain: "chain"}
muted := mute.Matches("chain", "proposal")
assert.Equal(t, muted, true, "Mute should match!")
assert.True(t, muted, "Mute should match!")
muted2 := mute.Matches("chain2", "proposal")
assert.Equal(t, muted2, false, "Mute should not match!")
assert.False(t, muted2, "Mute should not match!")
}

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

mute := &Mute{ProposalID: "proposal"}
muted := mute.Matches("chain", "proposal")
assert.Equal(t, muted, true, "Mute should match!")
assert.True(t, muted, "Mute should match!")
muted2 := mute.Matches("chain", "proposal2")
assert.Equal(t, muted2, false, "Mute should not match!")
assert.False(t, muted2, "Mute should not match!")
}

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

mute := &Mute{Chain: "chain", ProposalID: "proposal"}
muted := mute.Matches("chain", "proposal")
assert.Equal(t, muted, true, "Mute should match!")
assert.True(t, muted, "Mute should match!")
muted2 := mute.Matches("chain", "proposal2")
assert.Equal(t, muted2, false, "Mute should not match!")
assert.False(t, muted2, "Mute should not match!")
muted3 := mute.Matches("chain2", "proposal")
assert.Equal(t, muted3, false, "Mute should not match!")
assert.False(t, muted3, "Mute should not match!")
}

func TestMutesMatchesIgnoreExpired(t *testing.T) {
Expand All @@ -56,7 +56,7 @@ func TestMutesMatchesIgnoreExpired(t *testing.T) {
},
}
muted := mutes.IsMuted("chain", "proposal")
assert.Equal(t, muted, false, "Mute should not be muted!")
assert.False(t, muted, "Mute should not be muted!")
}

func TestMutesMatchesNotIgnoreActual(t *testing.T) {
Expand All @@ -68,7 +68,7 @@ func TestMutesMatchesNotIgnoreActual(t *testing.T) {
},
}
muted := mutes.IsMuted("chain", "proposal")
assert.Equal(t, muted, true, "Mute should be muted!")
assert.True(t, muted, "Mute should be muted!")
}

func TestMutesAddsMute(t *testing.T) {
Expand All @@ -81,8 +81,8 @@ func TestMutesAddsMute(t *testing.T) {
}

mutes.AddMute(&Mute{Chain: "chain2", Expires: time.Now().Add(time.Hour)})
assert.Equal(t, len(mutes.Mutes), 1, "There should be 1 mute!")
assert.Equal(t, mutes.Mutes[0].Chain, "chain2", "Chain name should match!")
assert.Len(t, mutes.Mutes, 1, "There should be 1 mute!")
assert.Equal(t, "chain2", mutes.Mutes[0].Chain, "Chain name should match!")
}

func TestMutesDeletesMute(t *testing.T) {
Expand All @@ -95,6 +95,6 @@ func TestMutesDeletesMute(t *testing.T) {
}

mutes.AddMute(&Mute{Chain: "chain2", Expires: time.Now().Add(time.Hour)})
assert.Equal(t, len(mutes.Mutes), 1, "There should be 1 mute!")
assert.Equal(t, mutes.Mutes[0].Chain, "chain2", "Chain name should match!")
assert.Len(t, mutes.Mutes, 1, "There should be 1 mute!")
assert.Equal(t, "chain2", mutes.Mutes[0].Chain, "Chain name should match!")
}
20 changes: 10 additions & 10 deletions pkg/report/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func TestReportGeneratorWithProposalError(t *testing.T) {
})

report := generator.GenerateReport(oldState, newState)
assert.Equal(t, len(report.Entries), 1, "Expected to have 1 entry!")
assert.Len(t, report.Entries, 1, "Expected to have 1 entry!")

entry, ok := report.Entries[0].(events.ProposalsQueryErrorEvent)
assert.True(t, ok, "Expected to have a proposal query error!")
assert.Equal(t, entry.Error.Error(), "test error", "Error text mismatch!")
assert.Equal(t, "test error", entry.Error.Error(), "Error text mismatch!")
}

func TestReportGeneratorWithVoteError(t *testing.T) {
Expand Down Expand Up @@ -68,11 +68,11 @@ func TestReportGeneratorWithVoteError(t *testing.T) {
})

report := generator.GenerateReport(oldState, newState)
assert.Equal(t, len(report.Entries), 1, "Expected to have 1 entry!")
assert.Len(t, report.Entries, 1, "Expected to have 1 entry!")

entry, ok := report.Entries[0].(events.VoteQueryError)
assert.True(t, ok, "Expected to have a vote query error!")
assert.Equal(t, entry.Proposal.ID, "proposal", "Proposal ID mismatch!")
assert.Equal(t, "proposal", entry.Proposal.ID, "Proposal ID mismatch!")
}

func TestReportGeneratorWithNotVoted(t *testing.T) {
Expand Down Expand Up @@ -103,11 +103,11 @@ func TestReportGeneratorWithNotVoted(t *testing.T) {
})

report := generator.GenerateReport(oldState, newState)
assert.Equal(t, len(report.Entries), 1, "Expected to have 1 entry!")
assert.Len(t, report.Entries, 1, "Expected to have 1 entry!")

entry, ok := report.Entries[0].(events.NotVotedEvent)
assert.True(t, ok, "Expected to have not voted type!")
assert.Equal(t, entry.Proposal.ID, "proposal", "Proposal ID mismatch!")
assert.Equal(t, "proposal", entry.Proposal.ID, "Proposal ID mismatch!")
}

func TestReportGeneratorWithVoted(t *testing.T) {
Expand Down Expand Up @@ -157,11 +157,11 @@ func TestReportGeneratorWithVoted(t *testing.T) {
})

report := generator.GenerateReport(oldState, newState)
assert.Equal(t, len(report.Entries), 1, "Expected to have 1 entry!")
assert.Len(t, report.Entries, 1, "Expected to have 1 entry!")

entry, ok := report.Entries[0].(events.VotedEvent)
assert.True(t, ok, "Expected to have voted type!")
assert.Equal(t, entry.Proposal.ID, "proposal", "Proposal ID mismatch!")
assert.Equal(t, "proposal", entry.Proposal.ID, "Proposal ID mismatch!")
}

func TestReportGeneratorWithRevoted(t *testing.T) {
Expand Down Expand Up @@ -215,9 +215,9 @@ func TestReportGeneratorWithRevoted(t *testing.T) {
})

report := generator.GenerateReport(oldState, newState)
assert.Equal(t, len(report.Entries), 1, "Expected to have 1 entry!")
assert.Len(t, report.Entries, 1, "Expected to have 1 entry!")

entry, ok := report.Entries[0].(events.RevotedEvent)
assert.True(t, ok, "Expected to have revoted type!")
assert.Equal(t, entry.Proposal.ID, "proposal", "Proposal ID mismatch!")
assert.Equal(t, "proposal", entry.Proposal.ID, "Proposal ID mismatch!")
}
2 changes: 1 addition & 1 deletion pkg/reporters/telegram/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (reporter *Reporter) HandleHelp(c tele.Context) error {

template, _ := reporter.GetTemplate("help")
var buffer bytes.Buffer
if err := template.Execute(&buffer, nil); err != nil {
if err := template.Execute(&buffer, reporter.Version); err != nil {
reporter.Logger.Error().Err(err).Msg("Error rendering help template")
return err
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/reporters/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Reporter struct {
TelegramBot *tele.Bot
Logger zerolog.Logger
Templates map[string]*template.Template

Version string
}

const (
Expand All @@ -39,6 +41,7 @@ func NewTelegramReporter(
mutesManager *mutes.Manager,
stateGenerator *state.Generator,
logger *zerolog.Logger,
version string,
) *Reporter {
return &Reporter{
TelegramToken: config.TelegramToken,
Expand All @@ -47,6 +50,7 @@ func NewTelegramReporter(
StateGenerator: stateGenerator,
Logger: logger.With().Str("component", "telegram_reporter").Logger(),
Templates: make(map[string]*template.Template, 0),
Version: version,
}
}

Expand Down
Loading
Loading