-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathblock_test.go
97 lines (93 loc) · 2.32 KB
/
block_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
package ton
import (
"os"
"reflect"
"testing"
"github.com/tonkeeper/tongo/boc"
"github.com/tonkeeper/tongo/tlb"
)
func TestBlockInfo_GetParents(t *testing.T) {
tests := []struct {
name string
want []BlockIDExt
filename string
wantErr bool
}{
{
filename: "testdata/raw-13516764.bin",
want: []BlockIDExt{
{
BlockID: BlockID{
Workchain: 0,
Shard: 0xa000000000000000, // a000000000000000
Seqno: 13516763},
RootHash: MustParseHash("617f643f15a42f28018e3e3c89f14b952a0d67fa90968ae5360a51b96c6a1c42"),
FileHash: MustParseHash("563aa5f3d51585b95c0c89bf6c4e39455f4c121269521c1c5b6dc07f03c5d230"),
},
{
BlockID: BlockID{
Workchain: 0,
Shard: 0xe000000000000000, // e000000000000000
Seqno: 13516699,
},
RootHash: MustParseHash("032b1bf3016c9b71816c52f207c4cd79d75541f78eacb11cac2ea7b77d2a603d"),
FileHash: MustParseHash("8dcab64721513f3db73a081dd61cdf51d7fec79347ab348d43ffb8bc052a8db3"),
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rawData, err := os.ReadFile(tt.filename)
if err != nil {
t.Errorf("ReadFile() failed: %v", err)
}
cell, err := boc.DeserializeBoc(rawData)
if err != nil {
t.Errorf("DeserializeBoc() failed: %v", err)
}
var data tlb.Block
if err = tlb.Unmarshal(cell[0], &data); err != nil {
t.Errorf("Unmarshal() failed: %v", err)
}
got, err := GetParents(data.Info)
if (err != nil) != tt.wantErr {
t.Errorf("GetParents() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetParents() got = %#v, want %v", got, tt.want)
}
})
}
}
func TestParseBlockID(t *testing.T) {
tests := []struct {
name string
s string
want BlockID
wantErr bool
}{
{
name: "all good",
s: "(-1,8000000000000000,29537038)",
want: BlockID{
Workchain: -1,
Shard: 0x8000000000000000,
Seqno: 29537038,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ParseBlockID(tt.s)
if (err != nil) != tt.wantErr {
t.Errorf("ParseBlockID() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseBlockID() got = %v, want %v", got, tt.want)
}
})
}
}