Skip to content

Commit

Permalink
chore: add fetchers test (#63)
Browse files Browse the repository at this point in the history
* chore: add balance fetcher test

* chore: improve test

* chore: add nop logger and use it in tests

* chore: add commission fetcher test

* chore: test init with multiple chains

* chore: add rewards fetcher test

* chore: pass config.Chains only to fetchers

* chore: add self delegation fetcher test

* chore: add delegations fetcher test

* chore: add unbonds fetcher test

* chore: add staking params fetcher test

* chore: add slashing params fetcher test

* chore: add consumers to staking params

* chore: add validators fetcher test

* chore: add soft opt-out threshold fetcher test

* chore: add node info fetcher test

* chore: do not init consumers on delegations fetcher

* chore: add signing info fetcher

* chore: add consumer validators fetcher

* chore: add consumer info fetcher

* chore: add price fetcher test, removed dex screener

* chore: probably fixed go.mod thing

* chore: some more tests
  • Loading branch information
freak12techno authored Jun 23, 2024
1 parent ca3df04 commit 0485a96
Show file tree
Hide file tree
Showing 63 changed files with 4,595 additions and 2,240 deletions.
1 change: 1 addition & 0 deletions assets/assigned-key-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"consumer_address":""}
1 change: 1 addition & 0 deletions assets/assigned-key.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"consumer_address":"cosmosvalcons1w426hkttrwrve9mj77ld67lzgx5u9m8pyplqg2"}
12 changes: 12 additions & 0 deletions assets/balances.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"balances": [
{
"denom": "uatom",
"amount": "596250"
}
],
"pagination": {
"next_key": null,
"total": "1"
}
}
1 change: 1 addition & 0 deletions assets/coingecko.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cosmos":{"usd":6.71}}
10 changes: 10 additions & 0 deletions assets/commission.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"commission": {
"commission": [
{
"denom": "uatom",
"amount": "35387184.119122794099577747"
}
]
}
}
14 changes: 14 additions & 0 deletions assets/consumer-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"chains": [
{
"chain_id": "neutron-1",
"client_id": "07-tendermint-1119",
"top_N": 95,
"min_power_in_top_N": "287843",
"validators_power_cap": 0,
"validator_set_cap": 0,
"allowlist": [],
"denylist": []
}
]
}
1 change: 1 addition & 0 deletions assets/consumer-validators.json

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions assets/delegations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"delegation_responses": [
{
"delegation": {
"delegator_address": "cosmos1qqqrukxs0rfmk43wpr8j79r407mj8cylpf8ux0",
"validator_address": "cosmosvaloper1xqz9pemz5e5zycaa89kys5aw6m8rhgsvw4328e",
"shares": "51000000.000000000000000000"
},
"balance": {
"denom": "uatom",
"amount": "51000000"
}
}
],
"pagination": {
"next_key": "FABpS2OZU5S9Lm9OifjQ+7igOjicFDAEUOdipmgiY705bEhTrtbOO6IM",
"total": "1729"
}
}
5 changes: 5 additions & 0 deletions assets/error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"code":12,
"message":"Not Implemented",
"details":[]
}
9 changes: 9 additions & 0 deletions assets/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ import (

//go:embed *
var EmbedFS embed.FS

func GetBytesOrPanic(path string) []byte {
bytes, err := EmbedFS.ReadFile(path)
if err != nil {
panic(err)
}

return bytes
}
19 changes: 19 additions & 0 deletions assets/fs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package assets

import (
"testing"

"github.com/stretchr/testify/require"
)

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

defer func() {
if r := recover(); r == nil {
require.Fail(t, "Expected to have a panic here!")
}
}()

GetBytesOrPanic("not-existing")
}
1 change: 1 addition & 0 deletions assets/node-info.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions assets/rewards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rewards": [
{
"denom": "uatom",
"amount": "690574.020284639200000000"
}
]
}
13 changes: 13 additions & 0 deletions assets/self-delegation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"delegation_response": {
"delegation": {
"delegator_address": "cosmos1xqz9pemz5e5zycaa89kys5aw6m8rhgsvtp9lt2",
"validator_address": "cosmosvaloper1xqz9pemz5e5zycaa89kys5aw6m8rhgsvw4328e",
"shares": "200000000.000000000000000000"
},
"balance": {
"denom": "uatom",
"amount": "200000000"
}
}
}
1 change: 1 addition & 0 deletions assets/signing-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"val_signing_info":{"address":"cosmosvalcons1rt4g447zhv6jcqwdl447y88guwm0eevnrelgzc","start_height":"14778937","index_offset":"5662147","jailed_until":"1970-01-01T00:00:00Z","tombstoned":false,"missed_blocks_counter":"8"}}
9 changes: 9 additions & 0 deletions assets/slashing-params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"params": {
"signed_blocks_window": "10000",
"min_signed_per_window": "0.050000000000000000",
"downtime_jail_duration": "600s",
"slash_fraction_double_sign": "0.050000000000000000",
"slash_fraction_downtime": "0.000100000000000000"
}
}
1 change: 1 addition & 0 deletions assets/soft-opt-out-threshold-invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"param":{"subspace":"ccvconsumer","key":"SoftOptOutThreshold","value":"\"test\""}}
1 change: 1 addition & 0 deletions assets/soft-opt-out-threshold.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"param":{"subspace":"ccvconsumer","key":"SoftOptOutThreshold","value":"\"0.05\""}}
13 changes: 13 additions & 0 deletions assets/staking-params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"params": {
"unbonding_time": "1814400s",
"max_validators": 180,
"max_entries": 7,
"historical_entries": 10000,
"bond_denom": "uatom",
"min_commission_rate": "0.050000000000000000",
"validator_bond_factor": "250.000000000000000000",
"global_liquid_staking_cap": "0.250000000000000000",
"validator_liquid_staking_cap": "1.000000000000000000"
}
}
22 changes: 22 additions & 0 deletions assets/unbonds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"unbonding_responses": [
{
"delegator_address": "cosmos1zse8yqt0h9v67jw2e4h0wttwcuvtg3wvn699ax",
"validator_address": "cosmosvaloper1xqz9pemz5e5zycaa89kys5aw6m8rhgsvw4328e",
"entries": [
{
"creation_height": "20753212",
"completion_time": "2024-06-27T21:21:52.380941282Z",
"initial_balance": "44670000",
"balance": "44670000",
"unbonding_id": "731559",
"unbonding_on_hold_ref_count": "1"
}
]
}
],
"pagination": {
"next_key": "FBd69Kj/w6D0COaUv3igceWwNCRf",
"total": "14"
}
}
1 change: 1 addition & 0 deletions assets/validators.json

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ provider-lcd-endpoint = ""
# 1. coingecko-currency
# Coingecko currency, specify it if you want to also get the wallet balance
# in total in USD. Optional.
# 2. dex-screener-chain-id and dex-screener-pair.
# dexscreener.com's chain ID (usually "osmosis") and pair (usually pool ID).
# Won't be used if coingecko-currency is provided.
# Either coingecko-currency or these two params are required for getting token price.
# 3. denom
# 2. denom
# The actual denom value (such as "uatom" for Cosmos Hub or "ibc/xxxxx" for IBC denoms). Required.
# 4. display-denom
# 3. display-denom
# The denom that'll be returned in labels. Required.
# 5. denom-coefficient
# 4. denom-coefficient
# The coefficient you need to multiply base denom to to get 1 token on Coingecko/DexScreener.
# Is exposed by `cosmos_validators_exporter_denom_coefficient` metric.
# Optional, defaults to 1_000_000.
Expand All @@ -62,7 +58,7 @@ provider-lcd-endpoint = ""
# which you can use to display a worthwhile of your unclaimed commission and use display-denom
# label for legend.
denoms = [
{ denom = "uatom", display-denom = "atom", coingecko-currency = "cosmos", denom-coefficient = 1000000, dex-screener-chain-id = "osmosis", dex-screener-pair = "1" },
{ denom = "uatom", display-denom = "atom", coingecko-currency = "cosmos", denom-coefficient = 1000000 },
]
# Bech32 prefix for a wallet address (example: "cosmos" for a Cosmos wallet). If omitted,
# the self-delegation metric will not be present.
Expand Down
Loading

0 comments on commit 0485a96

Please sign in to comment.