vm: add some checks for OVER and PICK, add OVER tests
These actually behaved correctly because of deferred sigsegv recover, but I think it would be nice to print something more meaningful for users.
This commit is contained in:
parent
85831e3e92
commit
eb224aeebe
2 changed files with 38 additions and 0 deletions
|
@ -339,6 +339,35 @@ func TestXTUCKgood(t *testing.T) {
|
|||
assert.Equal(t, int64(topelement), vm.estack.Peek(xtuckdepth).BigInt().Int64())
|
||||
}
|
||||
|
||||
func TestOVERbadNoitem(t *testing.T) {
|
||||
prog := makeProgram(OVER)
|
||||
vm := load(prog)
|
||||
vm.estack.PushVal(1)
|
||||
vm.Run()
|
||||
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
||||
}
|
||||
|
||||
func TestOVERbadNoitems(t *testing.T) {
|
||||
prog := makeProgram(OVER)
|
||||
vm := load(prog)
|
||||
vm.Run()
|
||||
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
||||
}
|
||||
|
||||
func TestOVERgood(t *testing.T) {
|
||||
prog := makeProgram(OVER)
|
||||
vm := load(prog)
|
||||
vm.estack.PushVal(42)
|
||||
vm.estack.PushVal(34)
|
||||
vm.Run()
|
||||
assert.Equal(t, false, vm.state.HasFlag(faultState))
|
||||
assert.Equal(t, int64(42), vm.estack.Peek(0).BigInt().Int64())
|
||||
assert.Equal(t, int64(34), vm.estack.Peek(1).BigInt().Int64())
|
||||
assert.Equal(t, int64(42), vm.estack.Peek(2).BigInt().Int64())
|
||||
assert.Equal(t, 3, vm.estack.Len())
|
||||
}
|
||||
|
||||
|
||||
func makeProgram(opcodes ...Instruction) []byte {
|
||||
prog := make([]byte, len(opcodes)+1) // RET
|
||||
for i := 0; i < len(opcodes); i++ {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue