commit cd41ebe0bad9bb973497f74b53e874d9e305f784
parent e9b9c025db271aa79173a1122b3fd578565a05ea
Author: nolash <dev@holbrook.no>
Date: Sun, 11 Apr 2021 12:35:59 +0200
Add double string test
Diffstat:
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/decode.c b/src/decode.c
@@ -76,6 +76,7 @@ int rlp_next(rlp_encoder_t *encoder, int *zlen, char **zdest) {
int r;
if (encoder->depth == -1) {
+ encoder->state = RLP_END;
return -1;
}
diff --git a/src/rlp.h b/src/rlp.h
@@ -12,6 +12,7 @@ enum rlp_state {
RLP_DECODE,
RLP_LIST,
RLP_STRING,
+ RLP_END,
RLP_ERR,
};
diff --git a/tests/check_vectors.c b/tests/check_vectors.c
@@ -27,6 +27,10 @@ START_TEST(rlp_dog_test) {
ck_assert_int_eq(l, 3);
ck_assert_mem_eq(zbuf, x_dog, l);
+ state = RLP_END;
+ rlp_next(&encoder, &l, &zbuf);
+ ck_assert_mem_eq(&encoder.state, &state, 1);
+
rlp_free(&encoder);
}
END_TEST
@@ -54,16 +58,24 @@ START_TEST(rlp_catdog_test) {
// reuse for decode
state = RLP_LIST;
- rlp_init(&encoder, 1024, encoder->buf);
+ rlp_init(&encoder, 1024, encoder.buf);
rlp_next(&encoder, &l, &zbuf);
ck_assert_mem_eq(&encoder.state, &state, 1);
ck_assert_int_eq(l, 8);
state = RLP_STRING;
rlp_next(&encoder, &l, &zbuf);
+ ck_assert_mem_eq(&encoder.state, &state, 1);
+ ck_assert_mem_eq(zbuf, x_cat, l);
+ rlp_next(&encoder, &l, &zbuf);
+ ck_assert_mem_eq(&encoder.state, &state, 1);
ck_assert_mem_eq(zbuf, x_dog, l);
+ state = RLP_END;
+ rlp_next(&encoder, &l, &zbuf);
+ ck_assert_mem_eq(&encoder.state, &state, 1);
+
rlp_free(&encoder);
}
END_TEST
@@ -130,7 +142,7 @@ Suite *rlp_vector_suite(void) {
s = suite_create("rlp_vector");
tcb = tcase_create("basic"); // examples from https://eth.wiki/fundamentals/rlp
tcase_add_test(tcb, rlp_dog_test);
- //tcase_add_test(tcb, rlp_catdog_test);
+ tcase_add_test(tcb, rlp_catdog_test);
//tcase_add_test(tcb, rlp_lorem_test);
//tcase_add_test(tcb, rlp_set_theoretical_representation_of_three);
suite_add_tcase(s, tcb);