|
19 | 19 | #include "../../test.hpp" |
20 | 20 | #include "electrum.hpp" |
21 | 21 |
|
22 | | -BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_three_block_confirmed_address_setup_fixture) |
| 22 | +using namespace system; |
| 23 | +static const code not_found{ server::error::not_found }; |
| 24 | +static const code wrong_version{ server::error::wrong_version }; |
| 25 | +static const code not_implemented{ server::error::not_implemented }; |
| 26 | +static const code invalid_argument{ server::error::invalid_argument }; |
| 27 | + |
| 28 | +BOOST_FIXTURE_TEST_SUITE(electrum_disabled_address_tests, electrum_disabled_address_index_setup_fixture) |
| 29 | + |
| 30 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_balance__no_address_index__not_implemented) |
| 31 | +{ |
| 32 | + BOOST_REQUIRE(!query_.address_enabled()); |
| 33 | + BOOST_REQUIRE(handshake(electrum::version::v1_0)); |
| 34 | + |
| 35 | + const auto request = R"({"id":901,"method":"blockchain.address.get_balance","params":["%1%"]})" "\n"; |
| 36 | + const auto response = get((boost::format(request) % "1JqDybm2nWTENrHvMyafbSXXtTk5Uv5QAn").str()); |
| 37 | + REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 38 | + BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), not_implemented.value()); |
| 39 | +} |
| 40 | + |
| 41 | +BOOST_AUTO_TEST_SUITE_END() |
| 42 | + |
| 43 | +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_ten_block_setup_fixture) |
23 | 44 |
|
24 | 45 | // blockchain.address.get_balance |
| 46 | + |
| 47 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_balance__missing_arguments__dropped) |
| 48 | +{ |
| 49 | + BOOST_REQUIRE(query_.address_enabled()); |
| 50 | + BOOST_REQUIRE(handshake(electrum::version::v1_0)); |
| 51 | + |
| 52 | + const auto response = get(R"({"id":901,"method":"blockchain.address.get_balance","params":[]})" "\n"); |
| 53 | + REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool()); |
| 54 | +} |
| 55 | + |
| 56 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_balance__empty_v1_3__wrong_version) |
| 57 | +{ |
| 58 | + BOOST_REQUIRE(handshake(electrum::version::v1_3)); |
| 59 | + |
| 60 | + const auto response = get(R"({"id":902,"method":"blockchain.address.get_balance","params":[""]})" "\n"); |
| 61 | + REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 62 | + BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), wrong_version.value()); |
| 63 | +} |
| 64 | + |
| 65 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_balance__invalid_address__invalid_argument) |
| 66 | +{ |
| 67 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 68 | + |
| 69 | + const auto response = get(R"({"id":903,"method":"blockchain.address.get_balance","params":["invalid"]})" "\n"); |
| 70 | + REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 71 | + BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), invalid_argument.value()); |
| 72 | +} |
| 73 | + |
| 74 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_balance__not_found_address__zero) |
| 75 | +{ |
| 76 | + BOOST_REQUIRE(handshake(electrum::version::v1_0)); |
| 77 | + |
| 78 | + const auto request = R"({"id":904,"method":"blockchain.address.get_balance","params":["%1%"]})" "\n"; |
| 79 | + const auto response = get((boost::format(request) % "1JqDybm2nWTENrHvMyafbSXXtTk5Uv5QAn").str()); |
| 80 | + REQUIRE_NO_THROW_TRUE(response.at("result").is_object()); |
| 81 | + |
| 82 | + const auto& result = response.at("result").as_object(); |
| 83 | + REQUIRE_NO_THROW_TRUE(result.at("confirmed").is_int64()); |
| 84 | + REQUIRE_NO_THROW_TRUE(result.at("unconfirmed").is_int64()); |
| 85 | + BOOST_REQUIRE_EQUAL(result.at("confirmed").as_int64(), 0x00); |
| 86 | + BOOST_REQUIRE_EQUAL(result.at("unconfirmed").as_int64(), 0x00); |
| 87 | +} |
| 88 | + |
| 89 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_balance__confirmed_and_unconfirmed_address__expected) |
| 90 | +{ |
| 91 | + BOOST_REQUIRE(handshake(electrum::version::v1_0)); |
| 92 | + |
| 93 | + // Add one confirmed p2sh/p2kh block and one unconfirmed. |
| 94 | + BOOST_REQUIRE(query_.set(test::bogus_block10, database::context{ 0, 10, 0 }, false, false)); |
| 95 | + BOOST_REQUIRE(query_.set(test::bogus_block11, database::context{ 0, 11, 0 }, false, false)); |
| 96 | + BOOST_REQUIRE(query_.push_confirmed(query_.to_header(test::bogus_block10.hash()), true)); |
| 97 | + |
| 98 | + const auto request = R"({"id":905,"method":"blockchain.address.get_balance","params":["%1%"]})" "\n"; |
| 99 | + const auto response = get((boost::format(request) % "1BaMPFdqMUQ46BV8iRcwbVfsam57oBLMM").str()); |
| 100 | + REQUIRE_NO_THROW_TRUE(response.at("result").is_object()); |
| 101 | + |
| 102 | + const auto& result = response.at("result").as_object(); |
| 103 | + REQUIRE_NO_THROW_TRUE(result.at("confirmed").is_int64()); |
| 104 | + REQUIRE_NO_THROW_TRUE(result.at("unconfirmed").is_int64()); |
| 105 | + BOOST_REQUIRE_EQUAL(result.at("confirmed").as_int64(), 0x09); // bogus_block11 |
| 106 | + |
| 107 | + // Currently unconfirmed ALWAYS returns zero (no graph to order conflicts). |
| 108 | + BOOST_REQUIRE_EQUAL(result.at("unconfirmed").as_int64(), 0x00); |
| 109 | + ////BOOST_REQUIRE_EQUAL(result.at("unconfirmed").as_int64(), 0x10 + 0x11 + 0x12); // bogus_block11 |
| 110 | +} |
| 111 | + |
25 | 112 | // blockchain.address.get_history |
26 | 113 | // blockchain.address.get_mempool |
27 | 114 | // blockchain.address.list_unspent |
|
0 commit comments