@@ -38,6 +38,17 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_balance__no_address_index_
3838 BOOST_REQUIRE_EQUAL (response.at (" error" ).as_object ().at (" code" ).as_int64 (), not_implemented.value ());
3939}
4040
41+ BOOST_AUTO_TEST_CASE (electrum__blockchain_address_get_history__no_address_index__not_implemented)
42+ {
43+ BOOST_REQUIRE (!query_.address_enabled ());
44+ BOOST_REQUIRE (handshake (electrum::version::v1_0));
45+
46+ const auto request = R"( {"id":1001,"method":"blockchain.address.get_history","params":["%1%"]})" " \n " ;
47+ const auto response = get ((boost::format (request) % " 1JqDybm2nWTENrHvMyafbSXXtTk5Uv5QAn" ).str ());
48+ REQUIRE_NO_THROW_TRUE (response.at (" error" ).as_object ().at (" code" ).is_int64 ());
49+ BOOST_REQUIRE_EQUAL (response.at (" error" ).as_object ().at (" code" ).as_int64 (), not_implemented.value ());
50+ }
51+
4152BOOST_AUTO_TEST_SUITE_END ()
4253
4354BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_ten_block_setup_fixture)
@@ -102,14 +113,90 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_balance__confirmed_and_unc
102113 const auto & result = response.at (" result" ).as_object ();
103114 REQUIRE_NO_THROW_TRUE (result.at (" confirmed" ).is_int64 ());
104115 REQUIRE_NO_THROW_TRUE (result.at (" unconfirmed" ).is_int64 ());
105- BOOST_REQUIRE_EQUAL (result.at (" confirmed" ).as_int64 (), 0x09 ); // bogus_block11
116+ BOOST_REQUIRE_EQUAL (result.at (" confirmed" ).as_int64 (), 0x09 ); // bogus_block10
106117
107118 // Currently unconfirmed ALWAYS returns zero (no graph to order conflicts).
108119 BOOST_REQUIRE_EQUAL (result.at (" unconfirmed" ).as_int64 (), 0x00 );
109120 // //BOOST_REQUIRE_EQUAL(result.at("unconfirmed").as_int64(), 0x10 + 0x11 + 0x12); // bogus_block11
110121}
111122
112123// blockchain.address.get_history
124+
125+ BOOST_AUTO_TEST_CASE (electrum__blockchain_address_get_history__missing_arguments__dropped)
126+ {
127+ BOOST_REQUIRE (query_.address_enabled ());
128+ BOOST_REQUIRE (handshake (electrum::version::v1_0));
129+
130+ const auto response = get (R"( {"id":1002,"method":"blockchain.address.get_history","params":[]})" " \n " );
131+ REQUIRE_NO_THROW_TRUE (response.at (" dropped" ).as_bool ());
132+ }
133+
134+ BOOST_AUTO_TEST_CASE (electrum__blockchain_address_get_history__empty_v1_3__wrong_version)
135+ {
136+ BOOST_REQUIRE (handshake (electrum::version::v1_3));
137+
138+ const auto response = get (R"( {"id":1003,"method":"blockchain.address.get_history","params":[""]})" " \n " );
139+ REQUIRE_NO_THROW_TRUE (response.at (" error" ).as_object ().at (" code" ).is_int64 ());
140+ BOOST_REQUIRE_EQUAL (response.at (" error" ).as_object ().at (" code" ).as_int64 (), wrong_version.value ());
141+ }
142+
143+ BOOST_AUTO_TEST_CASE (electrum__blockchain_address_get_history__invalid_address__invalid_argument)
144+ {
145+ BOOST_REQUIRE (handshake (electrum::version::v1_1));
146+
147+ const auto response = get (R"( {"id":1004,"method":"blockchain.address.get_history","params":["invalid"]})" " \n " );
148+ REQUIRE_NO_THROW_TRUE (response.at (" error" ).as_object ().at (" code" ).is_int64 ());
149+ BOOST_REQUIRE_EQUAL (response.at (" error" ).as_object ().at (" code" ).as_int64 (), invalid_argument.value ());
150+ }
151+
152+ BOOST_AUTO_TEST_CASE (electrum__blockchain_address_get_history__not_found_address__empty)
153+ {
154+ BOOST_REQUIRE (handshake (electrum::version::v1_0));
155+
156+ const auto request = R"( {"id":1005,"method":"blockchain.address.get_history","params":["%1%"]})" " \n " ;
157+ const auto response = get ((boost::format (request) % " 1JqDybm2nWTENrHvMyafbSXXtTk5Uv5QAn" ).str ());
158+ REQUIRE_NO_THROW_TRUE (response.at (" result" ).as_array ().empty ());
159+ }
160+
161+ BOOST_AUTO_TEST_CASE (electrum__blockchain_address_get_history__confirmed_address__expected)
162+ {
163+ BOOST_REQUIRE (handshake (electrum::version::v1_0));
164+
165+ // Add one confirmed p2sh/p2kh block and one unconfirmed (mirrors the get_balance confirmed test).
166+ BOOST_REQUIRE (query_.set (test::bogus_block10, database::context{ 0 , 10 , 0 }, false , false ));
167+ BOOST_REQUIRE (query_.set (test::bogus_block11, database::context{ 0 , 11 , 0 }, false , false ));
168+ BOOST_REQUIRE (query_.set (test::bogus_block12, database::context{ 0 , 12 , 0 }, false , false ));
169+ BOOST_REQUIRE (query_.push_confirmed (query_.to_header (test::bogus_block10.hash ()), true ));
170+
171+ const auto request = R"( {"id":1006,"method":"blockchain.address.get_history","params":["%1%"]})" " \n " ;
172+ const auto response = get ((boost::format (request) % " 1BaMPFdqMUQ46BV8iRcwbVfsam57oBLMM" ).str ());
173+ REQUIRE_NO_THROW_TRUE (response.at (" result" ).is_array ());
174+
175+ const auto & history = response.at (" result" ).as_array ();
176+ BOOST_REQUIRE_EQUAL (history.size (), 3u );
177+
178+ const auto hash1 = test::bogus_block10.transactions_ptr ()->at (1 )->hash (false );
179+ const auto & tx1 = history.at (0 ).as_object ();
180+ REQUIRE_NO_THROW_TRUE (tx1.at (" height" ).is_int64 ());
181+ REQUIRE_NO_THROW_TRUE (tx1.at (" tx_hash" ).is_string ());
182+ BOOST_CHECK_EQUAL (tx1.at (" height" ).as_int64 (), 10 );
183+ BOOST_CHECK_EQUAL (tx1.at (" tx_hash" ).as_string (), encode_hash (hash1));
184+
185+ const auto hash2 = test::bogus_block11.transactions_ptr ()->at (0 )->hash (false );
186+ const auto & tx2 = history.at (1 ).as_object ();
187+ REQUIRE_NO_THROW_TRUE (tx2.at (" height" ).is_int64 ());
188+ REQUIRE_NO_THROW_TRUE (tx2.at (" tx_hash" ).is_string ());
189+ BOOST_CHECK_EQUAL (tx2.at (" height" ).as_int64 (), 0 ); // rooted
190+ BOOST_CHECK_EQUAL (tx2.at (" tx_hash" ).as_string (), encode_hash (hash2));
191+
192+ const auto hash3 = test::bogus_block12.transactions_ptr ()->at (0 )->hash (false );
193+ const auto & tx3 = history.at (2 ).as_object ();
194+ REQUIRE_NO_THROW_TRUE (tx3.at (" height" ).is_int64 ());
195+ REQUIRE_NO_THROW_TRUE (tx3.at (" tx_hash" ).is_string ());
196+ BOOST_CHECK_EQUAL (tx3.at (" height" ).as_int64 (), -1 ); // not rooted
197+ BOOST_CHECK_EQUAL (tx3.at (" tx_hash" ).as_string (), encode_hash (hash3));
198+ }
199+
113200// blockchain.address.get_mempool
114201// blockchain.address.list_unspent
115202// blockchain.address.subscribe
0 commit comments