-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_splice_test.go
74 lines (62 loc) · 2.05 KB
/
func_splice_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
package neovm
import (
"bytes"
"math/big"
"testing"
vtypes "github.com/milechao/neovm/types"
)
func TestOpCat(t *testing.T) {
var e ExecutionEngine
stack := NewRandAccessStack()
stack.Push(NewStackItem(vtypes.NewByteArray([]byte("aaa"))))
stack.Push(NewStackItem(vtypes.NewByteArray([]byte("bbb"))))
e.EvaluationStack = stack
opCat(&e)
if Count(&e) != 1 || !bytes.Equal(PeekNByteArray(0, &e), []byte("aaabbb")) {
t.Fatalf("NeoVM OpCat test failed, expect aaabbb, got %s.", string(PeekNByteArray(0, &e)))
}
}
func TestOpSubStr(t *testing.T) {
var e ExecutionEngine
stack := NewRandAccessStack()
stack.Push(NewStackItem(vtypes.NewByteArray([]byte("12345"))))
stack.Push(NewStackItem(vtypes.NewInteger(big.NewInt(1))))
stack.Push(NewStackItem(vtypes.NewInteger(big.NewInt(4))))
e.EvaluationStack = stack
opSubStr(&e)
if !bytes.Equal(PeekNByteArray(0, &e), []byte("2345")) {
t.Fatalf("NeoVM OpSubStr test failed, expect 234, got %s.", string(PeekNByteArray(0, &e)))
}
}
func TestOpLeft(t *testing.T) {
var e ExecutionEngine
stack := NewRandAccessStack()
stack.Push(NewStackItem(vtypes.NewByteArray([]byte("12345"))))
stack.Push(NewStackItem(vtypes.NewInteger(big.NewInt(4))))
e.EvaluationStack = stack
opLeft(&e)
if !bytes.Equal(PeekNByteArray(0, &e), []byte("1234")) {
t.Fatalf("NeoVM OpLeft test failed, expect 1234, got %s.", string(PeekNByteArray(0, &e)))
}
}
func TestOpRight(t *testing.T) {
var e ExecutionEngine
stack := NewRandAccessStack()
stack.Push(NewStackItem(vtypes.NewByteArray([]byte("12345"))))
stack.Push(NewStackItem(vtypes.NewInteger(big.NewInt(3))))
e.EvaluationStack = stack
opRight(&e)
if !bytes.Equal(PeekNByteArray(0, &e), []byte("345")) {
t.Fatalf("NeoVM OpRight test failed, expect 345, got %s.", string(PeekNByteArray(0, &e)))
}
}
func TestOpSize(t *testing.T) {
var e ExecutionEngine
stack := NewRandAccessStack()
stack.Push(NewStackItem(vtypes.NewByteArray([]byte("12345"))))
e.EvaluationStack = stack
opSize(&e)
if PeekInt(&e) != 5 {
t.Fatalf("NeoVM OpSize test failed, expect 5, got %d.", PeekInt(&e))
}
}