Skip to content

Commit

Permalink
Improve/fix test rpc.account_representative_set
Browse files Browse the repository at this point in the history
The test wasn't really properly that the RPC commands worked.
It just checked that it got a reply.
I improved the test to check that the representative really changed.
  • Loading branch information
dsiganos committed Mar 30, 2022
1 parent 8386478 commit adefd4d
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2668,22 +2668,35 @@ TEST (rpc, account_representative_set)
{
nano::system system;
auto node = add_ipc_enabled_node (system);
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
auto & wallet = *system.wallet (0);
wallet.insert_adhoc (nano::dev::genesis_key.prv);

// create a 2nd account and send it some nano
nano::keypair key2;
wallet.insert_adhoc (key2.prv);
auto key2_open_block_hash = wallet.send_sync (nano::dev::genesis_key.pub, key2.pub, node->config.receive_minimum.number ());
ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->store.tx_begin_read (), key2_open_block_hash));
auto key2_open_block = node->store.block.get (node->store.tx_begin_read (), key2_open_block_hash);
ASSERT_EQ (nano::dev::genesis_key.pub, key2_open_block->representative ());

// now change the representative of key2 to be genesis
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
nano::keypair rep;
request.put ("account", nano::dev::genesis->account ().to_account ());
request.put ("representative", rep.pub.to_account ());
request.put ("account", key2.pub.to_account ());
request.put ("representative", key2.pub.to_account ());
request.put ("wallet", node->wallets.items.begin ()->first.to_string ());
request.put ("action", "account_representative_set");
auto response (wait_response (system, rpc_ctx, request));
std::string block_text1 (response.get<std::string> ("block"));

// check that the rep change succeeded
nano::block_hash hash;
ASSERT_FALSE (hash.decode_hex (block_text1));
ASSERT_FALSE (hash.is_zero ());
auto transaction (node->store.tx_begin_read ());
ASSERT_TRUE (node->store.block.exists (transaction, hash));
ASSERT_EQ (rep.pub, node->store.block.get (transaction, hash)->representative ());
auto block = node->store.block.get (node->store.tx_begin_read (), hash);
ASSERT_NE (block, nullptr);
ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->store.tx_begin_read (), hash));
ASSERT_EQ (key2.pub, block->representative ());
}

TEST (rpc, account_representative_set_work_disabled)
Expand Down

0 comments on commit adefd4d

Please sign in to comment.