nip49: add normalization test.

This commit is contained in:
fiatjaf 2024-02-16 00:02:58 -03:00
parent 2cba101c22
commit faf76711a5
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -1,6 +1,8 @@
package nip49
import (
"errors"
"slices"
"strings"
"testing"
)
@ -51,3 +53,21 @@ func TestEncryptAndDecrypt(t *testing.T) {
}
}
}
func TestNormalization(t *testing.T) {
nonce := []byte{1, 2, 3, 4}
n := 8
key1, err1 := getKey(string([]byte{0xE2, 0x84, 0xAB, 0xE2, 0x84, 0xA6}), nonce, n)
key2, err2 := getKey(string([]byte{0xC3, 0x85, 0xCE, 0xA9}), nonce, n)
key3, err3 := getKey("ÅΩ", nonce, n)
key4, err4 := getKey("ÅΩ", nonce, n)
if merr := errors.Join(err1, err2, err3, err4); merr != nil {
t.Fatalf("getKey errored: %s", merr)
return
}
if !slices.Equal(key1, key2) || !slices.Equal(key2, key3) || !slices.Equal(key3, key4) {
t.Fatalf("normalization failed")
return
}
}