Skip to content

Commit

Permalink
CI script: Test /chain/XXX/supply (#333)
Browse files Browse the repository at this point in the history
* ci script for mint params

* add ci test for chain supply

* removed mint params
  • Loading branch information
PrathyushaLakkireddy authored Dec 13, 2021
1 parent 3639e32 commit e9cfbef
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/chains/chain_supply_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package tests

import (
"encoding/json"
"fmt"
"net/http"
"os"
"testing"

"github.com/stretchr/testify/require"

utils "github.com/allinbits/demeris-backend/test_utils"
sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
chainSupplyEndpoint = "chain/%s/supply"
supplyKey = "supply"
)

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

// arrange
env := os.Getenv("ENV")
emIngress, _ := utils.LoadIngressInfo(env, t)
chains := utils.LoadChainsInfo(env, t)
client := utils.CreateNetClient(env, t)

for _, ch := range chains {
t.Run(ch.Name, func(t *testing.T) {

// arrange
url := fmt.Sprintf(baseUrl+chainSupplyEndpoint, emIngress.Protocol, emIngress.Host, emIngress.APIServerPath, ch.Name)
// act
resp, err := client.Get(url)
require.NoError(t, err)

defer resp.Body.Close()

// assert
if !ch.Enabled {
require.Equal(t, http.StatusBadRequest, resp.StatusCode, fmt.Sprintf("Chain %s HTTP code %d", ch.Name, resp.StatusCode))
} else {
require.Equal(t, http.StatusOK, resp.StatusCode, fmt.Sprintf("Chain %s HTTP code %d", ch.Name, resp.StatusCode))

var respValues map[string]interface{}
utils.RespBodyToMap(resp.Body, &respValues, t)

data, err := json.Marshal(respValues[supplyKey])
require.NoError(t, err)

var coins sdk.Coins
err = json.Unmarshal(data, &coins)
require.NoError(t, err)

//check if the repsonse is empty
require.NotEmpty(t, coins)
}
})
}
}

0 comments on commit e9cfbef

Please sign in to comment.