Skip to content

Commit

Permalink
Progress #8: Test shorts and force settles
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielhourt committed Jul 7, 2015
1 parent 8f25a3f commit 3d60449
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/exceptions.hpp>

#include <functional>

Expand Down Expand Up @@ -394,6 +395,8 @@ void_result asset_settle_evaluator::do_evaluate(const asset_settle_evaluator::op
FC_ASSERT(asset_to_settle->can_force_settle() || bitasset.has_settlement() );
if( bitasset.is_prediction_market )
FC_ASSERT( bitasset.has_settlement(), "global settlement must occur before force settling a prediction market" );
else if( bitasset.current_feed.settlement_price.is_null() )
FC_THROW_EXCEPTION(insufficient_feeds, "Cannot force settle with no price feed.");
FC_ASSERT(d.get_balance(d.get(op.account), *asset_to_settle) >= op.amount);

return void_result();
Expand Down
5 changes: 3 additions & 2 deletions libraries/chain/call_order_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/exceptions.hpp>
#include <fc/uint128.hpp>

namespace graphene { namespace chain {
Expand All @@ -43,8 +44,8 @@ void_result call_order_update_evaluator::do_evaluate(const call_order_update_ope

if( _bitasset_data->is_prediction_market )
FC_ASSERT( o.delta_collateral.amount == o.delta_debt.amount );
else
FC_ASSERT( !_bitasset_data->current_feed.settlement_price.is_null() );
else if( _bitasset_data->current_feed.settlement_price.is_null() )
FC_THROW_EXCEPTION(insufficient_feeds, "Cannot borrow asset with no price feed.");

if( o.delta_debt.amount < 0 )
{
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/graphene/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace graphene { namespace chain {
* @class database
* @brief tracks the blockchain state in an extensible manner
*/
class database : public object_database
class database : public db::object_database
{
public:
//////////////////// db_management.cpp ////////////////////
Expand Down
14 changes: 12 additions & 2 deletions tests/common/database_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ using namespace graphene::db;
#define INVOKE(test) ((struct test*)this)->test_method(); trx.clear()

#define PREP_ACTOR(name) \
fc::ecc::private_key name ## _private_key = generate_private_key(BOOST_PP_STRINGIZE(name));
fc::ecc::private_key name ## _private_key = generate_private_key(BOOST_PP_STRINGIZE(name));

#define ACTOR(name) \
PREP_ACTOR(name) \
Expand Down Expand Up @@ -146,10 +146,20 @@ struct database_fixture {
);

void force_global_settle(const asset_object& what, const price& p);
void force_settle(account_id_type who, asset what)
{ force_settle(who(db), what); }
void force_settle(const account_object& who, asset what);
void update_feed_producers(asset_id_type mia, flat_set<account_id_type> producers)
{ update_feed_producers(mia(db), producers); }
void update_feed_producers(const asset_object& mia, flat_set<account_id_type> producers);
void publish_feed(asset_id_type mia, account_id_type by, const price_feed& f)
{ publish_feed(mia(db), by(db), f); }
void publish_feed(const asset_object& mia, const account_object& by, const price_feed& f);
void borrow(account_id_type who, asset what, asset collateral)
{ borrow(who(db), what, collateral); }
void borrow(const account_object& who, asset what, asset collateral);
void cover(account_id_type who, asset what, asset collateral_freed)
{ cover(who(db), what, collateral_freed); }
void cover(const account_object& who, asset what, asset collateral_freed);

const asset_object& get_asset( const string& symbol )const;
Expand All @@ -163,7 +173,7 @@ struct database_fixture {
uint16_t market_fee_percent = 100 /*1%*/,
uint16_t flags = charge_market_fee);
const asset_object& create_user_issued_asset( const string& name );
const asset_object& create_user_issued_asset( const string& name,
const asset_object& create_user_issued_asset( const string& name,
const account_object& issuer,
uint16_t flags );
void issue_uia( const account_object& recipient, asset amount );
Expand Down

0 comments on commit 3d60449

Please sign in to comment.