|
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 | +static const std::string bogus_script_hash{ "9c2c84a6cf9809e08af19557e28d38257e6fee6981269760637a5f9dfb000b05" }; |
| 28 | +static const std::string found_script_hash{ "bad83872c90886be19b98734fd16741611efcd9f5de699c14b712675eec682f5" }; |
| 29 | + |
| 30 | +BOOST_FIXTURE_TEST_SUITE(electrum_disabled_address_tests, electrum_disabled_address_index_setup_fixture) |
| 31 | + |
| 32 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_balance__no_address_index__not_implemented) |
| 33 | +{ |
| 34 | + BOOST_REQUIRE(!query_.address_enabled()); |
| 35 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 36 | + |
| 37 | + const auto request = R"({"id":901,"method":"blockchain.scripthash.get_balance","params":["%1%"]})" "\n"; |
| 38 | + const auto response = get((boost::format(request) % bogus_script_hash).str()); |
| 39 | + REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 40 | + BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), not_implemented.value()); |
| 41 | +} |
| 42 | + |
| 43 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_history__no_address_index__not_implemented) |
| 44 | +{ |
| 45 | + BOOST_REQUIRE(!query_.address_enabled()); |
| 46 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 47 | + |
| 48 | + const auto request = R"({"id":1001,"method":"blockchain.scripthash.get_history","params":["%1%"]})" "\n"; |
| 49 | + const auto response = get((boost::format(request) % bogus_script_hash).str()); |
| 50 | + REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 51 | + BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), not_implemented.value()); |
| 52 | +} |
| 53 | + |
| 54 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_mempool__no_address_index__not_implemented) |
| 55 | +{ |
| 56 | + BOOST_REQUIRE(!query_.address_enabled()); |
| 57 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 58 | + |
| 59 | + const auto request = R"({"id":1001,"method":"blockchain.scripthash.get_mempool","params":["%1%"]})" "\n"; |
| 60 | + const auto response = get((boost::format(request) % bogus_script_hash).str()); |
| 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(), not_implemented.value()); |
| 63 | +} |
| 64 | + |
| 65 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_list_unspent__no_address_index__not_implemented) |
| 66 | +{ |
| 67 | + BOOST_REQUIRE(!query_.address_enabled()); |
| 68 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 69 | + |
| 70 | + const auto request = R"({"id":1001,"method":"blockchain.scripthash.listunspent","params":["%1%"]})" "\n"; |
| 71 | + const auto response = get((boost::format(request) % bogus_script_hash).str()); |
| 72 | + REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 73 | + BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), not_implemented.value()); |
| 74 | +} |
| 75 | + |
| 76 | +BOOST_AUTO_TEST_SUITE_END() |
| 77 | + |
| 78 | +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_ten_block_setup_fixture) |
23 | 79 |
|
24 | 80 | // blockchain.scripthash.get_balance |
| 81 | + |
| 82 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_balance__missing_arguments__dropped) |
| 83 | +{ |
| 84 | + BOOST_REQUIRE(query_.address_enabled()); |
| 85 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 86 | + |
| 87 | + const auto response = get(R"({"id":901,"method":"blockchain.scripthash.get_balance","params":[]})" "\n"); |
| 88 | + REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool()); |
| 89 | +} |
| 90 | + |
| 91 | +// Not yet. |
| 92 | +////BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_balance__empty_v1_7__wrong_version) |
| 93 | +////{ |
| 94 | +//// BOOST_REQUIRE(handshake(electrum::version::v1_7)); |
| 95 | +//// |
| 96 | +//// const auto response = get(R"({"id":902,"method":"blockchain.scripthash.get_balance","params":[""]})" "\n"); |
| 97 | +//// REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 98 | +//// BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), wrong_version.value()); |
| 99 | +////} |
| 100 | + |
| 101 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_balance__invalid_address__invalid_argument) |
| 102 | +{ |
| 103 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 104 | + |
| 105 | + const auto response = get(R"({"id":903,"method":"blockchain.scripthash.get_balance","params":["invalid"]})" "\n"); |
| 106 | + REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 107 | + BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), invalid_argument.value()); |
| 108 | +} |
| 109 | + |
| 110 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_balance__not_found_address__zero) |
| 111 | +{ |
| 112 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 113 | + |
| 114 | + const auto request = R"({"id":904,"method":"blockchain.scripthash.get_balance","params":["%1%"]})" "\n"; |
| 115 | + const auto response = get((boost::format(request) % bogus_script_hash).str()); |
| 116 | + REQUIRE_NO_THROW_TRUE(response.at("result").is_object()); |
| 117 | + |
| 118 | + const auto& result = response.at("result").as_object(); |
| 119 | + REQUIRE_NO_THROW_TRUE(result.at("confirmed").is_int64()); |
| 120 | + REQUIRE_NO_THROW_TRUE(result.at("unconfirmed").is_int64()); |
| 121 | + BOOST_REQUIRE_EQUAL(result.at("confirmed").as_int64(), 0x00); |
| 122 | + BOOST_REQUIRE_EQUAL(result.at("unconfirmed").as_int64(), 0x00); |
| 123 | +} |
| 124 | + |
| 125 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_balance__confirmed_and_unconfirmed_address__expected) |
| 126 | +{ |
| 127 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 128 | + |
| 129 | + // Add one confirmed p2sh/p2kh block and one unconfirmed. |
| 130 | + BOOST_REQUIRE(query_.set(test::bogus_block10, database::context{ 0, 10, 0 }, false, false)); |
| 131 | + BOOST_REQUIRE(query_.set(test::bogus_block11, database::context{ 0, 11, 0 }, false, false)); |
| 132 | + BOOST_REQUIRE(query_.push_confirmed(query_.to_header(test::bogus_block10.hash()), true)); |
| 133 | + |
| 134 | + const auto request = R"({"id":905,"method":"blockchain.scripthash.get_balance","params":["%1%"]})" "\n"; |
| 135 | + const auto response = get((boost::format(request) % found_script_hash).str()); |
| 136 | + REQUIRE_NO_THROW_TRUE(response.at("result").is_object()); |
| 137 | + |
| 138 | + const auto& result = response.at("result").as_object(); |
| 139 | + REQUIRE_NO_THROW_TRUE(result.at("confirmed").is_int64()); |
| 140 | + REQUIRE_NO_THROW_TRUE(result.at("unconfirmed").is_int64()); |
| 141 | + BOOST_REQUIRE_EQUAL(result.at("confirmed").as_int64(), 0x09); // bogus_block10 |
| 142 | + |
| 143 | + // Currently unconfirmed ALWAYS returns zero (no graph to order conflicts). |
| 144 | + BOOST_REQUIRE_EQUAL(result.at("unconfirmed").as_int64(), 0x00); |
| 145 | + ////BOOST_REQUIRE_EQUAL(result.at("unconfirmed").as_int64(), 0x10 + 0x11 + 0x12); // bogus_block11 |
| 146 | +} |
| 147 | + |
25 | 148 | // blockchain.scripthash.get_history |
| 149 | + |
| 150 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_history__missing_arguments__dropped) |
| 151 | +{ |
| 152 | + BOOST_REQUIRE(query_.address_enabled()); |
| 153 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 154 | + |
| 155 | + const auto response = get(R"({"id":1002,"method":"blockchain.scripthash.get_history","params":[]})" "\n"); |
| 156 | + REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool()); |
| 157 | +} |
| 158 | + |
| 159 | +// Not yet. |
| 160 | +////BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_history__empty_v1_7__wrong_version) |
| 161 | +////{ |
| 162 | +//// BOOST_REQUIRE(handshake(electrum::version::v1_7)); |
| 163 | +//// |
| 164 | +//// const auto response = get(R"({"id":1003,"method":"blockchain.scripthash.get_history","params":[""]})" "\n"); |
| 165 | +//// REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 166 | +//// BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), wrong_version.value()); |
| 167 | +////} |
| 168 | + |
| 169 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_history__invalid_address__invalid_argument) |
| 170 | +{ |
| 171 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 172 | + |
| 173 | + const auto response = get(R"({"id":1004,"method":"blockchain.scripthash.get_history","params":["invalid"]})" "\n"); |
| 174 | + REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 175 | + BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), invalid_argument.value()); |
| 176 | +} |
| 177 | + |
| 178 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_history__not_found_address__empty) |
| 179 | +{ |
| 180 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 181 | + |
| 182 | + const auto request = R"({"id":1005,"method":"blockchain.scripthash.get_history","params":["%1%"]})" "\n"; |
| 183 | + const auto response = get((boost::format(request) % bogus_script_hash).str()); |
| 184 | + REQUIRE_NO_THROW_TRUE(response.at("result").as_array().empty()); |
| 185 | +} |
| 186 | + |
| 187 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_history__confirmed_and_unconfirmed_address__expected) |
| 188 | +{ |
| 189 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 190 | + |
| 191 | + // Add one confirmed p2sh/p2kh block and one unconfirmed (mirrors the get_balance confirmed test). |
| 192 | + BOOST_REQUIRE(query_.set(test::bogus_block10, database::context{ 0, 10, 0 }, false, false)); |
| 193 | + BOOST_REQUIRE(query_.set(test::bogus_block11, database::context{ 0, 11, 0 }, false, false)); |
| 194 | + BOOST_REQUIRE(query_.set(test::bogus_block12, database::context{ 0, 12, 0 }, false, false)); |
| 195 | + BOOST_REQUIRE(query_.push_confirmed(query_.to_header(test::bogus_block10.hash()), true)); |
| 196 | + |
| 197 | + const auto request = R"({"id":1006,"method":"blockchain.scripthash.get_history","params":["%1%"]})" "\n"; |
| 198 | + const auto response = get((boost::format(request) % found_script_hash).str()); |
| 199 | + REQUIRE_NO_THROW_TRUE(response.at("result").is_array()); |
| 200 | + |
| 201 | + const auto& history = response.at("result").as_array(); |
| 202 | + BOOST_REQUIRE_EQUAL(history.size(), 3u); |
| 203 | + |
| 204 | + const auto hash1 = test::bogus_block10.transactions_ptr()->at(1)->hash(false); |
| 205 | + const auto& tx1 = history.at(0).as_object(); |
| 206 | + REQUIRE_NO_THROW_TRUE(tx1.at("height").is_int64()); |
| 207 | + REQUIRE_NO_THROW_TRUE(tx1.at("tx_hash").is_string()); |
| 208 | + BOOST_REQUIRE_EQUAL(tx1.at("height").as_int64(), 10); |
| 209 | + BOOST_REQUIRE_EQUAL(tx1.at("tx_hash").as_string(), encode_hash(hash1)); |
| 210 | + |
| 211 | + const auto hash2 = test::bogus_block11.transactions_ptr()->at(0)->hash(false); |
| 212 | + const auto& tx2 = history.at(1).as_object(); |
| 213 | + REQUIRE_NO_THROW_TRUE(tx2.at("height").is_int64()); |
| 214 | + REQUIRE_NO_THROW_TRUE(tx2.at("tx_hash").is_string()); |
| 215 | + BOOST_REQUIRE_EQUAL(tx2.at("height").as_int64(), 0); // rooted |
| 216 | + BOOST_REQUIRE_EQUAL(tx2.at("tx_hash").as_string(), encode_hash(hash2)); |
| 217 | + |
| 218 | + const auto hash3 = test::bogus_block12.transactions_ptr()->at(0)->hash(false); |
| 219 | + const auto& tx3 = history.at(2).as_object(); |
| 220 | + REQUIRE_NO_THROW_TRUE(tx3.at("height").is_int64()); |
| 221 | + REQUIRE_NO_THROW_TRUE(tx3.at("tx_hash").is_string()); |
| 222 | + BOOST_REQUIRE_EQUAL(tx3.at("height").as_int64(), -1); // not rooted |
| 223 | + BOOST_REQUIRE_EQUAL(tx3.at("tx_hash").as_string(), encode_hash(hash3)); |
| 224 | +} |
| 225 | + |
26 | 226 | // blockchain.scripthash.get_mempool |
27 | | -// blockchain.scripthash.listunspent |
| 227 | + |
| 228 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_mempool__missing_arguments__dropped) |
| 229 | +{ |
| 230 | + BOOST_REQUIRE(query_.address_enabled()); |
| 231 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 232 | + |
| 233 | + const auto response = get(R"({"id":1002,"method":"blockchain.scripthash.get_mempool","params":[]})" "\n"); |
| 234 | + REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool()); |
| 235 | +} |
| 236 | + |
| 237 | +// Not yet. |
| 238 | +////BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_mempool__empty_v1_7__wrong_version) |
| 239 | +////{ |
| 240 | +//// BOOST_REQUIRE(handshake(electrum::version::v1_7)); |
| 241 | +//// |
| 242 | +//// const auto response = get(R"({"id":1003,"method":"blockchain.scripthash.get_mempool","params":[""]})" "\n"); |
| 243 | +//// REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 244 | +//// BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), wrong_version.value()); |
| 245 | +////} |
| 246 | + |
| 247 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_mempool__invalid_address__invalid_argument) |
| 248 | +{ |
| 249 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 250 | + |
| 251 | + const auto response = get(R"({"id":1004,"method":"blockchain.scripthash.get_mempool","params":["invalid"]})" "\n"); |
| 252 | + REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 253 | + BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), invalid_argument.value()); |
| 254 | +} |
| 255 | + |
| 256 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_mempool__not_found_address__empty) |
| 257 | +{ |
| 258 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 259 | + |
| 260 | + const auto request = R"({"id":1005,"method":"blockchain.scripthash.get_mempool","params":["%1%"]})" "\n"; |
| 261 | + const auto response = get((boost::format(request) % bogus_script_hash).str()); |
| 262 | + REQUIRE_NO_THROW_TRUE(response.at("result").as_array().empty()); |
| 263 | +} |
| 264 | + |
| 265 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_mempool__confirmed_and_unconfirmed_address__expected) |
| 266 | +{ |
| 267 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 268 | + |
| 269 | + // Add one confirmed p2sh/p2kh block and one unconfirmed (mirrors the get_balance confirmed test). |
| 270 | + BOOST_REQUIRE(query_.set(test::bogus_block10, database::context{ 0, 10, 0 }, false, false)); |
| 271 | + BOOST_REQUIRE(query_.set(test::bogus_block11, database::context{ 0, 11, 0 }, false, false)); |
| 272 | + BOOST_REQUIRE(query_.set(test::bogus_block12, database::context{ 0, 12, 0 }, false, false)); |
| 273 | + BOOST_REQUIRE(query_.push_confirmed(query_.to_header(test::bogus_block10.hash()), true)); |
| 274 | + |
| 275 | + const auto request = R"({"id":1006,"method":"blockchain.scripthash.get_mempool","params":["%1%"]})" "\n"; |
| 276 | + const auto response = get((boost::format(request) % found_script_hash).str()); |
| 277 | + REQUIRE_NO_THROW_TRUE(response.at("result").is_array()); |
| 278 | + |
| 279 | + const auto& history = response.at("result").as_array(); |
| 280 | + BOOST_REQUIRE_EQUAL(history.size(), 2u); |
| 281 | + |
| 282 | + const auto hash1 = test::bogus_block11.transactions_ptr()->at(0)->hash(false); |
| 283 | + const auto& tx1 = history.at(0).as_object(); |
| 284 | + REQUIRE_NO_THROW_TRUE(tx1.at("height").is_int64()); |
| 285 | + REQUIRE_NO_THROW_TRUE(tx1.at("tx_hash").is_string()); |
| 286 | + BOOST_REQUIRE_EQUAL(tx1.at("height").as_int64(), 0); // rooted |
| 287 | + BOOST_REQUIRE_EQUAL(tx1.at("tx_hash").as_string(), encode_hash(hash1)); |
| 288 | + |
| 289 | + const auto hash2 = test::bogus_block12.transactions_ptr()->at(0)->hash(false); |
| 290 | + const auto& tx2 = history.at(1).as_object(); |
| 291 | + REQUIRE_NO_THROW_TRUE(tx2.at("height").is_int64()); |
| 292 | + REQUIRE_NO_THROW_TRUE(tx2.at("tx_hash").is_string()); |
| 293 | + BOOST_REQUIRE_EQUAL(tx2.at("height").as_int64(), -1); // not rooted |
| 294 | + BOOST_REQUIRE_EQUAL(tx2.at("tx_hash").as_string(), encode_hash(hash2)); |
| 295 | +} |
| 296 | + |
| 297 | +// blockchain.scripthash.list_unspent |
| 298 | + |
| 299 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_list_unspent__missing_arguments__dropped) |
| 300 | +{ |
| 301 | + BOOST_REQUIRE(query_.address_enabled()); |
| 302 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 303 | + |
| 304 | + const auto response = get(R"({"id":1002,"method":"blockchain.scripthash.listunspent","params":[]})" "\n"); |
| 305 | + REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool()); |
| 306 | +} |
| 307 | + |
| 308 | +// Not yet. |
| 309 | +////BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_list_unspent__empty_v1_7__wrong_version) |
| 310 | +////{ |
| 311 | +//// BOOST_REQUIRE(handshake(electrum::version::v1_7)); |
| 312 | +//// |
| 313 | +//// const auto response = get(R"({"id":1003,"method":"blockchain.scripthash.listunspent","params":[""]})" "\n"); |
| 314 | +//// REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 315 | +//// BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), wrong_version.value()); |
| 316 | +////} |
| 317 | + |
| 318 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_list_unspent__invalid_address__invalid_argument) |
| 319 | +{ |
| 320 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 321 | + |
| 322 | + const auto response = get(R"({"id":1004,"method":"blockchain.scripthash.listunspent","params":["invalid"]})" "\n"); |
| 323 | + REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); |
| 324 | + BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), invalid_argument.value()); |
| 325 | +} |
| 326 | + |
| 327 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_list_unspent__not_found_address__empty) |
| 328 | +{ |
| 329 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 330 | + |
| 331 | + const auto request = R"({"id":1005,"method":"blockchain.scripthash.listunspent","params":["%1%"]})" "\n"; |
| 332 | + const auto response = get((boost::format(request) % bogus_script_hash).str()); |
| 333 | + REQUIRE_NO_THROW_TRUE(response.at("result").as_array().empty()); |
| 334 | +} |
| 335 | + |
| 336 | +BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_list_unspent__confirmed_and_unconfirmed_address__expected) |
| 337 | +{ |
| 338 | + BOOST_REQUIRE(handshake(electrum::version::v1_1)); |
| 339 | + |
| 340 | + // Add one confirmed p2sh/p2kh block and one unconfirmed (mirrors the get_balance confirmed test). |
| 341 | + BOOST_REQUIRE(query_.set(test::bogus_block10, database::context{ 0, 10, 0 }, false, false)); |
| 342 | + BOOST_REQUIRE(query_.set(test::bogus_block11, database::context{ 0, 11, 0 }, false, false)); |
| 343 | + BOOST_REQUIRE(query_.set(test::bogus_block12, database::context{ 0, 12, 0 }, false, false)); |
| 344 | + BOOST_REQUIRE(query_.push_confirmed(query_.to_header(test::bogus_block10.hash()), true)); |
| 345 | + |
| 346 | + const auto request = R"({"id":1006,"method":"blockchain.scripthash.listunspent","params":["%1%"]})" "\n"; |
| 347 | + const auto response = get((boost::format(request) % found_script_hash).str()); |
| 348 | + REQUIRE_NO_THROW_TRUE(response.at("result").is_array()); |
| 349 | + |
| 350 | + const auto& unspent = response.at("result").as_array(); |
| 351 | + BOOST_REQUIRE_EQUAL(unspent.size(), 4u); |
| 352 | + |
| 353 | + const auto hash10 = test::bogus_block10.transactions_ptr()->at(1)->hash(false); |
| 354 | + const auto& tx1 = unspent.at(0).as_object(); |
| 355 | + BOOST_REQUIRE_EQUAL(tx1.at("tx_hash").as_string(), encode_hash(hash10)); |
| 356 | + BOOST_REQUIRE_EQUAL(tx1.at("tx_pos").as_int64(), 0); // tx.output.index(0) |
| 357 | + BOOST_REQUIRE_EQUAL(tx1.at("height").as_int64(), 10); // confirmed |
| 358 | + BOOST_REQUIRE_EQUAL(tx1.at("value").as_int64(), 0x09); |
| 359 | + |
| 360 | + const auto hash11 = test::bogus_block11.transactions_ptr()->at(0)->hash(false); |
| 361 | + const auto& tx2 = unspent.at(1).as_object(); |
| 362 | + BOOST_REQUIRE_EQUAL(tx2.at("tx_hash").as_string(), encode_hash(hash11)); |
| 363 | + BOOST_REQUIRE_EQUAL(tx2.at("tx_pos").as_int64(), 0); // tx.output.index(0) |
| 364 | + BOOST_REQUIRE_EQUAL(tx2.at("height").as_int64(), 0); // unconfirmed |
| 365 | + BOOST_REQUIRE_EQUAL(tx2.at("value").as_int64(), 0x10); |
| 366 | + |
| 367 | + const auto hash12 = test::bogus_block12.transactions_ptr()->at(0)->hash(false); |
| 368 | + const auto& tx4 = unspent.at(2).as_object(); |
| 369 | + BOOST_REQUIRE_EQUAL(tx4.at("tx_hash").as_string(), encode_hash(hash12)); |
| 370 | + BOOST_REQUIRE_EQUAL(tx4.at("tx_pos").as_int64(), 0); // tx.output.index(0) |
| 371 | + BOOST_REQUIRE_EQUAL(tx4.at("height").as_int64(), 0); // unconfirmed |
| 372 | + BOOST_REQUIRE_EQUAL(tx4.at("value").as_int64(), 0x10); |
| 373 | + |
| 374 | + const auto& tx3 = unspent.at(3).as_object(); |
| 375 | + BOOST_REQUIRE_EQUAL(tx3.at("tx_hash").as_string(), encode_hash(hash11)); |
| 376 | + BOOST_REQUIRE_EQUAL(tx3.at("tx_pos").as_int64(), 1); // tx.output.index(1) |
| 377 | + BOOST_REQUIRE_EQUAL(tx3.at("height").as_int64(), 0); // unconfirmed |
| 378 | + BOOST_REQUIRE_EQUAL(tx3.at("value").as_int64(), 0x11); |
| 379 | + |
| 380 | + // Index is point arbitrary sort priority. |
| 381 | + const auto point11_0 = chain::point{ hash11, 0 }; |
| 382 | + const auto point11_1 = chain::point{ hash11, 1 }; |
| 383 | + const auto point12_0 = chain::point{ hash12, 0 }; |
| 384 | + BOOST_REQUIRE(point11_0 < point12_0); |
| 385 | + BOOST_REQUIRE(point12_0 < point11_1); |
| 386 | +} |
| 387 | + |
28 | 388 | // blockchain.scripthash.subscribe |
29 | 389 | // blockchain.scripthash.unsubscribe |
30 | 390 |
|
|
0 commit comments