|
| 1 | +/** |
| 2 | + * Copyright (c) 2011-2026 libbitcoin developers (see AUTHORS) |
| 3 | + * |
| 4 | + * This file is part of libbitcoin. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU Affero General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU Affero General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Affero General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | +#include "../../test.hpp" |
| 20 | +#include "electrum.hpp" |
| 21 | + |
| 22 | +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture) |
| 23 | + |
| 24 | +// server.banner |
| 25 | + |
| 26 | +using namespace system; |
| 27 | +static const code not_found{ server::error::not_found }; |
| 28 | +static const code target_overflow{ server::error::target_overflow }; |
| 29 | +static const code invalid_argument{ server::error::invalid_argument }; |
| 30 | + |
| 31 | +BOOST_AUTO_TEST_CASE(electrum__server_banner__jsonrpc_unspecified_no_aparams__dropped) |
| 32 | +{ |
| 33 | + BOOST_CHECK(handshake()); |
| 34 | + |
| 35 | + // params[] required in json 1.0, server drops connection for invalid json-rpc. |
| 36 | + const auto response = get(R"({"id":42,"method":"server.banner"})" "\n"); |
| 37 | + BOOST_CHECK(response.at("dropped").as_bool()); |
| 38 | +} |
| 39 | + |
| 40 | +BOOST_AUTO_TEST_CASE(electrum__server_banner__jsonrpc_unspecified_named_aparams__dropped) |
| 41 | +{ |
| 42 | + BOOST_CHECK(handshake()); |
| 43 | + |
| 44 | + // params{} disallowed in json 1.0, server drops connection for invalid json-rpc. |
| 45 | + const auto response = get(R"({"id":42,"method":"server.banner","params":{}})" "\n"); |
| 46 | + BOOST_CHECK(response.at("dropped").as_bool()); |
| 47 | +} |
| 48 | + |
| 49 | +BOOST_AUTO_TEST_CASE(electrum__server_banner__jsonrpc_unspecified_empty_params__expected) |
| 50 | +{ |
| 51 | + BOOST_CHECK(handshake()); |
| 52 | + |
| 53 | + const auto response = get(R"({"id":42,"method":"server.banner","params":[]})" "\n"); |
| 54 | + BOOST_CHECK_EQUAL(response.at("result").as_string(), "banner_message"); |
| 55 | +} |
| 56 | + |
| 57 | +BOOST_AUTO_TEST_CASE(electrum__server_banner__jsonrpc_1__expected) |
| 58 | +{ |
| 59 | + BOOST_CHECK(handshake()); |
| 60 | + |
| 61 | + const auto response = get(R"({"jsonrpc":"1.0","id":42,"method":"server.banner","params":[]})" "\n"); |
| 62 | + BOOST_CHECK_EQUAL(response.at("result").as_string(), "banner_message"); |
| 63 | +} |
| 64 | + |
| 65 | +BOOST_AUTO_TEST_CASE(electrum__server_banner__jsonrpc_2__expected) |
| 66 | +{ |
| 67 | + BOOST_CHECK(handshake()); |
| 68 | + |
| 69 | + const auto response = get(R"({"jsonrpc":"2.0","id":42,"method":"server.banner"})" "\n"); |
| 70 | + BOOST_CHECK_EQUAL(response.at("result").as_string(), "banner_message"); |
| 71 | +} |
| 72 | + |
| 73 | +// server.donation_address |
| 74 | + |
| 75 | +BOOST_AUTO_TEST_CASE(electrum__server_donation_address__jsonrpc_1__expected) |
| 76 | +{ |
| 77 | + BOOST_CHECK(handshake()); |
| 78 | + |
| 79 | + const auto response = get(R"({"jsonrpc":"1.0","id":43,"method":"server.donation_address","params":[]})" "\n"); |
| 80 | + BOOST_CHECK_EQUAL(response.at("result").as_string(), "donation_address"); |
| 81 | +} |
| 82 | + |
| 83 | +BOOST_AUTO_TEST_CASE(electrum__server_donation_address__jsonrpc_2__expected) |
| 84 | +{ |
| 85 | + BOOST_CHECK(handshake()); |
| 86 | + |
| 87 | + const auto response = get(R"({"jsonrpc":"2.0","id":43,"method":"server.donation_address"})" "\n"); |
| 88 | + BOOST_CHECK_EQUAL(response.at("result").as_string(), "donation_address"); |
| 89 | +} |
| 90 | + |
| 91 | +BOOST_AUTO_TEST_SUITE_END() |
0 commit comments