diff --git a/.gitignore b/.gitignore index 163ce03..373a1c0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ main cover.out missed-blocks-checker dist -*.sqlite \ No newline at end of file +*.sqlite +**/.DS_Store \ No newline at end of file diff --git a/go.mod b/go.mod index 6aa2993..9f106ce 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module main -go 1.19 +go 1.18 require ( github.com/BurntSushi/toml v1.2.1 diff --git a/pkg/app.go b/pkg/app.go index 10f0feb..1397e65 100644 --- a/pkg/app.go +++ b/pkg/app.go @@ -46,6 +46,7 @@ func NewApp(configPath string, version string) *App { appManagers[index] = NewAppManager( logger, chainConfig, + version, metricsManager, database, ) diff --git a/pkg/app_manager.go b/pkg/app_manager.go index 1d416cf..53c6597 100644 --- a/pkg/app_manager.go +++ b/pkg/app_manager.go @@ -39,6 +39,7 @@ type AppManager struct { func NewAppManager( logger zerolog.Logger, config *configPkg.ChainConfig, + version string, metricsManager *metrics.Manager, database *databasePkg.Database, ) *AppManager { @@ -54,8 +55,8 @@ func NewAppManager( websocketManager := tendermint.NewWebsocketManager(managerLogger, config, metricsManager) reporters := []reportersPkg.Reporter{ - telegram.NewReporter(config, managerLogger, stateManager, metricsManager, snapshotManager), - discord.NewReporter(config, managerLogger, stateManager, metricsManager, snapshotManager), + telegram.NewReporter(config, version, managerLogger, stateManager, metricsManager, snapshotManager), + discord.NewReporter(config, version, managerLogger, stateManager, metricsManager, snapshotManager), } return &AppManager{ diff --git a/pkg/config/chain_test.go b/pkg/config/chain_test.go index 8b062ab..79f849d 100644 --- a/pkg/config/chain_test.go +++ b/pkg/config/chain_test.go @@ -3,6 +3,8 @@ package config import ( "testing" + "github.com/stretchr/testify/require" + "gopkg.in/guregu/null.v4" "github.com/stretchr/testify/assert" @@ -12,28 +14,28 @@ func TestGetChainNameWithoutPrettyName(t *testing.T) { t.Parallel() config := &ChainConfig{Name: "test"} - assert.Equal(t, config.GetName(), "test", "Names do not match!") + assert.Equal(t, "test", config.GetName(), "Names do not match!") } func TestGetChainNameWithPrettyName(t *testing.T) { t.Parallel() config := &ChainConfig{Name: "test", PrettyName: "Test"} - assert.Equal(t, config.GetName(), "Test", "Names do not match!") + assert.Equal(t, "Test", config.GetName(), "Names do not match!") } func TestGetChainBlocksSignCount(t *testing.T) { t.Parallel() config := &ChainConfig{BlocksWindow: 10000, MinSignedPerWindow: 0.05} - assert.Equal(t, config.GetBlocksSignCount(), int64(9500), "Blocks sign count does not match!") + assert.Equal(t, int64(9500), config.GetBlocksSignCount(), "Blocks sign count does not match!") } func TestGetChainBlocksMissCount(t *testing.T) { t.Parallel() config := &ChainConfig{BlocksWindow: 10000, MinSignedPerWindow: 0.05} - assert.Equal(t, config.GetBlocksMissCount(), int64(500), "Blocks miss count does not match!") + assert.Equal(t, int64(500), config.GetBlocksMissCount(), "Blocks miss count does not match!") } func TestValidateChainWithoutName(t *testing.T) { @@ -41,7 +43,7 @@ func TestValidateChainWithoutName(t *testing.T) { config := &ChainConfig{} err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateChainWithoutRPCEndpoints(t *testing.T) { @@ -49,7 +51,7 @@ func TestValidateChainWithoutRPCEndpoints(t *testing.T) { config := &ChainConfig{Name: "chain"} err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateConsumerChainWithoutProviderEndpoints(t *testing.T) { @@ -61,7 +63,7 @@ func TestValidateConsumerChainWithoutProviderEndpoints(t *testing.T) { IsConsumer: null.BoolFrom(true), } err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateConsumerChainWithoutChainID(t *testing.T) { @@ -74,7 +76,7 @@ func TestValidateConsumerChainWithoutChainID(t *testing.T) { ProviderRPCEndpoints: []string{"endpoint"}, } err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateNotEnoughThresholds(t *testing.T) { @@ -87,7 +89,7 @@ func TestValidateNotEnoughThresholds(t *testing.T) { EmojisEnd: []string{"x"}, } err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateNotEnoughStartEmojis(t *testing.T) { @@ -100,7 +102,7 @@ func TestValidateNotEnoughStartEmojis(t *testing.T) { EmojisEnd: []string{"x", "y"}, } err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateNotEnoughEndEmojis(t *testing.T) { @@ -113,7 +115,7 @@ func TestValidateNotEnoughEndEmojis(t *testing.T) { EmojisEnd: []string{"x"}, } err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateFirstThresholdNotZero(t *testing.T) { @@ -126,7 +128,7 @@ func TestValidateFirstThresholdNotZero(t *testing.T) { EmojisEnd: []string{"x", "y"}, } err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateLastThresholdNotHundred(t *testing.T) { @@ -139,7 +141,7 @@ func TestValidateLastThresholdNotHundred(t *testing.T) { EmojisEnd: []string{"x", "y"}, } err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateThresholdsInconsistent(t *testing.T) { @@ -152,7 +154,7 @@ func TestValidateThresholdsInconsistent(t *testing.T) { EmojisEnd: []string{"x", "y", "z"}, } err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateChainValid(t *testing.T) { @@ -165,7 +167,7 @@ func TestValidateChainValid(t *testing.T) { EmojisEnd: []string{"x", "y"}, } err := config.Validate() - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") } func TestValidateConsumerChainWithoutEndpoints(t *testing.T) { @@ -182,7 +184,7 @@ func TestValidateConsumerChainWithoutEndpoints(t *testing.T) { EmojisEnd: []string{"x", "y"}, } err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateConsumerChainWithoutChainId(t *testing.T) { @@ -199,7 +201,7 @@ func TestValidateConsumerChainWithoutChainId(t *testing.T) { EmojisEnd: []string{"x", "y"}, } err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateConsumerChainValid(t *testing.T) { @@ -216,5 +218,5 @@ func TestValidateConsumerChainValid(t *testing.T) { EmojisEnd: []string{"x", "y"}, } err := config.Validate() - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") } diff --git a/pkg/config/database_test.go b/pkg/config/database_test.go index 3af0578..4dbf694 100644 --- a/pkg/config/database_test.go +++ b/pkg/config/database_test.go @@ -3,7 +3,7 @@ package config import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestValidateDatabaseConfigWithoutPath(t *testing.T) { @@ -11,7 +11,7 @@ func TestValidateDatabaseConfigWithoutPath(t *testing.T) { config := &DatabaseConfig{Type: "sqlite"} err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateDatabaseConfigWithoutType(t *testing.T) { @@ -19,7 +19,7 @@ func TestValidateDatabaseConfigWithoutType(t *testing.T) { config := &DatabaseConfig{Path: "path"} err := config.Validate() - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestValidateDatabaseConfigOk(t *testing.T) { @@ -27,5 +27,5 @@ func TestValidateDatabaseConfigOk(t *testing.T) { config := &DatabaseConfig{Path: "path", Type: "sqlite"} err := config.Validate() - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") } diff --git a/pkg/config/missed_blocks_group_test.go b/pkg/config/missed_blocks_group_test.go index 3d24f66..fa65a81 100644 --- a/pkg/config/missed_blocks_group_test.go +++ b/pkg/config/missed_blocks_group_test.go @@ -3,7 +3,7 @@ package config import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestMissedBlocksGroupEmpty(t *testing.T) { @@ -11,7 +11,7 @@ func TestMissedBlocksGroupEmpty(t *testing.T) { groups := MissedBlocksGroups{} err := groups.Validate(10000) - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestMissedBlocksGroupMissingStart(t *testing.T) { @@ -21,7 +21,7 @@ func TestMissedBlocksGroupMissingStart(t *testing.T) { {Start: 5000, End: 10000}, } err := groups.Validate(10000) - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestMissedBlocksGroupMissingEnd(t *testing.T) { @@ -31,7 +31,7 @@ func TestMissedBlocksGroupMissingEnd(t *testing.T) { {Start: 0, End: 5000}, } err := groups.Validate(10000) - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestMissedBlocksGroupGaps(t *testing.T) { @@ -42,7 +42,7 @@ func TestMissedBlocksGroupGaps(t *testing.T) { {Start: 9000, End: 10000}, } err := groups.Validate(10000) - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestMissedBlocksValid(t *testing.T) { @@ -53,5 +53,5 @@ func TestMissedBlocksValid(t *testing.T) { {Start: 5000, End: 10000}, } err := groups.Validate(10000) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") } diff --git a/pkg/reporters/discord/discord.go b/pkg/reporters/discord/discord.go index e6f9128..4c2d666 100644 --- a/pkg/reporters/discord/discord.go +++ b/pkg/reporters/discord/discord.go @@ -22,6 +22,8 @@ type Reporter struct { Guild string Channel string + Version string + DiscordSession *discordgo.Session Logger zerolog.Logger Config *config.ChainConfig @@ -34,6 +36,7 @@ type Reporter struct { func NewReporter( chainConfig *config.ChainConfig, + version string, logger zerolog.Logger, manager *statePkg.Manager, metricsManager *metrics.Manager, @@ -50,6 +53,7 @@ func NewReporter( SnapshotManager: snapshotManager, TemplatesManager: templatesPkg.NewManager(logger, constants.DiscordReporterName), Commands: make(map[string]*Command, 0), + Version: version, } } diff --git a/pkg/reporters/discord/help.go b/pkg/reporters/discord/help.go index fb2d410..8bea503 100644 --- a/pkg/reporters/discord/help.go +++ b/pkg/reporters/discord/help.go @@ -15,7 +15,10 @@ func (reporter *Reporter) GetHelpCommand() *Command { Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { reporter.MetricsManager.LogReporterQuery(reporter.Config.Name, constants.DiscordReporterName, "help") - template, err := reporter.TemplatesManager.Render("Help", reporter.Commands) + template, err := reporter.TemplatesManager.Render("Help", helpRender{ + Version: reporter.Version, + Commands: reporter.Commands, + }) if err != nil { reporter.Logger.Error().Err(err).Str("template", "help").Msg("Error rendering template") return diff --git a/pkg/reporters/discord/types.go b/pkg/reporters/discord/types.go index 89e532f..cda706f 100644 --- a/pkg/reporters/discord/types.go +++ b/pkg/reporters/discord/types.go @@ -85,3 +85,8 @@ type statusRender struct { func (s statusRender) FormatNotSignedPercent(entry statusEntry) string { return fmt.Sprintf("%.2f", float64(entry.SigningInfo.GetNotSigned())/float64(s.ChainConfig.BlocksWindow)*100) } + +type helpRender struct { + Version string + Commands map[string]*Command +} diff --git a/pkg/reporters/reporter.go b/pkg/reporters/reporter.go index 6126d87..adde888 100644 --- a/pkg/reporters/reporter.go +++ b/pkg/reporters/reporter.go @@ -10,5 +10,5 @@ type Reporter interface { Name() constants.ReporterName Enabled() bool SerializeEvent(event types.ReportEvent) types.RenderEventItem - Send(*types.Report) error + Send(report *types.Report) error } diff --git a/pkg/reporters/telegram/help.go b/pkg/reporters/telegram/help.go index 2a7ea46..471df7c 100644 --- a/pkg/reporters/telegram/help.go +++ b/pkg/reporters/telegram/help.go @@ -14,7 +14,7 @@ func (reporter *Reporter) HandleHelp(c tele.Context) error { reporter.MetricsManager.LogReporterQuery(reporter.Config.Name, constants.TelegramReporterName, "help") - template, err := reporter.TemplatesManager.Render("Help", nil) + template, err := reporter.TemplatesManager.Render("Help", reporter.Version) if err != nil { return err } diff --git a/pkg/reporters/telegram/telegram.go b/pkg/reporters/telegram/telegram.go index 8f4aafb..930c86b 100644 --- a/pkg/reporters/telegram/telegram.go +++ b/pkg/reporters/telegram/telegram.go @@ -24,6 +24,8 @@ type Reporter struct { Chat int64 Admins []int64 + Version string + TelegramBot *tele.Bot Logger zerolog.Logger Config *config.ChainConfig @@ -39,6 +41,7 @@ const ( func NewReporter( chainConfig *config.ChainConfig, + version string, logger zerolog.Logger, manager *statePkg.Manager, metricsManager *metrics.Manager, @@ -54,6 +57,7 @@ func NewReporter( MetricsManager: metricsManager, SnapshotManager: snapshotManager, TemplatesManager: templatesPkg.NewManager(logger, constants.TelegramReporterName), + Version: version, } } diff --git a/pkg/reporters/telegram/unsubscribe.go b/pkg/reporters/telegram/unsubscribe.go index d9ea652..c3846e6 100644 --- a/pkg/reporters/telegram/unsubscribe.go +++ b/pkg/reporters/telegram/unsubscribe.go @@ -4,6 +4,7 @@ import ( "fmt" "html" "main/pkg/constants" + "strconv" "strings" tele "gopkg.in/telebot.v3" @@ -35,7 +36,7 @@ func (reporter *Reporter) HandleUnsubscribe(c tele.Context) error { )) } - removed := reporter.Manager.RemoveNotifier(address, reporter.Name(), fmt.Sprintf("%d", c.Sender().ID)) + removed := reporter.Manager.RemoveNotifier(address, reporter.Name(), strconv.FormatInt(c.Sender().ID, 10)) if !removed { return reporter.BotReply(c, "You are not subscribed to this validator's notifications") diff --git a/pkg/snapshot/manager_test.go b/pkg/snapshot/manager_test.go index 2f5329a..f21088d 100644 --- a/pkg/snapshot/manager_test.go +++ b/pkg/snapshot/manager_test.go @@ -7,6 +7,8 @@ import ( "main/pkg/types" "testing" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "gopkg.in/guregu/null.v4" ) @@ -47,10 +49,10 @@ func TestManagerCommitNewSnapshot(t *testing.T) { }) assert.True(t, manager.HasNewerSnapshot(), "Should not have older snapshot!") - assert.Equal(t, manager.GetOlderHeight(), int64(10), "Height mismatch!") + assert.Equal(t, int64(10), manager.GetOlderHeight(), "Height mismatch!") report, err := manager.GetReport() - assert.Nil(t, err, "Error should not be presented!") + require.NoError(t, err, "Error should not be presented!") assert.True(t, report.Empty(), "Report should be empty!") } diff --git a/pkg/snapshot/snapshot_test.go b/pkg/snapshot/snapshot_test.go index 95d3eaf..28543ea 100644 --- a/pkg/snapshot/snapshot_test.go +++ b/pkg/snapshot/snapshot_test.go @@ -5,6 +5,8 @@ import ( "main/pkg/constants" "testing" + "github.com/stretchr/testify/require" + "main/pkg/types" "github.com/stretchr/testify/assert" @@ -19,9 +21,9 @@ func TestValidatorCreated(t *testing.T) { }} report, err := newerSnapshot.GetReport(olderSnapshot, nil) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.Len(t, report.Events, 1, "Report should have 1 entry!") - assert.Equal(t, report.Events[0].Type(), constants.EventValidatorCreated, 1, "ReportEvent type mismatch!") + assert.Equal(t, constants.EventValidatorCreated, report.Events[0].Type(), 1, "ReportEvent type mismatch!") } func TestValidatorGroupChanged(t *testing.T) { @@ -48,10 +50,10 @@ func TestValidatorGroupChanged(t *testing.T) { }} report, err := newerSnapshot.GetReport(olderSnapshot, config) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.NotEmpty(t, report.Events, "Report should not be empty!") assert.Len(t, report.Events, 1, "Report should have exactly 1 entry!") - assert.Equal(t, report.Events[0].Type(), constants.EventValidatorGroupChanged, 1, "ReportEvent type mismatch!") + assert.Equal(t, constants.EventValidatorGroupChanged, report.Events[0].Type(), 1, "ReportEvent type mismatch!") } func TestValidatorTombstoned(t *testing.T) { @@ -78,11 +80,11 @@ func TestValidatorTombstoned(t *testing.T) { }} report, err := newerSnapshot.GetReport(olderSnapshot, config) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.NotEmpty(t, report.Events, "Report should not be empty!") assert.Len(t, report.Events, 1, "Report should have exactly 1 entry!") - assert.Equal(t, report.Events[0].Type(), constants.EventValidatorTombstoned, 1, "ReportEvent type mismatch!") + assert.Equal(t, constants.EventValidatorTombstoned, report.Events[0].Type(), 1, "ReportEvent type mismatch!") } func TestValidatorJailed(t *testing.T) { @@ -109,7 +111,7 @@ func TestValidatorJailed(t *testing.T) { }} report, err := newerSnapshot.GetReport(olderSnapshot, config) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.NotEmpty(t, report.Events, "Report should not be empty!") assert.Len(t, report.Events, 2, "Report should have exactly 2 entries!") @@ -147,11 +149,11 @@ func TestValidatorUnjailed(t *testing.T) { }} report, err := newerSnapshot.GetReport(olderSnapshot, config) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.NotEmpty(t, report.Events, "Report should not be empty!") assert.Len(t, report.Events, 1, "Report should have exactly 1 entry!") - assert.Equal(t, report.Events[0].Type(), constants.EventValidatorUnjailed, 1, "ReportEvent type mismatch!") + assert.Equal(t, constants.EventValidatorUnjailed, report.Events[0].Type(), 1, "ReportEvent type mismatch!") } func TestValidatorInactive(t *testing.T) { @@ -178,10 +180,10 @@ func TestValidatorInactive(t *testing.T) { }} report, err := newerSnapshot.GetReport(olderSnapshot, config) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.NotEmpty(t, report.Events, "Report should not be empty!") assert.Len(t, report.Events, 1, "Report should have exactly 1 entry!") - assert.Equal(t, report.Events[0].Type(), constants.EventValidatorInactive, 1, "ReportEvent type mismatch!") + assert.Equal(t, constants.EventValidatorInactive, report.Events[0].Type(), 1, "ReportEvent type mismatch!") } func TestValidatorActive(t *testing.T) { @@ -208,10 +210,10 @@ func TestValidatorActive(t *testing.T) { }} report, err := newerSnapshot.GetReport(olderSnapshot, config) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.NotEmpty(t, report.Events, "Report should not be empty!") assert.Len(t, report.Events, 1, "Report should have exactly 1 entry!") - assert.Equal(t, report.Events[0].Type(), constants.EventValidatorActive, 1, "ReportEvent type mismatch!") + assert.Equal(t, constants.EventValidatorActive, report.Events[0].Type(), 1, "ReportEvent type mismatch!") } func TestValidatorJailedAndChangedGroup(t *testing.T) { @@ -238,7 +240,7 @@ func TestValidatorJailedAndChangedGroup(t *testing.T) { }} report, err := newerSnapshot.GetReport(olderSnapshot, config) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.Empty(t, report.Events, "Report should be empty!") } @@ -270,7 +272,7 @@ func TestTombstonedAndNoPreviousSigningInfo(t *testing.T) { }} report, err := newerSnapshot.GetReport(olderSnapshot, config) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.Empty(t, report.Events, "Report should be empty!") } @@ -287,7 +289,7 @@ func TestToSlice(t *testing.T) { slice := entries.ToSlice() assert.NotEmpty(t, slice, "Slice should not be empty!") assert.Len(t, slice, 1, "Slice should have exactly 1 entry!") - assert.Equal(t, slice[0].Validator.Moniker, "test", 1, "Validator name mismatch!") + assert.Equal(t, "test", slice[0].Validator.Moniker, 1, "Validator name mismatch!") } func TestNewMissedBlocksGroupNotPresent(t *testing.T) { @@ -314,7 +316,7 @@ func TestNewMissedBlocksGroupNotPresent(t *testing.T) { }} report, err := newerSnapshot.GetReport(olderSnapshot, config) - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") assert.Nil(t, report, "Report should not be present!") } @@ -342,7 +344,7 @@ func TestOldMissedBlocksGroupNotPresent(t *testing.T) { }} report, err := newerSnapshot.GetReport(olderSnapshot, config) - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") assert.Nil(t, report, "Report should not be present!") } @@ -386,12 +388,12 @@ func TestSorting(t *testing.T) { }} report, err := newerSnapshot.GetReport(olderSnapshot, config) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.NotNil(t, report, "Report should be present!") assert.Len(t, report.Events, 3, "Slice should have exactly 3 entries!") - assert.Equal(t, report.Events[0].Type(), constants.EventValidatorTombstoned, "ReportEvent type mismatch!") - assert.Equal(t, report.Events[1].Type(), constants.EventValidatorJailed, "ReportEvent type mismatch!") - assert.Equal(t, report.Events[2].Type(), constants.EventValidatorGroupChanged, "ReportEvent type mismatch!") + assert.Equal(t, constants.EventValidatorTombstoned, report.Events[0].Type(), "ReportEvent type mismatch!") + assert.Equal(t, constants.EventValidatorJailed, report.Events[1].Type(), "ReportEvent type mismatch!") + assert.Equal(t, constants.EventValidatorGroupChanged, report.Events[2].Type(), "ReportEvent type mismatch!") } func TestSortingMissedBlocksGroups(t *testing.T) { @@ -453,11 +455,11 @@ func TestSortingMissedBlocksGroups(t *testing.T) { // 4) validator4 recovering 75 -> 25 report, err := newerSnapshot.GetReport(olderSnapshot, config) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.NotNil(t, report, "Report should be present!") assert.Len(t, report.Events, 4, "Slice should have exactly 4 entries!") - assert.Equal(t, report.Events[0].GetValidator().OperatorAddress, "validator2", "Wrong validator!") - assert.Equal(t, report.Events[1].GetValidator().OperatorAddress, "validator1", "Wrong validator!") - assert.Equal(t, report.Events[2].GetValidator().OperatorAddress, "validator3", "Wrong validator!") - assert.Equal(t, report.Events[3].GetValidator().OperatorAddress, "validator4", "Wrong validator!") + assert.Equal(t, "validator2", report.Events[0].GetValidator().OperatorAddress, "Wrong validator!") + assert.Equal(t, "validator1", report.Events[1].GetValidator().OperatorAddress, "Wrong validator!") + assert.Equal(t, "validator3", report.Events[2].GetValidator().OperatorAddress, "Wrong validator!") + assert.Equal(t, "validator4", report.Events[3].GetValidator().OperatorAddress, "Wrong validator!") } diff --git a/pkg/state/blocks_test.go b/pkg/state/blocks_test.go index c4392f6..4fd02b2 100644 --- a/pkg/state/blocks_test.go +++ b/pkg/state/blocks_test.go @@ -11,10 +11,10 @@ func TestBlocksAddBlock(t *testing.T) { t.Parallel() state := NewState() - assert.Len(t, state.blocks.blocks, 0, "Blocks should have 0 entries!") + assert.Empty(t, state.blocks.blocks, "Blocks should have 0 entries!") state.AddBlock(&types.Block{Height: 10}) - assert.Len(t, state.blocks.blocks, 1, "Blocks should have 1 entry!") + assert.NotEmpty(t, state.blocks.blocks, "Blocks should have 1 entry!") } func TestBlocksGetLatestBlock(t *testing.T) { @@ -27,7 +27,7 @@ func TestBlocksGetLatestBlock(t *testing.T) { latest := state.blocks.GetLatestBlock() - assert.Equal(t, latest.Height, int64(30), "Height mismatch!") + assert.Equal(t, int64(30), latest.Height, "Height mismatch!") } func TestBlocksGetEarliestBlock(t *testing.T) { @@ -40,7 +40,7 @@ func TestBlocksGetEarliestBlock(t *testing.T) { latest := state.GetEarliestBlock() - assert.Equal(t, latest.Height, int64(10), "Height mismatch!") + assert.Equal(t, int64(10), latest.Height, "Height mismatch!") } func TestBlocksGetBlock(t *testing.T) { @@ -80,7 +80,7 @@ func TestBlocksGetCountSinceLatest(t *testing.T) { state.AddBlock(&types.Block{Height: 5}) count := state.GetBlocksCountSinceLatest(5) - assert.Equal(t, count, int64(3), "There should be 3 blocks!") + assert.Equal(t, int64(3), count, "There should be 3 blocks!") } func TestBlocksGetMissingSinceLatest(t *testing.T) { @@ -92,6 +92,7 @@ func TestBlocksGetMissingSinceLatest(t *testing.T) { state.AddBlock(&types.Block{Height: 5}) missing := state.GetMissingBlocksSinceLatest(5) + assert.Len(t, missing, 2, "There should be 3 blocks!") assert.Contains(t, missing, int64(2), "Blocks mismatch!") assert.Contains(t, missing, int64(4), "Blocks mismatch!") diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go index 2d8a0c8..5ce5bec 100644 --- a/pkg/state/state_test.go +++ b/pkg/state/state_test.go @@ -7,6 +7,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" ) @@ -15,7 +17,7 @@ func TestStateGetAddAndLatestBlock(t *testing.T) { state := NewState() state.AddBlock(&types.Block{Height: 10}) - assert.Equal(t, state.GetLastBlockHeight(), int64(10), "Height mismatch!") + assert.Equal(t, int64(10), state.GetLastBlockHeight(), "Height mismatch!") } func TestStateSetAndGetValidators(t *testing.T) { @@ -31,12 +33,12 @@ func TestStateSetAndGetValidators(t *testing.T) { validatorsFromState := state.GetValidators() assert.Len(t, validatorsFromState, 1, "Length mismatch!") - assert.Equal(t, validatorsFromState["address"].Moniker, "moniker", "Validator mismatch!") + assert.Equal(t, "moniker", validatorsFromState["address"].Moniker, "Validator mismatch!") validatorFromState, found := state.GetValidator("address") - assert.True(t, found, 1, "Validator should be present!") - assert.Equal(t, validatorFromState.Moniker, "moniker", "Validator mismatch!") + assert.True(t, found, "Validator should be present!") + assert.Equal(t, "moniker", validatorFromState.Moniker, "Validator mismatch!") } func TestAddNotifierIfExists(t *testing.T) { @@ -55,7 +57,7 @@ func TestAddNotifierIfExists(t *testing.T) { added := state.AddNotifier("address", constants.TelegramReporterName, "id", "notifier") assert.False(t, added, "Notifiers should not be added") - assert.Equal(t, state.notifiers.Length(), 1, "New notifier should not be added!") + assert.Equal(t, 1, state.notifiers.Length(), "New notifier should not be added!") } func TestAddNotifierIfNotExists(t *testing.T) { @@ -73,7 +75,7 @@ func TestAddNotifierIfNotExists(t *testing.T) { added := state.AddNotifier("address", constants.TelegramReporterName, "id2", "newnotifier") assert.True(t, added, "Notifiers should be added") - assert.Equal(t, state.notifiers.Length(), 2, "New notifier should be added!") + assert.Equal(t, 2, state.notifiers.Length(), "New notifier should be added!") } func TestGetNotifiersForReporter(t *testing.T) { @@ -96,8 +98,8 @@ func TestGetNotifiersForReporter(t *testing.T) { }) reporterNotifiers := state.GetNotifiersForReporter("address", constants.TestReporterName) - assert.Equal(t, len(reporterNotifiers), 1, "Should have 1 notifier") - assert.Equal(t, reporterNotifiers[0].UserName, "notifier2", "Should have 1 notifier") + assert.Len(t, reporterNotifiers, 1, "Should have 1 notifier") + assert.Equal(t, "notifier2", reporterNotifiers[0].UserName, "Should have 1 notifier") } func TestGetValidatorsForNotifier(t *testing.T) { @@ -121,7 +123,7 @@ func TestGetValidatorsForNotifier(t *testing.T) { validatorNotifiers := state.GetValidatorsForNotifier(constants.TestReporterName, "id1") assert.Len(t, validatorNotifiers, 1, "Should have 1 notifier") - assert.Equal(t, validatorNotifiers[0], "address1", "Should have 1 notifier") + assert.Equal(t, "address1", validatorNotifiers[0], "Should have 1 notifier") } func TestRemoveNotifierIfNotExists(t *testing.T) { @@ -139,7 +141,7 @@ func TestRemoveNotifierIfNotExists(t *testing.T) { removed := state.RemoveNotifier("address", constants.TelegramReporterName, "id") assert.False(t, removed, "Notifiers should not be removed") - assert.Equal(t, state.notifiers.Length(), 1, "New notifier should not be removed!") + assert.Equal(t, 1, state.notifiers.Length(), "New notifier should not be removed!") } func TestRemoveNotifierIfExists(t *testing.T) { @@ -157,7 +159,7 @@ func TestRemoveNotifierIfExists(t *testing.T) { removed := state.RemoveNotifier("address", constants.TelegramReporterName, "id") assert.True(t, removed, "Notifiers should be removed") - assert.Equal(t, state.notifiers.Length(), 0, "New notifier should be removed!") + assert.Equal(t, 0, state.notifiers.Length(), "New notifier should be removed!") } func TestGetBlockTime(t *testing.T) { @@ -176,7 +178,7 @@ func TestGetBlockTime(t *testing.T) { }) blockTime := state.GetBlockTime() - assert.Equal(t, blockTime, 1500*time.Millisecond, "Wrong block time!") + assert.Equal(t, 1500*time.Millisecond, blockTime, "Wrong block time!") } func TestGetTimeToJail(t *testing.T) { @@ -204,7 +206,7 @@ func TestGetTimeToJail(t *testing.T) { // block_time = 1.5s // validator missed 50 blocks and needs to skip 40 more to get jailed // 40 * 1.5 = 60s - assert.Equal(t, blockTime, 60*time.Second, "Wrong jail time!") + assert.Equal(t, 60*time.Second, blockTime, "Wrong jail time!") } func TestValidatorsMissedBlocksNoBlocks(t *testing.T) { @@ -213,11 +215,11 @@ func TestValidatorsMissedBlocksNoBlocks(t *testing.T) { validator := &types.Validator{} signature, err := state.GetValidatorMissedBlocks(validator, 5) - assert.NotNil(t, err, "Error should be present!") - assert.Equal(t, signature.Signed, int64(0), "Argument mismatch!") - assert.Equal(t, signature.NoSignature, int64(0), "Argument mismatch!") - assert.Equal(t, signature.NotSigned, int64(0), "Argument mismatch!") - assert.Equal(t, signature.NotActive, int64(0), "Argument mismatch!") + require.Error(t, err, "Error should be present!") + assert.Equal(t, int64(0), signature.Signed, "Argument mismatch!") + assert.Equal(t, int64(0), signature.NoSignature, "Argument mismatch!") + assert.Equal(t, int64(0), signature.NotSigned, "Argument mismatch!") + assert.Equal(t, int64(0), signature.NotActive, "Argument mismatch!") } func TestValidatorsMissedBlocksAllSigned(t *testing.T) { @@ -234,12 +236,12 @@ func TestValidatorsMissedBlocksAllSigned(t *testing.T) { signature, err := state.GetValidatorMissedBlocks(validator, 5) - assert.Nil(t, err, "Error should not be present!") - assert.Equal(t, signature.Signed, int64(5), "Argument mismatch!") - assert.Equal(t, signature.NoSignature, int64(0), "Argument mismatch!") - assert.Equal(t, signature.NotSigned, int64(0), "Argument mismatch!") - assert.Equal(t, signature.NotActive, int64(0), "Argument mismatch!") - assert.Equal(t, signature.Proposed, int64(1), "Argument mismatch!") + require.NoError(t, err, "Error should not be present!") + assert.Equal(t, int64(5), signature.Signed, "Argument mismatch!") + assert.Equal(t, int64(0), signature.NoSignature, "Argument mismatch!") + assert.Equal(t, int64(0), signature.NotSigned, "Argument mismatch!") + assert.Equal(t, int64(0), signature.NotActive, "Argument mismatch!") + assert.Equal(t, int64(1), signature.Proposed, "Argument mismatch!") } func TestValidatorsMissedBlocksAllMissed(t *testing.T) { @@ -256,12 +258,12 @@ func TestValidatorsMissedBlocksAllMissed(t *testing.T) { signature, err := state.GetValidatorMissedBlocks(validator, 5) - assert.Nil(t, err, "Error should not be present!") - assert.Equal(t, signature.Signed, int64(0), "Argument mismatch!") - assert.Equal(t, signature.NoSignature, int64(3), "Argument mismatch!") - assert.Equal(t, signature.NotSigned, int64(2), "Argument mismatch!") - assert.Equal(t, signature.NotActive, int64(0), "Argument mismatch!") - assert.Equal(t, signature.Proposed, int64(0), "Argument mismatch!") + require.NoError(t, err, "Error should not be present!") + assert.Equal(t, int64(0), signature.Signed, "Argument mismatch!") + assert.Equal(t, int64(3), signature.NoSignature, "Argument mismatch!") + assert.Equal(t, int64(2), signature.NotSigned, "Argument mismatch!") + assert.Equal(t, int64(0), signature.NotActive, "Argument mismatch!") + assert.Equal(t, int64(0), signature.Proposed, "Argument mismatch!") } func TestValidatorsMissedBlocksAllInactive(t *testing.T) { @@ -278,12 +280,12 @@ func TestValidatorsMissedBlocksAllInactive(t *testing.T) { signature, err := state.GetValidatorMissedBlocks(validator, 5) - assert.Nil(t, err, "Error should not be present!") - assert.Equal(t, signature.Signed, int64(0), "Argument mismatch!") - assert.Equal(t, signature.NoSignature, int64(0), "Argument mismatch!") - assert.Equal(t, signature.NotSigned, int64(0), "Argument mismatch!") - assert.Equal(t, signature.NotActive, int64(5), "Argument mismatch!") - assert.Equal(t, signature.Proposed, int64(0), "Argument mismatch!") + require.NoError(t, err, "Error should not be present!") + assert.Equal(t, int64(0), signature.Signed, "Argument mismatch!") + assert.Equal(t, int64(0), signature.NoSignature, "Argument mismatch!") + assert.Equal(t, int64(0), signature.NotSigned, "Argument mismatch!") + assert.Equal(t, int64(5), signature.NotActive, "Argument mismatch!") + assert.Equal(t, int64(0), signature.Proposed, "Argument mismatch!") } func TestValidatorsMissedBlocksSomeSkipped(t *testing.T) { @@ -303,10 +305,10 @@ func TestValidatorsMissedBlocksSomeSkipped(t *testing.T) { signature, err := state.GetValidatorMissedBlocks(validator, 5) - assert.Nil(t, err, "Error should not be present!") - assert.Equal(t, signature.Signed, int64(4), "Argument mismatch!") - assert.Equal(t, signature.NoSignature, int64(0), "Argument mismatch!") - assert.Equal(t, signature.NotSigned, int64(1), "Argument mismatch!") - assert.Equal(t, signature.NotActive, int64(1), "Argument mismatch!") - assert.Equal(t, signature.Proposed, int64(0), "Argument mismatch!") + require.NoError(t, err, "Error should not be present!") + assert.Equal(t, int64(4), signature.Signed, "Argument mismatch!") + assert.Equal(t, int64(0), signature.NoSignature, "Argument mismatch!") + assert.Equal(t, int64(1), signature.NotSigned, "Argument mismatch!") + assert.Equal(t, int64(1), signature.NotActive, "Argument mismatch!") + assert.Equal(t, int64(0), signature.Proposed, "Argument mismatch!") } diff --git a/pkg/templates/manager.go b/pkg/templates/manager.go index 755041c..24ffbff 100644 --- a/pkg/templates/manager.go +++ b/pkg/templates/manager.go @@ -10,12 +10,12 @@ import ( ) type Manager interface { - Render(string, interface{}) (string, error) + Render(templateName string, data interface{}) (string, error) SerializeLink(link types.Link) template.HTML SerializeDate(date time.Time) string SerializeNotifiers(notifiers types.Notifiers) string SerializeNotifier(notifier *types.Notifier) string - SerializeEvent(types.RenderEventItem) string + SerializeEvent(event types.RenderEventItem) string } func NewManager(logger zerolog.Logger, reporterType constants.ReporterName) Manager { diff --git a/pkg/types/block_test.go b/pkg/types/block_test.go index d838bda..a4b8d63 100644 --- a/pkg/types/block_test.go +++ b/pkg/types/block_test.go @@ -10,7 +10,7 @@ func TestBlockHash(t *testing.T) { t.Parallel() block := Block{Height: 123} - assert.Equal(t, block.Hash(), "block_123", "Wrong block hash!") + assert.Equal(t, "block_123", block.Hash(), "Wrong block hash!") } func TestBlockSetValidators(t *testing.T) { @@ -21,5 +21,5 @@ func TestBlockSetValidators(t *testing.T) { block.SetValidators(map[string]bool{"1": true}) assert.NotNil(t, block.Validators, "Validators should not be nil!") assert.Len(t, block.Validators, 1, "Validators length should be 1!") - assert.Equal(t, block.Validators["1"], true, "Validators mismatch!") + assert.True(t, block.Validators["1"], "Validators mismatch!") } diff --git a/pkg/types/responses/block_test.go b/pkg/types/responses/block_test.go index 0c5b545..2ef488a 100644 --- a/pkg/types/responses/block_test.go +++ b/pkg/types/responses/block_test.go @@ -4,6 +4,8 @@ import ( "encoding/json" "testing" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" ) @@ -15,7 +17,7 @@ func TestToBlockInvalid(t *testing.T) { } block, err := blockRaw.ToBlock() - assert.NotNil(t, err, "Error should be presented!") + require.Error(t, err, "Error should be presented!") assert.Nil(t, block, "Block should not be presented!") } @@ -33,12 +35,12 @@ func TestToBlockValid(t *testing.T) { } block, err := blockRaw.ToBlock() - assert.Nil(t, err, "Error should not be presented!") + require.NoError(t, err, "Error should not be presented!") assert.NotNil(t, block, "Block should be presented!") - assert.Equalf(t, block.Height, int64(100), "Block height mismatch!") + assert.Equalf(t, int64(100), block.Height, "Block height mismatch!") assert.Len(t, block.Signatures, 2, "Block should have 2 signatures!") - assert.Equal(t, block.Signatures["first"], int32(1), "Block signature mismatch!") - assert.Equal(t, block.Signatures["second"], int32(2), "Block signature mismatch!") + assert.Equal(t, int32(1), block.Signatures["first"], "Block signature mismatch!") + assert.Equal(t, int32(2), block.Signatures["second"], "Block signature mismatch!") } func TestBlockResponseUnmarshalJson(t *testing.T) { @@ -51,13 +53,13 @@ func TestBlockResponseUnmarshalJson(t *testing.T) { err := json.Unmarshal([]byte(successJSON), &blockResponse) - assert.Nil(t, err, "Should not error unmarshalling JSON!") + require.NoError(t, err, "Should not error unmarshalling JSON!") assert.Nil(t, blockResponse.Error, "Unmarshall mismatch!") assert.NotNil(t, blockResponse.Result, "Unmarshall mismatch!") err2 := json.Unmarshal([]byte(errorJSON), &blockResponse) - assert.Nil(t, err2, "Should not error unmarshalling JSON!") + require.NoError(t, err2, "Should not error unmarshalling JSON!") assert.NotNil(t, blockResponse.Error, "Unmarshall mismatch!") assert.Nil(t, blockResponse.Result, "Unmarshall mismatch!") } diff --git a/pkg/types/responses/validators_test.go b/pkg/types/responses/validators_test.go index a19f27f..6b187c1 100644 --- a/pkg/types/responses/validators_test.go +++ b/pkg/types/responses/validators_test.go @@ -4,6 +4,8 @@ import ( "encoding/json" "testing" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" ) @@ -17,13 +19,13 @@ func TestValidatorsResponseUnmarshalJson(t *testing.T) { err := json.Unmarshal([]byte(successJSON), &validatorsResponse) - assert.Nil(t, err, "Should not error unmarshalling JSON!") + require.NoError(t, err, "Should not error unmarshalling JSON!") assert.Nil(t, validatorsResponse.Error, "Unmarshall mismatch!") assert.NotNil(t, validatorsResponse.Result, "Unmarshall mismatch!") err2 := json.Unmarshal([]byte(errorJSON), &validatorsResponse) - assert.Nil(t, err2, "Should not error unmarshalling JSON!") + require.NoError(t, err2, "Should not error unmarshalling JSON!") assert.NotNil(t, validatorsResponse.Error, "Unmarshall mismatch!") assert.Nil(t, validatorsResponse.Result, "Unmarshall mismatch!") } diff --git a/pkg/types/types_test.go b/pkg/types/types_test.go index b88c677..0edf67a 100644 --- a/pkg/types/types_test.go +++ b/pkg/types/types_test.go @@ -16,8 +16,8 @@ func TestValidatorsToMap(t *testing.T) { validatorsMap := validators.ToMap() assert.Len(t, validatorsMap, 2, "Map should have 2 entries!") - assert.Equal(t, validatorsMap["firstaddr"].Moniker, "first", "Validator mismatch!") - assert.Equal(t, validatorsMap["secondaddr"].Moniker, "second", "Validator mismatch!") + assert.Equal(t, "first", validatorsMap["firstaddr"].Moniker, "Validator mismatch!") + assert.Equal(t, "second", validatorsMap["secondaddr"].Moniker, "Validator mismatch!") } func TestValidatorsToSlice(t *testing.T) { diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go index 2aa71ad..15cfaf9 100644 --- a/pkg/utils/utils_test.go +++ b/pkg/utils/utils_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" ) @@ -27,7 +29,7 @@ func TestFilter(t *testing.T) { }) assert.Len(t, filtered, 1, "Array should have 1 entry!") - assert.Equal(t, filtered[0], "true", "Value mismatch!") + assert.Equal(t, "true", filtered[0], "Value mismatch!") } func TestMap(t *testing.T) { @@ -39,8 +41,8 @@ func TestMap(t *testing.T) { }) assert.Len(t, filtered, 2, "Array should have 2 entries!") - assert.Equal(t, filtered[0], 4, "Value mismatch!") - assert.Equal(t, filtered[1], 8, "Value mismatch!") + assert.Equal(t, 4, filtered[0], "Value mismatch!") + assert.Equal(t, 8, filtered[1], "Value mismatch!") } func TestContains(t *testing.T) { @@ -81,15 +83,17 @@ func TestFormatDuration(t *testing.T) { duration := 24*time.Hour + 2*time.Hour + 3*time.Minute + 4*time.Second assert.Equal( - t, FormatDuration(duration), + t, "1 day 2 hours 3 minutes 4 seconds", + FormatDuration(duration), "Value mismatch!", ) anotherDuration := 24 * time.Hour assert.Equal( - t, FormatDuration(anotherDuration), + t, "1 day", + FormatDuration(anotherDuration), "Value mismatch!", ) } @@ -105,14 +109,14 @@ func TestCompareTwoBech32FirstInvalid(t *testing.T) { t.Parallel() _, err := CompareTwoBech32("test", "cosmos1xqz9pemz5e5zycaa89kys5aw6m8rhgsvtp9lt2") - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestCompareTwoBech32SecondInvalid(t *testing.T) { t.Parallel() _, err := CompareTwoBech32("cosmos1xqz9pemz5e5zycaa89kys5aw6m8rhgsvtp9lt2", "test") - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestCompareTwoBech32SecondEqual(t *testing.T) { @@ -122,7 +126,7 @@ func TestCompareTwoBech32SecondEqual(t *testing.T) { "cosmos1xqz9pemz5e5zycaa89kys5aw6m8rhgsvtp9lt2", "cosmosvaloper1xqz9pemz5e5zycaa89kys5aw6m8rhgsvw4328e", ) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.True(t, equal, "Bech addresses should be equal!") } @@ -133,14 +137,14 @@ func TestCompareTwoBech32SecondNotEqual(t *testing.T) { "cosmos1xqz9pemz5e5zycaa89kys5aw6m8rhgsvtp9lt2", "cosmos1c4k24jzduc365kywrsvf5ujz4ya6mwymy8vq4q", ) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.False(t, equal, "Bech addresses should not be equal!") } func TestCompareBoolToFloat64(t *testing.T) { t.Parallel() - assert.Equal(t, BoolToFloat64(true), float64(1), "Value mismatch!") - assert.Equal(t, BoolToFloat64(false), float64(0), "Value mismatch!") + assert.InDelta(t, BoolToFloat64(true), float64(1), 0.001, "Value mismatch!") + assert.InDelta(t, BoolToFloat64(false), float64(0), 0.001, "Value mismatch!") } func TestSplitIntoChunks(t *testing.T) { @@ -150,13 +154,13 @@ func TestSplitIntoChunks(t *testing.T) { chunks := SplitIntoChunks(array, 2) assert.Len(t, chunks, 3, "There should be 3 chunks!") - assert.Equal(t, chunks[0], []int{1, 2}, "Value mismatch!") - assert.Equal(t, chunks[1], []int{3, 4}, "Value mismatch!") - assert.Equal(t, chunks[2], []int{5}, "Value mismatch!") + assert.Equal(t, []int{1, 2}, chunks[0], "Value mismatch!") + assert.Equal(t, []int{3, 4}, chunks[1], "Value mismatch!") + assert.Equal(t, []int{5}, chunks[2], "Value mismatch!") anotherArray := []int{} anotherChunks := SplitIntoChunks(anotherArray, 2) - assert.Len(t, anotherChunks, 0, "There should be 0 chunks!") + assert.Empty(t, anotherChunks, "There should be 0 chunks!") } func TestSplitStringIntoChunksLessThanOneChunk(t *testing.T) { @@ -191,7 +195,7 @@ func TestConvertBech32PrefixInvalid(t *testing.T) { "test", "cosmosvaloper", ) - assert.NotNil(t, err, "Error should be present!") + require.Error(t, err, "Error should be present!") } func TestConvertBech32PrefixValid(t *testing.T) { @@ -201,11 +205,11 @@ func TestConvertBech32PrefixValid(t *testing.T) { "cosmos1xqz9pemz5e5zycaa89kys5aw6m8rhgsvtp9lt2", "cosmosvaloper", ) - assert.Nil(t, err, "Error should not be present!") + require.NoError(t, err, "Error should not be present!") assert.Equal( t, - address, "cosmosvaloper1xqz9pemz5e5zycaa89kys5aw6m8rhgsvw4328e", + address, "Bech addresses should not be equal!", ) } @@ -213,13 +217,13 @@ func TestConvertBech32PrefixValid(t *testing.T) { func TestMaxInt64(t *testing.T) { t.Parallel() - assert.Equal(t, MaxInt64(1, 2), int64(2), "Value mismatch!") - assert.Equal(t, MaxInt64(2, 1), int64(2), "Value mismatch!") + assert.Equal(t, int64(2), MaxInt64(1, 2), "Value mismatch!") + assert.Equal(t, int64(2), MaxInt64(2, 1), "Value mismatch!") } func TestMinInt64(t *testing.T) { t.Parallel() - assert.Equal(t, MinInt64(1, 2), int64(1), "Value mismatch!") - assert.Equal(t, MinInt64(2, 1), int64(1), "Value mismatch!") + assert.Equal(t, int64(1), MinInt64(1, 2), "Value mismatch!") + assert.Equal(t, int64(1), MinInt64(2, 1), "Value mismatch!") } diff --git a/templates/discord/Help.md b/templates/discord/Help.md index 5762d00..2b78b78 100644 --- a/templates/discord/Help.md +++ b/templates/discord/Help.md @@ -1,4 +1,4 @@ -[missed-blocks-checker]() +[missed-blocks-checker]() v{{ .Version }} This bot can monitor missing blocks for validators on multiple Cosmos chains, subscribing to the notifications on multiple validators, and many more. @@ -6,11 +6,11 @@ subscribing to the notifications on multiple validators, and many more. Created by [🐹 Quokka Stake]() with ❤️. The bot can understand the following commands: -- - display this message -- [validator address] - subscribe to validator's notifications -- [validator address] - unsubscribe from validator's notifications -- - see the notification on validators you are subscribed to +- - display this message +- [validator address] - subscribe to validator's notifications +- [validator address] - unsubscribe from validator's notifications +- - see the notification on validators you are subscribed to - /missing - see the missed blocks counter of validators missing blocks - /validators - see the missed blocks counter of all validators -- - see the app config and chain params -- - see notifiers for each validator +- - see the app config and chain params +- - see notifiers for each validator diff --git a/templates/telegram/Help.html b/templates/telegram/Help.html index 96e05d5..22a4d9e 100644 --- a/templates/telegram/Help.html +++ b/templates/telegram/Help.html @@ -1,4 +1,4 @@ -missed-blocks-checker +missed-blocks-checker v {{ . }} This bot can monitor missing blocks for validators on multiple Cosmos chains, subscribing to the notifications on multiple validators, and many more.