improving try_create_sport test
This commit is contained in:
parent
6fe57fbb74
commit
6aa9057d12
3 changed files with 95 additions and 65 deletions
|
|
@ -68,57 +68,58 @@ BOOST_AUTO_TEST_CASE(generate_block)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(try_create_sport_and_try_again)
|
BOOST_AUTO_TEST_CASE(try_create_sport)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// "even" witnesses will approve the proposal
|
fc::optional<sport_id_type> result;
|
||||||
// we're expecting only 5 approvals, 6 needed
|
sport_create_operation sport_create_op;
|
||||||
fc::optional<sport_id_type> sport_id = try_create_sport({{"en", "Ice Hockey"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}});
|
sport_create_op.name = {{"en", "Ice Hockey"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}};
|
||||||
BOOST_REQUIRE(!sport_id.valid());
|
|
||||||
|
|
||||||
// adding new active witness
|
proposal_id_type proposal_id = propose_operation(sport_create_op);
|
||||||
const auto& witnesses = db.get_global_properties().active_witnesses;
|
|
||||||
ACTOR(nathan);
|
|
||||||
upgrade_to_lifetime_member(nathan_id);
|
|
||||||
trx.clear();
|
|
||||||
witness_id_type nathan_witness_id = create_witness(nathan_id, nathan_private_key).id;
|
|
||||||
// give nathan some voting stake
|
|
||||||
transfer(committee_account, nathan_id, asset(10000000));
|
|
||||||
generate_block();
|
|
||||||
set_expiration( db, trx );
|
|
||||||
|
|
||||||
// "even" witnesses vote for nathan
|
const auto& active_witnesses = db.get_global_properties().active_witnesses;
|
||||||
account_update_operation op;
|
int voting_count = active_witnesses.size() / 2;
|
||||||
op.account = nathan_id;
|
|
||||||
op.new_options = nathan_id(db).options;
|
|
||||||
op.new_options->votes.clear();
|
|
||||||
uint16_t count = -1;
|
|
||||||
uint16_t votes = 0;
|
|
||||||
for (const witness_id_type& witness_id : witnesses)
|
|
||||||
{
|
|
||||||
if (++count % 2)
|
|
||||||
continue;
|
|
||||||
op.new_options->votes.insert(witness_id(db).vote_id);
|
|
||||||
++votes;
|
|
||||||
}
|
|
||||||
op.new_options->num_witness = votes;
|
|
||||||
op.new_options->num_committee = 0;
|
|
||||||
|
|
||||||
trx.operations.push_back(op);
|
// 5 for
|
||||||
sign( trx, nathan_private_key );
|
std::vector<witness_id_type> witnesses;
|
||||||
PUSH_TX( db, trx );
|
for (const witness_id_type& witness_id : active_witnesses)
|
||||||
trx.clear();
|
{
|
||||||
|
witnesses.push_back(witness_id);
|
||||||
|
if (--voting_count == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
process_proposal_by_witnesses(witnesses, proposal_id);
|
||||||
|
|
||||||
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
|
// 1st out
|
||||||
// make sure nathan is in active_witnesses
|
witnesses.clear();
|
||||||
auto itr = std::find(witnesses.begin(), witnesses.end(), nathan_witness_id);
|
auto itr = active_witnesses.begin();
|
||||||
BOOST_CHECK(itr != witnesses.end());
|
witnesses.push_back(*itr);
|
||||||
|
process_proposal_by_witnesses(witnesses, proposal_id, true);
|
||||||
|
|
||||||
// now we're expecting 6 votes for
|
const auto& sport_index = db.get_index_type<sport_object_index>().indices().get<by_id>();
|
||||||
sport_id = try_create_sport({{"en", "Ice Hockey"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}});
|
// not yet approved
|
||||||
BOOST_REQUIRE(sport_id.valid());
|
BOOST_REQUIRE(sport_index.rbegin() == sport_index.rend());
|
||||||
BOOST_REQUIRE(*sport_id == sport_id_type());
|
|
||||||
|
// 6th for
|
||||||
|
witnesses.clear();
|
||||||
|
itr += 5;
|
||||||
|
witnesses.push_back(*itr);
|
||||||
|
process_proposal_by_witnesses(witnesses, proposal_id);
|
||||||
|
|
||||||
|
// not yet approved
|
||||||
|
BOOST_REQUIRE(sport_index.rbegin() == sport_index.rend());
|
||||||
|
|
||||||
|
// 7th for
|
||||||
|
witnesses.clear();
|
||||||
|
++itr;
|
||||||
|
witnesses.push_back(*itr);
|
||||||
|
process_proposal_by_witnesses(witnesses, proposal_id);
|
||||||
|
|
||||||
|
// done
|
||||||
|
BOOST_REQUIRE(sport_index.rbegin() != sport_index.rend());
|
||||||
|
sport_id_type sport_id = (*sport_index.rbegin()).id;
|
||||||
|
BOOST_REQUIRE(sport_id == sport_id_type());
|
||||||
|
|
||||||
} FC_LOG_AND_RETHROW()
|
} FC_LOG_AND_RETHROW()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1111,9 +1111,8 @@ vector< operation_history_object > database_fixture::get_operation_history( acco
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database_fixture::process_operation_by_witnesses(operation op, bool not_all)
|
void database_fixture::process_operation_by_witnesses(operation op)
|
||||||
{
|
{
|
||||||
uint16_t count = -1;
|
|
||||||
const flat_set<witness_id_type>& active_witnesses = db.get_global_properties().active_witnesses;
|
const flat_set<witness_id_type>& active_witnesses = db.get_global_properties().active_witnesses;
|
||||||
|
|
||||||
proposal_create_operation proposal_op;
|
proposal_create_operation proposal_op;
|
||||||
|
|
@ -1131,13 +1130,6 @@ void database_fixture::process_operation_by_witnesses(operation op, bool not_all
|
||||||
|
|
||||||
for (const witness_id_type& witness_id : active_witnesses)
|
for (const witness_id_type& witness_id : active_witnesses)
|
||||||
{
|
{
|
||||||
if (not_all)
|
|
||||||
{
|
|
||||||
if (++count % 2)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const witness_object& witness = witness_id(db);
|
const witness_object& witness = witness_id(db);
|
||||||
const account_object& witness_account = witness.witness_account(db);
|
const account_object& witness_account = witness.witness_account(db);
|
||||||
|
|
||||||
|
|
@ -1158,19 +1150,54 @@ void database_fixture::process_operation_by_witnesses(operation op, bool not_all
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fc::optional<sport_id_type> database_fixture::try_create_sport(internationalized_string_type name)
|
proposal_id_type database_fixture::propose_operation(operation op)
|
||||||
{ try {
|
{
|
||||||
fc::optional<sport_id_type> result;
|
const flat_set<witness_id_type>& active_witnesses = db.get_global_properties().active_witnesses;
|
||||||
sport_create_operation sport_create_op;
|
|
||||||
sport_create_op.name = name;
|
proposal_create_operation proposal_op;
|
||||||
process_operation_by_witnesses(sport_create_op, true);
|
proposal_op.fee_paying_account = (*active_witnesses.begin())(db).witness_account;
|
||||||
const auto& sport_index = db.get_index_type<sport_object_index>().indices().get<by_id>();
|
proposal_op.proposed_ops.emplace_back(op);
|
||||||
if (sport_index.rbegin() != sport_index.rend())
|
proposal_op.expiration_time = db.head_block_time() + fc::days(1);
|
||||||
|
|
||||||
|
signed_transaction tx;
|
||||||
|
tx.operations.push_back(proposal_op);
|
||||||
|
set_expiration(db, tx);
|
||||||
|
sign(tx, init_account_priv_key);
|
||||||
|
|
||||||
|
processed_transaction processed_tx = db.push_transaction(tx);
|
||||||
|
proposal_id_type proposal_id = processed_tx.operation_results[0].get<object_id_type>();
|
||||||
|
|
||||||
|
return proposal_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void database_fixture::process_proposal_by_witnesses(const std::vector<witness_id_type>& witnesses, proposal_id_type proposal_id, bool remove)
|
||||||
|
{
|
||||||
|
const auto& proposal_idx = db.get_index_type<proposal_index>().indices().get<by_id>();
|
||||||
|
|
||||||
|
for (const witness_id_type& witness_id : witnesses)
|
||||||
{
|
{
|
||||||
result = (*sport_index.rbegin()).id;
|
if (proposal_idx.find(proposal_id) == proposal_idx.end())
|
||||||
|
break;
|
||||||
|
|
||||||
|
const witness_object& witness = witness_id(db);
|
||||||
|
const account_object& witness_account = witness.witness_account(db);
|
||||||
|
|
||||||
|
proposal_update_operation pup;
|
||||||
|
pup.proposal = proposal_id;
|
||||||
|
pup.fee_paying_account = witness_account.id;
|
||||||
|
if (remove)
|
||||||
|
pup.active_approvals_to_remove.insert(witness_account.id);
|
||||||
|
else
|
||||||
|
pup.active_approvals_to_add.insert(witness_account.id);
|
||||||
|
|
||||||
|
signed_transaction tx;
|
||||||
|
tx.operations.push_back( pup );
|
||||||
|
set_expiration( db, tx );
|
||||||
|
sign(tx, init_account_priv_key);
|
||||||
|
|
||||||
|
db.push_transaction(tx, ~0);
|
||||||
}
|
}
|
||||||
return result;
|
}
|
||||||
} FC_CAPTURE_AND_RETHROW( (name) ) }
|
|
||||||
|
|
||||||
const sport_object& database_fixture::create_sport(internationalized_string_type name)
|
const sport_object& database_fixture::create_sport(internationalized_string_type name)
|
||||||
{ try {
|
{ try {
|
||||||
|
|
|
||||||
|
|
@ -284,8 +284,7 @@ struct database_fixture {
|
||||||
account_id_type dividend_holder_account_id,
|
account_id_type dividend_holder_account_id,
|
||||||
asset_id_type dividend_payout_asset_type) const;
|
asset_id_type dividend_payout_asset_type) const;
|
||||||
vector< operation_history_object > get_operation_history( account_id_type account_id )const;
|
vector< operation_history_object > get_operation_history( account_id_type account_id )const;
|
||||||
void process_operation_by_witnesses(operation op, bool not_all = false);
|
void process_operation_by_witnesses(operation op);
|
||||||
fc::optional<sport_id_type> try_create_sport(internationalized_string_type name);
|
|
||||||
const sport_object& create_sport(internationalized_string_type name);
|
const sport_object& create_sport(internationalized_string_type name);
|
||||||
const event_group_object& create_event_group(internationalized_string_type name, sport_id_type sport_id);
|
const event_group_object& create_event_group(internationalized_string_type name, sport_id_type sport_id);
|
||||||
const event_object& create_event(internationalized_string_type name, internationalized_string_type season, event_group_id_type event_group_id);
|
const event_object& create_event(internationalized_string_type name, internationalized_string_type season, event_group_id_type event_group_id);
|
||||||
|
|
@ -295,6 +294,9 @@ struct database_fixture {
|
||||||
|
|
||||||
void place_bet(account_id_type bettor_id, betting_market_id_type betting_market_id, bet_type back_or_lay, asset amount_to_bet, bet_multiplier_type backer_multiplier, share_type amount_reserved_for_fees);
|
void place_bet(account_id_type bettor_id, betting_market_id_type betting_market_id, bet_type back_or_lay, asset amount_to_bet, bet_multiplier_type backer_multiplier, share_type amount_reserved_for_fees);
|
||||||
void resolve_betting_market_group(betting_market_group_id_type betting_market_group_id, std::map<betting_market_id_type, betting_market_resolution_type> resolutions);
|
void resolve_betting_market_group(betting_market_group_id_type betting_market_group_id, std::map<betting_market_id_type, betting_market_resolution_type> resolutions);
|
||||||
|
|
||||||
|
proposal_id_type propose_operation(operation op);
|
||||||
|
void process_proposal_by_witnesses(const std::vector<witness_id_type>& witnesses, proposal_id_type proposal_id, bool remove = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue