From 63aa1fc0f9257988647295d808194c12247ebabd Mon Sep 17 00:00:00 2001 From: clemahieu Date: Mon, 12 Mar 2018 21:19:30 -0500 Subject: [PATCH] Adding test to make sure block_create can be used to create utx open blocks. --- rai/core_test/rpc.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ rai/node/rpc.cpp | 8 ++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/rai/core_test/rpc.cpp b/rai/core_test/rpc.cpp index 537e772b..f82e4377 100644 --- a/rai/core_test/rpc.cpp +++ b/rai/core_test/rpc.cpp @@ -3205,6 +3205,48 @@ TEST (rpc, block_create_utx) auto process_result (system.nodes[0]->process (*utx_block)); ASSERT_EQ (rai::process_result::progress, process_result.code); } +TEST (rpc, block_create_utx_open) +{ + rai::system system (24000, 1); + rai::keypair key; + rai::genesis genesis; + system.nodes[0]->ledger.utx_parse_canary = genesis.hash (); + system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); + system.wallet (0)->insert_adhoc (key.prv); + auto send_block (system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, rai::Gxrb_ratio)); + ASSERT_NE (nullptr, send_block); + boost::property_tree::ptree request; + request.put ("action", "block_create"); + request.put ("type", "utx"); + request.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); + request.put ("account", key.pub.to_account ()); + request.put ("previous", 0); + request.put ("representative", rai::test_genesis_key.pub.to_account ()); + request.put ("balance", rai::Gxrb_ratio.convert_to ()); + request.put ("link", send_block->hash ().to_string ()); + request.put ("work", rai::to_string_hex (system.nodes[0]->generate_work (send_block->hash ()))); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); + rpc.start (); + test_response response (request, rpc, system.service); + while (response.status == 0) + { + system.poll (); + } + ASSERT_EQ (200, response.status); + std::string utx_hash (response.json.get ("hash")); + auto utx_text (response.json.get ("block")); + std::stringstream block_stream (utx_text); + boost::property_tree::ptree block_l; + boost::property_tree::read_json (block_stream, block_l); + auto utx_block (rai::deserialize_block_json (block_l)); + ASSERT_NE (nullptr, utx_block); + ASSERT_EQ (rai::block_type::utx, utx_block->type ()); + ASSERT_EQ (utx_hash, utx_block->hash ().to_string ()); + ASSERT_TRUE (system.nodes [0]->latest (key.pub).is_zero ()); + auto process_result (system.nodes[0]->process (*utx_block)); + ASSERT_EQ (rai::process_result::progress, process_result.code); + ASSERT_FALSE (system.nodes [0]->latest (key.pub).is_zero ()); +} TEST (rpc, wallet_lock) { diff --git a/rai/node/rpc.cpp b/rai/node/rpc.cpp index 6059cf3c..aeae92cd 100644 --- a/rai/node/rpc.cpp +++ b/rai/node/rpc.cpp @@ -1190,7 +1190,11 @@ void rai::rpc_handler::block_create () auto error_link (link.decode_account (link_text.get ())); if (error_link) { - error_response (response, "Bad link number"); + auto error_link (link.decode_hex (link_text.get ())); + if (error_link) + { + error_response (response, "Bad link number"); + } } } if (prv.data != 0) @@ -1199,7 +1203,7 @@ void rai::rpc_handler::block_create () ed25519_publickey (prv.data.bytes.data (), pub.bytes.data ()); if (type == "utx") { - if (!account.is_zero () && !previous.is_zero () && !representative.is_zero () && !balance.is_zero () && link_text.is_initialized ()) + if (!account.is_zero () && previous_text.is_initialized () && !representative.is_zero () && !balance.is_zero () && link_text.is_initialized ()) { rai::utx_block utx (account, previous, representative, balance, link, prv, pub, work); boost::property_tree::ptree response_l;