keygen_test.go 825 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package logic
  2. import (
  3. "encoding/hex"
  4. "testing"
  5. )
  6. func TestNewKeyIden(t *testing.T) {
  7. iden := newKeyIden()
  8. if len(iden) != 32 {
  9. t.Fatalf("unexpected iden length: %d", len(iden))
  10. }
  11. if _, err := hex.DecodeString(iden); err != nil {
  12. t.Fatalf("iden is not hex: %v", err)
  13. }
  14. }
  15. func TestDeriveKeyContent(t *testing.T) {
  16. iden := newKeyIden()
  17. first, err := deriveKeyContent(iden)
  18. if err != nil {
  19. t.Fatalf("derive first content: %v", err)
  20. }
  21. second, err := deriveKeyContent(iden)
  22. if err != nil {
  23. t.Fatalf("derive second content: %v", err)
  24. }
  25. if len(first) != 64 {
  26. t.Fatalf("unexpected content length: %d", len(first))
  27. }
  28. if _, err := hex.DecodeString(first); err != nil {
  29. t.Fatalf("content is not hex: %v", err)
  30. }
  31. if first == second {
  32. t.Fatal("content should differ because the seed is random")
  33. }
  34. }