diff --git a/testutil/network/integration_test.go b/testutil/network/integration_test.go deleted file mode 100644 index 2839171..0000000 --- a/testutil/network/integration_test.go +++ /dev/null @@ -1,149 +0,0 @@ -package network - -import ( - "fmt" - "testing" - - "github.com/gogo/protobuf/proto" - "github.com/stretchr/testify/suite" - - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - "github.com/cosmos/cosmos-sdk/testutil/network" - sdk "github.com/cosmos/cosmos-sdk/types" - banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil" - "github.com/cosmos/cosmos-sdk/x/staking/client/cli" -) - -type IntegrationTestSuite struct { - suite.Suite - - cfg network.Config - network *network.Network -} - -func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { - return &IntegrationTestSuite{cfg: cfg} -} - -func (s *IntegrationTestSuite) SetupSuite() { - s.T().Log("setting up integration test suite") - - if testing.Short() { - s.T().Skip("skipping test in unit-tests mode.") - } - - s.network = network.New(s.T(), s.cfg) - - _, err := s.network.WaitForHeight(1) - s.Require().NoError(err) -} - -func (s *IntegrationTestSuite) TearDownSuite() { - s.T().Log("tearing down integration test suite") - s.network.Cleanup() -} - -func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() { - require := s.Require() - val := s.network.Validators[0] - - consPrivKey := ed25519.GenPrivKey() - consPubKeyBz, err := s.cfg.Codec.MarshalInterfaceJSON(consPrivKey.PubKey()) - require.NoError(err) - require.NotNil(consPubKeyBz) - - info, _, err := val.ClientCtx.Keyring.NewMnemonic("NewValidator", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) - require.NoError(err) - - newAddr := sdk.AccAddress(info.GetPubKey().Address()) - _, err = banktestutil.MsgSendExec( - val.ClientCtx, - val.Address, - newAddr, - sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), - ) - require.NoError(err) - - testCases := []struct { - name string - args []string - expectErr bool - expectedCode uint32 - respType proto.Message - }{ - { - "valid transaction", - []string{ - fmt.Sprintf("--%s=%s", cli.FlagPubKey, consPubKeyBz), - fmt.Sprintf("--%s=%dstake", cli.FlagAmount, 100), - fmt.Sprintf("--%s=NewValidator", cli.FlagMoniker), - fmt.Sprintf("--%s=AFAF00C4", cli.FlagIdentity), - fmt.Sprintf("--%s=https://newvalidator.io", cli.FlagWebsite), - fmt.Sprintf("--%s=contact@newvalidator.io", cli.FlagSecurityContact), - fmt.Sprintf("--%s='Hey, I am a new validator. Please delegate!'", cli.FlagDetails), - fmt.Sprintf("--%s=0.5", cli.FlagCommissionRate), - fmt.Sprintf("--%s=1.0", cli.FlagCommissionMaxRate), - fmt.Sprintf("--%s=0.1", cli.FlagCommissionMaxChangeRate), - fmt.Sprintf("--%s=1", cli.FlagMinSelfDelegation), - fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), - }, - false, 0, &sdk.TxResponse{}, - }, - { - "commission rate too low", - []string{ - fmt.Sprintf("--%s=%s", cli.FlagPubKey, consPubKeyBz), - fmt.Sprintf("--%s=%dstake", cli.FlagAmount, 100), - fmt.Sprintf("--%s=NewValidator", cli.FlagMoniker), - fmt.Sprintf("--%s=AFAF00C4", cli.FlagIdentity), - fmt.Sprintf("--%s=https://newvalidator.io", cli.FlagWebsite), - fmt.Sprintf("--%s=contact@newvalidator.io", cli.FlagSecurityContact), - fmt.Sprintf("--%s='Hey, I am a new validator. Please delegate!'", cli.FlagDetails), - fmt.Sprintf("--%s=0.004", cli.FlagCommissionRate), - fmt.Sprintf("--%s=1.0", cli.FlagCommissionMaxRate), - fmt.Sprintf("--%s=0.1", cli.FlagCommissionMaxChangeRate), - fmt.Sprintf("--%s=1", cli.FlagMinSelfDelegation), - fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), - }, - false, 4, &sdk.TxResponse{}, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.NewCreateValidatorCmd() - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - if tc.expectErr { - require.Error(err) - } else { - require.NoError(err, "test: %s\noutput: %s", tc.name, out.String()) - err = clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType) - require.NoError(err, out.String(), "test: %s, output\n:", tc.name, out.String()) - - txResp := tc.respType.(*sdk.TxResponse) - require.Equal(tc.expectedCode, txResp.Code, - "test: %s, output\n:", tc.name, out.String()) - } - }) - } -} - -func TestIntegrationTestSuite(t *testing.T) { - suite.Run(t, NewIntegrationTestSuite(DefaultConfig())) -} diff --git a/testutil/network/network.go b/testutil/network/network.go index 6196f22..9c1564b 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -26,10 +26,19 @@ type ( Config = network.Config ) -// New creates instance with fully configured Chihuahua network, along with -// creating a funded account for each name provided -func New(t *testing.T, config network.Config) *network.Network { - net := network.New(t, config) +// New creates instance with fully configured cosmos network. +// Accepts optional config, that will be used in place of the DefaultConfig() if provided. +func New(t *testing.T, configs ...network.Config) *network.Network { + if len(configs) > 1 { + panic("at most one config should be provided") + } + var cfg network.Config + if len(configs) == 0 { + cfg = DefaultConfig() + } else { + cfg = configs[0] + } + net := network.New(t, cfg) t.Cleanup(net.Cleanup) return net }