Skip to content

Commit

Permalink
Merge pull request #1983 from steemit/1515-market-order-supply-check
Browse files Browse the repository at this point in the history
1515 market order supply check
  • Loading branch information
Michael Vandeberg authored Jan 15, 2018
2 parents 2ef73e9 + 8ad1573 commit 159a143
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
12 changes: 11 additions & 1 deletion libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4347,7 +4347,17 @@ void database::validate_smt_invariants()const
#pragma message( "TODO: Add SMT vesting support here once it is implemented." )

// - Market orders
#pragma message( "TODO: Add limit_order_object iteration here once they support SMTs." )
const auto& limit_order_idx = get_index< limit_order_index >().indices();
for( auto itr = limit_order_idx.begin(); itr != limit_order_idx.end(); ++itr )
{
if( itr->sell_price.base.symbol.space() == asset_symbol_type::smt_nai_space )
{
asset a( itr->for_sale, itr->sell_price.base.symbol );
auto insertInfo = theMap.emplace( a.symbol, a );
if( insertInfo.second == false )
insertInfo.first->second += a;
}
}

// - Reward funds
#pragma message( "TODO: Add reward_fund_object iteration here once they support SMTs." )
Expand Down
3 changes: 3 additions & 0 deletions tests/db_fixture/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ void database_fixture::validate_database( void )
try
{
db->validate_invariants();
#ifdef STEEM_ENABLE_SMT
db->validate_smt_invariants();
#endif
}
FC_LOG_AND_RETHROW();
}
Expand Down
4 changes: 3 additions & 1 deletion tests/plugin_tests/smt_market_history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ BOOST_AUTO_TEST_CASE( smt_mh_test )
fund( "sam", ASSET( "1000.000 TESTS" ) );

const account_object& alice_account = db->get_account( "alice" );
db->adjust_balance( alice_account, asset( 1000000, any_smt_symbol ) );
asset alice_smt_balance( 1000000, any_smt_symbol );
db->adjust_balance( alice_account, alice_smt_balance );
db->adjust_supply( alice_smt_balance );

tx.operations.clear();
tx.signatures.clear();
Expand Down
9 changes: 8 additions & 1 deletion tests/tests/smt_operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ BOOST_AUTO_TEST_CASE( smt_limit_order_create_apply )
asset bob_balance = bob_account.balance;

db->adjust_balance( alice_account, alice_smt_balance );
db->adjust_supply( alice_smt_balance );
db->adjust_balance( bob_account, bob_smt_balance );
db->adjust_supply( bob_smt_balance );

tx.operations.clear();
tx.signatures.clear();
Expand Down Expand Up @@ -469,7 +471,9 @@ BOOST_AUTO_TEST_CASE( smt_limit_order_cancel_authorities )
asset_symbol_type alice_symbol = create_smt( "alice", alice_private_key, 3 );

const account_object& alice_account = db->get_account( "alice" );
db->adjust_balance( alice_account, asset( 100000, alice_symbol ) );
asset alice_balance( 100000, alice_symbol );
db->adjust_balance( alice_account, alice_balance );
db->adjust_supply( alice_balance );

tx.operations.clear();
tx.signatures.clear();
Expand Down Expand Up @@ -541,6 +545,7 @@ BOOST_AUTO_TEST_CASE( smt_limit_order_cancel_apply )
asset alice_balance = alice_account.balance;

db->adjust_balance( alice_account, alice_smt_balance );
db->adjust_supply( alice_smt_balance );

const auto& limit_order_idx = db->get_index< limit_order_index >().indices().get< by_account >();

Expand Down Expand Up @@ -611,7 +616,9 @@ BOOST_AUTO_TEST_CASE( smt_limit_order_create2_apply )
asset bob_balance = bob_account.balance;

db->adjust_balance( alice_account, alice_smt_balance );
db->adjust_supply( alice_smt_balance );
db->adjust_balance( bob_account, bob_smt_balance );
db->adjust_supply( bob_smt_balance );

tx.operations.clear();
tx.signatures.clear();
Expand Down
18 changes: 6 additions & 12 deletions tests/tests/smt_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ BOOST_AUTO_TEST_CASE( smt_create_apply )
op.smt_creation_fee = asset( too_low_fee_amount, SBD_SYMBOL );
FAIL_WITH_OP(op, bob_private_key, fc::assert_exception);

db->validate_invariants();
db->validate_smt_invariants();
validate_database();
}
FC_LOG_AND_RETHROW()
}
Expand Down Expand Up @@ -382,8 +381,7 @@ BOOST_AUTO_TEST_CASE( setup_emissions_apply )
FAIL_WITH_OP(fail_op, alice_private_key, fc::assert_exception)
}

db->validate_invariants();
db->validate_smt_invariants();
validate_database();
}
FC_LOG_AND_RETHROW()
}
Expand Down Expand Up @@ -445,8 +443,7 @@ BOOST_AUTO_TEST_CASE( set_setup_parameters_apply )
// - check applying smt_set_setup_parameters_operation after setup completed
}

db->validate_invariants();
db->validate_smt_invariants();
validate_database();
}
FC_LOG_AND_RETHROW()
}
Expand Down Expand Up @@ -601,8 +598,7 @@ BOOST_AUTO_TEST_CASE( runtime_parameters_apply )
PUSH_OP(op, alice_private_key);
}

db->validate_invariants();
db->validate_smt_invariants();
validate_database();
}
FC_LOG_AND_RETHROW()
}
Expand All @@ -623,8 +619,7 @@ BOOST_AUTO_TEST_CASE( smt_transfer_validate )
op.amount = asset(100, alice_symbol);
op.validate();

db->validate_invariants();
db->validate_smt_invariants();
validate_database();
}
FC_LOG_AND_RETHROW()
}
Expand Down Expand Up @@ -667,8 +662,7 @@ BOOST_AUTO_TEST_CASE( smt_transfer_apply )
FC_ASSERT( db->get_balance( "bob", alice_symbol ).amount == 20, "SMT transfer error" );
FC_ASSERT( db->get_balance( "bob", bob_symbol ).amount == 60, "SMT transfer error" );

db->validate_invariants();
db->validate_smt_invariants();
validate_database();
}
FC_LOG_AND_RETHROW()
}
Expand Down

0 comments on commit 159a143

Please sign in to comment.