OSDN Git Service

Feat(BVM): delete op abs and negate (#1900)
[bytom/bytom.git] / protocol / vm / numeric_test.go
1 package vm
2
3 import (
4         "fmt"
5         "math"
6         "math/big"
7         "testing"
8
9         "github.com/bytom/bytom/common"
10         "github.com/bytom/bytom/protocol/vm/mocks"
11         "github.com/bytom/bytom/testutil"
12 )
13
14 func TestNumericOps(t *testing.T) {
15         type testStruct struct {
16                 op      Op
17                 startVM *virtualMachine
18                 wantErr error
19                 wantVM  *virtualMachine
20         }
21         cases := []testStruct{{
22                 op: OP_1ADD,
23                 startVM: &virtualMachine{
24                         runLimit:  50000,
25                         dataStack: [][]byte{{0x02}},
26                 },
27                 wantVM: &virtualMachine{
28                         runLimit:  49998,
29                         dataStack: [][]byte{{0x03}},
30                 },
31         }, {
32                 op: OP_1SUB,
33                 startVM: &virtualMachine{
34                         runLimit:  50000,
35                         dataStack: [][]byte{{2}},
36                 },
37                 wantVM: &virtualMachine{
38                         runLimit:  49998,
39                         dataStack: [][]byte{{1}},
40                 },
41         }, {
42                 op: OP_1SUB,
43                 startVM: &virtualMachine{
44                         runLimit:  50000,
45                         dataStack: [][]byte{{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
46                 },
47                 wantVM: &virtualMachine{
48                         runLimit:     49998,
49                         deferredCost: -1,
50                         dataStack:    [][]byte{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
51                 },
52         }, {
53                 op: OP_2MUL,
54                 startVM: &virtualMachine{
55                         runLimit:  50000,
56                         dataStack: [][]byte{{2}},
57                 },
58                 wantVM: &virtualMachine{
59                         runLimit:  49998,
60                         dataStack: [][]byte{{4}},
61                 },
62         }, {
63                 op: OP_2MUL,
64                 startVM: &virtualMachine{
65                         runLimit:  50000,
66                         dataStack: [][]byte{{0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
67                 },
68                 wantVM: &virtualMachine{
69                         runLimit:  49998,
70                         dataStack: [][]byte{{0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe}},
71                 },
72         }, {
73                 op: OP_2MUL,
74                 startVM: &virtualMachine{
75                         runLimit:  50000,
76                         dataStack: [][]byte{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
77                 },
78                 wantVM: &virtualMachine{
79                         runLimit:     49998,
80                         deferredCost: 1,
81                         dataStack:    [][]byte{{0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe}},
82                 },
83         }, {
84                 op: OP_2DIV,
85                 startVM: &virtualMachine{
86                         runLimit:  50000,
87                         dataStack: [][]byte{{2}},
88                 },
89                 wantVM: &virtualMachine{
90                         runLimit:  49998,
91                         dataStack: [][]byte{{1}},
92                 },
93         }, {
94                 op: OP_NOT,
95                 startVM: &virtualMachine{
96                         runLimit:  50000,
97                         dataStack: [][]byte{{2}},
98                 },
99                 wantVM: &virtualMachine{
100                         runLimit:     49998,
101                         deferredCost: -1,
102                         dataStack:    [][]byte{{}},
103                 },
104         }, {
105                 op: OP_0NOTEQUAL,
106                 startVM: &virtualMachine{
107                         runLimit:  50000,
108                         dataStack: [][]byte{{2}},
109                 },
110                 wantVM: &virtualMachine{
111                         runLimit:  49998,
112                         dataStack: [][]byte{{1}},
113                 },
114         }, {
115                 op: OP_ADD,
116                 startVM: &virtualMachine{
117                         runLimit:  50000,
118                         dataStack: [][]byte{{2}, {1}},
119                 },
120                 wantVM: &virtualMachine{
121                         runLimit:     49998,
122                         deferredCost: -9,
123                         dataStack:    [][]byte{{3}},
124                 },
125         }, {
126                 op: OP_SUB,
127                 startVM: &virtualMachine{
128                         runLimit:  50000,
129                         dataStack: [][]byte{{2}, {1}},
130                 },
131                 wantVM: &virtualMachine{
132                         runLimit:     49998,
133                         deferredCost: -9,
134                         dataStack:    [][]byte{{1}},
135                 },
136         }, {
137                 op: OP_MUL,
138                 startVM: &virtualMachine{
139                         runLimit:  50000,
140                         dataStack: [][]byte{{2}, {1}},
141                 },
142                 wantVM: &virtualMachine{
143                         runLimit:     49992,
144                         deferredCost: -9,
145                         dataStack:    [][]byte{{2}},
146                 },
147         }, {
148                 op: OP_DIV,
149                 startVM: &virtualMachine{
150                         runLimit:  50000,
151                         dataStack: [][]byte{{2}, {1}},
152                 },
153                 wantVM: &virtualMachine{
154                         runLimit:     49992,
155                         deferredCost: -9,
156                         dataStack:    [][]byte{{2}},
157                 },
158         }, {
159                 op: OP_DIV,
160                 startVM: &virtualMachine{
161                         runLimit:  50000,
162                         dataStack: [][]byte{{2}, {}},
163                 },
164                 wantErr: ErrDivZero,
165         }, {
166                 op: OP_MOD,
167                 startVM: &virtualMachine{
168                         runLimit:  50000,
169                         dataStack: [][]byte{{2}, {1}},
170                 },
171                 wantVM: &virtualMachine{
172                         runLimit:     49992,
173                         deferredCost: -10,
174                         dataStack:    [][]byte{{}},
175                 },
176         }, {
177                 op: OP_MOD,
178                 startVM: &virtualMachine{
179                         runLimit:  50000,
180                         dataStack: [][]byte{{2}, {0}},
181                 },
182                 wantErr: ErrDivZero,
183         }, {
184                 op: OP_LSHIFT,
185                 startVM: &virtualMachine{
186                         runLimit:  50000,
187                         dataStack: [][]byte{{2}, {1}},
188                 },
189                 wantVM: &virtualMachine{
190                         runLimit:     49992,
191                         deferredCost: -9,
192                         dataStack:    [][]byte{{4}},
193                 },
194         }, {
195                 op: OP_RSHIFT,
196                 startVM: &virtualMachine{
197                         runLimit:  50000,
198                         dataStack: [][]byte{{2}, {1}},
199                 },
200                 wantVM: &virtualMachine{
201                         runLimit:     49992,
202                         deferredCost: -9,
203                         dataStack:    [][]byte{{1}},
204                 },
205         }, {
206                 op: OP_BOOLAND,
207                 startVM: &virtualMachine{
208                         runLimit:  50000,
209                         dataStack: [][]byte{{2}, {1}},
210                 },
211                 wantVM: &virtualMachine{
212                         runLimit:     49998,
213                         deferredCost: -9,
214                         dataStack:    [][]byte{{1}},
215                 },
216         }, {
217                 op: OP_BOOLOR,
218                 startVM: &virtualMachine{
219                         runLimit:  50000,
220                         dataStack: [][]byte{{2}, {1}},
221                 },
222                 wantVM: &virtualMachine{
223                         runLimit:     49998,
224                         deferredCost: -9,
225                         dataStack:    [][]byte{{1}},
226                 },
227         }, {
228                 op: OP_NUMEQUAL,
229                 startVM: &virtualMachine{
230                         runLimit:  50000,
231                         dataStack: [][]byte{{2}, {1}},
232                 },
233                 wantVM: &virtualMachine{
234                         runLimit:     49998,
235                         deferredCost: -10,
236                         dataStack:    [][]byte{{}},
237                 },
238         }, {
239                 op: OP_NUMEQUALVERIFY,
240                 startVM: &virtualMachine{
241                         runLimit:  50000,
242                         dataStack: [][]byte{{2}, {2}},
243                 },
244                 wantVM: &virtualMachine{
245                         runLimit:     49998,
246                         deferredCost: -18,
247                         dataStack:    [][]byte{},
248                 },
249         }, {
250                 op: OP_NUMEQUALVERIFY,
251                 startVM: &virtualMachine{
252                         runLimit:  50000,
253                         dataStack: [][]byte{{1}, {2}},
254                 },
255                 wantErr: ErrVerifyFailed,
256         }, {
257                 op: OP_NUMNOTEQUAL,
258                 startVM: &virtualMachine{
259                         runLimit:  50000,
260                         dataStack: [][]byte{{2}, {1}},
261                 },
262                 wantVM: &virtualMachine{
263                         runLimit:     49998,
264                         deferredCost: -9,
265                         dataStack:    [][]byte{{1}},
266                 },
267         }, {
268                 op: OP_LESSTHAN,
269                 startVM: &virtualMachine{
270                         runLimit:  50000,
271                         dataStack: [][]byte{{2}, {1}},
272                 },
273                 wantVM: &virtualMachine{
274                         runLimit:     49998,
275                         deferredCost: -10,
276                         dataStack:    [][]byte{{}},
277                 },
278         }, {
279                 op: OP_LESSTHANOREQUAL,
280                 startVM: &virtualMachine{
281                         runLimit:  50000,
282                         dataStack: [][]byte{{2}, {1}},
283                 },
284                 wantVM: &virtualMachine{
285                         runLimit:     49998,
286                         deferredCost: -10,
287                         dataStack:    [][]byte{{}},
288                 },
289         }, {
290                 op: OP_GREATERTHAN,
291                 startVM: &virtualMachine{
292                         runLimit:  50000,
293                         dataStack: [][]byte{{2}, {1}},
294                 },
295                 wantVM: &virtualMachine{
296                         runLimit:     49998,
297                         deferredCost: -9,
298                         dataStack:    [][]byte{{1}},
299                 },
300         }, {
301                 op: OP_GREATERTHANOREQUAL,
302                 startVM: &virtualMachine{
303                         runLimit:  50000,
304                         dataStack: [][]byte{{2}, {1}},
305                 },
306                 wantVM: &virtualMachine{
307                         runLimit:     49998,
308                         deferredCost: -9,
309                         dataStack:    [][]byte{{1}},
310                 },
311         }, {
312                 op: OP_MIN,
313                 startVM: &virtualMachine{
314                         runLimit:  50000,
315                         dataStack: [][]byte{{2}, {1}},
316                 },
317                 wantVM: &virtualMachine{
318                         runLimit:     49998,
319                         deferredCost: -9,
320                         dataStack:    [][]byte{{1}},
321                 },
322         }, {
323                 op: OP_MIN,
324                 startVM: &virtualMachine{
325                         runLimit:  50000,
326                         dataStack: [][]byte{{1}, {2}},
327                 },
328                 wantVM: &virtualMachine{
329                         runLimit:     49998,
330                         deferredCost: -9,
331                         dataStack:    [][]byte{{1}},
332                 },
333         }, {
334                 op: OP_MAX,
335                 startVM: &virtualMachine{
336                         runLimit:  50000,
337                         dataStack: [][]byte{{2}, {1}},
338                 },
339                 wantVM: &virtualMachine{
340                         runLimit:     49998,
341                         deferredCost: -9,
342                         dataStack:    [][]byte{{2}},
343                 },
344         }, {
345                 op: OP_MAX,
346                 startVM: &virtualMachine{
347                         runLimit:  50000,
348                         dataStack: [][]byte{{1}, {2}},
349                 },
350                 wantVM: &virtualMachine{
351                         runLimit:     49998,
352                         deferredCost: -9,
353                         dataStack:    [][]byte{{2}},
354                 },
355         }, {
356                 op: OP_WITHIN,
357                 startVM: &virtualMachine{
358                         runLimit:  50000,
359                         dataStack: [][]byte{{1}, {1}, {2}},
360                 },
361                 wantVM: &virtualMachine{
362                         runLimit:     49996,
363                         deferredCost: -18,
364                         dataStack:    [][]byte{{1}},
365                 },
366         }}
367
368         numops := []Op{
369                 OP_1ADD, OP_1SUB, OP_2MUL, OP_2DIV, OP_NOT, OP_0NOTEQUAL,
370                 OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_LSHIFT, OP_RSHIFT, OP_BOOLAND,
371                 OP_BOOLOR, OP_NUMEQUAL, OP_NUMEQUALVERIFY, OP_NUMNOTEQUAL, OP_LESSTHAN,
372                 OP_LESSTHANOREQUAL, OP_GREATERTHAN, OP_GREATERTHANOREQUAL, OP_MIN, OP_MAX, OP_WITHIN,
373         }
374
375         for _, op := range numops {
376                 cases = append(cases, testStruct{
377                         op: op,
378                         startVM: &virtualMachine{
379                                 runLimit:  0,
380                                 dataStack: [][]byte{{2}, {2}, {2}},
381                         },
382                         wantErr: ErrRunLimitExceeded,
383                 })
384         }
385
386         for i, c := range cases {
387                 err := ops[c.op].fn(c.startVM)
388
389                 if err != c.wantErr {
390                         t.Errorf("case %d, op %s: got err = %v want %v", i, ops[c.op].name, err, c.wantErr)
391                         continue
392                 }
393                 if c.wantErr != nil {
394                         continue
395                 }
396
397                 if !testutil.DeepEqual(c.startVM, c.wantVM) {
398                         t.Errorf("case %d, op %s: unexpected vm result\n\tgot:  %+v\n\twant: %+v\n", i, ops[c.op].name, c.startVM, c.wantVM)
399                 }
400         }
401 }
402
403 func TestRangeErrs(t *testing.T) {
404         cases := []struct {
405                 prog           string
406                 expectRangeErr bool
407         }{
408                 {"0 1ADD", false},
409                 {fmt.Sprintf("%d 1ADD", int64(math.MinInt64)), true},
410                 {fmt.Sprintf("%d 1ADD", int64(math.MaxInt64)-1), false},
411                 {fmt.Sprintf("%s 1ADD", big.NewInt(0).SetBytes(common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")).String()), true},
412                 {fmt.Sprintf("%s 1ADD", big.NewInt(0).SetBytes(common.Hex2Bytes("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")).String()), true},
413         }
414
415         for i, c := range cases {
416                 prog, _ := Assemble(c.prog)
417                 vm := &virtualMachine{
418                         program:  prog,
419                         runLimit: 50000,
420                 }
421                 err := vm.run()
422                 switch err {
423                 case nil:
424                         if c.expectRangeErr {
425                                 t.Errorf("case %d (%s): expected range error, got none", i, c.prog)
426                         }
427                 case ErrRange:
428                         if !c.expectRangeErr {
429                                 t.Errorf("case %d (%s): got unexpected range error", i, c.prog)
430                         }
431                 default:
432                         if c.expectRangeErr {
433                                 t.Errorf("case %d (%s): expected range error, got %s", i, c.prog, err)
434                         } else {
435                                 t.Errorf("case %d (%s): got unexpected error %s", i, c.prog, err)
436                         }
437                 }
438         }
439 }
440
441 func TestNumCompare(t *testing.T) {
442         type args struct {
443                 vm *virtualMachine
444                 op int
445         }
446         tests := []struct {
447                 name    string
448                 args    args
449                 want    [][]byte
450                 wantErr bool
451         }{
452                 {
453                         name: "test 2 > 1 for cmpLess",
454                         args: args{
455                                 vm: &virtualMachine{
456                                         dataStack: [][]byte{{0x02}, {0x01}},
457                                         runLimit:  50000,
458                                 },
459                                 op: cmpLess,
460                         },
461                         want:    [][]byte{{}},
462                         wantErr: false,
463                 },
464                 {
465                         name: "test 2 > 1 for cmpLessEqual",
466                         args: args{
467                                 vm: &virtualMachine{
468                                         dataStack: [][]byte{{0x02}, {0x01}},
469                                         runLimit:  50000,
470                                 },
471                                 op: cmpLessEqual,
472                         },
473                         want:    [][]byte{{}},
474                         wantErr: false,
475                 },
476                 {
477                         name: "test 2 > 1 for cmpGreater",
478                         args: args{
479                                 vm: &virtualMachine{
480                                         dataStack: [][]byte{{0x02}, {0x01}},
481                                         runLimit:  50000,
482                                 },
483                                 op: cmpGreater,
484                         },
485                         want:    [][]byte{{1}},
486                         wantErr: false,
487                 },
488                 {
489                         name: "test 2 > 1 for cmpGreaterEqual",
490                         args: args{
491                                 vm: &virtualMachine{
492                                         dataStack: [][]byte{{0x02}, {0x01}},
493                                         runLimit:  50000,
494                                 },
495                                 op: cmpGreaterEqual,
496                         },
497                         want:    [][]byte{{1}},
498                         wantErr: false,
499                 },
500                 {
501                         name: "test 2 > 1 for cmpEqual",
502                         args: args{
503                                 vm: &virtualMachine{
504                                         dataStack: [][]byte{{0x02}, {0x01}},
505                                         runLimit:  50000,
506                                 },
507                                 op: cmpEqual,
508                         },
509                         want:    [][]byte{{}},
510                         wantErr: false,
511                 },
512                 {
513                         name: "test 2 > 1 for cmpNotEqual",
514                         args: args{
515                                 vm: &virtualMachine{
516                                         dataStack: [][]byte{{0x02}, {0x01}},
517                                         runLimit:  50000,
518                                 },
519                                 op: cmpNotEqual,
520                         },
521                         want:    [][]byte{{1}},
522                         wantErr: false,
523                 },
524                 {
525                         name: "test 2 == 2 for cmpLess",
526                         args: args{
527                                 vm: &virtualMachine{
528                                         dataStack: [][]byte{{0x02}, {0x02}},
529                                         runLimit:  50000,
530                                 },
531                                 op: cmpLess,
532                         },
533                         want:    [][]byte{{1}},
534                         wantErr: false,
535                 },
536                 {
537                         name: "test 2 == 2 for cmpLessEqual",
538                         args: args{
539                                 vm: &virtualMachine{
540                                         dataStack: [][]byte{{0x02}, {0x02}},
541                                         runLimit:  50000,
542                                 },
543                                 op: cmpLessEqual,
544                         },
545                         want:    [][]byte{{1}},
546                         wantErr: false,
547                 },
548                 {
549                         name: "test 2 == 2 for cmpGreater",
550                         args: args{
551                                 vm: &virtualMachine{
552                                         dataStack: [][]byte{{0x02}, {0x02}},
553                                         runLimit:  50000,
554                                 },
555                                 op: cmpGreater,
556                         },
557                         want:    [][]byte{{1}},
558                         wantErr: false,
559                 },
560                 {
561                         name: "test 2 == 2 for cmpGreaterEqual",
562                         args: args{
563                                 vm: &virtualMachine{
564                                         dataStack: [][]byte{{0x02}, {0x02}},
565                                         runLimit:  50000,
566                                 },
567                                 op: cmpGreaterEqual,
568                         },
569                         want:    [][]byte{{1}},
570                         wantErr: false,
571                 },
572                 {
573                         name: "test 2 == 2 for cmpEqual",
574                         args: args{
575                                 vm: &virtualMachine{
576                                         dataStack: [][]byte{{0x02}, {0x02}},
577                                         runLimit:  50000,
578                                 },
579                                 op: cmpEqual,
580                         },
581                         want:    [][]byte{{1}},
582                         wantErr: false,
583                 },
584                 {
585                         name: "test 2 == 2 for cmpNotEqual",
586                         args: args{
587                                 vm: &virtualMachine{
588                                         dataStack: [][]byte{{0x02}, {0x02}},
589                                         runLimit:  50000,
590                                 },
591                                 op: cmpNotEqual,
592                         },
593                         want:    [][]byte{{1}},
594                         wantErr: false,
595                 },
596                 {
597                         name: "test 1 < 2 for cmpLess",
598                         args: args{
599                                 vm: &virtualMachine{
600                                         dataStack: [][]byte{{0x01}, {0x02}},
601                                         runLimit:  50000,
602                                 },
603                                 op: cmpLess,
604                         },
605                         want:    [][]byte{{1}},
606                         wantErr: false,
607                 },
608                 {
609                         name: "test 1 < 2 for cmpLessEqual",
610                         args: args{
611                                 vm: &virtualMachine{
612                                         dataStack: [][]byte{{0x01}, {0x02}},
613                                         runLimit:  50000,
614                                 },
615                                 op: cmpLessEqual,
616                         },
617                         want:    [][]byte{{1}},
618                         wantErr: false,
619                 },
620                 {
621                         name: "test 1 < 2 for cmpGreater",
622                         args: args{
623                                 vm: &virtualMachine{
624                                         dataStack: [][]byte{{0x01}, {0x02}},
625                                         runLimit:  50000,
626                                 },
627                                 op: cmpGreater,
628                         },
629                         want:    [][]byte{{}},
630                         wantErr: false,
631                 },
632                 {
633                         name: "test 1 < 2 for cmpGreaterEqual",
634                         args: args{
635                                 vm: &virtualMachine{
636                                         dataStack: [][]byte{{0x01}, {0x02}},
637                                         runLimit:  50000,
638                                 },
639                                 op: cmpGreaterEqual,
640                         },
641                         want:    [][]byte{{}},
642                         wantErr: false,
643                 },
644                 {
645                         name: "test 1 < 2 for cmpEqual",
646                         args: args{
647                                 vm: &virtualMachine{
648                                         dataStack: [][]byte{{0x01}, {0x02}},
649                                         runLimit:  50000,
650                                 },
651                                 op: cmpEqual,
652                         },
653                         want:    [][]byte{{}},
654                         wantErr: false,
655                 },
656                 {
657                         name: "test 1 < 2 for cmpNotEqual",
658                         args: args{
659                                 vm: &virtualMachine{
660                                         dataStack: [][]byte{{0x01}, {0x02}},
661                                         runLimit:  50000,
662                                 },
663                                 op: cmpNotEqual,
664                         },
665                         want:    [][]byte{{1}},
666                         wantErr: false,
667                 },
668         }
669         for _, tt := range tests {
670                 t.Run(tt.name, func(t *testing.T) {
671                         if err := doNumCompare(tt.args.vm, tt.args.op); (err != nil) != tt.wantErr {
672                                 t.Errorf("doNumCompare() error = %v, wantErr %v", err, tt.wantErr)
673                         }
674                 })
675         }
676 }
677
678 func TestOpMinMax(t *testing.T) {
679         type args struct {
680                 vm *virtualMachine
681                 f  func(vm *virtualMachine) error
682         }
683
684         tests := []struct {
685                 name    string
686                 args    args
687                 want    [][]byte
688                 wantErr bool
689         }{
690                 {
691                         name: "min of (2, 3)",
692                         args: args{
693                                 vm: &virtualMachine{
694                                         runLimit:  50000,
695                                         dataStack: [][]byte{{0x02}, {0x03}},
696                                 },
697                                 f: opMin,
698                         },
699                         want:    [][]byte{{0x02}},
700                         wantErr: false,
701                 },
702
703                 {
704                         name: "max of (2, 3)",
705                         args: args{
706                                 vm: &virtualMachine{
707                                         runLimit:  50000,
708                                         dataStack: [][]byte{{0x02}, {0x03}},
709                                 },
710                                 f: opMax,
711                         },
712                         want:    [][]byte{{0x03}},
713                         wantErr: false,
714                 },
715                 {
716                         name: "max of (two number, one number)",
717                         args: args{
718                                 vm: &virtualMachine{
719                                         runLimit:  50000,
720                                         dataStack: [][]byte{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, {0xff}},
721                                 },
722                                 f: opMax,
723                         },
724                         want:    [][]byte{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
725                         wantErr: false,
726                 },
727                 {
728                         name: "min of (0, -1) got error",
729                         args: args{
730                                 vm: &virtualMachine{
731                                         runLimit:  50000,
732                                         dataStack: [][]byte{{}, mocks.U256NumNegative1},
733                                 },
734                                 f: opMin,
735                         },
736                         want:    nil,
737                         wantErr: true,
738                 },
739                 {
740                         name: "max of (-1, -1) got error",
741                         args: args{
742                                 vm: &virtualMachine{
743                                         runLimit:  50000,
744                                         dataStack: [][]byte{mocks.U256NumNegative1, mocks.U256NumNegative1},
745                                 },
746                                 f: opMax,
747                         },
748                         want:    nil,
749                         wantErr: true,
750                 },
751         }
752         for _, tt := range tests {
753                 t.Run(tt.name, func(t *testing.T) {
754                         if err := tt.args.f(tt.args.vm); err != nil {
755                                 if !tt.wantErr {
756                                         t.Errorf("opAdd() error = %v, wantErr %v", err, tt.wantErr)
757                                 }
758                                 return
759                         }
760                         if !testutil.DeepEqual(tt.args.vm.dataStack, tt.want) {
761                                 t.Errorf("opAdd() error, got %v and wantErr %v", tt.args.vm.dataStack, tt.want)
762                         }
763                 })
764         }
765 }
766
767 func Test_op2Mul(t *testing.T) {
768         type args struct {
769                 vm *virtualMachine
770         }
771         tests := []struct {
772                 name    string
773                 args    args
774                 wantErr bool
775         }{
776                 {
777                         name: "test normal mul op",
778                         args: args{
779                                 vm: &virtualMachine{
780                                         runLimit:  50000,
781                                         dataStack: [][]byte{{2}},
782                                 },
783                         },
784                         wantErr: false,
785                 },
786                 {
787                         name: "test normal mul op of big number",
788                         args: args{
789                                 vm: &virtualMachine{
790                                         runLimit:  50000,
791                                         dataStack: [][]byte{{0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
792                                 },
793                         },
794                         wantErr: false,
795                 },
796                 {
797                         name: "test error of mul op negative",
798                         args: args{
799                                 vm: &virtualMachine{
800                                         runLimit:  50000,
801                                         dataStack: [][]byte{mocks.U256NumNegative1},
802                                 },
803                         },
804                         wantErr: true,
805                 },
806                 {
807                         name: "test error of mul op out range",
808                         args: args{
809                                 vm: &virtualMachine{
810                                         runLimit:  50000,
811                                         dataStack: [][]byte{mocks.MaxU256},
812                                 },
813                         },
814                         wantErr: true,
815                 },
816                 {
817                         name: "test error of mul op out range which result is min number",
818                         args: args{
819                                 vm: &virtualMachine{
820                                         runLimit:  50000,
821                                         dataStack: [][]byte{{0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
822                                 },
823                         },
824                         wantErr: true,
825                 },
826         }
827         for _, tt := range tests {
828                 t.Run(tt.name, func(t *testing.T) {
829                         if err := op2Mul(tt.args.vm); (err != nil) != tt.wantErr {
830                                 t.Errorf("op2Mul() error = %v, wantErr %v", err, tt.wantErr)
831                         }
832                 })
833         }
834 }
835
836 func Test_opMul(t *testing.T) {
837         type args struct {
838                 vm *virtualMachine
839         }
840         tests := []struct {
841                 name    string
842                 args    args
843                 want    [][]byte
844                 wantErr bool
845         }{
846                 {
847                         name: "test normal mul op",
848                         args: args{
849                                 vm: &virtualMachine{
850                                         runLimit:  50000,
851                                         dataStack: [][]byte{{2}, {2}},
852                                 },
853                         },
854                         want:    [][]byte{{4}},
855                         wantErr: false,
856                 },
857                 {
858                         name: "test normal mul op of big number",
859                         args: args{
860                                 vm: &virtualMachine{
861                                         runLimit:  50000,
862                                         dataStack: [][]byte{{0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, {0x02}},
863                                 },
864                         },
865                         want:    [][]byte{{0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe}},
866                         wantErr: false,
867                 },
868                 {
869                         name: "test error of mul op negative",
870                         args: args{
871                                 vm: &virtualMachine{
872                                         runLimit:  50000,
873                                         dataStack: [][]byte{mocks.U256NumNegative1, {0x02}},
874                                 },
875                         },
876                         wantErr: true,
877                 },
878                 {
879                         name: "test error of mul op out range",
880                         args: args{
881                                 vm: &virtualMachine{
882                                         runLimit:  50000,
883                                         dataStack: [][]byte{mocks.MaxU256},
884                                 },
885                         },
886                         wantErr: true,
887                 },
888                 {
889                         name: "test error of mul op out range which result is min number",
890                         args: args{
891                                 vm: &virtualMachine{
892                                         runLimit:  50000,
893                                         dataStack: [][]byte{{0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x02}},
894                                 },
895                         },
896                         wantErr: true,
897                 },
898         }
899         for _, tt := range tests {
900                 t.Run(tt.name, func(t *testing.T) {
901                         if err := opMul(tt.args.vm); err != nil {
902                                 if !tt.wantErr {
903                                         t.Errorf("opMul() error = %v, wantErr %v", err, tt.wantErr)
904                                 }
905                                 return
906                         }
907                         if !testutil.DeepEqual(tt.args.vm.dataStack, tt.want) {
908                                 t.Errorf("opMul() error, got %v and wantErr %v", tt.args.vm.dataStack, tt.want)
909                         }
910                 })
911         }
912 }
913
914 func Test_op1Sub(t *testing.T) {
915         type args struct {
916                 vm *virtualMachine
917         }
918         tests := []struct {
919                 name    string
920                 args    args
921                 want    [][]byte
922                 wantErr bool
923         }{
924                 {
925                         name: "Test 2 - 1 = 1",
926                         args: args{
927                                 vm: &virtualMachine{
928                                         runLimit:  50000,
929                                         dataStack: [][]byte{{0x02}},
930                                 },
931                         },
932                         want:    [][]byte{{0x01}},
933                         wantErr: false,
934                 },
935                 {
936                         name: "Test that two number become one number after op sub",
937                         args: args{
938                                 vm: &virtualMachine{
939                                         runLimit:  50000,
940                                         dataStack: [][]byte{{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
941                                 },
942                         },
943                         want:    [][]byte{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
944                         wantErr: false,
945                 },
946                 {
947                         name: "Test for 0 - 1 got error",
948                         args: args{
949                                 vm: &virtualMachine{
950                                         runLimit:  50000,
951                                         dataStack: [][]byte{{}},
952                                 },
953                         },
954                         want:    nil,
955                         wantErr: true,
956                 },
957                 {
958                         name: "Test for -1 - 1 got error",
959                         args: args{
960                                 vm: &virtualMachine{
961                                         runLimit:  50000,
962                                         dataStack: [][]byte{mocks.U256NumNegative1},
963                                 },
964                         },
965                         want:    nil,
966                         wantErr: true,
967                 },
968         }
969         for _, tt := range tests {
970                 t.Run(tt.name, func(t *testing.T) {
971                         if err := op1Sub(tt.args.vm); (err != nil) != tt.wantErr {
972                                 t.Errorf("op1Sub() error = %v, wantErr %v", err, tt.wantErr)
973                         }
974                         if !testutil.DeepEqual(tt.args.vm.dataStack, tt.want) {
975                                 t.Errorf("op1Sub() error, got %v and wantErr %v", tt.args.vm.dataStack, tt.want)
976                         }
977                 })
978         }
979 }
980
981 func Test_opSub(t *testing.T) {
982         type args struct {
983                 vm *virtualMachine
984         }
985         tests := []struct {
986                 name    string
987                 args    args
988                 want    [][]byte
989                 wantErr bool
990         }{
991                 {
992                         name: "Test 2 - 1 = 1",
993                         args: args{
994                                 vm: &virtualMachine{
995                                         runLimit:  50000,
996                                         dataStack: [][]byte{{0x02}, {0x01}},
997                                 },
998                         },
999                         want:    [][]byte{{0x01}},
1000                         wantErr: false,
1001                 },
1002                 {
1003                         name: "Test that two number become one number",
1004                         args: args{
1005                                 vm: &virtualMachine{
1006                                         runLimit:  50000,
1007                                         dataStack: [][]byte{{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x01}},
1008                                 },
1009                         },
1010                         want:    [][]byte{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
1011                         wantErr: false,
1012                 },
1013                 {
1014                         name: "Test for 0 - 1 got error",
1015                         args: args{
1016                                 vm: &virtualMachine{
1017                                         runLimit:  50000,
1018                                         dataStack: [][]byte{{}, {0x01}},
1019                                 },
1020                         },
1021                         want:    nil,
1022                         wantErr: true,
1023                 },
1024                 {
1025                         name: "Test for -1 - 1 got error",
1026                         args: args{
1027                                 vm: &virtualMachine{
1028                                         runLimit:  50000,
1029                                         dataStack: [][]byte{mocks.U256NumNegative1, {0x01}},
1030                                 },
1031                         },
1032                         want:    nil,
1033                         wantErr: true,
1034                 },
1035         }
1036         for _, tt := range tests {
1037                 t.Run(tt.name, func(t *testing.T) {
1038                         if err := opSub(tt.args.vm); (err != nil) != tt.wantErr {
1039                                 t.Errorf("opSub() error = %v, wantErr %v", err, tt.wantErr)
1040                         }
1041                         if !testutil.DeepEqual(tt.args.vm.dataStack, tt.want) {
1042                                 t.Errorf("opSub() error, got %v and wantErr %v", tt.args.vm.dataStack, tt.want)
1043                         }
1044                 })
1045         }
1046 }
1047
1048 func Test_op2Div(t *testing.T) {
1049         type args struct {
1050                 vm *virtualMachine
1051         }
1052         tests := []struct {
1053                 name    string
1054                 args    args
1055                 want    [][]byte
1056                 wantErr bool
1057         }{
1058                 {
1059                         name: "Test 2 div 2 = 1",
1060                         args: args{
1061                                 vm: &virtualMachine{
1062                                         runLimit:  50000,
1063                                         dataStack: [][]byte{{0x02}},
1064                                 },
1065                         },
1066                         want:    [][]byte{{0x01}},
1067                         wantErr: false,
1068                 },
1069                 {
1070                         name: "Test that two number become one number after op div",
1071                         args: args{
1072                                 vm: &virtualMachine{
1073                                         runLimit:  50000,
1074                                         dataStack: [][]byte{{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1075                                 },
1076                         },
1077                         want:    [][]byte{{0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1078                         wantErr: false,
1079                 },
1080                 {
1081                         name: "Test for 0 div 2 got 0",
1082                         args: args{
1083                                 vm: &virtualMachine{
1084                                         runLimit:  50000,
1085                                         dataStack: [][]byte{{}},
1086                                 },
1087                         },
1088                         want:    [][]byte{{}},
1089                         wantErr: false,
1090                 },
1091                 {
1092                         name: "Test for -1 div 2 got error",
1093                         args: args{
1094                                 vm: &virtualMachine{
1095                                         runLimit:  50000,
1096                                         dataStack: [][]byte{mocks.U256NumNegative1},
1097                                 },
1098                         },
1099                         want:    nil,
1100                         wantErr: true,
1101                 },
1102         }
1103         for _, tt := range tests {
1104                 t.Run(tt.name, func(t *testing.T) {
1105                         if err := op2Div(tt.args.vm); err != nil {
1106                                 if !tt.wantErr {
1107                                         t.Errorf("op2Div() error = %v, wantErr %v", err, tt.wantErr)
1108                                 }
1109                                 return
1110                         }
1111                         if !testutil.DeepEqual(tt.args.vm.dataStack, tt.want) {
1112                                 t.Errorf("op2Div() error, got %v and wantErr %v", tt.args.vm.dataStack, tt.want)
1113                         }
1114                 })
1115         }
1116 }
1117
1118 func Test_opDiv(t *testing.T) {
1119         type args struct {
1120                 vm *virtualMachine
1121         }
1122         tests := []struct {
1123                 name    string
1124                 args    args
1125                 want    [][]byte
1126                 wantErr bool
1127         }{
1128                 {
1129                         name: "Test 2 div 2 = 1",
1130                         args: args{
1131                                 vm: &virtualMachine{
1132                                         runLimit:  50000,
1133                                         dataStack: [][]byte{{0x02}, {0x02}},
1134                                 },
1135                         },
1136                         want:    [][]byte{{0x01}},
1137                         wantErr: false,
1138                 },
1139                 {
1140                         name: "Test 2 div 1 = 2",
1141                         args: args{
1142                                 vm: &virtualMachine{
1143                                         runLimit:  50000,
1144                                         dataStack: [][]byte{{0x02}, {0x01}},
1145                                 },
1146                         },
1147                         want:    [][]byte{{0x02}},
1148                         wantErr: false,
1149                 },
1150                 {
1151                         name: "Test that two number become one number after op div",
1152                         args: args{
1153                                 vm: &virtualMachine{
1154                                         runLimit:  50000,
1155                                         dataStack: [][]byte{{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x02}},
1156                                 },
1157                         },
1158                         want:    [][]byte{{0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1159                         wantErr: false,
1160                 },
1161                 {
1162                         name: "Test for 0 div 2 got 0",
1163                         args: args{
1164                                 vm: &virtualMachine{
1165                                         runLimit:  50000,
1166                                         dataStack: [][]byte{{}, {0x02}},
1167                                 },
1168                         },
1169                         want:    [][]byte{{}},
1170                         wantErr: false,
1171                 },
1172                 {
1173                         name: "Test for -1 div 2 got error",
1174                         args: args{
1175                                 vm: &virtualMachine{
1176                                         runLimit:  50000,
1177                                         dataStack: [][]byte{mocks.U256NumNegative1, {0x02}},
1178                                 },
1179                         },
1180                         want:    nil,
1181                         wantErr: true,
1182                 },
1183                 {
1184                         name: "Test for 1 div 0 got error",
1185                         args: args{
1186                                 vm: &virtualMachine{
1187                                         runLimit:  50000,
1188                                         dataStack: [][]byte{{0x01}, {}},
1189                                 },
1190                         },
1191                         want:    nil,
1192                         wantErr: true,
1193                 },
1194         }
1195         for _, tt := range tests {
1196                 t.Run(tt.name, func(t *testing.T) {
1197                         if err := opDiv(tt.args.vm); err != nil {
1198                                 if !tt.wantErr {
1199                                         t.Errorf("opDiv() error = %v, wantErr %v", err, tt.wantErr)
1200                                 }
1201                                 return
1202                         }
1203                         if !testutil.DeepEqual(tt.args.vm.dataStack, tt.want) {
1204                                 t.Errorf("opDiv() error, got %v and wantErr %v", tt.args.vm.dataStack, tt.want)
1205                         }
1206                 })
1207         }
1208 }
1209
1210 func Test_opAdd(t *testing.T) {
1211         type args struct {
1212                 vm *virtualMachine
1213         }
1214
1215         tests := []struct {
1216                 name    string
1217                 args    args
1218                 want    [][]byte
1219                 wantErr bool
1220         }{
1221                 {
1222                         name: "Test 2 + 2 = 4",
1223                         args: args{
1224                                 vm: &virtualMachine{
1225                                         runLimit:  50000,
1226                                         dataStack: [][]byte{{0x02}, {0x02}},
1227                                 },
1228                         },
1229                         want:    [][]byte{{0x04}},
1230                         wantErr: false,
1231                 },
1232                 {
1233                         name: "Test that one number become two number",
1234                         args: args{
1235                                 vm: &virtualMachine{
1236                                         runLimit:  50000,
1237                                         dataStack: [][]byte{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, {0x01}},
1238                                 },
1239                         },
1240                         want:    [][]byte{{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
1241                         wantErr: false,
1242                 },
1243                 {
1244                         name: "Test for 0 + -1 got error",
1245                         args: args{
1246                                 vm: &virtualMachine{
1247                                         runLimit:  50000,
1248                                         dataStack: [][]byte{{}, mocks.U256NumNegative1},
1249                                 },
1250                         },
1251                         want:    nil,
1252                         wantErr: true,
1253                 },
1254                 {
1255                         name: "Test for -1 + -1 got error",
1256                         args: args{
1257                                 vm: &virtualMachine{
1258                                         runLimit:  50000,
1259                                         dataStack: [][]byte{mocks.U256NumNegative1, mocks.U256NumNegative1},
1260                                 },
1261                         },
1262                         want:    nil,
1263                         wantErr: true,
1264                 },
1265         }
1266         for _, tt := range tests {
1267                 t.Run(tt.name, func(t *testing.T) {
1268                         if err := opAdd(tt.args.vm); err != nil {
1269                                 if !tt.wantErr {
1270                                         t.Errorf("opAdd() error = %v, wantErr %v", err, tt.wantErr)
1271                                 }
1272                                 return
1273                         }
1274                         if !testutil.DeepEqual(tt.args.vm.dataStack, tt.want) {
1275                                 t.Errorf("opAdd() error, got %v and wantErr %v", tt.args.vm.dataStack, tt.want)
1276                         }
1277                 })
1278         }
1279 }
1280
1281 func Test_opMod(t *testing.T) {
1282         type args struct {
1283                 vm *virtualMachine
1284         }
1285         tests := []struct {
1286                 name    string
1287                 args    args
1288                 want    [][]byte
1289                 wantErr bool
1290         }{
1291                 {
1292                         name: "Test 2 mod 2 = 0",
1293                         args: args{
1294                                 vm: &virtualMachine{
1295                                         runLimit:  50000,
1296                                         dataStack: [][]byte{{0x02}, {0x02}},
1297                                 },
1298                         },
1299                         want:    [][]byte{{}},
1300                         wantErr: false,
1301                 },
1302                 {
1303                         name: "Test 2 mod 1 = 0",
1304                         args: args{
1305                                 vm: &virtualMachine{
1306                                         runLimit:  50000,
1307                                         dataStack: [][]byte{{0x02}, {0x01}},
1308                                 },
1309                         },
1310                         want:    [][]byte{{}},
1311                         wantErr: false,
1312                 },
1313                 {
1314                         name: "Test 255 mod 4 = 3",
1315                         args: args{
1316                                 vm: &virtualMachine{
1317                                         runLimit:  50000,
1318                                         dataStack: [][]byte{{0xff}, {0x04}},
1319                                 },
1320                         },
1321                         want:    [][]byte{{0x03}},
1322                         wantErr: false,
1323                 },
1324                 {
1325                         name: "Test that two number become one number",
1326                         args: args{
1327                                 vm: &virtualMachine{
1328                                         runLimit:  50000,
1329                                         dataStack: [][]byte{{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x03}},
1330                                 },
1331                         },
1332                         want:    [][]byte{{0x01}},
1333                         wantErr: false,
1334                 },
1335                 {
1336                         name: "Test for 0 mod 2 got 0",
1337                         args: args{
1338                                 vm: &virtualMachine{
1339                                         runLimit:  50000,
1340                                         dataStack: [][]byte{{}, {0x02}},
1341                                 },
1342                         },
1343                         want:    [][]byte{{}},
1344                         wantErr: false,
1345                 },
1346                 {
1347                         name: "Test for -1 div 2 got error",
1348                         args: args{
1349                                 vm: &virtualMachine{
1350                                         runLimit:  50000,
1351                                         dataStack: [][]byte{mocks.U256NumNegative1, {0x02}},
1352                                 },
1353                         },
1354                         want:    nil,
1355                         wantErr: true,
1356                 },
1357                 {
1358                         name: "Test for 1 div 0 got error",
1359                         args: args{
1360                                 vm: &virtualMachine{
1361                                         runLimit:  50000,
1362                                         dataStack: [][]byte{{0x01}, {}},
1363                                 },
1364                         },
1365                         want:    nil,
1366                         wantErr: true,
1367                 },
1368         }
1369         for _, tt := range tests {
1370                 t.Run(tt.name, func(t *testing.T) {
1371                         if err := opMod(tt.args.vm); err != nil {
1372                                 if !tt.wantErr {
1373                                         t.Errorf("opMod() error = %v, wantErr %v", err, tt.wantErr)
1374                                 }
1375                                 return
1376                         }
1377                         if !testutil.DeepEqual(tt.args.vm.dataStack, tt.want) {
1378                                 t.Errorf("opMod() error, got %v and wantErr %v", tt.args.vm.dataStack, tt.want)
1379                         }
1380                 })
1381         }
1382 }
1383
1384 func TestOpShift(t *testing.T) {
1385         type args struct {
1386                 vm *virtualMachine
1387                 f  func(vm *virtualMachine) error
1388         }
1389
1390         tests := []struct {
1391                 name    string
1392                 args    args
1393                 want    [][]byte
1394                 wantErr bool
1395         }{
1396                 {
1397                         name: "2 left shift 0",
1398                         args: args{
1399                                 vm: &virtualMachine{
1400                                         runLimit:  50000,
1401                                         dataStack: [][]byte{{0x02}, {}},
1402                                 },
1403                                 f: opLshift,
1404                         },
1405                         want:    [][]byte{{0x02}},
1406                         wantErr: false,
1407                 },
1408                 {
1409                         name: "2 right shift 0",
1410                         args: args{
1411                                 vm: &virtualMachine{
1412                                         runLimit:  50000,
1413                                         dataStack: [][]byte{{0x02}, {}},
1414                                 },
1415                                 f: opRshift,
1416                         },
1417                         want:    [][]byte{{0x02}},
1418                         wantErr: false,
1419                 },
1420                 {
1421                         name: "2 left shift 3",
1422                         args: args{
1423                                 vm: &virtualMachine{
1424                                         runLimit:  50000,
1425                                         dataStack: [][]byte{{0x02}, {0x03}},
1426                                 },
1427                                 f: opLshift,
1428                         },
1429                         want:    [][]byte{{0x10}},
1430                         wantErr: false,
1431                 },
1432                 {
1433                         name: "2 right shift 3",
1434                         args: args{
1435                                 vm: &virtualMachine{
1436                                         runLimit:  50000,
1437                                         dataStack: [][]byte{{0x02}, {0x03}},
1438                                 },
1439                                 f: opRshift,
1440                         },
1441                         want:    [][]byte{{}},
1442                         wantErr: false,
1443                 },
1444                 {
1445                         name: "two number right shift become one number",
1446                         args: args{
1447                                 vm: &virtualMachine{
1448                                         runLimit:  50000,
1449                                         dataStack: [][]byte{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, {0x0f}},
1450                                 },
1451                                 f: opRshift,
1452                         },
1453                         want:    [][]byte{{0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
1454                         wantErr: false,
1455                 },
1456                 {
1457                         name: "two number left shift become overflow",
1458                         args: args{
1459                                 vm: &virtualMachine{
1460                                         runLimit:  50000,
1461                                         dataStack: [][]byte{{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, {0xff}},
1462                                 },
1463                                 f: opLshift,
1464                         },
1465                         wantErr: true,
1466                 },
1467                 {
1468                         name: "left shift not uint64",
1469                         args: args{
1470                                 vm: &virtualMachine{
1471                                         runLimit:  50000,
1472                                         dataStack: [][]byte{{0xff}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
1473                                 },
1474                                 f: opLshift,
1475                         },
1476                         want:    [][]byte{{}},
1477                         wantErr: false,
1478                 },
1479                 {
1480                         name: "right shift not uint64",
1481                         args: args{
1482                                 vm: &virtualMachine{
1483                                         runLimit:  50000,
1484                                         dataStack: [][]byte{{0xff}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
1485                                 },
1486                                 f: opRshift,
1487                         },
1488                         want:    [][]byte{{}},
1489                         wantErr: false,
1490                 },
1491                 {
1492                         name: "0 left shift -1 got error",
1493                         args: args{
1494                                 vm: &virtualMachine{
1495                                         runLimit:  50000,
1496                                         dataStack: [][]byte{{}, mocks.U256NumNegative1},
1497                                 },
1498                                 f: opLshift,
1499                         },
1500                         want:    nil,
1501                         wantErr: true,
1502                 },
1503                 {
1504                         name: "-1 right shift -1 got error",
1505                         args: args{
1506                                 vm: &virtualMachine{
1507                                         runLimit:  50000,
1508                                         dataStack: [][]byte{mocks.U256NumNegative1, mocks.U256NumNegative1},
1509                                 },
1510                                 f: opRshift,
1511                         },
1512                         want:    nil,
1513                         wantErr: true,
1514                 },
1515         }
1516         for _, tt := range tests {
1517                 t.Run(tt.name, func(t *testing.T) {
1518                         if err := tt.args.f(tt.args.vm); err != nil {
1519                                 if !tt.wantErr {
1520                                         t.Errorf("opShift() error = %v, wantErr %v", err, tt.wantErr)
1521                                 }
1522                                 return
1523                         }
1524                         if !testutil.DeepEqual(tt.args.vm.dataStack, tt.want) {
1525                                 t.Errorf("opShift() error, got %v and wantErr %v", tt.args.vm.dataStack, tt.want)
1526                         }
1527                 })
1528         }
1529 }