Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add proving test for new and old creation #134

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions eotsmanager/cmd/eotsd/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@
"path/filepath"
"testing"

bbntypes "github.com/babylonlabs-io/babylon/types"
"github.com/btcsuite/btcd/btcec/v2"
sdkflags "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/babylonlabs-io/finality-provider/eotsmanager"
eotscfg "github.com/babylonlabs-io/finality-provider/eotsmanager/config"
"github.com/babylonlabs-io/finality-provider/testutil"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
)

func FuzzNewKeysCmd(f *testing.F) {
Expand Down Expand Up @@ -90,3 +96,55 @@

return c, buf.String()
}

func TestCreateKeyOldNew(t *testing.T) {

Check failure on line 100 in eotsmanager/cmd/eotsd/keys_test.go

View workflow job for this annotation

GitHub Actions / lint_test / lint

Function TestCreateKeyOldNew missing the call to method parallel (paralleltest)
mnemonic, err := eotsmanager.NewMnemonic()
require.NoError(t, err)

homeDir := filepath.Join(t.TempDir(), "eots-home")
keyringBackend := "test"
dbBackend, err := eotscfg.DefaultDBConfigWithHomePath(homeDir).GetDBBackend()
require.NoError(t, err)

lm, err := eotsmanager.NewLocalEOTSManager(homeDir, keyringBackend, dbBackend, zap.NewNop())
require.NoError(t, err)

hdPath := ""
pwd := ""

// OLD WAY
eotsPk, err := lm.CreateKeyWithMnemonic("legoo", pwd, hdPath, mnemonic)
require.NoError(t, err)
require.NotNil(t, eotsPk)

// NEW WAY
cmd := NewKeysCmd()
cmd.Flags().AddFlagSet(NewKeysCmd().PersistentFlags())

mockIn := sdktestutil.ApplyMockIODiscardOutErr(cmd)
kbHome := t.TempDir()

cdc := moduletestutil.MakeTestEncodingConfig().Codec
kb, err := keyring.New("testingAppService", keyringBackend, kbHome, mockIn, cdc)
require.NoError(t, err)

newAccountKey, err := kb.NewAccount("legoo2", mnemonic, pwd, hdPath, hd.Secp256k1)
require.NoError(t, err)

newAccPub, err := newAccountKey.GetPubKey()
require.NoError(t, err)

var eotsPkNew *bbntypes.BIP340PubKey
switch v := newAccPub.(type) {
case *secp256k1.PubKey:
pk, err := btcec.ParsePubKey(v.Key)
require.NoError(t, err)

eotsPkNew = bbntypes.NewBIP340PubKeyFromBTCPK(pk)
require.NotNil(t, eotsPkNew)
default:
panic("iha")
}

require.True(t, eotsPk.Equals(eotsPkNew))
}
Loading