Skip to content

Commit df87d9f

Browse files
committed
Add "fee" and min version tests to get_history/_mempool.
1 parent 5739c55 commit df87d9f

2 files changed

Lines changed: 54 additions & 8 deletions

File tree

test/protocols/electrum/electrum_addresses.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_balance__missing_arguments
8686
REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool());
8787
}
8888

89-
BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_balance__empty_v1_3__wrong_version)
89+
BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_balance__obsoleted_version__wrong_version)
9090
{
9191
BOOST_REQUIRE(handshake(electrum::version::v1_3));
9292

@@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_history__missing_arguments
153153
REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool());
154154
}
155155

156-
BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_history__empty_v1_3__wrong_version)
156+
BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_history__obsoleted_version__wrong_version)
157157
{
158158
BOOST_REQUIRE(handshake(electrum::version::v1_3));
159159

@@ -201,20 +201,23 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_history__confirmed_and_unc
201201
const auto& tx1 = history.at(0).as_object();
202202
REQUIRE_NO_THROW_TRUE(tx1.at("height").is_int64());
203203
REQUIRE_NO_THROW_TRUE(tx1.at("tx_hash").is_string());
204+
BOOST_CHECK(!tx1.contains("fee"));
204205
BOOST_REQUIRE_EQUAL(tx1.at("height").as_int64(), 10);
205206
BOOST_REQUIRE_EQUAL(tx1.at("tx_hash").as_string(), encode_hash(hash1));
206207

207208
const auto hash2 = test::bogus_block11.transactions_ptr()->at(0)->hash(false);
208209
const auto& tx2 = history.at(1).as_object();
209210
REQUIRE_NO_THROW_TRUE(tx2.at("height").is_int64());
210211
REQUIRE_NO_THROW_TRUE(tx2.at("tx_hash").is_string());
212+
BOOST_CHECK_EQUAL(tx2.at("fee").as_int64(), floored_subtract(5'000'000'000 + 5'000'000'000, 0x10 + 0x11 + 0x12 + 0x13 + 0x14));
211213
BOOST_REQUIRE_EQUAL(tx2.at("height").as_int64(), 0); // rooted
212214
BOOST_REQUIRE_EQUAL(tx2.at("tx_hash").as_string(), encode_hash(hash2));
213215

214216
const auto hash3 = test::bogus_block12.transactions_ptr()->at(0)->hash(false);
215217
const auto& tx3 = history.at(2).as_object();
216218
REQUIRE_NO_THROW_TRUE(tx3.at("height").is_int64());
217219
REQUIRE_NO_THROW_TRUE(tx3.at("tx_hash").is_string());
220+
BOOST_CHECK_EQUAL(tx3.at("fee").as_int64(), floored_subtract(0x10 + 0x11, 0x0a));
218221
BOOST_REQUIRE_EQUAL(tx3.at("height").as_int64(), -1); // not rooted
219222
BOOST_REQUIRE_EQUAL(tx3.at("tx_hash").as_string(), encode_hash(hash3));
220223
}
@@ -230,7 +233,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_mempool__missing_arguments
230233
REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool());
231234
}
232235

233-
BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_mempool__empty_v1_3__wrong_version)
236+
BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_mempool__obsoleted_version__wrong_version)
234237
{
235238
BOOST_REQUIRE(handshake(electrum::version::v1_3));
236239

@@ -278,13 +281,15 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_address_get_mempool__confirmed_and_unc
278281
const auto& tx1 = history.at(0).as_object();
279282
REQUIRE_NO_THROW_TRUE(tx1.at("height").is_int64());
280283
REQUIRE_NO_THROW_TRUE(tx1.at("tx_hash").is_string());
284+
BOOST_CHECK_EQUAL(tx1.at("fee").as_int64(), floored_subtract(5'000'000'000 + 5'000'000'000, 0x10 + 0x11 + 0x12 + 0x13 + 0x14));
281285
BOOST_REQUIRE_EQUAL(tx1.at("height").as_int64(), 0); // rooted
282286
BOOST_REQUIRE_EQUAL(tx1.at("tx_hash").as_string(), encode_hash(hash1));
283287

284288
const auto hash2 = test::bogus_block12.transactions_ptr()->at(0)->hash(false);
285289
const auto& tx2 = history.at(1).as_object();
286290
REQUIRE_NO_THROW_TRUE(tx2.at("height").is_int64());
287291
REQUIRE_NO_THROW_TRUE(tx2.at("tx_hash").is_string());
292+
BOOST_CHECK_EQUAL(tx2.at("fee").as_int64(), floored_subtract(0x10 + 0x11, 0x0a));
288293
BOOST_REQUIRE_EQUAL(tx2.at("height").as_int64(), -1); // not rooted
289294
BOOST_REQUIRE_EQUAL(tx2.at("tx_hash").as_string(), encode_hash(hash2));
290295
}
@@ -300,7 +305,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_address_list_unspent__missing_argument
300305
REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool());
301306
}
302307

303-
BOOST_AUTO_TEST_CASE(electrum__blockchain_address_list_unspent__empty_v1_3__wrong_version)
308+
BOOST_AUTO_TEST_CASE(electrum__blockchain_address_list_unspent__obsoleted_version__wrong_version)
304309
{
305310
BOOST_REQUIRE(handshake(electrum::version::v1_3));
306311

test/protocols/electrum/electrum_scripthash.cpp

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,17 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_balance__missing_argume
8888
REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool());
8989
}
9090

91+
BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_balance__insufficient_version__dropped)
92+
{
93+
BOOST_REQUIRE(handshake(electrum::version::v1_0));
94+
95+
const auto response = get(R"({"id":902,"method":"blockchain.scripthash.get_balance","params":[""]})" "\n");
96+
REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64());
97+
BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), wrong_version.value());
98+
}
99+
91100
// Not yet.
92-
////BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_balance__empty_v1_7__wrong_version)
101+
////BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_balance__obsoleted_version__wrong_version)
93102
////{
94103
//// BOOST_REQUIRE(handshake(electrum::version::v1_7));
95104
////
@@ -156,8 +165,17 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_history__missing_argume
156165
REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool());
157166
}
158167

168+
BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_history__insufficient_version__dropped)
169+
{
170+
BOOST_REQUIRE(handshake(electrum::version::v1_0));
171+
172+
const auto response = get(R"({"id":902,"method":"blockchain.scripthash.get_history","params":[""]})" "\n");
173+
REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64());
174+
BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), wrong_version.value());
175+
}
176+
159177
// Not yet.
160-
////BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_history__empty_v1_7__wrong_version)
178+
////BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_history__obsoleted_version__wrong_version)
161179
////{
162180
//// BOOST_REQUIRE(handshake(electrum::version::v1_7));
163181
////
@@ -205,20 +223,23 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_history__confirmed_and_
205223
const auto& tx1 = history.at(0).as_object();
206224
REQUIRE_NO_THROW_TRUE(tx1.at("height").is_int64());
207225
REQUIRE_NO_THROW_TRUE(tx1.at("tx_hash").is_string());
226+
BOOST_CHECK(!tx1.contains("fee"));
208227
BOOST_REQUIRE_EQUAL(tx1.at("height").as_int64(), 10);
209228
BOOST_REQUIRE_EQUAL(tx1.at("tx_hash").as_string(), encode_hash(hash1));
210229

211230
const auto hash2 = test::bogus_block11.transactions_ptr()->at(0)->hash(false);
212231
const auto& tx2 = history.at(1).as_object();
213232
REQUIRE_NO_THROW_TRUE(tx2.at("height").is_int64());
214233
REQUIRE_NO_THROW_TRUE(tx2.at("tx_hash").is_string());
234+
BOOST_CHECK_EQUAL(tx2.at("fee").as_int64(), floored_subtract(5'000'000'000 + 5'000'000'000, 0x10 + 0x11 + 0x12 + 0x13 + 0x14));
215235
BOOST_REQUIRE_EQUAL(tx2.at("height").as_int64(), 0); // rooted
216236
BOOST_REQUIRE_EQUAL(tx2.at("tx_hash").as_string(), encode_hash(hash2));
217237

218238
const auto hash3 = test::bogus_block12.transactions_ptr()->at(0)->hash(false);
219239
const auto& tx3 = history.at(2).as_object();
220240
REQUIRE_NO_THROW_TRUE(tx3.at("height").is_int64());
221241
REQUIRE_NO_THROW_TRUE(tx3.at("tx_hash").is_string());
242+
BOOST_CHECK_EQUAL(tx3.at("fee").as_int64(), floored_subtract(0x10 + 0x11, 0x0a));
222243
BOOST_REQUIRE_EQUAL(tx3.at("height").as_int64(), -1); // not rooted
223244
BOOST_REQUIRE_EQUAL(tx3.at("tx_hash").as_string(), encode_hash(hash3));
224245
}
@@ -234,8 +255,17 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_mempool__missing_argume
234255
REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool());
235256
}
236257

258+
BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_mempool__insufficient_version__dropped)
259+
{
260+
BOOST_REQUIRE(handshake(electrum::version::v1_0));
261+
262+
const auto response = get(R"({"id":902,"method":"blockchain.scripthash.get_mempool","params":[""]})" "\n");
263+
REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64());
264+
BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), wrong_version.value());
265+
}
266+
237267
// Not yet.
238-
////BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_mempool__empty_v1_7__wrong_version)
268+
////BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_mempool__obsoleted_version__wrong_version)
239269
////{
240270
//// BOOST_REQUIRE(handshake(electrum::version::v1_7));
241271
////
@@ -283,13 +313,15 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_get_mempool__confirmed_and_
283313
const auto& tx1 = history.at(0).as_object();
284314
REQUIRE_NO_THROW_TRUE(tx1.at("height").is_int64());
285315
REQUIRE_NO_THROW_TRUE(tx1.at("tx_hash").is_string());
316+
BOOST_CHECK_EQUAL(tx1.at("fee").as_int64(), floored_subtract(5'000'000'000 + 5'000'000'000, 0x10 + 0x11 + 0x12 + 0x13 + 0x14));
286317
BOOST_REQUIRE_EQUAL(tx1.at("height").as_int64(), 0); // rooted
287318
BOOST_REQUIRE_EQUAL(tx1.at("tx_hash").as_string(), encode_hash(hash1));
288319

289320
const auto hash2 = test::bogus_block12.transactions_ptr()->at(0)->hash(false);
290321
const auto& tx2 = history.at(1).as_object();
291322
REQUIRE_NO_THROW_TRUE(tx2.at("height").is_int64());
292323
REQUIRE_NO_THROW_TRUE(tx2.at("tx_hash").is_string());
324+
BOOST_CHECK_EQUAL(tx1.at("fee").as_int64(), floored_subtract(5'000'000'000 + 5'000'000'000, 0x10 + 0x11 + 0x12 + 0x13 + 0x14));
293325
BOOST_REQUIRE_EQUAL(tx2.at("height").as_int64(), -1); // not rooted
294326
BOOST_REQUIRE_EQUAL(tx2.at("tx_hash").as_string(), encode_hash(hash2));
295327
}
@@ -305,8 +337,17 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_list_unspent__missing_argum
305337
REQUIRE_NO_THROW_TRUE(response.at("dropped").as_bool());
306338
}
307339

340+
BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_list_unspent__insufficient_version__dropped)
341+
{
342+
BOOST_REQUIRE(handshake(electrum::version::v1_0));
343+
344+
const auto response = get(R"({"id":902,"method":"blockchain.scripthash.listunspent","params":[""]})" "\n");
345+
REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64());
346+
BOOST_REQUIRE_EQUAL(response.at("error").as_object().at("code").as_int64(), wrong_version.value());
347+
}
348+
308349
// Not yet.
309-
////BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_list_unspent__empty_v1_7__wrong_version)
350+
////BOOST_AUTO_TEST_CASE(electrum__blockchain_scripthash_list_unspent__obsoleted_version__wrong_version)
310351
////{
311352
//// BOOST_REQUIRE(handshake(electrum::version::v1_7));
312353
////

0 commit comments

Comments
 (0)