Skip to content

Commit 47032a5

Browse files
committed
create better tests
1 parent 7e7f4e0 commit 47032a5

File tree

1 file changed

+97
-30
lines changed

1 file changed

+97
-30
lines changed

tlb/stack_test.go

Lines changed: 97 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,38 +75,93 @@ func Test_StackUnmarshal(t *testing.T) {
7575

7676
}
7777

78-
func Test_IntTupleUnmarshal(t *testing.T) {
78+
func Test_IntMatrixTupleUnmarshal(t *testing.T) {
7979
type test struct {
80-
name string
81-
hex string
82-
intsResult []int64
80+
name string
81+
hex string
82+
intsResultMatrix [][]int64
8383
}
8484

8585
tests := []test{
8686
{
87-
name: "tuple with 0 items",
88-
hex: "b5ee9c7201010201000b00010c000001070000010000",
89-
intsResult: []int64{},
87+
name: "tuple 0x0",
88+
hex: "b5ee9c7201010301001100020c000001070001010200000006070000",
89+
intsResultMatrix: [][]int64{{}},
9090
},
9191
{
92-
name: "tuple with 1 item",
93-
hex: "b5ee9c7201010301001700020c000001070001010200000012010000000000000003",
94-
intsResult: []int64{3},
92+
name: "tuple 0x1",
93+
hex: "b5ee9c7201010401001d00020c000001070001010200000106070001030012010000000000000001",
94+
intsResultMatrix: [][]int64{{1}},
9595
},
9696
{
97-
name: "tuple with 2 items",
98-
hex: "b5ee9c7201010401002300030c000001070002010203000000120100000000000000030012010000000000000004",
99-
intsResult: []int64{3, 4},
97+
name: "tuple 0x2",
98+
hex: "b5ee9c7201010501002900020c000001070001010200000206070002030400120100000000000000010012010000000000000002",
99+
intsResultMatrix: [][]int64{{1, 2}},
100100
},
101101
{
102-
name: "tuple with 3 items",
103-
hex: "b5ee9c7201010601003200030c000001070003010203000002000405001201000000000000000500120100000000000000030012010000000000000004",
104-
intsResult: []int64{3, 4, 5},
102+
name: "tuple 0x3",
103+
hex: "b5ee9c7201010701003800020c000001070001010200000206070003030402000506001201000000000000000300120100000000000000010012010000000000000002",
104+
intsResultMatrix: [][]int64{{1, 2, 3}},
105105
},
106106
{
107-
name: "tuple with 4 items",
108-
hex: "b5ee9c7201010801004100030c000001070004010203000002000405001201000000000000000602000607001201000000000000000500120100000000000000030012010000000000000004",
109-
intsResult: []int64{3, 4, 5, 6},
107+
name: "tuple 1x0",
108+
hex: "b5ee9c7201010301001200030c00000107000201020200000006070000",
109+
intsResultMatrix: [][]int64{{}, {}},
110+
},
111+
{
112+
name: "tuple 1x1",
113+
hex: "b5ee9c7201010601002f00030c000001070002010203000001060700010401060700010500120100000000000000010012010000000000000002",
114+
intsResultMatrix: [][]int64{{1}, {2}},
115+
},
116+
{
117+
name: "tuple 1x2",
118+
hex: "b5ee9c7201010801004700030c000001070002010203000002060700020405020607000206070012010000000000000001001201000000000000000200120100000000000000030012010000000000000004",
119+
intsResultMatrix: [][]int64{{1, 2}, {3, 4}},
120+
},
121+
{
122+
name: "tuple 1x3",
123+
hex: "b5ee9c7201010c01006500030c0000010700020102030000020607000304050206070003060702000809001201000000000000000302000a0b00120100000000000000060012010000000000000001001201000000000000000200120100000000000000040012010000000000000005",
124+
intsResultMatrix: [][]int64{{1, 2, 3}, {4, 5, 6}},
125+
},
126+
{
127+
name: "tuple 2x0",
128+
hex: "b5ee9c7201010401001600030c0000010700030102030000020003030006070000",
129+
intsResultMatrix: [][]int64{{}, {}, {}},
130+
},
131+
{
132+
name: "tuple 2x1",
133+
hex: "b5ee9c7201010901004400030c000001070003010203000002000405010607000106010607000107010607000108001201000000000000000300120100000000000000010012010000000000000002",
134+
intsResultMatrix: [][]int64{{1}, {2}, {3}},
135+
},
136+
{
137+
name: "tuple 2x2",
138+
hex: "b5ee9c7201010c01006800030c000001070003010203000002000405020607000206070206070002080902060700020a0b001201000000000000000500120100000000000000060012010000000000000001001201000000000000000200120100000000000000030012010000000000000004",
139+
intsResultMatrix: [][]int64{{1, 2}, {3, 4}, {5, 6}},
140+
},
141+
{
142+
name: "tuple 2x3",
143+
hex: "b5ee9c7201011201009500030c000001070003010203000002000405020607000306070206070003080902060700030a0b02000c0d001201000000000000000902000e0f0012010000000000000003020010110012010000000000000006001201000000000000000700120100000000000000080012010000000000000001001201000000000000000200120100000000000000040012010000000000000005",
144+
intsResultMatrix: [][]int64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}},
145+
},
146+
{
147+
name: "tuple 3x0",
148+
hex: "b5ee9c7201010501001a00030c000001070004010204000002000304020004040006070000",
149+
intsResultMatrix: [][]int64{{}, {}, {}, {}},
150+
},
151+
{
152+
name: "tuple 3x1",
153+
hex: "b5ee9c7201010c01005900030c00000107000401020300000200040501060700010602000708010607000109001201000000000000000401060700010a01060700010b001201000000000000000300120100000000000000010012010000000000000002",
154+
intsResultMatrix: [][]int64{{1}, {2}, {3}, {4}},
155+
},
156+
{
157+
name: "tuple 3x2",
158+
hex: "b5ee9c7201011001008900030c000001070004010203000002000405020607000206070200080902060700020a0b0012010000000000000007001201000000000000000802060700020c0d02060700020e0f001201000000000000000500120100000000000000060012010000000000000001001201000000000000000200120100000000000000030012010000000000000004",
159+
intsResultMatrix: [][]int64{{1, 2}, {3, 4}, {5, 6}, {7, 8}},
160+
},
161+
{
162+
name: "tuple 3x3",
163+
hex: "b5ee9c720101180100c500030c000001070004010203000002000405020607000306070200080902060700030a0b02000c0d001201000000000000000c02060700030e0f02060700031011020012130012010000000000000009001201000000000000000a001201000000000000000b020014150012010000000000000003020016170012010000000000000006001201000000000000000700120100000000000000080012010000000000000001001201000000000000000200120100000000000000040012010000000000000005",
164+
intsResultMatrix: [][]int64{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}},
110165
},
111166
}
112167
for _, tt := range tests {
@@ -122,25 +177,37 @@ func Test_IntTupleUnmarshal(t *testing.T) {
122177
}
123178
val := stack[0]
124179
if val.SumType != "VmStkTuple" {
125-
t.Fatalf("Stack value must be tuple, got %v", val.SumType)
180+
t.Errorf("Stack value must be tuple, got %v", val.SumType)
126181
}
127182
tuple := val.VmStkTuple
128-
if int(tuple.Len) != len(tt.intsResult) {
129-
t.Fatalf("want %v tuple len, got %v", len(tt.intsResult), tuple.Len)
130-
}
131-
if tuple.Data == nil { // for test case with 0 values in a tuple
132-
return
183+
if int(tuple.Len) != len(tt.intsResultMatrix) {
184+
t.Errorf("want %v tuple len, got %v", len(tt.intsResultMatrix), tuple.Len)
133185
}
134-
values, err := tuple.Data.RecursiveToSlice(len(tt.intsResult))
186+
values, err := tuple.Data.RecursiveToSlice(len(tt.intsResultMatrix))
135187
if err != nil {
136188
t.Fatal(err)
137189
}
138190
for i, v := range values {
139-
if v.SumType != "VmStkTinyInt" {
140-
t.Fatalf("want values[%v] to be VmStkTinyInt, got %v", i, v.SumType)
191+
if v.SumType != "VmStkTuple" {
192+
t.Errorf("want values[%v] to be VmStkTuple, got %v", i, v.SumType)
193+
}
194+
if int(v.VmStkTuple.Len) != len(tt.intsResultMatrix[i]) {
195+
t.Errorf("want %v tuple[%v] len, got %v", len(tt.intsResultMatrix[i]), i, v.VmStkTuple.Len)
196+
}
197+
if v.VmStkTuple.Data == nil { // for test case with 0 values in a tuple
198+
return
199+
}
200+
innerValues, err := v.VmStkTuple.Data.RecursiveToSlice(len(tt.intsResultMatrix[i]))
201+
if err != nil {
202+
t.Fatal(err)
141203
}
142-
if v.VmStkTinyInt != tt.intsResult[i] {
143-
t.Fatalf("want values[%v] == %v, got %v", i, tt.intsResult[i], v.VmStkTinyInt)
204+
for j, iV := range innerValues {
205+
if iV.SumType != "VmStkTinyInt" {
206+
t.Errorf("want values[%v][%v] to be VmStkTinyInt, got %v", i, j, iV.SumType)
207+
}
208+
if iV.VmStkTinyInt != tt.intsResultMatrix[i][j] {
209+
t.Errorf("want values[%v][%v] == %v, got %v", i, j, tt.intsResultMatrix[i][j], iV.VmStkTinyInt)
210+
}
144211
}
145212
}
146213
})

0 commit comments

Comments
 (0)