User vesting performance decay tests added (#411)

This commit is contained in:
serkixenos 2020-12-27 12:12:53 +01:00 committed by GitHub
parent 5b51953572
commit fdcf090730
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -670,10 +670,18 @@ BOOST_AUTO_TEST_CASE( voting )
auto witness2 = witness_id_type(2)(db);
BOOST_CHECK_EQUAL(witness2.total_votes, 0);
// vesting performance is 0 for both alice and bob
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 0);
// vote for witness1 and witness2 - sub-period 1
vote_for(alice_id, witness1.vote_id, alice_private_key);
vote_for(bob_id, witness2.vote_id, bob_private_key);
// after voting, vesting performance is 1 for both alice and bob
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
// go to maint
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
@ -683,6 +691,10 @@ BOOST_AUTO_TEST_CASE( voting )
BOOST_CHECK_EQUAL(witness1.total_votes, 1000);
BOOST_CHECK_EQUAL(witness2.total_votes, 1000);
// vesting performance is 1 for both alice and bob during whole gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(6);
witness1 = witness_id_type(1)(db);
@ -690,10 +702,29 @@ BOOST_AUTO_TEST_CASE( voting )
BOOST_CHECK_EQUAL(witness1.total_votes, 100);
BOOST_CHECK_EQUAL(witness2.total_votes, 100);
advance_x_maint(4);
// vesting performance is 1 for both alice and bob during whole gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(3);
// vesting performance is 1 for both alice and bob during whole gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(1);
// new subperiod started, vesting performance is decreased to 5/6 for both alice and bob, until they vote
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0);
//Bob votes for witness2 - sub-period 2
vote_for(bob_id, witness2.vote_id, bob_private_key);
// after voting, vesting performance is 5/6 for alice and 1 for bob
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
// go to maint
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
// vote decay as time pass
@ -703,9 +734,35 @@ BOOST_AUTO_TEST_CASE( voting )
BOOST_CHECK_EQUAL(witness1.total_votes, 83);
BOOST_CHECK_EQUAL(witness2.total_votes, 100);
advance_x_maint(10);
// after voting, vesting performance is 5/6 for alice and 1 for bob
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(4);
// vesting performance does not change during gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(4);
// vesting performance does not change during gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(1);
// new subperiod started, vesting performance is decreased to 4/6 for alice and 5/6 for bob, until they vote
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 4.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0);
//Bob votes for witness2 - sub-period 3
vote_for(bob_id, witness2.vote_id, bob_private_key);
// after voting, vesting performance is 4/6 for alice and 1 for bob
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 4.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
// decay more
witness1 = witness_id_type(1)(db);
@ -713,7 +770,27 @@ BOOST_AUTO_TEST_CASE( voting )
BOOST_CHECK_EQUAL(witness1.total_votes, 66);
BOOST_CHECK_EQUAL(witness2.total_votes, 100);
advance_x_maint(10);
// after voting, vesting performance is 4/6 for alice and 1 for bob
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 4.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(4);
// vesting performance does not change during gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 4.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(4);
// vesting performance does not change during gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 4.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(1);
// new subperiod started, vesting performance is decreased to 3/6 for alice and 5/6 for bob, until they vote
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 3.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0);
// Bob votes for witness2 - sub-period 4
vote_for(bob_id, witness2.vote_id, bob_private_key);
@ -724,7 +801,27 @@ BOOST_AUTO_TEST_CASE( voting )
BOOST_CHECK_EQUAL(witness1.total_votes, 50);
BOOST_CHECK_EQUAL(witness2.total_votes, 100);
advance_x_maint(10);
// after voting, vesting performance is 3/6 for alice and 1 for bob
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 3.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(4);
// vesting performance does not change during gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 3.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(4);
// vesting performance does not change during gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 3.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(1);
// new subperiod started, vesting performance is decreased to 2/6 for alice and 5/6 for bob, until they vote
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 2.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0);
// Bob votes for witness2 - sub-period 5
vote_for(bob_id, witness2.vote_id, bob_private_key);
@ -736,7 +833,27 @@ BOOST_AUTO_TEST_CASE( voting )
BOOST_CHECK_EQUAL(witness1.total_votes, 33);
BOOST_CHECK_EQUAL(witness2.total_votes, 100);
advance_x_maint(10);
// after voting, vesting performance is 2/6 for alice and 1 for bob
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 2.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(4);
// vesting performance does not change during gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 2.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(4);
// vesting performance does not change during gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 2.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(1);
// new subperiod started, vesting performance is decreased to 1/6 for alice and 5/6 for bob, until they vote
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0);
// Bob votes for witness2 - sub-period 6
vote_for(bob_id, witness2.vote_id, bob_private_key);
@ -747,14 +864,31 @@ BOOST_AUTO_TEST_CASE( voting )
BOOST_CHECK_EQUAL(witness1.total_votes, 16);
BOOST_CHECK_EQUAL(witness2.total_votes, 100);
// after voting, vesting performance is 1/6 for alice and 1 for bob
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
// we are still in gpos period 1
BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), now.sec_since_epoch());
advance_x_maint(5);
advance_x_maint(8);
// vesting performance does not change during gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(1);
// a new GPOS period is in but vote from user is before the start. Whoever votes in 6th sub-period, votes will carry
now = db.head_block_time();
BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), HARDFORK_GPOS_TIME.sec_since_epoch() + db.get_global_properties().parameters.gpos_period());
// new gpos period and his first subperiod started,
// vesting performance is decreased to 0 for alice, as she did not vote
// but stays 1 for bob, as he voted in last subperiod in previous gpos period
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1 );
generate_block();
// we are in the second GPOS period, at subperiod 1,
@ -764,12 +898,14 @@ BOOST_AUTO_TEST_CASE( voting )
//It's critical here, since bob votes in 6th sub-period of last vesting period, witness2 should retain his votes
BOOST_CHECK_EQUAL(witness2.total_votes, 100);
// lets vote here from alice to generate votes for witness 1
//vote from bob to reatin VF 1
vote_for(alice_id, witness1.vote_id, alice_private_key);
vote_for(bob_id, witness2.vote_id, bob_private_key);
generate_block();
// after voting, vesting performance is 1 for both alice and bob
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
// go to maint
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
@ -780,7 +916,17 @@ BOOST_AUTO_TEST_CASE( voting )
BOOST_CHECK_EQUAL(witness1.total_votes, 100);
BOOST_CHECK_EQUAL(witness2.total_votes, 100);
advance_x_maint(10);
advance_x_maint(8);
// vesting performance does not change during gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(1);
// new subperiod started, vesting performance is decreased to 5/6 for both alice and bob, until they vote
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0);
witness1 = witness_id_type(1)(db);
witness2 = witness_id_type(2)(db);
@ -791,7 +937,21 @@ BOOST_AUTO_TEST_CASE( voting )
vote_for(bob_id, witness2.vote_id, bob_private_key);
generate_block();
advance_x_maint(10);
// after voting, vesting performance is 5/6 for alice and 1 for bob
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(9);
// vesting performance does not change during gpos subperiod
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 5.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 1);
advance_x_maint(1);
// new subperiod started, vesting performance is decreased to 4/6 for alice and 5/6 for bob, until they vote
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 4.0/6.0);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0);
witness1 = witness_id_type(1)(db);
witness2 = witness_id_type(2)(db);
@ -801,6 +961,11 @@ BOOST_AUTO_TEST_CASE( voting )
// alice votes again, now for witness 2, her vote worth 100 now
vote_for(alice_id, witness2.vote_id, alice_private_key);
// after voting, vesting performance is 1 for alice and 5.0/6.0 for bob
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(alice_id(db)), 1);
BOOST_CHECK_EQUAL(db.calculate_vesting_factor(bob_id(db)), 5.0/6.0);
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
witness1 = witness_id_type(1)(db);