-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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(systemtests): fix failing tests #22145
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ package systemtests | |
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
"time" | ||
|
@@ -82,6 +83,10 @@ func TestQueryBlockByHeight(t *testing.T) { | |
} | ||
|
||
func TestQueryLatestValidatorSet(t *testing.T) { | ||
if sut.NodesCount() < 2 { | ||
t.Skip("not enough nodes") | ||
return | ||
} | ||
baseurl := fmt.Sprintf("http://localhost:%d", apiPortStart) | ||
sut.ResetChain(t) | ||
sut.StartChain(t) | ||
|
@@ -103,7 +108,7 @@ func TestQueryLatestValidatorSet(t *testing.T) { | |
assert.NoError(t, err) | ||
assert.Equal(t, len(res.Validators), 2) | ||
|
||
restRes := GetRequest(t, mustV(url.JoinPath(baseurl, "/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=0&pagination.limit=2"))) | ||
restRes := GetRequest(t, fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=%d&pagination.limit=%d", baseurl, 0, 2)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use Constructing URLs using Refactor the URL construction as follows: u, err := url.Parse(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest", baseurl))
if err != nil {
t.Fatal(err)
}
q := u.Query()
q.Set("pagination.offset", "0")
q.Set("pagination.limit", "2")
u.RawQuery = q.Encode()
restRes := GetRequest(t, u.String()) |
||
assert.Equal(t, len(gjson.GetBytes(restRes, "validators").Array()), 2) | ||
} | ||
|
||
|
@@ -161,13 +166,14 @@ func TestLatestValidatorSet_GRPCGateway(t *testing.T) { | |
} | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
rsp := GetRequest(t, mustV(url.JoinPath(baseurl, tc.url))) | ||
if tc.expErr { | ||
rsp := GetRequestWithHeaders(t, baseurl+tc.url, nil, http.StatusBadRequest) | ||
errMsg := gjson.GetBytes(rsp, "message").String() | ||
assert.Contains(t, errMsg, tc.expErrMsg) | ||
} else { | ||
assert.Equal(t, len(vals), int(gjson.GetBytes(rsp, "pagination.total").Int())) | ||
return | ||
} | ||
rsp := GetRequest(t, baseurl+tc.url) | ||
assert.Equal(t, len(vals), int(gjson.GetBytes(rsp, "pagination.total").Int())) | ||
}) | ||
} | ||
} | ||
|
@@ -204,41 +210,40 @@ func TestValidatorSetByHeight(t *testing.T) { | |
} | ||
} | ||
|
||
func TestValidatorSetByHeight_GRPCGateway(t *testing.T) { | ||
func TestValidatorSetByHeight_GRPCRestGateway(t *testing.T) { | ||
sut.ResetChain(t) | ||
sut.StartChain(t) | ||
|
||
vals := sut.RPCClient(t).Validators() | ||
|
||
baseurl := fmt.Sprintf("http://localhost:%d", apiPortStart) | ||
|
||
baseurl := sut.APIAddress() | ||
block := sut.AwaitNextBlock(t, time.Second*3) | ||
testCases := []struct { | ||
name string | ||
url string | ||
expErr bool | ||
expErrMsg string | ||
name string | ||
url string | ||
expErr bool | ||
expErrMsg string | ||
expHttpCode int | ||
}{ | ||
{"invalid height", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d", baseurl, -1), true, "height must be greater than 0"}, | ||
{"no pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d", baseurl, block), false, ""}, | ||
{"pagination invalid fields", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=-1&pagination.limit=-2", baseurl, block), true, "strconv.ParseUint"}, | ||
{"with pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.limit=2", baseurl, 1), false, ""}, | ||
{"invalid height", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d", baseurl, -1), true, "height must be greater than 0", http.StatusInternalServerError}, | ||
{"no pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d", baseurl, block), false, "", http.StatusOK}, | ||
{"pagination invalid fields", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=-1&pagination.limit=-2", baseurl, block), true, "strconv.ParseUint", http.StatusBadRequest}, | ||
{"with pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.limit=2", baseurl, 1), false, "", http.StatusOK}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
rsp := GetRequest(t, tc.url) | ||
rsp := GetRequestWithHeaders(t, tc.url, nil, tc.expHttpCode) | ||
if tc.expErr { | ||
errMsg := gjson.GetBytes(rsp, "message").String() | ||
assert.Contains(t, errMsg, tc.expErrMsg) | ||
} else { | ||
assert.Equal(t, len(vals), int(gjson.GetBytes(rsp, "pagination.total").Int())) | ||
return | ||
} | ||
assert.Equal(t, len(vals), int(gjson.GetBytes(rsp, "pagination.total").Int())) | ||
}) | ||
} | ||
} | ||
|
||
func TestABCIQuery(t *testing.T) { | ||
sut.ResetChain(t) | ||
sut.StartChain(t) | ||
|
||
qc := cmtservice.NewServiceClient(sut.RPCClient(t)) | ||
|
@@ -312,7 +317,7 @@ func TestABCIQuery(t *testing.T) { | |
} else { | ||
assert.NoError(t, err) | ||
assert.NotNil(t, res) | ||
assert.Equal(t, res.Code, tc.expectedCode) | ||
assert.Equal(t, tc.expectedCode, res.Code) | ||
} | ||
|
||
if tc.validQuery { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,25 +17,28 @@ import ( | |
) | ||
|
||
func TestChainUpgrade(t *testing.T) { | ||
// err> panic: failed to load latest version: failed to load store: initial version set to 22, but found earlier version 1 [cosmossdk.io/store@v1.1.1/rootmulti/store.go:256] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this probably needs to be reverted in the 0.52 backport |
||
t.Skip("Skipped until any v052 artifact is available AND main branch handles the store upgrade proper") | ||
|
||
// Scenario: | ||
// start a legacy chain with some state | ||
// when a chain upgrade proposal is executed | ||
// then the chain upgrades successfully | ||
sut.StopChain() | ||
|
||
legacyBinary := FetchExecutable(t, "v0.50") | ||
legacyBinary := FetchExecutable(t, "v0.52") | ||
t.Logf("+++ legacy binary: %s\n", legacyBinary) | ||
currentBranchBinary := sut.execBinary | ||
currentInitializer := sut.testnetInitializer | ||
sut.SetExecBinary(legacyBinary) | ||
sut.SetTestnetInitializer(NewModifyConfigYamlInitializer(legacyBinary, sut)) | ||
sut.SetTestnetInitializer(InitializerWithBinary(legacyBinary, sut)) | ||
sut.SetupChain() | ||
votingPeriod := 5 * time.Second // enough time to vote | ||
sut.ModifyGenesisJSON(t, SetGovVotingPeriod(t, votingPeriod)) | ||
|
||
const ( | ||
upgradeHeight int64 = 22 | ||
upgradeName = "v050-to-v051" | ||
upgradeName = "v052-to-v054" // must match UpgradeName in simapp/upgrades.go | ||
) | ||
|
||
sut.StartChain(t, fmt.Sprintf("--halt-height=%d", upgradeHeight+1)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant
return
statement aftert.Skip()
After calling
t.Skip("not enough nodes")
, the test execution is halted, so thereturn
statement on line 88 is unnecessary and can be removed.Apply this diff to remove the unnecessary
return
:if sut.NodesCount() < 2 { t.Skip("not enough nodes") - return }
📝 Committable suggestion