From 87bcee9d24c1371544b195be1af59b6fa1f6811b Mon Sep 17 00:00:00 2001 From: Sergey Date: Mon, 15 Jul 2024 22:17:12 +0300 Subject: [PATCH] chore: add populate validator tests --- pkg/data_fetcher/populate_validator_test.go | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/pkg/data_fetcher/populate_validator_test.go b/pkg/data_fetcher/populate_validator_test.go index 34d3916..53a16f7 100644 --- a/pkg/data_fetcher/populate_validator_test.go +++ b/pkg/data_fetcher/populate_validator_test.go @@ -116,3 +116,56 @@ func TestDataFetcherFetchValidatorSuccessfullyFetched(t *testing.T) { require.NotNil(t, data) require.Equal(t, "cosmosvaloper1xqz9pemz5e5zycaa89kys5aw6m8rhgsvw4328e", data.OperatorAddress) } + +//nolint:paralleltest // disabled due to httpmock usage +func TestDataFetcherPopulateValidatorNotPresent(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + + config := &configPkg.AppConfig{ + Chains: types.Chains{ + {Name: "chain"}, + }, + Metrics: configPkg.MetricsConfig{Enabled: false}, + } + + filesystem := &fs.MockFs{} + logger := loggerPkg.GetNopLogger() + aliasManager := aliasManagerPkg.NewAliasManager(logger, config, filesystem) + metricsManager := metrics.NewManager(logger, config.Metrics) + dataFetcher := NewDataFetcher(logger, config, aliasManager, metricsManager) + + validator := &types.Link{Value: "address"} + + dataFetcher.PopulateValidator(config.Chains[0], validator) + require.Empty(t, validator.Title) +} + +func TestDataFetcherPopulateValidatorPresent(t *testing.T) { + t.Parallel() + + config := &configPkg.AppConfig{ + Chains: types.Chains{ + {Name: "chain"}, + }, + Metrics: configPkg.MetricsConfig{Enabled: false}, + AliasesPath: "path.toml", + } + + filesystem := &fs.MockFs{} + logger := loggerPkg.GetNopLogger() + aliasManager := aliasManagerPkg.NewAliasManager(logger, config, filesystem) + metricsManager := metrics.NewManager(logger, config.Metrics) + dataFetcher := NewDataFetcher(logger, config, aliasManager, metricsManager) + + dataFetcher.Cache.Set("chain_validator_address", &responses.Validator{ + Description: responses.ValidatorDescription{ + Moniker: "🐹 Quokka Stake", + }, + }) + + validator := &types.Link{Value: "address"} + + dataFetcher.PopulateValidator(config.Chains[0], validator) + require.Equal(t, "🐹 Quokka Stake", validator.Title) +}