From fa9ce49d9d7f5d665ae1291e3a50ccd214e246fb Mon Sep 17 00:00:00 2001 From: Oksana Date: Fri, 20 Sep 2024 12:37:59 +0300 Subject: [PATCH 1/3] docs: posted a link to the developers Github (#21828) --- RELEASE_PROCESS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RELEASE_PROCESS.md b/RELEASE_PROCESS.md index 9bbb8817f862..e676be0d4ab1 100644 --- a/RELEASE_PROCESS.md +++ b/RELEASE_PROCESS.md @@ -212,9 +212,9 @@ Their responsibilities include: Currently residing Stable Release Managers: -* @tac0turtle - Marko Baricevic -* @julienrbrt - Julien Robert - +* [@tac0turtle - Marko Baricevic](https://github.com/tac0turtle) +* [@julienrbrt - Julien Robert](https://github.com/julienrbrt) + ## Cosmos SDK Modules Tagging Strategy The Cosmos SDK repository is a mono-repo where its Go modules have a different release process and cadence than the Cosmos SDK itself. From 5a05f12097ee7cf26b960eabde054f7492e8b78f Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 20 Sep 2024 04:38:31 -0500 Subject: [PATCH 2/3] tests(math): fix zero value test (#21821) --- math/dec_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/math/dec_test.go b/math/dec_test.go index e8336a97a24c..90d610199f3f 100644 --- a/math/dec_test.go +++ b/math/dec_test.go @@ -1032,11 +1032,13 @@ func Test_DocumentLegacyAsymmetry(t *testing.T) { zeroDecBz, err := zeroDec.Marshal() require.NoError(t, err) - zeroDecJSON := zeroDec.String() + zeroDecJSON, err := zeroDec.MarshalJSON() + require.NoError(t, err) emptyDecBz, err := emptyDec.Marshal() require.NoError(t, err) - emptyDecJSON := emptyDec.String() + emptyDecJSON, err := emptyDec.MarshalJSON() + require.NoError(t, err) // makes sense, zero and empty are semantically different and render differently require.NotEqual(t, zeroDecJSON, emptyDecJSON) @@ -1047,14 +1049,19 @@ func Test_DocumentLegacyAsymmetry(t *testing.T) { zeroDecRoundTrip := math.LegacyDec{} err = zeroDecRoundTrip.Unmarshal(zeroDecBz) require.NoError(t, err) - require.Equal(t, zeroDec.String(), zeroDecRoundTrip.String()) + zeroDecRoundTripJSON, err := zeroDecRoundTrip.MarshalJSON() + require.NoError(t, err) + require.Equal(t, zeroDecJSON, zeroDecRoundTripJSON) require.Equal(t, zeroDec, zeroDecRoundTrip) // empty values are not emptyDecRoundTrip := math.LegacyDec{} err = emptyDecRoundTrip.Unmarshal(emptyDecBz) require.NoError(t, err) + emptyDecRoundTripJSON, err := emptyDecRoundTrip.MarshalJSON() + require.NoError(t, err) + // !!! this is the key point, they are not equal, it looks like a bug - require.NotEqual(t, emptyDec.String(), emptyDecRoundTrip.String()) + require.NotEqual(t, emptyDecJSON, emptyDecRoundTripJSON) require.NotEqual(t, emptyDec, emptyDecRoundTrip) } From 8d248f0bfa87a7c17c993267a80416079b37c5f3 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:51:41 +0800 Subject: [PATCH 3/3] feat(client/keys): add support for importing hex key using standard input (#21829) --- CHANGELOG.md | 1 + client/keys/import.go | 20 ++++++++++++----- client/keys/import_test.go | 46 +++++++++++++++++++++----------------- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffb15bee3b26..b80a0c60b469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (cli) [#21372](https://github.com/cosmos/cosmos-sdk/pull/21372) Add a `bulk-add-genesis-account` genesis command to add many genesis accounts at once. * (crypto/keyring) [#21653](https://github.com/cosmos/cosmos-sdk/pull/21653) New Linux-only backend that adds Linux kernel's `keyctl` support. * (runtime) [#21704](https://github.com/cosmos/cosmos-sdk/pull/21704) Add StoreLoader in simappv2. +* (client/keys) [#21829](https://github.com/cosmos/cosmos-sdk/pull/21829) Add support for importing hex key using standard input. ### Improvements diff --git a/client/keys/import.go b/client/keys/import.go index 9a86da287978..c9893239ae07 100644 --- a/client/keys/import.go +++ b/client/keys/import.go @@ -34,7 +34,7 @@ func ImportKeyCommand() *cobra.Command { } buf := bufio.NewReader(clientCtx.Input) - bz, err := os.ReadFile(args[1]) + armor, err := os.ReadFile(args[1]) if err != nil { return err } @@ -44,17 +44,17 @@ func ImportKeyCommand() *cobra.Command { return err } - return clientCtx.Keyring.ImportPrivKey(args[0], string(bz), passphrase) + return clientCtx.Keyring.ImportPrivKey(name, string(armor), passphrase) }, } } func ImportKeyHexCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "import-hex ", + Use: "import-hex [hex]", Short: "Import private keys into the local keybase", Long: fmt.Sprintf("Import hex encoded private key into the local keybase.\nSupported key-types can be obtained with:\n%s list-key-types", version.AppName), - Args: cobra.ExactArgs(2), + Args: cobra.RangeArgs(1, 2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { @@ -65,7 +65,17 @@ func ImportKeyHexCommand() *cobra.Command { return errors.New("the provided name is invalid or empty after trimming whitespace") } keyType, _ := cmd.Flags().GetString(flags.FlagKeyType) - return clientCtx.Keyring.ImportPrivKeyHex(args[0], args[1], keyType) + var hexKey string + if len(args) == 2 { + hexKey = args[1] + } else { + buf := bufio.NewReader(clientCtx.Input) + hexKey, err = input.GetPassword("Enter hex private key:", buf) + if err != nil { + return err + } + } + return clientCtx.Keyring.ImportPrivKeyHex(name, hexKey, keyType) }, } cmd.Flags().String(flags.FlagKeyType, string(hd.Secp256k1Type), "private key signing algorithm kind") diff --git a/client/keys/import_test.go b/client/keys/import_test.go index bc9c5d34abb7..3f73cbd9659f 100644 --- a/client/keys/import_test.go +++ b/client/keys/import_test.go @@ -82,11 +82,11 @@ HbP+c6JmeJy9JXe2rbbF1QtCX1gLqGcDQPBXiCtFvP7/8wTZtVOPj8vREzhZ9ElO // Now add a temporary keybase kbHome := filepath.Join(t.TempDir(), fmt.Sprintf("kbhome-%s", tc.name)) - // Create dir, otherwise os.WriteFile will fail - if _, err := os.Stat(kbHome); os.IsNotExist(err) { - err = os.MkdirAll(kbHome, 0o700) - require.NoError(t, err) - } + require.NoError(t, os.MkdirAll(kbHome, 0o700)) + t.Cleanup(func() { + require.NoError(t, os.RemoveAll(kbHome)) + }) + kb, err := keyring.New(sdk.KeyringServiceName(), tc.keyringBackend, kbHome, nil, cdc) require.NoError(t, err) @@ -97,15 +97,9 @@ HbP+c6JmeJy9JXe2rbbF1QtCX1gLqGcDQPBXiCtFvP7/8wTZtVOPj8vREzhZ9ElO WithCodec(cdc) ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx) - t.Cleanup(cleanupKeys(t, kb, "keyname1")) - keyfile := filepath.Join(kbHome, "key.asc") require.NoError(t, os.WriteFile(keyfile, []byte(armoredKey), 0o600)) - defer func() { - _ = os.RemoveAll(kbHome) - }() - mockIn.Reset(tc.userInput) cmd.SetArgs([]string{ "keyname1", keyfile, @@ -128,6 +122,7 @@ func Test_runImportHexCmd(t *testing.T) { name string keyringBackend string hexKey string + stdInput bool keyType string expectError bool }{ @@ -137,6 +132,13 @@ func Test_runImportHexCmd(t *testing.T) { hexKey: "0xa3e57952e835ed30eea86a2993ac2a61c03e74f2085b3635bd94aa4d7ae0cfdf", keyType: "secp256k1", }, + { + name: "read the hex key from standard input", + keyringBackend: keyring.BackendTest, + stdInput: true, + hexKey: "0xa3e57952e835ed30eea86a2993ac2a61c03e74f2085b3635bd94aa4d7ae0cfdf", + keyType: "secp256k1", + }, } for _, tc := range testCases { @@ -147,6 +149,10 @@ func Test_runImportHexCmd(t *testing.T) { // Now add a temporary keybase kbHome := filepath.Join(t.TempDir(), fmt.Sprintf("kbhome-%s", tc.name)) + t.Cleanup(func() { + require.NoError(t, os.RemoveAll(kbHome)) + }) + kb, err := keyring.New(sdk.KeyringServiceName(), tc.keyringBackend, kbHome, nil, cdc) require.NoError(t, err) @@ -157,17 +163,17 @@ func Test_runImportHexCmd(t *testing.T) { WithCodec(cdc) ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx) - t.Cleanup(cleanupKeys(t, kb, "keyname1")) - - defer func() { - _ = os.RemoveAll(kbHome) - }() - - cmd.SetArgs([]string{ - "keyname1", tc.hexKey, + args := []string{"keyname1"} + if tc.stdInput { + mockIn.Reset(tc.hexKey) + } else { + args = append(args, tc.hexKey) + } + cmd.SetArgs(append( + args, fmt.Sprintf("--%s=%s", flags.FlagKeyType, tc.keyType), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, tc.keyringBackend), - }) + )) err = cmd.ExecuteContext(ctx) if tc.expectError {