forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
legacy_test.go
57 lines (43 loc) · 1.35 KB
/
legacy_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package keyring_test
import (
"io"
"path/filepath"
"testing"
"github.com/otiai10/copy"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
)
func TestNewLegacyKeyBase(t *testing.T) {
dir := t.TempDir()
kb, err := keyring.NewLegacy("keybasename", dir)
require.NoError(t, err)
require.NoError(t, kb.Close())
}
func TestLegacyKeybase(t *testing.T) {
dir := t.TempDir()
// Backup testdata
require.NoError(t, copy.Copy("testdata", dir))
kb, err := keyring.NewLegacy("keys", filepath.Join(dir, "keys"))
require.NoError(t, err)
t.Cleanup(func() { kb.Close() })
keys, err := kb.List()
require.NoError(t, err)
require.Equal(t, 2, len(keys))
armor, err := kb.ExportPubKey(keys[0].GetName())
require.NoError(t, err)
require.NotEmpty(t, armor)
_, err = kb.ExportPrivKey(keys[0].GetName(), "12345678", "12345678")
require.Error(t, err)
armoredInfo, err := kb.Export(keys[0].GetName())
require.NoError(t, err)
require.NotEmpty(t, armoredInfo)
importer, err := keyring.NewInfoImporter("cosmos", "memory", "", nil)
require.NoError(t, err)
err = importer.Import("test", "")
require.Error(t, err)
require.Equal(t, io.EOF, err)
require.NoError(t, importer.Import("test", armoredInfo))
err = importer.Import("test", armoredInfo)
require.Error(t, err)
require.Equal(t, `public key already exist in keybase`, err.Error())
}