-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwallet_test.go
More file actions
132 lines (96 loc) · 3.18 KB
/
Copy pathwallet_test.go
File metadata and controls
132 lines (96 loc) · 3.18 KB
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
package wallet
import (
"testing"
)
/**
* 钱包创建测试用例
*/
func Test_Wallet(t *testing.T) {
secret := "snsYqv2FsYLuibE9TGHdG5x5V5Qcn"
//私钥合法性测试
isOk := IsValidSecret(secret)
if !isOk {
t.Fatalf("Failure IsValidSecret(%s) is false", secret)
}
t.Logf("Success IsValidSecret(%s) is true", secret)
//根据私钥创建测试
wt, err := FromSecret(secret)
if err != nil {
t.Fatalf("Failure FromSecret : %s, err %v", secret, err)
}
t.Logf("Success FromSecret(%s). PublicKey : %s. Wallet address : %s", wt.GetSecret(), wt.GetPublicKey(), wt.GetAddress())
//钱包地址合法性验证
isOk = IsValidAddress(wt.GetAddress())
if !isOk {
t.Fatalf("Failure IsValidAddress(%s) is false", wt.GetAddress())
}
t.Logf("Success IsValidAddress(%s) is true", wt.GetAddress())
//生成新钱包
newWallet, err := Generate()
isOk = IsValidSecret(newWallet.GetSecret())
if !isOk {
t.Fatalf("New secret IsValidSecret(%s) is false", newWallet.GetSecret())
}
isOk = IsValidAddress(newWallet.GetAddress())
if !isOk {
t.Fatalf("New address IsValidAddress(%s) is false", newWallet.GetAddress())
}
t.Logf("Success new secret (%s). address (%s)", newWallet.GetSecret(), newWallet.GetAddress())
}
func Test_FromSecret(t *testing.T) {
secret := "ssc5eiFivvU2otV6bSYmJeZrAsQK3"
//根据私钥创建测试
wt, err := FromSecret(secret)
if err != nil {
t.Fatalf("Failure FromSecret : %s, err %v", secret, err)
}
t.Logf("Success FromSecret(%s). PublicKey : %s. Wallet address : %s", wt.GetSecret(), wt.GetPublicKey(), wt.GetAddress())
}
/*
*以下为request性能测试用例
*/
func BenchmarkWallet(b *testing.B) {
for i := 0; i < b.N; i++ {
secret := "snsYqv2FsYLuibE9TGHdG5x5V5Qcn"
//私钥合法性测试
isOk := IsValidSecret(secret)
if !isOk {
b.Fatalf("Failure IsValidSecret(%s) is false", secret)
}
b.Logf("Success IsValidSecret(%s) is true", secret)
//根据私钥创建测试
wt, err := FromSecret(secret)
if err != nil {
b.Fatalf("Failure FromSecret : %s, err %v", secret, err)
}
b.Logf("Success FromSecret(%s). PublicKey : %s. Wallet address : %s", wt.GetSecret(), wt.GetPublicKey(), wt.GetAddress())
//钱包地址合法性验证
isOk = IsValidAddress(wt.GetAddress())
if !isOk {
b.Fatalf("Failure IsValidAddress(%s) is false", wt.GetAddress())
}
b.Logf("Success IsValidAddress(%s) is true", wt.GetAddress())
//生成新钱包
newWallet, err := Generate()
isOk = IsValidSecret(newWallet.GetSecret())
if !isOk {
b.Fatalf("New secret IsValidSecret(%s) is false", newWallet.GetSecret())
}
isOk = IsValidAddress(newWallet.GetAddress())
if !isOk {
b.Fatalf("New address IsValidAddress(%s) is false", newWallet.GetAddress())
}
b.Logf("Success new secret (%s). address (%s)", newWallet.GetSecret(), newWallet.GetAddress())
}
}
func BenchmarkFromSecret(b *testing.B) {
for i := 0; i < b.N; i++ {
secret := "ssc5eiFivvU2otV6bSYmJeZrAsQK3"
//根据私钥创建测试
wt, err := FromSecret(secret)
if err != nil {
b.Fatalf("Failure FromSecret : %s, err %v", secret, err)
}
b.Logf("Success FromSecret(%s). PublicKey : %s. Wallet address : %s", wt.GetSecret(), wt.GetPublicKey(), wt.GetAddress())
}
}