Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: migrate e2e/mint to system tests #22294

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions tests/e2e/mint/cli_test.go

This file was deleted.

64 changes: 0 additions & 64 deletions tests/e2e/mint/grpc.go

This file was deleted.

50 changes: 0 additions & 50 deletions tests/e2e/mint/suite.go

This file was deleted.

98 changes: 98 additions & 0 deletions tests/systemtests/mint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package systemtests

import (
"fmt"
"net/http"
"testing"

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

func TestMintQueries(t *testing.T) {
// scenario: test mint grpc queries
// given a running chain

sut.ResetChain(t)
cli := NewCLIWrapper(t, sut, verbose)

sut.ModifyGenesisJSON(t,
func(genesis []byte) []byte {
state, err := sjson.Set(string(genesis), "app_state.mint.minter.inflation", "1.00")
require.NoError(t, err)
return []byte(state)
},
func(genesis []byte) []byte {
state, err := sjson.Set(string(genesis), "app_state.mint.params.inflation_max", "1.00")
require.NoError(t, err)
return []byte(state)
},
)

sut.StartChain(t)

sut.AwaitNextBlock(t)

baseurl := sut.APIAddress()
blockHeightHeader := "x-cosmos-block-height"
queryAtHeight := "1"

// TODO: check why difference in values when querying with height between v1 and v2
// ref: https://github.com/cosmos/cosmos-sdk/issues/22302
if isV2() {
queryAtHeight = "2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets open an issue about this so we dont forget it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #22302

}

paramsResp := `{"params":{"mint_denom":"stake","inflation_rate_change":"0.130000000000000000","inflation_max":"1.000000000000000000","inflation_min":"0.000000000000000000","goal_bonded":"0.670000000000000000","blocks_per_year":"6311520","max_supply":"0"}}`
inflationResp := `{"inflation":"1.000000000000000000"}`
annualProvisionsResp := `{"annual_provisions":"2000000000.000000000000000000"}`

testCases := []struct {
name string
url string
headers map[string]string
expOut string
}{
{
"gRPC request params",
fmt.Sprintf("%s/cosmos/mint/v1beta1/params", baseurl),
map[string]string{},
paramsResp,
},
{
"gRPC request inflation",
fmt.Sprintf("%s/cosmos/mint/v1beta1/inflation", baseurl),
map[string]string{},
inflationResp,
},
{
"gRPC request annual provisions",
fmt.Sprintf("%s/cosmos/mint/v1beta1/annual_provisions", baseurl),
map[string]string{
blockHeightHeader: queryAtHeight,
},
annualProvisionsResp,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// TODO: remove below check once grpc gateway is implemented in v2
if isV2() {
return
}
Comment on lines +80 to +83
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use t.Skip() to properly skip tests

Instead of returning early when isV2() is true, use t.Skip() to indicate that the test is being intentionally skipped. This approach provides clearer test output and accurately reflects the test status.

Apply this change:

-		return
+		t.Skip("Skipping test until gRPC gateway is implemented in v2")
	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// TODO: remove below check once grpc gateway is implemented in v2
if isV2() {
return
}
// TODO: remove below check once grpc gateway is implemented in v2
if isV2() {
t.Skip("Skipping test until gRPC gateway is implemented in v2")
}

resp := GetRequestWithHeaders(t, tc.url, tc.headers, http.StatusOK)
require.JSONEq(t, tc.expOut, string(resp))
})
}

// test cli queries
rsp := cli.CustomQuery("q", "mint", "params")
require.JSONEq(t, paramsResp, rsp)

rsp = cli.CustomQuery("q", "mint", "inflation")
require.JSONEq(t, inflationResp, rsp)

rsp = cli.CustomQuery("q", "mint", "annual-provisions", "--height="+queryAtHeight)
require.JSONEq(t, annualProvisionsResp, rsp)
}
Loading