From 09706ae3a6b3ed901522fcf89dcd419f95a51bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bujak?= Date: Fri, 12 Jan 2018 09:01:44 +0100 Subject: [PATCH 1/3] Made validate_smt_invariants a part of validate_database #1515 --- tests/db_fixture/database_fixture.cpp | 3 +++ tests/tests/smt_operation_tests.cpp | 9 ++++++++- tests/tests/smt_tests.cpp | 18 ++++++------------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/tests/db_fixture/database_fixture.cpp b/tests/db_fixture/database_fixture.cpp index df161504f7..e2fc040fe7 100644 --- a/tests/db_fixture/database_fixture.cpp +++ b/tests/db_fixture/database_fixture.cpp @@ -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(); } diff --git a/tests/tests/smt_operation_tests.cpp b/tests/tests/smt_operation_tests.cpp index fa1e559dc9..3e0d528e5b 100644 --- a/tests/tests/smt_operation_tests.cpp +++ b/tests/tests/smt_operation_tests.cpp @@ -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(); @@ -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(); @@ -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 >(); @@ -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(); diff --git a/tests/tests/smt_tests.cpp b/tests/tests/smt_tests.cpp index 5a3364a364..6075f370a5 100644 --- a/tests/tests/smt_tests.cpp +++ b/tests/tests/smt_tests.cpp @@ -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() } @@ -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() } @@ -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() } @@ -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() } @@ -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() } @@ -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() } From 3a9e88d33bd16a72d927f0c2a4507927fee6539e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bujak?= Date: Fri, 12 Jan 2018 09:57:46 +0100 Subject: [PATCH 2/3] Added market orders to SMT total supply control in validate_smt_invariants #1515 --- libraries/chain/database.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 94317df8b5..e03930c3fc 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -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." ) From 8ad15730cba646c4a64b0d1ca21601943ef407b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bujak?= Date: Fri, 12 Jan 2018 11:47:01 +0100 Subject: [PATCH 3/3] A fix to smt_mh_test plugin test #1515 --- tests/plugin_tests/smt_market_history.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/plugin_tests/smt_market_history.cpp b/tests/plugin_tests/smt_market_history.cpp index 2060fdcba7..803abceef4 100644 --- a/tests/plugin_tests/smt_market_history.cpp +++ b/tests/plugin_tests/smt_market_history.cpp @@ -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();