bdcontract-client/client/client_test.go
zhaoweijie a98d707e48 ref(clientactor): 优化 ExecuteContract 函数参数类型
- 将 ExecuteContract 函数的 arg 参数类型从 string 改为 any
- 增加对 arg 参数的类型判断和处理,支持字符串和其他类型的数据
- 修改签名逻辑,确保兼容新的 arg 参数类型
- 更新单元测试,演示新的 ExecuteContract 调用方式
2025-03-08 11:43:49 +08:00

114 lines
1.9 KiB
Go

package client
import (
"testing"
"go.fusiongalaxy.cn/bdware/bdcontract-client/sm2util"
)
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://127.0.0.1:21030/SCIDE"
pub, err := sm2util.ParsePublicKey("04180354fdb6507f8ab98ccfbe165ce11da74ba733f81af86ad6d32216b32cf4f797c559d50ceeefbf4c760c3483840471c67471b90acdffb388cd7d496d9a1610")
if err != nil {
return nil, err
}
priv, err := sm2util.ParsePrivateKey("1d4196947f59532db6f8f4055e58474a48db8f30b476ae3edc66406464521b3b", pub)
if err != nil {
return nil, err
}
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 := client.Ping()
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 := client.StartContract("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 := client.ExecuteContract("GlobalRouter", "listID", 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 := client.LoadNodeConfig()
if err != nil {
t.Log(config)
t.Error(err)
return
}
t.Log(config)
}