/
dao_example.go
116 lines (84 loc) · 2.78 KB
/
dao_example.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
package test
import (
"context"
"encoding/json"
"fmt"
"github.com/nervosnetwork/ckb-sdk-go/mercury/example/constant"
"github.com/nervosnetwork/ckb-sdk-go/mercury/example/utils"
"github.com/nervosnetwork/ckb-sdk-go/mercury/model"
"github.com/nervosnetwork/ckb-sdk-go/mercury/model/req"
"github.com/nervosnetwork/ckb-sdk-go/mercury/model/source"
"github.com/nervosnetwork/ckb-sdk-go/utils/amount"
"testing"
)
func TestDaoDepositWithAddress(t *testing.T) {
builder := model.NewDaoDepositPayloadBuilder()
item, _ := req.NewAddressItem(constant.TEST_ADDRESS3)
builder.AddFrom(source.Free, item)
builder.AddAmount(amount.CkbToShannon(300).Uint64())
transaction, err := constant.GetMercuryApiInstance().BuildDaoDepositTransaction(builder.Build())
marshal, _ := json.Marshal(builder.Build())
fmt.Println(string(marshal))
if err != nil {
t.Error(err)
}
tx := utils.Sign(transaction)
hash, err := constant.GetMercuryApiInstance().SendTransaction(context.Background(), tx)
if err != nil {
t.Error(err)
}
fmt.Println(hash)
}
func TestDaoDepositWithIdentity(t *testing.T) {
builder := model.NewDaoDepositPayloadBuilder()
item, _ := req.NewIdentityItemByCkb(constant.TEST_PUBKEY3)
builder.AddFrom(source.Free, item)
builder.AddAmount(amount.CkbToShannon(300).Uint64())
transaction, err := constant.GetMercuryApiInstance().BuildDaoDepositTransaction(builder.Build())
marshal, _ := json.Marshal(builder.Build())
fmt.Println(string(marshal))
if err != nil {
t.Error(err)
}
tx := utils.Sign(transaction)
hash, err := constant.GetMercuryApiInstance().SendTransaction(context.Background(), tx)
if err != nil {
t.Error(err)
}
fmt.Println(hash)
}
func TestDaoWithdraw(t *testing.T) {
builder := model.NewDaoWithdrawPayloadBuilder()
item, _ := req.NewIdentityItemByCkb(constant.TEST_PUBKEY3)
builder.AddItem(item)
builder.AddPayFee(constant.TEST_ADDRESS1)
transaction, err := constant.GetMercuryApiInstance().BuildDaoWithdrawTransaction(builder.Build())
marshal, _ := json.Marshal(builder.Build())
fmt.Println(string(marshal))
if err != nil {
t.Error(err)
}
tx := utils.Sign(transaction)
hash, err := constant.GetMercuryApiInstance().SendTransaction(context.Background(), tx)
if err != nil {
t.Error(err)
}
fmt.Println(hash)
}
func TestDaoClaim(t *testing.T) {
builder := model.NewDaoClaimPayloadBuilder()
item, _ := req.NewIdentityItemByCkb(constant.TEST_PUBKEY3)
builder.AddItem(item)
transaction, err := constant.GetMercuryApiInstance().BuildDaoClaimTransaction(builder.Build())
marshal, _ := json.Marshal(builder.Build())
fmt.Println(string(marshal))
if err != nil {
t.Error(err)
}
tx := utils.Sign(transaction)
hash, err := constant.GetMercuryApiInstance().SendTransaction(context.Background(), tx)
if err != nil {
t.Error(err)
}
fmt.Println(hash)
}