@@ -51,9 +51,9 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_utxo_get_address__invalid_index__inval
5151{
5252 BOOST_REQUIRE (handshake (electrum::version::v1_0));
5353
54- constexpr auto hash = " 4444444444444444444444444444444444444444444444444444444444444444 " ;
54+ constexpr hash_digest hash{ 0x42 } ;
5555 const auto request = R"( {"id":901,"method":"blockchain.utxo.get_address","params":["%1%",-1]})" " \n " ;
56- const auto response = get ((boost::format (request) % hash).str ());
56+ const auto response = get ((boost::format (request) % encode_hash ( hash) ).str ());
5757 REQUIRE_NO_THROW_TRUE (response.at (" error" ).as_object ().at (" code" ).is_int64 ());
5858 BOOST_REQUIRE_EQUAL (response.at (" error" ).as_object ().at (" code" ).as_int64 (), invalid_argument.value ());
5959}
@@ -71,9 +71,9 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_utxo_get_address__tx_not_found__null)
7171{
7272 BOOST_REQUIRE (handshake (electrum::version::v1_0));
7373
74- constexpr auto hash = " 4444444444444444444444444444444444444444444444444444444444444444 " ;
74+ constexpr hash_digest hash{ 0x42 } ;
7575 const auto request = R"( {"id":901,"method":"blockchain.utxo.get_address","params":["%1%",0]})" " \n " ;
76- const auto response = get ((boost::format (request) % hash).str ());
76+ const auto response = get ((boost::format (request) % encode_hash ( hash) ).str ());
7777 REQUIRE_NO_THROW_TRUE (response.at (" result" ).is_null ());
7878}
7979
@@ -122,6 +122,95 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_utxo_get_address__p2sh__expected)
122122}
123123
124124// blockchain.outpoint.get_status
125+
126+ BOOST_AUTO_TEST_CASE (electrum__blockchain_outpoint_get_status__insufficient_version__wrong_version)
127+ {
128+ BOOST_REQUIRE (handshake (electrum::version::v1_6));
129+
130+ constexpr auto hash = " 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b" ;
131+ const auto request = R"( {"id":1101,"method":"blockchain.outpoint.get_status","params":["%1%",0]})" " \n " ;
132+ const auto response = get ((boost::format (request) % hash).str ());
133+ REQUIRE_NO_THROW_TRUE (response.at (" error" ).as_object ().at (" code" ).is_int64 ());
134+ BOOST_REQUIRE_EQUAL (response.at (" error" ).as_object ().at (" code" ).as_int64 (), wrong_version.value ());
135+ }
136+
137+ BOOST_AUTO_TEST_CASE (electrum__blockchain_outpoint_get_status__missing_arguments__dropped)
138+ {
139+ BOOST_REQUIRE (handshake (electrum::version::v1_7));
140+
141+ const auto response = get (R"( {"id":1102,"method":"blockchain.outpoint.get_status","params":[]})" " \n " );
142+ REQUIRE_NO_THROW_TRUE (response.at (" dropped" ).as_bool ());
143+ }
144+
145+ BOOST_AUTO_TEST_CASE (electrum__blockchain_outpoint_get_status__invalid_hash__invalid_argument)
146+ {
147+ BOOST_REQUIRE (handshake (electrum::version::v1_7));
148+
149+ const auto response = get (R"( {"id":1103,"method":"blockchain.outpoint.get_status","params":["not_a_hash", 0]})" " \n " );
150+ REQUIRE_NO_THROW_TRUE (response.at (" error" ).as_object ().at (" code" ).is_int64 ());
151+ BOOST_REQUIRE_EQUAL (response.at (" error" ).as_object ().at (" code" ).as_int64 (), invalid_argument.value ());
152+ }
153+
154+ BOOST_AUTO_TEST_CASE (electrum__blockchain_outpoint_get_status__invalid_index__invalid_argument)
155+ {
156+ BOOST_REQUIRE (handshake (electrum::version::v1_7));
157+
158+ constexpr hash_digest hash{ 0x42 };
159+ const auto request = R"( {"id":1104,"method":"blockchain.outpoint.get_status","params":["%1%",-1]})" " \n " ;
160+ const auto response = get ((boost::format (request) % encode_hash (hash)).str ());
161+ REQUIRE_NO_THROW_TRUE (response.at (" error" ).as_object ().at (" code" ).is_int64 ());
162+ BOOST_REQUIRE_EQUAL (response.at (" error" ).as_object ().at (" code" ).as_int64 (), invalid_argument.value ());
163+ }
164+
165+ BOOST_AUTO_TEST_CASE (electrum__blockchain_outpoint_get_status__tx_not_found__not_found)
166+ {
167+ BOOST_REQUIRE (handshake (electrum::version::v1_7));
168+
169+ constexpr hash_digest hash{ 0x42 };
170+ const auto request = R"( {"id":1105,"method":"blockchain.outpoint.get_status","params":["%1%",0]})" " \n " ;
171+ const auto response = get ((boost::format (request) % encode_hash (hash)).str ());
172+ REQUIRE_NO_THROW_TRUE (response.at (" error" ).as_object ().at (" code" ).is_int64 ());
173+ BOOST_REQUIRE_EQUAL (response.at (" error" ).as_object ().at (" code" ).as_int64 (), not_found.value ());
174+ }
175+
176+ BOOST_AUTO_TEST_CASE (electrum__blockchain_outpoint_get_status__confirmed_unspent__expected)
177+ {
178+ BOOST_REQUIRE (handshake (electrum::version::v1_7));
179+
180+ const auto hash1 = test::block1.transactions_ptr ()->at (0 )->hash (false );
181+ const auto request = R"( {"id":1106,"method":"blockchain.outpoint.get_status","params":["%1%",0]})" " \n " ;
182+ const auto response = get ((boost::format (request) % encode_hash (hash1)).str ());
183+ REQUIRE_NO_THROW_TRUE (response.at (" result" ).is_object ());
184+
185+ const auto & result = response.at (" result" ).as_object ();
186+ REQUIRE_NO_THROW_TRUE (result.at (" height" ).is_int64 ());
187+ BOOST_REQUIRE (!result.contains (" spender_txhash" ));
188+ BOOST_REQUIRE (!result.contains (" spender_height" ));
189+ BOOST_CHECK_EQUAL (result.at (" height" ).as_int64 (), 1 );
190+ }
191+
192+ BOOST_AUTO_TEST_CASE (electrum__blockchain_outpoint_get_status__confirmed_spent__expected)
193+ {
194+ BOOST_REQUIRE (handshake (electrum::version::v1_7));
195+
196+ BOOST_REQUIRE (query_.set (test::bogus_block10, database::context{ 0 , 10 , 0 }, false , false ));
197+ BOOST_REQUIRE (query_.push_confirmed (query_.to_header (test::bogus_block10.hash ()), true ));
198+
199+ const auto hash1 = test::block1.transactions_ptr ()->at (0 )->hash (false );
200+ const auto request = R"( {"id":1107,"method":"blockchain.outpoint.get_status","params":["%1%",0]})" " \n " ;
201+ const auto response = get ((boost::format (request) % encode_hash (hash1)).str ());
202+ REQUIRE_NO_THROW_TRUE (response.at (" result" ).is_object ());
203+
204+ const auto hash10 = test::bogus_block10.transactions_ptr ()->at (1 )->hash (false );
205+ const auto & result = response.at (" result" ).as_object ();
206+ REQUIRE_NO_THROW_TRUE (result.at (" height" ).is_int64 ());
207+ REQUIRE_NO_THROW_TRUE (result.at (" spender_height" ).is_int64 ());
208+ REQUIRE_NO_THROW_TRUE (result.at (" spender_txhash" ).is_string ());
209+ BOOST_CHECK_EQUAL (result.at (" height" ).as_int64 (), 1 );
210+ BOOST_CHECK_EQUAL (result.at (" spender_height" ).as_int64 (), 10 );
211+ BOOST_CHECK_EQUAL (result.at (" spender_txhash" ).as_string (), encode_hash (hash10));
212+ }
213+
125214// blockchain.outpoint.subscribe
126215// blockchain.outpoint.unsubscribe
127216
0 commit comments