Skip to content

Commit

Permalink
Making sure work is generated on wallet key when seed is changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Mar 18, 2016
1 parent 878bc87 commit b01eee2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
5 changes: 4 additions & 1 deletion rai/node/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,10 @@ void rai::wallet::work_generate (rai::account const & account_a, rai::block_hash
BOOST_LOG (node.log) << "Work generation complete: " << (std::chrono::duration_cast <std::chrono::microseconds> (std::chrono::system_clock::now () - begin).count ()) << " us";
}
rai::transaction transaction (store.environment, nullptr, true);
work_update (transaction, account_a, root_a, work);
if (store.exists (transaction, account_a))
{
work_update (transaction, account_a, root_a, work);
}
}

rai::wallets::wallets (bool & error_a, rai::node & node_a) :
Expand Down
15 changes: 10 additions & 5 deletions rai/qt/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,22 +279,27 @@ wallet (wallet_a)
rai::raw_key seed_l;
if (!seed_l.data.decode_hex (seed->text ().toStdString ()))
{
bool successful (false);
{
rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, true);
if (this->wallet.wallet_m->store.valid_password (transaction))
{
this->wallet.wallet_m->store.seed_set (transaction, seed_l);
this->wallet.account = this->wallet.wallet_m->store.deterministic_insert (transaction);
seed->clear ();
clear_line->clear ();
show_line_ok (*seed);
successful = true;
}
else
{
show_line_error (*seed);
}
}
this->wallet.refresh ();
if (successful)
{
this->wallet.account = this->wallet.wallet_m->deterministic_insert ();
seed->clear ();
clear_line->clear ();
show_line_ok (*seed);
this->wallet.refresh ();
}
}
else
{
Expand Down
33 changes: 32 additions & 1 deletion rai/qt_test/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ TEST (wallet, change_seed)
auto key3 (system.wallet (0)->deterministic_insert ());
rai::raw_key seed3;
system.wallet (0)->store.seed (seed3, rai::transaction (system.wallet (0)->store.environment, nullptr, false));
rai_qt::wallet wallet (*test_application, *system.nodes [0], system.wallet (0), key1);
auto wallet_key (key1);
rai_qt::wallet wallet (*test_application, *system.nodes [0], system.wallet (0), wallet_key);
QTest::mouseClick (wallet.show_advanced, Qt::LeftButton);
ASSERT_EQ (wallet.advanced.window, wallet.main_stack->currentWidget ());
QTest::mouseClick (wallet.advanced.accounts, Qt::LeftButton);
Expand Down Expand Up @@ -605,6 +606,36 @@ TEST (wallet, change_seed)
ASSERT_TRUE (system.wallet (0)->exists (key1));
}

TEST (wallet, seed_work_generation)
{
rai::system system (24000, 1);
auto key1 (system.wallet (0)->deterministic_insert ());
rai_qt::wallet wallet (*test_application, *system.nodes [0], system.wallet (0), key1);
QTest::mouseClick (wallet.show_advanced, Qt::LeftButton);
ASSERT_EQ (wallet.advanced.window, wallet.main_stack->currentWidget ());
QTest::mouseClick (wallet.advanced.accounts, Qt::LeftButton);
ASSERT_EQ (wallet.accounts.window, wallet.main_stack->currentWidget ());
QTest::mouseClick (wallet.accounts.import_wallet, Qt::LeftButton);
ASSERT_EQ (wallet.import.window, wallet.main_stack->currentWidget ());
rai::raw_key seed;
seed.data.clear ();
QTest::keyClicks (wallet.import.seed, seed.data.to_string ().c_str ());
QTest::keyClicks (wallet.import.clear_line, "clear keys");
QTest::mouseClick (wallet.import.import_seed, Qt::LeftButton);
auto iterations (0);
uint64_t work_start;
system.wallet (0)->store.work_get (rai::transaction (system.wallet (0)->store.environment, nullptr, false), key1, work_start);
uint64_t work (work_start);
while (work == work_start)
{
system.poll ();
system.wallet (0)->store.work_get (rai::transaction (system.wallet (0)->store.environment, nullptr, false), key1, work);
++iterations;
ASSERT_LT (iterations, 200);
}
ASSERT_FALSE (system.work.work_validate (system.nodes [0]->ledger.latest_root (rai::transaction (system.wallet (0)->store.environment, nullptr, false), key1), work));
}

TEST (wallet, backup_seed)
{
rai::system system (24000, 1);
Expand Down

0 comments on commit b01eee2

Please sign in to comment.