Add SUB Opcode

This commit is contained in:
BlockChainDev 2019-03-15 22:55:08 +00:00
parent abc3b46f1c
commit 280d526f41
2 changed files with 31 additions and 0 deletions

View file

@ -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{
stack.ADD: Add,
stack.SUB: Sub,
}

View file

@ -37,3 +37,33 @@ func TestAddOp(t *testing.T) {
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())
}