forked from Finschia/finschia-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signing_algorithms_test.go
75 lines (63 loc) · 1.52 KB
/
signing_algorithms_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
63
64
65
66
67
68
69
70
71
72
73
74
75
package keyring
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/line/lbm-sdk/crypto/hd"
)
func TestNewSigningAlgoByString(t *testing.T) {
tests := []struct {
name string
algoStr string
isSupported bool
expectedAlgo SignatureAlgo
expectedErr error
}{
{
"supported algorithm",
"secp256k1",
true,
hd.Secp256k1,
nil,
},
{
"not supported",
"notsupportedalgo",
false,
nil,
fmt.Errorf("provided algorithm \"notsupportedalgo\" is not supported"),
},
}
list := SigningAlgoList{hd.Secp256k1}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
algorithm, err := NewSigningAlgoFromString(tt.algoStr, list)
if tt.isSupported {
require.Equal(t, hd.Secp256k1, algorithm)
} else {
require.EqualError(t, err, tt.expectedErr.Error())
}
})
}
}
func TestAltSigningAlgoList_Contains(t *testing.T) {
list := SigningAlgoList{hd.Secp256k1}
require.True(t, list.Contains(hd.Secp256k1))
require.False(t, list.Contains(notSupportedAlgo{}))
}
func TestAltSigningAlgoList_String(t *testing.T) {
list := SigningAlgoList{hd.Secp256k1, notSupportedAlgo{}}
require.Equal(t, fmt.Sprintf("%s,notSupported", string(hd.Secp256k1Type)), list.String())
}
type notSupportedAlgo struct {
}
func (n notSupportedAlgo) Name() hd.PubKeyType {
return "notSupported"
}
func (n notSupportedAlgo) Derive() hd.DeriveFn {
return hd.Secp256k1.Derive()
}
func (n notSupportedAlgo) Generate() hd.GenerateFn {
return hd.Secp256k1.Generate()
}