Skip to content

Commit

Permalink
feat: Support providing custom keyring for keystore. (backport cosmos…
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored and JeancarloBarrios committed Sep 28, 2024
1 parent e9fd663 commit b1aabae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ It is strongly recommended to upgrade to these releases as well.

* (telemetry) [#12405](https://github.com/cosmos/cosmos-sdk/pull/12405) Add _query_ calls metric to telemetry.

### Improvements

* [#12453](https://github.com/cosmos/cosmos-sdk/pull/12453) Add `NewInMemoryWithKeyring` function which allows the creation of in memory `keystore` instances with a specified set of existing items.

## [v0.46.0-rc2](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0-rc2) - 2022-07-05

### Features
Expand Down
46 changes: 45 additions & 1 deletion crypto/keyring/keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
Expand Down Expand Up @@ -1069,7 +1070,50 @@ func TestAltKeyring_UnsafeExportPrivKeyHex(t *testing.T) {
require.Error(t, err)
}

func TestNewAccount(t *testing.T) {
func TestInMemoryWithKeyring(t *testing.T) {
priv := cryptotypes.PrivKey(secp256k1.GenPrivKey())
pub := priv.PubKey()

cdc := getCodec()
_, err := NewLocalRecord("test record", priv, pub)

multi := multisig.NewLegacyAminoPubKey(
1, []cryptotypes.PubKey{
pub,
},
)

appName := "test-app"

legacyMultiInfo, err := NewLegacyMultiInfo(appName, multi)
require.NoError(t, err)
serializedLegacyMultiInfo := MarshalInfo(legacyMultiInfo)

kb := NewInMemoryWithKeyring(keyring.NewArrayKeyring([]keyring.Item{
{
Key: appName + ".info",
Data: serializedLegacyMultiInfo,
Description: "test description",
},
}), cdc)

t.Run("key exists", func(t *testing.T) {
_, err := kb.Key(appName)
require.NoError(t, err)
})

t.Run("key deleted", func(t *testing.T) {
err := kb.Delete(appName)
require.NoError(t, err)

t.Run("key is gone", func(t *testing.T) {
_, err := kb.Key(appName)
require.Error(t, err)
})
})
}

func TestInMemoryCreateMultisig(t *testing.T) {
cdc := getCodec()

tests := []struct {
Expand Down

0 comments on commit b1aabae

Please sign in to comment.