From c326a5bd9d74a599c967a2ad49536110d054a846 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 16 Jul 2020 14:30:14 +0200 Subject: implement forgettable contract terms core logic (#6365) --- src/json/test_json.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'src/json/test_json.c') diff --git a/src/json/test_json.c b/src/json/test_json.c index 2e7aba50a..e876d95db 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; } -- cgit v1.2.3