Skip to content

Commit

Permalink
refactor(crypto): remove dependency on simapp from tests (#12614)
Browse files Browse the repository at this point in the history
## Description

Closes: #12612 



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
kocubinski authored Jul 18, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7c43d52 commit c99a631
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 9 additions & 3 deletions crypto/armor_test.go
Original file line number Diff line number Diff line change
@@ -13,13 +13,16 @@ import (
tmcrypto "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/xsalsa20symmetric"

"cosmossdk.io/depinject"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/crypto"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
_ "github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
"github.com/cosmos/cosmos-sdk/types"
)

@@ -71,8 +74,11 @@ func TestArmorUnarmorPrivKey(t *testing.T) {

func TestArmorUnarmorPubKey(t *testing.T) {
// Select the encryption and storage for your cryptostore
encCfg := simapp.MakeTestEncodingConfig()
cstore := keyring.NewInMemory(encCfg.Codec)
var cdc codec.Codec
err := depinject.Inject(configurator.NewAppConfig(), &cdc)
require.NoError(t, err)

cstore := keyring.NewInMemory(cdc)

// Add keys and see they return in alphabetical order
k, _, err := cstore.NewMnemonic("Bob", keyring.English, types.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
10 changes: 7 additions & 3 deletions crypto/keys/multisig/multisig_test.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import (

"github.com/stretchr/testify/require"

"cosmossdk.io/depinject"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/codec/types"
@@ -15,7 +16,8 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"github.com/cosmos/cosmos-sdk/simapp"
_ "github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
@@ -356,8 +358,10 @@ func TestDisplay(t *testing.T) {
require.PanicsWithValue("reflect.Value.Interface: cannot return value obtained from unexported field or method",
func() { require.Empty(msig.String()) },
)
ccfg := simapp.MakeTestEncodingConfig()
bz, err := ccfg.Codec.MarshalInterfaceJSON(msig)
var cdc codec.Codec
err := depinject.Inject(configurator.NewAppConfig(), &cdc)
require.NoError(err)
bz, err := cdc.MarshalInterfaceJSON(msig)
require.NoError(err)
expectedPrefix := `{"@type":"/cosmos.crypto.multisig.LegacyAminoPubKey","threshold":2,"public_keys":[{"@type":"/cosmos.crypto.secp256k1.PubKey"`
require.True(strings.HasPrefix(string(bz), expectedPrefix))

0 comments on commit c99a631

Please sign in to comment.