|
17 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 | */ |
19 | 19 | #include "../../test.hpp" |
| 20 | +#include "../blocks.hpp" |
20 | 21 | #include "electrum.hpp" |
| 22 | +#include <boost/format.hpp> |
21 | 23 |
|
22 | 24 | BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture) |
23 | 25 |
|
| 26 | +// blockchain.transaction.broadcast |
| 27 | + |
| 28 | +using namespace system; |
| 29 | +static const code invalid_argument{ server::error::invalid_argument }; |
| 30 | +static const code unconfirmable_transaction{ server::error::unconfirmable_transaction }; |
| 31 | + |
| 32 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_broadcast__empty__invalid_argument) |
| 33 | +{ |
| 34 | + BOOST_CHECK(handshake()); |
| 35 | + |
| 36 | + const auto response = get(R"({"id":74,"method":"blockchain.transaction.broadcast","params":[""]})" "\n"); |
| 37 | + BOOST_CHECK_EQUAL(response.at("error").as_object().at("code").as_int64(), invalid_argument.value()); |
| 38 | +} |
| 39 | + |
| 40 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_broadcast__invalid_encoding__invalid_argument) |
| 41 | +{ |
| 42 | + BOOST_CHECK(handshake()); |
| 43 | + |
| 44 | + const auto response = get(R"({"id":75,"method":"blockchain.transaction.broadcast","params":["deadbeef"]})" "\n"); |
| 45 | + BOOST_CHECK_EQUAL(response.at("error").as_object().at("code").as_int64(), invalid_argument.value()); |
| 46 | +} |
| 47 | + |
| 48 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_broadcast__invalid_tx__invalid_argument) |
| 49 | +{ |
| 50 | + BOOST_CHECK(handshake()); |
| 51 | + |
| 52 | + const auto response = get(R"({"id":76,"method":"blockchain.transaction.broadcast","params":["0100000001"]})" "\n"); |
| 53 | + BOOST_CHECK_EQUAL(response.at("error").as_object().at("code").as_int64(), invalid_argument.value()); |
| 54 | +} |
| 55 | + |
| 56 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_broadcast__genesis_coinbase__unconfirmable_transaction) |
| 57 | +{ |
| 58 | + BOOST_CHECK(handshake()); |
| 59 | + |
| 60 | + const auto tx0_text = encode_base16(genesis.transactions_ptr()->front()->to_data(true)); |
| 61 | + constexpr auto request = R"({"id":73,"method":"blockchain.transaction.broadcast","params":["%1%"]})" "\n"; |
| 62 | + const auto response = get((boost::format(request) % tx0_text).str()); |
| 63 | + BOOST_CHECK_EQUAL(response.at("error").as_object().at("code").as_int64(), unconfirmable_transaction.value()); |
| 64 | +} |
| 65 | + |
24 | 66 | BOOST_AUTO_TEST_SUITE_END() |
0 commit comments