MCPcopy Create free account
hub / github.com/chain/txvm / TestSimpleOpcodes

Function TestSimpleOpcodes

protocol/txvm/simple_ops_test.go:13–1258  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestSimpleOpcodes(t *testing.T) {
14
15 cases := []struct {
16 name string
17 pre stack // items on the vm stack before op is run
18 opcode byte // instruction to be tested
19 post stack // contract stack after execution, from bottom -> top of stack
20 wanterr error // check only if post is nil
21 }{
22
23 /* NUMERIC AND BOOLEAN INSTRUCTIONS */
24
25 {
26 name: "int",
27 pre: stack{Bytes([]byte{0xE5, 0x8E, 0x26})},
28 opcode: op.Int,
29 post: stack{Int(624485)},
30 },
31 {
32 name: "int fail",
33 pre: stack{Bytes([]byte{0xE5})},
34 opcode: op.Int,
35 wanterr: ErrInt,
36 },
37 {
38 name: "int fail",
39 pre: stack{Int(63)},
40 opcode: op.Int,
41 wanterr: ErrType,
42 },
43 {
44 name: "add small ints",
45 pre: stack{Int(1), Int(5)},
46 opcode: op.Add,
47 post: stack{Int(6)},
48 },
49 {
50 name: "add large ints",
51 pre: stack{Int(1000000000000001), Int(99999999999999)},
52 opcode: op.Add,
53 post: stack{Int(1100000000000000)},
54 },
55 {
56 name: "add fail type",
57 pre: stack{Bytes("hello"), Bytes("there")},
58 opcode: op.Add,
59 wanterr: ErrType,
60 },
61 {
62 name: "add fail underflow",
63 pre: stack{Int(29859)},
64 opcode: op.Add,
65 wanterr: ErrUnderflow,
66 },
67 {
68 name: "negate pos int",
69 pre: stack{Int(15)},
70 opcode: op.Neg,

Callers

nothing calls this directly

Calls 6

recoverExecMethod · 0.95
RootFunction · 0.92
BytesTypeAlias · 0.85
IntTypeAlias · 0.85
compareStacksFunction · 0.85
mustDecodeHexFunction · 0.70

Tested by

no test coverage detected