-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vm: missing tests for CALL* instructions #833
Conversation
Codecov Report
@@ Coverage Diff @@
## master #833 +/- ##
==========================================
+ Coverage 67.68% 68.36% +0.67%
==========================================
Files 141 141
Lines 13175 13175
==========================================
+ Hits 8918 9007 +89
+ Misses 3849 3756 -93
- Partials 408 412 +4
Continue to review full report at Codecov.
|
Added tests for: - bit operatoins: AND, OR, XOR - numeric operations: BOOLOR, MIN, MAX, WITHIN, NEGATE
5128414
to
d94df66
Compare
97f4188
to
f44e621
Compare
800436c
to
ad39973
Compare
pkg/vm/vm_test.go
Outdated
} | ||
|
||
func TestCALLI(t *testing.T) { | ||
prog := []byte{byte(opcode.PUSHBYTES2), byte(opcode.Opcode(uint16(1))), byte(opcode.Opcode(uint16(1) >> 8)), // little-endian |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
byte(opcode.Opcode(uint16(1)))
is just a 1
, really. And it makes no sense doing uint16(1) >> 8
as it's just a 0
.
pkg/vm/vm_test.go
Outdated
byte(opcode.TOALTSTACK), byte(opcode.DUPFROMALTSTACK), | ||
byte(opcode.JMPIF), byte(0x4), byte(0), byte(opcode.RET), | ||
byte(opcode.FROMALTSTACK), byte(opcode.DEC), | ||
byte(opcode.CALLI), byte(0), byte(1), 0xF8, 0xFF} // -8 -> JMP to TOALTSTACK) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't jump to TOALTSTACK
, rather it will jump to JMPIF
.
And I'd suggest something like this to test RV and stack isolation properly.
- Check that alt stack is clean (it must panic on
FROMALTSTACK
):
PUSH1
DUP
TOALTSTACK
JMP 0x2 /* to CALLI */
FROMALTSTACK
RET
CALLI {0, 0, -2} /* to FROMALTSTACK */
RET
- Check parameter and return values copying:
PUSH3
PUSH2
PUSH1
JMP 0x2 /* to CALLI */
SUB /* 2 - 1 */
RET
CALLI {1, 2, -4} /* to SUB */
MUL /* 3 * 1 */
RET
It should run to completion and leave 3
on estack. Failing to copy pcount
elements it would fail on SUB
, doing it in wrong order it would compute -1
instead on 1, not returning rvcount
elements it would fail on MUL
, so it seems to be a nice test to me.
Estack isolation can also be checked with DEPTH
as with CALLE
tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally got how it works!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added also DEPTH check
abb49f8
to
5752c19
Compare
5752c19
to
9f0bc2a
Compare
Add missing tests for: