Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

x/auth: in-process test refactor #6573

Merged
merged 71 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
9a02e1a
remove unused functions
jgimeno Jul 1, 2020
55cabc9
create helper func to send tx
jgimeno Jul 1, 2020
3c5dec4
refactor to use test help to send tx by client
jgimeno Jul 1, 2020
e78c747
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
jgimeno Jul 2, 2020
e8242f0
Commit before getting backend.
jgimeno Jul 2, 2020
c40e293
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
jgimeno Jul 2, 2020
836b685
Temporal commit
jgimeno Jul 3, 2020
2827d29
temp commit
jgimeno Jul 3, 2020
b5f89c7
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
jgimeno Jul 8, 2020
5376b5f
remove the creation of txbuilder from cli
jgimeno Jul 8, 2020
0a6690f
fix imports
jgimeno Jul 8, 2020
204aa71
update changelog
jgimeno Jul 8, 2020
db8bc87
Merge branch 'master' into jonathan/tx-builder
jgimeno Jul 8, 2020
58774c3
Remove unused function.
jgimeno Jul 8, 2020
772733e
Merge branch 'jonathan/tx-builder' of github.com:cosmos/cosmos-sdk in…
jgimeno Jul 8, 2020
da4f432
Merge branch 'jonathan/tx-builder' into jonathan/auth-module-inproces…
jgimeno Jul 9, 2020
af47525
Add flag home into tx sign command.
jgimeno Jul 9, 2020
c4ff30e
Merge branch 'jonathan/tx-builder' into jonathan/auth-module-inproces…
jgimeno Jul 9, 2020
3962c82
migrade TestCLIValidateSignatures to use new test suite
jgimeno Jul 9, 2020
f46f8ea
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
jgimeno Jul 9, 2020
54a84a6
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
jgimeno Jul 9, 2020
47767d6
migrate test one
jgimeno Jul 9, 2020
ea95899
Add changes to make sign batch.
jgimeno Jul 9, 2020
8c7958c
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
jgimeno Jul 10, 2020
f0c22e5
make test pass
jgimeno Jul 10, 2020
1e9e3e2
refactor common logic
jgimeno Jul 10, 2020
dbe63bd
First part of cli sign.
jgimeno Jul 10, 2020
604a936
Add test for sign batch.
jgimeno Jul 10, 2020
69024ab
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
jgimeno Jul 10, 2020
c91d2e5
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
Jul 10, 2020
0f26ab0
refactor a little and improve the test
jgimeno Jul 10, 2020
03197b4
Merge branch 'jonathan/auth-module-inprocess-integration-test' of git…
jgimeno Jul 10, 2020
6670230
migrate broadcast command
jgimeno Jul 10, 2020
4fc0031
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
Jul 10, 2020
ff460e8
fix linter
jgimeno Jul 10, 2020
bfd58dd
Merge branch 'jonathan/auth-module-inprocess-integration-test' of git…
jgimeno Jul 10, 2020
3bab3e5
Remove printf for debug in bank module.
jgimeno Jul 10, 2020
5006376
Fix unused err var.
jgimeno Jul 10, 2020
3a86663
fix linter
jgimeno Jul 10, 2020
ebe54b8
fix test
jgimeno Jul 10, 2020
21810a5
fix tests client
jgimeno Jul 10, 2020
7046e76
Fix linter.
jgimeno Jul 10, 2020
286492c
Temp commit signature.
jgimeno Jul 13, 2020
8e9a1d5
encode tx
jgimeno Jul 13, 2020
9f96ef9
migrate tests
jgimeno Jul 13, 2020
1a755a3
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
jgimeno Jul 13, 2020
67805a4
Fix imports.
jgimeno Jul 13, 2020
4973b9a
Remove changelog
jgimeno Jul 13, 2020
1f4db6e
fix tests
jgimeno Jul 13, 2020
54fa3cc
Fix tests.
jgimeno Jul 13, 2020
a3f7647
Update x/bank/client/testutil/cli_helpers.go
Jul 13, 2020
61ad3cf
Remove alias.
jgimeno Jul 13, 2020
1bf0a90
Merge branch 'jonathan/auth-module-inprocess-integration-test' of git…
jgimeno Jul 13, 2020
af3a0f2
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
fedekunze Jul 13, 2020
57baa45
Remove wait for N block func.
jgimeno Jul 13, 2020
b7604f5
Merge branch 'jonathan/auth-module-inprocess-integration-test' of git…
jgimeno Jul 13, 2020
b9667fe
export callCmd function into its own file.
jgimeno Jul 13, 2020
7bf3912
fix imports
jgimeno Jul 13, 2020
9fba248
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
jgimeno Jul 13, 2020
72debd9
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
alexanderbez Jul 14, 2020
a1997f0
bring back to inner functions
jgimeno Jul 14, 2020
8523e71
Merge branch 'jonathan/auth-module-inprocess-integration-test' of git…
jgimeno Jul 14, 2020
9138048
apply mock io
jgimeno Jul 14, 2020
bae1521
the helpers use mockio
jgimeno Jul 14, 2020
6a35ee9
fix bug
jgimeno Jul 14, 2020
45374fb
Add Helpers.
jgimeno Jul 14, 2020
4a05e9c
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
jgimeno Jul 14, 2020
16bf27f
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
jgimeno Jul 14, 2020
dded545
return to put the function in testutil package
jgimeno Jul 14, 2020
8616606
return BufferWriter in ExecTestCLICmd
jgimeno Jul 14, 2020
4e9e0e3
Merge branch 'master' into jonathan/auth-module-inprocess-integration…
jgimeno Jul 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 83 additions & 35 deletions x/auth/client/cli/cli_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build cli_test

package cli_test

import (
Expand All @@ -8,15 +6,61 @@ import (
"testing"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/tests"
"github.com/cosmos/cosmos-sdk/tests/cli"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/client/testutil"
authtest "github.com/cosmos/cosmos-sdk/x/auth/client/testutil"
bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
)

type IntegrationTestSuite struct {
suite.Suite

cfg testutil.Config
network *testutil.Network
}

func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")

cfg := testutil.DefaultConfig()
cfg.NumValidators = 1

s.cfg = cfg
s.network = testutil.NewTestNetwork(s.T(), 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) TestCLIValidateSignatures() {
val := s.network.Validators[0]
tx, err := bankcli.SendTx(
val.ClientCtx,
val.Address.String(),
val.Address.String(),
sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), sdk.NewInt(10)),
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)),
),
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()),
fmt.Sprintf("--%s=true", flags.FlagGenerateOnly),
)
s.Require().NoError(err)
fmt.Printf("%s", tx)
}

func TestCLIValidateSignatures(t *testing.T) {
t.Parallel()
f := cli.InitFixtures(t)
Expand All @@ -40,7 +84,7 @@ func TestCLIValidateSignatures(t *testing.T) {
t.Cleanup(cleanup)

// validate we can successfully sign
success, stdout, _ = testutil.TxSign(f, cli.KeyFoo, unsignedTxFile.Name())
success, stdout, _ = authtest.TxSign(f, cli.KeyFoo, unsignedTxFile.Name())
require.True(t, success)

stdTx := cli.UnmarshalStdTx(t, f.Cdc, stdout)
Expand All @@ -54,7 +98,7 @@ func TestCLIValidateSignatures(t *testing.T) {
t.Cleanup(cleanup)

// validate signatures
success, _, _ = testutil.TxValidateSignatures(f, signedTxFile.Name())
success, _, _ = authtest.TxValidateSignatures(f, signedTxFile.Name())
require.True(t, success)

// modify the transaction
Expand All @@ -64,7 +108,7 @@ func TestCLIValidateSignatures(t *testing.T) {
t.Cleanup(cleanup)

// validate signature validation failure due to different transaction sig bytes
success, _, _ = testutil.TxValidateSignatures(f, modSignedTxFile.Name())
success, _, _ = authtest.TxValidateSignatures(f, modSignedTxFile.Name())
require.False(t, success)

// Cleanup testing directories
Expand All @@ -89,18 +133,18 @@ func TestCLISignBatch(t *testing.T) {
t.Cleanup(cleanup1)

// sign-batch file - offline is set but account-number and sequence are not
success, _, stderr = testutil.TxSignBatch(f, cli.KeyFoo, batchfile.Name(), "--offline")
success, _, stderr = authtest.TxSignBatch(f, cli.KeyFoo, batchfile.Name(), "--offline")
require.Contains(t, stderr, "required flag(s) \"account-number\", \"sequence\" not set")
require.False(t, success)

// sign-batch file
success, stdout, stderr := testutil.TxSignBatch(f, cli.KeyFoo, batchfile.Name())
success, stdout, stderr := authtest.TxSignBatch(f, cli.KeyFoo, batchfile.Name())
require.True(t, success)
require.Empty(t, stderr)
require.Equal(t, 3, len(strings.Split(strings.Trim(stdout, "\n"), "\n")))

// sign-batch file
success, stdout, stderr = testutil.TxSignBatch(f, cli.KeyFoo, batchfile.Name(), "--signature-only")
success, stdout, stderr = authtest.TxSignBatch(f, cli.KeyFoo, batchfile.Name(), "--signature-only")
require.True(t, success)
require.Empty(t, stderr)
require.Equal(t, 3, len(strings.Split(strings.Trim(stdout, "\n"), "\n")))
Expand All @@ -109,13 +153,13 @@ func TestCLISignBatch(t *testing.T) {
t.Cleanup(cleanup2)

// sign-batch file
success, stdout, stderr = testutil.TxSignBatch(f, cli.KeyFoo, malformedFile.Name())
success, stdout, stderr = authtest.TxSignBatch(f, cli.KeyFoo, malformedFile.Name())
require.False(t, success)
require.Equal(t, 1, len(strings.Split(strings.Trim(stdout, "\n"), "\n")))
require.Equal(t, "ERROR: cannot parse disfix JSON wrapper: invalid character 'm' looking for beginning of value\n", stderr)

// sign-batch file
success, stdout, _ = testutil.TxSignBatch(f, cli.KeyFoo, malformedFile.Name(), "--signature-only")
success, stdout, _ = authtest.TxSignBatch(f, cli.KeyFoo, malformedFile.Name(), "--signature-only")
require.False(t, success)
require.Equal(t, 1, len(strings.Split(strings.Trim(stdout, "\n"), "\n")))

Expand Down Expand Up @@ -166,23 +210,23 @@ func TestCLISendGenerateSignAndBroadcast(t *testing.T) {
t.Cleanup(cleanup)

// Test validate-signatures
success, stdout, _ = testutil.TxValidateSignatures(f, unsignedTxFile.Name())
success, stdout, _ = authtest.TxValidateSignatures(f, unsignedTxFile.Name())
require.False(t, success)
require.Equal(t, fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n\n", fooAddr.String()), stdout)

// Test sign

// Does not work in offline mode
success, stdout, stderr = testutil.TxSign(f, cli.KeyFoo, unsignedTxFile.Name(), "--offline")
success, stdout, stderr = authtest.TxSign(f, cli.KeyFoo, unsignedTxFile.Name(), "--offline")
require.Contains(t, stderr, "required flag(s) \"account-number\", \"sequence\" not set")
require.False(t, success)

// But works offline if we set account number and sequence
success, _, _ = testutil.TxSign(f, cli.KeyFoo, unsignedTxFile.Name(), "--offline", "--account-number", "1", "--sequence", "1")
success, _, _ = authtest.TxSign(f, cli.KeyFoo, unsignedTxFile.Name(), "--offline", "--account-number", "1", "--sequence", "1")
require.True(t, success)

// Sign transaction
success, stdout, _ = testutil.TxSign(f, cli.KeyFoo, unsignedTxFile.Name())
success, stdout, _ = authtest.TxSign(f, cli.KeyFoo, unsignedTxFile.Name())
require.True(t, success)
msg = cli.UnmarshalStdTx(t, f.Cdc, stdout)
require.Equal(t, len(msg.Msgs), 1)
Expand All @@ -194,7 +238,7 @@ func TestCLISendGenerateSignAndBroadcast(t *testing.T) {
t.Cleanup(cleanup)

// Test validate-signatures
success, stdout, _ = testutil.TxValidateSignatures(f, signedTxFile.Name())
success, stdout, _ = authtest.TxValidateSignatures(f, signedTxFile.Name())
require.True(t, success)
require.Equal(t, fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n 0: %v\t\t\t[OK]\n\n", fooAddr.String(),
fooAddr.String()), stdout)
Expand All @@ -206,12 +250,12 @@ func TestCLISendGenerateSignAndBroadcast(t *testing.T) {
// Test broadcast

// Does not work in offline mode
success, _, stderr = testutil.TxBroadcast(f, signedTxFile.Name(), "--offline")
success, _, stderr = authtest.TxBroadcast(f, signedTxFile.Name(), "--offline")
require.Contains(t, stderr, "cannot broadcast tx during offline mode")
require.False(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)

success, stdout, _ = testutil.TxBroadcast(f, signedTxFile.Name())
success, stdout, _ = authtest.TxBroadcast(f, signedTxFile.Name())
require.True(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)

Expand Down Expand Up @@ -247,27 +291,27 @@ func TestCLIMultisignInsufficientCosigners(t *testing.T) {
t.Cleanup(cleanup)

// Sign with foo's key
success, stdout, _ = testutil.TxSign(f, cli.KeyFoo, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String(), "-y")
success, stdout, _ = authtest.TxSign(f, cli.KeyFoo, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String(), "-y")
require.True(t, success)

// Write the output to disk
fooSignatureFile, cleanup := tests.WriteToNewTempFile(t, stdout)
t.Cleanup(cleanup)

// Multisign, not enough signatures
success, stdout, _ = testutil.TxMultisign(f, unsignedTxFile.Name(), cli.KeyFooBarBaz, []string{fooSignatureFile.Name()})
success, stdout, _ = authtest.TxMultisign(f, unsignedTxFile.Name(), cli.KeyFooBarBaz, []string{fooSignatureFile.Name()})
require.True(t, success)

// Write the output to disk
signedTxFile, cleanup := tests.WriteToNewTempFile(t, stdout)
t.Cleanup(cleanup)

// Validate the multisignature
success, _, _ = testutil.TxValidateSignatures(f, signedTxFile.Name())
success, _, _ = authtest.TxValidateSignatures(f, signedTxFile.Name())
require.False(t, success)

// Broadcast the transaction
success, stdOut, _ := testutil.TxBroadcast(f, signedTxFile.Name())
success, stdOut, _ := authtest.TxBroadcast(f, signedTxFile.Name())
require.Contains(t, stdOut, "signature verification failed")
require.True(t, success)

Expand Down Expand Up @@ -297,11 +341,11 @@ func TestCLIEncode(t *testing.T) {
t.Cleanup(cleanup)

// Run the encode command
success, base64Encoded, _ := testutil.TxEncode(f, jsonTxFile.Name())
success, base64Encoded, _ := authtest.TxEncode(f, jsonTxFile.Name())
require.True(t, success)
trimmedBase64 := strings.Trim(base64Encoded, "\"\n")
// Check that the transaction decodes as expected
success, stdout, stderr = testutil.TxDecode(f, trimmedBase64)
success, stdout, stderr = authtest.TxDecode(f, trimmedBase64)
decodedTx := cli.UnmarshalStdTx(t, f.Cdc, stdout)
require.Equal(t, "deadbeef", decodedTx.Memo)
}
Expand Down Expand Up @@ -334,23 +378,23 @@ func TestCLIMultisignSortSignatures(t *testing.T) {
t.Cleanup(cleanup)

// Sign with foo's key
success, stdout, _ = testutil.TxSign(f, cli.KeyFoo, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String())
success, stdout, _ = authtest.TxSign(f, cli.KeyFoo, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String())
require.True(t, success)

// Write the output to disk
fooSignatureFile, cleanup := tests.WriteToNewTempFile(t, stdout)
t.Cleanup(cleanup)

// Sign with baz's key
success, stdout, _ = testutil.TxSign(f, cli.KeyBaz, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String())
success, stdout, _ = authtest.TxSign(f, cli.KeyBaz, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String())
require.True(t, success)

// Write the output to disk
bazSignatureFile, cleanup := tests.WriteToNewTempFile(t, stdout)
t.Cleanup(cleanup)

// Multisign, keys in different order
success, stdout, _ = testutil.TxMultisign(f, unsignedTxFile.Name(), cli.KeyFooBarBaz, []string{
success, stdout, _ = authtest.TxMultisign(f, unsignedTxFile.Name(), cli.KeyFooBarBaz, []string{
bazSignatureFile.Name(), fooSignatureFile.Name()})
require.True(t, success)

Expand All @@ -359,11 +403,11 @@ func TestCLIMultisignSortSignatures(t *testing.T) {
t.Cleanup(cleanup)

// Validate the multisignature
success, _, _ = testutil.TxValidateSignatures(f, signedTxFile.Name())
success, _, _ = authtest.TxValidateSignatures(f, signedTxFile.Name())
require.True(t, success)

// Broadcast the transaction
success, _, _ = testutil.TxBroadcast(f, signedTxFile.Name())
success, _, _ = authtest.TxBroadcast(f, signedTxFile.Name())
require.True(t, success)

// Cleanup testing directories
Expand Down Expand Up @@ -399,15 +443,15 @@ func TestCLIMultisign(t *testing.T) {
t.Cleanup(cleanup)

// Sign with foo's key
success, stdout, _ = testutil.TxSign(f, cli.KeyFoo, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String(), "-y")
success, stdout, _ = authtest.TxSign(f, cli.KeyFoo, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String(), "-y")
require.True(t, success)

// Write the output to disk
fooSignatureFile, cleanup := tests.WriteToNewTempFile(t, stdout)
t.Cleanup(cleanup)

// Sign with bar's key
success, stdout, _ = testutil.TxSign(f, cli.KeyBar, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String(), "-y")
success, stdout, _ = authtest.TxSign(f, cli.KeyBar, unsignedTxFile.Name(), "--multisig", fooBarBazAddr.String(), "-y")
require.True(t, success)

// Write the output to disk
Expand All @@ -417,13 +461,13 @@ func TestCLIMultisign(t *testing.T) {
// Multisign

// Does not work in offline mode
success, stdout, _ = testutil.TxMultisign(f, unsignedTxFile.Name(), cli.KeyFooBarBaz, []string{
success, stdout, _ = authtest.TxMultisign(f, unsignedTxFile.Name(), cli.KeyFooBarBaz, []string{
fooSignatureFile.Name(), barSignatureFile.Name()}, "--offline")
require.Contains(t, "couldn't verify signature", stdout)
require.False(t, success)

// Success multisign
success, stdout, _ = testutil.TxMultisign(f, unsignedTxFile.Name(), cli.KeyFooBarBaz, []string{
success, stdout, _ = authtest.TxMultisign(f, unsignedTxFile.Name(), cli.KeyFooBarBaz, []string{
fooSignatureFile.Name(), barSignatureFile.Name()})
require.True(t, success)

Expand All @@ -432,13 +476,17 @@ func TestCLIMultisign(t *testing.T) {
t.Cleanup(cleanup)

// Validate the multisignature
success, _, _ = testutil.TxValidateSignatures(f, signedTxFile.Name())
success, _, _ = authtest.TxValidateSignatures(f, signedTxFile.Name())
require.True(t, success)

// Broadcast the transaction
success, _, _ = testutil.TxBroadcast(f, signedTxFile.Name())
success, _, _ = authtest.TxBroadcast(f, signedTxFile.Name())
require.True(t, success)

// Cleanup testing directories
f.Cleanup()
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
Loading