-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_pushdata_test.go
59 lines (51 loc) · 1.53 KB
/
func_pushdata_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
package neovm
import (
"bytes"
"encoding/binary"
"testing"
"github.com/milechao/neovm/utils"
)
func TestGetPushData(t *testing.T) {
var e ExecutionEngine
var iRet int8
var ret []byte
e.Context = NewExecutionContext(&e, nil)
e.OpCode = PUSH0
iRet, ok := getPushData(&e).(int8)
if !ok || iRet != 0 {
t.Error("NeoVM getPushData PUSH0 execute failed.")
}
e.OpCode = PUSHDATA1
e.Context.OpReader = utils.NewVmReader([]byte{4, 1, 1, 1, 1})
ret, ok = getPushData(&e).([]byte)
if !ok || !bytes.Equal(ret, []byte{1, 1, 1, 1}) {
t.Fatal("NeoVM getPushData PUSHDATA1 execute failed.")
}
e.OpCode = PUSHDATA2
b := make([]byte, 2)
binary.LittleEndian.PutUint16(b, 4)
b = append(b, []byte{1, 1, 1, 1}...)
e.Context.OpReader = utils.NewVmReader(b)
ret, ok = getPushData(&e).([]byte)
if !ok || !bytes.Equal(ret, []byte{1, 1, 1, 1}) {
t.Fatal("NeoVM getPushData PUSHDATA2 execute failed.")
}
e.OpCode = PUSHDATA4
b = make([]byte, 4)
binary.LittleEndian.PutUint32(b, 4)
b = append(b, []byte{1, 1, 1, 1}...)
e.Context.OpReader = utils.NewVmReader(b)
ret, ok = getPushData(&e).([]byte)
if !ok || !bytes.Equal(ret, []byte{1, 1, 1, 1}) {
t.Fatal("NeoVM getPushData PUSHDATA4 execute failed.")
}
for _, opCode := range []OpCode{PUSHM1, PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7,
PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16} {
e.OpCode = opCode
expect := int8(opCode - PUSH1 + 1)
iRet, ok = getPushData(&e).(int8)
if !ok || expect != iRet {
t.Fatal("NeoVM getPushData execute failed.")
}
}
}