refactor(tests): testutil.Network as an interface (#18389)

Co-authored-by: Anmol <anmol1696@gmail.com>
This commit is contained in:
Marko 2023-11-08 19:38:57 +01:00 committed by GitHub
parent 8fbf6166f6
commit 03c3f8e71f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 959 additions and 863 deletions

View File

@ -21,12 +21,12 @@ func TestStatusCommand(t *testing.T) {
require.NoError(t, err)
require.NoError(t, network.WaitForNextBlock())
val0 := network.Validators[0]
val0 := network.GetValidators()[0]
cmd := server.StatusCommand()
out, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cmd, []string{})
out, err := clitestutil.ExecTestCLICmd(val0.GetClientCtx(), cmd, []string{})
require.NoError(t, err)
// Make sure the output has the validator moniker.
require.Contains(t, out.String(), fmt.Sprintf("\"moniker\":\"%s\"", val0.Moniker))
require.Contains(t, out.String(), fmt.Sprintf("\"moniker\":\"%s\"", val0.GetMoniker()))
}

View File

@ -22,7 +22,7 @@ import (
type IntegrationTestSuite struct {
suite.Suite
network *network.Network
network network.NetworkI
}
func (s *IntegrationTestSuite) SetupSuite() {
@ -47,7 +47,7 @@ func (s *IntegrationTestSuite) TestCLIQueryConn() {
s.T().Skip("data race in comet is causing this to fail")
var header metadata.MD
testClient := testdata.NewQueryClient(s.network.Validators[0].ClientCtx)
testClient := testdata.NewQueryClient(s.network.GetValidators()[0].GetClientCtx())
res, err := testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"}, grpc.Header(&header))
s.NoError(err)
@ -91,15 +91,15 @@ func (s *IntegrationTestSuite) TestQueryABCIHeight() {
_, err := s.network.WaitForHeight(tc.expHeight)
s.Require().NoError(err)
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
clientCtx = clientCtx.WithHeight(tc.ctxHeight)
req := abci.RequestQuery{
Path: fmt.Sprintf("store/%s/key", banktypes.StoreKey),
Height: tc.reqHeight,
Data: address.MustLengthPrefix(val.Address),
Data: address.MustLengthPrefix(val.GetAddress()),
Prove: true,
}

View File

@ -40,7 +40,7 @@ type GRPCWebTestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
protoCdc *codec.ProtoCodec
}
@ -68,7 +68,7 @@ func (s *GRPCWebTestSuite) TearDownSuite() {
}
func (s *GRPCWebTestSuite) Test_Latest_Validators() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
for _, contentType := range []string{grpcWebContentType} {
headers, trailers, responses, err := s.makeGrpcRequest(
"/cosmos.base.tendermint.v1beta1.Service/GetLatestValidatorSet",
@ -84,7 +84,7 @@ func (s *GRPCWebTestSuite) Test_Latest_Validators() {
s.Require().NoError(err)
pubKey, ok := valsSet.Validators[0].PubKey.GetCachedValue().(cryptotypes.PubKey)
s.Require().Equal(true, ok)
s.Require().Equal(pubKey, val.PubKey)
s.Require().Equal(pubKey, val.GetPubKey())
}
}
@ -128,7 +128,7 @@ func serializeProtoMessages(messages []proto.Message) [][]byte {
func (s *GRPCWebTestSuite) makeRequest(
verb, method string, headers http.Header, body io.Reader, isText bool,
) (*http.Response, error) {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
contentType := "application/grpc-web"
if isText {
// base64 encode the body
@ -146,7 +146,7 @@ func (s *GRPCWebTestSuite) makeRequest(
contentType = "application/grpc-web-text"
}
url := fmt.Sprintf("http://%s%s", strings.TrimPrefix(val.AppConfig.API.Address, "tcp://"), method)
url := fmt.Sprintf("http://%s%s", strings.TrimPrefix(val.GetAppConfig().API.Address, "tcp://"), method)
req, err := http.NewRequest(verb, url, body)
s.Require().NoError(err, "failed creating a request")
req.Header = headers

View File

@ -14,7 +14,7 @@ import (
type IntegrationTestSuite struct {
suite.Suite
network *network.Network
network network.NetworkI
}
func (s *IntegrationTestSuite) SetupSuite() {

File diff suppressed because it is too large Load Diff

View File

@ -16,9 +16,9 @@ import (
)
func (s *E2ETestSuite) TestQueryGrantGRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
grantee := s.grantee[1]
grantsURL := val.APIAddress + "/cosmos/authz/v1beta1/grants?granter=%s&grantee=%s&msg_type_url=%s"
grantsURL := val.GetAPIAddress() + "/cosmos/authz/v1beta1/grants?granter=%s&grantee=%s&msg_type_url=%s"
testCases := []struct {
name string
url string
@ -33,7 +33,7 @@ func (s *E2ETestSuite) TestQueryGrantGRPC() {
},
{
"fail invalid grantee address",
fmt.Sprintf(grantsURL, val.Address.String(), "invalid_grantee", typeMsgSend),
fmt.Sprintf(grantsURL, val.GetAddress().String(), "invalid_grantee", typeMsgSend),
true,
"decoding bech32 failed: invalid separator index -1: invalid request",
},
@ -45,19 +45,19 @@ func (s *E2ETestSuite) TestQueryGrantGRPC() {
},
{
"fail with empty grantee",
fmt.Sprintf(grantsURL, val.Address.String(), "", typeMsgSend),
fmt.Sprintf(grantsURL, val.GetAddress().String(), "", typeMsgSend),
true,
"empty address string is not allowed: invalid request",
},
{
"fail invalid msg-type",
fmt.Sprintf(grantsURL, val.Address.String(), grantee.String(), "invalidMsg"),
fmt.Sprintf(grantsURL, val.GetAddress().String(), grantee.String(), "invalidMsg"),
true,
"authorization not found for invalidMsg type",
},
{
"valid query",
fmt.Sprintf(grantsURL, val.Address.String(), grantee.String(), typeMsgSend),
fmt.Sprintf(grantsURL, val.GetAddress().String(), grantee.String(), typeMsgSend),
false,
"",
},
@ -71,10 +71,10 @@ func (s *E2ETestSuite) TestQueryGrantGRPC() {
require.Contains(string(resp), tc.errorMsg)
} else {
var g authz.QueryGrantsResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &g)
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &g)
require.NoError(err)
require.Len(g.Grants, 1)
err = g.Grants[0].UnpackInterfaces(val.ClientCtx.InterfaceRegistry)
err = g.Grants[0].UnpackInterfaces(val.GetClientCtx().InterfaceRegistry)
require.NoError(err)
auth, err := g.Grants[0].GetAuthorization()
require.NoError(err)
@ -85,9 +85,9 @@ func (s *E2ETestSuite) TestQueryGrantGRPC() {
}
func (s *E2ETestSuite) TestQueryGrantsGRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
grantee := s.grantee[1]
grantsURL := val.APIAddress + "/cosmos/authz/v1beta1/grants?granter=%s&grantee=%s"
grantsURL := val.GetAPIAddress() + "/cosmos/authz/v1beta1/grants?granter=%s&grantee=%s"
testCases := []struct {
name string
url string
@ -98,7 +98,7 @@ func (s *E2ETestSuite) TestQueryGrantsGRPC() {
}{
{
"valid query: expect single grant",
fmt.Sprintf(grantsURL, val.Address.String(), grantee.String()),
fmt.Sprintf(grantsURL, val.GetAddress().String(), grantee.String()),
false,
"",
func() {},
@ -108,14 +108,14 @@ func (s *E2ETestSuite) TestQueryGrantsGRPC() {
},
{
"valid query: expect two grants",
fmt.Sprintf(grantsURL, val.Address.String(), grantee.String()),
fmt.Sprintf(grantsURL, val.GetAddress().String(), grantee.String()),
false,
"",
func() {
_, err := authzclitestutil.CreateGrant(val.ClientCtx, []string{
_, err := authzclitestutil.CreateGrant(val.GetClientCtx(), []string{
grantee.String(),
"generic",
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=%s", cli.FlagMsgType, typeMsgVote),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
@ -131,7 +131,7 @@ func (s *E2ETestSuite) TestQueryGrantsGRPC() {
},
{
"valid query: expect single grant with pagination",
fmt.Sprintf(grantsURL+"&pagination.limit=1", val.Address.String(), grantee.String()),
fmt.Sprintf(grantsURL+"&pagination.limit=1", val.GetAddress().String(), grantee.String()),
false,
"",
func() {},
@ -141,7 +141,7 @@ func (s *E2ETestSuite) TestQueryGrantsGRPC() {
},
{
"valid query: expect two grants with pagination",
fmt.Sprintf(grantsURL+"&pagination.limit=2", val.Address.String(), grantee.String()),
fmt.Sprintf(grantsURL+"&pagination.limit=2", val.GetAddress().String(), grantee.String()),
false,
"",
func() {},
@ -161,7 +161,7 @@ func (s *E2ETestSuite) TestQueryGrantsGRPC() {
s.Require().Contains(string(resp), tc.errMsg)
} else {
var authorizations authz.QueryGrantsResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &authorizations)
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &authorizations)
s.Require().NoError(err)
tc.postRun(&authorizations)
}
@ -170,7 +170,7 @@ func (s *E2ETestSuite) TestQueryGrantsGRPC() {
}
func (s *E2ETestSuite) TestQueryGranterGrantsGRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
grantee := s.grantee[1]
require := s.Require()
@ -183,21 +183,21 @@ func (s *E2ETestSuite) TestQueryGranterGrantsGRPC() {
}{
{
"invalid account address",
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/granter/%s", val.APIAddress, "invalid address"),
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/granter/%s", val.GetAPIAddress(), "invalid address"),
true,
"decoding bech32 failed",
0,
},
{
"no authorizations found",
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/granter/%s", val.APIAddress, grantee.String()),
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/granter/%s", val.GetAPIAddress(), grantee.String()),
false,
"",
0,
},
{
"valid query",
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/granter/%s", val.APIAddress, val.Address.String()),
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/granter/%s", val.GetAPIAddress(), val.GetAddress().String()),
false,
"",
6,
@ -212,7 +212,7 @@ func (s *E2ETestSuite) TestQueryGranterGrantsGRPC() {
require.Contains(string(resp), tc.errMsg)
} else {
var authorizations authz.QueryGranterGrantsResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &authorizations)
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &authorizations)
require.NoError(err)
require.Len(authorizations.Grants, tc.numItems)
}
@ -221,7 +221,7 @@ func (s *E2ETestSuite) TestQueryGranterGrantsGRPC() {
}
func (s *E2ETestSuite) TestQueryGranteeGrantsGRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
grantee := s.grantee[1]
require := s.Require()
@ -234,21 +234,21 @@ func (s *E2ETestSuite) TestQueryGranteeGrantsGRPC() {
}{
{
"invalid account address",
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/grantee/%s", val.APIAddress, "invalid address"),
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/grantee/%s", val.GetAPIAddress(), "invalid address"),
true,
"decoding bech32 failed",
0,
},
{
"no authorizations found",
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/grantee/%s", val.APIAddress, val.Address.String()),
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/grantee/%s", val.GetAPIAddress(), val.GetAddress().String()),
false,
"",
0,
},
{
"valid query",
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/grantee/%s", val.APIAddress, grantee.String()),
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/grantee/%s", val.GetAPIAddress(), grantee.String()),
false,
"",
1,
@ -263,7 +263,7 @@ func (s *E2ETestSuite) TestQueryGranteeGrantsGRPC() {
require.Contains(string(resp), tc.errMsg)
} else {
var authorizations authz.QueryGranteeGrantsResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &authorizations)
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &authorizations)
require.NoError(err)
require.Len(authorizations.Grants, tc.numItems)
}

View File

@ -34,7 +34,7 @@ type E2ETestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
grantee []sdk.AccAddress
}
@ -49,7 +49,7 @@ func (s *E2ETestSuite) SetupSuite() {
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
s.grantee = make([]sdk.AccAddress, 6)
// Send some funds to the new account.
@ -58,7 +58,7 @@ func (s *E2ETestSuite) SetupSuite() {
s.msgSendExec(s.grantee[0])
// create a proposal with deposit
_, err = govtestutil.MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(),
_, err = govtestutil.MsgSubmitLegacyProposal(val.GetClientCtx(), val.GetAddress().String(),
"Text Proposal 1", "Where is the title!?", govv1beta1.ProposalTypeText,
fmt.Sprintf("--%s=%s", govcli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, govv1.DefaultMinDepositTokens).String()))
s.Require().NoError(err)
@ -70,11 +70,11 @@ func (s *E2ETestSuite) SetupSuite() {
s.msgSendExec(s.grantee[1])
// grant send authorization to grantee2
out, err := authzclitestutil.CreateGrant(val.ClientCtx, []string{
out, err := authzclitestutil.CreateGrant(val.GetClientCtx(), []string{
s.grantee[1].String(),
"send",
fmt.Sprintf("--%s=100stake", cli.FlagSpendLimit),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(10))).String()),
@ -83,18 +83,18 @@ func (s *E2ETestSuite) SetupSuite() {
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
var response sdk.TxResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, response.TxHash, 0))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), response.TxHash, 0))
// Create new account in the keyring.
s.grantee[2] = s.createAccount("grantee3")
// grant send authorization to grantee3
_, err = authzclitestutil.CreateGrant(val.ClientCtx, []string{
_, err = authzclitestutil.CreateGrant(val.GetClientCtx(), []string{
s.grantee[2].String(),
"send",
fmt.Sprintf("--%s=100stake", cli.FlagSpendLimit),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(10))).String()),
@ -111,13 +111,13 @@ func (s *E2ETestSuite) SetupSuite() {
s.grantee[5] = s.createAccount("grantee6")
// grant send authorization with allow list to grantee4
out, err = authzclitestutil.CreateGrant(val.ClientCtx,
out, err = authzclitestutil.CreateGrant(val.GetClientCtx(),
[]string{
s.grantee[3].String(),
"send",
fmt.Sprintf("--%s=100stake", cli.FlagSpendLimit),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%d", cli.FlagExpiration, time.Now().Add(time.Minute*time.Duration(120)).Unix()),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
@ -127,14 +127,14 @@ func (s *E2ETestSuite) SetupSuite() {
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, response.TxHash, 0))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), response.TxHash, 0))
}
func (s *E2ETestSuite) createAccount(uid string) sdk.AccAddress {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
// Create new account in the keyring.
k, _, err := val.ClientCtx.Keyring.NewMnemonic(uid, keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
k, _, err := val.GetClientCtx().Keyring.NewMnemonic(uid, keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
s.Require().NoError(err)
addr, err := k.GetAddress()
@ -144,10 +144,10 @@ func (s *E2ETestSuite) createAccount(uid string) sdk.AccAddress {
}
func (s *E2ETestSuite) msgSendExec(grantee sdk.AccAddress) {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
// Send some funds to the new account.
from := val.Address
from := val.GetAddress()
coins := sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(200)))
msgSend := &bank.MsgSend{
FromAddress: from.String(),
@ -156,7 +156,7 @@ func (s *E2ETestSuite) msgSendExec(grantee sdk.AccAddress) {
}
out, err := clitestutil.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend,
from,
clitestutil.TestTxConfig{},
@ -178,18 +178,18 @@ var (
)
func (s *E2ETestSuite) TestExecAuthorizationWithExpiration() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
grantee := s.grantee[0]
tenSeconds := time.Now().Add(time.Second * time.Duration(10)).Unix()
_, err := authzclitestutil.CreateGrant(
val.ClientCtx,
val.GetClientCtx(),
[]string{
grantee.String(),
"generic",
fmt.Sprintf("--%s=%s", cli.FlagMsgType, typeMsgVote),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%d", cli.FlagExpiration, tenSeconds),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
@ -197,7 +197,7 @@ func (s *E2ETestSuite) TestExecAuthorizationWithExpiration() {
)
s.Require().NoError(err)
// msg vote
voteTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.gov.v1.MsgVote","proposal_id":"1","voter":"%s","option":"VOTE_OPTION_YES"}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.Address.String())
voteTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.gov.v1.MsgVote","proposal_id":"1","voter":"%s","option":"VOTE_OPTION_YES"}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.GetAddress().String())
execMsg := testutil.WriteToNewTempFile(s.T(), voteTx)
defer execMsg.Close()
@ -205,7 +205,7 @@ func (s *E2ETestSuite) TestExecAuthorizationWithExpiration() {
time.Sleep(12 * time.Second)
cmd := cli.NewCmdExecAuthorization()
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{
execMsg.Name(),
@ -221,18 +221,18 @@ func (s *E2ETestSuite) TestExecAuthorizationWithExpiration() {
}
func (s *E2ETestSuite) TestNewExecGenericAuthorized() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
grantee := s.grantee[0]
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()
_, err := authzclitestutil.CreateGrant(
val.ClientCtx,
val.GetClientCtx(),
[]string{
grantee.String(),
"generic",
fmt.Sprintf("--%s=%s", cli.FlagMsgType, typeMsgVote),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%d", cli.FlagExpiration, twoHours),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
@ -242,7 +242,7 @@ func (s *E2ETestSuite) TestNewExecGenericAuthorized() {
s.Require().NoError(s.network.WaitForNextBlock())
// msg vote
voteTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.gov.v1.MsgVote","proposal_id":"1","voter":"%s","option":"VOTE_OPTION_YES"}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.Address.String())
voteTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.gov.v1.MsgVote","proposal_id":"1","voter":"%s","option":"VOTE_OPTION_YES"}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.GetAddress().String())
execMsg := testutil.WriteToNewTempFile(s.T(), voteTx)
defer execMsg.Close()
@ -308,7 +308,7 @@ func (s *E2ETestSuite) TestNewExecGenericAuthorized() {
tc := tc
s.Run(tc.name, func() {
cmd := cli.NewCmdExecAuthorization()
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
@ -317,26 +317,26 @@ func (s *E2ETestSuite) TestNewExecGenericAuthorized() {
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
txResp := tc.respType.(*sdk.TxResponse)
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, txResp.TxHash, tc.expectedCode))
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), txResp.TxHash, tc.expectedCode))
}
})
}
}
func (s *E2ETestSuite) TestNewExecGrantAuthorized() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
grantee := s.grantee[0]
grantee1 := s.grantee[2]
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()
_, err := authzclitestutil.CreateGrant(
val.ClientCtx,
val.GetClientCtx(),
[]string{
grantee.String(),
"send",
fmt.Sprintf("--%s=12%stoken", cli.FlagSpendLimit, val.Moniker),
fmt.Sprintf("--%s=12%stoken", cli.FlagSpendLimit, val.GetMoniker()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%d", cli.FlagExpiration, twoHours),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
@ -345,9 +345,9 @@ func (s *E2ETestSuite) TestNewExecGrantAuthorized() {
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
from := val.Address
from := val.GetAddress()
tokens := sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), math.NewInt(12)),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), math.NewInt(12)),
)
msgSend := &bank.MsgSend{
FromAddress: from.String(),
@ -355,7 +355,7 @@ func (s *E2ETestSuite) TestNewExecGrantAuthorized() {
Amount: tokens,
}
normalGeneratedTx, err := clitestutil.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend,
from,
clitestutil.TestTxConfig{
@ -418,7 +418,7 @@ func (s *E2ETestSuite) TestNewExecGrantAuthorized() {
tc := tc
s.Run(tc.name, func() {
cmd := cli.NewCmdExecAuthorization()
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
var response sdk.TxResponse
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
@ -433,27 +433,27 @@ func (s *E2ETestSuite) TestNewExecGrantAuthorized() {
default:
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, response.TxHash, tc.expectedCode))
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), response.TxHash, tc.expectedCode))
}
})
}
}
func (s *E2ETestSuite) TestExecSendAuthzWithAllowList() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
grantee := s.grantee[3]
allowedAddr := s.grantee[4]
notAllowedAddr := s.grantee[5]
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()
_, err := authzclitestutil.CreateGrant(
val.ClientCtx,
val.GetClientCtx(),
[]string{
grantee.String(),
"send",
fmt.Sprintf("--%s=100stake", cli.FlagSpendLimit),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%d", cli.FlagExpiration, twoHours),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
@ -463,7 +463,7 @@ func (s *E2ETestSuite) TestExecSendAuthzWithAllowList() {
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
from := val.Address
from := val.GetAddress()
tokens := sdk.NewCoins(
sdk.NewCoin("stake", math.NewInt(12)),
)
@ -474,7 +474,7 @@ func (s *E2ETestSuite) TestExecSendAuthzWithAllowList() {
}
validGeneratedTx, err := clitestutil.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend,
from,
clitestutil.TestTxConfig{
@ -491,7 +491,7 @@ func (s *E2ETestSuite) TestExecSendAuthzWithAllowList() {
Amount: tokens,
}
invalidGeneratedTx, err := clitestutil.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend1,
from,
clitestutil.TestTxConfig{
@ -512,9 +512,9 @@ func (s *E2ETestSuite) TestExecSendAuthzWithAllowList() {
}
var response sdk.TxResponse
cmd := cli.NewCmdExecAuthorization()
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
out, err := clitestutil.ExecTestCLICmd(val.GetClientCtx(), cmd, args)
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(s.network.WaitForNextBlock())
// test sending to not allowed address
@ -525,14 +525,14 @@ func (s *E2ETestSuite) TestExecSendAuthzWithAllowList() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
}
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
out, err = clitestutil.ExecTestCLICmd(val.GetClientCtx(), cmd, args)
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(s.network.WaitForNextBlock())
// query tx and check result
err = s.network.RetryForBlocks(func() error {
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, authcli.QueryTxCmd(), []string{response.TxHash, fmt.Sprintf("--%s=json", flags.FlagOutput)})
out, err = clitestutil.ExecTestCLICmd(val.GetClientCtx(), authcli.QueryTxCmd(), []string{response.TxHash, fmt.Sprintf("--%s=json", flags.FlagOutput)})
return err
}, 3)
s.Require().NoError(err)
@ -540,21 +540,21 @@ func (s *E2ETestSuite) TestExecSendAuthzWithAllowList() {
}
func (s *E2ETestSuite) TestExecDelegateAuthorization() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
grantee := s.grantee[0]
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()
_, err := authzclitestutil.CreateGrant(
val.ClientCtx,
val.GetClientCtx(),
[]string{
grantee.String(),
"delegate",
fmt.Sprintf("--%s=100stake", cli.FlagSpendLimit),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%d", cli.FlagExpiration, twoHours),
fmt.Sprintf("--%s=%s", cli.FlagAllowedValidators, val.ValAddress.String()),
fmt.Sprintf("--%s=%s", cli.FlagAllowedValidators, val.GetValAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
},
)
@ -565,7 +565,7 @@ func (s *E2ETestSuite) TestExecDelegateAuthorization() {
sdk.NewCoin("stake", math.NewInt(50)),
)
delegateTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.staking.v1beta1.MsgDelegate","delegator_address":"%s","validator_address":"%s","amount":{"denom":"%s","amount":"%s"}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.Address.String(), val.ValAddress.String(),
delegateTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.staking.v1beta1.MsgDelegate","delegator_address":"%s","validator_address":"%s","amount":{"denom":"%s","amount":"%s"}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.GetAddress().String(), val.GetValAddress().String(),
tokens.GetDenomByIndex(0), tokens[0].Amount)
execMsg := testutil.WriteToNewTempFile(s.T(), delegateTx)
defer execMsg.Close()
@ -622,7 +622,7 @@ func (s *E2ETestSuite) TestExecDelegateAuthorization() {
tc := tc
s.Run(tc.name, func() {
cmd := cli.NewCmdExecAuthorization()
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
@ -632,22 +632,22 @@ func (s *E2ETestSuite) TestExecDelegateAuthorization() {
var response sdk.TxResponse
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, response.TxHash, tc.expectedCode))
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), response.TxHash, tc.expectedCode))
}
})
}
// test delegate no spend-limit
_, err = authzclitestutil.CreateGrant(
val.ClientCtx,
val.GetClientCtx(),
[]string{
grantee.String(),
"delegate",
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%d", cli.FlagExpiration, twoHours),
fmt.Sprintf("--%s=%s", cli.FlagAllowedValidators, val.ValAddress.String()),
fmt.Sprintf("--%s=%s", cli.FlagAllowedValidators, val.GetValAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
},
)
@ -658,7 +658,7 @@ func (s *E2ETestSuite) TestExecDelegateAuthorization() {
sdk.NewCoin("stake", math.NewInt(50)),
)
delegateTx = fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.staking.v1beta1.MsgDelegate","delegator_address":"%s","validator_address":"%s","amount":{"denom":"%s","amount":"%s"}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.Address.String(), val.ValAddress.String(),
delegateTx = fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.staking.v1beta1.MsgDelegate","delegator_address":"%s","validator_address":"%s","amount":{"denom":"%s","amount":"%s"}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.GetAddress().String(), val.GetValAddress().String(),
tokens.GetDenomByIndex(0), tokens[0].Amount)
execMsg = testutil.WriteToNewTempFile(s.T(), delegateTx)
defer execMsg.Close()
@ -689,7 +689,7 @@ func (s *E2ETestSuite) TestExecDelegateAuthorization() {
tc := tc
s.Run(tc.name, func() {
cmd := cli.NewCmdExecAuthorization()
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
@ -699,23 +699,23 @@ func (s *E2ETestSuite) TestExecDelegateAuthorization() {
var response sdk.TxResponse
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, response.TxHash, tc.expectedCode))
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), response.TxHash, tc.expectedCode))
}
})
}
// test delegating to denied validator
_, err = authzclitestutil.CreateGrant(
val.ClientCtx,
val.GetClientCtx(),
[]string{
grantee.String(),
"delegate",
fmt.Sprintf("--%s=100stake", cli.FlagSpendLimit),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%d", cli.FlagExpiration, twoHours),
fmt.Sprintf("--%s=%s", cli.FlagDenyValidators, val.ValAddress.String()),
fmt.Sprintf("--%s=%s", cli.FlagDenyValidators, val.GetValAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
},
)
@ -730,39 +730,39 @@ func (s *E2ETestSuite) TestExecDelegateAuthorization() {
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
}
cmd := cli.NewCmdExecAuthorization()
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
out, err := clitestutil.ExecTestCLICmd(val.GetClientCtx(), cmd, args)
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
var response sdk.TxResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
// query tx and check result
err = s.network.RetryForBlocks(func() error {
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, authcli.QueryTxCmd(), []string{response.TxHash, fmt.Sprintf("--%s=json", flags.FlagOutput)})
out, err = clitestutil.ExecTestCLICmd(val.GetClientCtx(), authcli.QueryTxCmd(), []string{response.TxHash, fmt.Sprintf("--%s=json", flags.FlagOutput)})
return err
}, 3)
s.Require().NoError(err)
s.Contains(out.String(), fmt.Sprintf("cannot delegate/undelegate to %s validator", val.ValAddress.String()))
s.Contains(out.String(), fmt.Sprintf("cannot delegate/undelegate to %s validator", val.GetValAddress().String()))
}
func (s *E2ETestSuite) TestExecUndelegateAuthorization() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
grantee := s.grantee[0]
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()
// granting undelegate msg authorization
_, err := authzclitestutil.CreateGrant(
val.ClientCtx,
val.GetClientCtx(),
[]string{
grantee.String(),
"unbond",
fmt.Sprintf("--%s=100stake", cli.FlagSpendLimit),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%d", cli.FlagExpiration, twoHours),
fmt.Sprintf("--%s=%s", cli.FlagAllowedValidators, val.ValAddress.String()),
fmt.Sprintf("--%s=%s", cli.FlagAllowedValidators, val.GetValAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
},
)
@ -771,12 +771,12 @@ func (s *E2ETestSuite) TestExecUndelegateAuthorization() {
// delegating stakes to validator
msg := &stakingtypes.MsgDelegate{
DelegatorAddress: val.Address.String(),
ValidatorAddress: val.ValAddress.String(),
DelegatorAddress: val.GetAddress().String(),
ValidatorAddress: val.GetValAddress().String(),
Amount: sdk.NewCoin("stake", math.NewInt(100)),
}
_, err = clitestutil.SubmitTestTx(val.ClientCtx, msg, val.Address, clitestutil.TestTxConfig{})
_, err = clitestutil.SubmitTestTx(val.GetClientCtx(), msg, val.GetAddress(), clitestutil.TestTxConfig{})
s.Require().NoError(err)
@ -784,7 +784,7 @@ func (s *E2ETestSuite) TestExecUndelegateAuthorization() {
sdk.NewCoin("stake", math.NewInt(50)),
)
undelegateTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.staking.v1beta1.MsgUndelegate","delegator_address":"%s","validator_address":"%s","amount":{"denom":"%s","amount":"%s"}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.Address.String(), val.ValAddress.String(),
undelegateTx := fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.staking.v1beta1.MsgUndelegate","delegator_address":"%s","validator_address":"%s","amount":{"denom":"%s","amount":"%s"}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.GetAddress().String(), val.GetValAddress().String(),
tokens.GetDenomByIndex(0), tokens[0].Amount)
execMsg := testutil.WriteToNewTempFile(s.T(), undelegateTx)
defer execMsg.Close()
@ -844,7 +844,7 @@ func (s *E2ETestSuite) TestExecUndelegateAuthorization() {
tc := tc
s.Run(tc.name, func() {
cmd := cli.NewCmdExecAuthorization()
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
@ -854,22 +854,22 @@ func (s *E2ETestSuite) TestExecUndelegateAuthorization() {
var response sdk.TxResponse
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, response.TxHash, tc.expectedCode))
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), response.TxHash, tc.expectedCode))
}
})
}
// grant undelegate authorization without limit
_, err = authzclitestutil.CreateGrant(
val.ClientCtx,
val.GetClientCtx(),
[]string{
grantee.String(),
"unbond",
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%d", cli.FlagExpiration, twoHours),
fmt.Sprintf("--%s=%s", cli.FlagAllowedValidators, val.ValAddress.String()),
fmt.Sprintf("--%s=%s", cli.FlagAllowedValidators, val.GetValAddress().String()),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
},
)
@ -880,7 +880,7 @@ func (s *E2ETestSuite) TestExecUndelegateAuthorization() {
sdk.NewCoin("stake", math.NewInt(50)),
)
undelegateTx = fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.staking.v1beta1.MsgUndelegate","delegator_address":"%s","validator_address":"%s","amount":{"denom":"%s","amount":"%s"}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.Address.String(), val.ValAddress.String(),
undelegateTx = fmt.Sprintf(`{"body":{"messages":[{"@type":"/cosmos.staking.v1beta1.MsgUndelegate","delegator_address":"%s","validator_address":"%s","amount":{"denom":"%s","amount":"%s"}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}`, val.GetAddress().String(), val.GetValAddress().String(),
tokens.GetDenomByIndex(0), tokens[0].Amount)
execMsg = testutil.WriteToNewTempFile(s.T(), undelegateTx)
defer execMsg.Close()
@ -912,7 +912,7 @@ func (s *E2ETestSuite) TestExecUndelegateAuthorization() {
tc := tc
s.Run(tc.name, func() {
cmd := cli.NewCmdExecAuthorization()
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
@ -922,7 +922,7 @@ func (s *E2ETestSuite) TestExecUndelegateAuthorization() {
var response sdk.TxResponse
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, response.TxHash, tc.expectedCode))
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), response.TxHash, tc.expectedCode))
}
})
}

View File

@ -15,8 +15,8 @@ import (
)
func (s *E2ETestSuite) TestTotalSupplyGRPCHandler() {
val := s.network.Validators[0]
baseURL := val.APIAddress
val := s.network.GetValidators()[0]
baseURL := val.GetAPIAddress()
testCases := []struct {
name string
@ -34,7 +34,7 @@ func (s *E2ETestSuite) TestTotalSupplyGRPCHandler() {
&types.QueryTotalSupplyResponse{},
&types.QueryTotalSupplyResponse{
Supply: sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), s.cfg.AccountTokens),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), s.cfg.AccountTokens),
sdk.NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Add(math.NewInt(10))),
),
Pagination: &query.PageResponse{
@ -94,15 +94,15 @@ func (s *E2ETestSuite) TestTotalSupplyGRPCHandler() {
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
})
}
}
func (s *E2ETestSuite) TestDenomMetadataGRPCHandler() {
val := s.network.Validators[0]
baseURL := val.APIAddress
val := s.network.GetValidators()[0]
baseURL := val.GetAPIAddress()
testCases := []struct {
name string
@ -216,9 +216,9 @@ func (s *E2ETestSuite) TestDenomMetadataGRPCHandler() {
s.Require().NoError(err)
if tc.expErr {
s.Require().Error(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Error(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
} else {
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
}
})
@ -226,8 +226,8 @@ func (s *E2ETestSuite) TestDenomMetadataGRPCHandler() {
}
func (s *E2ETestSuite) TestBalancesGRPCHandler() {
val := s.network.Validators[0]
baseURL := val.APIAddress
val := s.network.GetValidators()[0]
baseURL := val.GetAPIAddress()
testCases := []struct {
name string
@ -237,11 +237,11 @@ func (s *E2ETestSuite) TestBalancesGRPCHandler() {
}{
{
"gRPC total account balance",
fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", baseURL, val.Address.String()),
fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", baseURL, val.GetAddress().String()),
&types.QueryAllBalancesResponse{},
&types.QueryAllBalancesResponse{
Balances: sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), s.cfg.AccountTokens),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), s.cfg.AccountTokens),
sdk.NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Sub(s.cfg.BondedTokens)),
),
Pagination: &query.PageResponse{
@ -251,7 +251,7 @@ func (s *E2ETestSuite) TestBalancesGRPCHandler() {
},
{
"gPRC account balance of a denom",
fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/by_denom?denom=%s", baseURL, val.Address.String(), s.cfg.BondDenom),
fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/by_denom?denom=%s", baseURL, val.GetAddress().String(), s.cfg.BondDenom),
&types.QueryBalanceResponse{},
&types.QueryBalanceResponse{
Balance: &sdk.Coin{
@ -262,7 +262,7 @@ func (s *E2ETestSuite) TestBalancesGRPCHandler() {
},
{
"gPRC account balance of a bogus denom",
fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/by_denom?denom=foobar", baseURL, val.Address.String()),
fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/by_denom?denom=foobar", baseURL, val.GetAddress().String()),
&types.QueryBalanceResponse{},
&types.QueryBalanceResponse{
Balance: &sdk.Coin{
@ -279,7 +279,7 @@ func (s *E2ETestSuite) TestBalancesGRPCHandler() {
resp, err := testutil.GetRequest(tc.url)
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
})
}

View File

@ -23,7 +23,7 @@ type E2ETestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
}
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
@ -93,12 +93,12 @@ func (s *E2ETestSuite) TearDownSuite() {
}
func (s *E2ETestSuite) TestNewSendTxCmdGenOnly() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
from := val.Address
to := val.Address
from := val.GetAddress()
to := val.GetAddress()
amount := sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), math.NewInt(10)),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), math.NewInt(10)),
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)),
)
@ -109,7 +109,7 @@ func (s *E2ETestSuite) TestNewSendTxCmdGenOnly() {
}
bz, err := clitestutil.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend,
from,
clitestutil.TestTxConfig{
@ -124,12 +124,12 @@ func (s *E2ETestSuite) TestNewSendTxCmdGenOnly() {
}
func (s *E2ETestSuite) TestNewSendTxCmdDryRun() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
from := val.Address
to := val.Address
from := val.GetAddress()
to := val.GetAddress()
amount := sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), math.NewInt(10)),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), math.NewInt(10)),
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)),
)
@ -140,7 +140,7 @@ func (s *E2ETestSuite) TestNewSendTxCmdDryRun() {
}
out, err := clitestutil.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend,
from,
clitestutil.TestTxConfig{
@ -153,7 +153,7 @@ func (s *E2ETestSuite) TestNewSendTxCmdDryRun() {
}
func (s *E2ETestSuite) TestNewSendTxCmd() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
testCases := []struct {
name string
@ -166,10 +166,10 @@ func (s *E2ETestSuite) TestNewSendTxCmd() {
}{
{
"valid transaction",
val.Address,
val.Address,
val.GetAddress(),
val.GetAddress(),
sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), math.NewInt(10)),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), math.NewInt(10)),
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)),
),
clitestutil.TestTxConfig{
@ -179,10 +179,10 @@ func (s *E2ETestSuite) TestNewSendTxCmd() {
},
{
"not enough fees",
val.Address,
val.Address,
val.GetAddress(),
val.GetAddress(),
sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), math.NewInt(10)),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), math.NewInt(10)),
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)),
),
clitestutil.TestTxConfig{
@ -195,10 +195,10 @@ func (s *E2ETestSuite) TestNewSendTxCmd() {
},
{
"not enough gas",
val.Address,
val.Address,
val.GetAddress(),
val.GetAddress(),
sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), math.NewInt(10)),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), math.NewInt(10)),
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)),
),
clitestutil.TestTxConfig{
@ -216,14 +216,14 @@ func (s *E2ETestSuite) TestNewSendTxCmd() {
s.Require().NoError(s.network.WaitForNextBlock())
s.Run(tc.name, func() {
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
msgSend := types.MsgSend{
FromAddress: tc.from.String(),
ToAddress: tc.to.String(),
Amount: tc.amount,
}
bz, err := clitestutil.SubmitTestTx(val.ClientCtx, &msgSend, tc.from, tc.config)
bz, err := clitestutil.SubmitTestTx(val.GetClientCtx(), &msgSend, tc.from, tc.config)
if tc.expectErr {
s.Require().Error(err)
} else {
@ -238,7 +238,7 @@ func (s *E2ETestSuite) TestNewSendTxCmd() {
}
func (s *E2ETestSuite) TestNewMultiSendTxCmd() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
testAddr := sdk.AccAddress("cosmos139f7kncmglres2nf3h4hc4tade85ekfr8sulz5")
testCases := []struct {
@ -253,10 +253,10 @@ func (s *E2ETestSuite) TestNewMultiSendTxCmd() {
}{
{
"valid transaction",
val.Address,
[]sdk.AccAddress{val.Address, testAddr},
val.GetAddress(),
[]sdk.AccAddress{val.GetAddress(), testAddr},
sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), math.NewInt(10)),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), math.NewInt(10)),
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)),
),
[]string{
@ -268,10 +268,10 @@ func (s *E2ETestSuite) TestNewMultiSendTxCmd() {
},
{
"valid split transaction",
val.Address,
[]sdk.AccAddress{val.Address, testAddr},
val.GetAddress(),
[]sdk.AccAddress{val.GetAddress(), testAddr},
sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), math.NewInt(10)),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), math.NewInt(10)),
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)),
),
[]string{
@ -284,10 +284,10 @@ func (s *E2ETestSuite) TestNewMultiSendTxCmd() {
},
{
"not enough arguments",
val.Address,
[]sdk.AccAddress{val.Address},
val.GetAddress(),
[]sdk.AccAddress{val.GetAddress()},
sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), math.NewInt(10)),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), math.NewInt(10)),
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)),
),
[]string{
@ -299,10 +299,10 @@ func (s *E2ETestSuite) TestNewMultiSendTxCmd() {
},
{
"chain-id shouldn't be used with offline and generate-only flags",
val.Address,
[]sdk.AccAddress{val.Address, testAddr},
val.GetAddress(),
[]sdk.AccAddress{val.GetAddress(), testAddr},
sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), math.NewInt(10)),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), math.NewInt(10)),
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)),
),
[]string{
@ -316,10 +316,10 @@ func (s *E2ETestSuite) TestNewMultiSendTxCmd() {
},
{
"not enough fees",
val.Address,
[]sdk.AccAddress{val.Address, testAddr},
val.GetAddress(),
[]sdk.AccAddress{val.GetAddress(), testAddr},
sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), math.NewInt(10)),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), math.NewInt(10)),
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)),
),
[]string{
@ -333,10 +333,10 @@ func (s *E2ETestSuite) TestNewMultiSendTxCmd() {
},
{
"not enough gas",
val.Address,
[]sdk.AccAddress{val.Address, testAddr},
val.GetAddress(),
[]sdk.AccAddress{val.GetAddress(), testAddr},
sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), math.NewInt(10)),
sdk.NewCoin(fmt.Sprintf("%stoken", val.GetMoniker()), math.NewInt(10)),
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)),
),
[]string{
@ -356,7 +356,7 @@ func (s *E2ETestSuite) TestNewMultiSendTxCmd() {
s.Require().NoError(s.network.WaitForNextBlock())
s.Run(tc.name, func() {
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
bz, err := MsgMultiSendExec(clientCtx, tc.from, tc.to, tc.amount, tc.args...)
if tc.expectErr {

View File

@ -26,7 +26,7 @@ type E2ETestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
queryClient cmtservice.ServiceClient
}
@ -47,7 +47,7 @@ func (s *E2ETestSuite) SetupSuite() {
s.Require().NoError(s.network.WaitForNextBlock())
s.queryClient = cmtservice.NewServiceClient(s.network.Validators[0].ClientCtx)
s.queryClient = cmtservice.NewServiceClient(s.network.GetValidators()[0].GetClientCtx())
}
func (s *E2ETestSuite) TearDownSuite() {
@ -56,58 +56,58 @@ func (s *E2ETestSuite) TearDownSuite() {
}
func (s *E2ETestSuite) TestQueryNodeInfo() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
res, err := s.queryClient.GetNodeInfo(context.Background(), &cmtservice.GetNodeInfoRequest{})
s.Require().NoError(err)
s.Require().Equal(res.ApplicationVersion.AppName, version.NewInfo().AppName)
restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/node_info", val.APIAddress))
restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/node_info", val.GetAPIAddress()))
s.Require().NoError(err)
var getInfoRes cmtservice.GetNodeInfoResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(restRes, &getInfoRes))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(restRes, &getInfoRes))
s.Require().Equal(getInfoRes.ApplicationVersion.AppName, version.NewInfo().AppName)
}
func (s *E2ETestSuite) TestQuerySyncing() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
_, err := s.queryClient.GetSyncing(context.Background(), &cmtservice.GetSyncingRequest{})
s.Require().NoError(err)
restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/syncing", val.APIAddress))
restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/syncing", val.GetAPIAddress()))
s.Require().NoError(err)
var syncingRes cmtservice.GetSyncingResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(restRes, &syncingRes))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(restRes, &syncingRes))
}
func (s *E2ETestSuite) TestQueryLatestBlock() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
_, err := s.queryClient.GetLatestBlock(context.Background(), &cmtservice.GetLatestBlockRequest{})
s.Require().NoError(err)
restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/latest", val.APIAddress))
restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/latest", val.GetAPIAddress()))
s.Require().NoError(err)
var blockInfoRes cmtservice.GetLatestBlockResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(restRes, &blockInfoRes))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(restRes, &blockInfoRes))
s.Require().Contains(blockInfoRes.SdkBlock.Header.ProposerAddress, "cosmosvalcons")
}
func (s *E2ETestSuite) TestQueryBlockByHeight() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
_, err := s.queryClient.GetBlockByHeight(context.Background(), &cmtservice.GetBlockByHeightRequest{Height: 1})
s.Require().NoError(err)
restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/%d", val.APIAddress, 1))
restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/%d", val.GetAPIAddress(), 1))
s.Require().NoError(err)
var blockInfoRes cmtservice.GetBlockByHeightResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(restRes, &blockInfoRes))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(restRes, &blockInfoRes))
s.Require().Contains(blockInfoRes.SdkBlock.Header.ProposerAddress, "cosmosvalcons")
}
func (s *E2ETestSuite) TestQueryLatestValidatorSet() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
// nil pagination
res, err := s.queryClient.GetLatestValidatorSet(context.Background(), &cmtservice.GetLatestValidatorSetRequest{
@ -117,7 +117,7 @@ func (s *E2ETestSuite) TestQueryLatestValidatorSet() {
s.Require().Equal(1, len(res.Validators))
content, ok := res.Validators[0].PubKey.GetCachedValue().(cryptotypes.PubKey)
s.Require().Equal(true, ok)
s.Require().Equal(content, val.PubKey)
s.Require().Equal(content, val.GetPubKey())
// with pagination
_, err = s.queryClient.GetLatestValidatorSet(context.Background(), &cmtservice.GetLatestValidatorSetRequest{Pagination: &qtypes.PageRequest{
@ -127,22 +127,22 @@ func (s *E2ETestSuite) TestQueryLatestValidatorSet() {
s.Require().NoError(err)
// rest request without pagination
_, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest", val.APIAddress))
_, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest", val.GetAPIAddress()))
s.Require().NoError(err)
// rest request with pagination
restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=%d&pagination.limit=%d", val.APIAddress, 0, 1))
restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=%d&pagination.limit=%d", val.GetAPIAddress(), 0, 1))
s.Require().NoError(err)
var validatorSetRes cmtservice.GetLatestValidatorSetResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(restRes, &validatorSetRes))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(restRes, &validatorSetRes))
s.Require().Equal(1, len(validatorSetRes.Validators))
anyPub, err := codectypes.NewAnyWithValue(val.PubKey)
anyPub, err := codectypes.NewAnyWithValue(val.GetPubKey())
s.Require().NoError(err)
s.Require().Equal(validatorSetRes.Validators[0].PubKey, anyPub)
}
func (s *E2ETestSuite) TestLatestValidatorSet_GRPC() {
vals := s.network.Validators
vals := s.network.GetValidators()
testCases := []struct {
name string
req *cmtservice.GetLatestValidatorSetRequest
@ -166,23 +166,23 @@ func (s *E2ETestSuite) TestLatestValidatorSet_GRPC() {
s.Require().Equal(grpcRes.Pagination.Total, uint64(len(vals)))
content, ok := grpcRes.Validators[0].PubKey.GetCachedValue().(cryptotypes.PubKey)
s.Require().Equal(true, ok)
s.Require().Equal(content, vals[0].PubKey)
s.Require().Equal(content, vals[0].GetPubKey())
}
})
}
}
func (s *E2ETestSuite) TestLatestValidatorSet_GRPCGateway() {
vals := s.network.Validators
vals := s.network.GetValidators()
testCases := []struct {
name string
url string
expErr bool
expErrMsg string
}{
{"no pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest", vals[0].APIAddress), false, ""},
{"pagination invalid fields", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=-1&pagination.limit=-2", vals[0].APIAddress), true, "strconv.ParseUint"},
{"with pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=0&pagination.limit=2", vals[0].APIAddress), false, ""},
{"no pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest", vals[0].GetAPIAddress()), false, ""},
{"pagination invalid fields", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=-1&pagination.limit=-2", vals[0].GetAPIAddress()), true, "strconv.ParseUint"},
{"with pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=0&pagination.limit=2", vals[0].GetAPIAddress()), false, ""},
}
for _, tc := range testCases {
tc := tc
@ -193,10 +193,10 @@ func (s *E2ETestSuite) TestLatestValidatorSet_GRPCGateway() {
s.Require().Contains(string(res), tc.expErrMsg)
} else {
var result cmtservice.GetLatestValidatorSetResponse
err = vals[0].ClientCtx.Codec.UnmarshalJSON(res, &result)
err = vals[0].GetClientCtx().Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)
s.Require().Equal(uint64(len(vals)), result.Pagination.Total)
anyPub, err := codectypes.NewAnyWithValue(vals[0].PubKey)
anyPub, err := codectypes.NewAnyWithValue(vals[0].GetPubKey())
s.Require().NoError(err)
s.Require().Equal(result.Validators[0].PubKey, anyPub)
}
@ -205,7 +205,7 @@ func (s *E2ETestSuite) TestLatestValidatorSet_GRPCGateway() {
}
func (s *E2ETestSuite) TestValidatorSetByHeight_GRPC() {
vals := s.network.Validators
vals := s.network.GetValidators()
testCases := []struct {
name string
req *cmtservice.GetValidatorSetByHeightRequest
@ -234,17 +234,17 @@ func (s *E2ETestSuite) TestValidatorSetByHeight_GRPC() {
}
func (s *E2ETestSuite) TestValidatorSetByHeight_GRPCGateway() {
vals := s.network.Validators
vals := s.network.GetValidators()
testCases := []struct {
name string
url string
expErr bool
expErrMsg string
}{
{"invalid height", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d", vals[0].APIAddress, -1), true, "height must be greater than 0"},
{"no pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d", vals[0].APIAddress, 1), false, ""},
{"pagination invalid fields", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=-1&pagination.limit=-2", vals[0].APIAddress, 1), true, "strconv.ParseUint"},
{"with pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=0&pagination.limit=2", vals[0].APIAddress, 1), false, ""},
{"invalid height", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d", vals[0].GetAPIAddress(), -1), true, "height must be greater than 0"},
{"no pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d", vals[0].GetAPIAddress(), 1), false, ""},
{"pagination invalid fields", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=-1&pagination.limit=-2", vals[0].GetAPIAddress(), 1), true, "strconv.ParseUint"},
{"with pagination", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=0&pagination.limit=2", vals[0].GetAPIAddress(), 1), false, ""},
}
for _, tc := range testCases {
tc := tc
@ -255,7 +255,7 @@ func (s *E2ETestSuite) TestValidatorSetByHeight_GRPCGateway() {
s.Require().Contains(string(res), tc.expErrMsg)
} else {
var result cmtservice.GetValidatorSetByHeightResponse
err = vals[0].ClientCtx.Codec.UnmarshalJSON(res, &result)
err = vals[0].GetClientCtx().Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)
s.Require().Equal(uint64(len(vals)), result.Pagination.Total)
}

View File

@ -20,7 +20,7 @@ type GRPCQueryTestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
}
func (s *GRPCQueryTestSuite) SetupSuite() {
@ -44,8 +44,8 @@ func (s *GRPCQueryTestSuite) TearDownSuite() {
}
func (s *GRPCQueryTestSuite) TestQueryParamsGRPC() {
val := s.network.Validators[0]
baseURL := val.APIAddress
val := s.network.GetValidators()[0]
baseURL := val.GetAPIAddress()
testCases := []struct {
name string
@ -68,15 +68,15 @@ func (s *GRPCQueryTestSuite) TestQueryParamsGRPC() {
resp, err := sdktestutil.GetRequest(tc.url)
s.Run(tc.name, func() {
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Equal(tc.expected, tc.respType)
})
}
}
func (s *GRPCQueryTestSuite) TestQueryValidatorDistributionInfoGRPC() {
val := s.network.Validators[0]
baseURL := val.APIAddress
val := s.network.GetValidators()[0]
baseURL := val.GetAPIAddress()
testCases := []struct {
name string
@ -92,7 +92,7 @@ func (s *GRPCQueryTestSuite) TestQueryValidatorDistributionInfoGRPC() {
},
{
"gRPC request with valid validator address ",
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s", baseURL, val.ValAddress.String()),
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s", baseURL, val.GetValAddress().String()),
false,
&types.QueryValidatorDistributionInfoResponse{},
},
@ -103,18 +103,18 @@ func (s *GRPCQueryTestSuite) TestQueryValidatorDistributionInfoGRPC() {
resp, err := sdktestutil.GetRequest(tc.url)
s.Run(tc.name, func() {
if tc.expErr {
s.Require().Error(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Error(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
} else {
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
}
})
}
}
func (s *GRPCQueryTestSuite) TestQueryOutstandingRewardsGRPC() {
val := s.network.Validators[0]
baseURL := val.APIAddress
val := s.network.GetValidators()[0]
baseURL := val.GetAPIAddress()
rewards, err := sdk.ParseDecCoins("19.6stake")
s.Require().NoError(err)
@ -137,7 +137,7 @@ func (s *GRPCQueryTestSuite) TestQueryOutstandingRewardsGRPC() {
},
{
"gRPC request params valid address",
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/outstanding_rewards", baseURL, val.ValAddress.String()),
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/outstanding_rewards", baseURL, val.GetValAddress().String()),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "2",
},
@ -156,10 +156,10 @@ func (s *GRPCQueryTestSuite) TestQueryOutstandingRewardsGRPC() {
resp, err := sdktestutil.GetRequestWithHeaders(tc.url, tc.headers)
s.Run(tc.name, func() {
if tc.expErr {
s.Require().Error(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Error(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
} else {
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
}
})
@ -167,8 +167,8 @@ func (s *GRPCQueryTestSuite) TestQueryOutstandingRewardsGRPC() {
}
func (s *GRPCQueryTestSuite) TestQueryValidatorCommissionGRPC() {
val := s.network.Validators[0]
baseURL := val.APIAddress
val := s.network.GetValidators()[0]
baseURL := val.GetAPIAddress()
commission, err := sdk.ParseDecCoins("9.8stake")
s.Require().NoError(err)
@ -191,7 +191,7 @@ func (s *GRPCQueryTestSuite) TestQueryValidatorCommissionGRPC() {
},
{
"gRPC request params valid address",
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/commission", baseURL, val.ValAddress.String()),
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/commission", baseURL, val.GetValAddress().String()),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "2",
},
@ -210,10 +210,10 @@ func (s *GRPCQueryTestSuite) TestQueryValidatorCommissionGRPC() {
resp, err := sdktestutil.GetRequestWithHeaders(tc.url, tc.headers)
s.Run(tc.name, func() {
if tc.expErr {
s.Require().Error(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Error(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
} else {
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
}
})
@ -221,8 +221,8 @@ func (s *GRPCQueryTestSuite) TestQueryValidatorCommissionGRPC() {
}
func (s *GRPCQueryTestSuite) TestQuerySlashesGRPC() {
val := s.network.Validators[0]
baseURL := val.APIAddress
val := s.network.GetValidators()[0]
baseURL := val.GetAPIAddress()
testCases := []struct {
name string
@ -240,21 +240,21 @@ func (s *GRPCQueryTestSuite) TestQuerySlashesGRPC() {
},
{
"invalid start height",
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes?starting_height=%s&ending_height=%s", baseURL, val.ValAddress.String(), "-1", "3"),
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes?starting_height=%s&ending_height=%s", baseURL, val.GetValAddress().String(), "-1", "3"),
true,
&types.QueryValidatorSlashesResponse{},
nil,
},
{
"invalid start height",
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes?starting_height=%s&ending_height=%s", baseURL, val.ValAddress.String(), "1", "-3"),
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes?starting_height=%s&ending_height=%s", baseURL, val.GetValAddress().String(), "1", "-3"),
true,
&types.QueryValidatorSlashesResponse{},
nil,
},
{
"valid request get slashes",
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes?starting_height=%s&ending_height=%s", baseURL, val.ValAddress.String(), "1", "3"),
fmt.Sprintf("%s/cosmos/distribution/v1beta1/validators/%s/slashes?starting_height=%s&ending_height=%s", baseURL, val.GetValAddress().String(), "1", "3"),
false,
&types.QueryValidatorSlashesResponse{},
&types.QueryValidatorSlashesResponse{
@ -269,10 +269,10 @@ func (s *GRPCQueryTestSuite) TestQuerySlashesGRPC() {
s.Run(tc.name, func() {
if tc.expErr {
s.Require().Error(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Error(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
} else {
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
}
})
@ -280,8 +280,8 @@ func (s *GRPCQueryTestSuite) TestQuerySlashesGRPC() {
}
func (s *GRPCQueryTestSuite) TestQueryDelegatorRewardsGRPC() {
val := s.network.Validators[0]
baseURL := val.APIAddress
val := s.network.GetValidators()[0]
baseURL := val.GetAPIAddress()
rewards, err := sdk.ParseDecCoins("9.8stake")
s.Require().NoError(err)
@ -304,7 +304,7 @@ func (s *GRPCQueryTestSuite) TestQueryDelegatorRewardsGRPC() {
},
{
"valid request",
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards", baseURL, val.Address.String()),
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards", baseURL, val.GetAddress().String()),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "2",
},
@ -312,14 +312,14 @@ func (s *GRPCQueryTestSuite) TestQueryDelegatorRewardsGRPC() {
&types.QueryDelegationTotalRewardsResponse{},
&types.QueryDelegationTotalRewardsResponse{
Rewards: []types.DelegationDelegatorReward{
types.NewDelegationDelegatorReward(val.ValAddress.String(), rewards),
types.NewDelegationDelegatorReward(val.GetValAddress().String(), rewards),
},
Total: rewards,
},
},
{
"wrong validator address(specific validator rewards)",
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards/%s", baseURL, val.Address.String(), "wrongValAddress"),
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards/%s", baseURL, val.GetAddress().String(), "wrongValAddress"),
map[string]string{},
true,
&types.QueryDelegationTotalRewardsResponse{},
@ -327,7 +327,7 @@ func (s *GRPCQueryTestSuite) TestQueryDelegatorRewardsGRPC() {
},
{
"valid request(specific validator rewards)",
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards/%s", baseURL, val.Address.String(), val.ValAddress.String()),
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/rewards/%s", baseURL, val.GetAddress().String(), val.GetValAddress().String()),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "2",
},
@ -345,10 +345,10 @@ func (s *GRPCQueryTestSuite) TestQueryDelegatorRewardsGRPC() {
s.Run(tc.name, func() {
if tc.expErr {
s.Require().Error(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Error(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
} else {
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
}
})
@ -356,8 +356,8 @@ func (s *GRPCQueryTestSuite) TestQueryDelegatorRewardsGRPC() {
}
func (s *GRPCQueryTestSuite) TestQueryDelegatorValidatorsGRPC() {
val := s.network.Validators[0]
baseURL := val.APIAddress
val := s.network.GetValidators()[0]
baseURL := val.GetAPIAddress()
testCases := []struct {
name string
@ -382,11 +382,11 @@ func (s *GRPCQueryTestSuite) TestQueryDelegatorValidatorsGRPC() {
},
{
"valid request",
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/validators", baseURL, val.Address.String()),
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/validators", baseURL, val.GetAddress().String()),
false,
&types.QueryDelegatorValidatorsResponse{},
&types.QueryDelegatorValidatorsResponse{
Validators: []string{val.ValAddress.String()},
Validators: []string{val.GetValAddress().String()},
},
},
}
@ -397,10 +397,10 @@ func (s *GRPCQueryTestSuite) TestQueryDelegatorValidatorsGRPC() {
s.Run(tc.name, func() {
if tc.expErr {
s.Require().Error(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Error(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
} else {
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
}
})
@ -408,8 +408,8 @@ func (s *GRPCQueryTestSuite) TestQueryDelegatorValidatorsGRPC() {
}
func (s *GRPCQueryTestSuite) TestQueryWithdrawAddressGRPC() {
val := s.network.Validators[0]
baseURL := val.APIAddress
val := s.network.GetValidators()[0]
baseURL := val.GetAPIAddress()
testCases := []struct {
name string
@ -434,11 +434,11 @@ func (s *GRPCQueryTestSuite) TestQueryWithdrawAddressGRPC() {
},
{
"valid request",
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/withdraw_address", baseURL, val.Address.String()),
fmt.Sprintf("%s/cosmos/distribution/v1beta1/delegators/%s/withdraw_address", baseURL, val.GetAddress().String()),
false,
&types.QueryDelegatorWithdrawAddressResponse{},
&types.QueryDelegatorWithdrawAddressResponse{
WithdrawAddress: val.Address.String(),
WithdrawAddress: val.GetAddress().String(),
},
},
}
@ -449,10 +449,10 @@ func (s *GRPCQueryTestSuite) TestQueryWithdrawAddressGRPC() {
s.Run(tc.name, func() {
if tc.expErr {
s.Require().Error(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Error(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
} else {
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
}
})

View File

@ -24,7 +24,7 @@ type WithdrawAllTestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
}
func (s *WithdrawAllTestSuite) SetupSuite() {
@ -50,11 +50,11 @@ func (s *WithdrawAllTestSuite) TearDownSuite() {
// `NumValidators` the existing tests are leading to non-determnism so created new suite for this test.
func (s *WithdrawAllTestSuite) TestNewWithdrawAllRewardsGenerateOnly() {
require := s.Require()
val := s.network.Validators[0]
val1 := s.network.Validators[1]
clientCtx := val.ClientCtx
val := s.network.GetValidators()[0]
val1 := s.network.GetValidators()[1]
clientCtx := val.GetClientCtx()
info, _, err := val.ClientCtx.Keyring.NewMnemonic("newAccount", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
info, _, err := val.GetClientCtx().Keyring.NewMnemonic("newAccount", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
require.NoError(err)
pubkey, err := info.GetPubKey()
@ -63,14 +63,14 @@ func (s *WithdrawAllTestSuite) TestNewWithdrawAllRewardsGenerateOnly() {
newAddr := sdk.AccAddress(pubkey.Address())
msgSend := &banktypes.MsgSend{
FromAddress: val.Address.String(),
FromAddress: val.GetAddress().String(),
ToAddress: newAddr.String(),
Amount: sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(2000))),
}
_, err = clitestutil.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend,
val.Address,
val.GetAddress(),
clitestutil.TestTxConfig{},
)
@ -80,22 +80,22 @@ func (s *WithdrawAllTestSuite) TestNewWithdrawAllRewardsGenerateOnly() {
// delegate 500 tokens to validator1
msg := &stakingtypes.MsgDelegate{
DelegatorAddress: newAddr.String(),
ValidatorAddress: val.ValAddress.String(),
ValidatorAddress: val.GetValAddress().String(),
Amount: sdk.NewCoin("stake", math.NewInt(500)),
}
_, err = clitestutil.SubmitTestTx(val.ClientCtx, msg, newAddr, clitestutil.TestTxConfig{})
_, err = clitestutil.SubmitTestTx(val.GetClientCtx(), msg, newAddr, clitestutil.TestTxConfig{})
require.NoError(err)
require.NoError(s.network.WaitForNextBlock())
// delegate 500 tokens to validator2
msg2 := &stakingtypes.MsgDelegate{
DelegatorAddress: newAddr.String(),
ValidatorAddress: val1.ValAddress.String(),
ValidatorAddress: val1.GetValAddress().String(),
Amount: sdk.NewCoin("stake", math.NewInt(500)),
}
_, err = clitestutil.SubmitTestTx(val.ClientCtx, msg2, newAddr, clitestutil.TestTxConfig{})
_, err = clitestutil.SubmitTestTx(val.GetClientCtx(), msg2, newAddr, clitestutil.TestTxConfig{})
require.NoError(err)
require.NoError(s.network.WaitForNextBlock())

View File

@ -22,7 +22,7 @@ type DepositTestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
}
func NewDepositTestSuite(cfg network.Config) *DepositTestSuite {
@ -37,7 +37,7 @@ func (s *DepositTestSuite) SetupSuite() {
s.Require().NoError(err)
}
func (s *DepositTestSuite) submitProposal(val *network.Validator, initialDeposit sdk.Coin, name string) uint64 {
func (s *DepositTestSuite) submitProposal(val network.ValidatorI, initialDeposit sdk.Coin, name string) uint64 {
var exactArgs []string
if !initialDeposit.IsZero() {
@ -45,8 +45,8 @@ func (s *DepositTestSuite) submitProposal(val *network.Validator, initialDeposit
}
_, err := govclitestutil.MsgSubmitLegacyProposal(
val.ClientCtx,
val.Address.String(),
val.GetClientCtx(),
val.GetAddress().String(),
fmt.Sprintf("Text Proposal %s", name),
"Where is the title!?",
v1beta1.ProposalTypeText,
@ -56,7 +56,7 @@ func (s *DepositTestSuite) submitProposal(val *network.Validator, initialDeposit
s.Require().NoError(s.network.WaitForNextBlock())
// query proposals, return the last's id
res, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals", val.APIAddress))
res, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals", val.GetAPIAddress()))
s.Require().NoError(err)
var proposals v1.QueryProposalsResponse
err = s.cfg.Codec.UnmarshalJSON(res, &proposals)
@ -72,7 +72,7 @@ func (s *DepositTestSuite) TearDownSuite() {
}
func (s *DepositTestSuite) TestQueryDepositsWithInitialDeposit() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens)
// submit proposal with an initial deposit
@ -93,14 +93,14 @@ func (s *DepositTestSuite) TestQueryDepositsWithInitialDeposit() {
}
func (s *DepositTestSuite) TestQueryProposalAfterVotingPeriod() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens.Sub(math.NewInt(50)))
// submit proposal with an initial deposit
id := s.submitProposal(val, depositAmount, "TestQueryProposalAfterVotingPeriod")
proposalID := strconv.FormatUint(id, 10)
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals", val.APIAddress))
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals", val.GetAPIAddress()))
s.Require().NoError(err)
var proposals v1.QueryProposalsResponse
err = s.cfg.Codec.UnmarshalJSON(resp, &proposals)
@ -108,7 +108,7 @@ func (s *DepositTestSuite) TestQueryProposalAfterVotingPeriod() {
s.Require().GreaterOrEqual(len(proposals.Proposals), 1)
// query proposal
resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.APIAddress, proposalID))
resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.GetAPIAddress(), proposalID))
s.Require().NoError(err)
var proposal v1.QueryProposalResponse
err = s.cfg.Codec.UnmarshalJSON(resp, &proposal)
@ -118,7 +118,7 @@ func (s *DepositTestSuite) TestQueryProposalAfterVotingPeriod() {
time.Sleep(25 * time.Second)
// query proposal
resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.APIAddress, proposalID))
resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.GetAPIAddress(), proposalID))
s.Require().NoError(err)
s.Require().Contains(string(resp), fmt.Sprintf("proposal %s doesn't exist", proposalID))
@ -127,10 +127,10 @@ func (s *DepositTestSuite) TestQueryProposalAfterVotingPeriod() {
s.Require().Len(deposits.Deposits, 0)
}
func (s *DepositTestSuite) queryDeposits(val *network.Validator, proposalID string, exceptErr bool, message string) *v1.QueryDepositsResponse {
func (s *DepositTestSuite) queryDeposits(val network.ValidatorI, proposalID string, exceptErr bool, message string) *v1.QueryDepositsResponse {
s.Require().NoError(s.network.WaitForNextBlock())
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits", val.APIAddress, proposalID))
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits", val.GetAPIAddress(), proposalID))
s.Require().NoError(err)
if exceptErr {
@ -139,16 +139,16 @@ func (s *DepositTestSuite) queryDeposits(val *network.Validator, proposalID stri
}
var depositsRes v1.QueryDepositsResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &depositsRes)
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &depositsRes)
s.Require().NoError(err)
return &depositsRes
}
func (s *DepositTestSuite) queryDeposit(val *network.Validator, proposalID string, exceptErr bool, message string) *v1.QueryDepositResponse {
func (s *DepositTestSuite) queryDeposit(val network.ValidatorI, proposalID string, exceptErr bool, message string) *v1.QueryDepositResponse {
s.Require().NoError(s.network.WaitForNextBlock())
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.APIAddress, proposalID, val.Address.String()))
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.GetAPIAddress(), proposalID, val.GetAddress().String()))
s.Require().NoError(err)
if exceptErr {
@ -157,7 +157,7 @@ func (s *DepositTestSuite) queryDeposit(val *network.Validator, proposalID strin
}
var depositRes v1.QueryDepositResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &depositRes)
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &depositRes)
s.Require().NoError(err)
return &depositRes

View File

@ -13,7 +13,7 @@ import (
)
func (s *E2ETestSuite) TestGetProposalGRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
testCases := []struct {
name string
@ -22,17 +22,17 @@ func (s *E2ETestSuite) TestGetProposalGRPC() {
}{
{
"empty proposal",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.APIAddress, ""),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.GetAPIAddress(), ""),
true,
},
{
"get non existing proposal",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.APIAddress, "10"),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.GetAPIAddress(), "10"),
true,
},
{
"get proposal with id",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.APIAddress, "1"),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.GetAPIAddress(), "1"),
false,
},
}
@ -44,7 +44,7 @@ func (s *E2ETestSuite) TestGetProposalGRPC() {
s.Require().NoError(err)
var proposal v1.QueryProposalResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &proposal)
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &proposal)
if tc.expErr {
s.Require().Error(err)
@ -57,7 +57,7 @@ func (s *E2ETestSuite) TestGetProposalGRPC() {
}
func (s *E2ETestSuite) TestGetProposalsGRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
testCases := []struct {
name string
@ -68,7 +68,7 @@ func (s *E2ETestSuite) TestGetProposalsGRPC() {
}{
{
"get proposals with height 1",
fmt.Sprintf("%s/cosmos/gov/v1/proposals", val.APIAddress),
fmt.Sprintf("%s/cosmos/gov/v1/proposals", val.GetAPIAddress()),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "1",
},
@ -77,14 +77,14 @@ func (s *E2ETestSuite) TestGetProposalsGRPC() {
},
{
"valid request",
fmt.Sprintf("%s/cosmos/gov/v1/proposals", val.APIAddress),
fmt.Sprintf("%s/cosmos/gov/v1/proposals", val.GetAPIAddress()),
map[string]string{},
4,
false,
},
{
"valid request with filter by status",
fmt.Sprintf("%s/cosmos/gov/v1/proposals?proposal_status=1", val.APIAddress),
fmt.Sprintf("%s/cosmos/gov/v1/proposals?proposal_status=1", val.GetAPIAddress()),
map[string]string{},
1,
false,
@ -98,7 +98,7 @@ func (s *E2ETestSuite) TestGetProposalsGRPC() {
s.Require().NoError(err)
var proposals v1.QueryProposalsResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &proposals)
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &proposals)
if tc.expErr {
s.Require().Empty(proposals.Proposals)
@ -111,9 +111,9 @@ func (s *E2ETestSuite) TestGetProposalsGRPC() {
}
func (s *E2ETestSuite) TestGetProposalVoteGRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
voterAddressBech32 := val.Address.String()
voterAddressBech32 := val.GetAddress().String()
testCases := []struct {
name string
@ -123,31 +123,31 @@ func (s *E2ETestSuite) TestGetProposalVoteGRPC() {
}{
{
"empty proposal",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.APIAddress, "", voterAddressBech32),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.GetAPIAddress(), "", voterAddressBech32),
true,
v1.NewNonSplitVoteOption(v1.OptionYes),
},
{
"get non existing proposal",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.APIAddress, "10", voterAddressBech32),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.GetAPIAddress(), "10", voterAddressBech32),
true,
v1.NewNonSplitVoteOption(v1.OptionYes),
},
{
"get proposal with wrong voter address",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.APIAddress, "1", "wrongVoterAddress"),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.GetAPIAddress(), "1", "wrongVoterAddress"),
true,
v1.NewNonSplitVoteOption(v1.OptionYes),
},
{
"get proposal with id",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.APIAddress, "1", voterAddressBech32),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.GetAPIAddress(), "1", voterAddressBech32),
false,
v1.NewNonSplitVoteOption(v1.OptionYes),
},
{
"get proposal with id for split vote",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.APIAddress, "3", voterAddressBech32),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes/%s", val.GetAPIAddress(), "3", voterAddressBech32),
false,
v1.WeightedVoteOptions{
&v1.WeightedVoteOption{Option: v1.OptionYes, Weight: math.LegacyNewDecWithPrec(60, 2).String()},
@ -165,7 +165,7 @@ func (s *E2ETestSuite) TestGetProposalVoteGRPC() {
s.Require().NoError(err)
var vote v1.QueryVoteResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &vote)
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &vote)
if tc.expErr {
s.Require().Error(err)
@ -183,7 +183,7 @@ func (s *E2ETestSuite) TestGetProposalVoteGRPC() {
}
func (s *E2ETestSuite) TestGetProposalVotesGRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
testCases := []struct {
name string
@ -192,12 +192,12 @@ func (s *E2ETestSuite) TestGetProposalVotesGRPC() {
}{
{
"votes with empty proposal id",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes", val.APIAddress, ""),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes", val.GetAPIAddress(), ""),
true,
},
{
"get votes with valid id",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes", val.APIAddress, "1"),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/votes", val.GetAPIAddress(), "1"),
false,
},
}
@ -209,7 +209,7 @@ func (s *E2ETestSuite) TestGetProposalVotesGRPC() {
s.Require().NoError(err)
var votes v1.QueryVotesResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &votes)
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &votes)
if tc.expErr {
s.Require().Error(err)
@ -222,7 +222,7 @@ func (s *E2ETestSuite) TestGetProposalVotesGRPC() {
}
func (s *E2ETestSuite) TestGetProposalDepositGRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
testCases := []struct {
name string
@ -231,22 +231,22 @@ func (s *E2ETestSuite) TestGetProposalDepositGRPC() {
}{
{
"get deposit with empty proposal id",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.APIAddress, "", val.Address.String()),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.GetAPIAddress(), "", val.GetAddress().String()),
true,
},
{
"get deposit of non existing proposal",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.APIAddress, "10", val.Address.String()),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.GetAPIAddress(), "10", val.GetAddress().String()),
true,
},
{
"get deposit with wrong depositer address",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.APIAddress, "1", "wrongDepositerAddress"),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.GetAPIAddress(), "1", "wrongDepositerAddress"),
true,
},
{
"get deposit valid request",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.APIAddress, "1", val.Address.String()),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.GetAPIAddress(), "1", val.GetAddress().String()),
false,
},
}
@ -258,7 +258,7 @@ func (s *E2ETestSuite) TestGetProposalDepositGRPC() {
s.Require().NoError(err)
var deposit v1.QueryDepositResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &deposit)
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &deposit)
if tc.expErr {
s.Require().Error(err)
@ -271,7 +271,7 @@ func (s *E2ETestSuite) TestGetProposalDepositGRPC() {
}
func (s *E2ETestSuite) TestGetProposalDepositsGRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
testCases := []struct {
name string
@ -280,12 +280,12 @@ func (s *E2ETestSuite) TestGetProposalDepositsGRPC() {
}{
{
"get deposits with empty proposal id",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits", val.APIAddress, ""),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits", val.GetAPIAddress(), ""),
true,
},
{
"valid request",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits", val.APIAddress, "1"),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits", val.GetAPIAddress(), "1"),
false,
},
}
@ -297,7 +297,7 @@ func (s *E2ETestSuite) TestGetProposalDepositsGRPC() {
s.Require().NoError(err)
var deposits v1.QueryDepositsResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &deposits)
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &deposits)
if tc.expErr {
s.Require().Error(err)
@ -311,7 +311,7 @@ func (s *E2ETestSuite) TestGetProposalDepositsGRPC() {
}
func (s *E2ETestSuite) TestGetTallyGRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
testCases := []struct {
name string
@ -320,17 +320,17 @@ func (s *E2ETestSuite) TestGetTallyGRPC() {
}{
{
"get tally with no proposal id",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/tally", val.APIAddress, ""),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/tally", val.GetAPIAddress(), ""),
true,
},
{
"get tally with non existing proposal",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/tally", val.APIAddress, "10"),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/tally", val.GetAPIAddress(), "10"),
true,
},
{
"get tally valid request",
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/tally", val.APIAddress, "1"),
fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/tally", val.GetAPIAddress(), "1"),
false,
},
}
@ -342,7 +342,7 @@ func (s *E2ETestSuite) TestGetTallyGRPC() {
s.Require().NoError(err)
var tally v1.QueryTallyResultResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &tally)
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &tally)
if tc.expErr {
s.Require().Error(err)
@ -355,7 +355,7 @@ func (s *E2ETestSuite) TestGetTallyGRPC() {
}
func (s *E2ETestSuite) TestGetParamsGRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
params := v1.DefaultParams()
dp := v1.NewDepositParams(params.MinDeposit, params.MaxDepositPeriod) //nolint:staticcheck // we use deprecated gov commands here, but we don't want to remove them
@ -371,26 +371,26 @@ func (s *E2ETestSuite) TestGetParamsGRPC() {
}{
{
"request params with empty params type",
fmt.Sprintf("%s/cosmos/gov/v1/params/%s", val.APIAddress, ""),
fmt.Sprintf("%s/cosmos/gov/v1/params/%s", val.GetAPIAddress(), ""),
true, nil, nil,
},
{
"get deposit params",
fmt.Sprintf("%s/cosmos/gov/v1/params/%s", val.APIAddress, v1.ParamDeposit),
fmt.Sprintf("%s/cosmos/gov/v1/params/%s", val.GetAPIAddress(), v1.ParamDeposit),
false,
&v1.QueryParamsResponse{},
&v1.QueryParamsResponse{DepositParams: &dp, Params: &params},
},
{
"get vote params",
fmt.Sprintf("%s/cosmos/gov/v1/params/%s", val.APIAddress, v1.ParamVoting),
fmt.Sprintf("%s/cosmos/gov/v1/params/%s", val.GetAPIAddress(), v1.ParamVoting),
false,
&v1.QueryParamsResponse{},
&v1.QueryParamsResponse{VotingParams: &vp, Params: &params},
},
{
"get tally params",
fmt.Sprintf("%s/cosmos/gov/v1/params/%s", val.APIAddress, v1.ParamTallying),
fmt.Sprintf("%s/cosmos/gov/v1/params/%s", val.GetAPIAddress(), v1.ParamTallying),
false,
&v1.QueryParamsResponse{},
&v1.QueryParamsResponse{TallyParams: &tp, Params: &params},
@ -402,7 +402,7 @@ func (s *E2ETestSuite) TestGetParamsGRPC() {
s.Run(tc.name, func() {
resp, err := testutil.GetRequest(tc.url)
s.Require().NoError(err)
err = val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType)
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType)
if tc.expErr {
s.Require().Error(err)

View File

@ -26,7 +26,7 @@ type E2ETestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
}
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
@ -41,12 +41,12 @@ func (s *E2ETestSuite) SetupSuite() {
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
val := s.network.Validators[0]
clientCtx := val.ClientCtx
val := s.network.GetValidators()[0]
clientCtx := val.GetClientCtx()
var resp sdk.TxResponse
// create a proposal with deposit
out, err := govclitestutil.MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(),
out, err := govclitestutil.MsgSubmitLegacyProposal(val.GetClientCtx(), val.GetAddress().String(),
"Text Proposal 1", "Where is the title!?", v1beta1.ProposalTypeText,
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens).String()))
s.Require().NoError(err)
@ -54,14 +54,14 @@ func (s *E2ETestSuite) SetupSuite() {
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, 0))
// vote for proposal
out, err = govclitestutil.MsgVote(val.ClientCtx, val.Address.String(), "1", "yes")
out, err = govclitestutil.MsgVote(val.GetClientCtx(), val.GetAddress().String(), "1", "yes")
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, 0))
// create a proposal with a small deposit
minimumAcceptedDep := v1.DefaultMinDepositTokens.ToLegacyDec().Mul(v1.DefaultMinDepositRatio).Ceil().TruncateInt()
out, err = govclitestutil.MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(),
out, err = govclitestutil.MsgSubmitLegacyProposal(val.GetClientCtx(), val.GetAddress().String(),
"Text Proposal 2", "Where is the title!?", v1beta1.ProposalTypeText,
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, minimumAcceptedDep).String()))
@ -70,7 +70,7 @@ func (s *E2ETestSuite) SetupSuite() {
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, 0))
// create a proposal3 with deposit
out, err = govclitestutil.MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(),
out, err = govclitestutil.MsgSubmitLegacyProposal(val.GetClientCtx(), val.GetAddress().String(),
"Text Proposal 3", "Where is the title!?", v1beta1.ProposalTypeText,
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens).String()))
s.Require().NoError(err)
@ -78,7 +78,7 @@ func (s *E2ETestSuite) SetupSuite() {
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, 0))
// create a proposal4 with deposit to check the cancel proposal cli tx
out, err = govclitestutil.MsgSubmitLegacyProposal(val.ClientCtx, val.Address.String(),
out, err = govclitestutil.MsgSubmitLegacyProposal(val.GetClientCtx(), val.GetAddress().String(),
"Text Proposal 4", "Where is the title!?", v1beta1.ProposalTypeText,
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens).String()))
s.Require().NoError(err)
@ -86,7 +86,7 @@ func (s *E2ETestSuite) SetupSuite() {
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, 0))
// vote for proposal3 as val
out, err = govclitestutil.MsgVote(val.ClientCtx, val.Address.String(), "3", "yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05")
out, err = govclitestutil.MsgVote(val.GetClientCtx(), val.GetAddress().String(), "3", "yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05")
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, 0))
@ -98,7 +98,7 @@ func (s *E2ETestSuite) TearDownSuite() {
}
func (s *E2ETestSuite) TestNewCmdSubmitProposal() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
// Create a legacy proposal JSON, make sure it doesn't pass this new CLI
// command.
@ -154,7 +154,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitProposal() {
"valid proposal",
[]string{
validPropFile.Name(),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
@ -168,7 +168,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitProposal() {
s.Run(tc.name, func() {
cmd := cli.NewCmdSubmitProposal()
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
@ -184,7 +184,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitProposal() {
}
func (s *E2ETestSuite) TestNewCmdSubmitLegacyProposal() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
invalidProp := `{
"title": "",
"description": "Where is the title!?",
@ -213,7 +213,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitLegacyProposal() {
"invalid proposal (file)",
[]string{
fmt.Sprintf("--%s=%s", cli.FlagProposal, invalidPropFile.Name()), //nolint:staticcheck // we are intentionally using a deprecated flag here.
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
},
@ -225,7 +225,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitLegacyProposal() {
fmt.Sprintf("--%s='Where is the title!?'", cli.FlagDescription), //nolint:staticcheck // we are intentionally using a deprecated flag here.
fmt.Sprintf("--%s=%s", cli.FlagProposalType, v1beta1.ProposalTypeText), //nolint:staticcheck // we are intentionally using a deprecated flag here.
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10000)).String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
},
@ -236,7 +236,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitLegacyProposal() {
//nolint:staticcheck // we are intentionally using a deprecated flag here.
[]string{
fmt.Sprintf("--%s=%s", cli.FlagProposal, validPropFile.Name()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
@ -250,7 +250,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitLegacyProposal() {
fmt.Sprintf("--%s='Where is the title!?'", cli.FlagDescription), //nolint:staticcheck // we are intentionally using a deprecated flag here.
fmt.Sprintf("--%s=%s", cli.FlagProposalType, v1beta1.ProposalTypeText), //nolint:staticcheck // we are intentionally using a deprecated flag here.
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, math.NewInt(100000)).String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
@ -264,7 +264,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitLegacyProposal() {
s.Run(tc.name, func() {
cmd := cli.NewCmdSubmitLegacyProposal()
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
@ -280,7 +280,7 @@ func (s *E2ETestSuite) TestNewCmdSubmitLegacyProposal() {
}
func (s *E2ETestSuite) TestNewCmdWeightedVote() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
testCases := []struct {
name string
@ -298,7 +298,7 @@ func (s *E2ETestSuite) TestNewCmdWeightedVote() {
[]string{
"10",
"yes",
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
@ -310,7 +310,7 @@ func (s *E2ETestSuite) TestNewCmdWeightedVote() {
[]string{
"1",
"yes",
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
@ -322,7 +322,7 @@ func (s *E2ETestSuite) TestNewCmdWeightedVote() {
[]string{
"1",
"yes",
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--metadata=%s", "AQ=="),
@ -335,7 +335,7 @@ func (s *E2ETestSuite) TestNewCmdWeightedVote() {
[]string{
"1",
"yes/0.6,no/0.3,abstain/0.05,no_with_veto/0.05",
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
@ -347,7 +347,7 @@ func (s *E2ETestSuite) TestNewCmdWeightedVote() {
[]string{
"1",
"yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05",
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.GetAddress().String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
@ -360,7 +360,7 @@ func (s *E2ETestSuite) TestNewCmdWeightedVote() {
tc := tc
s.Run(tc.name, func() {
cmd := cli.NewCmdWeightedVote()
clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
var txResp sdk.TxResponse
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)

View File

@ -27,7 +27,7 @@ type E2ETestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
group *group.GroupInfo
groupPolicies []*group.GroupPolicyInfo
@ -57,10 +57,10 @@ func (s *E2ETestSuite) SetupSuite() {
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
// create a new account
info, _, err := val.ClientCtx.Keyring.NewMnemonic("NewValidator", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
info, _, err := val.GetClientCtx().Keyring.NewMnemonic("NewValidator", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
s.Require().NoError(err)
pk, err := info.GetPubKey()
@ -68,15 +68,15 @@ func (s *E2ETestSuite) SetupSuite() {
account := sdk.AccAddress(pk.Address())
msgSend := &banktypes.MsgSend{
FromAddress: val.Address.String(),
FromAddress: val.GetAddress().String(),
ToAddress: account.String(),
Amount: sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(2000))),
}
_, err = clitestutil.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend,
val.Address,
val.GetAddress(),
clitestutil.TestTxConfig{
GenOnly: true,
},
@ -96,12 +96,12 @@ func (s *E2ETestSuite) SetupSuite() {
"metadata": "%s"
}
]
}`, val.Address.String(), memberWeight, validMetadata)
}`, val.GetAddress().String(), memberWeight, validMetadata)
validMembersFile := testutil.WriteToNewTempFile(s.T(), validMembers)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, client.MsgCreateGroupCmd(),
out, err := clitestutil.ExecTestCLICmd(val.GetClientCtx(), client.MsgCreateGroupCmd(),
append(
[]string{
val.Address.String(),
val.GetAddress().String(),
validMetadata,
validMembersFile.Name(),
},
@ -110,10 +110,10 @@ func (s *E2ETestSuite) SetupSuite() {
)
s.Require().NoError(err, out.String())
txResp := sdk.TxResponse{}
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, txResp.TxHash, 0))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), txResp.TxHash, 0))
s.group = &group.GroupInfo{Id: 1, Admin: val.Address.String(), Metadata: validMetadata, TotalWeight: "3", Version: 1}
s.group = &group.GroupInfo{Id: 1, Admin: val.GetAddress().String(), Metadata: validMetadata, TotalWeight: "3", Version: 1}
// create 5 group policies
for i := 0; i < 5; i++ {
@ -122,20 +122,20 @@ func (s *E2ETestSuite) SetupSuite() {
threshold = 3
}
s.createGroupThresholdPolicyWithBalance(val.Address.String(), "1", threshold, 1000)
s.createGroupThresholdPolicyWithBalance(val.GetAddress().String(), "1", threshold, 1000)
s.Require().NoError(s.network.WaitForNextBlock())
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/group/v1/group_policies_by_group/1", val.APIAddress))
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/group/v1/group_policies_by_group/1", val.GetAPIAddress()))
s.Require().NoError(err)
var groupPoliciesResp group.QueryGroupPoliciesByGroupResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, &groupPoliciesResp))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, &groupPoliciesResp))
s.Require().Len(groupPoliciesResp.GroupPolicies, i+1)
}
// create group policy with percentage decision policy
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, client.MsgCreateGroupPolicyCmd(),
out, err = clitestutil.ExecTestCLICmd(val.GetClientCtx(), client.MsgCreateGroupPolicyCmd(),
append(
[]string{
val.Address.String(),
val.GetAddress().String(),
"1",
validMetadata,
testutil.WriteToNewTempFile(s.T(), fmt.Sprintf(`{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"%f", "windows":{"voting_period":"30000s"}}`, 0.5)).Name(),
@ -144,61 +144,61 @@ func (s *E2ETestSuite) SetupSuite() {
),
)
s.Require().NoError(err, out.String())
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, txResp.TxHash, 0))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), txResp.TxHash, 0))
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/group/v1/group_policies_by_group/1", val.APIAddress))
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/group/v1/group_policies_by_group/1", val.GetAPIAddress()))
s.Require().NoError(err)
var groupPoliciesResp group.QueryGroupPoliciesByGroupResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, &groupPoliciesResp))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, &groupPoliciesResp))
s.Require().Equal(len(groupPoliciesResp.GroupPolicies), 6)
s.groupPolicies = groupPoliciesResp.GroupPolicies
// create a proposal
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, client.MsgSubmitProposalCmd(),
out, err = clitestutil.ExecTestCLICmd(val.GetClientCtx(), client.MsgSubmitProposalCmd(),
append(
[]string{
s.createCLIProposal(
s.groupPolicies[0].Address, val.Address.String(),
s.groupPolicies[0].Address, val.Address.String(),
s.groupPolicies[0].Address, val.GetAddress().String(),
s.groupPolicies[0].Address, val.GetAddress().String(),
"", "title", "summary"),
},
s.commonFlags...,
),
)
s.Require().NoError(err, out.String())
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, txResp.TxHash, 0))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), txResp.TxHash, 0))
msg := &group.MsgVote{
ProposalId: uint64(1),
Voter: val.Address.String(),
Voter: val.GetAddress().String(),
Option: group.VOTE_OPTION_YES,
}
// vote
out, err = clitestutil.SubmitTestTx(val.ClientCtx, msg, val.Address, clitestutil.TestTxConfig{})
out, err = clitestutil.SubmitTestTx(val.GetClientCtx(), msg, val.GetAddress(), clitestutil.TestTxConfig{})
s.Require().NoError(err, out.String())
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, txResp.TxHash, 0))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), txResp.TxHash, 0))
resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/group/v1/proposal/1", val.APIAddress))
resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/group/v1/proposal/1", val.GetAPIAddress()))
s.Require().NoError(err)
var proposalRes group.QueryProposalResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, &proposalRes))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, &proposalRes))
s.proposal = proposalRes.Proposal
resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/group/v1/vote_by_proposal_voter/1/%s", val.APIAddress, val.Address.String()))
resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/group/v1/vote_by_proposal_voter/1/%s", val.GetAPIAddress(), val.GetAddress().String()))
s.Require().NoError(err)
var voteRes group.QueryVoteByProposalVoterResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, &voteRes))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, &voteRes))
s.vote = voteRes.Vote
s.voter = &group.Member{
Address: val.Address.String(),
Address: val.GetAddress().String(),
Weight: memberWeight,
Metadata: validMetadata,
}
@ -241,8 +241,8 @@ func (s *E2ETestSuite) createCLIProposal(groupPolicyAddress, proposer, sendFrom,
func (s *E2ETestSuite) createGroupThresholdPolicyWithBalance(adminAddress, groupID string, threshold int, tokens int64) string {
s.Require().NoError(s.network.WaitForNextBlock())
val := s.network.Validators[0]
clientCtx := val.ClientCtx
val := s.network.GetValidators()[0]
clientCtx := val.GetClientCtx()
out, err := clitestutil.ExecTestCLICmd(clientCtx, client.MsgCreateGroupPolicyCmd(),
append(
@ -257,29 +257,29 @@ func (s *E2ETestSuite) createGroupThresholdPolicyWithBalance(adminAddress, group
)
txResp := sdk.TxResponse{}
s.Require().NoError(err, out.String())
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.ClientCtx, txResp.TxHash, 0))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.Require().NoError(clitestutil.CheckTxCode(s.network, val.GetClientCtx(), txResp.TxHash, 0))
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/group/v1/group_policies_by_group/%s", val.APIAddress, groupID))
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/group/v1/group_policies_by_group/%s", val.GetAPIAddress(), groupID))
s.Require().NoError(err)
var res group.QueryGroupPoliciesByGroupResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, &res))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, &res))
groupPolicyAddress := res.GroupPolicies[0].Address
addr, err := sdk.AccAddressFromBech32(groupPolicyAddress)
s.Require().NoError(err)
msgSend := &banktypes.MsgSend{
FromAddress: val.Address.String(),
FromAddress: val.GetAddress().String(),
ToAddress: addr.String(),
Amount: sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(tokens))),
}
_, err = clitestutil.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend,
val.Address,
val.GetAddress(),
clitestutil.TestTxConfig{
GenOnly: true,
},

View File

@ -13,8 +13,8 @@ import (
)
func (s *E2ETestSuite) TestQueryGRPC() {
val := s.network.Validators[0]
baseURL := val.APIAddress
val := s.network.GetValidators()[0]
baseURL := val.GetAPIAddress()
testCases := []struct {
name string
url string
@ -57,7 +57,7 @@ func (s *E2ETestSuite) TestQueryGRPC() {
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
s.Run(tc.name, func() {
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
})
}

View File

@ -13,7 +13,7 @@ type E2ETestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
}
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {

View File

@ -24,7 +24,7 @@ type E2ETestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
}
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
@ -53,26 +53,26 @@ func (s *E2ETestSuite) TearDownSuite() {
// ref: https://github.com/cosmos/cosmos-sdk/issues/7401.
func (s *E2ETestSuite) TestBlockResults() {
require := s.Require()
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
// Create new account in the keyring.
k, _, err := val.ClientCtx.Keyring.NewMnemonic("NewDelegator", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
k, _, err := val.GetClientCtx().Keyring.NewMnemonic("NewDelegator", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
require.NoError(err)
pub, err := k.GetPubKey()
require.NoError(err)
newAddr := sdk.AccAddress(pub.Address())
msgSend := &banktypes.MsgSend{
FromAddress: val.Address.String(),
FromAddress: val.GetAddress().String(),
ToAddress: newAddr.String(),
Amount: sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(200))),
}
// Send some funds to the new account.
_, err = clitestutil.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend,
val.Address,
val.GetAddress(),
clitestutil.TestTxConfig{},
)
require.NoError(err)
@ -80,13 +80,13 @@ func (s *E2ETestSuite) TestBlockResults() {
msgDel := &stakingtypes.MsgDelegate{
DelegatorAddress: newAddr.String(),
ValidatorAddress: val.ValAddress.String(),
ValidatorAddress: val.GetValAddress().String(),
Amount: sdk.NewCoin(s.cfg.BondDenom, math.NewInt(150)),
}
// create a delegation from the new account to validator `val`.
_, err = clitestutil.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgDel,
newAddr,
clitestutil.TestTxConfig{},
@ -95,7 +95,7 @@ func (s *E2ETestSuite) TestBlockResults() {
require.NoError(s.network.WaitForNextBlock())
// Create a HTTP rpc client.
rpcClient, err := http.New(val.RPCAddress, "/websocket")
rpcClient, err := http.New(val.GetRPCAddress(), "/websocket")
require.NoError(err)
// Loop until we find a block result with the correct validator updates.
@ -115,7 +115,7 @@ func (s *E2ETestSuite) TestBlockResults() {
valUpdate := res.ValidatorUpdates[0]
require.Equal(
valUpdate.GetPubKey().Sum.(*crypto.PublicKey_Ed25519).Ed25519,
val.PubKey.Bytes(),
val.GetPubKey().Bytes(),
)
return nil

View File

@ -23,7 +23,7 @@ import (
type E2EBenchmarkSuite struct {
cfg network.Config
network *network.Network
network network.NetworkI
txHeight int64
queryClient tx.ServiceClient
@ -44,13 +44,13 @@ func BenchmarkTx(b *testing.B) {
s := NewE2EBenchmarkSuite(b)
b.Cleanup(s.Close)
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txBuilder := mkTxBuilder(b, s)
// Convert the txBuilder to a tx.Tx.
protoTx, err := txBuilderToProtoTx(txBuilder)
assert.NilError(b, err)
// Encode the txBuilder to txBytes.
txBytes, err := val.ClientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
txBytes, err := val.GetClientCtx().TxConfig.TxEncoder()(txBuilder.GetTx())
assert.NilError(b, err)
testCases := []struct {
@ -95,22 +95,22 @@ func NewE2EBenchmarkSuite(tb testing.TB) *E2EBenchmarkSuite {
s.network, err = network.New(tb, tb.TempDir(), s.cfg)
assert.NilError(tb, err)
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
assert.NilError(tb, s.network.WaitForNextBlock())
s.queryClient = tx.NewServiceClient(val.ClientCtx)
s.queryClient = tx.NewServiceClient(val.GetClientCtx())
msgSend := &banktypes.MsgSend{
FromAddress: val.Address.String(),
ToAddress: val.Address.String(),
FromAddress: val.GetAddress().String(),
ToAddress: val.GetAddress().String(),
Amount: sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))),
}
// Create a new MsgSend tx from val to itself.
out, err := cli.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend,
val.Address,
val.GetAddress(),
cli.TestTxConfig{
Memo: "foobar",
},
@ -119,19 +119,19 @@ func NewE2EBenchmarkSuite(tb testing.TB) *E2EBenchmarkSuite {
assert.NilError(tb, err)
var txRes sdk.TxResponse
assert.NilError(tb, val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes))
assert.NilError(tb, val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &txRes))
assert.Equal(tb, uint32(0), txRes.Code, txRes)
msgSend1 := &banktypes.MsgSend{
FromAddress: val.Address.String(),
ToAddress: val.Address.String(),
FromAddress: val.GetAddress().String(),
ToAddress: val.GetAddress().String(),
Amount: sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(1))),
}
out, err = cli.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend1,
val.Address,
val.GetAddress(),
cli.TestTxConfig{
Offline: true,
AccNum: 0,
@ -142,10 +142,10 @@ func NewE2EBenchmarkSuite(tb testing.TB) *E2EBenchmarkSuite {
assert.NilError(tb, err)
var tr sdk.TxResponse
assert.NilError(tb, val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &tr))
assert.NilError(tb, val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &tr))
assert.Equal(tb, uint32(0), tr.Code)
resp, err := cli.GetTxResponse(s.network, val.ClientCtx, tr.TxHash)
resp, err := cli.GetTxResponse(s.network, val.GetClientCtx(), tr.TxHash)
assert.NilError(tb, err)
s.txHeight = resp.Height
return s
@ -158,17 +158,17 @@ func (s *E2EBenchmarkSuite) Close() {
func mkTxBuilder(tb testing.TB, s *E2EBenchmarkSuite) client.TxBuilder {
tb.Helper()
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
assert.NilError(tb, s.network.WaitForNextBlock())
// prepare txBuilder with msg
txBuilder := val.ClientCtx.TxConfig.NewTxBuilder()
txBuilder := val.GetClientCtx().TxConfig.NewTxBuilder()
feeAmount := sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)}
gasLimit := testdata.NewTestGasLimit()
assert.NilError(tb,
txBuilder.SetMsgs(&banktypes.MsgSend{
FromAddress: val.Address.String(),
ToAddress: val.Address.String(),
FromAddress: val.GetAddress().String(),
ToAddress: val.GetAddress().String(),
Amount: sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)},
}),
)
@ -178,13 +178,13 @@ func mkTxBuilder(tb testing.TB, s *E2EBenchmarkSuite) client.TxBuilder {
// setup txFactory
txFactory := clienttx.Factory{}.
WithChainID(val.ClientCtx.ChainID).
WithKeybase(val.ClientCtx.Keyring).
WithTxConfig(val.ClientCtx.TxConfig).
WithChainID(val.GetClientCtx().ChainID).
WithKeybase(val.GetClientCtx().Keyring).
WithTxConfig(val.GetClientCtx().TxConfig).
WithSignMode(signing.SignMode_SIGN_MODE_DIRECT)
// Sign Tx.
err := authclient.SignTx(txFactory, val.ClientCtx, val.Moniker, txBuilder, false, true)
err := authclient.SignTx(txFactory, val.GetClientCtx(), val.GetMoniker(), txBuilder, false, true)
assert.NilError(tb, err)
return txBuilder

View File

@ -42,7 +42,7 @@ type E2ETestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
txHeight int64
queryClient tx.ServiceClient
@ -60,22 +60,22 @@ func (s *E2ETestSuite) SetupSuite() {
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
s.Require().NoError(s.network.WaitForNextBlock())
s.queryClient = tx.NewServiceClient(val.ClientCtx)
s.queryClient = tx.NewServiceClient(val.GetClientCtx())
msgSend := &banktypes.MsgSend{
FromAddress: val.Address.String(),
ToAddress: val.Address.String(),
FromAddress: val.GetAddress().String(),
ToAddress: val.GetAddress().String(),
Amount: sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))),
}
// Create a new MsgSend tx from val to itself.
out, err := cli.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend,
val.Address,
val.GetAddress(),
cli.TestTxConfig{
Memo: "foobar",
},
@ -84,20 +84,20 @@ func (s *E2ETestSuite) SetupSuite() {
s.Require().NoError(err)
var txRes sdk.TxResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &txRes))
s.Require().Equal(uint32(0), txRes.Code, txRes)
s.goodTxHash = txRes.TxHash
msgSend1 := &banktypes.MsgSend{
FromAddress: val.Address.String(),
ToAddress: val.Address.String(),
FromAddress: val.GetAddress().String(),
ToAddress: val.GetAddress().String(),
Amount: sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(1))),
}
out1, err := cli.SubmitTestTx(
val.ClientCtx,
val.GetClientCtx(),
msgSend1,
val.Address,
val.GetAddress(),
cli.TestTxConfig{
Offline: true,
AccNum: 0,
@ -108,10 +108,10 @@ func (s *E2ETestSuite) SetupSuite() {
s.Require().NoError(err)
var tr sdk.TxResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out1.Bytes(), &tr))
s.Require().NoError(val.GetClientCtx().Codec.UnmarshalJSON(out1.Bytes(), &tr))
s.Require().Equal(uint32(0), tr.Code)
resp, err := cli.GetTxResponse(s.network, val.ClientCtx, tr.TxHash)
resp, err := cli.GetTxResponse(s.network, val.GetClientCtx(), tr.TxHash)
s.Require().NoError(err)
s.txHeight = resp.Height
}
@ -155,13 +155,13 @@ func (s *E2ETestSuite) TestQueryBySig() {
}
func (s *E2ETestSuite) TestSimulateTx_GRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
// Convert the txBuilder to a tx.Tx.
protoTx, err := txBuilderToProtoTx(txBuilder)
s.Require().NoError(err)
// Encode the txBuilder to txBytes.
txBytes, err := val.ClientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
txBytes, err := val.GetClientCtx().TxConfig.TxEncoder()(txBuilder.GetTx())
s.Require().NoError(err)
testCases := []struct {
@ -202,13 +202,13 @@ func (s *E2ETestSuite) TestSimulateTx_GRPC() {
}
func (s *E2ETestSuite) TestSimulateTx_GRPCGateway() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
// Convert the txBuilder to a tx.Tx.
protoTx, err := txBuilderToProtoTx(txBuilder)
s.Require().NoError(err)
// Encode the txBuilder to txBytes.
txBytes, err := val.ClientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
txBytes, err := val.GetClientCtx().TxConfig.TxEncoder()(txBuilder.GetTx())
s.Require().NoError(err)
testCases := []struct {
@ -224,15 +224,15 @@ func (s *E2ETestSuite) TestSimulateTx_GRPCGateway() {
for _, tc := range testCases {
s.Run(tc.name, func() {
req, err := val.ClientCtx.Codec.MarshalJSON(tc.req)
req, err := val.GetClientCtx().Codec.MarshalJSON(tc.req)
s.Require().NoError(err)
res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/simulate", val.APIAddress), "application/json", req)
res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/simulate", val.GetAPIAddress()), "application/json", req)
s.Require().NoError(err)
if tc.expErr {
s.Require().Contains(string(res), tc.expErrMsg)
} else {
var result tx.SimulateResponse
err = val.ClientCtx.Codec.UnmarshalJSON(res, &result)
err = val.GetClientCtx().Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)
// Check the result and gas used are correct.
s.Require().Len(result.GetResult().MsgResponses, 1)
@ -336,7 +336,7 @@ func (s *E2ETestSuite) TestGetTxEvents_GRPC() {
}
func (s *E2ETestSuite) TestGetTxEvents_GRPCGateway() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
testCases := []struct {
name string
url string
@ -346,49 +346,49 @@ func (s *E2ETestSuite) TestGetTxEvents_GRPCGateway() {
}{
{
"empty params",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs", val.APIAddress),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs", val.GetAPIAddress()),
true,
"query cannot be empty", 0,
},
{
"without pagination",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s", val.APIAddress, bankMsgSendEventAction),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s", val.GetAPIAddress(), bankMsgSendEventAction),
false,
"", 3,
},
{
"with pagination",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s&page=%d&limit=%d", val.APIAddress, bankMsgSendEventAction, 1, 2),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s&page=%d&limit=%d", val.GetAPIAddress(), bankMsgSendEventAction, 1, 2),
false,
"", 2,
},
{
"valid request: order by asc",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s&query=%s&order_by=ORDER_BY_ASC", val.APIAddress, bankMsgSendEventAction, "message.module='bank'"),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s&query=%s&order_by=ORDER_BY_ASC", val.GetAPIAddress(), bankMsgSendEventAction, "message.module='bank'"),
false,
"", 3,
},
{
"valid request: order by desc",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s&query=%s&order_by=ORDER_BY_DESC", val.APIAddress, bankMsgSendEventAction, "message.module='bank'"),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s&query=%s&order_by=ORDER_BY_DESC", val.GetAPIAddress(), bankMsgSendEventAction, "message.module='bank'"),
false,
"", 3,
},
{
"invalid request: invalid order by",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s&query=%s&order_by=invalid_order", val.APIAddress, bankMsgSendEventAction, "message.module='bank'"),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s&query=%s&order_by=invalid_order", val.GetAPIAddress(), bankMsgSendEventAction, "message.module='bank'"),
true,
"is not a valid tx.OrderBy", 0,
},
{
"expect pass with multiple-events",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s&query=%s", val.APIAddress, bankMsgSendEventAction, "message.module='bank'"),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s&query=%s", val.GetAPIAddress(), bankMsgSendEventAction, "message.module='bank'"),
false,
"", 3,
},
{
"expect pass with escape event",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s", val.APIAddress, "message.action%3D'/cosmos.bank.v1beta1.MsgSend'"),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s", val.GetAPIAddress(), "message.action%3D'/cosmos.bank.v1beta1.MsgSend'"),
false,
"", 3,
},
@ -401,7 +401,7 @@ func (s *E2ETestSuite) TestGetTxEvents_GRPCGateway() {
s.Require().Contains(string(res), tc.expErrMsg)
} else {
var result tx.GetTxsEventResponse
err = val.ClientCtx.Codec.UnmarshalJSON(res, &result)
err = val.GetClientCtx().Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err, "failed to unmarshal JSON: %s", res)
s.Require().GreaterOrEqual(len(result.Txs), 1)
s.Require().Equal("foobar", result.Txs[0].Body.Memo)
@ -440,7 +440,7 @@ func (s *E2ETestSuite) TestGetTx_GRPC() {
}
func (s *E2ETestSuite) TestGetTx_GRPCGateway() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
testCases := []struct {
name string
url string
@ -449,17 +449,17 @@ func (s *E2ETestSuite) TestGetTx_GRPCGateway() {
}{
{
"empty params",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/", val.APIAddress),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/", val.GetAPIAddress()),
true, "tx hash cannot be empty",
},
{
"dummy hash",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", val.APIAddress, "deadbeef"),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", val.GetAPIAddress(), "deadbeef"),
true, "code = NotFound desc = tx not found: deadbeef",
},
{
"good hash",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", val.APIAddress, s.goodTxHash),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", val.GetAPIAddress(), s.goodTxHash),
false, "",
},
}
@ -471,7 +471,7 @@ func (s *E2ETestSuite) TestGetTx_GRPCGateway() {
s.Require().Contains(string(res), tc.expErrMsg)
} else {
var result tx.GetTxResponse
err = val.ClientCtx.Codec.UnmarshalJSON(res, &result)
err = val.GetClientCtx().Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)
s.Require().Equal("foobar", result.Tx.Body.Memo)
s.Require().NotZero(result.TxResponse.Height)
@ -487,9 +487,9 @@ func (s *E2ETestSuite) TestGetTx_GRPCGateway() {
}
func (s *E2ETestSuite) TestBroadcastTx_GRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
txBytes, err := val.ClientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
txBytes, err := val.GetClientCtx().TxConfig.TxEncoder()(txBuilder.GetTx())
s.Require().NoError(err)
testCases := []struct {
@ -525,9 +525,9 @@ func (s *E2ETestSuite) TestBroadcastTx_GRPC() {
}
func (s *E2ETestSuite) TestBroadcastTx_GRPCGateway() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
txBytes, err := val.ClientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
txBytes, err := val.GetClientCtx().TxConfig.TxEncoder()(txBuilder.GetTx())
s.Require().NoError(err)
testCases := []struct {
@ -546,15 +546,15 @@ func (s *E2ETestSuite) TestBroadcastTx_GRPCGateway() {
for _, tc := range testCases {
s.Run(tc.name, func() {
req, err := val.ClientCtx.Codec.MarshalJSON(tc.req)
req, err := val.GetClientCtx().Codec.MarshalJSON(tc.req)
s.Require().NoError(err)
res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs", val.APIAddress), "application/json", req)
res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs", val.GetAPIAddress()), "application/json", req)
s.Require().NoError(err)
if tc.expErr {
s.Require().Contains(string(res), tc.expErrMsg)
} else {
var result tx.BroadcastTxResponse
err = val.ClientCtx.Codec.UnmarshalJSON(res, &result)
err = val.GetClientCtx().Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)
s.Require().Equal(uint32(0), result.TxResponse.Code, "rawlog", result.TxResponse.RawLog)
}
@ -563,9 +563,10 @@ func (s *E2ETestSuite) TestBroadcastTx_GRPCGateway() {
}
func (s *E2ETestSuite) TestSimMultiSigTx() {
val1 := *s.network.Validators[0]
val1 := s.network.GetValidators()[0]
clientCtx := val1.GetClientCtx()
kr := val1.ClientCtx.Keyring
kr := clientCtx.Keyring
account1, _, err := kr.NewMnemonic("newAccount1", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
s.Require().NoError(err)
@ -585,7 +586,7 @@ func (s *E2ETestSuite) TestSimMultiSigTx() {
s.Require().NoError(s.network.WaitForNextBlock())
multisigRecord, err := val1.ClientCtx.Keyring.Key("multi")
multisigRecord, err := clientCtx.Keyring.Key("multi")
s.Require().NoError(err)
height, err := s.network.LatestHeight()
@ -599,15 +600,15 @@ func (s *E2ETestSuite) TestSimMultiSigTx() {
// Send coins from validator to multisig.
coin := sdk.NewInt64Coin(s.cfg.BondDenom, 15)
msgSend := &banktypes.MsgSend{
FromAddress: val1.Address.String(),
FromAddress: val1.GetAddress().String(),
ToAddress: addr.String(),
Amount: sdk.NewCoins(coin),
}
_, err = cli.SubmitTestTx(
val1.ClientCtx,
clientCtx,
msgSend,
val1.Address,
val1.GetAddress(),
cli.TestTxConfig{},
)
@ -620,16 +621,16 @@ func (s *E2ETestSuite) TestSimMultiSigTx() {
msgSend1 := &banktypes.MsgSend{
FromAddress: addr.String(),
ToAddress: val1.Address.String(),
ToAddress: val1.GetAddress().String(),
Amount: sdk.NewCoins(
sdk.NewInt64Coin(s.cfg.BondDenom, 5),
),
}
// Generate multisig transaction.
multiGeneratedTx, err := cli.SubmitTestTx(
val1.ClientCtx,
clientCtx,
msgSend1,
val1.Address,
val1.GetAddress(),
cli.TestTxConfig{
GenOnly: true,
Memo: "foobar",
@ -644,27 +645,27 @@ func (s *E2ETestSuite) TestSimMultiSigTx() {
// Sign with account1
addr1, err := account1.GetAddress()
s.Require().NoError(err)
val1.ClientCtx.HomeDir = strings.Replace(val1.ClientCtx.HomeDir, "simd", "simcli", 1)
account1Signature, err := authtest.TxSignExec(val1.ClientCtx, addr1, multiGeneratedTxFile.Name(), "--multisig", addr.String())
clientCtx.HomeDir = strings.Replace(clientCtx.HomeDir, "simd", "simcli", 1)
account1Signature, err := authtest.TxSignExec(clientCtx, addr1, multiGeneratedTxFile.Name(), "--multisig", addr.String())
s.Require().NoError(err)
sign1File := testutil.WriteToNewTempFile(s.T(), account1Signature.String())
// Sign with account2
addr2, err := account2.GetAddress()
s.Require().NoError(err)
account2Signature, err := authtest.TxSignExec(val1.ClientCtx, addr2, multiGeneratedTxFile.Name(), "--multisig", addr.String())
account2Signature, err := authtest.TxSignExec(clientCtx, addr2, multiGeneratedTxFile.Name(), "--multisig", addr.String())
s.Require().NoError(err)
sign2File := testutil.WriteToNewTempFile(s.T(), account2Signature.String())
// multisign tx
val1.ClientCtx.Offline = false
multiSigWith2Signatures, err := authtest.TxMultiSignExec(val1.ClientCtx, multisigRecord.Name, multiGeneratedTxFile.Name(), sign1File.Name(), sign2File.Name())
clientCtx.Offline = false
multiSigWith2Signatures, err := authtest.TxMultiSignExec(clientCtx, multisigRecord.Name, multiGeneratedTxFile.Name(), sign1File.Name(), sign2File.Name())
s.Require().NoError(err)
// convert from protoJSON to protoBinary for sim
sdkTx, err := val1.ClientCtx.TxConfig.TxJSONDecoder()(multiSigWith2Signatures.Bytes())
sdkTx, err := clientCtx.TxConfig.TxJSONDecoder()(multiSigWith2Signatures.Bytes())
s.Require().NoError(err)
txBytes, err := val1.ClientCtx.TxConfig.TxEncoder()(sdkTx)
txBytes, err := clientCtx.TxConfig.TxEncoder()(sdkTx)
s.Require().NoError(err)
// simulate tx
@ -715,7 +716,7 @@ func (s *E2ETestSuite) TestGetBlockWithTxs_GRPC() {
}
func (s *E2ETestSuite) TestGetBlockWithTxs_GRPCGateway() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
testCases := []struct {
name string
url string
@ -724,17 +725,17 @@ func (s *E2ETestSuite) TestGetBlockWithTxs_GRPCGateway() {
}{
{
"empty params",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/block/0", val.APIAddress),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/block/0", val.GetAPIAddress()),
true, "height must not be less than 1 or greater than the current height",
},
{
"bad height",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/block/%d", val.APIAddress, 9999999),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/block/%d", val.GetAPIAddress(), 9999999),
true, "height must not be less than 1 or greater than the current height",
},
{
"good request",
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/block/%d", val.APIAddress, s.txHeight),
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/block/%d", val.GetAPIAddress(), s.txHeight),
false, "",
},
}
@ -746,7 +747,7 @@ func (s *E2ETestSuite) TestGetBlockWithTxs_GRPCGateway() {
s.Require().Contains(string(res), tc.expErrMsg)
} else {
var result tx.GetBlockWithTxsResponse
err = val.ClientCtx.Codec.UnmarshalJSON(res, &result)
err = val.GetClientCtx().Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)
s.Require().Equal("foobar", result.Txs[0].Body.Memo)
s.Require().Equal(result.Block.Header.Height, s.txHeight)
@ -756,7 +757,7 @@ func (s *E2ETestSuite) TestGetBlockWithTxs_GRPCGateway() {
}
func (s *E2ETestSuite) TestTxEncode_GRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
protoTx, err := txBuilderToProtoTx(txBuilder)
s.Require().NoError(err)
@ -784,7 +785,7 @@ func (s *E2ETestSuite) TestTxEncode_GRPC() {
s.Require().NoError(err)
s.Require().NotEmpty(res.GetTxBytes())
tx, err := val.ClientCtx.TxConfig.TxDecoder()(res.TxBytes)
tx, err := val.GetClientCtx().TxConfig.TxDecoder()(res.TxBytes)
s.Require().NoError(err)
s.Require().Equal(protoTx.GetMsgs(), tx.GetMsgs())
}
@ -793,7 +794,7 @@ func (s *E2ETestSuite) TestTxEncode_GRPC() {
}
func (s *E2ETestSuite) TestTxEncode_GRPCGateway() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
protoTx, err := txBuilderToProtoTx(txBuilder)
s.Require().NoError(err)
@ -810,19 +811,19 @@ func (s *E2ETestSuite) TestTxEncode_GRPCGateway() {
for _, tc := range testCases {
s.Run(tc.name, func() {
req, err := val.ClientCtx.Codec.MarshalJSON(tc.req)
req, err := val.GetClientCtx().Codec.MarshalJSON(tc.req)
s.Require().NoError(err)
res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/encode", val.APIAddress), "application/json", req)
res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/encode", val.GetAPIAddress()), "application/json", req)
s.Require().NoError(err)
if tc.expErr {
s.Require().Contains(string(res), tc.expErrMsg)
} else {
var result tx.TxEncodeResponse
err := val.ClientCtx.Codec.UnmarshalJSON(res, &result)
err := val.GetClientCtx().Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)
tx, err := val.ClientCtx.TxConfig.TxDecoder()(result.TxBytes)
tx, err := val.GetClientCtx().TxConfig.TxDecoder()(result.TxBytes)
s.Require().NoError(err)
s.Require().Equal(protoTx.GetMsgs(), tx.GetMsgs())
}
@ -831,10 +832,10 @@ func (s *E2ETestSuite) TestTxEncode_GRPCGateway() {
}
func (s *E2ETestSuite) TestTxDecode_GRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
encodedTx, err := val.ClientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
encodedTx, err := val.GetClientCtx().TxConfig.TxEncoder()(txBuilder.GetTx())
s.Require().NoError(err)
invalidTxBytes := append(encodedTx, byte(0o00))
@ -864,7 +865,7 @@ func (s *E2ETestSuite) TestTxDecode_GRPC() {
s.Require().NotEmpty(res.GetTx())
txb := authtx.WrapTx(res.Tx)
tx, err := val.ClientCtx.TxConfig.TxEncoder()(txb.GetTx())
tx, err := val.GetClientCtx().TxConfig.TxEncoder()(txb.GetTx())
s.Require().NoError(err)
s.Require().Equal(encodedTx, tx)
}
@ -873,10 +874,10 @@ func (s *E2ETestSuite) TestTxDecode_GRPC() {
}
func (s *E2ETestSuite) TestTxDecode_GRPCGateway() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
encodedTxBytes, err := val.ClientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
encodedTxBytes, err := val.GetClientCtx().TxConfig.TxEncoder()(txBuilder.GetTx())
s.Require().NoError(err)
invalidTxBytes := append(encodedTxBytes, byte(0o00))
@ -894,20 +895,20 @@ func (s *E2ETestSuite) TestTxDecode_GRPCGateway() {
for _, tc := range testCases {
s.Run(tc.name, func() {
req, err := val.ClientCtx.Codec.MarshalJSON(tc.req)
req, err := val.GetClientCtx().Codec.MarshalJSON(tc.req)
s.Require().NoError(err)
res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/decode", val.APIAddress), "application/json", req)
res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/decode", val.GetAPIAddress()), "application/json", req)
s.Require().NoError(err)
if tc.expErr {
s.Require().Contains(string(res), tc.expErrMsg)
} else {
var result tx.TxDecodeResponse
err := val.ClientCtx.Codec.UnmarshalJSON(res, &result)
err := val.GetClientCtx().Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)
txb := authtx.WrapTx(result.Tx)
tx, err := val.ClientCtx.TxConfig.TxEncoder()(txb.GetTx())
tx, err := val.GetClientCtx().TxConfig.TxEncoder()(txb.GetTx())
s.Require().NoError(err)
s.Require().Equal(encodedTxBytes, tx)
}
@ -916,17 +917,17 @@ func (s *E2ETestSuite) TestTxDecode_GRPCGateway() {
}
func (s *E2ETestSuite) readTestAminoTxJSON() ([]byte, *legacytx.StdTx) {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txJSONBytes, err := os.ReadFile("testdata/tx_amino1.json")
s.Require().NoError(err)
var stdTx legacytx.StdTx
err = val.ClientCtx.LegacyAmino.UnmarshalJSON(txJSONBytes, &stdTx)
err = val.GetClientCtx().LegacyAmino.UnmarshalJSON(txJSONBytes, &stdTx)
s.Require().NoError(err)
return txJSONBytes, &stdTx
}
func (s *E2ETestSuite) TestTxEncodeAmino_GRPC() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txJSONBytes, stdTx := s.readTestAminoTxJSON()
testCases := []struct {
@ -954,7 +955,7 @@ func (s *E2ETestSuite) TestTxEncodeAmino_GRPC() {
s.Require().NotEmpty(res.GetAminoBinary())
var decodedTx legacytx.StdTx
err = val.ClientCtx.LegacyAmino.Unmarshal(res.AminoBinary, &decodedTx)
err = val.GetClientCtx().LegacyAmino.Unmarshal(res.AminoBinary, &decodedTx)
s.Require().NoError(err)
s.Require().Equal(decodedTx.GetMsgs(), stdTx.GetMsgs())
}
@ -963,7 +964,7 @@ func (s *E2ETestSuite) TestTxEncodeAmino_GRPC() {
}
func (s *E2ETestSuite) TestTxEncodeAmino_GRPCGateway() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txJSONBytes, stdTx := s.readTestAminoTxJSON()
testCases := []struct {
@ -979,20 +980,20 @@ func (s *E2ETestSuite) TestTxEncodeAmino_GRPCGateway() {
for _, tc := range testCases {
s.Run(tc.name, func() {
req, err := val.ClientCtx.Codec.MarshalJSON(tc.req)
req, err := val.GetClientCtx().Codec.MarshalJSON(tc.req)
s.Require().NoError(err)
res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/encode/amino", val.APIAddress), "application/json", req)
res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/encode/amino", val.GetAPIAddress()), "application/json", req)
s.Require().NoError(err)
if tc.expErr {
s.Require().Contains(string(res), tc.expErrMsg)
} else {
var result tx.TxEncodeAminoResponse
err := val.ClientCtx.Codec.UnmarshalJSON(res, &result)
err := val.GetClientCtx().Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)
var decodedTx legacytx.StdTx
err = val.ClientCtx.LegacyAmino.Unmarshal(result.AminoBinary, &decodedTx)
err = val.GetClientCtx().LegacyAmino.Unmarshal(result.AminoBinary, &decodedTx)
s.Require().NoError(err)
s.Require().Equal(decodedTx.GetMsgs(), stdTx.GetMsgs())
}
@ -1001,11 +1002,11 @@ func (s *E2ETestSuite) TestTxEncodeAmino_GRPCGateway() {
}
func (s *E2ETestSuite) readTestAminoTxBinary() ([]byte, *legacytx.StdTx) {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
txJSONBytes, err := os.ReadFile("testdata/tx_amino1.bin")
s.Require().NoError(err)
var stdTx legacytx.StdTx
err = val.ClientCtx.LegacyAmino.Unmarshal(txJSONBytes, &stdTx)
err = val.GetClientCtx().LegacyAmino.Unmarshal(txJSONBytes, &stdTx)
s.Require().NoError(err)
return txJSONBytes, &stdTx
}
@ -1040,7 +1041,7 @@ func (s *E2ETestSuite) TestTxDecodeAmino_GRPC() {
s.Require().NotEmpty(res.GetAminoJson())
var decodedTx legacytx.StdTx
err = s.network.Validators[0].ClientCtx.LegacyAmino.UnmarshalJSON([]byte(res.GetAminoJson()), &decodedTx)
err = s.network.GetValidators()[0].GetClientCtx().LegacyAmino.UnmarshalJSON([]byte(res.GetAminoJson()), &decodedTx)
s.Require().NoError(err)
s.Require().Equal(stdTx.GetMsgs(), decodedTx.GetMsgs())
}
@ -1049,7 +1050,7 @@ func (s *E2ETestSuite) TestTxDecodeAmino_GRPC() {
}
func (s *E2ETestSuite) TestTxDecodeAmino_GRPCGateway() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
encodedTx, stdTx := s.readTestAminoTxBinary()
invalidTxBytes := append(encodedTx, byte(0o00))
@ -1067,20 +1068,20 @@ func (s *E2ETestSuite) TestTxDecodeAmino_GRPCGateway() {
for _, tc := range testCases {
s.Run(tc.name, func() {
req, err := val.ClientCtx.Codec.MarshalJSON(tc.req)
req, err := val.GetClientCtx().Codec.MarshalJSON(tc.req)
s.Require().NoError(err)
res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/decode/amino", val.APIAddress), "application/json", req)
res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/decode/amino", val.GetAPIAddress()), "application/json", req)
s.Require().NoError(err)
if tc.expErr {
s.Require().Contains(string(res), tc.expErrMsg)
} else {
var result tx.TxDecodeAminoResponse
err := val.ClientCtx.Codec.UnmarshalJSON(res, &result)
err := val.GetClientCtx().Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)
var decodedTx legacytx.StdTx
err = val.ClientCtx.LegacyAmino.UnmarshalJSON([]byte(result.AminoJson), &decodedTx)
err = val.GetClientCtx().LegacyAmino.UnmarshalJSON([]byte(result.AminoJson), &decodedTx)
s.Require().NoError(err)
s.Require().Equal(stdTx.GetMsgs(), decodedTx.GetMsgs())
}
@ -1093,17 +1094,17 @@ func TestE2ETestSuite(t *testing.T) {
}
func (s *E2ETestSuite) mkTxBuilder() client.TxBuilder {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
s.Require().NoError(s.network.WaitForNextBlock())
// prepare txBuilder with msg
txBuilder := val.ClientCtx.TxConfig.NewTxBuilder()
txBuilder := val.GetClientCtx().TxConfig.NewTxBuilder()
feeAmount := sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)}
gasLimit := testdata.NewTestGasLimit()
s.Require().NoError(
txBuilder.SetMsgs(&banktypes.MsgSend{
FromAddress: val.Address.String(),
ToAddress: val.Address.String(),
FromAddress: val.GetAddress().String(),
ToAddress: val.GetAddress().String(),
Amount: sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)},
}),
)
@ -1112,17 +1113,17 @@ func (s *E2ETestSuite) mkTxBuilder() client.TxBuilder {
txBuilder.SetMemo("foobar")
signers, err := txBuilder.GetTx().GetSigners()
s.Require().NoError(err)
s.Require().Equal([][]byte{val.Address}, signers)
s.Require().Equal([][]byte{val.GetAddress()}, signers)
// setup txFactory
txFactory := clienttx.Factory{}.
WithChainID(val.ClientCtx.ChainID).
WithKeybase(val.ClientCtx.Keyring).
WithTxConfig(val.ClientCtx.TxConfig).
WithChainID(val.GetClientCtx().ChainID).
WithKeybase(val.GetClientCtx().Keyring).
WithTxConfig(val.GetClientCtx().TxConfig).
WithSignMode(signing.SignMode_SIGN_MODE_DIRECT)
// Sign Tx.
err = authclient.SignTx(txFactory, val.ClientCtx, val.Moniker, txBuilder, false, true)
err = authclient.SignTx(txFactory, val.GetClientCtx(), val.GetMoniker(), txBuilder, false, true)
s.Require().NoError(err)
return txBuilder

View File

@ -33,7 +33,7 @@ type IntegrationTestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
network network.NetworkI
conn *grpc.ClientConn
}
@ -51,9 +51,9 @@ func (s *IntegrationTestSuite) SetupSuite() {
_, err = s.network.WaitForHeight(2)
s.Require().NoError(err)
val0 := s.network.Validators[0]
val0 := s.network.GetValidators()[0]
s.conn, err = grpc.Dial(
val0.AppConfig.GRPC.Address,
val0.GetAppConfig().GRPC.Address,
grpc.WithInsecure(), //nolint:staticcheck // ignore SA1019, we don't need to use a secure connection for tests
grpc.WithDefaultCallOptions(grpc.ForceCodec(codec.NewProtoCodec(s.cfg.InterfaceRegistry).GRPCCodec())),
)
@ -75,20 +75,20 @@ func (s *IntegrationTestSuite) TestGRPCServer_TestService() {
}
func (s *IntegrationTestSuite) TestGRPCServer_BankBalance() {
val0 := s.network.Validators[0]
val0 := s.network.GetValidators()[0]
// gRPC query to bank service should work
denom := fmt.Sprintf("%stoken", val0.Moniker)
denom := fmt.Sprintf("%stoken", val0.GetMoniker())
bankClient := banktypes.NewQueryClient(s.conn)
var header metadata.MD
bankRes, err := bankClient.Balance(
context.Background(),
&banktypes.QueryBalanceRequest{Address: val0.Address.String(), Denom: denom},
&banktypes.QueryBalanceRequest{Address: val0.GetAddress().String(), Denom: denom},
grpc.Header(&header), // Also fetch grpc header
)
s.Require().NoError(err)
s.Require().Equal(
sdk.NewCoin(denom, s.network.Config.AccountTokens),
sdk.NewCoin(denom, s.cfg.AccountTokens),
*bankRes.GetBalance(),
)
blockHeight := header.Get(grpctypes.GRPCBlockHeightHeader)
@ -97,7 +97,7 @@ func (s *IntegrationTestSuite) TestGRPCServer_BankBalance() {
// Request metadata should work
_, err = bankClient.Balance(
metadata.AppendToOutgoingContext(context.Background(), grpctypes.GRPCBlockHeightHeader, "1"), // Add metadata to request
&banktypes.QueryBalanceRequest{Address: val0.Address.String(), Denom: denom},
&banktypes.QueryBalanceRequest{Address: val0.GetAddress().String(), Denom: denom},
grpc.Header(&header),
)
s.Require().NoError(err)
@ -164,11 +164,11 @@ func (s *IntegrationTestSuite) TestGRPCServer_GetTxsEvent() {
}
func (s *IntegrationTestSuite) TestGRPCServer_BroadcastTx() {
val0 := s.network.Validators[0]
val0 := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
txBytes, err := val0.ClientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
txBytes, err := val0.GetClientCtx().TxConfig.TxEncoder()(txBuilder.GetTx())
s.Require().NoError(err)
// Broadcast the tx via gRPC.
@ -220,7 +220,7 @@ func (s *IntegrationTestSuite) TestGRPCUnpacker() {
ir := s.cfg.InterfaceRegistry
queryClient := stakingtypes.NewQueryClient(s.conn)
validator, err := queryClient.Validator(context.Background(),
&stakingtypes.QueryValidatorRequest{ValidatorAddr: s.network.Validators[0].ValAddress.String()})
&stakingtypes.QueryValidatorRequest{ValidatorAddr: s.network.GetValidators()[0].GetValAddress().String()})
require.NoError(s.T(), err)
// no unpacked interfaces yet, so ConsAddr will be nil
@ -238,17 +238,17 @@ func (s *IntegrationTestSuite) TestGRPCUnpacker() {
// mkTxBuilder creates a TxBuilder containing a signed tx from validator 0.
func (s *IntegrationTestSuite) mkTxBuilder() client.TxBuilder {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
s.Require().NoError(s.network.WaitForNextBlock())
// prepare txBuilder with msg
txBuilder := val.ClientCtx.TxConfig.NewTxBuilder()
txBuilder := val.GetClientCtx().TxConfig.NewTxBuilder()
feeAmount := sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)}
gasLimit := testdata.NewTestGasLimit()
s.Require().NoError(
txBuilder.SetMsgs(&banktypes.MsgSend{
FromAddress: val.Address.String(),
ToAddress: val.Address.String(),
FromAddress: val.GetAddress().String(),
ToAddress: val.GetAddress().String(),
Amount: sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)},
}),
)
@ -258,13 +258,13 @@ func (s *IntegrationTestSuite) mkTxBuilder() client.TxBuilder {
// setup txFactory
txFactory := clienttx.Factory{}.
WithChainID(val.ClientCtx.ChainID).
WithKeybase(val.ClientCtx.Keyring).
WithTxConfig(val.ClientCtx.TxConfig).
WithChainID(val.GetClientCtx().ChainID).
WithKeybase(val.GetClientCtx().Keyring).
WithTxConfig(val.GetClientCtx().TxConfig).
WithSignMode(signing.SignMode_SIGN_MODE_DIRECT)
// Sign Tx.
err := authclient.SignTx(txFactory, val.ClientCtx, val.Moniker, txBuilder, false, true)
err := authclient.SignTx(txFactory, val.GetClientCtx(), val.GetMoniker(), txBuilder, false, true)
s.Require().NoError(err)
return txBuilder

View File

@ -13,7 +13,7 @@ import (
// CheckTxCode verifies that the transaction result returns a specific code
// Takes a network, wait for two blocks and fetch the transaction from its hash
func CheckTxCode(network *network.Network, clientCtx client.Context, txHash string, expectedCode uint32) error {
func CheckTxCode(network network.NetworkI, clientCtx client.Context, txHash string, expectedCode uint32) error {
// wait for 2 blocks
for i := 0; i < 2; i++ {
if err := network.WaitForNextBlock(); err != nil {
@ -41,7 +41,7 @@ func CheckTxCode(network *network.Network, clientCtx client.Context, txHash stri
// GetTxResponse returns queries the transaction response of a transaction from its hash
// Takes a network, wait for two blocks and fetch the transaction from its hash
func GetTxResponse(network *network.Network, clientCtx client.Context, txHash string) (sdk.TxResponse, error) {
func GetTxResponse(network network.NetworkI, clientCtx client.Context, txHash string) (sdk.TxResponse, error) {
// wait for 2 blocks
for i := 0; i < 2; i++ {
if err := network.WaitForNextBlock(); err != nil {

View File

@ -0,0 +1,44 @@
package network
import (
"time"
"github.com/cosmos/cosmos-sdk/client"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/server"
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// NetworkI is an interface for a network of validators.
// It is used to abstract over the different network types (in-process, docker, etc.).
// if used there is a requirement to expose query and tx client for the nodes
type NetworkI interface {
// GetValidators returns the validators in the network
GetValidators() []ValidatorI
// WaitForNextBlock waits for the network to reach the next block
WaitForNextBlock() error
// WaitForHeight waits for the network to reach the given height
WaitForHeight(height int64) (int64, error)
// WaitForHeightWithTimeout waits for the network to reach the given height or times out
WaitForHeightWithTimeout(int64, time.Duration) (int64, error)
// RetryForBlocks retries the given function until it returns no error or the given number of blocks has passed
RetryForBlocks(retryFunc func() error, blocks int) error
// LatestHeight returns the latest height of the network
LatestHeight() (int64, error)
Cleanup()
}
// ValidatorI expose a validator's context and configuration
type ValidatorI interface {
GetCtx() *server.Context
GetAppConfig() *srvconfig.Config
GetAddress() sdk.AccAddress
GetValAddress() sdk.ValAddress
GetClientCtx() client.Context
GetAPIAddress() string
GetRPCAddress() string
GetPubKey() cryptotypes.PubKey
GetMoniker() string
}

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"os"
"os/signal"
@ -17,12 +16,8 @@ import (
"testing"
"time"
"github.com/cometbft/cometbft/node"
cmtclient "github.com/cometbft/cometbft/rpc/client"
dbm "github.com/cosmos/cosmos-db"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"cosmossdk.io/core/address"
"cosmossdk.io/depinject"
@ -51,7 +46,6 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/api"
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/testutil"
@ -274,39 +268,6 @@ type (
Config Config
}
// Validator defines an in-process CometBFT validator node. Through this object,
// a client can make RPC and API calls and interact with any client command
// or handler.
Validator struct {
AppConfig *srvconfig.Config
ClientCtx client.Context
Ctx *server.Context
Dir string
NodeID string
PubKey cryptotypes.PubKey
Moniker string
APIAddress string
RPCAddress string
P2PAddress string
Address sdk.AccAddress
ValAddress sdk.ValAddress
RPCClient cmtclient.Client
app servertypes.Application
tmNode *node.Node
api *api.Server
grpc *grpc.Server
grpcWeb *http.Server
errGroup *errgroup.Group
cancelFn context.CancelFunc
}
// ValidatorI expose a validator's context and configuration
ValidatorI interface {
GetCtx() *server.Context
GetAppConfig() *srvconfig.Config
}
// Logger is a network logger interface that exposes testnet-level Log() methods for an in-process testing network
// This is not to be confused with logging that may happen at an individual node or validator level
Logger interface {
@ -316,19 +277,10 @@ type (
)
var (
_ Logger = (*testing.T)(nil)
_ Logger = (*CLILogger)(nil)
_ ValidatorI = Validator{}
_ Logger = (*testing.T)(nil)
_ Logger = (*CLILogger)(nil)
)
func (v Validator) GetCtx() *server.Context {
return v.Ctx
}
func (v Validator) GetAppConfig() *srvconfig.Config {
return v.AppConfig
}
// CLILogger wraps a cobra.Command and provides command logging methods.
type CLILogger struct {
cmd *cobra.Command
@ -350,7 +302,7 @@ func NewCLILogger(cmd *cobra.Command) CLILogger {
}
// New creates a new Network for integration tests or in-process testnets run via the CLI
func New(l Logger, baseDir string, cfg Config) (*Network, error) {
func New(l Logger, baseDir string, cfg Config) (NetworkI, error) {
// only one caller/test can create and use a network at a time
l.Log("acquiring test network lock")
lock.Lock()
@ -612,17 +564,17 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
network.Validators[i] = &Validator{
AppConfig: appCfg,
ClientCtx: clientCtx,
Ctx: ctx,
Dir: filepath.Join(network.BaseDir, nodeDirName),
NodeID: nodeID,
PubKey: pubKey,
Moniker: nodeDirName,
RPCAddress: cmtCfg.RPC.ListenAddress,
P2PAddress: cmtCfg.P2P.ListenAddress,
APIAddress: apiAddr,
Address: addr,
ValAddress: sdk.ValAddress(addr),
clientCtx: clientCtx,
ctx: ctx,
dir: filepath.Join(network.BaseDir, nodeDirName),
nodeID: nodeID,
pubKey: pubKey,
moniker: nodeDirName,
rPCAddress: cmtCfg.RPC.ListenAddress,
p2PAddress: cmtCfg.P2P.ListenAddress,
aPIAddress: apiAddr,
address: addr,
valAddress: sdk.ValAddress(addr),
}
}
@ -696,7 +648,7 @@ func (n *Network) LatestHeight() (int64, error) {
var latestHeight int64
val := n.Validators[0]
queryClient := cmtservice.NewServiceClient(val.ClientCtx)
queryClient := cmtservice.NewServiceClient(val.clientCtx)
for {
select {
@ -730,6 +682,14 @@ func (n *Network) WaitForHeight(h int64) (int64, error) {
return n.WaitForHeightWithTimeout(h, 10*time.Second)
}
func (n *Network) GetValidators() []ValidatorI {
var vals []ValidatorI
for _, val := range n.Validators {
vals = append(vals, val)
}
return vals
}
// WaitForHeightWithTimeout is the same as WaitForHeight except the caller can
// provide a custom timeout.
func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, error) {
@ -745,7 +705,7 @@ func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, err
var latestHeight int64
val := n.Validators[0]
queryClient := cmtservice.NewServiceClient(val.ClientCtx)
queryClient := cmtservice.NewServiceClient(val.clientCtx)
for {
select {

View File

@ -31,8 +31,8 @@ import (
)
func startInProcess(cfg Config, val *Validator) error {
logger := val.Ctx.Logger
cmtCfg := val.Ctx.Config
logger := val.ctx.Logger
cmtCfg := val.ctx.Config
cmtCfg.Instrumentation.Prometheus = false
if err := val.AppConfig.ValidateBasic(); err != nil {
@ -44,7 +44,7 @@ func startInProcess(cfg Config, val *Validator) error {
return err
}
app := cfg.AppConstructor(*val)
app := cfg.AppConstructor(val)
val.app = app
appGenesisProvider := func() (*cmttypes.GenesisDoc, error) {
@ -65,7 +65,7 @@ func startInProcess(cfg Config, val *Validator) error {
appGenesisProvider,
cmtcfg.DefaultDBProvider,
node.DefaultMetricsProvider(cmtCfg.Instrumentation),
servercmtlog.CometLoggerWrapper{Logger: logger.With("module", val.Moniker)},
servercmtlog.CometLoggerWrapper{Logger: logger.With("module", val.moniker)},
)
if err != nil {
return err
@ -76,18 +76,18 @@ func startInProcess(cfg Config, val *Validator) error {
}
val.tmNode = tmNode
if val.RPCAddress != "" {
val.RPCClient = local.New(tmNode)
if val.rPCAddress != "" {
val.rPCClient = local.New(tmNode)
}
// We'll need a RPC client if the validator exposes a gRPC or REST endpoint.
if val.APIAddress != "" || val.AppConfig.GRPC.Enable {
val.ClientCtx = val.ClientCtx.
WithClient(val.RPCClient)
if val.aPIAddress != "" || val.AppConfig.GRPC.Enable {
val.clientCtx = val.clientCtx.
WithClient(val.rPCClient)
app.RegisterTxService(val.ClientCtx)
app.RegisterTendermintService(val.ClientCtx)
app.RegisterNodeService(val.ClientCtx, *val.AppConfig)
app.RegisterTxService(val.clientCtx)
app.RegisterTendermintService(val.clientCtx)
app.RegisterNodeService(val.clientCtx, *val.AppConfig)
}
ctx := context.Background()
@ -97,7 +97,7 @@ func startInProcess(cfg Config, val *Validator) error {
grpcCfg := val.AppConfig.GRPC
if grpcCfg.Enable {
grpcSrv, err := servergrpc.NewGRPCServer(val.ClientCtx, app, grpcCfg)
grpcSrv, err := servergrpc.NewGRPCServer(val.clientCtx, app, grpcCfg)
if err != nil {
return err
}
@ -111,8 +111,8 @@ func startInProcess(cfg Config, val *Validator) error {
val.grpc = grpcSrv
}
if val.APIAddress != "" {
apiSrv := api.New(val.ClientCtx, logger.With(log.ModuleKey, "api-server"), val.grpc)
if val.aPIAddress != "" {
apiSrv := api.New(val.clientCtx, logger.With(log.ModuleKey, "api-server"), val.grpc)
app.RegisterAPIRoutes(apiSrv, val.AppConfig.API)
val.errGroup.Go(func() error {
@ -132,15 +132,15 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error {
}
for i := 0; i < cfg.NumValidators; i++ {
cmtCfg := vals[i].Ctx.Config
cmtCfg := vals[i].ctx.Config
nodeDir := filepath.Join(outputDir, vals[i].Moniker, "simd")
nodeDir := filepath.Join(outputDir, vals[i].moniker, "simd")
gentxsDir := filepath.Join(outputDir, "gentxs")
cmtCfg.Moniker = vals[i].Moniker
cmtCfg.Moniker = vals[i].moniker
cmtCfg.SetRoot(nodeDir)
initCfg := genutiltypes.NewInitConfig(cfg.ChainID, gentxsDir, vals[i].NodeID, vals[i].PubKey)
initCfg := genutiltypes.NewInitConfig(cfg.ChainID, gentxsDir, vals[i].nodeID, vals[i].pubKey)
genFile := cmtCfg.GenesisFile()
appGenesis, err := genutiltypes.AppGenesisFromFile(genFile)

View File

@ -0,0 +1,84 @@
package network
import (
"context"
"net/http"
"github.com/cometbft/cometbft/node"
cmtclient "github.com/cometbft/cometbft/rpc/client"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"github.com/cosmos/cosmos-sdk/client"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/api"
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Validator defines an in-process CometBFT validator node. Through this object,
// a client can make RPC and API calls and interact with any client command
// or handler.
type Validator struct {
AppConfig *srvconfig.Config
clientCtx client.Context
ctx *server.Context
dir string
nodeID string
pubKey cryptotypes.PubKey
moniker string
aPIAddress string
rPCAddress string
p2PAddress string
address sdk.AccAddress
valAddress sdk.ValAddress
rPCClient cmtclient.Client
app servertypes.Application
tmNode *node.Node
api *api.Server
grpc *grpc.Server
grpcWeb *http.Server
errGroup *errgroup.Group
cancelFn context.CancelFunc
}
var _ ValidatorI = &Validator{}
func (v *Validator) GetCtx() *server.Context {
return v.ctx
}
func (v *Validator) GetClientCtx() client.Context {
return v.clientCtx
}
func (v *Validator) GetAppConfig() *srvconfig.Config {
return v.AppConfig
}
func (v *Validator) GetAddress() sdk.AccAddress {
return v.address
}
func (v *Validator) GetValAddress() sdk.ValAddress {
return v.valAddress
}
func (v *Validator) GetAPIAddress() string {
return v.aPIAddress
}
func (v *Validator) GetRPCAddress() string {
return v.rPCAddress
}
func (v *Validator) GetPubKey() cryptotypes.PubKey {
return v.pubKey
}
func (v *Validator) GetMoniker() string {
return v.moniker
}

View File

@ -23,24 +23,24 @@ func TestAccountRetriever(t *testing.T) {
_, err = network.WaitForHeight(3)
require.NoError(t, err)
val := network.Validators[0]
clientCtx := val.ClientCtx
val := network.GetValidators()[0]
clientCtx := val.GetClientCtx()
ar := types.AccountRetriever{}
clientCtx = clientCtx.WithHeight(2)
acc, err := ar.GetAccount(clientCtx, val.Address)
acc, err := ar.GetAccount(clientCtx, val.GetAddress())
require.NoError(t, err)
require.NotNil(t, acc)
acc, height, err := ar.GetAccountWithHeight(clientCtx, val.Address)
acc, height, err := ar.GetAccountWithHeight(clientCtx, val.GetAddress())
require.NoError(t, err)
require.NotNil(t, acc)
require.Equal(t, height, int64(2))
require.NoError(t, ar.EnsureExists(clientCtx, val.Address))
require.NoError(t, ar.EnsureExists(clientCtx, val.GetAddress()))
accNum, accSeq, err := ar.GetAccountNumberSequence(clientCtx, val.Address)
accNum, accSeq, err := ar.GetAccountNumberSequence(clientCtx, val.GetAddress())
require.NoError(t, err)
require.Equal(t, accNum, uint64(0))
require.Equal(t, accSeq, uint64(1))