-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtrustsql_test.go
More file actions
97 lines (80 loc) · 2.55 KB
/
trustsql_test.go
File metadata and controls
97 lines (80 loc) · 2.55 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
package trustsql
import (
"fmt"
"testing"
"time"
"github.com/KleeTaurus/go-trustsql-sdk/tsiss"
)
const (
issGetSignStrTestURI = "http://39.107.26.141:8007/trustsql/v1.0/iss_get_sign_str"
issQueryTestURI = "http://39.107.26.141:8007/trustsql/v1.0/iss_query"
)
func TestGeneratePairkey(t *testing.T) {
client := GenRandomPairkey()
/*
log.Printf("Private Key: %s, len: %d\n", base64Encode(c.PrivateKey), len(c.PrivateKey))
log.Printf("Public key : %s, len: %d\n", base64Encode(c.PublicKey), len(c.PublicKey))
log.Printf("Address : %s, len: %d\n", c.GetAddrByPubkey(), len(c.GetAddrByPubkey()))
*/
if len(client.PrivateKey) != 32 {
t.Errorf("Incorrect length of the private key, it should be 32 bytes\n")
}
if len(client.PublicKey) != 33 {
t.Errorf("Incorrect length of the public key, it should be 33 bytes\n")
}
if len(client.GetAddrByPubkey()) != 34 && len(client.GetAddrByPubkey()) != 33 {
t.Errorf("Incorrect length of the address, it should be 34 or 33 bytes\n")
}
}
func TestGetIssSignStr(t *testing.T) {
client, err := NewClient("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
if err != nil {
t.Error("GeneratePairkeyByPrivateKey err")
}
client.SetAppendIssURI(issGetSignStrTestURI)
ia := tsiss.IssAppend{
Version: "1.0",
SignType: "ECDSA",
MchID: "xxxxxxxxxxxxxxxxx",
MchSign: "",
ChainID: "xxxxxxxxxxxxxxx",
LedgerID: "xxxxxxxxxxxxxx",
InfoKey: "xxxxxxxxxxxxxxxx",
InfoVersion: "1",
State: "1",
Content: map[string]interface{}{"content": "test"},
Notes: map[string]interface{}{"note": "test"},
CommitTime: "2018-04-04 16:47:31",
Account: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
PublicKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
TimeStamp: time.Now().Unix(),
}
signStr, err := client.GetIssSignStr(&ia)
if err != nil {
t.Errorf("GetIssSignStr failed %s", err)
}
fmt.Printf("signstr is: %+v\n", signStr)
}
func TestAppendIss(t *testing.T) {
}
func TestQueryIss(t *testing.T) {
client := GenRandomPairkey()
client.SetQueryIssURI(issQueryTestURI)
iq := tsiss.IssQuery{
Version: "1.0",
SignType: "ECDSA",
MchID: "gbec7b7cece75c8a5",
MchSign: "MEYCIQDCoCYth2zGer2Z/kliD11jRXGKqLqLNk/vo18js+CvRwIhANTQ3PbN9vj9YjmaB+rma2Sz0D+30WgZPOHAO9ysRsj1",
ChainID: "xxxxxxxxxxxxxx",
LedgerID: "xxxxxxxxxxxxxx",
Content: map[string]interface{}{"owner": "ulegal"},
Notes: map[string]interface{}{"extInfo": "default"},
PageNo: "1",
PageLimit: "2",
Timestamp: "1503648096",
}
_, err := client.QueryIss(&iq)
if err != nil {
t.Error(err)
}
}