From cb7429e8188a570182cebf1bded52940d612781d Mon Sep 17 00:00:00 2001
From: pbattu123
Date: Tue, 7 Apr 2020 01:31:17 -0300
Subject: [PATCH] code improvement with edge case handling
---
libraries/chain/asset_object.cpp | 7 ++++---
.../graphene/chain/protocol/lottery_ops.hpp | 2 +-
tests/tests/lottery_tests.cpp | 17 +++++------------
3 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp
index 989c417a..f6585075 100644
--- a/libraries/chain/asset_object.cpp
+++ b/libraries/chain/asset_object.cpp
@@ -207,7 +207,8 @@ vector asset_object::get_ticket_ids( database& db ) const
if( ath->next == account_transaction_history_id_type() )
{
- ids.insert(ids.end(), balance-1, oho.id.instance());
+ if(balance > 1 && oho.op.which() == operation::tag::value)
+ ids.insert(ids.end(), balance-1, oho.id.instance());
ath = nullptr;
break;
}
@@ -269,9 +270,9 @@ map< account_id_type, vector< uint16_t > > asset_object::distribute_winners_part
reward_op.is_benefactor_reward = false;
reward_op.winner = holders[winner_num];
time_point_sec now = time_point::now();
- if(now > HARDFORK_5050_1_TIME)
+ if(now > HARDFORK_5050_1_TIME && ticket_ids.size() >= winner_num)
{
- const static_variant tkt_id = ticket_ids[winner_num];
+ const static_variant tkt_id = ticket_ids[winner_num];
reward_op.winner_ticket_id = tkt_id;
}
reward_op.win_percentage = tickets[c];
diff --git a/libraries/chain/include/graphene/chain/protocol/lottery_ops.hpp b/libraries/chain/include/graphene/chain/protocol/lottery_ops.hpp
index 5114ad90..0bc64129 100644
--- a/libraries/chain/include/graphene/chain/protocol/lottery_ops.hpp
+++ b/libraries/chain/include/graphene/chain/protocol/lottery_ops.hpp
@@ -52,7 +52,7 @@ namespace graphene { namespace chain {
share_type calculate_fee( const fee_parameters_type& k )const;
};
- typedef static_variant ticket_num;
+ typedef static_variant ticket_num;
/**
* @ingroup operations
diff --git a/tests/tests/lottery_tests.cpp b/tests/tests/lottery_tests.cpp
index 9499136a..063c15c1 100644
--- a/tests/tests/lottery_tests.cpp
+++ b/tests/tests/lottery_tests.cpp
@@ -525,21 +525,14 @@ BOOST_AUTO_TEST_CASE( lottery_winner_ticket_id_test )
for( uint8_t win: test_asset.lottery_options->winning_tickets )
winners_part += win;
- auto participants = test_asset.distribute_winners_part( db );
- test_asset.distribute_benefactors_part( db );
- test_asset.distribute_sweeps_holders_part( db );
- generate_block();
- for( auto p: participants ) {
- idump(( get_operation_history(p.first) ));
- }
- auto benefactor_history = get_operation_history( account_id_type() );
- for( auto h: benefactor_history ) {
+ while( db.head_block_time() < ( test_asset.lottery_options->end_date ) )
+ generate_block();
+
+ auto op_history = get_operation_history( account_id_type(1) ); //Can observe operation 79 to verify winner ticket number
+ for( auto h: op_history ) {
idump((h));
}
- while( db.head_block_time() < ( test_asset.lottery_options->end_date + fc::seconds(30) ) )
- generate_block();
-
BOOST_CHECK( db.get_balance( test_asset.get_id() ).amount.value == 0 );
uint64_t creator_recieved = db.get_balance( account_id_type(), asset_id_type() ).amount.value - creator_balance_before_end;
test_asset = test_asset_id(db);