btcs

bitcoin script parser/evaluator/compiler/decompiler
git clone git://jb55.com/btcs
Log | Files | Refs | README | LICENSE

commit c1d023dce1b322732ee541d0306fddd0d408534a
parent 75976c7dd4a4f577d9472888ce41e613c73de32c
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 26 Oct 2017 12:08:02 -0700

test/script: generic failure if eval fails

Diffstat:
Mscript.c | 6++++--
Mscript.h | 2+-
Mtest.c | 11++++++++++-
3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/script.c b/script.c @@ -4,9 +4,10 @@ #include "stack.h" #include <stdio.h> -void script_add_error(const char *serror) { +int script_add_error(const char *serror) { // TODO: set_error fprintf(stderr, "error: %s\n", serror); + return 0; } void script_add_warning(const char *warning) { @@ -50,7 +51,7 @@ cast_to_bool(struct val val) { /* return false; */ } -void +int script_eval(struct stack *script, struct stack *stack) { int op_count = 0; void **p = script->bottom; @@ -312,6 +313,7 @@ script_eval(struct stack *script, struct stack *stack) { } } + return 1; } void script_print_ops(struct stack *stack) { diff --git a/script.h b/script.h @@ -27,7 +27,7 @@ struct script { int script_new(struct script *); void script_free(struct script *); -void script_eval(struct stack *, struct stack*); +int script_eval(struct stack *, struct stack*); void script_print_ops(struct stack *); void script_print_vals(struct stack *); diff --git a/test.c b/test.c @@ -50,6 +50,14 @@ TEST(test_nip) { ok_stacks_equal(stack, expected, "test_nip"); } +TEST(test_2dup_not_enough_input) { + stack_push_op(script, OP_1); + stack_push_op(script, OP_2DUP); + + int res = script_eval(script, stack); + ok(res == 0, "2dup fail on small stack"); +} + static inline void run_test(struct stack *script, struct stack *stack, struct stack *expected, @@ -69,7 +77,7 @@ main(int argc, char *argv[]) { struct stack *stack = &_stack; struct stack *expected = &_expected; - plan(4); + plan(5); stack_init(script); stack_init(stack); @@ -77,6 +85,7 @@ main(int argc, char *argv[]) { RUNTEST(test_simple); RUNTEST(test_nip); + RUNTEST(test_2dup_not_enough_input); stack_free(expected); stack_free(stack);