-
Notifications
You must be signed in to change notification settings - Fork 648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add last_vote_time to account stats object #1449
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d1c15c
add last_vote_time
oxarbitrage 5e24f65
change last_vote_time to do_apply
oxarbitrage 5688e7b
minor spacing changes
oxarbitrage 956f1c9
bump database
oxarbitrage 115ed51
clarify proxy vote test times
oxarbitrage 0171861
Merge branch 'develop' into issue1393
oxarbitrage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -414,5 +414,130 @@ BOOST_AUTO_TEST_CASE(invalid_voting_account) | |
|
||
} FC_LOG_AND_RETHROW() | ||
} | ||
BOOST_AUTO_TEST_CASE(last_voting_date) | ||
{ | ||
try | ||
{ | ||
ACTORS((alice)); | ||
|
||
transfer(committee_account, alice_id, asset(100)); | ||
|
||
// we are going to vote for this witness | ||
auto witness1 = witness_id_type(1)(db); | ||
|
||
auto stats_obj = db.get_account_stats_by_owner(alice_id); | ||
BOOST_CHECK_EQUAL(stats_obj.last_vote_time.sec_since_epoch(), 0); | ||
|
||
// alice votes | ||
graphene::chain::account_update_operation op; | ||
op.account = alice_id; | ||
op.new_options = alice.options; | ||
op.new_options->votes.insert(witness1.vote_id); | ||
trx.operations.push_back(op); | ||
sign(trx, alice_private_key); | ||
PUSH_TX( db, trx, ~0 ); | ||
|
||
auto now = db.head_block_time().sec_since_epoch(); | ||
|
||
// last_vote_time is updated for alice | ||
stats_obj = db.get_account_stats_by_owner(alice_id); | ||
BOOST_CHECK_EQUAL(stats_obj.last_vote_time.sec_since_epoch(), now); | ||
|
||
} FC_LOG_AND_RETHROW() | ||
} | ||
BOOST_AUTO_TEST_CASE(last_voting_date_proxy) | ||
{ | ||
try | ||
{ | ||
ACTORS((alice)(proxy)(bob)); | ||
|
||
transfer(committee_account, alice_id, asset(100)); | ||
transfer(committee_account, bob_id, asset(200)); | ||
transfer(committee_account, proxy_id, asset(300)); | ||
|
||
generate_block(); | ||
|
||
// witness to vote for | ||
auto witness1 = witness_id_type(1)(db); | ||
|
||
// alice changes proxy, this is voting activity | ||
{ | ||
graphene::chain::account_update_operation op; | ||
op.account = alice_id; | ||
op.new_options = alice_id(db).options; | ||
op.new_options->voting_account = proxy_id; | ||
trx.operations.push_back(op); | ||
sign(trx, alice_private_key); | ||
PUSH_TX( db, trx, ~0 ); | ||
} | ||
// alice last_vote_time is updated | ||
auto alice_stats_obj = db.get_account_stats_by_owner(alice_id); | ||
auto now = db.head_block_time().sec_since_epoch(); | ||
BOOST_CHECK_EQUAL(alice_stats_obj.last_vote_time.sec_since_epoch(), now); | ||
|
||
generate_block(); | ||
|
||
// alice update account but no proxy or voting changes are done | ||
{ | ||
graphene::chain::account_update_operation op; | ||
op.account = alice_id; | ||
op.new_options = alice_id(db).options; | ||
trx.operations.push_back(op); | ||
sign(trx, alice_private_key); | ||
set_expiration( db, trx ); | ||
PUSH_TX( db, trx, ~0 ); | ||
} | ||
// last_vote_time is not updated | ||
now = db.head_block_time().sec_since_epoch(); | ||
alice_stats_obj = db.get_account_stats_by_owner(alice_id); | ||
BOOST_CHECK(alice_stats_obj.last_vote_time.sec_since_epoch() != now); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better check that |
||
|
||
generate_block(); | ||
|
||
// bob votes | ||
{ | ||
graphene::chain::account_update_operation op; | ||
op.account = bob_id; | ||
op.new_options = bob_id(db).options; | ||
op.new_options->votes.insert(witness1.vote_id); | ||
trx.operations.push_back(op); | ||
sign(trx, bob_private_key); | ||
set_expiration( db, trx ); | ||
PUSH_TX(db, trx, ~0); | ||
} | ||
|
||
// last_vote_time for bob is updated as he voted | ||
now = db.head_block_time().sec_since_epoch(); | ||
auto bob_stats_obj = db.get_account_stats_by_owner(bob_id); | ||
BOOST_CHECK_EQUAL(bob_stats_obj.last_vote_time.sec_since_epoch(), now); | ||
|
||
generate_block(); | ||
|
||
// proxy votes | ||
{ | ||
graphene::chain::account_update_operation op; | ||
op.account = proxy_id; | ||
op.new_options = proxy_id(db).options; | ||
op.new_options->votes.insert(witness1.vote_id); | ||
trx.operations.push_back(op); | ||
sign(trx, proxy_private_key); | ||
PUSH_TX(db, trx, ~0); | ||
} | ||
|
||
// proxy just voted so the last_vote_time is updated | ||
now = db.head_block_time().sec_since_epoch(); | ||
auto proxy_stats_obj = db.get_account_stats_by_owner(proxy_id); | ||
BOOST_CHECK_EQUAL(proxy_stats_obj.last_vote_time.sec_since_epoch(), now); | ||
|
||
// alice haves proxy, proxy votes but last_vote_time is not updated for alice | ||
alice_stats_obj = db.get_account_stats_by_owner(alice_id); | ||
BOOST_CHECK(alice_stats_obj.last_vote_time.sec_since_epoch() != now); | ||
|
||
// bob haves nothing to do with proxy so last_vote_time is not updated | ||
bob_stats_obj = db.get_account_stats_by_owner(bob_id); | ||
BOOST_CHECK(bob_stats_obj.last_vote_time.sec_since_epoch() != now); | ||
|
||
} FC_LOG_AND_RETHROW() | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means every time when
do_evaluate
is called (E.G. byvalidate_transaction
API ?), the data will be updated. Butdo_evaluate
can fail.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually as an unwritten principle we don't modify database in
do_evaluate
, but probably it's practically fine to do so. @pmconrad your opinion?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that
do_evaluate
must not modify the database.IMO it's a good design decision to separate the various stages of operation evaluation, and we should stick with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, thanks. ill refactor to do the update in
do_apply
or something different.