summaryrefslogtreecommitdiff
path: root/src/json/test_json.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/json/test_json.c')
-rw-r--r--src/json/test_json.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/json/test_json.c b/src/json/test_json.c
index 2e7aba50..e876d95d 100644
--- a/src/json/test_json.c
+++ b/src/json/test_json.c
@@ -56,6 +56,74 @@ test_amount (void)
}
+static int
+test_contract ()
+{
+ struct GNUNET_HashCode h1;
+ struct GNUNET_HashCode h2;
+ json_t *c1;
+ json_t *c2;
+ json_t *c3;
+
+ c1 = json_pack ("{s:s, s:{s:s, s:{s:s}}}",
+ "k1", "v1",
+ "k2", "n1", "n2",
+ /***/ "_forgettable", "n1", "salt");
+ GNUNET_assert (NULL != c1);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_contract_mark_forgettable (c1,
+ "k1"));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_contract_hash (c1,
+ &h1));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_contract_part_forget (c1,
+ "k1"));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_contract_hash (c1,
+ &h2));
+ json_decref (c1);
+ if (0 !=
+ GNUNET_memcmp (&h1,
+ &h2))
+ {
+ GNUNET_break (0);
+ return 1;
+ }
+ c2 = json_pack ("{s:s}",
+ "n1", "n2");
+ GNUNET_assert (NULL != c2);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_contract_mark_forgettable (c2,
+ "n1"));
+ c3 = json_pack ("{s:s, s:o}",
+ "k1", "v1",
+ "k2", c2);
+ GNUNET_assert (NULL != c3);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_contract_mark_forgettable (c3,
+ "k1"));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_contract_hash (c3,
+ &h1));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_contract_part_forget (c2,
+ "n1"));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_contract_hash (c3,
+ &h2));
+ json_decref (c3);
+ if (0 !=
+ GNUNET_memcmp (&h1,
+ &h2))
+ {
+ GNUNET_break (0);
+ return 1;
+ }
+ return 0;
+}
+
+
int
main (int argc,
const char *const argv[])
@@ -67,6 +135,8 @@ main (int argc,
NULL);
if (0 != test_amount ())
return 1;
+ if (0 != test_contract ())
+ return 2;
return 0;
}