added new betting test - try_create_sport_and_try_again
This commit is contained in:
parent
fb22da620d
commit
054423dce0
4 changed files with 82 additions and 4 deletions
|
|
@ -68,6 +68,61 @@ BOOST_AUTO_TEST_CASE(generate_block)
|
|||
}
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_CASE(try_create_sport_and_try_again)
|
||||
{
|
||||
try
|
||||
{
|
||||
// "even" witnesses will approve the proposal
|
||||
// we're expecting only 5 approvals, 6 needed
|
||||
fc::optional<sport_id_type> sport_id = try_create_sport({{"en", "Ice Hockey"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}});
|
||||
BOOST_REQUIRE(!sport_id.valid());
|
||||
|
||||
// adding new active witness
|
||||
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
|
||||
account_update_operation op;
|
||||
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);
|
||||
sign( trx, nathan_private_key );
|
||||
PUSH_TX( db, trx );
|
||||
trx.clear();
|
||||
|
||||
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
|
||||
// make sure nathan is in active_witnesses
|
||||
auto itr = std::find(witnesses.begin(), witnesses.end(), nathan_witness_id);
|
||||
BOOST_CHECK(itr != witnesses.end());
|
||||
|
||||
// now we're expecting 6 votes for
|
||||
sport_id = try_create_sport({{"en", "Ice Hockey"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}});
|
||||
BOOST_REQUIRE(sport_id.valid());
|
||||
BOOST_REQUIRE(*sport_id == sport_id_type());
|
||||
|
||||
} FC_LOG_AND_RETHROW()
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(simple_bet_win)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -1111,8 +1111,9 @@ vector< operation_history_object > database_fixture::get_operation_history( acco
|
|||
return result;
|
||||
}
|
||||
|
||||
void database_fixture::process_operation_by_witnesses(operation op)
|
||||
void database_fixture::process_operation_by_witnesses(operation op, bool not_all)
|
||||
{
|
||||
uint16_t count = -1;
|
||||
const flat_set<witness_id_type>& active_witnesses = db.get_global_properties().active_witnesses;
|
||||
|
||||
proposal_create_operation proposal_op;
|
||||
|
|
@ -1130,6 +1131,13 @@ void database_fixture::process_operation_by_witnesses(operation op)
|
|||
|
||||
for (const witness_id_type& witness_id : active_witnesses)
|
||||
{
|
||||
if (not_all)
|
||||
{
|
||||
if (++count % 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const witness_object& witness = witness_id(db);
|
||||
const account_object& witness_account = witness.witness_account(db);
|
||||
|
||||
|
|
@ -1144,13 +1152,26 @@ void database_fixture::process_operation_by_witnesses(operation op)
|
|||
sign(tx, init_account_priv_key);
|
||||
|
||||
db.push_transaction(tx, ~0);
|
||||
|
||||
const auto& proposal_idx = db.get_index_type<proposal_index>().indices().get<by_id>();
|
||||
if (proposal_idx.find(proposal_id) == proposal_idx.end())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fc::optional<sport_id_type> database_fixture::try_create_sport(internationalized_string_type name)
|
||||
{ try {
|
||||
fc::optional<sport_id_type> result;
|
||||
sport_create_operation sport_create_op;
|
||||
sport_create_op.name = name;
|
||||
process_operation_by_witnesses(sport_create_op, true);
|
||||
const auto& sport_index = db.get_index_type<sport_object_index>().indices().get<by_id>();
|
||||
if (sport_index.rbegin() != sport_index.rend())
|
||||
{
|
||||
result = (*sport_index.rbegin()).id;
|
||||
}
|
||||
return result;
|
||||
} FC_CAPTURE_AND_RETHROW( (name) ) }
|
||||
|
||||
const sport_object& database_fixture::create_sport(internationalized_string_type name)
|
||||
{ try {
|
||||
sport_create_operation sport_create_op;
|
||||
|
|
|
|||
|
|
@ -284,7 +284,8 @@ struct database_fixture {
|
|||
account_id_type dividend_holder_account_id,
|
||||
asset_id_type dividend_payout_asset_type) const;
|
||||
vector< operation_history_object > get_operation_history( account_id_type account_id )const;
|
||||
void process_operation_by_witnesses(operation op);
|
||||
void process_operation_by_witnesses(operation op, bool not_all = false);
|
||||
fc::optional<sport_id_type> try_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_object& create_event(internationalized_string_type name, internationalized_string_type season, event_group_id_type event_group_id);
|
||||
|
|
|
|||
|
|
@ -1085,7 +1085,8 @@ BOOST_FIXTURE_TEST_CASE( rsf_missed_blocks, database_fixture )
|
|||
FC_LOG_AND_RETHROW()
|
||||
}
|
||||
|
||||
// the test should be revised
|
||||
// the test written in 2015 should be revised, currently it is not possible to push block to db2
|
||||
// without skip_witness_signature | skip_witness_schedule_check | skip_authority_check
|
||||
BOOST_FIXTURE_TEST_CASE( transaction_invalidated_in_cache, database_fixture )
|
||||
{
|
||||
try
|
||||
|
|
|
|||
Loading…
Reference in a new issue