You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

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