Skip to content

Commit 08f6681

Browse files
committed
chore: add more tests
Signed-off-by: D4ryl00 <d4ryl00@gmail.com>
1 parent f7d1719 commit 08f6681

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tm2/pkg/crypto/keys/client/add_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,4 +553,48 @@ func TestAdd_Derive(t *testing.T) {
553553

554554
require.ErrorIs(t, cmd.ParseAndRun(ctx, args), errInvalidDerivationPath)
555555
})
556+
557+
t.Run("derivation path overwrite aborted", func(t *testing.T) {
558+
t.Parallel()
559+
560+
var (
561+
kbHome = t.TempDir()
562+
mnemonic = generateTestMnemonic(t)
563+
baseOptions = BaseOptions{
564+
InsecurePasswordStdin: true,
565+
Home: kbHome,
566+
}
567+
keyName = "example-key"
568+
path = "44'/118'/0'/0/0"
569+
)
570+
571+
// Pre-create a key that will collide with the derived name.
572+
kb, err := keys.NewKeyBaseFromDir(kbHome)
573+
require.NoError(t, err)
574+
575+
_, err = kb.CreateAccount(keyName, mnemonic, "", "encrypt", 0, 0)
576+
require.NoError(t, err)
577+
578+
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
579+
defer cancelFn()
580+
581+
io := commands.NewTestIO()
582+
io.SetIn(strings.NewReader("n\n"))
583+
584+
// Create the command
585+
cmd := NewRootCmdWithBaseConfig(io, baseOptions)
586+
587+
args := []string{
588+
"add",
589+
"--insecure-password-stdin",
590+
"--home",
591+
kbHome,
592+
"--recover",
593+
keyName,
594+
"--derivation-path",
595+
path,
596+
}
597+
598+
require.ErrorIs(t, cmd.ParseAndRun(ctx, args), errOverwriteAborted)
599+
})
556600
}

0 commit comments

Comments
 (0)