-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
185 lines (174 loc) · 3.72 KB
/
utils_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package utils
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/qom-one/qomapp/v1/crypto/ethsecp256k1"
)
func init() {
cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount("qom", "qompub")
}
func TestIsSupportedKeys(t *testing.T) {
testCases := []struct {
name string
pk cryptotypes.PubKey
isSupported bool
}{
{
"nil key",
nil,
false,
},
{
"ethsecp256k1 key",
ðsecp256k1.PubKey{},
true,
},
{
"ed25519 key",
&ed25519.PubKey{},
true,
},
{
"multisig key - no pubkeys",
&multisig.LegacyAminoPubKey{},
false,
},
{
"multisig key - valid pubkeys",
multisig.NewLegacyAminoPubKey(2, []cryptotypes.PubKey{&ed25519.PubKey{}, &ed25519.PubKey{}, &ed25519.PubKey{}}),
true,
},
{
"multisig key - nested multisig",
multisig.NewLegacyAminoPubKey(2, []cryptotypes.PubKey{&ed25519.PubKey{}, &ed25519.PubKey{}, &multisig.LegacyAminoPubKey{}}),
false,
},
{
"multisig key - invalid pubkey",
multisig.NewLegacyAminoPubKey(2, []cryptotypes.PubKey{&ed25519.PubKey{}, &ed25519.PubKey{}, &secp256k1.PubKey{}}),
false,
},
{
"cosmos secp256k1",
&secp256k1.PubKey{},
false,
},
}
for _, tc := range testCases {
require.Equal(t, tc.isSupported, IsSupportedKey(tc.pk), tc.name)
}
}
func TestGetEvmosAddressFromBech32(t *testing.T) {
testCases := []struct {
name string
address string
expAddress string
expError bool
}{
{
"blank bech32 address",
" ",
"",
true,
},
{
"invalid bech32 address",
"evmos",
"",
true,
},
{
"invalid address bytes",
"evmos1123",
"",
true,
},
{
"evmos address",
"qom1qql8ag4cluz6r4dz28p3w00dnc9w8ueudpwdcu",
"qom1qql8ag4cluz6r4dz28p3w00dnc9w8ueudpwdcu",
false,
},
{
"cosmos address",
"cosmos1qql8ag4cluz6r4dz28p3w00dnc9w8ueulg2gmc",
"qom1qql8ag4cluz6r4dz28p3w00dnc9w8ueudpwdcu",
false,
},
{
"osmosis address",
"osmo1qql8ag4cluz6r4dz28p3w00dnc9w8ueuhnecd2",
"qom1qql8ag4cluz6r4dz28p3w00dnc9w8ueudpwdcu",
false,
},
}
for _, tc := range testCases {
addr, err := GetQomAddressFromBech32(tc.address)
if tc.expError {
require.Error(t, err, tc.name)
} else {
require.NoError(t, err, tc.name)
require.Equal(t, tc.expAddress, addr.String(), tc.name)
}
}
}
func TestEvmosCoinDenom(t *testing.T) {
testCases := []struct {
name string
denom string
expError bool
}{
{
"valid denom - native coin",
"aqom",
false,
},
{
"valid denom - ibc coin",
"ibc/7B2A4F6E798182988D77B6B884919AF617A73503FDAC27C916CD7A69A69013CF",
false,
},
{
"valid denom - ethereum address (ERC-20 contract)",
"erc20/0x52908400098527886e0f7030069857D2E4169EE7",
false,
},
{
"invalid denom - only one character",
"a",
true,
},
{
"invalid denom - too large (> 127 chars)",
"ibc/7B2A4F6E798182988D77B6B884919AF617A73503FDAC27C916CD7A69A69013CF7B2A4F6E798182988D77B6B884919AF617A73503FDAC27C916CD7A69A69013CF",
true,
},
{
"invalid denom - starts with 0 but not followed by 'x'",
"0a52908400098527886E0F7030069857D2E4169EE7",
true,
},
{
"invalid denom - hex address but 19 bytes long",
"0x52908400098527886E0F7030069857D2E4169E",
true,
},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("Case %s", tc.name), func(t *testing.T) {
err := sdk.ValidateDenom(tc.denom)
if tc.expError {
require.Error(t, err, tc.name)
} else {
require.NoError(t, err, tc.name)
}
})
}
}