OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / tendermint / go-crypto / keys / cryptostore / storage_test.go
1 package cryptostore
2
3 import (
4         "testing"
5
6         "github.com/stretchr/testify/assert"
7
8         crypto "github.com/tendermint/go-crypto"
9         cmn "github.com/tendermint/tmlibs/common"
10
11         keys "github.com/tendermint/go-crypto/keys"
12 )
13
14 func TestSortKeys(t *testing.T) {
15         assert := assert.New(t)
16
17         gen := func() crypto.PrivKey {
18                 key, _ := GenEd25519.Generate(cmn.RandBytes(16))
19                 return key
20         }
21         assert.NotEqual(gen(), gen())
22
23         // alphabetical order is n3, n1, n2
24         n1, n2, n3 := "john", "mike", "alice"
25         infos := keys.Infos{
26                 info(n1, gen()),
27                 info(n2, gen()),
28                 info(n3, gen()),
29         }
30
31         // make sure they are initialized unsorted
32         assert.Equal(n1, infos[0].Name)
33         assert.Equal(n2, infos[1].Name)
34         assert.Equal(n3, infos[2].Name)
35
36         // now they are sorted
37         infos.Sort()
38         assert.Equal(n3, infos[0].Name)
39         assert.Equal(n1, infos[1].Name)
40         assert.Equal(n2, infos[2].Name)
41
42         // make sure info put some real data there...
43         assert.NotEmpty(infos[0].PubKey)
44         assert.NotEmpty(infos[0].PubKey.Address())
45         assert.NotEmpty(infos[1].PubKey)
46         assert.NotEmpty(infos[1].PubKey.Address())
47         assert.NotEqual(infos[0].PubKey, infos[1].PubKey)
48 }