Skip to content

Commit

Permalink
feature: add balances section in config (#553)
Browse files Browse the repository at this point in the history
* add balances section in config

* update test cases to add custom balances
  • Loading branch information
Anmol1696 authored Sep 12, 2024
1 parent 85f6073 commit b1db037
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
7 changes: 7 additions & 0 deletions starship/charts/devnet/templates/chains/cosmos/genesis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ spec:
echo "Create consensus key json file"
$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json
cat $CHAIN_DIR/config/consensus_key.json
echo "Add custom accounts and balances"
CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")
{{- range $balance := $chain.balances }}
echo "Adding balance to {{ $balance.address }}"
$CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account {{ $balance.address }} {{ $balance.amount }} --keyring-backend="test"
{{- end }}
resources: {{- include "devnet.node.resources" ( dict "node" $chain "context" $ ) | trim | nindent 12 }}
volumeMounts:
- mountPath: {{ $chain.home }}
Expand Down
18 changes: 18 additions & 0 deletions starship/charts/devnet/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,24 @@
"enabled",
"provider"
]
},
"balances": {
"type": "array",
"items": {
"type": "object",
"properties": {
"address": {
"type": "string"
},
"amount": {
"type": "string"
}
},
"required": [
"address",
"amount"
]
}
}
},
"additionalProperties": false,
Expand Down
6 changes: 6 additions & 0 deletions starship/tests/e2e/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Chain struct {
Faucet *Feature `name:"faucet" json:"faucet" yaml:"faucet"`
Ports Port `name:"ports" json:"ports" yaml:"ports"`
Genesis map[string]interface{} `name:"genesis" json:"genesis" yaml:"genesis"`
Balances []Balance `name:"balances" json:"balances" yaml:"balances"`
}

type Port struct {
Expand All @@ -18,6 +19,11 @@ type Port struct {
Faucet int `name:"faucet" json:"faucet" yaml:"faucet"`
}

type Balance struct {
Address string `name:"address" json:"address" yaml:"address"`
Amount string `name:"amount" json:"amount" yaml:"amount"`
}

type Relayer struct {
Name string `name:"name" json:"name" yaml:"name"`
Type string `name:"type" json:"type" yaml:"type"`
Expand Down
5 changes: 5 additions & 0 deletions starship/tests/e2e/configs/one-chain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ chains:
memory: 500M
faucet:
concurrency: 2
balances:
- address: osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5
amount: "2000000000000uosmo"
- address: osmo10eykchznjdn8jdlwaj5v9wvlmdsp6kxx7u0hv9
amount: "2000000000000uosmo"
genesis:
app_state:
staking:
Expand Down
37 changes: 37 additions & 0 deletions starship/tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,40 @@ func (s *TestSuite) TestRelayers_State() {
s.Require().Equal("success", data["status"].(string))
}
}

func (s *TestSuite) TestChains_Balances() {
if s.config.Chains[0].Ports.Rest == 0 {
s.T().Skip("skip staking params test for non-rest endpoint")
}
s.T().Log("running test for /cosmos/bank/v1beta1/balances/{address} endpoint for each chain")
if s.configFile != "configs/one-chain.yaml" {
s.T().Skip("skip tests for checking custom balances")
}

for _, chain := range s.config.Chains {
for _, balance := range chain.Balances {
url := fmt.Sprintf("http://0.0.0.0:%d/cosmos/bank/v1beta1/balances/%s", chain.Ports.Rest, balance.Address)

req, err := http.NewRequest(http.MethodGet, url, nil)
s.Require().NoError(err)

body := s.MakeRequest(req, 200)

// Parse the response body
data := map[string]interface{}{}
err = json.NewDecoder(body).Decode(&data)
s.Require().NoError(err)

// Check for exactly one balance in the response
balances, ok := data["balances"].([]interface{})
s.Require().True(ok, "balances should be an array")
s.Require().Len(balances, 1, "there should be exactly one balance")

// Check that the amount and denom match the `coins` in the config
balanceMap, ok := balances[0].(map[string]interface{})
s.Require().True(ok, "balance should be a map")
coins := fmt.Sprintf("%s%s", balanceMap["amount"], balanceMap["denom"])
s.Require().Equal(balance.Amount, coins, "balance mismatch for address %s", balance.Address)
}
}
}

0 comments on commit b1db037

Please sign in to comment.