reformatted sources

This commit is contained in:
gulliver 2022-12-11 17:04:37 +01:00
parent 79094c8a6d
commit a46efc9a78

View File

@ -1,10 +1,9 @@
#include <catch2/catch_test_macros.hpp>
#include "crow/json.h" #include "crow/json.h"
#include "model.hpp" #include "model.hpp"
#include <catch2/catch_test_macros.hpp>
TEST_CASE("PublicKey::to_json", "[to_json]") { TEST_CASE("PublicKey::to_json", "[to_json]") {
PublicKey k {"daaa63ddda38c189b8c49020c8276adbe0a695685a...", PublicKey k{"daaa63ddda38c189b8c49020c8276adbe0a695685a...", "65537"};
"65537" };
auto json = k.to_json(); auto json = k.to_json();
@ -16,8 +15,7 @@ TEST_CASE( "PublicKey::to_json", "[to_json]" ) {
TEST_CASE("RequestCDDSerial::from_string", "[from_string]") { TEST_CASE("RequestCDDSerial::from_string", "[from_string]") {
// good case // good case
std::string good = std::string good = "{"
"{"
"\"message_reference\": 100000," "\"message_reference\": 100000,"
"\"type\": \"request cdd serial\"" "\"type\": \"request cdd serial\""
"}"; "}";
@ -78,7 +76,8 @@ TEST_CASE( "RequestCDDC::from_string", "[from_string]" ) {
TEST_CASE("RequestMKCs::from_string", "[from_string]") { TEST_CASE("RequestMKCs::from_string", "[from_string]") {
// good case // good case
auto res = RequestMKCs::from_string( "{" auto res =
RequestMKCs::from_string("{"
"\"denominations\": [1, 2, 5]," "\"denominations\": [1, 2, 5],"
"\"message_reference\": 100002," "\"message_reference\": 100002,"
"\"mint_key_ids\": []," "\"mint_key_ids\": [],"
@ -106,7 +105,8 @@ TEST_CASE( "RequestMKCs::from_string", "[from_string]" ) {
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
// invalid attribute name // invalid attribute name
res = RequestMKCs::from_string("{" res =
RequestMKCs::from_string("{"
"\"denominations\": [1, 2, 5]," "\"denominations\": [1, 2, 5],"
"\"x_message_reference\": 100002," // WRONG NAME "\"x_message_reference\": 100002," // WRONG NAME
"\"mint_key_ids\": []," "\"mint_key_ids\": [],"
@ -122,13 +122,14 @@ TEST_CASE( "RequestMKCs::from_string", "[from_string]" ) {
"\"type\": \"request wrong type\"" "\"type\": \"request wrong type\""
"}"); "}");
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
} }
TEST_CASE("Blind::from_json", "[from_string]") { TEST_CASE("Blind::from_json", "[from_string]") {
auto good = crow::json::load("{" auto good = crow::json::load(
"\"blinded_payload_hash\": \"924edb672c3345492f38341ff86b57181da4c673ef...\"," "{"
"\"blinded_payload_hash\": "
"\"924edb672c3345492f38341ff86b57181da4c673ef...\","
"\"mint_key_id\": \"1ceb977bb531c65f133ab8b0d60862b17369d96\"," "\"mint_key_id\": \"1ceb977bb531c65f133ab8b0d60862b17369d96\","
"\"reference\": \"a0\"," "\"reference\": \"a0\","
"\"type\": \"blinded payload hash\"" "\"type\": \"blinded payload hash\""
@ -141,9 +142,9 @@ TEST_CASE( "Blind::from_json", "[from_string]" ) {
REQUIRE(res->mint_key_id == "1ceb977bb531c65f133ab8b0d60862b17369d96"); REQUIRE(res->mint_key_id == "1ceb977bb531c65f133ab8b0d60862b17369d96");
REQUIRE(res->reference == "a0"); REQUIRE(res->reference == "a0");
// bad cases // bad cases
// wrong_type["blinded_payload_hash"]= "924edb672c3345492f38341ff86b57181da4c673ef..."; // wrong_type["blinded_payload_hash"]=
// wrong_type["mint_key_id"]= "1ceb977bb531c65f133ab8b0d60862b17369d96"; // "924edb672c3345492f38341ff86b57181da4c673ef..."; wrong_type["mint_key_id"]=
// wrong_type["reference"] = "a0"; // "1ceb977bb531c65f133ab8b0d60862b17369d96"; wrong_type["reference"] = "a0";
// wrong_type["type"]= "wrong type"; // wrong_type["type"]= "wrong type";
// res = Blind::from_json(wrong_type); // res = Blind::from_json(wrong_type);
@ -151,22 +152,26 @@ TEST_CASE( "Blind::from_json", "[from_string]" ) {
TEST_CASE("RequestMint::from_string", "[from_string]") { TEST_CASE("RequestMint::from_string", "[from_string]") {
// good case // good case
auto res = RequestMint::from_string( "{" auto res = RequestMint::from_string(
"{"
"\"blinds\": [" "\"blinds\": ["
"{" "{"
"\"blinded_payload_hash\": \"924edb672c3345492f38341ff86b57181da4c673ef...\"," "\"blinded_payload_hash\": "
"\"924edb672c3345492f38341ff86b57181da4c673ef...\","
"\"mint_key_id\": \"1ceb977bb531c65f133ab8b0d60862b17369d96\"," "\"mint_key_id\": \"1ceb977bb531c65f133ab8b0d60862b17369d96\","
"\"reference\": \"a0\"," "\"reference\": \"a0\","
"\"type\": \"blinded payload hash\"" "\"type\": \"blinded payload hash\""
"}," "},"
"{" "{"
"\"blinded_payload_hash\": \"95db92e1c46ebea5edec5e508a831263de6fb78b4c...\"," "\"blinded_payload_hash\": "
"\"95db92e1c46ebea5edec5e508a831263de6fb78b4c...\","
"\"mint_key_id\": \"f2864e5cd937dbaa4825e73a81062de162143682\"," "\"mint_key_id\": \"f2864e5cd937dbaa4825e73a81062de162143682\","
"\"reference\": \"a1\"," "\"reference\": \"a1\","
"\"type\": \"blinded payload hash\"" "\"type\": \"blinded payload hash\""
"}," "},"
"{" "{"
"\"blinded_payload_hash\": \"10afac98ac43eb40e996c621d5db4d2238348e3f74...\"," "\"blinded_payload_hash\": "
"\"10afac98ac43eb40e996c621d5db4d2238348e3f74...\","
"\"mint_key_id\": \"897a16bf12bd9ba474ef7be0e3a53553a7b4ece8\"," "\"mint_key_id\": \"897a16bf12bd9ba474ef7be0e3a53553a7b4ece8\","
"\"reference\": \"a2\"," "\"reference\": \"a2\","
"\"type\": \"blinded payload hash\"" "\"type\": \"blinded payload hash\""
@ -187,7 +192,8 @@ TEST_CASE( "RequestMint::from_string", "[from_string]" ) {
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
// invalid type // invalid type
res = RequestMint::from_string( "{" res = RequestMint::from_string(
"{"
"\"blinds\": []," "\"blinds\": [],"
"\"message_reference\": 100003," "\"message_reference\": 100003,"
"\"transaction_reference\": \"b2221a58008a05a6c4647159c324c985\"," "\"transaction_reference\": \"b2221a58008a05a6c4647159c324c985\","
@ -196,7 +202,8 @@ TEST_CASE( "RequestMint::from_string", "[from_string]" ) {
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
// invalid attribute name // invalid attribute name
res = RequestMint::from_string("{" res = RequestMint::from_string(
"{"
"\"blinds\": []," "\"blinds\": [],"
"\"x_message_reference\": 100003," "\"x_message_reference\": 100003,"
"\"transaction_reference\": \"b2221a58008a05a6c4647159c324c985\"," "\"transaction_reference\": \"b2221a58008a05a6c4647159c324c985\","
@ -205,7 +212,8 @@ TEST_CASE( "RequestMint::from_string", "[from_string]" ) {
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
// invalid attribute type (not an array as expected) // invalid attribute type (not an array as expected)
res = RequestMint::from_string("{" res = RequestMint::from_string(
"{"
"\"blinds\": 1," "\"blinds\": 1,"
"\"message_reference\": 100003," "\"message_reference\": 100003,"
"\"transaction_reference\": \"b2221a58008a05a6c4647159c324c985\"," "\"transaction_reference\": \"b2221a58008a05a6c4647159c324c985\","
@ -219,7 +227,8 @@ TEST_CASE( "RequestRenew::from_string", "[from_string]" ) {
"{" "{"
" \"blinds\": [" " \"blinds\": ["
" {" " {"
" \"blinded_payload_hash\": \"7ed0cda1c1b36f544514b12848b8436974b7b9f6c7...\"," " \"blinded_payload_hash\": "
"\"7ed0cda1c1b36f544514b12848b8436974b7b9f6c7...\","
" \"mint_key_id\": \"f2864e5cd937dbaa4825e73a81062de162143682\"," " \"mint_key_id\": \"f2864e5cd937dbaa4825e73a81062de162143682\","
" \"reference\": \"b0\"," " \"reference\": \"b0\","
" \"type\": \"blinded payload hash\"" " \"type\": \"blinded payload hash\""
@ -247,7 +256,8 @@ TEST_CASE( "RequestRenew::from_string", "[from_string]" ) {
REQUIRE(res.has_value() == true); REQUIRE(res.has_value() == true);
// invalid attribute name // invalid attribute name
res = RequestRenew::from_string("{" res = RequestRenew::from_string(
"{"
"\"blinds\": []," "\"blinds\": [],"
"\"coins\": []," "\"coins\": [],"
"\"x_message_reference\": 100003," "\"x_message_reference\": 100003,"
@ -257,7 +267,8 @@ TEST_CASE( "RequestRenew::from_string", "[from_string]" ) {
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
// invalid attribute type (not an array as expected) // invalid attribute type (not an array as expected)
res = RequestRenew::from_string("{" res = RequestRenew::from_string(
"{"
"\"blinds\": 1," "\"blinds\": 1,"
"\"coins\": []," "\"coins\": [],"
"\"message_reference\": 100003," "\"message_reference\": 100003,"
@ -269,7 +280,8 @@ TEST_CASE( "RequestRenew::from_string", "[from_string]" ) {
TEST_CASE("RequestResume::from_string", "[from_string]") { TEST_CASE("RequestResume::from_string", "[from_string]") {
// good case // good case
auto res = RequestResume::from_string( "{" auto res = RequestResume::from_string(
"{"
"\"message_reference\": 100005," "\"message_reference\": 100005,"
"\"transaction_reference\": \"ad45f23d3b1a11df587fd2803bab6c39\"," "\"transaction_reference\": \"ad45f23d3b1a11df587fd2803bab6c39\","
"\"type\": \"request resume\"" "\"type\": \"request resume\""
@ -284,7 +296,8 @@ TEST_CASE( "RequestResume::from_string", "[from_string]" ) {
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
// invalid type // invalid type
res = RequestResume::from_string( "{" res = RequestResume::from_string(
"{"
"\"message_reference\": 100005," "\"message_reference\": 100005,"
"\"transaction_reference\": \"ad45f23d3b1a11df587fd2803bab6c39\"," "\"transaction_reference\": \"ad45f23d3b1a11df587fd2803bab6c39\","
"\"type\": \"Wrong type\"" "\"type\": \"Wrong type\""
@ -294,7 +307,8 @@ TEST_CASE( "RequestResume::from_string", "[from_string]" ) {
// invalid attribute name // invalid attribute name
res = RequestResume::from_string("{" res = RequestResume::from_string("{"
"\"message_reference\": 100005," "\"message_reference\": 100005,"
"\"WRONG_ATTR_transaction_reference\": \"ad45f23d3b1a11df587fd2803bab6c39\"," "\"WRONG_ATTR_transaction_reference\": "
"\"ad45f23d3b1a11df587fd2803bab6c39\","
"\"type\": \"request resume\"" "\"type\": \"request resume\""
"}"); "}");
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
@ -302,7 +316,8 @@ TEST_CASE( "RequestResume::from_string", "[from_string]" ) {
TEST_CASE("RequestRedeem::from_string", "[from_string]") { TEST_CASE("RequestRedeem::from_string", "[from_string]") {
auto res = RequestRedeem::from_string( "{" auto res = RequestRedeem::from_string(
"{"
"\"coins\": [" "\"coins\": ["
"{" "{"
"\"payload\": {" "\"payload\": {"
@ -365,4 +380,3 @@ TEST_CASE( "RequestRedeem::from_string", "[from_string]" ) {
"}"); "}");
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
} }