bdcontract-client/client/client_test.go
zhaoweijie a08ed7e35f refactor(client): 重构客户端方法并优化密钥处理
-将私钥和公钥的解析逻辑移至 NewClient 方法中- 优化 RequestWithSignature 方法,使其支持泛型返回值
- 移除不必要的 genHttpResponse 函数
- 更新客户端方法,使其使用新的 RequestWithSignature 实现
- 调整测试代码以适应新的客户端实现
2025-06-03 15:56:02 +08:00

106 lines
1.7 KiB
Go

package client
import (
"testing"
)
func TestStruct(t *testing.T) {
type a struct {
name string
age int
}
b := &a{age: 1}
t.Log(b.age)
t.Log(b.name == "")
}
func genClient() (*Client, error) {
url := "http://021.node.internetapi.cn:21030/SCIDE"
pub := "042731bc66608ba21a4301cd6522e3d6a6c7964f8dc3618cfe5d0aae493229a98623de23dfb35a5f9b7b4ac53e1f82ea79325ddf96d88a6bbcaf075df7e98acc5a"
priv := "481343eac82e0d18f8ea3a9f82a8f065543d720209e9f0d8d508f7e343883c45"
client, err := NewClient(url, priv, pub, HttpCOptions{})
if err != nil {
return nil, err
}
return client, nil
}
func TestNewClient(t *testing.T) {
client, err := genClient()
if err != nil {
t.Error(err)
}
t.Log(client)
}
func TestClient_Ping(t *testing.T) {
client, err := genClient()
if err != nil {
t.Error(err)
}
resp, err := Ping(client)
if err != nil {
t.Log(resp.Status)
t.Error(err)
return
}
t.Log(resp.Data, resp.Status)
}
func TestClient_StartContract(t *testing.T) {
client, err := genClient()
if err != nil {
t.Error(err)
}
resp, err := StartContract(client, "contract TestContract")
if err != nil {
t.Log(resp)
return
}
t.Log(resp)
}
func TestClient_ExecuteContract(t *testing.T) {
client, err := genClient()
if err != nil {
t.Error(err)
}
resp, err := ExecuteContract[any](client, "GlobalRouter", "listLRS", map[string]any{"offset": 0, "count": 12, "queryByCreateTime": "true", "filter": "prefixId"}, false, true)
if err != nil {
t.Log(resp)
return
}
t.Log(resp)
}
func TestClient_LoadNodeConfig(t *testing.T) {
client, err := genClient()
if err != nil {
t.Error(err)
}
config, err := LoadNodeConfig(client)
if err != nil {
t.Log(config)
t.Error(err)
return
}
t.Log(config)
}