-
Notifications
You must be signed in to change notification settings - Fork 45
/
wallet_test.go
314 lines (281 loc) · 12.3 KB
/
wallet_test.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package goar
import (
"encoding/base64"
"os"
"github.com/everFinance/goar/types"
"github.com/everFinance/goar/utils"
"github.com/stretchr/testify/assert"
"testing"
)
var testWallet *Wallet
var err error
func init() {
clientUrl := "https://arweave.net"
testWallet, err = NewWallet([]byte(`{ "kty": "RSA",
"n":
"nQ9iy1fRM2xrgggjHhN1xZUnOkm9B4KFsJzH70v7uLMVyDqfyIJEVXeJ4Jhk_8KpjzYQ1kYfnCMjeXnhTUfY3PbeqY4PsK5nTje0uoOe1XGogeGAyKr6mVtKPhBku-aq1gz7LLRHndO2tvLRbLwX1931vNk94bSfJPYg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RwCgm-Jsh4mwojFXhmyWmGlgcbWYw6tZjder28_uE7Mxlb87kVlrbeiGAY9ax8Xe97nyq29ZUf0re47YeAINnAbELuuFAbeQDId5PUQ",
"dq":
"woDVvUZ64OAfbRNaZ_vFJHxVr6K5uppjFcYDq-h-57UMVClXMjhCxf3FIqrjnAuVAi0aSzcBXVMTT4S5pUC1iOkxoAsZdu_f0qCqRF7VojG5f8SkUxN3FuSZeSP7JESM3UGmgYUeTuIV9TnujXr92CctyST1GFv7FiRLxAYBUzdQGzPXkn9cn2GJmf0cSqVKgA2L5eGY5HxeoCes_DOh4oD_zTRjttQXzHidVbprhr43_Lx9By46hf_oCQVdf0eaaYfV9HnQW_UT_7c0FtNy8fskR2tk87ofU3Fs-MPO9PhdFonRniEiTTr0ylslk3zHahzLvjZsJG457ICWSUb8gQ",
"qi":
"ENtqTq3iiDkeiyPWD7pNRfiwIJnY5Zf97yXakxe04usHXWKmZulllttqsDkfHOXkBxRxHxqqTgOLuRpNsLrpI5MAxs8uSl13A70LUzHldnE8ePgt0688UpoI5Iw9oV2RdF_LvSrsgpa-SeexXxbZqXWpDNeUxYt2S327cS8HmrnETKy9z9VoVFmCT6_NCnxOaOTwr67dPBnGnW7nT3499m_aqmikCNjcmkfYihED6S2jZBRHPaSDM7JPPyQSEyRkGjR4z9JzhLOvbJf8tDKSE00JXJClmbpX-5qRcNt0gcJy6ceYQs-c94I24yGpunMMSwGo2i1-sGNwH1wj5-gv1Q" }`),
clientUrl)
if err != nil {
panic(err)
}
}
func TestPubKey(t *testing.T) {
pubKey := testWallet.Signer.PubKey
assert.Equal(t, "nQ9iy1fRM2xrgggjHhN1xZUnOkm9B4KFsJzH70v7uLMVyDqfyIJEVXeJ4Jhk_8KpjzYQ1kYfnCMjeXnhTUfY3PbeqY4PsK5nTje0uoOe1XGogeGAyKr6mVtKPhBku-aq1gz7LLRHndO2tvLRbLwX1931vNk94bSfJPYgMfU7OXxFXbTdKU38W6u9ShoaJGgUQI1GObd_sid1UVniCmu7P-99XPkixqyacsrkHzBajGz1S7jGmpQR669KWE9Z0unvH0KSHxAKoDD7Q7QZO7_4ujTBaIFwy_SJUxzVV8G33xvs7edmRdiqMdVK5W0LED9gbS4dv_aee9IxUJQqulSqZphPgShIiGNl9TcL5iUi9gc9cXR7ISyavos6VGiem_A-S-5f-_OKxoeZzvgAQda8sD6jtBTTuM5eLvgAbosbaSi7zFYCN7zeFdB72OfvCh72ZWSpBMH3dkdxsKCDmXUXvPdDLEnnRS87-MP5RV9Z6foq_YSEN5MFTMDdo4CpFGYl6mWTP6wUP8oM3Mpz3-_HotwSZEjASvWtiff2tc1fDHulVMYIutd52Fis_FKj6K1fzpiDYVA1W3cV4P28Q1-uF3CZ8nJEa5FXchB9lFrXB4HvsJVG6LPSt-y2R9parGi1_kEc6vOYIesKspgZ0hLyIKtqpTQFiPgKRlyUc-WEn5E", base64.RawURLEncoding.EncodeToString(pubKey.N.Bytes()))
}
func TestAddress(t *testing.T) {
addr := testWallet.Signer.Address
assert.Equal(t, "eIgnDk4vSKPe0lYB6yhCHDV1dOw3JgYHGocfj7WGrjQ", addr)
}
// test sand ar without data
func TestWallet_SendAR(t *testing.T) {
// arNode := "https://arweave.net"
// w, err := NewWalletFromPath("./example/testKey.json", arNode) // your wallet private key
// assert.NoError(t, err)
//
// target := "cSYOy8-p1QFenktkDBFyRM3cwZSTrQ_J4EsELLho_UE"
// amount := big.NewFloat(0.001)
// tags := []types.Tag{
// {Name: "GOAR", Value: "sendAR"},
// }
// tx, err := w.SendAR(amount, target, tags)
// assert.NoError(t, err)
// t.Logf("tx hash: %s \n", tx.ID)
}
// test send small size file
func TestWallet_SendDataSpeedUp01(t *testing.T) {
// arNode := "https://arweave.net"
// w, err := NewWalletFromPath("./example/testKey.json", arNode) // your wallet private key
// assert.NoError(t, err)
//
// // data := []byte("aaa this is a goar test small size file data") // small file
// data := make([]byte, 255*1024)
// for i := 0; i < len(data); i++ {
// data[i] = byte('b' + i)
// }
// tags := []types.Tag{
// {Name: "GOAR", Value: "SMDT"},
// }
// tx, err := w.SendDataSpeedUp(data, tags, 50)
// assert.NoError(t, err)
// t.Logf("tx hash: %s", tx.ID)
}
// test send big size file
func TestWallet_SendDataSpeedUp02(t *testing.T) {
// proxyUrl := "http://127.0.0.1:8001"
// arNode := "https://arweave.net"
// w, err := NewWalletFromPath("./wallet/account1.json", arNode, proxyUrl) // your wallet private key
// assert.NoError(t, err)
//
// data, err := os.ReadFile("/Users/sandyzhou/Downloads/abc.jpeg")
// if err != nil {
// panic(err)
// }
// tags := []types.Tag{
// {Name: "Sender", Value: "Jie"},
// {Name: "Data-Introduce", Value: "Happy anniversary, my google and dearest! I‘m so grateful to have you in my life. I love you to infinity and beyond! (⁎⁍̴̛ᴗ⁍̴̛⁎)"},
// }
// tx, err := w.SendDataSpeedUp(data, tags, 10)
// assert.NoError(t, err)
// t.Logf("tx hash: %s", tx.ID)
}
func Test_SendPstTransfer(t *testing.T) {
// w, err := NewWalletFromPath("./wallet/account1.json","https://arweave.net")
// assert.NoError(t, err)
//
// contractId := "usjm4PCxUd5mtaon7zc97-dt-3qf67yPyqgzLnLqk5A"
// target := "Ii5wAMlLNz13n26nYY45mcZErwZLjICmYd46GZvn4ck"
// qty := big.NewInt(1)
// arTx, err := w.SendPst(contractId,target,qty,nil,50)
// assert.NoError(t, err)
// t.Log(arTx.ID)
}
func TestWallet_WarpTransfer(t *testing.T) {
warpGateWay := "https://gateway.warp.cc"
w, err := NewWalletFromPath("./wallet/account1.json", warpGateWay)
assert.NoError(t, err)
contractId := "usjm4PCxUd5mtaon7zc97-dt-3qf67yPyqgzLnLqk5A" // vrt
target := "Ii5wAMlLNz13n26nYY45mcZErwZLjICmYd46GZvn4ck"
qty := int64(2)
id, err := w.WarpTransfer(contractId, target, qty)
assert.NoError(t, err)
t.Log(id)
}
func TestCreateUploader(t *testing.T) {
w, err := NewWalletFromPath("./wallet/account1.json", "https://arweave.net")
assert.NoError(t, err)
t.Log(w.Signer.Address)
data, err := os.ReadFile("/Users/sandyzhou/Downloads/44444.mp4")
if err != nil {
panic(err)
}
tags := []types.Tag{
{Name: "Content-Type", Value: "video/mpeg4"},
}
tx, err := w.SendData(data, tags)
assert.NoError(t, err)
t.Log(tx.ID)
}
func TestNewWallet(t *testing.T) {
cli := NewClient("https://arseed-dev.web3infra.dev")
data, err := cli.GetTransactionData("SAk5DdgYiKZTBFIxpVmiOQKsJdVbXr9qj5jTA5ACDmY")
assert.NoError(t, err)
os.WriteFile("/Users/sandyzhou/Downloads/55555.mp4", data, 0666)
// -I6guxsTtnaLazLN4HgCHtYXNXQGALcHDrpi6oz7Cbk
// 91s
// _OXH-KzWyJVZsHEJ257uMcsi1VqdvMLroxVTeAYODi4
// 408s
// 355oQfW-6XM659iG4Yy69vyAeuTC5v7c_QqGU4iRI9Q
// 48s
// _bIcfrydLSGRzwLDYvwCB16SpKAeClJdZHLRC0lgOnQ
// 24s
}
func TestTransactionUploader_ConcurrentUploadChunks(t *testing.T) {
w, err := NewWalletFromPath("./wallet/account1.json", "https://arweave.net")
assert.NoError(t, err)
t.Log(w.Signer.Address)
signer01 := w.Signer
// sig item01 by ecc signer
itemSigner01, err := NewItemSigner(signer01)
assert.NoError(t, err)
d1, err := os.ReadFile("/Users/sandyzhou/Downloads/1.jpeg")
if err != nil {
panic(err)
}
item01, err := itemSigner01.CreateAndSignItem(d1, "", "", []types.Tag{
{Name: "Content-Type", Value: "image/jpeg"},
{Name: "Owner", Value: "Vv"},
})
assert.NoError(t, err)
t.Log("item01", "id", item01.Id)
d2, err := os.ReadFile("/Users/sandyzhou/Downloads/2.jpeg")
if err != nil {
panic(err)
}
item02, err := itemSigner01.CreateAndSignItem(d2, "", "", []types.Tag{
{Name: "Content-Type", Value: "image/jpeg"},
{Name: "Owner", Value: "Vv"},
})
assert.NoError(t, err)
t.Log("item02", "id", item02.Id)
d3, err := os.ReadFile("/Users/sandyzhou/Downloads/3.jpeg")
if err != nil {
panic(err)
}
item03, err := itemSigner01.CreateAndSignItem(d3, "", "", []types.Tag{
{Name: "Content-Type", Value: "image/jpeg"},
{Name: "Owner", Value: "Vv"},
})
assert.NoError(t, err)
t.Log("item03", "id", item03.Id)
d4, err := os.ReadFile("/Users/sandyzhou/Downloads/4.jpeg")
if err != nil {
panic(err)
}
item04, err := itemSigner01.CreateAndSignItem(d4, "", "", []types.Tag{
{Name: "Content-Type", Value: "image/jpeg"},
{Name: "Owner", Value: "Vv"},
})
assert.NoError(t, err)
d5, err := os.ReadFile("/Users/sandyzhou/Downloads/5.jpeg")
if err != nil {
panic(err)
}
item05, err := itemSigner01.CreateAndSignItem(d5, "", "", []types.Tag{
{Name: "Content-Type", Value: "image/jpeg"},
{Name: "Owner", Value: "Vv"},
})
assert.NoError(t, err)
t.Log("item05", "id", item05.Id)
d6, err := os.ReadFile("/Users/sandyzhou/Downloads/6.jpeg")
if err != nil {
panic(err)
}
item06, err := itemSigner01.CreateAndSignItem(d6, "", "", []types.Tag{
{Name: "Content-Type", Value: "image/jpeg"},
{Name: "Owner", Value: "Vv"},
})
assert.NoError(t, err)
t.Log("item06", "id", item06.Id)
d7, err := os.ReadFile("/Users/sandyzhou/Downloads/7.jpeg")
if err != nil {
panic(err)
}
item07, err := itemSigner01.CreateAndSignItem(d7, "", "", []types.Tag{
{Name: "Content-Type", Value: "image/jpeg"},
{Name: "Owner", Value: "Vv"},
})
assert.NoError(t, err)
t.Log("item07", "id", item07.Id)
d8, err := os.ReadFile("/Users/sandyzhou/Downloads/8.jpeg")
if err != nil {
panic(err)
}
item08, err := itemSigner01.CreateAndSignItem(d8, "", "", []types.Tag{
{Name: "Content-Type", Value: "image/jpeg"},
{Name: "Owner", Value: "Vv"},
})
assert.NoError(t, err)
t.Log("item08", "id", item08.Id)
d9, err := os.ReadFile("/Users/sandyzhou/Downloads/9.jpeg")
if err != nil {
panic(err)
}
item09, err := itemSigner01.CreateAndSignItem(d9, "", "", []types.Tag{
{Name: "Content-Type", Value: "image/jpeg"},
{Name: "Owner", Value: "Vv"},
})
assert.NoError(t, err)
t.Log("item09", "id", item09.Id)
d10, err := os.ReadFile("/Users/sandyzhou/Downloads/10.jpeg")
if err != nil {
panic(err)
}
item10, err := itemSigner01.CreateAndSignItem(d10, "", "", []types.Tag{
{Name: "Content-Type", Value: "image/jpeg"},
{Name: "Owner", Value: "Vv"},
})
assert.NoError(t, err)
t.Log("item10", "id", item10.Id)
d11, err := os.ReadFile("/Users/sandyzhou/Downloads/11.jpeg")
if err != nil {
panic(err)
}
item11, err := itemSigner01.CreateAndSignItem(d11, "", "", []types.Tag{
{Name: "Content-Type", Value: "image/jpeg"},
{Name: "Owner", Value: "Vv"},
})
assert.NoError(t, err)
t.Log("item11", "id", item11.Id)
// assemble bundle
bundle, err := utils.NewBundle(item01, item02, item03, item04, item05, item06, item07, item08, item09, item10, item11)
assert.NoError(t, err)
t.Log(len(bundle.BundleBinary))
// send to arweave
// ctx ,cancel := context.WithTimeout(context.Background(),100*time.Millisecond)
// defer cancel()
// tx, err := w.SendBundleTx(ctx, 0,bundle.BundleBinary, []types.Tag{
// {Name: "APP", Value: "Goar"},
// {Name: "Protocol-Name", Value: "BAR"},
// {Name: "Action", Value: "Burn"},
// {Name: "App-Name", Value: "SmartWeaveAction"},
// {Name: "App-Version", Value: "0.3.0"},
// {Name: "Input", Value: `{"function":"mint"}`},
// {Name: "Contract", Value: "VFr3Bk-uM-motpNNkkFg4lNW1BMmSfzqsVO551Ho4hA"},
// })
// assert.NoError(t, err)
// t.Log(tx.ID)
}