Skip to content

Commit

Permalink
Merge branch 'main' into julien/validate
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Sep 20, 2024
2 parents 04d06bd + 8d248f0 commit e54aea3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* (x/validate) [#21822](https://github.com/cosmos/cosmos-sdk/pull/21822) New module solely responsible for providing ante/post handlers and tx validators for v2. It can be extended by the app developer to provide extra tx validators.
* In comparison to x/auth/tx/config, there is no app config to skip ante/post handlers, as overwriting them in baseapp or not injecting the x/validate module has the same effect.

Expand Down
6 changes: 3 additions & 3 deletions RELEASE_PROCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 15 additions & 5 deletions client/keys/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 <name> <hex>",
Use: "import-hex <name> [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 {
Expand All @@ -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")
Expand Down
46 changes: 26 additions & 20 deletions client/keys/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
Expand All @@ -128,6 +122,7 @@ func Test_runImportHexCmd(t *testing.T) {
name string
keyringBackend string
hexKey string
stdInput bool
keyType string
expectError bool
}{
Expand All @@ -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 {
Expand All @@ -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)

Expand All @@ -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 {
Expand Down
15 changes: 11 additions & 4 deletions math/dec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

0 comments on commit e54aea3

Please sign in to comment.