forked from rollkit/bitcoin-da
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relayer_test.go
73 lines (69 loc) · 1.5 KB
/
relayer_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
package bitcoinda_test
import (
"encoding/hex"
"fmt"
bitcoinda "github.com/rollkit/bitcoin-da"
)
// ExampleRelayer_Write tests that writing data to the blockchain works as
// expected.
func ExampleRelayer_Write() {
// Example usage
relayer, err := bitcoinda.NewRelayer(bitcoinda.Config{
Host: "localhost:18332",
User: "rpcuser",
Pass: "rpcpass",
HTTPPostMode: true,
DisableTLS: true,
})
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Writing...")
_, err = relayer.Write([]byte("rollkit-btc: gm"))
if err != nil {
fmt.Println(err)
return
}
fmt.Println("done")
// Output: Writing...
// done
}
// ExampleRelayer_Read tests that reading data from the blockchain works as
// expected.
func ExampleRelayer_Read() {
// Example usage
relayer, err := bitcoinda.NewRelayer(bitcoinda.Config{
Host: "localhost:18332",
User: "rpcuser",
Pass: "rpcpass",
HTTPPostMode: true,
DisableTLS: true,
})
if err != nil {
fmt.Println(err)
return
}
_, err = relayer.Write([]byte("rollkit-btc: gm"))
if err != nil {
fmt.Println(err)
return
}
// TODO: either mock or generate block
// We're assuming the prev tx was mined at height 146
height := uint64(146)
blobs, err := relayer.Read(height)
if err != nil {
fmt.Println(err)
return
}
for _, blob := range blobs {
got, err := hex.DecodeString(fmt.Sprintf("%x", blob))
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(got))
}
// Output: rollkit-btc: gm
}