Add SUB
Opcode
This commit is contained in:
parent
abc3b46f1c
commit
280d526f41
2 changed files with 31 additions and 0 deletions
|
@ -4,4 +4,5 @@ import "github.com/CityOfZion/neo-go/pkg/vm/stack"
|
||||||
|
|
||||||
var opFunc = map[stack.Instruction]func(ctx *stack.Context, istack *stack.Invocation) error{
|
var opFunc = map[stack.Instruction]func(ctx *stack.Context, istack *stack.Invocation) error{
|
||||||
stack.ADD: Add,
|
stack.ADD: Add,
|
||||||
|
stack.SUB: Sub,
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,3 +37,33 @@ func TestAddOp(t *testing.T) {
|
||||||
assert.Equal(t, int64(43), item.Value().Int64())
|
assert.Equal(t, int64(43), item.Value().Int64())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSubOp(t *testing.T) {
|
||||||
|
|
||||||
|
v := VM{}
|
||||||
|
|
||||||
|
a, err := stack.NewInt(big.NewInt(30))
|
||||||
|
if err != nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
b, err := stack.NewInt(big.NewInt(40))
|
||||||
|
if err != nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := stack.NewContext([]byte{})
|
||||||
|
ctx.Estack.Push(a).Push(b)
|
||||||
|
|
||||||
|
v.ExecuteOp(stack.SUB, ctx)
|
||||||
|
|
||||||
|
// Stack should have one item
|
||||||
|
assert.Equal(t, 1, ctx.Estack.Len())
|
||||||
|
|
||||||
|
item, err := ctx.Estack.PopInt()
|
||||||
|
if err != nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, int64(-10), item.Value().Int64())
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue