-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathnativetype_test.go
62 lines (54 loc) · 1.76 KB
/
nativetype_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package solana
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestMustPublicKeyFromBase58(t *testing.T) {
require.Panics(t, func() {
MustPublicKeyFromBase58("toto")
})
}
func TestSignature_Verify(t *testing.T) {
type input struct {
publickKey string
message string
signature string
}
tests := []struct {
name string
in input
expected bool
}{
{
"pass",
input{
publickKey: "Gkodg1n3z56G8XWohmNSwPNYYtsfrc1AFCZndT7XjjZ2",
message: "Signing a message that will prove to the server you own public key associated to your wallet",
signature: "7003d58a9db0ad2cb288014bf41ad60f4ad8d207b232b4adbb37933850e7c96693547e63bf977ed98f67e7b6911c376236ac14095c57b984afc14dc2c1bec308",
},
true,
},
{
"fails",
input{
publickKey: "Gkodg1n3z56G8XWohmNSwPNYYtsfrc1AFCZndT7XjjZ2",
message: "Signing a message that will prove to the server you own public key associated to your wallet",
signature: "8003d58a9db0ad2cb288014bf41ad60f4ad8d207b232b4adbb37933850e7c96693547e63bf977ed98f67e7b6911c376236ac14095c57b984afc14dc2c1bec308",
},
false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
publicKey := MustPublicKeyFromBase58(test.in.publickKey)
message := []byte(test.in.message)
signature, err := NewSignatureFromString(test.in.signature)
require.NoError(t, err)
if test.expected {
require.True(t, signature.Verify(publicKey, message), "Signature %s is invalid for public key %s (message %q)", test.in.signature, publicKey, test.in.message)
} else {
require.False(t, signature.Verify(publicKey, message), "Signature %s is valid but should not have been for public key %s (message %s)", test.in.signature, publicKey, test.in.message)
}
})
}
}