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.

41 lines
945 B

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