Skip to content

Commit

Permalink
Remove testutil dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Oct 1, 2024
1 parent 52d8b2e commit b371472
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 105 deletions.
18 changes: 18 additions & 0 deletions tests/systemtests/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package systemtests

import (
"fmt"
"net/http"
"os"
"testing"
"time"
Expand Down Expand Up @@ -674,31 +675,37 @@ func TestAuthzGRPCQueries(t *testing.T) {
{
"invalid granter address",
fmt.Sprintf(grantURL, "invalid_granter", grantee1Addr, msgSendTypeURL),
http.StatusInternalServerError,
bech32FailOutput,
},
{
"invalid grantee address",
fmt.Sprintf(grantURL, granterAddr, "invalid_grantee", msgSendTypeURL),
http.StatusInternalServerError,
bech32FailOutput,
},
{
"with empty granter",
fmt.Sprintf(grantURL, "", grantee1Addr, msgSendTypeURL),
http.StatusInternalServerError,
emptyStrOutput,
},
{
"with empty grantee",
fmt.Sprintf(grantURL, granterAddr, "", msgSendTypeURL),
http.StatusInternalServerError,
emptyStrOutput,
},
{
"invalid msg-type",
fmt.Sprintf(grantURL, granterAddr, grantee1Addr, "invalidMsg"),
http.StatusInternalServerError,
invalidMsgTypeOutput,
},
{
"valid grant query",
fmt.Sprintf(grantURL, granterAddr, grantee1Addr, msgSendTypeURL),
http.StatusOK,
expGrantOutput,
},
}
Expand All @@ -712,26 +719,31 @@ func TestAuthzGRPCQueries(t *testing.T) {
{
"expect single grant",
fmt.Sprintf(grantsURL, granterAddr, grantee1Addr),
http.StatusOK,
fmt.Sprintf(`{"grants":[{%s}],"pagination":{"next_key":null,"total":"1"}}`, grant1),
},
{
"expect two grants",
fmt.Sprintf(grantsURL, granterAddr, grantee2Addr),
http.StatusOK,
fmt.Sprintf(`{"grants":[{%s},{%s}],"pagination":{"next_key":null,"total":"2"}}`, grant2, grant3),
},
{
"expect single grant with pagination",
fmt.Sprintf(grantsURL+"&pagination.limit=1", granterAddr, grantee2Addr),
http.StatusOK,
fmt.Sprintf(`{"grants":[{%s}],"pagination":{"next_key":"L2Nvc21vcy5nb3YudjEuTXNnVm90ZQ==","total":"0"}}`, grant2),
},
{
"expect single grant with pagination limit and offset",
fmt.Sprintf(grantsURL+"&pagination.limit=1&pagination.offset=1", granterAddr, grantee2Addr),
http.StatusOK,
fmt.Sprintf(`{"grants":[{%s}],"pagination":{"next_key":null,"total":"0"}}`, grant3),
},
{
"expect two grants with pagination",
fmt.Sprintf(grantsURL+"&pagination.limit=2", granterAddr, grantee2Addr),
http.StatusOK,
fmt.Sprintf(`{"grants":[{%s},{%s}],"pagination":{"next_key":null,"total":"0"}}`, grant2, grant3),
},
}
Expand All @@ -749,16 +761,19 @@ func TestAuthzGRPCQueries(t *testing.T) {
{
"invalid granter account address",
fmt.Sprintf(grantsByGranterURL, "invalid address"),
http.StatusInternalServerError,
decodingFailedOutput,
},
{
"no authorizations found from granter",
fmt.Sprintf(grantsByGranterURL, grantee2Addr),
http.StatusOK,
noAuthorizationsOutput,
},
{
"valid granter query",
fmt.Sprintf(grantsByGranterURL, grantee1Addr),
http.StatusOK,
granterQueryOutput,
},
}
Expand All @@ -773,16 +788,19 @@ func TestAuthzGRPCQueries(t *testing.T) {
{
"invalid grantee account address",
fmt.Sprintf(grantsByGranteeURL, "invalid address"),
http.StatusInternalServerError,
decodingFailedOutput,
},
{
"no authorizations found from grantee",
fmt.Sprintf(grantsByGranteeURL, granterAddr),
http.StatusOK,
noAuthorizationsOutput,
},
{
"valid grantee query",
fmt.Sprintf(grantsByGranteeURL, grantee1Addr),
http.StatusOK,
grantee1GrantsOutput,
},
}
Expand Down
29 changes: 19 additions & 10 deletions tests/systemtests/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ package systemtests

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

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"

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

func TestBankSendTxCmd(t *testing.T) {
Expand Down Expand Up @@ -53,7 +51,7 @@ func TestBankSendTxCmd(t *testing.T) {
insufficientCmdArgs = append(insufficientCmdArgs, fmt.Sprintf("%d%s", valBalance, denom), "--fees=10stake")
rsp = cli.Run(insufficientCmdArgs...)
RequireTxFailure(t, rsp)
require.Contains(t, rsp, sdkerrors.ErrInsufficientFunds.Error())
require.Contains(t, rsp, "insufficient funds")

// test tx bank send with unauthorized signature
assertUnauthorizedErr := func(_ assert.TestingT, gotErr error, gotOutputs ...interface{}) bool {
Expand Down Expand Up @@ -234,23 +232,26 @@ func TestBankGRPCQueries(t *testing.T) {
blockHeight := sut.CurrentHeight()

supplyTestCases := []struct {
name string
url string
headers map[string]string
expOut string
name string
url string
headers map[string]string
expHttpCode int
expOut string
}{
{
"test GRPC total supply",
supplyUrl,
map[string]string{
blockHeightHeader: fmt.Sprintf("%d", blockHeight),
},
http.StatusOK,
expTotalSupplyOutput,
},
{
"test GRPC total supply of a specific denom",
supplyUrl + "/by_denom?denom=" + newDenom,
map[string]string{},
http.StatusOK,
specificDenomOutput,
},
{
Expand All @@ -259,20 +260,22 @@ func TestBankGRPCQueries(t *testing.T) {
map[string]string{
blockHeightHeader: fmt.Sprintf("%d", blockHeight+5),
},
http.StatusInternalServerError,
"invalid height",
},
{
"test GRPC total supply of a bogus denom",
supplyUrl + "/by_denom?denom=foobar",
map[string]string{},
http.StatusOK,
// http.StatusNotFound,
bogusDenomOutput,
},
}

for _, tc := range supplyTestCases {
t.Run(tc.name, func(t *testing.T) {
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
require.NoError(t, err)
resp := GetRequestWithHeaders(t, tc.url, tc.headers, tc.expHttpCode)
require.Contains(t, string(resp), tc.expOut)
})
}
Expand All @@ -283,16 +286,19 @@ func TestBankGRPCQueries(t *testing.T) {
{
"test GRPC client metadata",
denomMetadataUrl,
http.StatusOK,
fmt.Sprintf(`{"metadatas":%s,"pagination":{"next_key":null,"total":"2"}}`, bankDenomMetadata),
},
{
"test GRPC client metadata of a specific denom",
denomMetadataUrl + "/uatom",
http.StatusOK,
fmt.Sprintf(`{"metadata":%s}`, atomDenomMetadata),
},
{
"test GRPC client metadata of a bogus denom",
denomMetadataUrl + "/foobar",
http.StatusNotFound,
`{"code":5, "message":"client metadata for denom foobar", "details":[]}`,
},
}
Expand All @@ -307,16 +313,19 @@ func TestBankGRPCQueries(t *testing.T) {
{
"test GRPC total account balance",
balanceUrl + account1Addr,
http.StatusOK,
allBalancesOutput,
},
{
"test GRPC account balance of a specific denom",
fmt.Sprintf("%s%s/by_denom?denom=%s", balanceUrl, account1Addr, newDenom),
http.StatusOK,
fmt.Sprintf(`{"balance":%s}`, specificDenomOutput),
},
{
"test GRPC account balance of a bogus denom",
fmt.Sprintf("%s%s/by_denom?denom=foobar", balanceUrl, account1Addr),
http.StatusOK,
fmt.Sprintf(`{"balance":%s}`, bogusDenomOutput),
},
}
Expand Down
3 changes: 1 addition & 2 deletions tests/systemtests/bankv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ func TestBankV2SendTxCmd(t *testing.T) {
valBalanceAfer := gjson.Get(valRaw, "balance.amount").Int()

// TODO: Make DeductFee ante handler work with bank/v2
require.Equal(t, valBalanceAfer, valBalance - transferAmount)
require.Equal(t, valBalanceAfer, valBalance-transferAmount)

receiverRaw := cli.CustomQuery("q", "bankv2", "balance", receiverAddr, denom)
receiverBalance := gjson.Get(receiverRaw, "balance.amount").Int()
require.Equal(t, receiverBalance, transferAmount)

}
23 changes: 9 additions & 14 deletions tests/systemtests/cometbft_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package systemtests
import (
"context"
"fmt"
"net/url"
"testing"
"time"

Expand All @@ -15,7 +16,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil"
qtypes "github.com/cosmos/cosmos-sdk/types/query"
)

Expand All @@ -32,7 +32,7 @@ func TestQueryNodeInfo(t *testing.T) {
assert.Equal(t, res.ApplicationVersion.Version, v)

// TODO: we should be adding a way to distinguish a v2. Eventually we should skip some v2 system depending on the consensus engine we want to test
restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/node_info", baseurl))
restRes := GetRequest(t, mustV(url.JoinPath(baseurl, "/cosmos/base/tendermint/v1beta1/node_info")))
assert.NoError(t, err)
assert.Equal(t, gjson.GetBytes(restRes, "application_version.version").String(), res.ApplicationVersion.Version)
}
Expand All @@ -46,8 +46,7 @@ func TestQuerySyncing(t *testing.T) {
res, err := qc.GetSyncing(context.Background(), &cmtservice.GetSyncingRequest{})
assert.NoError(t, err)

restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/syncing", baseurl))
assert.NoError(t, err)
restRes := GetRequest(t, mustV(url.JoinPath(baseurl, "/cosmos/base/tendermint/v1beta1/syncing")))
assert.Equal(t, gjson.GetBytes(restRes, "syncing").Bool(), res.Syncing)
}

Expand All @@ -61,8 +60,7 @@ func TestQueryLatestBlock(t *testing.T) {
assert.NoError(t, err)
assert.Contains(t, res.SdkBlock.Header.ProposerAddress, "cosmosvalcons")

_, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/latest", baseurl))
assert.NoError(t, err)
_ = GetRequest(t, mustV(url.JoinPath(baseurl, "/cosmos/base/tendermint/v1beta1/blocks/latest")))
}

func TestQueryBlockByHeight(t *testing.T) {
Expand All @@ -78,8 +76,7 @@ func TestQueryBlockByHeight(t *testing.T) {
assert.Equal(t, res.SdkBlock.Header.Height, int64(2))
assert.Contains(t, res.SdkBlock.Header.ProposerAddress, "cosmosvalcons")

restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/%d", baseurl, 2))
assert.NoError(t, err)
restRes := GetRequest(t, mustV(url.JoinPath(baseurl, "/cosmos/base/tendermint/v1beta1/blocks/2")))
assert.Equal(t, gjson.GetBytes(restRes, "sdk_block.header.height").Int(), int64(2))
assert.Contains(t, gjson.GetBytes(restRes, "sdk_block.header.proposer_address").String(), "cosmosvalcons")
}
Expand All @@ -106,8 +103,7 @@ func TestQueryLatestValidatorSet(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, len(res.Validators), 2)

restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=%d&pagination.limit=%d", baseurl, 0, 2))
assert.NoError(t, err)
restRes := GetRequest(t, mustV(url.JoinPath(baseurl, "/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=0&pagination.limit=2")))
assert.Equal(t, len(gjson.GetBytes(restRes, "validators").Array()), 2)
}

Expand Down Expand Up @@ -144,6 +140,7 @@ func TestLatestValidatorSet(t *testing.T) {
})
}
}

func TestLatestValidatorSet_GRPCGateway(t *testing.T) {
sut.ResetChain(t)
sut.StartChain(t)
Expand All @@ -164,8 +161,7 @@ func TestLatestValidatorSet_GRPCGateway(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
rsp, err := testutil.GetRequest(fmt.Sprintf("%s%s", baseurl, tc.url))
assert.NoError(t, err)
rsp := GetRequest(t, mustV(url.JoinPath(baseurl, tc.url)))
if tc.expErr {
errMsg := gjson.GetBytes(rsp, "message").String()
assert.Contains(t, errMsg, tc.expErrMsg)
Expand Down Expand Up @@ -230,8 +226,7 @@ func TestValidatorSetByHeight_GRPCGateway(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
rsp, err := testutil.GetRequest(tc.url)
assert.NoError(t, err)
rsp := GetRequest(t, tc.url)
if tc.expErr {
errMsg := gjson.GetBytes(rsp, "message").String()
assert.Contains(t, errMsg, tc.expErrMsg)
Expand Down
3 changes: 1 addition & 2 deletions tests/systemtests/fraud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ func TestValidatorDoubleSign(t *testing.T) {
newNode := sut.AddFullnode(t, func(nodeNumber int, nodePath string) {
valKeyFile := filepath.Join(WorkDir, nodePath, "config", "priv_validator_key.json")
_ = os.Remove(valKeyFile)
_, err := copyFile(filepath.Join(WorkDir, sut.nodePath(0), "config", "priv_validator_key.json"), valKeyFile)
require.NoError(t, err)
_ = MustCopyFile(filepath.Join(WorkDir, sut.nodePath(0), "config", "priv_validator_key.json"), valKeyFile)
})
sut.AwaitNodeUp(t, fmt.Sprintf("http://%s:%d", newNode.IP, newNode.RPCPort))

Expand Down
Loading

0 comments on commit b371472

Please sign in to comment.