@@ -6842,6 +6842,91 @@ TEST (rpc, confirmation_active)
6842
6842
}
6843
6843
6844
6844
TEST (rpc, confirmation_info)
6845
+ {
6846
+ nano::test::system system ;
6847
+ nano::node_config node_config;
6848
+ node_config.backlog_scan .enable = false ; // Disable backlog scan to avoid unwanted elections
6849
+ auto node = add_ipc_enabled_node (system );
6850
+ auto const rpc_ctx = add_rpc (system , node);
6851
+
6852
+ auto rep1 = nano::test::setup_rep (system , *node, 100 * nano::Knano_ratio);
6853
+ auto rep2 = nano::test::setup_rep (system , *node, 1000 * nano::Knano_ratio);
6854
+ auto rep3 = nano::test::setup_rep (system , *node, 2000 * nano::Knano_ratio);
6855
+ auto rep4 = nano::keypair{}; // Representative with zero weight
6856
+ auto rep5 = nano::test::setup_rep (system , *node, 1500 * nano::Knano_ratio); // Additional final representative
6857
+
6858
+ nano::block_builder builder;
6859
+ auto send = builder
6860
+ .state ()
6861
+ .account (nano::dev::genesis_key.pub )
6862
+ .previous (node->latest (nano::dev::genesis_key.pub ))
6863
+ .link (nano::public_key{})
6864
+ .representative (nano::dev::genesis_key.pub )
6865
+ .balance (nano::dev::constants.genesis_amount - 10000 * nano::Knano_ratio)
6866
+ .sign (nano::dev::genesis_key.prv , nano::dev::genesis_key.pub )
6867
+ .work (*system .work .generate (node->latest (nano::dev::genesis_key.pub )))
6868
+ .build ();
6869
+ node->process_active (send);
6870
+
6871
+ ASSERT_TIMELY (5s, !node->active .empty ());
6872
+
6873
+ auto election = node->active .election (send->qualified_root ());
6874
+ ASSERT_NE (nullptr , election);
6875
+
6876
+ auto vote1 = nano::test::make_vote (rep1, { send });
6877
+ auto vote2 = nano::test::make_vote (rep2, { send });
6878
+ auto vote3 = nano::test::make_final_vote (rep3, { send });
6879
+ auto vote4 = nano::test::make_vote (rep4, { send }); // Add vote from zero-weight representative
6880
+ auto vote5 = nano::test::make_final_vote (rep5, { send }); // Add another final vote
6881
+
6882
+ node->vote_processor .vote_blocking (vote1, nano::test::fake_channel (*node));
6883
+ node->vote_processor .vote_blocking (vote2, nano::test::fake_channel (*node));
6884
+ node->vote_processor .vote_blocking (vote3, nano::test::fake_channel (*node));
6885
+ node->vote_processor .vote_blocking (vote4, nano::test::fake_channel (*node));
6886
+ node->vote_processor .vote_blocking (vote5, nano::test::fake_channel (*node));
6887
+
6888
+ boost::property_tree::ptree request;
6889
+ request.put (" action" , " confirmation_info" );
6890
+ request.put (" root" , send->qualified_root ().to_string ());
6891
+ request.put (" representatives" , " true" );
6892
+ request.put (" json_block" , " true" );
6893
+ {
6894
+ auto response (wait_response (system , rpc_ctx, request));
6895
+
6896
+ ASSERT_EQ (0 , response.get <unsigned > (" announcements" ));
6897
+ // FIXME: The voters and representatives list always contains a "ghost" representative with zero weight, investigate why
6898
+ ASSERT_EQ (6 , response.get <unsigned > (" voters" ));
6899
+ ASSERT_EQ (send->hash ().to_string (), response.get <std::string> (" last_winner" ));
6900
+ ASSERT_EQ (" 4600000000000000000000000000000000000" , response.get <std::string> (" total_tally" ));
6901
+ ASSERT_EQ (" 3500000000000000000000000000000000000" , response.get <std::string> (" final_tally" ));
6902
+
6903
+ auto & blocks (response.get_child (" blocks" ));
6904
+ ASSERT_EQ (1 , blocks.size ());
6905
+
6906
+ auto block_info = blocks.find (send->hash ().to_string ());
6907
+ ASSERT_NE (block_info, blocks.not_found ());
6908
+
6909
+ ASSERT_EQ (" 4600000000000000000000000000000000000" , block_info->second .get <std::string> (" tally" ));
6910
+
6911
+ auto & representatives = block_info->second .get_child (" representatives" );
6912
+ ASSERT_EQ (6 , representatives.size ());
6913
+ ASSERT_EQ (" 100000000000000000000000000000000000" , representatives.get <std::string> (rep1.pub .to_account ()));
6914
+ ASSERT_EQ (" 1000000000000000000000000000000000000" , representatives.get <std::string> (rep2.pub .to_account ()));
6915
+ ASSERT_EQ (" 2000000000000000000000000000000000000" , representatives.get <std::string> (rep3.pub .to_account ()));
6916
+ ASSERT_EQ (" 0" , representatives.get <std::string> (rep4.pub .to_account ()));
6917
+ ASSERT_EQ (" 1500000000000000000000000000000000000" , representatives.get <std::string> (rep5.pub .to_account ()));
6918
+
6919
+ auto & representatives_final = block_info->second .get_child (" representatives_final" );
6920
+ ASSERT_EQ (2 , representatives_final.size ());
6921
+ ASSERT_EQ (" 2000000000000000000000000000000000000" , representatives_final.get <std::string> (rep3.pub .to_account ()));
6922
+ ASSERT_EQ (" 1500000000000000000000000000000000000" , representatives_final.get <std::string> (rep5.pub .to_account ()));
6923
+
6924
+ // Verify the contents field exists
6925
+ ASSERT_TRUE (block_info->second .get_child_optional (" contents" ).is_initialized ());
6926
+ }
6927
+ }
6928
+
6929
+ TEST (rpc, confirmation_info_empty)
6845
6930
{
6846
6931
nano::test::system system ;
6847
6932
auto node1 = add_ipc_enabled_node (system );
@@ -6867,6 +6952,7 @@ TEST (rpc, confirmation_info)
6867
6952
{
6868
6953
auto response (wait_response (system , rpc_ctx, request));
6869
6954
ASSERT_EQ (1 , response.count (" announcements" ));
6955
+ // FIXME: The voters and representatives list always contains a "ghost" representative with zero weight, investigate why
6870
6956
ASSERT_EQ (1 , response.get <unsigned > (" voters" ));
6871
6957
ASSERT_EQ (send->hash ().to_string (), response.get <std::string> (" last_winner" ));
6872
6958
auto & blocks (response.get_child (" blocks" ));
0 commit comments