Fixing issues and testing send.

This commit is contained in:
clemahieu 2014-11-29 19:49:38 -06:00
commit 393828e8b4
3 changed files with 42 additions and 9 deletions

View file

@ -783,19 +783,19 @@ void rai_qt::block_creation::activate_change ()
void rai_qt::block_creation::create_send ()
{
rai::account account_l;
auto error (account_l.decode_hex (account->text ().toStdString ()));
auto error (account_l.decode_base58check (account->text ().toStdString ()));
if (!error)
{
rai::amount amount_l;
error = account_l.decode_hex (amount->text ().toStdString ());
error = amount_l.decode_hex (amount->text ().toStdString ());
if (!error)
{
rai::account destination_l;
error = destination_l.decode_hex (destination->text ().toStdString ());
error = destination_l.decode_base58check (destination->text ().toStdString ());
if (!error)
{
rai::private_key key;
if (client.client_m.wallet.fetch (account_l, key))
if (!client.client_m.wallet.fetch (account_l, key))
{
auto balance (client.client_m.ledger.account_balance (account_l));
if (amount_l.number () <= balance)
@ -910,7 +910,7 @@ void rai_qt::block_creation::create_change ()
if (!error)
{
rai::account representative_l;
error = representative_l.decode_hex (representative->text ().toStdString ());
error = representative_l.decode_base58check (representative->text ().toStdString ());
if (!error)
{
rai::frontier frontier;
@ -962,7 +962,7 @@ void rai_qt::block_creation::create_open ()
if (!error)
{
rai::account representative_l;
error = representative_l.decode_hex (representative->text ().toStdString ());
error = representative_l.decode_base58check (representative->text ().toStdString ());
if (!error)
{
rai::account source;

View file

@ -1,5 +1,7 @@
#include <gtest/gtest.h>
#include <boost/property_tree/json_parser.hpp>
#include <rai/qt/qt.hpp>
#include <thread>
#include <QTest>
@ -159,7 +161,7 @@ TEST (client, process_block)
send.work = system.clients [0]->ledger.create_work (send);
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send.hash (), send.signature);
std::string destination;
send.hashables.destination.encode_hex (destination);
send.hashables.destination.encode_base58check (destination);
std::string previous;
send.hashables.previous.encode_hex (previous);
std::string balance;
@ -172,4 +174,35 @@ TEST (client, process_block)
ASSERT_EQ (send.hash (), system.clients [0]->ledger.latest (rai::genesis_account));
QTest::mouseClick(client.block_entry.back, Qt::LeftButton);
ASSERT_EQ (client.advanced.window, client.main_stack->currentWidget ());
}
TEST (client, create_send)
{
rai::keypair key;
rai::system system (24000, 1);
system.clients [0]->wallet.insert (rai::test_genesis_key.prv);
system.clients [0]->wallet.insert (key.prv);
int argc (0);
QApplication application (argc, nullptr);
rai_qt::client client (application, *system.clients [0]);
QTest::mouseClick (client.show_advanced, Qt::LeftButton);
QTest::mouseClick (client.advanced.create_block, Qt::LeftButton);
QTest::mouseClick (client.block_creation.send, Qt::LeftButton);
std::string account;
rai::test_genesis_key.pub.encode_base58check (account);
QTest::keyClicks (client.block_creation.account, account.c_str ());
QTest::keyClicks (client.block_creation.amount, "56bc75e2d63100000");
std::string destination;
key.pub.encode_base58check (destination);
QTest::keyClicks (client.block_creation.destination, destination.c_str ());
QTest::mouseClick (client.block_creation.create, Qt::LeftButton);
std::string json (client.block_creation.block->toPlainText ().toStdString ());
ASSERT_FALSE (json.empty ());
rai::send_block send;
boost::property_tree::ptree tree1;
std::stringstream istream (json);
boost::property_tree::read_json (istream, tree1);
ASSERT_FALSE (send.deserialize_json (tree1));
ASSERT_EQ (rai::process_result::progress, system.clients [0]->ledger.process (send));
ASSERT_EQ (rai::process_result::old, system.clients [0]->ledger.process (send));
}

View file

@ -315,7 +315,7 @@ void rai::send_block::serialize_json (std::string & string_a) const
boost::property_tree::ptree tree;
tree.put ("type", "send");
std::string destination;
hashables.destination.encode_hex (destination);
hashables.destination.encode_base58check (destination);
tree.put ("destination", destination);
std::string previous;
hashables.previous.encode_hex (previous);
@ -366,7 +366,7 @@ bool rai::send_block::deserialize_json (boost::property_tree::ptree const & tree
auto balance_l (tree_a.get <std::string> ("balance"));
auto work_l (tree_a.get <std::string> ("work"));
auto signature_l (tree_a.get <std::string> ("signature"));
result = hashables.destination.decode_hex (destination_l);
result = hashables.destination.decode_base58check (destination_l);
if (!result)
{
result = hashables.previous.decode_hex (previous_l);