Skip to content

Commit

Permalink
test importing private key (#43)
Browse files Browse the repository at this point in the history
* test importing private key

* change log
  • Loading branch information
KonradStaniec authored Nov 26, 2024
1 parent 4bfd897 commit c16524d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Improvements

* [#43](https://github.com/babylonlabs-io/covenant-emulator/pull/43) Test importing
private key to the cosmos keyring

## v0.9.0

* [#33](https://github.com/babylonlabs-io/covenant-emulator/pull/33) Add remote
Expand Down
17 changes: 12 additions & 5 deletions covenant-signer/itest/testmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2etest

import (
"context"
"encoding/hex"
"fmt"
"testing"
"time"
Expand Down Expand Up @@ -54,7 +55,6 @@ func StartManager(
_ = h.GenerateBlocks(int(numMatureOutputsInWallet) + 100)

appConfig := config.DefaultConfig()

appConfig.KeyStore.KeyStoreType = "cosmos"
appConfig.KeyStore.CosmosKeyStore.ChainID = "test-chain"
appConfig.KeyStore.CosmosKeyStore.Passphrase = passphrase
Expand All @@ -65,9 +65,16 @@ func StartManager(
retriever, err := cosmos.NewCosmosKeyringRetriever(appConfig.KeyStore.CosmosKeyStore)
require.NoError(t, err)

keyInfo, err := retriever.Kr.CreateChainKey(
appConfig.KeyStore.CosmosKeyStore.Passphrase,
"",
covPrivKey, err := btcec.NewPrivateKey()
require.NoError(t, err)

hexPrivKey := hex.EncodeToString(covPrivKey.Serialize())

// Import private key to keyring, from hex string
err = retriever.Kr.GetKeyring().ImportPrivKeyHex(
appConfig.KeyStore.CosmosKeyStore.KeyName,
hexPrivKey,
"secp256k1",
)
require.NoError(t, err)

Expand Down Expand Up @@ -103,7 +110,7 @@ func StartManager(
t: t,
bitcoindHandler: h,
walletPass: passphrase,
covenantPrivKey: keyInfo.PrivateKey,
covenantPrivKey: covPrivKey,
signerConfig: appConfig,
app: app,
server: server,
Expand Down
1 change: 0 additions & 1 deletion covenant-signer/keystore/cosmos/keyringcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func (kc *ChainKeyringController) CreateChainKey(passphrase, hdPath string) (*Ch
if err != nil {
return nil, err
}

// read entropy seed straight from tmcrypto.Rand and convert to mnemonic
entropySeed, err := bip39.NewEntropy(mnemonicEntropySize)
if err != nil {
Expand Down

0 comments on commit c16524d

Please sign in to comment.