-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x/auth: turn sign --validate-sigantures into a standalone command
--validate-signatures should not be a flag of the sign command as the operation performed (transaction signatures verification) is logically distinct. cli_test is and has always been an horrible name for package directory as it's very much Go anti-idiomatic - _test is the suffix used by test packages, not directories. Plus, CLI test cases can and should live alongside other testcases that don't require binaries to be built beforehand. Thus: x/module/client/cli_test/*.go -> x/module/client/cli/ Test files that require sim{cli,d} shall be tagged with // +build cli_test With regard to cli test auxiliary functions, they should live in: x/module/client/testutil/
- Loading branch information
Alessio Treglia
committed
May 2, 2020
1 parent
01b59db
commit 9586d6f
Showing
20 changed files
with
352 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// +build cli_test | ||
|
||
package cli_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/tests" | ||
"github.com/cosmos/cosmos-sdk/tests/cli" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/client/testutil" | ||
) | ||
|
||
func TestCLIValidateSignatures(t *testing.T) { | ||
t.Parallel() | ||
f := cli.InitFixtures(t) | ||
|
||
// start simd server | ||
proc := f.SDStart() | ||
t.Cleanup(func() { proc.Stop(false) }) | ||
|
||
f.ValidateGenesis() | ||
|
||
fooAddr := f.KeyAddress(cli.KeyFoo) | ||
barAddr := f.KeyAddress(cli.KeyBar) | ||
|
||
// generate sendTx with default gas | ||
success, stdout, stderr := testutil.TxSend(f, fooAddr.String(), barAddr, sdk.NewInt64Coin("stake", 10), "--generate-only") | ||
require.True(t, success) | ||
require.Empty(t, stderr) | ||
|
||
// write unsigned tx to file | ||
unsignedTxFile, cleanup := tests.WriteToNewTempFile(t, stdout) | ||
t.Cleanup(cleanup) | ||
|
||
// validate we can successfully sign | ||
success, stdout, _ = testutil.TxSign(f, cli.KeyFoo, unsignedTxFile.Name()) | ||
require.True(t, success) | ||
|
||
stdTx := cli.UnmarshalStdTx(t, f.Cdc, stdout) | ||
|
||
require.Equal(t, len(stdTx.Msgs), 1) | ||
require.Equal(t, 1, len(stdTx.GetSignatures())) | ||
require.Equal(t, fooAddr.String(), stdTx.GetSigners()[0].String()) | ||
|
||
// write signed tx to file | ||
signedTxFile, cleanup := tests.WriteToNewTempFile(t, stdout) | ||
t.Cleanup(cleanup) | ||
|
||
// validate signatures | ||
success, _, _ = testutil.TxValidateSignatures(f, signedTxFile.Name()) | ||
require.True(t, success) | ||
|
||
// modify the transaction | ||
stdTx.Memo = "MODIFIED-ORIGINAL-TX-BAD" | ||
bz := cli.MarshalStdTx(t, f.Cdc, stdTx) | ||
modSignedTxFile, cleanup := tests.WriteToNewTempFile(t, string(bz)) | ||
t.Cleanup(cleanup) | ||
|
||
// validate signature validation failure due to different transaction sig bytes | ||
success, _, _ = testutil.TxValidateSignatures(f, modSignedTxFile.Name()) | ||
require.False(t, success) | ||
|
||
// Cleanup testing directories | ||
f.Cleanup() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.