Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilkumarpilli committed Sep 25, 2024
1 parent d602eed commit fb4dc68
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions tests/systemtests/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"

"github.com/cosmos/cosmos-sdk/testutil"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

Expand Down Expand Up @@ -225,46 +226,56 @@ func TestBankGRPCQueries(t *testing.T) {
supplyUrl := baseurl + "/cosmos/bank/v1beta1/supply"

// as supply might change for each block, can't set complete expected output
expTotalSupplyOutput := `{"supply":[{"denom":"newdenom","amount":"10000000"},{"denom":"stake","amount"`
specificDenomOutput := fmt.Sprintf(`{"denom":"%s","amount":"%s"}`, newDenom, initialAmount)
// below output depends on block height and voting power
expTotalSupplyOutput := fmt.Sprintf(`{"supply":[%s,{"denom":"stake","amount":"2010000191"},{"denom":"testtoken","amount":"4000000000"}],"pagination":{"next_key":null,"total":"3"}}`, specificDenomOutput)
bogusDenomOutput := `{"denom":"foobar","amount":"0"}`

blockHeightHeader := "x-cosmos-block-height"
blockHeight := sut.CurrentHeight()

supplyTestCases := []GRPCTestCaseWithHeaders{
supplyTestCases := []struct {
name string
url string
headers map[string]string
expOut string
}{
{
"test GRPC total supply",
supplyUrl,
map[string]string{
blockHeightHeader: "1",
blockHeightHeader: fmt.Sprintf("%d", blockHeight),
},
expTotalSupplyOutput,
},
{
"test GRPC total supply of a specific denom",
supplyUrl + "/by_denom?denom=" + newDenom,
map[string]string{},
fmt.Sprintf(`{"amount":%s}`, specificDenomOutput),
specificDenomOutput,
},
{
"error when querying supply with height greater than block height",
supplyUrl,
map[string]string{
blockHeightHeader: fmt.Sprintf("%d", blockHeight+5),
},
`{"code":2, "message":"codespace sdk code 26: invalid height: cannot query with height in the future; please provide a valid height", "details":[]}`,
"invalid height",
},
{
"test GRPC total supply of a bogus denom",
supplyUrl + "/by_denom?denom=foobar",
map[string]string{},
fmt.Sprintf(`{"amount":%s}`, bogusDenomOutput),
bogusDenomOutput,
},
}

RunGRPCQueriesWithHeaders(t, supplyTestCases)
for _, tc := range supplyTestCases {
t.Run(tc.name, func(t *testing.T) {
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
require.NoError(t, err)
require.Contains(t, string(resp), tc.expOut)
})
}

// test denom metadata endpoint
denomMetadataUrl := baseurl + "/cosmos/bank/v1beta1/denoms_metadata"
Expand Down

0 comments on commit fb4dc68

Please sign in to comment.