From c1d41e2987939f6c4d38d085c849f80427006da1 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 22 Oct 2017 14:03:19 +0200 Subject: [PATCH 01/74] Fixed js_operation_serializer --- programs/CMakeLists.txt | 2 +- programs/js_operation_serializer/main.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index 1ed11b0..130be60 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -1,6 +1,6 @@ add_subdirectory( cli_wallet ) add_subdirectory( mused ) #add_subdirectory( delayed_node ) -#add_subdirectory( js_operation_serializer ) +add_subdirectory( js_operation_serializer ) #add_subdirectory( size_checker ) #add_subdirectory( util ) diff --git a/programs/js_operation_serializer/main.cpp b/programs/js_operation_serializer/main.cpp index 56beeec..0da797b 100644 --- a/programs/js_operation_serializer/main.cpp +++ b/programs/js_operation_serializer/main.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include From 0fa86fe5d384ef44e0521af2bfd9bc0f0c99f6a8 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 31 Oct 2017 21:50:24 +0100 Subject: [PATCH 02/74] Removed live_tests + unused method --- libraries/chain/database.cpp | 33 ---- .../chain/include/muse/chain/database.hpp | 1 - tests/tests/live_tests.cpp | 177 ------------------ 3 files changed, 211 deletions(-) delete mode 100644 tests/tests/live_tests.cpp diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 03c57e3..24568f3 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -3431,39 +3431,6 @@ void database::perform_vesting_share_split( uint32_t magnitude ) } -void database::retally_witness_votes() -{ - const auto& witness_idx = get_index_type< witness_index >().indices(); - - // Clear all witness votes - for( auto itr = witness_idx.begin(); itr != witness_idx.end(); ++itr ) - { - modify( *itr, [&]( witness_object& w ) - { - w.votes = 0; - w.virtual_position = 0; - } ); - } - - const auto& account_idx = get_index_type< account_index >().indices(); - - // Apply all existing votes by account - for( auto itr = account_idx.begin(); itr != account_idx.end(); ++itr ) - { - if( itr->proxy != MUSE_PROXY_TO_SELF_ACCOUNT ) continue; - - const auto& a = *itr; - - const auto& vidx = get_index_type().indices().get(); - auto wit_itr = vidx.lower_bound( boost::make_tuple( a.get_id(), witness_id_type() ) ); - while( wit_itr != vidx.end() && wit_itr->account == a.get_id() ) - { - adjust_witness_vote( wit_itr->witness(*this), a.witness_vote_weight() ); - ++wit_itr; - } - } -} - void database::retally_witness_vote_counts( bool force ) { const auto& account_idx = get_index_type< account_index >().indices(); diff --git a/libraries/chain/include/muse/chain/database.hpp b/libraries/chain/include/muse/chain/database.hpp index 29639a1..9f95f9b 100644 --- a/libraries/chain/include/muse/chain/database.hpp +++ b/libraries/chain/include/muse/chain/database.hpp @@ -389,7 +389,6 @@ namespace muse { namespace chain { int match( const limit_order_object& bid, const limit_order_object& ask, const price& trade_price ); void perform_vesting_share_split( uint32_t magnitude ); - void retally_witness_votes(); void retally_witness_vote_counts( bool force = false ); void retally_liquidity_weight(); diff --git a/tests/tests/live_tests.cpp b/tests/tests/live_tests.cpp deleted file mode 100644 index b540a56..0000000 --- a/tests/tests/live_tests.cpp +++ /dev/null @@ -1,177 +0,0 @@ -#include - -#include -#include -#include - -#include - -#include - -#include "../common/database_fixture.hpp" - -#include - -using namespace muse::chain; -using namespace muse::chain::test; - -#ifndef IS_TEST_NET - -BOOST_FIXTURE_TEST_SUITE( live_tests, live_database_fixture ) - -BOOST_AUTO_TEST_CASE( vests_stock_split ) -{ - try - { - /*BOOST_TEST_MESSAGE( "Gathering state prior to split" ); - - uint32_t magnitude = 1000000; - - flat_map< string, share_type > account_vests; - flat_map< string, share_type > account_vsf_votes; - const auto& acnt_idx = db.get_index_type< account_index >().indices().get< by_name >(); - auto acnt_itr = acnt_idx.begin(); - - BOOST_TEST_MESSAGE( "Saving account vesting shares" ); - - while( acnt_itr != acnt_idx.end() ) - { - account_vests[acnt_itr->name] = acnt_itr->vesting_shares.amount; - account_vsf_votes[acnt_itr->name] = acnt_itr->proxied_vsf_votes_total().value; - acnt_itr++; - } - - auto old_virtual_supply = db.get_dynamic_global_properties().virtual_supply; - auto old_current_supply = db.get_dynamic_global_properties().current_supply; - auto old_vesting_fund = db.get_dynamic_global_properties().total_vesting_fund_muse; - auto old_vesting_shares = db.get_dynamic_global_properties().total_vesting_shares; - auto old_reward_fund = db.get_dynamic_global_properties().total_reward_fund_muse; - - flat_map< std::tuple< string, string >, share_type > comment_net_rshares; - flat_map< std::tuple< string, string >, share_type > comment_abs_rshares; - - fc::uint128_t total_rshares2 = 0; - const auto& com_idx = db.get_index_type< comment_index >().indices().get< by_permlink >(); - auto com_itr = com_idx.begin(); - auto gpo = db.get_dynamic_global_properties(); - - BOOST_TEST_MESSAGE( "Saving comment rshare values" ); - - while( com_itr != com_idx.end() ) - { - comment_net_rshares[ std::make_tuple( com_itr->author, com_itr->permlink ) ] = com_itr->net_rshares; - comment_abs_rshares[ std::make_tuple( com_itr->author, com_itr->permlink ) ] = com_itr->abs_rshares; - total_vote_weights[ com_itr->id ] = 0; - orig_vote_weight[ com_itr->id ] = com_itr->total_vote_weight; - - if( com_itr->net_rshares.value > 0 ) - { - total_rshares2 += com_itr->net_rshares.value > 0 ? fc::uint128_t( com_itr->net_rshares.value ) * com_itr->net_rshares.value * magnitude * magnitude : 0; - u256 rs( com_itr->net_rshares.value ); - u256 rf( gpo.total_reward_fund_muse.amount.value ); - auto rs2 = rs * rs; - u256 rshares2 = old_rshares2.hi; - rshares2 = rshares2 << 64; - rshares2 += old_rshares2.lo; - expected_reward[ com_itr->id ] = static_cast< uint64_t >( rf * rs2 / rshares2 ); - } - com_itr++; - } - - BOOST_TEST_MESSAGE( "Saving category rshares" ); - - const auto& cat_idx = db.get_index_type< category_index >().indices(); - flat_map< category_id_type, share_type > category_rshares; - - for( auto cat_itr = cat_idx.begin(); cat_itr != cat_idx.end(); cat_itr++ ) - { - category_rshares[ cat_itr->id ] = cat_itr->abs_rshares; - } - - BOOST_TEST_MESSAGE( "Perform split" ); - fc::time_point start = fc::time_point::now(); - db.perform_vesting_share_split( magnitude ); - fc::time_point end = fc::time_point::now(); - ilog( "Vesting split execution time: ${t} us", ("t",end - start) ); - - BOOST_TEST_MESSAGE( "Verify split took place correctly" ); - - BOOST_REQUIRE( db.get_dynamic_global_properties().current_supply == old_current_supply ); - BOOST_REQUIRE( db.get_dynamic_global_properties().virtual_supply == old_virtual_supply ); - BOOST_REQUIRE( db.get_dynamic_global_properties().total_vesting_fund_muse == old_vesting_fund ); - BOOST_REQUIRE( db.get_dynamic_global_properties().total_vesting_shares.amount == old_vesting_shares.amount * magnitude ); - BOOST_REQUIRE( db.get_dynamic_global_properties().total_reward_shares2 == total_rshares2 ); - BOOST_REQUIRE( db.get_dynamic_global_properties().total_reward_fund_muse == old_reward_fund ); - - BOOST_TEST_MESSAGE( "Check accounts were updated" ); - acnt_itr = acnt_idx.begin(); - while( acnt_itr != acnt_idx.end() ) - { - BOOST_REQUIRE( acnt_itr->vesting_shares.amount == account_vests[ acnt_itr->name ] * magnitude ); - BOOST_REQUIRE( acnt_itr->proxied_vsf_votes_total().value == account_vsf_votes[ acnt_itr->name ] * magnitude ); - acnt_itr++; - } - - gpo = db.get_dynamic_global_properties(); - - com_itr = com_idx.begin(); - while( com_itr != com_idx.end() ) - { - BOOST_REQUIRE( com_itr->net_rshares == comment_net_rshares[ std::make_tuple( com_itr->author, com_itr->permlink ) ] * magnitude ); - BOOST_REQUIRE( com_itr->abs_rshares == comment_abs_rshares[ std::make_tuple( com_itr->author, com_itr->permlink ) ] * magnitude ); - BOOST_REQUIRE( com_itr->total_vote_weight == total_vote_weights[ com_itr->id ] ); - - if( com_itr->net_rshares.value > 0 ) - { - u256 rs( com_itr->net_rshares.value ); - u256 rf( gpo.total_reward_fund_muse.amount.value ); - u256 rshares2 = total_rshares2.hi; - rshares2 = ( rshares2 << 64 ) + total_rshares2.lo; - auto rs2 = rs * rs; - - BOOST_REQUIRE( static_cast< uint64_t >( ( rf * rs2 ) / rshares2 ) == expected_reward[ com_itr->id] ); - } - com_itr++; - } - - for( auto cat_itr = cat_idx.begin(); cat_itr != cat_idx.end(); cat_itr++ ) - { - BOOST_REQUIRE( cat_itr->abs_rshares.value == category_rshares[ cat_itr->id ].value * magnitude ); - } - - validate_database();*/ - } - FC_LOG_AND_RETHROW() -} - -BOOST_AUTO_TEST_CASE( retally_votes ) -{ - try - { - flat_map< witness_id_type, share_type > expected_votes; - - const auto& by_account_witness_idx = db.get_index_type< witness_vote_index >().indices(); - - for( auto vote: by_account_witness_idx ) - { - if( expected_votes.find( vote.witness ) == expected_votes.end() ) - expected_votes[ vote.witness ] = vote.account( db ).witness_vote_weight(); - else - expected_votes[ vote.witness ] += vote.account( db ).witness_vote_weight(); - } - - db.retally_witness_votes(); - - const auto& witness_idx = db.get_index_type< witness_index >().indices(); - - for( auto witness: witness_idx ) - { - BOOST_REQUIRE_EQUAL( witness.votes.value, expected_votes[ witness.id ].value ); - } - } - FC_LOG_AND_RETHROW() -} - -BOOST_AUTO_TEST_SUITE_END() - -#endif From d87a16c8c0109a6ffa8d9aab0b458d7405cbce6e Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 31 Oct 2017 22:58:53 +0100 Subject: [PATCH 03/74] Got basic_tests to work --- libraries/chain/database.cpp | 2 +- tests/common/database_fixture.cpp | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 24568f3..7258d6c 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -2259,7 +2259,7 @@ void database::init_genesis( const genesis_state_type& initial_allocation ) p.time = MUSE_GENESIS_TIME; p.recent_slots_filled = fc::uint128::max_value(); p.participation_count = 128; - p.current_supply = asset( 0, MUSE_SYMBOL );//asset( initial_allocation.init_supply, MUSE_SYMBOL ); + p.current_supply = asset( initial_allocation.init_supply + 10 * (MUSE_NUM_INIT_MINERS - 1), MUSE_SYMBOL ); p.virtual_supply = p.current_supply; p.maximum_block_size = MUSE_MAX_BLOCK_SIZE; } ); diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 2bd9240..0fe9277 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -51,9 +51,19 @@ clean_database_fixture::clean_database_fixture() ahplugin->plugin_set_app( &app ); ahplugin->plugin_initialize( options ); + validate_database(); generate_block(); + validate_database(); + + { + const account_object& init_acct = db.get_account( MUSE_INIT_MINER_NAME ); + db.modify( init_acct, [&]( account_object& acct ) { + acct.active.add_authority( init_account_pub_key, acct.active.weight_threshold ); + }); + } + db.set_hardfork( MUSE_NUM_HARDFORKS ); - vest( "initminer", 10000 ); + vest( MUSE_INIT_MINER_NAME, 10000 ); // Fill up the rest of the required miners for( int i = MUSE_NUM_INIT_MINERS; i < MUSE_MAX_MINERS; i++ ) @@ -143,11 +153,18 @@ string database_fixture::generate_anon_acct_name() return "anon-acct-x" + std::to_string( anon_acct_count++ ); } +static genesis_state_type prepare_genesis() { + genesis_state_type result; + result.init_supply = 10000 * MUSE_ASSET_PRECISION; + return result; +} + void database_fixture::open_database() { if( !data_dir ) { data_dir = fc::temp_directory( graphene::utilities::temp_directory_path() ); - db.open( data_dir->path() ); + const genesis_state_type genesis = prepare_genesis(); + db.open( data_dir->path(), genesis ); } } From 3470a82ba3513cce4756e854766ae84ecf5ec02b Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 1 Nov 2017 23:16:43 +0100 Subject: [PATCH 04/74] Made block_tests work --- tests/common/database_fixture.cpp | 6 +- tests/tests/block_tests.cpp | 388 ++++++++---------------------- 2 files changed, 108 insertions(+), 286 deletions(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 0fe9277..1c01078 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -60,6 +60,10 @@ clean_database_fixture::clean_database_fixture() db.modify( init_acct, [&]( account_object& acct ) { acct.active.add_authority( init_account_pub_key, acct.active.weight_threshold ); }); + const witness_object& init_witness = db.get_witness( MUSE_INIT_MINER_NAME ); + db.modify( init_witness, [&]( witness_object& witness ) { + witness.signing_key = init_account_pub_key; + }); } db.set_hardfork( MUSE_NUM_HARDFORKS ); @@ -155,7 +159,7 @@ string database_fixture::generate_anon_acct_name() static genesis_state_type prepare_genesis() { genesis_state_type result; - result.init_supply = 10000 * MUSE_ASSET_PRECISION; + result.init_supply = 10000 * asset::scaled_precision( MUSE_ASSET_PRECISION ); return result; } diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 49e7d10..c15bf05 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifdef IS_TEST_NET #include #include @@ -101,6 +100,30 @@ BOOST_AUTO_TEST_CASE( block_database_test ) } } +static const fc::ecc::private_key& init_account_priv_key() +{ + static const auto priv_key = fc::ecc::private_key::regenerate( fc::sha256::hash( string( "init_key" ) ) ); + return priv_key; +} + +static const fc::ecc::public_key& init_account_pub_key() +{ + static const auto pub_key = init_account_priv_key().get_public_key(); + return pub_key; +} + +static void init_witness_keys( muse::chain::database& db ) +{ + const account_object& init_acct = db.get_account( MUSE_INIT_MINER_NAME ); + db.modify( init_acct, []( account_object& acct ) { + acct.active.add_authority( init_account_pub_key(), acct.active.weight_threshold ); + }); + const witness_object& init_witness = db.get_witness( MUSE_INIT_MINER_NAME ); + db.modify( init_witness, []( witness_object& witness ) { + witness.signing_key = init_account_pub_key(); + }); +} + BOOST_AUTO_TEST_CASE( generate_empty_blocks ) { try { @@ -108,13 +131,16 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) fc::temp_directory data_dir( graphene::utilities::temp_directory_path() ); signed_block b; + genesis_state_type genesis; + genesis.init_supply = INITIAL_TEST_SUPPLY; + // TODO: Don't generate this here - auto init_account_priv_key = fc::ecc::private_key::regenerate( fc::sha256::hash( string( "init_key" ) ) ); signed_block cutoff_block; { database db; - db.open(data_dir.path(), INITIAL_TEST_SUPPLY ); - b = db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + db.open(data_dir.path(), genesis ); + init_witness_keys( db ); + b = db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1), init_account_priv_key(), database::skip_nothing); // TODO: Change this test when we correct #406 // n.b. we generate MUSE_MIN_UNDO_HISTORY+1 extra blocks which will be discarded on save @@ -124,7 +150,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) //witness_id_type prev_witness = b.witness; string cur_witness = db.get_scheduled_witness(1); //BOOST_CHECK( cur_witness != prev_witness ); - b = db.generate_block(db.get_slot_time(1), cur_witness, init_account_priv_key, database::skip_nothing); + b = db.generate_block(db.get_slot_time(1), cur_witness, init_account_priv_key(), database::skip_nothing); BOOST_CHECK( b.witness == cur_witness ); uint32_t cutoff_height = db.get_dynamic_global_properties().last_irreversible_block_num; if( cutoff_height >= 200 ) @@ -137,7 +163,8 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) } { database db; - db.open(data_dir.path(), INITIAL_TEST_SUPPLY ); + db.open(data_dir.path(), genesis ); + init_witness_keys( db ); BOOST_CHECK_EQUAL( db.head_block_num(), cutoff_block.block_num() ); b = cutoff_block; for( uint32_t i = 0; i < 200; ++i ) @@ -146,7 +173,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) //witness_id_type prev_witness = b.witness; string cur_witness = db.get_scheduled_witness(1); //BOOST_CHECK( cur_witness != prev_witness ); - b = db.generate_block(db.get_slot_time(1), cur_witness, init_account_priv_key, database::skip_nothing); + b = db.generate_block(db.get_slot_time(1), cur_witness, init_account_priv_key(), database::skip_nothing); } BOOST_CHECK_EQUAL( db.head_block_num(), cutoff_block.block_num()+200 ); } @@ -159,19 +186,22 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) BOOST_AUTO_TEST_CASE( undo_block ) { try { + genesis_state_type genesis; + genesis.init_supply = INITIAL_TEST_SUPPLY; + fc::temp_directory data_dir( graphene::utilities::temp_directory_path() ); { database db; - db.open(data_dir.path(), INITIAL_TEST_SUPPLY ); + db.open(data_dir.path(), genesis ); + init_witness_keys( db ); fc::time_point_sec now( MUSE_TESTING_GENESIS_TIMESTAMP ); std::vector< time_point_sec > time_stack; - auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("init_key")) ); for( uint32_t i = 0; i < 5; ++i ) { now = db.get_slot_time(1); time_stack.push_back( now ); - auto b = db.generate_block( now, db.get_scheduled_witness( 1 ), init_account_priv_key, database::skip_nothing ); + auto b = db.generate_block( now, db.get_scheduled_witness( 1 ), init_account_priv_key(), database::skip_nothing ); } BOOST_CHECK( db.head_block_num() == 5 ); BOOST_CHECK( db.head_block_time() == now ); @@ -194,7 +224,7 @@ BOOST_AUTO_TEST_CASE( undo_block ) { now = db.get_slot_time(1); time_stack.push_back( now ); - auto b = db.generate_block( now, db.get_scheduled_witness( 1 ), init_account_priv_key, database::skip_nothing ); + auto b = db.generate_block( now, db.get_scheduled_witness( 1 ), init_account_priv_key(), database::skip_nothing ); } BOOST_CHECK( db.head_block_num() == 7 ); } @@ -210,30 +240,34 @@ BOOST_AUTO_TEST_CASE( fork_blocks ) fc::temp_directory data_dir1( graphene::utilities::temp_directory_path() ); fc::temp_directory data_dir2( graphene::utilities::temp_directory_path() ); + genesis_state_type genesis; + genesis.init_supply = INITIAL_TEST_SUPPLY; + //TODO This test needs 6-7 ish witnesses prior to fork database db1; - db1.open( data_dir1.path(), INITIAL_TEST_SUPPLY ); + db1.open( data_dir1.path(), genesis ); + init_witness_keys( db1 ); database db2; - db2.open( data_dir2.path(), INITIAL_TEST_SUPPLY ); + db2.open( data_dir2.path(), genesis ); + init_witness_keys( db2 ); - auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("init_key")) ); for( uint32_t i = 0; i < 10; ++i ) { - auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key(), database::skip_nothing); try { PUSH_BLOCK( db2, b ); } FC_CAPTURE_AND_RETHROW( ("db2") ); } for( uint32_t i = 10; i < 13; ++i ) { - auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key(), database::skip_nothing); } string db1_tip = db1.head_block_id().str(); uint32_t next_slot = 3; for( uint32_t i = 13; i < 16; ++i ) { - auto b = db2.generate_block(db2.get_slot_time(next_slot), db2.get_scheduled_witness(next_slot), init_account_priv_key, database::skip_nothing); + auto b = db2.generate_block(db2.get_slot_time(next_slot), db2.get_scheduled_witness(next_slot), init_account_priv_key(), database::skip_nothing); next_slot = 1; // notify both databases of the new block. // only db2 should switch to the new fork, db1 should not @@ -248,11 +282,11 @@ BOOST_AUTO_TEST_CASE( fork_blocks ) BOOST_CHECK_EQUAL(db1.head_block_num(), 13); BOOST_CHECK_EQUAL(db2.head_block_num(), 13); { - auto b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key(), database::skip_nothing); good_block = b; b.transactions.emplace_back(signed_transaction()); b.transactions.back().operations.emplace_back(transfer_operation()); - b.sign( init_account_priv_key ); + b.sign( init_account_priv_key() ); BOOST_CHECK_EQUAL(b.block_num(), 14); MUSE_CHECK_THROW(PUSH_BLOCK( db1, b ), fc::exception); } @@ -274,40 +308,43 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create ) try { fc::temp_directory dir1( graphene::utilities::temp_directory_path() ), dir2( graphene::utilities::temp_directory_path() ); + + genesis_state_type genesis; + genesis.init_supply = INITIAL_TEST_SUPPLY; + database db1, db2; - db1.open( dir1.path(), INITIAL_TEST_SUPPLY ); - db2.open( dir2.path(), INITIAL_TEST_SUPPLY ); + db1.open( dir1.path(), genesis ); + init_witness_keys( db1 ); + db2.open( dir2.path(), genesis ); + init_witness_keys( db2 ); - auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("init_key")) ); - public_key_type init_account_pub_key = init_account_priv_key.get_public_key(); const graphene::db::index& account_idx = db1.get_index(implementation_ids, impl_account_object_type); - //* signed_transaction trx; account_id_type alice_id = account_idx.get_next_id(); account_create_operation cop; + cop.fee = asset(50, MUSE_SYMBOL); cop.new_account_name = "alice"; cop.creator = MUSE_INIT_MINER_NAME; - cop.owner = authority(1, init_account_pub_key, 1); + cop.owner = authority(1, init_account_pub_key(), 1); cop.active = cop.owner; trx.operations.push_back(cop); trx.set_expiration( db1.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); - trx.sign( init_account_priv_key, db1.get_chain_id() ); + trx.sign( init_account_priv_key(), db1.get_chain_id() ); PUSH_TX( db1, trx ); - //*/ + // generate blocks // db1 : A // db2 : B C D - - auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key(), database::skip_nothing); BOOST_CHECK( alice_id == db1.get_account( "alice" ).id ); - //BOOST_CHECK(alice_id(db1).name == "alice"); + BOOST_CHECK( alice_id(db1).name == "alice" ); - b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key(), database::skip_nothing); db1.push_block(b); - b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key(), database::skip_nothing); db1.push_block(b); MUSE_REQUIRE_THROW(alice_id(db2), fc::exception); alice_id(db1); /// it should be included in the pending state @@ -316,7 +353,7 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create ) PUSH_TX( db2, trx ); - b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key(), database::skip_nothing); db1.push_block(b); BOOST_CHECK(alice_id(db1).name == "alice"); @@ -332,27 +369,31 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions ) try { fc::temp_directory dir1( graphene::utilities::temp_directory_path() ), dir2( graphene::utilities::temp_directory_path() ); + + genesis_state_type genesis; + genesis.init_supply = INITIAL_TEST_SUPPLY; + database db1, db2; - db1.open(dir1.path(), INITIAL_TEST_SUPPLY ); - db2.open(dir2.path(), INITIAL_TEST_SUPPLY ); + db1.open(dir1.path(), genesis ); + init_witness_keys( db1 ); + db2.open(dir2.path(), genesis ); + init_witness_keys( db2 ); BOOST_CHECK( db1.get_chain_id() == db2.get_chain_id() ); auto skip_sigs = database::skip_transaction_signatures | database::skip_authority_check; - auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("init_key")) ); - public_key_type init_account_pub_key = init_account_priv_key.get_public_key(); const graphene::db::index& account_idx = db1.get_index(implementation_ids, impl_account_object_type); signed_transaction trx; account_create_operation cop; cop.new_account_name = "alice"; cop.creator = MUSE_INIT_MINER_NAME; - cop.owner = authority(1, init_account_pub_key, 1); + cop.owner = authority(1, init_account_pub_key(), 1); cop.active = cop.owner; trx.operations.push_back(cop); trx.set_expiration( db1.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); - trx.sign( init_account_priv_key, db1.get_chain_id() ); + trx.sign( init_account_priv_key(), db1.get_chain_id() ); PUSH_TX( db1, trx, skip_sigs ); trx = decltype(trx)(); @@ -362,12 +403,12 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions ) t.amount = asset(500,MUSE_SYMBOL); trx.operations.push_back(t); trx.set_expiration( db1.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); - trx.sign( init_account_priv_key, db1.get_chain_id() ); + trx.sign( init_account_priv_key(), db1.get_chain_id() ); PUSH_TX( db1, trx, skip_sigs ); MUSE_CHECK_THROW(PUSH_TX( db1, trx, skip_sigs ), fc::exception); - auto b = db1.generate_block( db1.get_slot_time(1), db1.get_scheduled_witness( 1 ), init_account_priv_key, skip_sigs ); + auto b = db1.generate_block( db1.get_slot_time(1), db1.get_scheduled_witness( 1 ), init_account_priv_key(), skip_sigs ); PUSH_BLOCK( db2, b, skip_sigs ); MUSE_CHECK_THROW(PUSH_TX( db1, trx, skip_sigs ), fc::exception); @@ -384,16 +425,17 @@ BOOST_AUTO_TEST_CASE( tapos ) { try { fc::temp_directory dir1( graphene::utilities::temp_directory_path() ); - database db1; - db1.open(dir1.path(), INITIAL_TEST_SUPPLY ); - const account_object& init1 = *db1.get_index_type().indices().get().find( MUSE_INIT_MINER_NAME ); + genesis_state_type genesis; + genesis.init_supply = INITIAL_TEST_SUPPLY; + + database db1; + db1.open(dir1.path(), genesis ); + init_witness_keys( db1 ); - auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("init_key")) ); - public_key_type init_account_pub_key = init_account_priv_key.get_public_key(); const graphene::db::index& account_idx = db1.get_index(implementation_ids, impl_account_object_type); - auto b = db1.generate_block( db1.get_slot_time(1), db1.get_scheduled_witness( 1 ), init_account_priv_key, database::skip_nothing); + auto b = db1.generate_block( db1.get_slot_time(1), db1.get_scheduled_witness( 1 ), init_account_priv_key(), database::skip_nothing); BOOST_TEST_MESSAGE( "Creating a transaction with reference block" ); idump((db1.head_block_id())); @@ -402,19 +444,20 @@ BOOST_AUTO_TEST_CASE( tapos ) trx.set_reference_block( db1.head_block_id() ); account_create_operation cop; + cop.fee = asset(50, MUSE_SYMBOL); cop.new_account_name = "alice"; cop.creator = MUSE_INIT_MINER_NAME; - cop.owner = authority(1, init_account_pub_key, 1); + cop.owner = authority(1, init_account_pub_key(), 1); cop.active = cop.owner; trx.operations.push_back(cop); trx.set_expiration( db1.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); - trx.sign( init_account_priv_key, db1.get_chain_id() ); + trx.sign( init_account_priv_key(), db1.get_chain_id() ); BOOST_TEST_MESSAGE( "Pushing Pending Transaction" ); idump((trx)); db1.push_transaction(trx); BOOST_TEST_MESSAGE( "Generating a block" ); - b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key(), database::skip_nothing); trx.clear(); transfer_operation t; @@ -423,13 +466,13 @@ BOOST_AUTO_TEST_CASE( tapos ) t.amount = asset(50,MUSE_SYMBOL); trx.operations.push_back(t); trx.set_expiration( db1.head_block_time() + fc::seconds(2) ); - trx.sign( init_account_priv_key, db1.get_chain_id() ); + trx.sign( init_account_priv_key(), db1.get_chain_id() ); idump((trx)(db1.head_block_time())); - b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key(), database::skip_nothing); idump((b)); - b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key(), database::skip_nothing); trx.signatures.clear(); - trx.sign( init_account_priv_key, db1.get_chain_id() ); + trx.sign( init_account_priv_key(), db1.get_chain_id() ); BOOST_REQUIRE_THROW( db1.push_transaction(trx, 0/*database::skip_transaction_signatures | database::skip_authority_check*/), fc::exception ); } catch (fc::exception& e) { edump((e.to_detail_string())); @@ -523,10 +566,10 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, clean_database_fixture ) db.push_transaction(trx, ~0); trx.operations.clear(); - t.from = "bob"; - t.to = MUSE_INIT_MINER_NAME; - t.amount = asset(amount,MUSE_SYMBOL); - trx.operations.push_back(t); + account_witness_vote_operation v; + v.account = "bob"; + v.witness = MUSE_INIT_MINER_NAME; + trx.operations.push_back(v); trx.validate(); BOOST_TEST_MESSAGE( "Verify that not-signing causes an exception" ); @@ -545,7 +588,6 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, clean_database_fixture ) BOOST_TEST_MESSAGE( "Verify that signing once with the proper key passes" ); trx.signatures.pop_back(); db.push_transaction(trx, 0); - trx.sign( bob_private_key, db.get_chain_id() ); } FC_LOG_AND_RETHROW() } @@ -731,7 +773,6 @@ BOOST_FIXTURE_TEST_CASE( skip_block, clean_database_fixture ) BOOST_REQUIRE( db.head_block_num() == 1 ); int init_block_num = db.head_block_num(); - fc::time_point_sec init_block_time = db.head_block_time(); int miss_blocks = fc::minutes( 1 ).to_seconds() / MUSE_BLOCK_INTERVAL; auto witness = db.get_scheduled_witness( miss_blocks ); auto block_time = db.get_slot_time( miss_blocks ); @@ -749,230 +790,7 @@ BOOST_FIXTURE_TEST_CASE( skip_block, clean_database_fixture ) FC_LOG_AND_RETHROW(); } -/*** - * This test is designed to queue up 10 POW workers who should each get a turn - * once per round. The difficulty should increase by 2x after each POW operation and - * decrease by half every time a POW witness produces a block. - * - * After a POW witness has produced a block and their round is over, they become - * a regular witness scheduled based upon votes. Currently this test does nothing - * to set up votes. Further more the total non pow witnesses is less than the MAX - * witnesses which means after a POW witness produces they get included in the next - * round too. - * - * Under normal conditions the top 19 will have more votes than any POW witness so - * this wouldn't happen. - */ -/* -BOOST_FIXTURE_TEST_CASE( pow_blocks, clean_database_fixture ) { -try { - ACTOR(bob1); - ACTOR(bob2); - ACTOR(bob3); - ACTOR(bob4); - ACTOR(bob5); - ACTOR(bob6); - ACTOR(bob7); - ACTOR(bob8); - ACTOR(bob9); - ACTOR(bob10); - vector names = {"bob1", - "bob2", - "bob3", - "bob4", - "bob5", - "bob6", - "bob7", - "bob8", - "bob9", - "bob10"}; - - vector keys = { bob1_private_key, - bob2_private_key, - bob3_private_key, - bob4_private_key, - bob5_private_key, - bob6_private_key, - bob7_private_key, - bob8_private_key, - bob9_private_key, - bob10_private_key }; - - generate_block(); - generate_block(); - generate_block(); - - pow_operation op; - - op.block_id = db.head_block_id(); - - for( uint32_t i = 0; i < 10; ++i ) { - op.worker_account = names[i]; - op.work.worker = keys[i].get_public_key(); - do { - op.nonce++; - op.work.create( keys[i], op.work_input() ); - } while ( db.get_pow_target() < op.work.work ); - - trx.operations.clear(); - trx.operations.push_back(op); - trx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); - db.push_transaction( trx ); - } - - /// TODO: actually add checks to detect when this is failing - for( uint32_t i = 0; i < 200; ++i ) { - auto next_witness = db.get_scheduled_witness(0); - // wdump((i)(next_witness)(db.get_pow_target())); - generate_block(database::skip_witness_signature); - } - - -} FC_LOG_AND_RETHROW() } -*/ -/* -BOOST_FIXTURE_TEST_CASE( pow_block, clean_database_fixture ) -{ - try - { - ACTOR( alice ) - - auto init_miner_balance = db.get_account( MUSE_INIT_MINER_NAME ).balance; - auto target = db.get_pow_target(); - - signed_transaction tx; - pow_operation pow; - pow.block_id = db.head_block_id(); - pow.worker_account = "alice"; - - do - { - pow.nonce++; - pow.work.create( alice_private_key, pow.work_input() ); - } while ( db.get_pow_target() < pow.work.work ); - - tx.operations.push_back( pow ); - tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); - db.push_transaction( tx, 0 ); - generate_block(); - - init_miner_balance += asset( MUSE_MIN_POW_REWARD.amount * MUSE_MAX_MINERS, MUSE_SYMBOL ) + MUSE_MIN_PRODUCER_REWARD; - auto alice_balance = db.get_account( "alice" ).balance; - auto alice_vesting_shares = db.get_account( "alice" ).vesting_shares; - - BOOST_REQUIRE_EQUAL( db.get_account( MUSE_INIT_MINER_NAME ).balance.amount.value, init_miner_balance.amount.value ); - BOOST_REQUIRE_EQUAL( db.get_pow_target(), target ); - init_miner_balance.amount += ( MUSE_MAX_MINERS - ( db.head_block_num() % MUSE_MAX_MINERS ) ) * MUSE_MIN_PRODUCER_REWARD.amount; - generate_blocks( MUSE_MAX_MINERS - ( db.head_block_num() % MUSE_MAX_MINERS ) ); - - for (int i = 1; i <= MUSE_MAX_MINERS + 1; i++ ) - { - BOOST_REQUIRE_EQUAL( db.get_scheduled_witness( 1 ), "alice" ); - generate_block( 0, alice_private_key, 0 ); - if ( alice_vesting_shares.amount.value == 0 ) - { - alice_vesting_shares += MUSE_MIN_PRODUCER_REWARD * db.get_dynamic_global_properties().get_vesting_share_price(); - } - else - { - alice_balance += MUSE_MIN_PRODUCER_REWARD; - } - - BOOST_REQUIRE( db.get_account( "alice" ).vesting_shares == alice_vesting_shares ); - BOOST_REQUIRE( db.get_account( "alice" ).balance == alice_balance ); - } - - pow.block_id = db.head_block_id(); - - private_key_type bob_private_key = fc::ecc::private_key::regenerate( fc::sha256::hash( string( "bob" ) ) ); - private_key_type sam_private_key = fc::ecc::private_key::regenerate( fc::sha256::hash( string( "sam" ) ) ); - - pow.worker_account = "bob"; - - do - { - pow.nonce++; - pow.work.create( bob_private_key, pow.work_input() ); - } while ( db.get_pow_target() < pow.work.work ); - - tx.operations.clear(); - tx.operations.push_back( pow ); - tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); - db.push_transaction( tx, 0 ); - - pow.worker_account = "sam"; - - do - { - pow.nonce++; - pow.work.create( sam_private_key, pow.work_input() ); - } while ( db.get_pow_target() < pow.work.work ); - - tx.operations.clear(); - tx.operations.push_back( pow ); - db.push_transaction( tx, 0 ); - - init_miner_balance.amount += 3 * asset( MUSE_MIN_POW_REWARD.amount * MUSE_MAX_MINERS, MUSE_SYMBOL ).amount; - - } FC_LOG_AND_RETHROW() -} - -/* -BOOST_FIXTURE_TEST_CASE( overproduction_test ) -{ - try { - fc::temp_directory dir1( graphene::utilities::temp_directory_path() ), - dir2( graphene::utilities::temp_directory_path() ); - database db1, - db2; - db1.open( dir1.path(), INITIAL_TEST_SUPPLY ); - db2.open( dir2.path(), INITIAL_TEST_SUPPLY ); - - auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("init_key")) ); - public_key_type init_account_pub_key = init_account_priv_key.get_public_key(); - const graphene::db::index& account_idx = db1.get_index(implementation_ids, impl_account_object_type); - - //* - signed_transaction trx; - account_id_type alice_id = account_idx.get_next_id(); - account_create_operation cop; - cop.new_account_name = "alice"; - cop.creator = MUSE_INIT_MINER_NAME; - cop.owner = authority(1, init_account_pub_key, 1); - cop.active = cop.owner; - trx.operations.push_back(cop); - trx.set_expiration( db1.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); - trx.sign( init_account_priv_key, db1.get_chain_id() ); - PUSH_TX( db1, trx ); - // generate blocks - // db1 : A - // db2 : B C D - - auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); - - BOOST_CHECK( alice_id == db1.get_account( "alice" ).id ); - //BOOST_CHECK(alice_id(db1).name == "alice"); - - b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); - db1.push_block(b); - b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); - db1.push_block(b); - MUSE_REQUIRE_THROW(alice_id(db2), fc::exception); - alice_id(db1); /// it should be included in the pending state - db1.clear_pending(); // clear it so that we can verify it was properly removed from pending state. - MUSE_REQUIRE_THROW(alice_id(db1), fc::exception); - - PUSH_TX( db2, trx ); - - b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); - db1.push_block(b); - - BOOST_CHECK(alice_id(db1).name == "alice"); - BOOST_CHECK(alice_id(db2).name == "alice"); - } FC_LOG_AND_RETHROW() -} -//*/ - +#ifdef MUSE_HARDFORK_0_1 BOOST_FIXTURE_TEST_CASE( hardfork_test, database_fixture ) { try @@ -1053,6 +871,6 @@ BOOST_FIXTURE_TEST_CASE( hardfork_test, database_fixture ) } FC_LOG_AND_RETHROW() } +#endif BOOST_AUTO_TEST_SUITE_END() -#endif \ No newline at end of file From 48083129441affa83631fa794f9b0eb5906ac8dc Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 2 Nov 2017 21:52:04 +0100 Subject: [PATCH 05/74] Reactivated serialization_tests, added test cases for "decimals issue", added missing assertion to hardfork deserialization --- libraries/chain/protocol/version.cpp | 1 + tests/tests/serialization_tests.cpp | 94 +++++++++++++++++++++------- 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/libraries/chain/protocol/version.cpp b/libraries/chain/protocol/version.cpp index 6bbea43..6d0fdfd 100644 --- a/libraries/chain/protocol/version.cpp +++ b/libraries/chain/protocol/version.cpp @@ -77,5 +77,6 @@ namespace fc void from_variant( const variant& var, muse::chain::hardfork_version& hv ) { from_variant( var, (muse::chain::version&) hv ); + FC_ASSERT( !(hv.v_num & 0xFFFF), "Hardfork revision must be 0!" ); } } \ No newline at end of file diff --git a/tests/tests/serialization_tests.cpp b/tests/tests/serialization_tests.cpp index 8911524..77bae07 100644 --- a/tests/tests/serialization_tests.cpp +++ b/tests/tests/serialization_tests.cpp @@ -21,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifdef IS_TEST_NET #include #include @@ -86,33 +85,83 @@ BOOST_AUTO_TEST_CASE( asset_test ) { try { - BOOST_CHECK_EQUAL( asset().decimals(), 3 ); - BOOST_CHECK_EQUAL( asset().symbol_name(), "TESTS" ); - BOOST_CHECK_EQUAL( asset().to_string(), "0.000 TESTS" ); + BOOST_CHECK_EQUAL( asset().decimals(), MUSE_ASSET_PRECISION ); + BOOST_CHECK_EQUAL( asset().asset_id, MUSE_SYMBOL ); + BOOST_CHECK_EQUAL( asset().to_string(), "0.000000 2.28.0" ); BOOST_TEST_MESSAGE( "Asset Test" ); - asset muse = asset::from_string( "123.456 TESTS" ); - asset mbd = asset::from_string( "654.321 TBD" ); - asset tmp = asset::from_string( "0.456 TESTS" ); - BOOST_CHECK_EQUAL( tmp.amount.value, 456 ); - tmp = asset::from_string( "0.056 TESTS" ); - BOOST_CHECK_EQUAL( tmp.amount.value, 56 ); + asset muse = asset::from_string( "123.456 2.28.0" ); + asset mbd = asset::from_string( "654.321 2.28.2" ); + asset tmp = asset::from_string( "0.456 2.28.0" ); + BOOST_CHECK_EQUAL( tmp.amount.value, 456000 ); + tmp = asset::from_string( "0.056 2.28.0" ); + BOOST_CHECK_EQUAL( tmp.amount.value, 56000 ); BOOST_CHECK( std::abs( muse.to_real() - 123.456 ) < 0.0005 ); - BOOST_CHECK_EQUAL( muse.decimals(), 3 ); - BOOST_CHECK_EQUAL( muse.symbol_name(), "TESTS" ); - BOOST_CHECK_EQUAL( muse.to_string(), "123.456 TESTS" ); - BOOST_CHECK_EQUAL( muse.symbol, MUSE_SYMBOL); - BOOST_CHECK_EQUAL( asset(50, MUSE_SYMBOL).to_string(), "0.050 TESTS" ); - BOOST_CHECK_EQUAL( asset(50000, MUSE_SYMBOL).to_string(), "50.000 TESTS" ); + BOOST_CHECK_EQUAL( muse.decimals(), MUSE_ASSET_PRECISION ); + BOOST_CHECK_EQUAL( muse.asset_id, MUSE_SYMBOL ); + BOOST_CHECK_EQUAL( muse.to_string(), "123.456000 2.28.0" ); + BOOST_CHECK_EQUAL( asset(50, MUSE_SYMBOL).to_string(), "0.000050 2.28.0" ); + BOOST_CHECK_EQUAL( asset(50000000, MUSE_SYMBOL).to_string(), "50.000000 2.28.0" ); BOOST_CHECK( std::abs( mbd.to_real() - 654.321 ) < 0.0005 ); - BOOST_CHECK_EQUAL( mbd.decimals(), 3 ); - BOOST_CHECK_EQUAL( mbd.symbol_name(), "TBD" ); - BOOST_CHECK_EQUAL( mbd.to_string(), "654.321 TBD" ); - BOOST_CHECK_EQUAL( mbd.symbol, MBD_SYMBOL); - BOOST_CHECK_EQUAL( asset(50, MBD_SYMBOL).to_string(), "0.050 TBD" ); - BOOST_CHECK_EQUAL( asset(50000, MBD_SYMBOL).to_string(), "50.000 TBD" ); + BOOST_CHECK_EQUAL( mbd.decimals(), MUSE_ASSET_PRECISION ); + BOOST_CHECK_EQUAL( mbd.asset_id, MBD_SYMBOL ); + BOOST_CHECK_EQUAL( mbd.to_string(), "654.321000 2.28.2" ); + BOOST_CHECK_EQUAL( asset(50000, MBD_SYMBOL).to_string(), "0.050000 2.28.2" ); + BOOST_CHECK_EQUAL( asset(50000000, MBD_SYMBOL).to_string(), "50.000000 2.28.2" ); + + muse = asset::from_string( "123.456789 2.28.1" ); + BOOST_CHECK_EQUAL( muse.asset_id, VESTS_SYMBOL ); + BOOST_CHECK_EQUAL( muse.amount.value, 123456789 ); + + muse = asset::from_string( "123.45678 2.28.1" ); + BOOST_CHECK_EQUAL( muse.asset_id, VESTS_SYMBOL ); + BOOST_CHECK_EQUAL( muse.amount.value, 123456780 ); + + muse = asset::from_string( "123.4567 2.28.1" ); + BOOST_CHECK_EQUAL( muse.asset_id, VESTS_SYMBOL ); + BOOST_CHECK_EQUAL( muse.amount.value, 123456700 ); + + muse = asset::from_string( "123.456 2.28.1" ); + BOOST_CHECK_EQUAL( muse.asset_id, VESTS_SYMBOL ); + BOOST_CHECK_EQUAL( muse.amount.value, 123456000 ); + + muse = asset::from_string( "123.45 2.28.1" ); + BOOST_CHECK_EQUAL( muse.asset_id, VESTS_SYMBOL ); + BOOST_CHECK_EQUAL( muse.amount.value, 123450000 ); + + muse = asset::from_string( "123.4 2.28.1" ); + BOOST_CHECK_EQUAL( muse.asset_id, VESTS_SYMBOL ); + BOOST_CHECK_EQUAL( muse.amount.value, 123400000 ); + + muse = asset::from_string( "123.0 2.28.1" ); + BOOST_CHECK_EQUAL( muse.asset_id, VESTS_SYMBOL ); + BOOST_CHECK_EQUAL( muse.amount.value, 123000000 ); + + muse = asset::from_string( "123 2.28.1" ); + BOOST_CHECK_EQUAL( muse.asset_id, VESTS_SYMBOL ); + BOOST_CHECK_EQUAL( muse.amount.value, 123000000 ); + + mbd = asset::from_string( "120.0000091 2.28.2" ); + BOOST_CHECK_EQUAL( mbd.asset_id, MBD_SYMBOL ); + BOOST_CHECK_EQUAL( mbd.amount.value, 120000009 ); + BOOST_CHECK_EQUAL( mbd.to_string(), "120.000009 2.28.2" ); + + mbd = asset( 120000090, MBD_SYMBOL ); + BOOST_CHECK_EQUAL( mbd.to_string(), "120.000090 2.28.2" ); + + mbd = asset( 120000900, MBD_SYMBOL ); + BOOST_CHECK_EQUAL( mbd.to_string(), "120.000900 2.28.2" ); + + mbd = asset( 120009000, MBD_SYMBOL ); + BOOST_CHECK_EQUAL( mbd.to_string(), "120.009000 2.28.2" ); + + mbd = asset( 120090000, MBD_SYMBOL ); + BOOST_CHECK_EQUAL( mbd.to_string(), "120.090000 2.28.2" ); + + mbd = asset( 120900000, MBD_SYMBOL ); + BOOST_CHECK_EQUAL( mbd.to_string(), "120.900000 2.28.2" ); } FC_LOG_AND_RETHROW() } @@ -256,4 +305,3 @@ BOOST_AUTO_TEST_CASE( hardfork_version_test ) } BOOST_AUTO_TEST_SUITE_END() -#endif From c35c96ebfa1ae06a206db91fdb079892709b8a7f Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 2 Nov 2017 21:54:39 +0100 Subject: [PATCH 06/74] Removed two unused (and wrong) config vars --- libraries/chain/get_config.cpp | 2 -- libraries/chain/include/muse/chain/config.hpp | 3 --- 2 files changed, 5 deletions(-) diff --git a/libraries/chain/get_config.cpp b/libraries/chain/get_config.cpp index fceb761..2776845 100644 --- a/libraries/chain/get_config.cpp +++ b/libraries/chain/get_config.cpp @@ -35,8 +35,6 @@ fc::variant_object get_config() result["MUSE_APR_PERCENT_SHIFT_PER_ROUND"] = MUSE_APR_PERCENT_SHIFT_PER_ROUND; result["MUSE_BANDWIDTH_AVERAGE_WINDOW_SECONDS"] = MUSE_BANDWIDTH_AVERAGE_WINDOW_SECONDS; result["MUSE_BANDWIDTH_PRECISION"] = MUSE_BANDWIDTH_PRECISION; - result["MUSE_BLOCKCHAIN_PRECISION"] = MUSE_BLOCKCHAIN_PRECISION; - result["MUSE_BLOCKCHAIN_PRECISION_DIGITS"] = MUSE_BLOCKCHAIN_PRECISION_DIGITS; result["MUSE_BLOCKCHAIN_HARDFORK_VERSION"] = MUSE_BLOCKCHAIN_HARDFORK_VERSION; result["MUSE_BLOCKCHAIN_VERSION"] = MUSE_BLOCKCHAIN_VERSION; result["MUSE_BLOCK_INTERVAL"] = MUSE_BLOCK_INTERVAL; diff --git a/libraries/chain/include/muse/chain/config.hpp b/libraries/chain/include/muse/chain/config.hpp index c6ee8f6..35aa338 100644 --- a/libraries/chain/include/muse/chain/config.hpp +++ b/libraries/chain/include/muse/chain/config.hpp @@ -250,10 +250,7 @@ #define MUSE_MAX_UNDO_HISTORY 10000 #define MUSE_MIN_TRANSACTION_EXPIRATION_LIMIT (MUSE_BLOCK_INTERVAL * 5) // 5 transactions per block -#define MUSE_BLOCKCHAIN_PRECISION uint64_t( 1000 ) -#define MUSE_BLOCKCHAIN_PRECISION_DIGITS 3 -//#define MUSE_TRANSFER_FEE (1*MUSE_BLOCKCHAIN_PRECISION) #define MUSE_MAX_INSTANCE_ID (uint64_t(-1)>>16) /** NOTE: making this a power of 2 (say 2^15) would greatly accelerate fee calcs */ #define MUSE_MAX_AUTHORITY_MEMBERSHIP 10 From 52b74a194b8814b622c1f20c92abb48a7d0eb614 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 8 Nov 2017 23:00:45 +0100 Subject: [PATCH 07/74] Made operation_tests work --- tests/tests/operation_tests.cpp | 575 ++++++++++++++++---------------- 1 file changed, 287 insertions(+), 288 deletions(-) diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index c471dc6..7b7dff4 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -1,4 +1,3 @@ -#ifdef IS_TEST_NET #include #include @@ -67,12 +66,12 @@ BOOST_AUTO_TEST_CASE( account_create_authorities ) tx.sign( init_account_priv_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_duplicate_sig ); - BOOST_TEST_MESSAGE( "--- Test failure when signed by an additional signature not in the creator's authority" ); +/* BOOST_TEST_MESSAGE( "--- Test failure when signed by an additional signature not in the creator's authority" ); tx.signatures.clear(); tx.sign( init_account_priv_key, db.get_chain_id() ); tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_irrelevant_sig ); - +*/ BOOST_TEST_MESSAGE( "--- Test failure when signed by a signature not in the creator's authority" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); @@ -98,7 +97,7 @@ BOOST_AUTO_TEST_CASE( account_create_apply ) account_create_operation op; - op.fee = asset( 100, MUSE_SYMBOL ); + op.fee = asset( 100000, MUSE_SYMBOL ); op.new_account_name = "alice"; op.creator = MUSE_INIT_MINER_NAME; op.owner = authority( 1, priv_key.get_public_key(), 1 ); @@ -124,8 +123,8 @@ BOOST_AUTO_TEST_CASE( account_create_apply ) BOOST_REQUIRE( acct.memo_key == priv_key.get_public_key() ); BOOST_REQUIRE_EQUAL( acct.proxy, "" ); BOOST_REQUIRE( acct.created == db.head_block_time() ); - BOOST_REQUIRE_EQUAL( acct.balance.amount.value, ASSET( "0.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( acct.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( acct.balance.amount.value, ASSET( "0.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( acct.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); #ifndef IS_LOW_MEM BOOST_REQUIRE_EQUAL( acct.json_metadata, op.json_metadata ); @@ -135,9 +134,9 @@ BOOST_AUTO_TEST_CASE( account_create_apply ) /// because init_witness has created vesting shares and blocks have been produced, 100 MUSE is worth less than 100 vesting shares due to rounding BOOST_REQUIRE_EQUAL( acct.vesting_shares.amount.value, ( op.fee * ( vest_shares / vests ) ).amount.value ); - BOOST_REQUIRE_EQUAL( acct.vesting_withdraw_rate.amount.value, ASSET( "0.000000 VESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( acct.vesting_withdraw_rate.amount.value, ASSET( "0.000000 2.28.1" ).amount.value ); BOOST_REQUIRE_EQUAL( acct.proxied_vsf_votes_total().value, 0 ); - BOOST_REQUIRE_EQUAL( ( init_starting_balance - ASSET( "0.100 TESTS" ) ).amount.value, init.balance.amount.value ); + BOOST_REQUIRE_EQUAL( ( init_starting_balance - ASSET( "0.100000 2.28.0" ) ).amount.value, init.balance.amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test failure of duplicate account creation" ); @@ -149,12 +148,12 @@ BOOST_AUTO_TEST_CASE( account_create_apply ) BOOST_REQUIRE( acct.memo_key == priv_key.get_public_key() ); BOOST_REQUIRE_EQUAL( acct.proxy, "" ); BOOST_REQUIRE( acct.created == db.head_block_time() ); - BOOST_REQUIRE_EQUAL( acct.balance.amount.value, ASSET( "0.000 MUSE " ).amount.value ); - BOOST_REQUIRE_EQUAL( acct.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( acct.balance.amount.value, ASSET( "0.000 2.28.0 " ).amount.value ); + BOOST_REQUIRE_EQUAL( acct.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); BOOST_REQUIRE_EQUAL( acct.vesting_shares.amount.value, ( op.fee * ( vest_shares / vests ) ).amount.value ); - BOOST_REQUIRE_EQUAL( acct.vesting_withdraw_rate.amount.value, ASSET( "0.000000 VESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( acct.vesting_withdraw_rate.amount.value, ASSET( "0.000000 2.28.1" ).amount.value ); BOOST_REQUIRE_EQUAL( acct.proxied_vsf_votes_total().value, 0 ); - BOOST_REQUIRE_EQUAL( ( init_starting_balance - ASSET( "0.100 TESTS" ) ).amount.value, init.balance.amount.value ); + BOOST_REQUIRE_EQUAL( ( init_starting_balance - ASSET( "0.100000 2.28.0" ) ).amount.value, init.balance.amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test failure when creator cannot cover fee" ); @@ -213,10 +212,10 @@ BOOST_AUTO_TEST_CASE( account_update_authorities ) tx.sign( bob_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); - BOOST_TEST_MESSAGE( "--- Test failure when containing additional incorrect signature" ); +/* BOOST_TEST_MESSAGE( "--- Test failure when containing additional incorrect signature" ); tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_irrelevant_sig ); - +*/ BOOST_TEST_MESSAGE( "--- Test failure when containing duplicate signatures" ); tx.signatures.clear(); tx.sign( active_key, db.get_chain_id() ); @@ -242,10 +241,10 @@ BOOST_AUTO_TEST_CASE( account_update_authorities ) tx.sign( active_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_owner_auth ); - BOOST_TEST_MESSAGE( "--- Test failure when owner key and active key are present" ); +/* BOOST_TEST_MESSAGE( "--- Test failure when owner key and active key are present" ); tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_irrelevant_sig ); - +*/ BOOST_TEST_MESSAGE( "--- Test failure when incorrect signature" ); tx.signatures.clear(); tx.sign( alice_post_key, db.get_chain_id() ); @@ -318,6 +317,7 @@ BOOST_AUTO_TEST_CASE( account_update_apply ) FC_LOG_AND_RETHROW() } +/* BOOST_AUTO_TEST_CASE( comment_validate ) { try @@ -759,7 +759,7 @@ BOOST_AUTO_TEST_CASE( vote_apply ) itr = vote_idx.find( std::make_tuple( new_bob_comment.id, new_sam.id ) ); new_cashout_time = db.head_block_time().sec_since_epoch() + MUSE_CASHOUT_WINDOW_SECONDS; - auto sam_weight /*= ( ( uint128_t( new_sam.vesting_shares.amount.value ) ) / 400 + 1 ).to_uint64();*/ + auto sam_weight //= ( ( uint128_t( new_sam.vesting_shares.amount.value ) ) / 400 + 1 ).to_uint64(); = ( ( uint128_t( new_sam.vesting_shares.amount.value ) * ( MUSE_100_PERCENT / 400 + 1 ) ) / MUSE_100_PERCENT ).to_uint64(); BOOST_REQUIRE_EQUAL( new_sam.voting_power, MUSE_100_PERCENT - ( MUSE_100_PERCENT / 400 + 1 ) ); @@ -940,7 +940,7 @@ BOOST_AUTO_TEST_CASE( vote_apply ) } FC_LOG_AND_RETHROW() } - +*/ BOOST_AUTO_TEST_CASE( transfer_validate ) { try @@ -957,14 +957,14 @@ BOOST_AUTO_TEST_CASE( transfer_authorities ) try { ACTORS( (alice)(bob) ) - fund( "alice", 10000 ); + fund( "alice", 10000000 ); BOOST_TEST_MESSAGE( "Testing: transfer_authorities" ); transfer_operation op; op.from = "alice"; op.to = "bob"; - op.amount = ASSET( "2.500 TESTS" ); + op.amount = ASSET( "2.500000 2.28.0" ); signed_transaction tx; tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); @@ -983,12 +983,12 @@ BOOST_AUTO_TEST_CASE( transfer_authorities ) tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_duplicate_sig ); - BOOST_TEST_MESSAGE( "--- Test failure when signed by an additional signature not in the creator's authority" ); +/* BOOST_TEST_MESSAGE( "--- Test failure when signed by an additional signature not in the creator's authority" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); tx.sign( bob_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_irrelevant_sig ); - +*/ BOOST_TEST_MESSAGE( "--- Test success with witness signature" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); @@ -1006,17 +1006,17 @@ BOOST_AUTO_TEST_CASE( transfer_apply ) BOOST_TEST_MESSAGE( "Testing: transfer_apply" ); ACTORS( (alice)(bob) ) - fund( "alice", 10000 ); + fund( "alice", 10000000 ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "10.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET(" 0.000 TESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "10.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET(" 0.000 2.28.0" ).amount.value ); signed_transaction tx; transfer_operation op; op.from = "alice"; op.to = "bob"; - op.amount = ASSET( "5.000 TESTS" ); + op.amount = ASSET( "5.000 2.28.0" ); BOOST_TEST_MESSAGE( "--- Test normal transaction" ); tx.operations.push_back( op ); @@ -1024,8 +1024,8 @@ BOOST_AUTO_TEST_CASE( transfer_apply ) tx.sign( alice_private_key, db.get_chain_id() ); db.push_transaction( tx, 0 ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "5.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "5.000 TESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "5.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "5.000 2.28.0" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Generating a block" ); @@ -1034,8 +1034,8 @@ BOOST_AUTO_TEST_CASE( transfer_apply ) const auto& new_alice = db.get_account( "alice" ); const auto& new_bob = db.get_account( "bob" ); - BOOST_REQUIRE_EQUAL( new_alice.balance.amount.value, ASSET( "5.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( new_bob.balance.amount.value, ASSET( "5.000 TESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_alice.balance.amount.value, ASSET( "5.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_bob.balance.amount.value, ASSET( "5.000 2.28.0" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test emptying an account" ); @@ -1046,8 +1046,8 @@ BOOST_AUTO_TEST_CASE( transfer_apply ) tx.sign( alice_private_key, db.get_chain_id() ); db.push_transaction( tx, database::skip_transaction_dupe_check ); - BOOST_REQUIRE_EQUAL( new_alice.balance.amount.value, ASSET( "0.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( new_bob.balance.amount.value, ASSET( "10.000 TESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_alice.balance.amount.value, ASSET( "0.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_bob.balance.amount.value, ASSET( "10.000 2.28.0" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test transferring non-existent funds" ); @@ -1058,8 +1058,8 @@ BOOST_AUTO_TEST_CASE( transfer_apply ) tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), fc::assert_exception ); - BOOST_REQUIRE_EQUAL( new_alice.balance.amount.value, ASSET( "0.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( new_bob.balance.amount.value, ASSET( "10.000 TESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_alice.balance.amount.value, ASSET( "0.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_bob.balance.amount.value, ASSET( "10.000 2.28.0" ).amount.value ); validate_database(); } @@ -1082,14 +1082,14 @@ BOOST_AUTO_TEST_CASE( transfer_to_vesting_authorities ) try { ACTORS( (alice)(bob) ) - fund( "alice", 10000 ); + fund( "alice", 10000000 ); BOOST_TEST_MESSAGE( "Testing: transfer_to_vesting_authorities" ); transfer_to_vesting_operation op; op.from = "alice"; op.to = "bob"; - op.amount = ASSET( "2.500 TESTS" ); + op.amount = ASSET( "2.500000 2.28.0" ); signed_transaction tx; tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); @@ -1108,12 +1108,12 @@ BOOST_AUTO_TEST_CASE( transfer_to_vesting_authorities ) tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_duplicate_sig ); - BOOST_TEST_MESSAGE( "--- Test failure when signed by an additional signature not in the creator's authority" ); +/* BOOST_TEST_MESSAGE( "--- Test failure when signed by an additional signature not in the creator's authority" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); tx.sign( bob_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_irrelevant_sig ); - +*/ BOOST_TEST_MESSAGE( "--- Test success with from signature" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); @@ -1131,11 +1131,11 @@ BOOST_AUTO_TEST_CASE( transfer_to_vesting_apply ) BOOST_TEST_MESSAGE( "Testing: transfer_to_vesting_apply" ); ACTORS( (alice)(bob) ) - fund( "alice", 10000 ); + fund( "alice", 10000000 ); const auto& gpo = db.get_dynamic_global_properties(); - BOOST_REQUIRE( alice.balance == ASSET( "10.000 TESTS" ) ); + BOOST_REQUIRE( alice.balance == ASSET( "10.000 2.28.0" ) ); auto shares = asset( gpo.total_vesting_shares.amount, VESTS_SYMBOL ); auto vests = asset( gpo.total_vesting_fund_muse.amount, MUSE_SYMBOL ); @@ -1145,7 +1145,7 @@ BOOST_AUTO_TEST_CASE( transfer_to_vesting_apply ) transfer_to_vesting_operation op; op.from = "alice"; op.to = ""; - op.amount = ASSET( "7.500 TESTS" ); + op.amount = ASSET( "7.500000 2.28.0" ); signed_transaction tx; tx.operations.push_back( op ); @@ -1158,14 +1158,14 @@ BOOST_AUTO_TEST_CASE( transfer_to_vesting_apply ) vests += op.amount; alice_shares += new_vest; - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "2.500 TESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "2.500000 2.28.0" ).amount.value ); BOOST_REQUIRE_EQUAL( alice.vesting_shares.amount.value, alice_shares.amount.value ); BOOST_REQUIRE_EQUAL( gpo.total_vesting_fund_muse.amount.value, vests.amount.value ); BOOST_REQUIRE_EQUAL( gpo.total_vesting_shares.amount.value, shares.amount.value ); validate_database(); op.to = "bob"; - op.amount = asset( 2000, MUSE_SYMBOL ); + op.amount = asset( 2000000, MUSE_SYMBOL ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -1178,9 +1178,9 @@ BOOST_AUTO_TEST_CASE( transfer_to_vesting_apply ) vests += op.amount; bob_shares += new_vest; - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "0.500 TESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "0.500000 2.28.0" ).amount.value ); BOOST_REQUIRE_EQUAL( alice.vesting_shares.amount.value, alice_shares.amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "0.000 TESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "0.000 2.28.0" ).amount.value ); BOOST_REQUIRE_EQUAL( bob.vesting_shares.amount.value, bob_shares.amount.value ); BOOST_REQUIRE_EQUAL( gpo.total_vesting_fund_muse.amount.value, vests.amount.value ); BOOST_REQUIRE_EQUAL( gpo.total_vesting_shares.amount.value, shares.amount.value ); @@ -1188,9 +1188,9 @@ BOOST_AUTO_TEST_CASE( transfer_to_vesting_apply ) MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), fc::assert_exception ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "0.500 TESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "0.500000 2.28.0" ).amount.value ); BOOST_REQUIRE_EQUAL( alice.vesting_shares.amount.value, alice_shares.amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "0.000 TESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "0.000 2.28.0" ).amount.value ); BOOST_REQUIRE_EQUAL( bob.vesting_shares.amount.value, bob_shares.amount.value ); BOOST_REQUIRE_EQUAL( gpo.total_vesting_fund_muse.amount.value, vests.amount.value ); BOOST_REQUIRE_EQUAL( gpo.total_vesting_shares.amount.value, shares.amount.value ); @@ -1217,12 +1217,12 @@ BOOST_AUTO_TEST_CASE( withdraw_vesting_authorities ) BOOST_TEST_MESSAGE( "Testing: withdraw_vesting_authorities" ); ACTORS( (alice)(bob) ) - fund( "alice", 10000 ); - vest( "alice", 10000 ); + fund( "alice", 10000000 ); + vest( "alice", 10000000 ); withdraw_vesting_operation op; op.account = "alice"; - op.vesting_shares = ASSET( "0.001000 VESTS" ); + op.vesting_shares = ASSET( "0.001000 2.28.1" ); signed_transaction tx; tx.operations.push_back( op ); @@ -1239,12 +1239,12 @@ BOOST_AUTO_TEST_CASE( withdraw_vesting_authorities ) tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_duplicate_sig ); - BOOST_TEST_MESSAGE( "--- Test failure with additional incorrect signature" ); +/* BOOST_TEST_MESSAGE( "--- Test failure with additional incorrect signature" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); tx.sign( bob_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_irrelevant_sig ); - +*/ BOOST_TEST_MESSAGE( "--- Test failure with incorrect signature" ); tx.signatures.clear(); tx.sign( alice_post_key, db.get_chain_id() ); @@ -1262,8 +1262,8 @@ BOOST_AUTO_TEST_CASE( withdraw_vesting_apply ) BOOST_TEST_MESSAGE( "Testing: withdraw_vesting_apply" ); ACTORS( (alice) ) - fund( "alice", 10000 ); - vest( "alice", 10000 ); + fund( "alice", 10000000 ); + vest( "alice", 10000000 ); BOOST_TEST_MESSAGE( "--- Test withdraw of existing VESTS" ); @@ -1280,7 +1280,7 @@ BOOST_AUTO_TEST_CASE( withdraw_vesting_apply ) db.push_transaction( tx, 0 ); BOOST_REQUIRE_EQUAL( alice.vesting_shares.amount.value, old_vesting_shares.amount.value ); - BOOST_REQUIRE_EQUAL( alice.vesting_withdraw_rate.amount.value, ( old_vesting_shares.amount / 208 ).value ); + BOOST_REQUIRE_EQUAL( alice.vesting_withdraw_rate.amount.value, ( old_vesting_shares.amount / 2 / MUSE_VESTING_WITHDRAW_INTERVALS ).value ); BOOST_REQUIRE_EQUAL( alice.to_withdraw.value, op.vesting_shares.amount.value ); BOOST_REQUIRE( alice.next_vesting_withdrawal == db.head_block_time() + MUSE_VESTING_WITHDRAW_INTERVAL_SECONDS ); validate_database(); @@ -1296,12 +1296,12 @@ BOOST_AUTO_TEST_CASE( withdraw_vesting_apply ) db.push_transaction( tx, 0 ); BOOST_REQUIRE_EQUAL( alice.vesting_shares.amount.value, old_vesting_shares.amount.value ); - BOOST_REQUIRE_EQUAL( alice.vesting_withdraw_rate.amount.value, ( old_vesting_shares.amount / 312 ).value ); + BOOST_REQUIRE_EQUAL( alice.vesting_withdraw_rate.amount.value, ( old_vesting_shares.amount / 3 / MUSE_VESTING_WITHDRAW_INTERVALS ).value ); BOOST_REQUIRE_EQUAL( alice.to_withdraw.value, op.vesting_shares.amount.value ); BOOST_REQUIRE( alice.next_vesting_withdrawal == db.head_block_time() + MUSE_VESTING_WITHDRAW_INTERVAL_SECONDS ); validate_database(); - BOOST_TEST_MESSAGE( "--- Test withdrawing more vests than available" ); + BOOST_TEST_MESSAGE( "--- Test withdrawing more VESTS than available" ); auto old_withdraw_amount = alice.to_withdraw; tx.operations.clear(); tx.signatures.clear(); @@ -1313,7 +1313,7 @@ BOOST_AUTO_TEST_CASE( withdraw_vesting_apply ) MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); BOOST_REQUIRE_EQUAL( alice.vesting_shares.amount.value, old_vesting_shares.amount.value ); - BOOST_REQUIRE_EQUAL( alice.vesting_withdraw_rate.amount.value, ( old_vesting_shares.amount / 312 ).value ); + BOOST_REQUIRE_EQUAL( alice.vesting_withdraw_rate.amount.value, ( old_vesting_shares.amount / 3 / MUSE_VESTING_WITHDRAW_INTERVALS ).value ); BOOST_REQUIRE( alice.next_vesting_withdrawal == db.head_block_time() + MUSE_VESTING_WITHDRAW_INTERVAL_SECONDS ); validate_database(); @@ -1353,14 +1353,14 @@ BOOST_AUTO_TEST_CASE( witness_update_authorities ) BOOST_TEST_MESSAGE( "Testing: witness_update_authorities" ); ACTORS( (alice)(bob) ); - fund( "alice", 10000 ); + fund( "alice", 10000000 ); private_key_type signing_key = generate_private_key( "new_key" ); witness_update_operation op; op.owner = "alice"; op.url = "foo.bar"; - op.fee = ASSET( "1.000 TESTS" ); + op.fee = ASSET( "1.000 2.28.0" ); op.block_signing_key = signing_key.get_public_key(); signed_transaction tx; @@ -1380,12 +1380,12 @@ BOOST_AUTO_TEST_CASE( witness_update_authorities ) tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_duplicate_sig ); - BOOST_TEST_MESSAGE( "--- Test failure when signed by an additional signature not in the creator's authority" ); +/* BOOST_TEST_MESSAGE( "--- Test failure when signed by an additional signature not in the creator's authority" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); tx.sign( bob_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_irrelevant_sig ); - +*/ BOOST_TEST_MESSAGE( "--- Test success with witness signature" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); @@ -1406,7 +1406,7 @@ BOOST_AUTO_TEST_CASE( witness_update_apply ) BOOST_TEST_MESSAGE( "Testing: witness_update_apply" ); ACTORS( (alice) ) - fund( "alice", 10000 ); + fund( "alice", 10000000 ); private_key_type signing_key = generate_private_key( "new_key" ); @@ -1415,7 +1415,7 @@ BOOST_AUTO_TEST_CASE( witness_update_apply ) witness_update_operation op; op.owner = "alice"; op.url = "foo.bar"; - op.fee = ASSET( "1.000 TESTS" ); + op.fee = ASSET( "1.000 2.28.0" ); op.block_signing_key = signing_key.get_public_key(); op.props.account_creation_fee = asset( MUSE_MIN_ACCOUNT_CREATION_FEE + 10, MUSE_SYMBOL); op.props.maximum_block_size = MUSE_MIN_BLOCK_SIZE_LIMIT + 100; @@ -1438,12 +1438,12 @@ BOOST_AUTO_TEST_CASE( witness_update_apply ) BOOST_REQUIRE_EQUAL( alice_witness.total_missed, 0 ); BOOST_REQUIRE_EQUAL( alice_witness.last_aslot, 0 ); BOOST_REQUIRE_EQUAL( alice_witness.last_confirmed_block_num, 0 ); - BOOST_REQUIRE_EQUAL( alice_witness.pow_worker, 0 ); +// BOOST_REQUIRE_EQUAL( alice_witness.pow_worker, 0 ); BOOST_REQUIRE_EQUAL( alice_witness.votes.value, 0 ); BOOST_REQUIRE( alice_witness.virtual_last_update == 0 ); BOOST_REQUIRE( alice_witness.virtual_position == 0 ); BOOST_REQUIRE( alice_witness.virtual_scheduled_time == fc::uint128_t::max_value() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "10.000 TESTS" ).amount.value ); // No fee + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "10.000 2.28.0" ).amount.value ); // No fee validate_database(); BOOST_TEST_MESSAGE( "--- Test updating a witness" ); @@ -1465,12 +1465,12 @@ BOOST_AUTO_TEST_CASE( witness_update_apply ) BOOST_REQUIRE_EQUAL( alice_witness.total_missed, 0 ); BOOST_REQUIRE_EQUAL( alice_witness.last_aslot, 0 ); BOOST_REQUIRE_EQUAL( alice_witness.last_confirmed_block_num, 0 ); - BOOST_REQUIRE_EQUAL( alice_witness.pow_worker, 0 ); +// BOOST_REQUIRE_EQUAL( alice_witness.pow_worker, 0 ); BOOST_REQUIRE_EQUAL( alice_witness.votes.value, 0 ); BOOST_REQUIRE( alice_witness.virtual_last_update == 0 ); BOOST_REQUIRE( alice_witness.virtual_position == 0 ); BOOST_REQUIRE( alice_witness.virtual_scheduled_time == fc::uint128_t::max_value() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "10.000 TESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "10.000 2.28.0" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test failure when upgrading a non-existent account" ); @@ -1505,7 +1505,7 @@ BOOST_AUTO_TEST_CASE( account_witness_vote_authorities ) ACTORS( (alice)(bob)(sam) ) - fund( "alice", 1000 ); + fund( "alice", 1000000 ); private_key_type alice_witness_key = generate_private_key( "alice_witness" ); witness_create( "alice", alice_private_key, "foo.bar", alice_witness_key.get_public_key(), 1000 ); @@ -1518,11 +1518,11 @@ BOOST_AUTO_TEST_CASE( account_witness_vote_authorities ) tx.operations.push_back( op ); BOOST_TEST_MESSAGE( "--- Test failure when no signatures" ); - MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_basic_auth ); BOOST_TEST_MESSAGE( "--- Test failure when signed by a signature not in the account's authority" ); - tx.sign( bob_post_key, db.get_chain_id() ); - MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.sign( alice_post_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_basic_auth ); BOOST_TEST_MESSAGE( "--- Test failure when duplicate signatures" ); tx.signatures.clear(); @@ -1545,7 +1545,7 @@ BOOST_AUTO_TEST_CASE( account_witness_vote_authorities ) proxy( "bob", "sam" ); tx.signatures.clear(); tx.sign( sam_private_key, db.get_chain_id() ); - MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_missing_active_auth ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_missing_basic_auth ); validate_database(); } @@ -1559,9 +1559,9 @@ BOOST_AUTO_TEST_CASE( account_witness_vote_apply ) BOOST_TEST_MESSAGE( "Testing: account_witness_vote_apply" ); ACTORS( (alice)(bob)(sam) ) - fund( "alice" , 5000 ); - vest( "alice", 5000 ); - fund( "sam", 1000 ); + fund( "alice" , 5000000 ); + vest( "alice", 5000000 ); + fund( "sam", 1000000 ); private_key_type sam_witness_key = generate_private_key( "sam_key" ); witness_create( "sam", sam_private_key, "foo.bar", sam_witness_key.get_public_key(), 1000 ); @@ -1696,11 +1696,11 @@ BOOST_AUTO_TEST_CASE( account_witness_proxy_authorities ) tx.operations.push_back( op ); BOOST_TEST_MESSAGE( "--- Test failure when no signatures" ); - MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_basic_auth ); BOOST_TEST_MESSAGE( "--- Test failure when signed by a signature not in the account's authority" ); - tx.sign( bob_post_key, db.get_chain_id() ); - MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.sign( alice_post_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_basic_auth ); BOOST_TEST_MESSAGE( "--- Test failure when duplicate signatures" ); tx.signatures.clear(); @@ -1722,7 +1722,7 @@ BOOST_AUTO_TEST_CASE( account_witness_proxy_authorities ) BOOST_TEST_MESSAGE( "--- Test failure with proxy signature" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); - MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_missing_active_auth ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_missing_basic_auth ); validate_database(); } @@ -1918,12 +1918,12 @@ BOOST_AUTO_TEST_CASE( feed_publish_authorities ) BOOST_TEST_MESSAGE( "Testing: feed_publish_authorities" ); ACTORS( (alice)(bob) ) - fund( "alice", 10000 ); + fund( "alice", 10000000 ); witness_create( "alice", alice_private_key, "foo.bar", alice_private_key.get_public_key(), 1000 ); feed_publish_operation op; op.publisher = "alice"; - op.exchange_rate = price( ASSET( "1.000 TESTS" ), ASSET( "1.000 TBD" ) ); + op.exchange_rate = price( ASSET( "1.000 2.28.0" ), ASSET( "1.000 2.28.2" ) ); signed_transaction tx; tx.operations.push_back( op ); @@ -1942,12 +1942,12 @@ BOOST_AUTO_TEST_CASE( feed_publish_authorities ) tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_duplicate_sig ); - BOOST_TEST_MESSAGE( "--- Test failure with additional incorrect signature" ); +/* BOOST_TEST_MESSAGE( "--- Test failure with additional incorrect signature" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); tx.sign( bob_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_irrelevant_sig ); - +*/ BOOST_TEST_MESSAGE( "--- Test success with witness account signature" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); @@ -1965,13 +1965,13 @@ BOOST_AUTO_TEST_CASE( feed_publish_apply ) BOOST_TEST_MESSAGE( "Testing: feed_publish_apply" ); ACTORS( (alice) ) - fund( "alice", 10000 ); + fund( "alice", 10000000 ); witness_create( "alice", alice_private_key, "foo.bar", alice_private_key.get_public_key(), 1000 ); BOOST_TEST_MESSAGE( "--- Test publishing price feed" ); feed_publish_operation op; op.publisher = "alice"; - op.exchange_rate = price( ASSET( "1000.000 TESTS" ), ASSET( "1.000 TBD" ) ); // 1000 MUSE : 1 SBD + op.exchange_rate = price( ASSET( "1000.000 2.28.0" ), ASSET( "1.000 2.28.2" ) ); // 1000 MUSE : 1 SBD signed_transaction tx; tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); @@ -2000,7 +2000,7 @@ BOOST_AUTO_TEST_CASE( feed_publish_apply ) tx.operations.clear(); tx.signatures.clear(); - op.exchange_rate = price( ASSET(" 1500.000 TESTS" ), ASSET( "1.000 TBD" ) ); + op.exchange_rate = price( ASSET(" 1500.000 2.28.0" ), ASSET( "1.000 2.28.2" ) ); op.publisher = "alice"; tx.operations.push_back( op ); tx.sign( alice_private_key, db.get_chain_id() ); @@ -2031,17 +2031,17 @@ BOOST_AUTO_TEST_CASE( convert_authorities ) BOOST_TEST_MESSAGE( "Testing: convert_authorities" ); ACTORS( (alice)(bob) ) - fund( "alice", 10000 ); + fund( "alice", 10000000 ); - set_price_feed( price( ASSET( "1.000 TESTS" ), ASSET( "1.000 TBD" ) ) ); + set_price_feed( price( ASSET( "1.000 2.28.0" ), ASSET( "1.000 2.28.2" ) ) ); - convert( "alice", ASSET( "2.500 TESTS" ) ); + convert( "alice", ASSET( "2.500000 2.28.0" ) ); validate_database(); convert_operation op; op.owner = "alice"; - op.amount = ASSET( "2.500 TBD" ); + op.amount = ASSET( "2.500000 2.28.2" ); signed_transaction tx; tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); @@ -2060,12 +2060,12 @@ BOOST_AUTO_TEST_CASE( convert_authorities ) tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_duplicate_sig ); - BOOST_TEST_MESSAGE( "--- Test failure when signed by an additional signature not in the creator's authority" ); +/* BOOST_TEST_MESSAGE( "--- Test failure when signed by an additional signature not in the creator's authority" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); tx.sign( bob_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_irrelevant_sig ); - +*/ BOOST_TEST_MESSAGE( "--- Test success with owner signature" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); @@ -2082,8 +2082,8 @@ BOOST_AUTO_TEST_CASE( convert_apply ) { BOOST_TEST_MESSAGE( "Testing: convert_apply" ); ACTORS( (alice)(bob) ); - fund( "alice", 10000 ); - fund( "bob" , 10000 ); + fund( "alice", 10000000 ); + fund( "bob" , 10000000 ); convert_operation op; signed_transaction tx; @@ -2091,36 +2091,36 @@ BOOST_AUTO_TEST_CASE( convert_apply ) const auto& convert_request_idx = db.get_index_type< convert_index >().indices().get< by_owner >(); - set_price_feed( price( ASSET( "1.000 TESTS" ), ASSET( "1.000 TBD" ) ) ); + set_price_feed( price( ASSET( "1.000 2.28.0" ), ASSET( "1.000 2.28.2" ) ) ); - convert( "alice", ASSET( "2.500 TESTS" ) ); - convert( "bob", ASSET( "7.000 TESTS" ) ); + convert( "alice", ASSET( "2.500000 2.28.0" ) ); + convert( "bob", ASSET( "7.000 2.28.0" ) ); const auto& new_alice = db.get_account( "alice" ); const auto& new_bob = db.get_account( "bob" ); - BOOST_TEST_MESSAGE( "--- Test failure when account does not have the required TESTS" ); + BOOST_TEST_MESSAGE( "--- Test failure when account does not have the required MUSE" ); op.owner = "bob"; - op.amount = ASSET( "5.000 TESTS" ); + op.amount = ASSET( "5.000 2.28.0" ); tx.operations.push_back( op ); tx.sign( bob_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); - BOOST_REQUIRE_EQUAL( new_bob.balance.amount.value, ASSET( "3.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( new_bob.mbd_balance.amount.value, ASSET( "7.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_bob.balance.amount.value, ASSET( "3.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_bob.mbd_balance.amount.value, ASSET( "7.000 2.28.2" ).amount.value ); validate_database(); - BOOST_TEST_MESSAGE( "--- Test failure when account does not have the required TBD" ); + BOOST_TEST_MESSAGE( "--- Test failure when account does not have the required MBD" ); op.owner = "alice"; - op.amount = ASSET( "5.000 TBD" ); + op.amount = ASSET( "5.000 2.28.2" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); - BOOST_REQUIRE_EQUAL( new_alice.balance.amount.value, ASSET( "7.500 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( new_alice.mbd_balance.amount.value, ASSET( "2.500 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_alice.balance.amount.value, ASSET( "7.500000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_alice.mbd_balance.amount.value, ASSET( "2.500000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test failure when account does not exist" ); @@ -2131,17 +2131,18 @@ BOOST_AUTO_TEST_CASE( convert_apply ) tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); - BOOST_TEST_MESSAGE( "--- Test success converting SBD to TESTS" ); + BOOST_TEST_MESSAGE( "--- Test success converting MBD to MUSE" ); op.owner = "bob"; - op.amount = ASSET( "3.000 TBD" ); + op.amount = ASSET( "3.000 2.28.2" ); tx.operations.clear(); tx.signatures.clear(); + tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); tx.operations.push_back( op ); tx.sign( bob_private_key, db.get_chain_id() ); db.push_transaction( tx, 0 ); - BOOST_REQUIRE_EQUAL( new_bob.balance.amount.value, ASSET( "3.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( new_bob.mbd_balance.amount.value, ASSET( "4.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_bob.balance.amount.value, ASSET( "3.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_bob.mbd_balance.amount.value, ASSET( "4.000 2.28.2" ).amount.value ); auto convert_request = convert_request_idx.find( std::make_tuple( op.owner, op.requestid ) ); BOOST_REQUIRE( convert_request != convert_request_idx.end() ); @@ -2152,21 +2153,21 @@ BOOST_AUTO_TEST_CASE( convert_apply ) BOOST_REQUIRE( convert_request->conversion_date == db.head_block_time() + MUSE_CONVERSION_DELAY ); BOOST_TEST_MESSAGE( "--- Test failure from repeated id" ); - op.amount = ASSET( "2.000 TESTS" ); + op.amount = ASSET( "2.000 2.28.0" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); - BOOST_REQUIRE_EQUAL( new_bob.balance.amount.value, ASSET( "3.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( new_bob.mbd_balance.amount.value, ASSET( "4.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_bob.balance.amount.value, ASSET( "3.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( new_bob.mbd_balance.amount.value, ASSET( "4.000 2.28.2" ).amount.value ); convert_request = convert_request_idx.find( std::make_tuple( op.owner, op.requestid ) ); BOOST_REQUIRE( convert_request != convert_request_idx.end() ); BOOST_REQUIRE_EQUAL( convert_request->owner, op.owner ); BOOST_REQUIRE_EQUAL( convert_request->requestid, op.requestid ); - BOOST_REQUIRE_EQUAL( convert_request->amount.amount.value, ASSET( "3.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( convert_request->amount.amount.value, ASSET( "3.000 2.28.2" ).amount.value ); //BOOST_REQUIRE_EQUAL( convert_request->premium, 100000 ); BOOST_REQUIRE( convert_request->conversion_date == db.head_block_time() + MUSE_CONVERSION_DELAY ); validate_database(); @@ -2190,12 +2191,12 @@ BOOST_AUTO_TEST_CASE( limit_order_create_authorities ) BOOST_TEST_MESSAGE( "Testing: limit_order_create_authorities" ); ACTORS( (alice)(bob) ) - fund( "alice", 10000 ); + fund( "alice", 10000000 ); limit_order_create_operation op; op.owner = "alice"; - op.amount_to_sell = ASSET( "1.000 TESTS" ); - op.min_to_receive = ASSET( "1.000 TBD" ); + op.amount_to_sell = ASSET( "1.000 2.28.0" ); + op.min_to_receive = ASSET( "1.000 2.28.2" ); signed_transaction tx; tx.operations.push_back( op ); @@ -2212,12 +2213,12 @@ BOOST_AUTO_TEST_CASE( limit_order_create_authorities ) tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_duplicate_sig ); - BOOST_TEST_MESSAGE( "--- Test failure with additional incorrect signature" ); +/* BOOST_TEST_MESSAGE( "--- Test failure with additional incorrect signature" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); tx.sign( bob_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_irrelevant_sig ); - +*/ BOOST_TEST_MESSAGE( "--- Test failure with incorrect signature" ); tx.signatures.clear(); tx.sign( alice_post_key, db.get_chain_id() ); @@ -2234,12 +2235,12 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) { BOOST_TEST_MESSAGE( "Testing: limit_order_create_apply" ); - set_price_feed( price( ASSET( "1.000 TESTS" ), ASSET( "1.000 TBD" ) ) ); + set_price_feed( price( ASSET( "1.000 2.28.0" ), ASSET( "1.000 2.28.2" ) ) ); ACTORS( (alice)(bob) ) - fund( "alice", 1000000 ); - fund( "bob", 1000000 ); - convert( "bob", ASSET("1000.000 TESTS" ) ); + fund( "alice", 1000000000 ); + fund( "bob", 1000000000 ); + convert( "bob", ASSET("1000.000 2.28.0" ) ); const auto& limit_order_idx = db.get_index_type< limit_order_index >().indices().get< by_account >(); @@ -2249,8 +2250,8 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) op.owner = "bob"; op.orderid = 1; - op.amount_to_sell = ASSET( "10.000 TESTS" ); - op.min_to_receive = ASSET( "10.000 TBD" ); + op.amount_to_sell = ASSET( "10.000 2.28.0" ); + op.min_to_receive = ASSET( "10.000 2.28.2" ); op.fill_or_kill = false; tx.operations.push_back( op ); tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); @@ -2258,14 +2259,14 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "bob", op.orderid ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "0.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "100.0000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "0.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "1000.0000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test failure when amount to receive is 0" ); op.owner = "alice"; - op.min_to_receive = ASSET( "0.000 TBD" ); + op.min_to_receive = ASSET( "0.000 2.28.2" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2273,14 +2274,14 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "alice", op.orderid ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "1000.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "1000.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test failure when amount to sell is 0" ); - op.amount_to_sell = ASSET( "0.000 TESTS" ); - op.min_to_receive = ASSET( "10.000 TBD" ) ; + op.amount_to_sell = ASSET( "0.000 2.28.0" ); + op.min_to_receive = ASSET( "10.000 2.28.2" ) ; tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2288,14 +2289,14 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "alice", op.orderid ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "1000.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "1000.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test success creating limit order that will not be filled" ); - op.amount_to_sell = ASSET( "10.000 TESTS" ); - op.min_to_receive = ASSET( "15.000 TBD" ); + op.amount_to_sell = ASSET( "10.000 2.28.0" ); + op.min_to_receive = ASSET( "15.000 2.28.2" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2308,14 +2309,14 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) BOOST_REQUIRE_EQUAL( limit_order->orderid, op.orderid ); BOOST_REQUIRE( limit_order->for_sale == op.amount_to_sell.amount ); BOOST_REQUIRE( limit_order->sell_price == price( op.amount_to_sell / op.min_to_receive ) ); - BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MBD_SYMBOL, MUSE_SYMBOL ) ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MUSE_SYMBOL, MBD_SYMBOL ) ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test failure creating limit order with duplicate id" ); - op.amount_to_sell = ASSET( "20.000 TESTS" ); + op.amount_to_sell = ASSET( "20.000 2.28.0" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2326,11 +2327,11 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) BOOST_REQUIRE( limit_order != limit_order_idx.end() ); BOOST_REQUIRE_EQUAL( limit_order->seller, op.owner ); BOOST_REQUIRE_EQUAL( limit_order->orderid, op.orderid ); - BOOST_REQUIRE( limit_order->for_sale == 10000 ); - BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "10.000 TESTS" ), op.min_to_receive ) ); - BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MBD_SYMBOL, MUSE_SYMBOL ) ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE( limit_order->for_sale == 10000000 ); + BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "10.000 2.28.0" ), op.min_to_receive ) ); + BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MUSE_SYMBOL, MBD_SYMBOL ) ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test sucess killing an order that will not be filled" ); @@ -2344,8 +2345,8 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "alice", op.orderid ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test having a partial match to limit order" ); @@ -2354,8 +2355,8 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) op.owner = "bob"; op.orderid = 1; - op.amount_to_sell = ASSET( "7.500 TBD" ); - op.min_to_receive = ASSET( "5.000 TESTS" ); + op.amount_to_sell = ASSET( "7.500000 2.28.2" ); + op.min_to_receive = ASSET( "5.000 2.28.0" ); op.fill_or_kill = false; tx.operations.clear(); tx.signatures.clear(); @@ -2370,26 +2371,26 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) BOOST_REQUIRE( limit_order != limit_order_idx.end() ); BOOST_REQUIRE_EQUAL( limit_order->seller, "alice" ); BOOST_REQUIRE_EQUAL( limit_order->orderid, op.orderid ); - BOOST_REQUIRE( limit_order->for_sale == 5000 ); - BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "10.000 TESTS" ), ASSET( "15.000 TBD" ) ) ); - BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MBD_SYMBOL, MUSE_SYMBOL ) ); + BOOST_REQUIRE( limit_order->for_sale == 5000000 ); + BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "10.000 2.28.0" ), ASSET( "15.000 2.28.2" ) ) ); + BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MUSE_SYMBOL, MBD_SYMBOL ) ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "bob", op.orderid ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "7.500 TBD" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "5.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "992.500 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "7.500000 2.28.2" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "5.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "992.500000 2.28.2" ).amount.value ); BOOST_REQUIRE_EQUAL( fill_order_op.open_owner, "alice" ); BOOST_REQUIRE_EQUAL( fill_order_op.open_orderid, 1 ); - BOOST_REQUIRE_EQUAL( fill_order_op.open_pays.amount.value, ASSET( "5.000 TESTS").amount.value ); + BOOST_REQUIRE_EQUAL( fill_order_op.open_pays.amount.value, ASSET( "5.000 2.28.0").amount.value ); BOOST_REQUIRE_EQUAL( fill_order_op.current_owner, "bob" ); BOOST_REQUIRE_EQUAL( fill_order_op.current_orderid, 1 ); - BOOST_REQUIRE_EQUAL( fill_order_op.current_pays.amount.value, ASSET( "7.500 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( fill_order_op.current_pays.amount.value, ASSET( "7.500000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test filling an existing order fully, but the new order partially" ); - op.amount_to_sell = ASSET( "15.000 TBD" ); - op.min_to_receive = ASSET( "10.000 TESTS" ); + op.amount_to_sell = ASSET( "15.000 2.28.2" ); + op.min_to_receive = ASSET( "10.000 2.28.0" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2400,22 +2401,22 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) BOOST_REQUIRE( limit_order != limit_order_idx.end() ); BOOST_REQUIRE_EQUAL( limit_order->seller, "bob" ); BOOST_REQUIRE_EQUAL( limit_order->orderid, 1 ); - BOOST_REQUIRE_EQUAL( limit_order->for_sale.value, 7500 ); - BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "15.000 TBD" ), ASSET( "10.000 TESTS" ) ) ); - BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MBD_SYMBOL, MUSE_SYMBOL ) ); + BOOST_REQUIRE_EQUAL( limit_order->for_sale.value, 7500000 ); + BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "15.000 2.28.2" ), ASSET( "10.000 2.28.0" ) ) ); + BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MUSE_SYMBOL, MBD_SYMBOL ) ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "alice", 1 ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "15.000 TBD" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "10.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "977.500 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "15.000 2.28.2" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "10.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "977.500000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test filling an existing order and new order fully" ); op.owner = "alice"; op.orderid = 3; - op.amount_to_sell = ASSET( "5.000 TESTS" ); - op.min_to_receive = ASSET( "7.500 TBD" ); + op.amount_to_sell = ASSET( "5.000 2.28.0" ); + op.min_to_receive = ASSET( "7.500000 2.28.2" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2424,18 +2425,18 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "alice", 3 ) ) == limit_order_idx.end() ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "bob", 1 ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "985.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "22.500 TBD" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "15.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "977.500 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "985.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "22.500000 2.28.2" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "15.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "977.500000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test filling limit order with better order when partial order is better." ); op.owner = "alice"; op.orderid = 4; - op.amount_to_sell = ASSET( "10.000 TESTS" ); - op.min_to_receive = ASSET( "11.000 TBD" ); + op.amount_to_sell = ASSET( "10.000 2.28.0" ); + op.min_to_receive = ASSET( "11.000 2.28.2" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2444,8 +2445,8 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) op.owner = "bob"; op.orderid = 4; - op.amount_to_sell = ASSET( "12.000 TBD" ); - op.min_to_receive = ASSET( "10.000 TESTS" ); + op.amount_to_sell = ASSET( "12.000 2.28.2" ); + op.min_to_receive = ASSET( "10.000 2.28.0" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2457,13 +2458,13 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) BOOST_REQUIRE( limit_order_idx.find(std::make_tuple( "alice", 4 ) ) == limit_order_idx.end() ); BOOST_REQUIRE_EQUAL( limit_order->seller, "bob" ); BOOST_REQUIRE_EQUAL( limit_order->orderid, 4 ); - BOOST_REQUIRE_EQUAL( limit_order->for_sale.value, 1000 ); - BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "12.000 TBD" ), ASSET( "10.000 TESTS" ) ) ); - BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MBD_SYMBOL, MUSE_SYMBOL ) ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "975.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "33.500 TBD" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "25.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "965.500 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( limit_order->for_sale.value, 1000000 ); + BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "12.000 2.28.2" ), ASSET( "10.000 2.28.0" ) ) ); + BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MUSE_SYMBOL, MBD_SYMBOL ) ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "975.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "33.500000 2.28.2" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "25.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "965.500000 2.28.2" ).amount.value ); validate_database(); limit_order_cancel_operation can; @@ -2482,8 +2483,8 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) op.owner = "alice"; op.orderid = 5; - op.amount_to_sell = ASSET( "20.000 TESTS" ); - op.min_to_receive = ASSET( "22.000 TBD" ); + op.amount_to_sell = ASSET( "20.000 2.28.0" ); + op.min_to_receive = ASSET( "22.000 2.28.2" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2492,8 +2493,8 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) op.owner = "bob"; op.orderid = 5; - op.amount_to_sell = ASSET( "12.000 TBD" ); - op.min_to_receive = ASSET( "10.000 TESTS" ); + op.amount_to_sell = ASSET( "12.000 2.28.2" ); + op.min_to_receive = ASSET( "10.000 2.28.0" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2505,13 +2506,13 @@ BOOST_AUTO_TEST_CASE( limit_order_create_apply ) BOOST_REQUIRE( limit_order_idx.find(std::make_tuple( "bob", 5 ) ) == limit_order_idx.end() ); BOOST_REQUIRE_EQUAL( limit_order->seller, "alice" ); BOOST_REQUIRE_EQUAL( limit_order->orderid, 5 ); - BOOST_REQUIRE_EQUAL( limit_order->for_sale.value, 9091 ); - BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "20.000 TESTS" ), ASSET( "22.000 TBD" ) ) ); - BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MBD_SYMBOL, MUSE_SYMBOL ) ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "955.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "45.500 TBD" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "35.909 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "954.500 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( limit_order->for_sale.value, 9090910 ); + BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "20.000 2.28.0" ), ASSET( "22.000 2.28.2" ) ) ); + BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MUSE_SYMBOL, MBD_SYMBOL ) ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "955.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "45.500000 2.28.2" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "35.909090 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "954.500000 2.28.2" ).amount.value ); validate_database(); } FC_LOG_AND_RETHROW() @@ -2524,12 +2525,12 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_authorities ) BOOST_TEST_MESSAGE( "Testing: limit_order_create2_authorities" ); ACTORS( (alice)(bob) ) - fund( "alice", 10000 ); + fund( "alice", 10000000 ); limit_order_create2_operation op; op.owner = "alice"; - op.amount_to_sell = ASSET( "1.000 TESTS" ); - op.exchange_rate = price( ASSET( "1.000 TESTS" ), ASSET( "1.000 TBD" ) ); + op.amount_to_sell = ASSET( "1.000 2.28.0" ); + op.exchange_rate = price( ASSET( "1.000 2.28.0" ), ASSET( "1.000 2.28.2" ) ); signed_transaction tx; tx.operations.push_back( op ); @@ -2546,12 +2547,12 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_authorities ) tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_duplicate_sig ); - BOOST_TEST_MESSAGE( "--- Test failure with additional incorrect signature" ); +/* BOOST_TEST_MESSAGE( "--- Test failure with additional incorrect signature" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); tx.sign( bob_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_irrelevant_sig ); - +*/ BOOST_TEST_MESSAGE( "--- Test failure with incorrect signature" ); tx.signatures.clear(); tx.sign( alice_post_key, db.get_chain_id() ); @@ -2568,12 +2569,12 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) { BOOST_TEST_MESSAGE( "Testing: limit_order_create2_apply" ); - set_price_feed( price( ASSET( "1.000 TESTS" ), ASSET( "1.000 TBD" ) ) ); + set_price_feed( price( ASSET( "1.000 2.28.0" ), ASSET( "1.000 2.28.2" ) ) ); ACTORS( (alice)(bob) ) - fund( "alice", 1000000 ); - fund( "bob", 1000000 ); - convert( "bob", ASSET("1000.000 TESTS" ) ); + fund( "alice", 1000000000 ); + fund( "bob", 1000000000 ); + convert( "bob", ASSET("1000.000 2.28.0" ) ); const auto& limit_order_idx = db.get_index_type< limit_order_index >().indices().get< by_account >(); @@ -2583,8 +2584,8 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) op.owner = "bob"; op.orderid = 1; - op.amount_to_sell = ASSET( "10.000 TESTS" ); - op.exchange_rate = price( ASSET( "1.000 TESTS" ), ASSET( "1.000 TBD" ) ); + op.amount_to_sell = ASSET( "10.000 2.28.0" ); + op.exchange_rate = price( ASSET( "1.000 2.28.0" ), ASSET( "1.000 2.28.2" ) ); op.fill_or_kill = false; tx.operations.push_back( op ); tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); @@ -2592,14 +2593,14 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "bob", op.orderid ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "0.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "100.0000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "0.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "1000.0000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test failure when price is 0" ); op.owner = "alice"; - op.exchange_rate = price( ASSET( "0.000 TESTS" ), ASSET( "1.000 TBD" ) ); + op.exchange_rate = price( ASSET( "0.000 2.28.0" ), ASSET( "1.000 2.28.2" ) ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2607,14 +2608,14 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "alice", op.orderid ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "1000.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "1000.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test failure when amount to sell is 0" ); - op.amount_to_sell = ASSET( "0.000 TESTS" ); - op.exchange_rate = price( ASSET( "1.000 TESTS" ), ASSET( "1.000 TBD" ) ); + op.amount_to_sell = ASSET( "0.000 2.28.0" ); + op.exchange_rate = price( ASSET( "1.000 2.28.0" ), ASSET( "1.000 2.28.2" ) ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2622,14 +2623,14 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "alice", op.orderid ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "1000.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "1000.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test success creating limit order that will not be filled" ); - op.amount_to_sell = ASSET( "10.000 TESTS" ); - op.exchange_rate = price( ASSET( "2.000 TESTS" ), ASSET( "3.000 TBD" ) ); + op.amount_to_sell = ASSET( "10.000 2.28.0" ); + op.exchange_rate = price( ASSET( "2.000 2.28.0" ), ASSET( "3.000 2.28.2" ) ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2642,14 +2643,14 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) BOOST_REQUIRE_EQUAL( limit_order->orderid, op.orderid ); BOOST_REQUIRE( limit_order->for_sale == op.amount_to_sell.amount ); BOOST_REQUIRE( limit_order->sell_price == op.exchange_rate ); - BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MBD_SYMBOL, MUSE_SYMBOL ) ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MUSE_SYMBOL, MBD_SYMBOL ) ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test failure creating limit order with duplicate id" ); - op.amount_to_sell = ASSET( "20.000 TESTS" ); + op.amount_to_sell = ASSET( "20.000 2.28.0" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2660,11 +2661,11 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) BOOST_REQUIRE( limit_order != limit_order_idx.end() ); BOOST_REQUIRE_EQUAL( limit_order->seller, op.owner ); BOOST_REQUIRE_EQUAL( limit_order->orderid, op.orderid ); - BOOST_REQUIRE( limit_order->for_sale == 10000 ); + BOOST_REQUIRE( limit_order->for_sale == 10000000 ); BOOST_REQUIRE( limit_order->sell_price == op.exchange_rate ); - BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MBD_SYMBOL, MUSE_SYMBOL ) ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MUSE_SYMBOL, MBD_SYMBOL ) ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test sucess killing an order that will not be filled" ); @@ -2678,8 +2679,8 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "alice", op.orderid ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test having a partial match to limit order" ); @@ -2688,8 +2689,8 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) op.owner = "bob"; op.orderid = 1; - op.amount_to_sell = ASSET( "7.500 TBD" ); - op.exchange_rate = price( ASSET( "3.000 TBD" ), ASSET( "2.000 TESTS" ) ); + op.amount_to_sell = ASSET( "7.500000 2.28.2" ); + op.exchange_rate = price( ASSET( "3.000 2.28.2" ), ASSET( "2.000 2.28.0" ) ); op.fill_or_kill = false; tx.operations.clear(); tx.signatures.clear(); @@ -2704,26 +2705,26 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) BOOST_REQUIRE( limit_order != limit_order_idx.end() ); BOOST_REQUIRE_EQUAL( limit_order->seller, "alice" ); BOOST_REQUIRE_EQUAL( limit_order->orderid, op.orderid ); - BOOST_REQUIRE( limit_order->for_sale == 5000 ); - BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "2.000 TESTS" ), ASSET( "3.000 TBD" ) ) ); - BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MBD_SYMBOL, MUSE_SYMBOL ) ); + BOOST_REQUIRE( limit_order->for_sale == 5000000 ); + BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "2.000 2.28.0" ), ASSET( "3.000 2.28.2" ) ) ); + BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MUSE_SYMBOL, MBD_SYMBOL ) ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "bob", op.orderid ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "7.500 TBD" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "5.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "992.500 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "7.500000 2.28.2" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "5.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "992.500000 2.28.2" ).amount.value ); BOOST_REQUIRE_EQUAL( fill_order_op.open_owner, "alice" ); BOOST_REQUIRE_EQUAL( fill_order_op.open_orderid, 1 ); - BOOST_REQUIRE_EQUAL( fill_order_op.open_pays.amount.value, ASSET( "5.000 TESTS").amount.value ); + BOOST_REQUIRE_EQUAL( fill_order_op.open_pays.amount.value, ASSET( "5.000 2.28.0").amount.value ); BOOST_REQUIRE_EQUAL( fill_order_op.current_owner, "bob" ); BOOST_REQUIRE_EQUAL( fill_order_op.current_orderid, 1 ); - BOOST_REQUIRE_EQUAL( fill_order_op.current_pays.amount.value, ASSET( "7.500 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( fill_order_op.current_pays.amount.value, ASSET( "7.500000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test filling an existing order fully, but the new order partially" ); - op.amount_to_sell = ASSET( "15.000 TBD" ); - op.exchange_rate = price( ASSET( "3.000 TBD" ), ASSET( "2.000 TESTS" ) ); + op.amount_to_sell = ASSET( "15.000 2.28.2" ); + op.exchange_rate = price( ASSET( "3.000 2.28.2" ), ASSET( "2.000 2.28.0" ) ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2734,22 +2735,22 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) BOOST_REQUIRE( limit_order != limit_order_idx.end() ); BOOST_REQUIRE_EQUAL( limit_order->seller, "bob" ); BOOST_REQUIRE_EQUAL( limit_order->orderid, 1 ); - BOOST_REQUIRE_EQUAL( limit_order->for_sale.value, 7500 ); - BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "3.000 TBD" ), ASSET( "2.000 TESTS" ) ) ); - BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MBD_SYMBOL, MUSE_SYMBOL ) ); + BOOST_REQUIRE_EQUAL( limit_order->for_sale.value, 7500000 ); + BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "3.000 2.28.2" ), ASSET( "2.000 2.28.0" ) ) ); + BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MUSE_SYMBOL, MBD_SYMBOL ) ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "alice", 1 ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "15.000 TBD" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "10.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "977.500 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "990.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "15.000 2.28.2" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "10.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "977.500000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test filling an existing order and new order fully" ); op.owner = "alice"; op.orderid = 3; - op.amount_to_sell = ASSET( "5.000 TESTS" ); - op.exchange_rate = price( ASSET( "2.000 TESTS" ), ASSET( "3.000 TBD" ) ); + op.amount_to_sell = ASSET( "5.000 2.28.0" ); + op.exchange_rate = price( ASSET( "2.000 2.28.0" ), ASSET( "3.000 2.28.2" ) ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2758,18 +2759,18 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "alice", 3 ) ) == limit_order_idx.end() ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "bob", 1 ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "985.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "22.500 TBD" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "15.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "977.500 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "985.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "22.500000 2.28.2" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "15.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "977.500000 2.28.2" ).amount.value ); validate_database(); BOOST_TEST_MESSAGE( "--- Test filling limit order with better order when partial order is better." ); op.owner = "alice"; op.orderid = 4; - op.amount_to_sell = ASSET( "10.000 TESTS" ); - op.exchange_rate = price( ASSET( "1.000 TESTS" ), ASSET( "1.100 TBD" ) ); + op.amount_to_sell = ASSET( "10.000 2.28.0" ); + op.exchange_rate = price( ASSET( "1.000 2.28.0" ), ASSET( "1.100000 2.28.2" ) ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2778,8 +2779,8 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) op.owner = "bob"; op.orderid = 4; - op.amount_to_sell = ASSET( "12.000 TBD" ); - op.exchange_rate = price( ASSET( "1.200 TBD" ), ASSET( "1.000 TESTS" ) ); + op.amount_to_sell = ASSET( "12.000 2.28.2" ); + op.exchange_rate = price( ASSET( "1.200000 2.28.2" ), ASSET( "1.000 2.28.0" ) ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2791,13 +2792,13 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) BOOST_REQUIRE( limit_order_idx.find(std::make_tuple( "alice", 4 ) ) == limit_order_idx.end() ); BOOST_REQUIRE_EQUAL( limit_order->seller, "bob" ); BOOST_REQUIRE_EQUAL( limit_order->orderid, 4 ); - BOOST_REQUIRE_EQUAL( limit_order->for_sale.value, 1000 ); + BOOST_REQUIRE_EQUAL( limit_order->for_sale.value, 1000000 ); BOOST_REQUIRE( limit_order->sell_price == op.exchange_rate ); - BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MBD_SYMBOL, MUSE_SYMBOL ) ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "975.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "33.500 TBD" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "25.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "965.500 TBD" ).amount.value ); + BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MUSE_SYMBOL, MBD_SYMBOL ) ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "975.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "33.500000 2.28.2" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "25.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "965.500000 2.28.2" ).amount.value ); validate_database(); limit_order_cancel_operation can; @@ -2816,8 +2817,8 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) op.owner = "alice"; op.orderid = 5; - op.amount_to_sell = ASSET( "20.000 TESTS" ); - op.exchange_rate = price( ASSET( "1.000 TESTS" ), ASSET( "1.100 TBD" ) ); + op.amount_to_sell = ASSET( "20.000 2.28.0" ); + op.exchange_rate = price( ASSET( "1.000 2.28.0" ), ASSET( "1.100000 2.28.2" ) ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2826,8 +2827,8 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) op.owner = "bob"; op.orderid = 5; - op.amount_to_sell = ASSET( "12.000 TBD" ); - op.exchange_rate = price( ASSET( "1.200 TBD" ), ASSET( "1.000 TESTS" ) ); + op.amount_to_sell = ASSET( "12.000 2.28.2" ); + op.exchange_rate = price( ASSET( "1.200000 2.28.2" ), ASSET( "1.000 2.28.0" ) ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2839,13 +2840,13 @@ BOOST_AUTO_TEST_CASE( limit_order_create2_apply ) BOOST_REQUIRE( limit_order_idx.find(std::make_tuple( "bob", 5 ) ) == limit_order_idx.end() ); BOOST_REQUIRE_EQUAL( limit_order->seller, "alice" ); BOOST_REQUIRE_EQUAL( limit_order->orderid, 5 ); - BOOST_REQUIRE_EQUAL( limit_order->for_sale.value, 9091 ); - BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "1.000 TESTS" ), ASSET( "1.100 TBD" ) ) ); - BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MBD_SYMBOL, MUSE_SYMBOL ) ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "955.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "45.500 TBD" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "35.909 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "954.500 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( limit_order->for_sale.value, 9090910 ); + BOOST_REQUIRE( limit_order->sell_price == price( ASSET( "1.000 2.28.0" ), ASSET( "1.100000 2.28.2" ) ) ); + BOOST_REQUIRE( limit_order->get_market() == std::make_pair( MUSE_SYMBOL, MBD_SYMBOL ) ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "955.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "45.500000 2.28.2" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.balance.amount.value, ASSET( "35.909090 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( bob.mbd_balance.amount.value, ASSET( "954.500000 2.28.2" ).amount.value ); validate_database(); } FC_LOG_AND_RETHROW() @@ -2867,13 +2868,13 @@ BOOST_AUTO_TEST_CASE( limit_order_cancel_authorities ) BOOST_TEST_MESSAGE( "Testing: limit_order_cancel_authorities" ); ACTORS( (alice)(bob) ) - fund( "alice", 10000 ); + fund( "alice", 10000000 ); limit_order_create_operation c; c.owner = "alice"; c.orderid = 1; - c.amount_to_sell = ASSET( "1.000 TESTS" ); - c.min_to_receive = ASSET( "1.000 TBD" ); + c.amount_to_sell = ASSET( "1.000 2.28.0" ); + c.min_to_receive = ASSET( "1.000 2.28.2" ); signed_transaction tx; tx.operations.push_back( c ); @@ -2900,12 +2901,12 @@ BOOST_AUTO_TEST_CASE( limit_order_cancel_authorities ) tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_duplicate_sig ); - BOOST_TEST_MESSAGE( "--- Test failure with additional incorrect signature" ); +/* BOOST_TEST_MESSAGE( "--- Test failure with additional incorrect signature" ); tx.signatures.clear(); tx.sign( alice_private_key, db.get_chain_id() ); tx.sign( bob_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_dupe_check ), tx_irrelevant_sig ); - +*/ BOOST_TEST_MESSAGE( "--- Test failure with incorrect signature" ); tx.signatures.clear(); tx.sign( alice_post_key, db.get_chain_id() ); @@ -2923,7 +2924,7 @@ BOOST_AUTO_TEST_CASE( limit_order_cancel_apply ) BOOST_TEST_MESSAGE( "Testing: limit_order_cancel_apply" ); ACTORS( (alice) ) - fund( "alice", 10000 ); + fund( "alice", 10000000 ); const auto& limit_order_idx = db.get_index_type< limit_order_index >().indices().get< by_account >(); @@ -2944,8 +2945,8 @@ BOOST_AUTO_TEST_CASE( limit_order_cancel_apply ) limit_order_create_operation create; create.owner = "alice"; create.orderid = 5; - create.amount_to_sell = ASSET( "5.000 TESTS" ); - create.min_to_receive = ASSET( "7.500 TBD" ); + create.amount_to_sell = ASSET( "5.000 2.28.0" ); + create.min_to_receive = ASSET( "7.500000 2.28.2" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( create ); @@ -2961,8 +2962,8 @@ BOOST_AUTO_TEST_CASE( limit_order_cancel_apply ) db.push_transaction( tx, 0 ); BOOST_REQUIRE( limit_order_idx.find( std::make_tuple( "alice", 5 ) ) == limit_order_idx.end() ); - BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "10.000 TESTS" ).amount.value ); - BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.balance.amount.value, ASSET( "10.000 2.28.0" ).amount.value ); + BOOST_REQUIRE_EQUAL( alice.mbd_balance.amount.value, ASSET( "0.000 2.28.2" ).amount.value ); } FC_LOG_AND_RETHROW() } @@ -3001,12 +3002,12 @@ BOOST_AUTO_TEST_CASE( account_recovery ) BOOST_TEST_MESSAGE( "Testing: account recovery" ); ACTORS( (alice) ); - fund( "alice", 1000000 ); + fund( "alice", 1000000000 ); BOOST_TEST_MESSAGE( "Creating account bob with alice" ); account_create_operation acc_create; - acc_create.fee = ASSET( "10.000 TESTS" ); + acc_create.fee = ASSET( "10.000 2.28.0" ); acc_create.creator = "alice"; acc_create.new_account_name = "bob"; acc_create.owner = authority( 1, generate_private_key( "bob_owner" ).get_public_key(), 1 ); @@ -3338,6 +3339,4 @@ BOOST_AUTO_TEST_CASE( change_recovery_account ) FC_LOG_AND_RETHROW() } - BOOST_AUTO_TEST_SUITE_END() -#endif From bab761fd4a7be3362c1275d934a0d9f20ae2d418 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 8 Nov 2017 23:22:24 +0100 Subject: [PATCH 08/74] Enabled operation_time_tests, or at least some --- tests/tests/operation_time_tests.cpp | 144 ++++++++++++++------------- 1 file changed, 73 insertions(+), 71 deletions(-) diff --git a/tests/tests/operation_time_tests.cpp b/tests/tests/operation_time_tests.cpp index ca30d8b..f0104f0 100644 --- a/tests/tests/operation_time_tests.cpp +++ b/tests/tests/operation_time_tests.cpp @@ -1,4 +1,3 @@ -#ifdef IS_TEST_NET #include #include @@ -17,7 +16,7 @@ using namespace muse::chain; using namespace muse::chain::test; BOOST_FIXTURE_TEST_SUITE( operation_time_tests, clean_database_fixture ) - +/* BOOST_AUTO_TEST_CASE( comment_payout ) { try @@ -32,7 +31,7 @@ BOOST_AUTO_TEST_CASE( comment_payout ) fund( "dave", 5000 ); vest( "dave", 5000 ); - price exchange_rate( ASSET( "1.000 TESTS" ), ASSET( "1.000 TBD" ) ); + price exchange_rate( ASSET( "1.000 2.28.0" ), ASSET( "1.000 2.28.2" ) ); set_price_feed( exchange_rate ); signed_transaction tx; @@ -104,7 +103,7 @@ BOOST_AUTO_TEST_CASE( comment_payout ) //generate_blocks( db.get_comment( "bob", "test" ).cashout_time - MUSE_BLOCK_INTERVAL, true ); - auto reward_muse = db.get_dynamic_global_properties().total_reward_fund_muse + ASSET( "1.667 TESTS" ); + auto reward_muse = db.get_dynamic_global_properties().total_reward_fund_muse + ASSET( "1.666667 2.28.0" ); auto total_rshares2 = db.get_dynamic_global_properties().total_reward_shares2; auto bob_comment_rshares = db.get_comment( "bob", "test" ).net_rshares; auto bob_vest_shares = db.get_account( "bob" ).vesting_shares; @@ -184,7 +183,7 @@ BOOST_AUTO_TEST_CASE( comment_payout ) } FC_LOG_AND_RETHROW() } - +*/ BOOST_AUTO_TEST_CASE( discussion_rewards ) { @@ -1167,34 +1166,34 @@ BOOST_AUTO_TEST_CASE( convert_delay ) { ACTORS( (alice) ) - set_price_feed( price( asset::from_string( "1.250 TESTS" ), asset::from_string( "1.000 TBD" ) ) ); - + set_price_feed( price( asset::from_string( "1.250 2.28.0" ), asset::from_string( "1.000 2.28.2" ) ) ); +/* convert_operation op; - comment_operation comment; + //comment_operation comment; vote_operation vote; signed_transaction tx; tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); - comment.author = "alice"; - comment.title = "foo"; - comment.body = "bar"; - comment.permlink = "test"; - comment.parent_permlink = "test"; - tx.operations.push_back( comment ); - tx.sign( alice_private_key, db.get_chain_id() ); - db.push_transaction( tx, 0 ); - - tx.operations.clear(); - tx.signatures.clear(); - vote.voter = "alice"; - vote.author = "alice"; - vote.permlink = "test"; - vote.weight = MUSE_100_PERCENT; - tx.operations.push_back( vote ); - tx.sign( alice_private_key, db.get_chain_id() ); - db.push_transaction( tx, 0 ); - - generate_blocks( db.get_comment( "alice", "test" ).cashout_time, true ); + //comment.author = "alice"; + //comment.title = "foo"; + //comment.body = "bar"; + //comment.permlink = "test"; + //comment.parent_permlink = "test"; + //tx.operations.push_back( comment ); + //tx.sign( alice_private_key, db.get_chain_id() ); + //db.push_transaction( tx, 0 ); + + //tx.operations.clear(); + //tx.signatures.clear(); + //vote.voter = "alice"; + //vote.author = "alice"; + //vote.permlink = "test"; + //vote.weight = MUSE_100_PERCENT; + //tx.operations.push_back( vote ); + //tx.sign( alice_private_key, db.get_chain_id() ); + //db.push_transaction( tx, 0 ); + + //generate_blocks( db.get_comment( "alice", "test" ).cashout_time, true ); auto start_balance = asset( db.get_comment( "alice", "test" ).total_payout_value.amount / 2, MBD_SYMBOL ); @@ -1202,7 +1201,7 @@ BOOST_AUTO_TEST_CASE( convert_delay ) tx.operations.clear(); tx.signatures.clear(); op.owner = "alice"; - op.amount = asset( 2000, MBD_SYMBOL ); + op.amount = asset( 2000000, MBD_SYMBOL ); op.requestid = 2; tx.operations.push_back( op ); tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); @@ -1231,12 +1230,13 @@ BOOST_AUTO_TEST_CASE( convert_delay ) convert_request = convert_request_idx.find( std::make_tuple( "alice", 2 ) ); BOOST_REQUIRE( convert_request == convert_request_idx.end() ); - BOOST_REQUIRE_EQUAL( alice_3.balance.amount.value, 2500 ); + BOOST_REQUIRE_EQUAL( alice_3.balance.amount.value, 2500000 ); BOOST_REQUIRE_EQUAL( alice_3.mbd_balance.amount.value, ( start_balance - op.amount ).amount.value ); BOOST_REQUIRE_EQUAL( vop.owner, "alice" ); BOOST_REQUIRE_EQUAL( vop.requestid, 2 ); - BOOST_REQUIRE_EQUAL( vop.amount_in.amount.value, ASSET( "2.000 TBD" ).amount.value ); - BOOST_REQUIRE_EQUAL( vop.amount_out.amount.value, ASSET( "2.500 TESTS" ).amount.value ); + BOOST_REQUIRE_EQUAL( vop.amount_in.amount.value, ASSET( "2.000 2.28.2" ).amount.value ); + BOOST_REQUIRE_EQUAL( vop.amount_out.amount.value, ASSET( "2.500 2.28.0" ).amount.value ); + */ validate_database(); } FC_LOG_AND_RETHROW(); @@ -1399,7 +1399,6 @@ BOOST_AUTO_TEST_CASE( muse_inflation ) validate_database(); } -/* virtual_supply = gpo.virtual_supply; vesting_shares = gpo.total_vesting_shares; vesting_muse = gpo.total_vesting_fund_muse; @@ -1432,10 +1431,10 @@ BOOST_AUTO_TEST_CASE( mbd_interest ) { ACTORS( (alice)(bob) ) - set_price_feed( price( asset::from_string( "1.000 TESTS" ), asset::from_string( "1.000 TBD" ) ) ); + set_price_feed( price( asset::from_string( "1.000 2.28.0" ), asset::from_string( "1.000 2.28.2" ) ) ); BOOST_TEST_MESSAGE( "Testing interest over smallest interest period" ); - +/* convert_operation op; comment_operation comment; vote_operation vote; @@ -1471,7 +1470,7 @@ BOOST_AUTO_TEST_CASE( mbd_interest ) transfer_operation transfer; transfer.to = "bob"; transfer.from = "alice"; - transfer.amount = ASSET( "1.000 TBD" ); + transfer.amount = ASSET( "1.000 2.28.2" ); tx.operations.clear(); tx.signatures.clear(); tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); @@ -1521,6 +1520,7 @@ BOOST_AUTO_TEST_CASE( mbd_interest ) db.push_transaction( tx, 0 ); BOOST_REQUIRE_EQUAL( db.get_account( "alice" ).mbd_balance.amount.value, alice_mbd.amount.value - ASSET( "1.000 TBD" ).amount.value + ( ( ( ( uint128_t( alice_mbd.amount.value ) * ( db.head_block_time() - start_time ).to_seconds() + alice_coindays ) / MUSE_SECONDS_PER_YEAR ) * gpo.mbd_interest_rate ) / MUSE_100_PERCENT ).to_uint64() ); +*/ validate_database(); } FC_LOG_AND_RETHROW(); @@ -1532,15 +1532,15 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards ) try { - db.liquidity_rewards_enabled = false; + //db.liquidity_rewards_enabled = false; ACTORS( (alice)(bob)(sam)(dave) ) BOOST_TEST_MESSAGE( "Rewarding Bob with TESTS" ); - auto exchange_rate = price( ASSET( "1.250 TESTS" ), ASSET( "1.000 TBD" ) ); + auto exchange_rate = price( ASSET( "1.250 2.28.0" ), ASSET( "1.000 2.28.2" ) ); set_price_feed( exchange_rate ); - +/* signed_transaction tx; comment_operation comment; comment.author = "alice"; @@ -1633,14 +1633,14 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards ) /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "alice" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, alice_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, alice_muse_volume ); - BOOST_CHECK( reward->last_update == alice_reward_last_update );*/ + BOOST_CHECK( reward->last_update == alice_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "bob" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "bob" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, bob_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, bob_muse_volume ); - BOOST_CHECK( reward->last_update == bob_reward_last_update );*/ + BOOST_CHECK( reward->last_update == bob_reward_last_update );* / auto fill_order_op = ops[0].get< fill_order_operation >(); @@ -1732,21 +1732,21 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards ) /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "alice" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, alice_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, alice_muse_volume ); - BOOST_CHECK( reward->last_update == alice_reward_last_update );*/ + BOOST_CHECK( reward->last_update == alice_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "bob" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "bob" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, bob_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, bob_muse_volume ); - BOOST_CHECK( reward->last_update == bob_reward_last_update );*/ + BOOST_CHECK( reward->last_update == bob_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "sam" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "sam" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, sam_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, sam_muse_volume ); - BOOST_CHECK( reward->last_update == sam_reward_last_update );*/ + BOOST_CHECK( reward->last_update == sam_reward_last_update );* / BOOST_TEST_MESSAGE( "Testing a partial fill before minimum time and full fill after minimum time" ); @@ -1792,21 +1792,21 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards ) /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "alice" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, alice_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, alice_muse_volume ); - BOOST_CHECK( reward->last_update == alice_reward_last_update );*/ + BOOST_CHECK( reward->last_update == alice_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "bob" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "bob" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, bob_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, bob_muse_volume ); - BOOST_CHECK( reward->last_update == bob_reward_last_update );*/ + BOOST_CHECK( reward->last_update == bob_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "sam" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "sam" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, sam_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, sam_muse_volume ); - BOOST_CHECK( reward->last_update == sam_reward_last_update );*/ + BOOST_CHECK( reward->last_update == sam_reward_last_update );* / generate_blocks( db.head_block_time() + MUSE_MIN_LIQUIDITY_REWARD_PERIOD_SEC_HF10, true ); @@ -1840,21 +1840,21 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards ) /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "alice" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, alice_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, alice_muse_volume ); - BOOST_CHECK( reward->last_update == alice_reward_last_update );*/ + BOOST_CHECK( reward->last_update == alice_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "bob" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "bob" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, bob_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, bob_muse_volume ); - BOOST_CHECK( reward->last_update == bob_reward_last_update );*/ + BOOST_CHECK( reward->last_update == bob_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "sam" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "sam" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, sam_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, sam_muse_volume ); - BOOST_CHECK( reward->last_update == sam_reward_last_update );*/ + BOOST_CHECK( reward->last_update == sam_reward_last_update );* / BOOST_TEST_MESSAGE( "Trading to give Alice and Bob positive volumes to receive rewards" ); @@ -1913,28 +1913,28 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards ) /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "alice" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, alice_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, alice_muse_volume ); - BOOST_CHECK( reward->last_update == alice_reward_last_update );*/ + BOOST_CHECK( reward->last_update == alice_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "bob" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "bob" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, bob_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, bob_muse_volume ); - BOOST_CHECK( reward->last_update == bob_reward_last_update );*/ + BOOST_CHECK( reward->last_update == bob_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "sam" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "sam" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, sam_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, sam_muse_volume ); - BOOST_CHECK( reward->last_update == sam_reward_last_update );*/ + BOOST_CHECK( reward->last_update == sam_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "dave" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "dave" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, dave_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, dave_muse_volume ); - BOOST_CHECK( reward->last_update == dave_reward_last_update );*/ + BOOST_CHECK( reward->last_update == dave_reward_last_update );* / op.owner = "bob"; op.amount_to_sell.amount = alice_mbd.amount / 20; @@ -1966,28 +1966,28 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards ) /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "alice" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, alice_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, alice_muse_volume ); - BOOST_CHECK( reward->last_update == alice_reward_last_update );*/ + BOOST_CHECK( reward->last_update == alice_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "bob" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "bob" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, bob_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, bob_muse_volume ); - BOOST_CHECK( reward->last_update == bob_reward_last_update );*/ + BOOST_CHECK( reward->last_update == bob_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "sam" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "sam" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, sam_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, sam_muse_volume ); - BOOST_CHECK( reward->last_update == sam_reward_last_update );*/ + BOOST_CHECK( reward->last_update == sam_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "dave" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "dave" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, dave_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, dave_muse_volume ); - BOOST_CHECK( reward->last_update == dave_reward_last_update );*/ + BOOST_CHECK( reward->last_update == dave_reward_last_update );* / transfer.to = "bob"; transfer.from = "alice"; @@ -2041,28 +2041,28 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards ) /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "alice" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, alice_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, alice_muse_volume ); - BOOST_CHECK( reward->last_update == alice_reward_last_update );*/ + BOOST_CHECK( reward->last_update == alice_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "bob" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "bob" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, bob_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, bob_muse_volume ); - BOOST_CHECK( reward->last_update == bob_reward_last_update );*/ + BOOST_CHECK( reward->last_update == bob_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "sam" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "sam" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, sam_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, sam_muse_volume ); - BOOST_CHECK( reward->last_update == sam_reward_last_update );*/ + BOOST_CHECK( reward->last_update == sam_reward_last_update );* / reward = liquidity_idx.find( db.get_account( "dave" ).id ); BOOST_REQUIRE( reward == liquidity_idx.end() ); /*BOOST_CHECK_EQUAL( reward->owner, db.get_account( "dave" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, dave_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, dave_muse_volume ); - BOOST_CHECK( reward->last_update == dave_reward_last_update );*/ + BOOST_CHECK( reward->last_update == dave_reward_last_update );* / auto dave_last_order_time = db.head_block_time(); @@ -2121,8 +2121,8 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards ) op.owner = "sam"; op.orderid = 14; - op.amount_to_sell = ASSET( "1.000 TESTS" ); - op.min_to_receive = ASSET( "1.000 TBD" ); + op.amount_to_sell = ASSET( "1.000 2.28.0" ); + op.min_to_receive = ASSET( "1.000 2.28.2" ); tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( op ); @@ -2137,7 +2137,7 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards ) BOOST_CHECK_EQUAL( reward->owner, db.get_account( "sam" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, sam_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, sam_muse_volume ); - BOOST_CHECK( reward->last_update == sam_reward_last_update );*/ + BOOST_CHECK( reward->last_update == sam_reward_last_update );* / generate_block(); @@ -2152,7 +2152,7 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards ) tx.sign( alice_private_key, db.get_chain_id() ); db.push_transaction( tx, 0 ); - sam_mbd_volume = ASSET( "1.000 TBD" ).amount.value; + sam_mbd_volume = ASSET( "1.000 2.28.2" ).amount.value; sam_muse_volume = 0; sam_reward_last_update = db.head_block_time(); @@ -2161,7 +2161,8 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards ) BOOST_CHECK_EQUAL( reward->owner, db.get_account( "sam" ).id ); BOOST_CHECK_EQUAL( reward->mbd_volume, sam_mbd_volume ); BOOST_CHECK_EQUAL( reward->muse_volume, sam_muse_volume ); - BOOST_CHECK( reward->last_update == sam_reward_last_update );*/ + BOOST_CHECK( reward->last_update == sam_reward_last_update );* / +*/ } FC_LOG_AND_RETHROW(); } @@ -2174,7 +2175,7 @@ BOOST_AUTO_TEST_CASE( post_rate_limit ) fund( "alice", 10000 ); vest( "alice", 10000 ); - +/* comment_operation op; op.author = "alice"; op.permlink = "test1"; @@ -2258,6 +2259,7 @@ BOOST_AUTO_TEST_CASE( post_rate_limit ) BOOST_REQUIRE( db.get_account( "alice" ).post_bandwidth == alice_post_bandwidth ); BOOST_REQUIRE( db.get_comment( "alice", "test5" ).reward_weight == reward_weight ); +*/ } FC_LOG_AND_RETHROW() } @@ -2277,11 +2279,11 @@ BOOST_AUTO_TEST_CASE( comment_freeze ) vest( "sam", 10000 ); vest( "dave", 10000 ); - auto exchange_rate = price( ASSET( "1.250 TESTS" ), ASSET( "1.000 TBD" ) ); + auto exchange_rate = price( ASSET( "1.250 2.28.0" ), ASSET( "1.000 2.28.2" ) ); set_price_feed( exchange_rate ); signed_transaction tx; - +/* comment_operation comment; comment.author = "alice"; comment.parent_author = ""; @@ -2409,10 +2411,10 @@ BOOST_AUTO_TEST_CASE( comment_freeze ) tx.operations.push_back( comment ); tx.sign( alice_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); +*/ } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_SUITE_END() -#endif From 070147ba90287fc7d4285c3132ce468fcd0f00e5 Mon Sep 17 00:00:00 2001 From: tilllinden Date: Thu, 14 Sep 2017 16:37:06 +0200 Subject: [PATCH 09/74] error in asset parsing correction correction of correction correction of correction --- .../include/muse/chain/protocol/asset.hpp | 45 +---------------- libraries/chain/protocol/asset.cpp | 49 ++++++++++++++++++- 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/libraries/chain/include/muse/chain/protocol/asset.hpp b/libraries/chain/include/muse/chain/protocol/asset.hpp index a7b8125..bb8bcfe 100644 --- a/libraries/chain/include/muse/chain/protocol/asset.hpp +++ b/libraries/chain/include/muse/chain/protocol/asset.hpp @@ -7,50 +7,9 @@ namespace muse { namespace chain { struct asset { - string to_string()const { - int64_t init_digits=amount.value/(precision()); - uint64_t fraction=amount.value%(precision()); - string output=std::to_string(init_digits); - output=output+"."+std::to_string(precision() + fraction).erase(0,1); - object_id_type id_t(asset_id); - output = output +" "+ std::string(id_t); - return output; - } + string to_string()const; - static asset from_string(string from) { - int64_t amount; - string s = fc::trim( from ); - auto dot_pos = s.find( "." ); - auto space_pos = s.find( " " ); - FC_ASSERT ( space_pos != std::string::npos ); - if(space_pos < dot_pos) { //no dot in the first part - auto intpart = s.substr( 0, space_pos ); - amount = fc::to_int64(intpart)*static_precision(); - }else{ - - auto intpart = s.substr( 0, dot_pos ); - amount = fc::to_int64(intpart)*static_precision(); - - std::string fractpart = s.substr( dot_pos+1, std::min(space_pos-dot_pos-1, MUSE_ASSET_PRECISION)); - uint64_t fract_amount = fc::to_int64(fractpart); - for(int i=MUSE_ASSET_PRECISION; i< fractpart.length(); i--) - fract_amount*=10; - - amount = amount + fract_amount; - } - - auto asset_id_s = s.substr( space_pos+1 ); - auto first_dot = asset_id_s.find('.'); - auto second_dot = asset_id_s.find('.',first_dot+1); - FC_ASSERT( first_dot != second_dot ); - FC_ASSERT( first_dot != 0 && first_dot != std::string::npos ); - uint64_t number = fc::to_uint64(asset_id_s.substr( second_dot+1 )); - - FC_ASSERT( number <= GRAPHENE_DB_MAX_INSTANCE_ID ); - - return asset(amount, asset_id_type(number)); - - } + static asset from_string(string from); asset( share_type a = 0, asset_id_type id = MUSE_SYMBOL ) :amount(a),asset_id(id){} diff --git a/libraries/chain/protocol/asset.cpp b/libraries/chain/protocol/asset.cpp index 3e644d6..a846716 100644 --- a/libraries/chain/protocol/asset.cpp +++ b/libraries/chain/protocol/asset.cpp @@ -16,7 +16,54 @@ namespace muse { namespace chain { //a[0] = d; } - share_type asset::scaled_precision( uint8_t precision ){ + + string asset::to_string()const { + int64_t init_digits=amount.value/(precision()); + uint64_t fraction=amount.value%(precision()); + string output=std::to_string(init_digits); + output=output+"."+std::to_string(precision() + fraction).erase(0,1); + object_id_type id_t(asset_id); + output = output +" "+ std::string(id_t); + return output; + } + + asset asset::from_string(string from) { + int64_t amount; + string s = fc::trim( from ); + auto dot_pos = s.find( "." ); + auto space_pos = s.find( " " ); + FC_ASSERT ( space_pos != std::string::npos ); + if(space_pos < dot_pos) { //no dot in the first part + auto intpart = s.substr( 0, space_pos ); + amount = fc::to_int64(intpart)*static_precision(); + }else{ + + auto intpart = s.substr( 0, dot_pos ); + amount = fc::to_int64(intpart)*static_precision(); + + std::string fractpart = s.substr( dot_pos+1, std::min(space_pos-dot_pos-1, MUSE_ASSET_PRECISION)); + while (fractpart.size() < MUSE_ASSET_PRECISION) + fractpart+='0'; + + uint64_t fract_amount = fc::to_int64(fractpart); + + amount = amount + fract_amount; + } + + auto asset_id_s = s.substr( space_pos+1 ); + auto first_dot = asset_id_s.find('.'); + auto second_dot = asset_id_s.find('.',first_dot+1); + FC_ASSERT( first_dot != second_dot ); + FC_ASSERT( first_dot != 0 && first_dot != std::string::npos ); + uint64_t number = fc::to_uint64(asset_id_s.substr( second_dot+1 )); + + FC_ASSERT( number <= GRAPHENE_DB_MAX_INSTANCE_ID ); + + return asset(amount, asset_id_type(number)); + + } + +share_type asset::scaled_precision( uint8_t precision ){ FC_ASSERT(precision<19); share_type res=1; for (int i=0; i< precision; i++) From 2de5c5626c4d38571e06d36d5426a56ad1a65c61 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 27 Oct 2017 18:12:54 +0200 Subject: [PATCH 10/74] Cleanup, optimization --- .../include/muse/chain/protocol/asset.hpp | 7 +--- libraries/chain/protocol/asset.cpp | 41 +++---------------- 2 files changed, 6 insertions(+), 42 deletions(-) diff --git a/libraries/chain/include/muse/chain/protocol/asset.hpp b/libraries/chain/include/muse/chain/protocol/asset.hpp index bb8bcfe..6f8da30 100644 --- a/libraries/chain/include/muse/chain/protocol/asset.hpp +++ b/libraries/chain/include/muse/chain/protocol/asset.hpp @@ -9,7 +9,7 @@ namespace muse { namespace chain { { string to_string()const; - static asset from_string(string from); + static asset from_string(const string& from); asset( share_type a = 0, asset_id_type id = MUSE_SYMBOL ) :amount(a),asset_id(id){} @@ -23,13 +23,8 @@ namespace muse { namespace chain { static share_type scaled_precision(uint8_t precision); uint8_t decimals()const; - //std::string symbol_name()const; int64_t precision()const; static int64_t static_precision(); - void set_decimals(uint8_t d); - - //static asset from_string( const string& from ); - //string to_string()const; asset& operator += ( const asset& o ) { diff --git a/libraries/chain/protocol/asset.cpp b/libraries/chain/protocol/asset.cpp index a846716..bbf522a 100644 --- a/libraries/chain/protocol/asset.cpp +++ b/libraries/chain/protocol/asset.cpp @@ -7,15 +7,7 @@ namespace muse { namespace chain { uint8_t asset::decimals()const { return MUSE_ASSET_PRECISION; - // auto a = (const char*)&symbol; - // return a[0]; } - void asset::set_decimals(uint8_t d){ - return; - //auto a = (char*)&symbol; - //a[0] = d; - } - string asset::to_string()const { int64_t init_digits=amount.value/(precision()); @@ -27,7 +19,7 @@ namespace muse { namespace chain { return output; } - asset asset::from_string(string from) { + asset asset::from_string(const string& from) { int64_t amount; string s = fc::trim( from ); auto dot_pos = s.find( "." ); @@ -63,45 +55,22 @@ namespace muse { namespace chain { } -share_type asset::scaled_precision( uint8_t precision ){ - FC_ASSERT(precision<19); + share_type asset::scaled_precision( uint8_t decimals ){ + FC_ASSERT(decimals<19); share_type res=1; - for (int i=0; i< precision; i++) + for (int i=0; i< decimals; i++) res*=10; return res; } -/* std::string asset::symbol_name()const { - auto a = (const char*)&symbol; - assert( a[7] == 0 ); - return &a[1]; - } -*/ + int64_t asset::static_precision(){ return 1000000; } int64_t asset::precision()const { return 1000000; - /*static int64_t table[] = { - 1, 10, 100, 1000, 10000, - 100000, 1000000, 10000000, 100000000ll, - 1000000000ll, 10000000000ll, - 100000000000ll, 1000000000000ll, - 10000000000000ll, 100000000000000ll - }; - return table[ decimals() ];*/ } - /*string asset::to_string()const { - string result = fc::to_string(amount.value / precision()); - if( decimals() ) - { - auto fract = amount.value % precision(); - result += "." + fc::to_string(precision() + fract).erase(0,1); - } - return result + " "; - }*/ - bool operator == ( const price& a, const price& b ) { if( std::tie( a.base.asset_id, a.quote.asset_id ) != std::tie( b.base.asset_id, b.quote.asset_id ) ) From 19161eea5570f5b860339fee4e572b3d00c6a950 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 24 Oct 2017 22:22:13 +0200 Subject: [PATCH 11/74] Added test for reward calculation --- tests/tests/reward_tests.cpp | 103 +++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 tests/tests/reward_tests.cpp diff --git a/tests/tests/reward_tests.cpp b/tests/tests/reward_tests.cpp new file mode 100644 index 0000000..3ac4b82 --- /dev/null +++ b/tests/tests/reward_tests.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2017 Peertracks, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include + +#include "../common/database_fixture.hpp" + +using namespace muse::chain; +using namespace graphene::db; + +BOOST_AUTO_TEST_SUITE( reward_tests ) + +/** + * According to cob, the inflation + * "should be a total of about 9.5% per year. But from that 9.5% 10% to + * wtnesses, 15% vests and 75% content" + * Meaning witnesses receive 0.95% inflation, vests 1.425% (rounded to 1.43) + * and content 7.125% (rounded to 7.12%). + * + * As a rough estimate we assume that the average supply over the course of + * the year is 1.0475 times the supply at the beginning (in reality it's + * slightly lower). + */ + +BOOST_AUTO_TEST_CASE( witness_reward_test ) +{ + int64_t supply = 18000000LL * 1000000; + int64_t expected_witness_reward = supply * .0095; + + int64_t avg_supply = 1.0475 * supply; + int64_t avg_witness_reward = calc_percent_reward_per_block( avg_supply ).value; + int64_t witness_reward_per_year = avg_witness_reward * MUSE_BLOCKS_PER_YEAR; + + std::cerr << "Expected witness reward: " << expected_witness_reward + << ". actual: " << witness_reward_per_year << std::endl; + // check estimate is within 5% of expected + BOOST_CHECK( expected_witness_reward * .95 < witness_reward_per_year ); + BOOST_CHECK( witness_reward_per_year < expected_witness_reward * 1.05 ); +} + +BOOST_AUTO_TEST_CASE( vesting_reward_test ) +{ + int64_t supply = 18000000LL * 1000000; + int64_t expected_vesting_reward = supply * .01425; + + int64_t avg_supply = 1.0475 * supply; + int64_t avg_vesting_reward = calc_percent_reward_per_block( avg_supply ).value; + int64_t vesting_reward_per_year = avg_vesting_reward * MUSE_BLOCKS_PER_YEAR; + + std::cerr << "Expected vesting reward: " << expected_vesting_reward + << ". actual: " << vesting_reward_per_year << std::endl; + // check estimate is within 5% of expected + BOOST_CHECK( expected_vesting_reward * .95 < vesting_reward_per_year ); + BOOST_CHECK( vesting_reward_per_year < expected_vesting_reward * 1.05 ); +} + +BOOST_AUTO_TEST_CASE( content_reward_test ) +{ + int64_t supply = 18000000LL * 1000000; + int64_t expected_content_reward = supply * .07125; + + int64_t avg_supply = 1.0475 * supply; + int64_t avg_content_reward = calc_percent_reward_per_day( avg_supply ).value; + int64_t content_reward_per_year = avg_content_reward * 365; + + std::cerr << "Expected content reward: " << expected_content_reward + << ". actual: " << content_reward_per_year << std::endl; + // check estimate is within 5% of expected + BOOST_CHECK( expected_content_reward * .95 < content_reward_per_year ); + BOOST_CHECK( content_reward_per_year < expected_content_reward * 1.05 ); +} + +/** + * Verify block producer reward + */ +BOOST_AUTO_TEST_CASE( producer_test ) +{ +} + +BOOST_AUTO_TEST_SUITE_END() From 4a80b88786140b4c7c36ded1c448a952108bfb71 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 24 Oct 2017 23:24:00 +0200 Subject: [PATCH 12/74] Added a script for computing APR multipliers / shifts --- programs/util/calc_inflation_constants.js | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 programs/util/calc_inflation_constants.js diff --git a/programs/util/calc_inflation_constants.js b/programs/util/calc_inflation_constants.js new file mode 100755 index 0000000..0873638 --- /dev/null +++ b/programs/util/calc_inflation_constants.js @@ -0,0 +1,43 @@ +#!/usr/bin/node + +require("console"); + +//var MUSE_100_PCT = 100000; +var MUSE_100_PCT = 10000; + +//var TOTAL_INFLATION = 1; +var TOTAL_INFLATION = .095; + +var MAX_MULT = Math.pow(2,64) / MUSE_100_PCT; + +var BLOCK_TIME_SECS = 3; +var DAYS_PER_YEAR = 365; +var HOURS_PER_YEAR = 24 * DAYS_PER_YEAR; +var BLOCKS_PER_YEAR = HOURS_PER_YEAR * 3600 / BLOCK_TIME_SECS; +var ROUNDS_PER_YEAR = BLOCKS_PER_YEAR / 21; + +var WANTED = { + BLOCK: BLOCKS_PER_YEAR, + ROUND: ROUNDS_PER_YEAR, + HOUR: HOURS_PER_YEAR, + DAY: DAYS_PER_YEAR +}; + +function calc_constants( steps ) { + var multiplier = Math.expm1(Math.log1p(TOTAL_INFLATION) / steps) / MUSE_100_PCT; + var shift = 0; + while (multiplier < MAX_MULT) { + shift++; + multiplier *= 2; + } + shift--; + multiplier /= 2; + return [Math.round(multiplier + .5), shift]; +} + +Object.keys(WANTED).forEach(function (key) { + var result = calc_constants( WANTED[key] ); + //console.log("// " + key + ": " + WANTED[key] + " - " + result[0] + " >> " + result[1]); + console.log("#define MUSE_APR_PERCENT_MULTIPLY_PER_" + key + " (0x" + result[0].toString(16) + "ULL)"); + console.log("#define MUSE_APR_PERCENT_SHIFT_PER_" + key + " " + result[1]); +}); From 97604ec51b4deab645be67dabc0d4bd399eea0d2 Mon Sep 17 00:00:00 2001 From: tilllinden Date: Thu, 14 Sep 2017 17:55:13 +0200 Subject: [PATCH 13/74] partial correction reward system reworked, HF prepared finetuning removing debug calculations Update muse_evaluator.cpp bugfix in backward compatibility --- libraries/chain/database.cpp | 51 ++++++++----------- libraries/chain/hardfork.d/0-1.hf | 6 +++ libraries/chain/hardfork.d/0-preamble.hf | 2 +- .../chain/include/muse/chain/compound.hpp | 26 ++++++++-- libraries/chain/include/muse/chain/config.hpp | 27 ++++++++-- .../chain/include/muse/chain/database.hpp | 9 +--- libraries/chain/muse_evaluator.cpp | 21 ++++++-- libraries/chain/protocol/operations.cpp | 1 - 8 files changed, 92 insertions(+), 51 deletions(-) create mode 100644 libraries/chain/hardfork.d/0-1.hf diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 03c57e3..fea7361 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1821,6 +1821,7 @@ void database::process_funds() auto witness_pay = get_producer_reward(); auto vesting_reward = get_vesting_reward(); + if( props.head_block_number < MUSE_START_VESTING_BLOCK ) vesting_reward.amount = 0; @@ -1862,7 +1863,12 @@ asset database::get_liquidity_reward()const asset database::get_content_reward()const { const auto& props = get_dynamic_global_properties(); + static_assert( MUSE_BLOCK_INTERVAL == 3, "this code assumes a 3-second time interval" ); + if(has_hardfork(MUSE_HARDFORK_0_1)){ + asset percent( calc_percent_reward_per_day_new< MUSE_CONTENT_APR_PERCENT_N >( props.virtual_supply.amount ), MUSE_SYMBOL ); + return std::max( percent, MUSE_MIN_CONTENT_REWARD ); + } asset percent( calc_percent_reward_per_day< MUSE_CONTENT_APR_PERCENT >( props.virtual_supply.amount ), MUSE_SYMBOL ); return std::max( percent, MUSE_MIN_CONTENT_REWARD ); } @@ -1871,6 +1877,11 @@ asset database::get_vesting_reward()const { const auto& props = get_dynamic_global_properties(); static_assert( MUSE_BLOCK_INTERVAL == 3, "this code assumes a 3-second time interval" ); + + if(has_hardfork(MUSE_HARDFORK_0_1)){ + asset percent( calc_percent_reward_per_block_new< MUSE_VESTING_ARP_PERCENT_N >( props.virtual_supply.amount ), MUSE_SYMBOL ); + return percent; + } asset percent( calc_percent_reward_per_block< MUSE_VESTING_ARP_PERCENT >( props.virtual_supply.amount ), MUSE_SYMBOL ); return percent; } @@ -1879,7 +1890,15 @@ asset database::get_producer_reward() { const auto& props = get_dynamic_global_properties(); static_assert( MUSE_BLOCK_INTERVAL == 3, "this code assumes a 3-second time interval" ); - asset percent( calc_percent_reward_per_block< MUSE_PRODUCER_APR_PERCENT >( props.virtual_supply.amount ), MUSE_SYMBOL); + + asset percent; + if( has_hardfork(MUSE_HARDFORK_0_1)){ + asset p (calc_percent_reward_per_block_new< MUSE_PRODUCER_APR_PERCENT_N >( props.virtual_supply.amount), MUSE_SYMBOL ); + percent = p; + }else { + asset p (calc_percent_reward_per_block< MUSE_PRODUCER_APR_PERCENT >( props.virtual_supply.amount ), MUSE_SYMBOL); + percent = p; + } auto pay = std::max( percent, MUSE_MIN_PRODUCER_REWARD ); const auto& witness_account = get_account( props.current_witness ); @@ -1931,32 +1950,6 @@ void database::pay_liquidity_reward() } } -uint16_t database::get_activity_rewards_percent() const -{ - return 0; -} - -uint16_t database::get_discussion_rewards_percent() const -{ - /* - if( has_hardfork( MUSE_HARDFORK_0_8__116 ) ) - return MUSE_1_PERCENT * 25; - else - */ - return 0; -} - - -uint128_t database::get_content_constant_s() const -{ - return uint128_t( uint64_t(2000000000000ll) ); // looking good for posters -} - -uint128_t database::calculate_vshares( uint128_t rshares ) const -{ - auto s = get_content_constant_s(); - return ( rshares + s ) * ( rshares + s ) - s * s; -} /** * Iterates over all conversion requests with a conversion date before @@ -3231,7 +3224,6 @@ void database::init_hardforks() const auto& hardforks = hardfork_property_id_type()( *this ); FC_ASSERT( hardforks.last_hardfork <= MUSE_NUM_HARDFORKS, "Chain knows of more hardforks than configuration", ("hardforks.last_hardfork",hardforks.last_hardfork)("MUSE_NUM_HARDFORKS",MUSE_NUM_HARDFORKS) ); FC_ASSERT( _hardfork_versions[ hardforks.last_hardfork ] <= MUSE_BLOCKCHAIN_VERSION, "Blockchain version is older than last applied hardfork" ); - FC_ASSERT( MUSE_BLOCKCHAIN_HARDFORK_VERSION == _hardfork_versions[ MUSE_NUM_HARDFORKS ] ); } void database::reset_virtual_schedule_time() @@ -3275,7 +3267,8 @@ void database::process_hardforks() bool database::has_hardfork( uint32_t hardfork )const { - return hardfork_property_id_type()( *this ).processed_hardforks.size() > hardfork; + uint32_t processed_hardforks = hardfork_property_id_type()( *this ).processed_hardforks.size(); + return processed_hardforks > hardfork; } void database::set_hardfork( uint32_t hardfork, bool apply_now ) diff --git a/libraries/chain/hardfork.d/0-1.hf b/libraries/chain/hardfork.d/0-1.hf new file mode 100644 index 0000000..65a5de9 --- /dev/null +++ b/libraries/chain/hardfork.d/0-1.hf @@ -0,0 +1,6 @@ +#ifndef MUSE_HARDFORK_0_1 +#define MUSE_HARDFORK_0_1 1 +// 9/23/2017 00:00:00 GMT +#define MUSE_HARDFORK_0_1_TIME 1506124800 +#define MUSE_HARDFORK_0_1_VERSION hardfork_version( 0, 1 ) +#endif diff --git a/libraries/chain/hardfork.d/0-preamble.hf b/libraries/chain/hardfork.d/0-preamble.hf index a357af5..f4fc851 100644 --- a/libraries/chain/hardfork.d/0-preamble.hf +++ b/libraries/chain/hardfork.d/0-preamble.hf @@ -33,5 +33,5 @@ FC_REFLECT_DERIVED( muse::chain::hardfork_property_object, (graphene::db::object (processed_hardforks)(last_hardfork)(current_hardfork_version) (next_hardfork)(next_hardfork_time) ) -#define MUSE_NUM_HARDFORKS 0 +#define MUSE_NUM_HARDFORKS 1 diff --git a/libraries/chain/include/muse/chain/compound.hpp b/libraries/chain/include/muse/chain/compound.hpp index 42a301c..fda55c2 100644 --- a/libraries/chain/include/muse/chain/compound.hpp +++ b/libraries/chain/include/muse/chain/compound.hpp @@ -21,19 +21,32 @@ share_type calc_percent_reward( share_type current_supply ) static const uint128_t half = uint128_t(1) << (shift_constant - 1); - uint128_t reward = current_supply.value; - reward *= (percent * multiply_constant); // compile-time constant, fits in 64 bits + uint128_t reward = current_supply.value; //18000000000000 + reward *= (percent * multiply_constant); // compile-time constant, fits in 64 bits //95*18000000000000*133921203762304 reward += half; // round to nearest whole integer instead of truncating - reward >>= shift_constant; + reward >>= shift_constant; //1480 return reward.to_uint64(); } +// (1+x)^REWARDS_PER_YEAR = 1.095 +// ln (1+x) * REWARDS_PER_YEAR = ln(1.095) +// ln (1+x) = ln(1.095) / REWARDS_PER_YEAR +// x = exp( ln(1.095) / REWARDS_PER_YEAR ) - 1 +// Block per year - 10512000 + + template< uint16_t percent > inline share_type calc_percent_reward_per_hour( share_type current_supply ) { return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_HOUR, MUSE_APR_PERCENT_SHIFT_PER_HOUR >( current_supply ); } +template< uint16_t percent > +inline share_type calc_percent_reward_per_block_new( share_type current_supply ) +{ + return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK_N, MUSE_APR_PERCENT_SHIFT_PER_BLOCK_N >( current_supply ); +} + template< uint16_t percent > inline share_type calc_percent_reward_per_block( share_type current_supply ) { @@ -52,4 +65,11 @@ inline share_type calc_percent_reward_per_day( share_type current_supply ) return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_DAY, MUSE_APR_PERCENT_SHIFT_PER_DAY >( current_supply ); } + +template< uint16_t percent > +inline share_type calc_percent_reward_per_day_new( share_type current_supply ) +{ + return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_DAY_N, MUSE_APR_PERCENT_SHIFT_PER_DAY_N >( current_supply ); +} + } } diff --git a/libraries/chain/include/muse/chain/config.hpp b/libraries/chain/include/muse/chain/config.hpp index c6ee8f6..4f99268 100644 --- a/libraries/chain/include/muse/chain/config.hpp +++ b/libraries/chain/include/muse/chain/config.hpp @@ -101,7 +101,7 @@ #define MUSE_MAX_ASSET_SYMBOL_LENGTH 8 #define MUSE_BLOCK_INTERVAL 3 -#define MUSE_BLOCKS_PER_YEAR (365*24*60*60/MUSE_BLOCK_INTERVAL) +#define MUSE_BLOCKS_PER_YEAR (365*24*60*60/MUSE_BLOCK_INTERVAL) //10512000 #define MUSE_BLOCKS_PER_DAY (24*60*60/MUSE_BLOCK_INTERVAL) #define MUSE_START_VESTING_BLOCK (MUSE_BLOCKS_PER_DAY * 1) #define MUSE_START_MINER_VOTING_BLOCK (MUSE_BLOCKS_PER_DAY * 1) @@ -183,6 +183,14 @@ // chosen to be the maximal value such that MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK * 2**64 * 100000 < 2**128 #define MUSE_APR_PERCENT_SHIFT_PER_BLOCK 87 +#define MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK_N ( (uint64_t( 0x1E60 ) << 0x20) \ + | (uint64_t( 0x47E3 ) << 0x10) \ + | (uint64_t( 0x17B2 ) ) \ + ) +#define MUSE_APR_PERCENT_SHIFT_PER_BLOCK_N 85 + + + #define MUSE_APR_PERCENT_MULTIPLY_PER_ROUND ( (uint64_t( 0x79cc ) << 0x20 ) \ | (uint64_t( 0xf5c7 ) << 0x10 ) \ | (uint64_t( 0x3480 ) ) \ @@ -207,11 +215,20 @@ #define MUSE_APR_PERCENT_SHIFT_PER_DAY 73 -#define MUSE_CURATE_APR_PERCENT_RESERVE 1 +#define MUSE_APR_PERCENT_MULTIPLY_PER_DAY_N (uint64_t( 0x1AB378B55670 ) ) + + +#define MUSE_APR_PERCENT_SHIFT_PER_DAY_N 70 + + +#define MUSE_CURATE_APR_PERCENT_RESERVE 10 #define MUSE_CONTENT_APR_PERCENT 712 -#define MUSE_LIQUIDITY_APR_PERCENT 0 -#define MUSE_VESTING_ARP_PERCENT 143 -#define MUSE_PRODUCER_APR_PERCENT 95 +#define MUSE_CONTENT_APR_PERCENT_N 7500 +#define MUSE_LIQUIDITY_APR_PERCENT 0 +#define MUSE_VESTING_ARP_PERCENT 143 +#define MUSE_VESTING_ARP_PERCENT_N 1500 +#define MUSE_PRODUCER_APR_PERCENT 95 +#define MUSE_PRODUCER_APR_PERCENT_N 1000 #define MUSE_CURATION_THRESHOLD1 1000 #define MUSE_CURATION_THRESHOLD2 2000 diff --git a/libraries/chain/include/muse/chain/database.hpp b/libraries/chain/include/muse/chain/database.hpp index 29639a1..3dcd31c 100644 --- a/libraries/chain/include/muse/chain/database.hpp +++ b/libraries/chain/include/muse/chain/database.hpp @@ -326,14 +326,9 @@ namespace muse { namespace chain { asset get_curation_reward()const; asset get_pow_reward()const; - uint16_t get_activity_rewards_percent() const; - uint16_t get_discussion_rewards_percent() const; - uint16_t get_curation_rewards_percent() const; + uint16_t get_curation_rewards_percent() const; - uint128_t get_content_constant_s() const; - uint128_t calculate_vshares( uint128_t rshares ) const; - - void pay_liquidity_reward(); + void pay_liquidity_reward(); //////////////////// db_getter.cpp //////////////////// diff --git a/libraries/chain/muse_evaluator.cpp b/libraries/chain/muse_evaluator.cpp index 962f200..a68f29c 100644 --- a/libraries/chain/muse_evaluator.cpp +++ b/libraries/chain/muse_evaluator.cpp @@ -341,7 +341,10 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) FC_ASSERT( itr != by_url_idx.end(), "Content does not exist" ); bool two_sides = itr->comp_meta.third_party_publishers; - FC_ASSERT( !two_sides || o.side == o.master, "Cannot edit composition side data when only one side has been defined" ); + if(db().has_hardfork(MUSE_HARDFORK_0_1)) + FC_ASSERT( two_sides || o.side == o.master, "Cannot edit composition side data when only one side has been defined" ); + else + FC_ASSERT( !two_sides || o.side == o.master, "Cannot edit composition side data when only one side has been defined" ); for( const distribution& d : o.new_distributions ) { @@ -404,10 +407,18 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) con.manage_comp.weight_threshold = o.new_threshold; } } - if( o.new_playing_reward > 0 ) - con.playing_reward = o.new_playing_reward; - if( o.new_publishers_share > 0 ) - con.playing_reward = o.new_publishers_share; + if(db().has_hardfork(MUSE_HARDFORK_0_1)) { + if( o.new_playing_reward > 0 ) + con.playing_reward = o.new_playing_reward; + if( o.new_publishers_share > 0 ) + con.publishers_share = o.new_publishers_share; + }else + { + if( o.new_playing_reward != con.playing_reward ) + con.playing_reward = o.new_playing_reward; + if( o.new_publishers_share != con.publishers_share ) + con.publishers_share = o.new_publishers_share; + } }); //TODO_MUSE - the redistribute shall affect only the respective side... delete the accumulated balance afterwards if( redistribute_master ) diff --git a/libraries/chain/protocol/operations.cpp b/libraries/chain/protocol/operations.cpp index 63ba4d6..86ad184 100644 --- a/libraries/chain/protocol/operations.cpp +++ b/libraries/chain/protocol/operations.cpp @@ -98,7 +98,6 @@ struct operation_get_required_auth template void operator()( const T& v )const { - wlog("getting authorities"); v.get_required_active_authorities( active ); v.get_required_owner_authorities( owner ); v.get_required_basic_authorities( basic ); From 2d75ec13fe236cd6f08e865e6ba6acca03acce9c Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 10 Nov 2017 15:16:04 +0100 Subject: [PATCH 14/74] Adapted reward tests to post-hf computation --- tests/tests/reward_tests.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/tests/reward_tests.cpp b/tests/tests/reward_tests.cpp index 3ac4b82..1dfa4a1 100644 --- a/tests/tests/reward_tests.cpp +++ b/tests/tests/reward_tests.cpp @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE( witness_reward_test ) int64_t expected_witness_reward = supply * .0095; int64_t avg_supply = 1.0475 * supply; - int64_t avg_witness_reward = calc_percent_reward_per_block( avg_supply ).value; + int64_t avg_witness_reward = calc_percent_reward_per_block_new( avg_supply ).value; int64_t witness_reward_per_year = avg_witness_reward * MUSE_BLOCKS_PER_YEAR; std::cerr << "Expected witness reward: " << expected_witness_reward @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE( vesting_reward_test ) int64_t expected_vesting_reward = supply * .01425; int64_t avg_supply = 1.0475 * supply; - int64_t avg_vesting_reward = calc_percent_reward_per_block( avg_supply ).value; + int64_t avg_vesting_reward = calc_percent_reward_per_block_new( avg_supply ).value; int64_t vesting_reward_per_year = avg_vesting_reward * MUSE_BLOCKS_PER_YEAR; std::cerr << "Expected vesting reward: " << expected_vesting_reward @@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE( content_reward_test ) int64_t expected_content_reward = supply * .07125; int64_t avg_supply = 1.0475 * supply; - int64_t avg_content_reward = calc_percent_reward_per_day( avg_supply ).value; + int64_t avg_content_reward = calc_percent_reward_per_day_new( avg_supply ).value; int64_t content_reward_per_year = avg_content_reward * 365; std::cerr << "Expected content reward: " << expected_content_reward From 9523dfd5039ae58e5a0c6af3bf40dad66c07d2bb Mon Sep 17 00:00:00 2001 From: g-champagne Date: Sat, 4 Nov 2017 08:43:56 -0400 Subject: [PATCH 15/74] Changed date of HF to 2017/11/14 12:00:00 AM --- libraries/chain/hardfork.d/0-1.hf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/hardfork.d/0-1.hf b/libraries/chain/hardfork.d/0-1.hf index 65a5de9..06908a6 100644 --- a/libraries/chain/hardfork.d/0-1.hf +++ b/libraries/chain/hardfork.d/0-1.hf @@ -1,6 +1,6 @@ #ifndef MUSE_HARDFORK_0_1 #define MUSE_HARDFORK_0_1 1 -// 9/23/2017 00:00:00 GMT -#define MUSE_HARDFORK_0_1_TIME 1506124800 +// Tuesday, November 14, 2017 12:00:00 AM UTC +#define MUSE_HARDFORK_0_1_TIME 1510617600 #define MUSE_HARDFORK_0_1_VERSION hardfork_version( 0, 1 ) #endif From 7bafa5b2ea8980e27bd698fab878e48bef8618ef Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 10 Nov 2017 18:55:00 +0100 Subject: [PATCH 16/74] Fixed error message --- libraries/chain/muse_evaluator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/muse_evaluator.cpp b/libraries/chain/muse_evaluator.cpp index a68f29c..e491c74 100644 --- a/libraries/chain/muse_evaluator.cpp +++ b/libraries/chain/muse_evaluator.cpp @@ -30,7 +30,7 @@ void streaming_platform_update_evaluator::do_apply( const streaming_platform_upd FC_ASSERT( o.url.size() <= MUSE_MAX_STREAMING_PLATFORM_URL_LENGTH ); - FC_ASSERT( sp_account.balance >= o.fee, "Isufficient balance to create account", ( "creator.balance", sp_account.balance )( "required", o.fee ) ); + FC_ASSERT( sp_account.balance >= o.fee, "Isufficient balance to update streaming platform: have ${c}, need ${f}", ( "c", sp_account.balance )( "f", o.fee ) ); const auto& by_streaming_platform_name_idx = db().get_index_type< streaming_platform_index >().indices().get< by_name >(); auto wit_itr = by_streaming_platform_name_idx.find( o.owner ); From 757d332a24515502eb1d3dd7390a6d04d3b352ab Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 10 Nov 2017 22:56:46 +0100 Subject: [PATCH 17/74] create_content fixes --- libraries/wallet/wallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 0785e25..7581cf4 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2296,14 +2296,13 @@ annotated_signed_transaction wallet_api::create_content(string uploader, string op.uploader = uploader; op.url = url; op.track_meta.track_title = title; + op.album_meta.album_title = title; op.distributions = distributor; op.management = management; op.management_threshold = threshold; if( playing_reward > 0 ) op.playing_reward = playing_reward; op.comp_meta.third_party_publishers = third_party_publishers; - op.album_meta.album_title = title; - op.track_meta.track_title = title; if( third_party_publishers ) { FC_ASSERT(management_publishing.size() > 0); @@ -2312,6 +2311,7 @@ annotated_signed_transaction wallet_api::create_content(string uploader, string if( distributor_publishing.size()>0 ) op.distributions_comp = distributor_publishing; } + op.publishers_share = publishers_share; signed_transaction tx; tx.operations.push_back( op ); tx.validate(); From 614e50ae992948e0cb03768ae44d5a082e12da2e Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 10 Nov 2017 22:57:32 +0100 Subject: [PATCH 18/74] Added muse tests, first part --- tests/common/database_fixture.hpp | 1 + tests/tests/muse_tests.cpp | 217 ++++++++++++++++++++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 tests/tests/muse_tests.cpp diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 24b3545..dfeb89d 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp new file mode 100644 index 0000000..355a7d9 --- /dev/null +++ b/tests/tests/muse_tests.cpp @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2017 Peertracks, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include + +#include "../common/database_fixture.hpp" + +using namespace muse::chain; +using namespace graphene::db; + +BOOST_FIXTURE_TEST_SUITE( muse_tests, clean_database_fixture ) + +#define FAIL( msg, op ) \ + BOOST_TEST_MESSAGE( "--- Test failure " # msg ); \ + tx.operations.clear(); \ + tx.operations.push_back( op ); \ + MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_signatures ), fc::assert_exception ) + +BOOST_AUTO_TEST_CASE( streamingplatform_test ) +{ + try + { + BOOST_TEST_MESSAGE( "Testing: streaming platform contract" ); + + muse::app::database_api dbapi(db); + + ACTORS( (suzy)(uhura)(paula)(martha)(colette) ); + + signed_transaction tx; + tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); + + // --------- Create streaming platform ------------ + + streaming_platform_update_operation spuo; + spuo.fee = asset( MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE, MUSE_SYMBOL ); + spuo.owner = "suzy"; + spuo.url = "http://www.google.de"; + tx.operations.push_back( spuo ); + + FAIL( "when insufficient funds for fee", spuo ); + + fund( "suzy", 10 * MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE ); + + spuo.fee = asset( 10, MUSE_SYMBOL ); + FAIL( "when fee too low", spuo ); + + spuo.fee = asset( MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE, MUSE_SYMBOL ); + spuo.owner = "x"; + FAIL( "with bad account", spuo ); + + spuo.owner = "suzy"; + spuo.url = ""; + FAIL( "without url", spuo ); + + spuo.url = "1234567890+++"; // MUSE_MAX_STREAMING_PLATFORM_URL_LENGTH + for( int i = 0; i < MUSE_MAX_STREAMING_PLATFORM_URL_LENGTH / 10; i++ ) + spuo.url += "1234567890"; + FAIL( "with too long url", spuo ); + + BOOST_TEST_MESSAGE( "--- Test success" ); + spuo.url = "http://www.google.de"; + tx.operations.clear(); + tx.operations.push_back( spuo ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + // --------- Look up streaming platforms ------------ + + set sps = dbapi.lookup_streaming_platform_accounts("x", 5); + BOOST_CHECK( sps.empty() ); + + sps = dbapi.lookup_streaming_platform_accounts("", 5); + BOOST_CHECK_EQUAL( 1, sps.size() ); + BOOST_CHECK( sps.find("suzy") != sps.end() ); + + // --------- Create content ------------ + + fund( "uhura", 1000000 ); + + content_operation cop; + cop.uploader = "uhura"; + cop.url = "ipfs://abcdef1"; + cop.album_meta.album_title = "First test song"; + cop.track_meta.track_title = "First test song"; + cop.comp_meta.third_party_publishers = false; + distribution dist; + dist.payee = "paula"; + dist.bp = MUSE_100_PERCENT; + cop.distributions.push_back( dist ); + management_vote mgmt; + mgmt.voter = "martha"; + mgmt.percentage = 100; + cop.management.push_back( mgmt ); + cop.management_threshold = 100; + cop.playing_reward = 10; + cop.publishers_share = 0; + + cop.uploader = "x"; + FAIL( "with bad account", cop ); + + cop.uploader = "uhura"; + cop.url = "http://abcdef1"; + FAIL( "with bad url protocol", cop ); + cop.url = ""; + FAIL( "with empty url", cop ); + cop.url = "ipfs://1234567890"; + for( int i = 0; i < MUSE_MAX_URL_LENGTH / 10; i++ ) + cop.url += "1234567890"; + FAIL( "with too long url", cop ); + + cop.url = "ipfs://abcdef1"; + cop.album_meta.album_title = ""; + FAIL( "with empty album title", cop ); + cop.album_meta.album_title = "Sixteen tons"; + for( int i = 0; i < 16; i++ ) + cop.album_meta.album_title += " are sixteen tons"; + FAIL( "with long album title", cop ); + + cop.album_meta.album_title = "First test song"; + cop.track_meta.track_title = ""; + FAIL( "with empty track title", cop ); + cop.track_meta.track_title = "Sixteen tons"; + for( int i = 0; i < 16; i++ ) + cop.track_meta.track_title += " are sixteen tons"; + FAIL( "with long track title", cop ); + + cop.track_meta.track_title = "First test song"; + cop.distributions.begin()->payee = "x"; + FAIL( "with invalid payee name", cop ); + cop.distributions.begin()->payee = "bob"; + FAIL( "with non-existing payee", cop ); + + cop.distributions.begin()->payee = "paula"; + cop.distributions.begin()->bp = MUSE_100_PERCENT + 1; + FAIL( "with invalid distribution", cop ); + + cop.distributions.begin()->bp = MUSE_100_PERCENT; + cop.management.begin()->voter = "x"; + FAIL( "with invalid voter name", cop ); + cop.management.begin()->voter = "bob"; + FAIL( "with non-existant voter", cop ); + + cop.management.begin()->voter = "martha"; + cop.management.begin()->percentage = 101; + FAIL( "with invalid voter percentage", cop ); + + cop.management.begin()->percentage = 100; + cop.playing_reward = MUSE_100_PERCENT + 1; + FAIL( "with invalid playing reward", cop ); + + cop.playing_reward = 10; + cop.publishers_share = MUSE_100_PERCENT + 1; + FAIL( "with invalid publisher's share", cop ); + + cop.publishers_share = 0; + BOOST_TEST_MESSAGE( "--- Test success" ); + tx.operations.clear(); + tx.operations.push_back( cop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + // --------- Publish playtime ------------ + + streaming_platform_report_operation spro; + spro.streaming_platform = "suzy"; + spro.consumer = "colette"; + spro.content = "ipfs://abcdef1"; + spro.play_time = 100; + + spro.streaming_platform = "x"; + FAIL( "with invalid platform name", spro ); + spro.streaming_platform = "bob"; + FAIL( "with non-existing platform", spro ); + + spro.streaming_platform = "suzy"; + spro.consumer = "x"; + FAIL( "with invalid consumer name", spro ); + spro.consumer = "bob"; + FAIL( "with non-existing consumer", spro ); + + spro.consumer = "colette"; + spro.content = "ipfs://no"; + FAIL( "with non-existing content", spro ); + + spro.content = "ipfs://abcdef1"; + BOOST_TEST_MESSAGE( "--- Test success" ); + tx.operations.clear(); + tx.operations.push_back( spro ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + validate_database(); + } + FC_LOG_AND_RETHROW() +} + +BOOST_AUTO_TEST_SUITE_END() From 027c4ea00cbe033d4b6e2f445ce49a32e1f07e56 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 11 Nov 2017 23:08:08 +0100 Subject: [PATCH 19/74] Expanded tests --- tests/tests/muse_tests.cpp | 282 ++++++++++++++++++++++++++++++++++++- 1 file changed, 275 insertions(+), 7 deletions(-) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 355a7d9..df3226c 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -39,21 +39,24 @@ BOOST_FIXTURE_TEST_SUITE( muse_tests, clean_database_fixture ) tx.operations.push_back( op ); \ MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_signatures ), fc::assert_exception ) -BOOST_AUTO_TEST_CASE( streamingplatform_test ) +BOOST_AUTO_TEST_CASE( simple_test ) { try { + generate_blocks( time_point_sec( MUSE_HARDFORK_0_1_TIME ) ); + BOOST_CHECK( db.has_hardfork( MUSE_HARDFORK_0_1 ) ); + BOOST_TEST_MESSAGE( "Testing: streaming platform contract" ); muse::app::database_api dbapi(db); - ACTORS( (suzy)(uhura)(paula)(martha)(colette) ); + ACTORS( (suzy)(uhura)(paula)(penny)(martha)(muriel)(colette) ); signed_transaction tx; tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); // --------- Create streaming platform ------------ - + { streaming_platform_update_operation spuo; spuo.fee = asset( MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE, MUSE_SYMBOL ); spuo.owner = "suzy"; @@ -85,20 +88,22 @@ BOOST_AUTO_TEST_CASE( streamingplatform_test ) tx.operations.clear(); tx.operations.push_back( spuo ); db.push_transaction( tx, database::skip_transaction_signatures ); - + } // --------- Look up streaming platforms ------------ - + { set sps = dbapi.lookup_streaming_platform_accounts("x", 5); BOOST_CHECK( sps.empty() ); sps = dbapi.lookup_streaming_platform_accounts("", 5); BOOST_CHECK_EQUAL( 1, sps.size() ); BOOST_CHECK( sps.find("suzy") != sps.end() ); + } + const streaming_platform_object& suzys = db.get_streaming_platform( "suzy" ); // --------- Create content ------------ fund( "uhura", 1000000 ); - + { content_operation cop; cop.uploader = "uhura"; cop.url = "ipfs://abcdef1"; @@ -179,9 +184,11 @@ BOOST_AUTO_TEST_CASE( streamingplatform_test ) tx.operations.clear(); tx.operations.push_back( cop ); db.push_transaction( tx, database::skip_transaction_signatures ); + } + const content_object& song1 = db.get_content( "ipfs://abcdef1" ); // --------- Publish playtime ------------ - + { streaming_platform_report_operation spro; spro.streaming_platform = "suzy"; spro.consumer = "colette"; @@ -208,6 +215,267 @@ BOOST_AUTO_TEST_CASE( streamingplatform_test ) tx.operations.clear(); tx.operations.push_back( spro ); db.push_transaction( tx, database::skip_transaction_signatures ); + } + // --------- Verify playtime ------------ + + BOOST_CHECK_EQUAL( 100, colette.total_listening_time ); + BOOST_CHECK_EQUAL( 1, song1.times_played ); + BOOST_CHECK_EQUAL( 1, song1.times_played_24 ); + + vector reports = dbapi.get_reports_for_account( "colette" ); + BOOST_CHECK_EQUAL( 1, reports.size() ); + BOOST_CHECK_EQUAL( suzys.id, reports[0].streaming_platform ); + BOOST_CHECK_EQUAL( colette.id, reports[0].consumer ); + BOOST_CHECK_EQUAL( song1.id, reports[0].content ); + BOOST_CHECK_EQUAL( db.head_block_time().sec_since_epoch(), reports[0].created.sec_since_epoch() ); + BOOST_CHECK_EQUAL( 100, reports[0].play_time ); + + // --------- Content update ------------ + { + content_update_operation cup; + cup.side = content_update_operation::side_t::master; + cup.url = "ipfs://abcdef1"; + + cup.side = content_update_operation::side_t::publisher; + FAIL( "of publisher update for single-sided content", cup ); + + cup.side = content_update_operation::side_t::master; + cup.url = "ipfs://no"; + FAIL( "of update for non-existant url", cup ); + + cup.url = "ipfs://abcdef1"; + cup.new_playing_reward = MUSE_100_PERCENT + 1; + FAIL( "of update with too high playing reward", cup ); + + cup.new_playing_reward = 11; + cup.new_publishers_share = MUSE_100_PERCENT + 1; + FAIL( "of update with too high publishers share", cup ); + + cup.new_publishers_share = 1; + cup.album_meta = content_metadata_album_master(); + cup.album_meta->album_title = ""; + FAIL( "with empty album title", cup ); + cup.album_meta->album_title = "Sixteen tons"; + for( int i = 0; i < 16; i++ ) + cup.album_meta->album_title += " are sixteen tons"; + FAIL( "with long album title", cup ); + + cup.album_meta->album_title = "Simple test album"; + cup.track_meta = content_metadata_track_master(); + cup.track_meta->track_title = ""; + FAIL( "with empty track title", cup ); + cup.track_meta->track_title = "Sixteen tons"; + for( int i = 0; i < 16; i++ ) + cup.track_meta->track_title += " are sixteen tons"; + FAIL( "with long track title", cup ); + + cup.track_meta->track_title = "Simple test track"; + distribution dist; + dist.payee = "penny"; + dist.bp = MUSE_100_PERCENT; + cup.new_distributions.push_back( dist ); + cup.new_distributions[0].payee = "x"; + FAIL( "with invalid payee name", cup ); + cup.new_distributions[0].payee = "bob"; + FAIL( "with non-existing payee", cup ); + + cup.new_distributions[0].payee = "penny"; + cup.new_distributions[0].bp = MUSE_100_PERCENT + 1; + FAIL( "with invalid distribution", cup ); + + cup.new_distributions[0].bp = MUSE_100_PERCENT; + management_vote mgmt; + mgmt.voter = "muriel"; + mgmt.percentage = 100; + cup.new_management.push_back( mgmt ); + cup.new_management[0].voter = "x"; + FAIL( "with invalid voter name", cup ); + cup.new_management[0].voter = "bob"; + FAIL( "with non-existant voter", cup ); + + cup.new_management[0].voter = "muriel"; + cup.new_management[0].percentage = 101; + FAIL( "with invalid voter percentage", cup ); + + cup.new_management[0].percentage = 100; + BOOST_TEST_MESSAGE( "--- Test success" ); + tx.operations.clear(); + tx.operations.push_back( cup ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + // --------- Verify update ------------ + + BOOST_CHECK_EQUAL( "Simple test album", song1.album_meta.album_title ); + BOOST_CHECK_EQUAL( "Simple test track", song1.track_meta.track_title ); + BOOST_CHECK_EQUAL( "penny", song1.distributions_master[0].payee ); + BOOST_CHECK_EQUAL( 100, song1.manage_master.account_auths.at("muriel") ); + BOOST_CHECK_EQUAL( 11, song1.playing_reward ); + BOOST_CHECK_EQUAL( 1, song1.publishers_share ); + + validate_database(); + } + FC_LOG_AND_RETHROW() +} + +BOOST_AUTO_TEST_CASE( multi_test ) +{ + try + { + generate_blocks( time_point_sec( MUSE_HARDFORK_0_1_TIME ) ); + BOOST_CHECK( db.has_hardfork( MUSE_HARDFORK_0_1 ) ); + + BOOST_TEST_MESSAGE( "Testing: streaming platform contract" ); + + muse::app::database_api dbapi(db); + + ACTORS( (suzy)(uhura)(paula)(penny)(martha)(miranda)(muriel)(colette) ); + + signed_transaction tx; + tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); + + // --------- Create streaming platform ------------ + { + fund( "suzy", 10 * MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE ); + + streaming_platform_update_operation spuo; + spuo.fee = asset( MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE, MUSE_SYMBOL ); + spuo.owner = "suzy"; + spuo.url = "http://www.google.de"; + tx.operations.clear(); + tx.operations.push_back( spuo ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + + // --------- Look up streaming platforms ------------ + +// const streaming_platform_object& suzys = db.get_streaming_platform( "suzy" ); + + // --------- Create content ------------ + + fund( "uhura", 1000000 ); + { + content_operation cop; + cop.uploader = "uhura"; + cop.url = "ipfs://abcdef9"; + cop.album_meta.album_title = "Multi test song"; + cop.track_meta.track_title = "Multi test song"; + cop.comp_meta.third_party_publishers = true; + distribution dist; + dist.payee = "paula"; + dist.bp = MUSE_100_PERCENT / 3; + cop.distributions.push_back( dist ); + dist.payee = "penny"; + dist.bp = MUSE_100_PERCENT - dist.bp; + cop.distributions.push_back( dist ); + management_vote mgmt; + mgmt.voter = "martha"; + mgmt.percentage = 34; + cop.management.push_back( mgmt ); + mgmt.voter = "miranda"; + mgmt.percentage = 33; + cop.management.push_back( mgmt ); + mgmt.voter = "muriel"; + mgmt.percentage = 33; + cop.management.push_back( mgmt ); + cop.management_threshold = 50; + cop.playing_reward = 10; + cop.publishers_share = 1000; + cop.distributions_comp = vector(); + dist.bp = MUSE_100_PERCENT; + cop.distributions_comp->push_back(dist); + cop.management_comp = vector(); + mgmt.percentage = 100; + cop.management_comp->push_back(mgmt); + cop.management_threshold_comp = 100; + + (*cop.distributions_comp)[0].payee = "x"; + FAIL( "with invalid payee name", cop ); + (*cop.distributions_comp)[0].payee = "bob"; + FAIL( "with non-existing payee", cop ); + + (*cop.distributions_comp)[0].payee = "penny"; + (*cop.distributions_comp)[0].bp++; + FAIL( "with invalid distribution", cop ); + + (*cop.distributions_comp)[0].bp--; + (*cop.management_comp)[0].voter = "x"; + FAIL( "with invalid voter name", cop ); + (*cop.management_comp)[0].voter = "bob"; + FAIL( "with non-existant voter", cop ); + + (*cop.management_comp)[0].voter = "martha"; + (*cop.management_comp)[0].percentage++; + FAIL( "with invalid voter percentage", cop ); + + (*cop.management_comp)[0].percentage--; + BOOST_TEST_MESSAGE( "--- Test success" ); + tx.operations.clear(); + tx.operations.push_back( cop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + const content_object& song1 = db.get_content( "ipfs://abcdef9" ); + BOOST_CHECK_EQUAL( 2, song1.distributions_master.size() ); + BOOST_CHECK_EQUAL( 1, song1.distributions_comp.size() ); + BOOST_CHECK_EQUAL( 3, song1.manage_master.num_auths() ); + BOOST_CHECK_EQUAL( 1, song1.manage_comp.num_auths() ); + + // --------- Publish playtime ------------ + { + streaming_platform_report_operation spro; + spro.streaming_platform = "suzy"; + spro.consumer = "colette"; + spro.content = "ipfs://abcdef9"; + spro.play_time = 100; + + BOOST_TEST_MESSAGE( "--- Test success" ); + tx.operations.clear(); + tx.operations.push_back( spro ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + + // --------- Content update ------------ + { + content_update_operation cup; + cup.side = content_update_operation::side_t::publisher; + cup.url = "ipfs://abcdef9"; + cup.new_playing_reward = 11; + cup.new_publishers_share = 1; + + cup.album_meta = content_metadata_album_master(); + cup.album_meta->album_title = "Hello World"; + FAIL( "when publisher changes album metadata", cup ); + + cup.album_meta.reset(); + cup.track_meta = content_metadata_track_master(); + cup.track_meta->track_title = "Hello World"; + FAIL( "when publisher changes track metadata", cup ); + + cup.track_meta.reset(); + distribution dist; + dist.payee = "penny"; + dist.bp = MUSE_100_PERCENT; + cup.new_distributions.push_back( dist ); + management_vote mgmt; + mgmt.voter = "muriel"; + mgmt.percentage = 100; + cup.new_management.push_back( mgmt ); + + cup.comp_meta = content_metadata_publisher(); + cup.comp_meta->third_party_publishers = false; + BOOST_TEST_MESSAGE( "--- Test success" ); + tx.operations.clear(); + tx.operations.push_back( cup ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + // --------- Verify update ------------ + + BOOST_CHECK( song1.comp_meta.third_party_publishers ); + BOOST_CHECK_EQUAL( "penny", song1.distributions_comp[0].payee ); + BOOST_CHECK_EQUAL( 1, song1.distributions_comp.size() ); + BOOST_CHECK_EQUAL( 100, song1.manage_comp.account_auths.at("muriel") ); + BOOST_CHECK_EQUAL( 1, song1.manage_comp.num_auths() ); + BOOST_CHECK_EQUAL( 11, song1.playing_reward ); + BOOST_CHECK_EQUAL( 1, song1.publishers_share ); validate_database(); } From 7a2bcdcceb75349a401e44524ee07dc5e2949fb3 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 13 Nov 2017 23:07:34 +0100 Subject: [PATCH 20/74] Added content votes + triggered content reward payouts --- tests/tests/muse_tests.cpp | 178 ++++++++++++++++++++++++++++++++++--- 1 file changed, 166 insertions(+), 12 deletions(-) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index df3226c..92c45b4 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -50,7 +50,9 @@ BOOST_AUTO_TEST_CASE( simple_test ) muse::app::database_api dbapi(db); - ACTORS( (suzy)(uhura)(paula)(penny)(martha)(muriel)(colette) ); + ACTORS( (suzy)(uhura)(paula)(penny)(martha)(muriel)(colette)(veronica)(vici) ); + + generate_block(); signed_transaction tx; tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); @@ -65,7 +67,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) FAIL( "when insufficient funds for fee", spuo ); - fund( "suzy", 10 * MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE ); + fund( "suzy", MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE ); spuo.fee = asset( 10, MUSE_SYMBOL ); FAIL( "when fee too low", spuo ); @@ -102,7 +104,6 @@ BOOST_AUTO_TEST_CASE( simple_test ) // --------- Create content ------------ - fund( "uhura", 1000000 ); { content_operation cop; cop.uploader = "uhura"; @@ -218,14 +219,14 @@ BOOST_AUTO_TEST_CASE( simple_test ) } // --------- Verify playtime ------------ - BOOST_CHECK_EQUAL( 100, colette.total_listening_time ); + BOOST_CHECK_EQUAL( 100, colette_id(db).total_listening_time ); BOOST_CHECK_EQUAL( 1, song1.times_played ); BOOST_CHECK_EQUAL( 1, song1.times_played_24 ); vector reports = dbapi.get_reports_for_account( "colette" ); BOOST_CHECK_EQUAL( 1, reports.size() ); BOOST_CHECK_EQUAL( suzys.id, reports[0].streaming_platform ); - BOOST_CHECK_EQUAL( colette.id, reports[0].consumer ); + BOOST_CHECK_EQUAL( colette_id, reports[0].consumer ); BOOST_CHECK_EQUAL( song1.id, reports[0].content ); BOOST_CHECK_EQUAL( db.head_block_time().sec_since_epoch(), reports[0].created.sec_since_epoch() ); BOOST_CHECK_EQUAL( 100, reports[0].play_time ); @@ -312,6 +313,84 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 11, song1.playing_reward ); BOOST_CHECK_EQUAL( 1, song1.publishers_share ); + // --------- Vote ------------ + { + vote_operation vop; + vop.voter = "veronica"; + vop.url = "ipfs://abcdef1"; + vop.weight = 1; + + vop.voter = "x"; + FAIL( "with bad account", vop ); + + vop.voter = "veronica"; + vop.url = "http://abcdef1"; + FAIL( "with bad url protocol", vop ); + vop.url = ""; + FAIL( "with empty url", vop ); + vop.url = "ipfs://1234567890"; + for( int i = 0; i < MUSE_MAX_URL_LENGTH / 10; i++ ) + vop.url += "1234567890"; + FAIL( "with too long url", vop ); + + vop.url = "ipfs://abcdef1"; + vop.weight = MUSE_100_PERCENT + 1; + FAIL( "with bad weight", vop ); + + vop.weight = 1; + BOOST_TEST_MESSAGE( "--- Test success" ); + tx.operations.clear(); + tx.operations.push_back( vop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + vop.voter = "vici"; + tx.operations.clear(); + tx.operations.push_back( vop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + + BOOST_CHECK_EQUAL( 0, suzy_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, penny_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, veronica_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, vici_id(db).balance.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, penny_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, veronica_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, vici_id(db).mbd_balance.amount.value ); + + BOOST_CHECK_EQUAL( 100000, suzy_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, uhura_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, paula_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, penny_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, martha_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, muriel_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, colette_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, veronica_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, vici_id(db).vesting_shares.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, penny_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); + + generate_blocks( db.head_block_time() + 86400 ); + validate_database(); } FC_LOG_AND_RETHROW() @@ -328,14 +407,16 @@ BOOST_AUTO_TEST_CASE( multi_test ) muse::app::database_api dbapi(db); - ACTORS( (suzy)(uhura)(paula)(penny)(martha)(miranda)(muriel)(colette) ); + ACTORS( (suzy)(uhura)(paula)(penny)(martha)(miranda)(muriel)(colette)(veronica)(vici) ); + + generate_block(); signed_transaction tx; tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); // --------- Create streaming platform ------------ { - fund( "suzy", 10 * MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE ); + fund( "suzy", MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE ); streaming_platform_update_operation spuo; spuo.fee = asset( MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE, MUSE_SYMBOL ); @@ -346,13 +427,8 @@ BOOST_AUTO_TEST_CASE( multi_test ) db.push_transaction( tx, database::skip_transaction_signatures ); } - // --------- Look up streaming platforms ------------ - -// const streaming_platform_object& suzys = db.get_streaming_platform( "suzy" ); - // --------- Create content ------------ - fund( "uhura", 1000000 ); { content_operation cop; cop.uploader = "uhura"; @@ -477,6 +553,84 @@ BOOST_AUTO_TEST_CASE( multi_test ) BOOST_CHECK_EQUAL( 11, song1.playing_reward ); BOOST_CHECK_EQUAL( 1, song1.publishers_share ); + // --------- Vote ------------ + { + vote_operation vop; + vop.voter = "veronica"; + vop.url = "ipfs://abcdef9"; + vop.weight = 1; + + vop.voter = "x"; + FAIL( "with bad account", vop ); + + vop.voter = "veronica"; + vop.url = "http://abcdef9"; + FAIL( "with bad url protocol", vop ); + vop.url = ""; + FAIL( "with empty url", vop ); + vop.url = "ipfs://1234567890"; + for( int i = 0; i < MUSE_MAX_URL_LENGTH / 10; i++ ) + vop.url += "1234567890"; + FAIL( "with too long url", vop ); + + vop.url = "ipfs://abcdef9"; + vop.weight = MUSE_100_PERCENT + 1; + FAIL( "with bad weight", vop ); + + vop.weight = 1; + BOOST_TEST_MESSAGE( "--- Test success" ); + tx.operations.clear(); + tx.operations.push_back( vop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + vop.voter = "vici"; + tx.operations.clear(); + tx.operations.push_back( vop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + + BOOST_CHECK_EQUAL( 0, suzy_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, penny_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, veronica_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, vici_id(db).balance.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, penny_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, veronica_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, vici_id(db).mbd_balance.amount.value ); + + BOOST_CHECK_EQUAL( 100000, suzy_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, uhura_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, paula_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, penny_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, martha_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, muriel_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, colette_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, veronica_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, vici_id(db).vesting_shares.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, penny_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); + + generate_blocks( db.head_block_time() + 86400 ); + validate_database(); } FC_LOG_AND_RETHROW() From ae51678cf1f3b418ab64a402aebc0ee7caa52e16 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 14 Nov 2017 22:33:55 +0100 Subject: [PATCH 21/74] Added checks for expected payouts --- tests/tests/muse_tests.cpp | 150 ++++++++++++++++++++++++++++++++++--- 1 file changed, 140 insertions(+), 10 deletions(-) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 92c45b4..29fb228 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -186,7 +186,6 @@ BOOST_AUTO_TEST_CASE( simple_test ) tx.operations.push_back( cop ); db.push_transaction( tx, database::skip_transaction_signatures ); } - const content_object& song1 = db.get_content( "ipfs://abcdef1" ); // --------- Publish playtime ------------ { @@ -218,7 +217,8 @@ BOOST_AUTO_TEST_CASE( simple_test ) db.push_transaction( tx, database::skip_transaction_signatures ); } // --------- Verify playtime ------------ - + { + const content_object& song1 = db.get_content( "ipfs://abcdef1" ); BOOST_CHECK_EQUAL( 100, colette_id(db).total_listening_time ); BOOST_CHECK_EQUAL( 1, song1.times_played ); BOOST_CHECK_EQUAL( 1, song1.times_played_24 ); @@ -230,7 +230,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( song1.id, reports[0].content ); BOOST_CHECK_EQUAL( db.head_block_time().sec_since_epoch(), reports[0].created.sec_since_epoch() ); BOOST_CHECK_EQUAL( 100, reports[0].play_time ); - + } // --------- Content update ------------ { content_update_operation cup; @@ -305,14 +305,15 @@ BOOST_AUTO_TEST_CASE( simple_test ) db.push_transaction( tx, database::skip_transaction_signatures ); } // --------- Verify update ------------ - + { + const content_object& song1 = db.get_content( "ipfs://abcdef1" ); BOOST_CHECK_EQUAL( "Simple test album", song1.album_meta.album_title ); BOOST_CHECK_EQUAL( "Simple test track", song1.track_meta.track_title ); BOOST_CHECK_EQUAL( "penny", song1.distributions_master[0].payee ); BOOST_CHECK_EQUAL( 100, song1.manage_master.account_auths.at("muriel") ); BOOST_CHECK_EQUAL( 11, song1.playing_reward ); BOOST_CHECK_EQUAL( 1, song1.publishers_share ); - + } // --------- Vote ------------ { vote_operation vop; @@ -389,7 +390,70 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); - generate_blocks( db.head_block_time() + 86400 ); + generate_blocks( db.head_block_time() + 86400 - MUSE_BLOCK_INTERVAL ); + + asset daily_content_reward = asset( 1863530, MUSE_SYMBOL ); //db.get_content_reward(); + + generate_block(); + + { + const auto& dgpo = db.get_dynamic_global_properties(); + asset curation_reserve = asset( daily_content_reward.amount.value / 10, MUSE_SYMBOL ); + daily_content_reward -= curation_reserve; + asset platform_reward = asset( daily_content_reward.amount.value * 11 / MUSE_100_PERCENT, MUSE_SYMBOL ); // playing reward + daily_content_reward -= platform_reward; + asset comp_reward = asset( daily_content_reward.amount.value * 1 / MUSE_100_PERCENT, MUSE_SYMBOL ); // publishers_share + asset master_reward = daily_content_reward - comp_reward; + + const content_object& song1 = db.get_content( "ipfs://abcdef1" ); + BOOST_CHECK_EQUAL( 0, song1.accumulated_balance_master.amount.value ); + BOOST_CHECK_EQUAL( comp_reward.amount.value, song1.accumulated_balance_comp.amount.value ); + BOOST_CHECK_EQUAL( comp_reward.asset_id, song1.accumulated_balance_comp.asset_id ); + BOOST_CHECK_EQUAL( master_reward.amount.value, penny_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 100000 + (platform_reward * dgpo.get_vesting_share_price()).amount.value, suzy_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( curation_reserve.amount.value / 10, veronica_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( ( curation_reserve.amount.value - curation_reserve.amount.value / 10 ) / 10, vici_id(db).balance.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); + //BOOST_CHECK_EQUAL( 0, penny_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).balance.amount.value ); + //BOOST_CHECK_EQUAL( 0, veronica_id(db).balance.amount.value ); + //BOOST_CHECK_EQUAL( 0, vici_id(db).balance.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, penny_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, veronica_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, vici_id(db).mbd_balance.amount.value ); + + //BOOST_CHECK_EQUAL( 100000, suzy_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, uhura_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, paula_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, penny_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, martha_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, muriel_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, colette_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, veronica_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, vici_id(db).vesting_shares.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, penny_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); + } validate_database(); } @@ -489,12 +553,13 @@ BOOST_AUTO_TEST_CASE( multi_test ) tx.operations.push_back( cop ); db.push_transaction( tx, database::skip_transaction_signatures ); } + { const content_object& song1 = db.get_content( "ipfs://abcdef9" ); BOOST_CHECK_EQUAL( 2, song1.distributions_master.size() ); BOOST_CHECK_EQUAL( 1, song1.distributions_comp.size() ); BOOST_CHECK_EQUAL( 3, song1.manage_master.num_auths() ); BOOST_CHECK_EQUAL( 1, song1.manage_comp.num_auths() ); - + } // --------- Publish playtime ------------ { streaming_platform_report_operation spro; @@ -544,7 +609,8 @@ BOOST_AUTO_TEST_CASE( multi_test ) db.push_transaction( tx, database::skip_transaction_signatures ); } // --------- Verify update ------------ - + { + const content_object& song1 = db.get_content( "ipfs://abcdef9" ); BOOST_CHECK( song1.comp_meta.third_party_publishers ); BOOST_CHECK_EQUAL( "penny", song1.distributions_comp[0].payee ); BOOST_CHECK_EQUAL( 1, song1.distributions_comp.size() ); @@ -552,7 +618,7 @@ BOOST_AUTO_TEST_CASE( multi_test ) BOOST_CHECK_EQUAL( 1, song1.manage_comp.num_auths() ); BOOST_CHECK_EQUAL( 11, song1.playing_reward ); BOOST_CHECK_EQUAL( 1, song1.publishers_share ); - + } // --------- Vote ------------ { vote_operation vop; @@ -629,7 +695,71 @@ BOOST_AUTO_TEST_CASE( multi_test ) BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); - generate_blocks( db.head_block_time() + 86400 ); + generate_blocks( db.head_block_time() + 86400 - MUSE_BLOCK_INTERVAL ); + + asset daily_content_reward = asset( 1863530, MUSE_SYMBOL ); //db.get_content_reward(); + + generate_block(); + + { + const auto& dgpo = db.get_dynamic_global_properties(); + asset curation_reserve = asset( daily_content_reward.amount.value / 10, MUSE_SYMBOL ); + daily_content_reward -= curation_reserve; + asset platform_reward = asset( daily_content_reward.amount.value * 11 / MUSE_100_PERCENT, MUSE_SYMBOL ); // playing reward + daily_content_reward -= platform_reward; + asset comp_reward = asset( daily_content_reward.amount.value * 1 / MUSE_100_PERCENT, MUSE_SYMBOL ); // publishers_share + asset master_reward = daily_content_reward - comp_reward; + + const content_object& song1 = db.get_content( "ipfs://abcdef9" ); + BOOST_CHECK_EQUAL( 0, song1.accumulated_balance_master.amount.value ); + BOOST_CHECK_EQUAL( 0, song1.accumulated_balance_comp.amount.value ); + BOOST_CHECK_EQUAL( master_reward.amount.value * (MUSE_100_PERCENT/3) / MUSE_100_PERCENT, paula_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( comp_reward.amount.value + master_reward.amount.value * (MUSE_100_PERCENT - MUSE_100_PERCENT/3) / MUSE_100_PERCENT, penny_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 100000 + (platform_reward * dgpo.get_vesting_share_price()).amount.value, suzy_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( curation_reserve.amount.value / 10, veronica_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( ( curation_reserve.amount.value - curation_reserve.amount.value / 10 ) / 10, vici_id(db).balance.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).balance.amount.value ); + //BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); + //BOOST_CHECK_EQUAL( 0, penny_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).balance.amount.value ); + //BOOST_CHECK_EQUAL( 0, veronica_id(db).balance.amount.value ); + //BOOST_CHECK_EQUAL( 0, vici_id(db).balance.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, penny_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, veronica_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, vici_id(db).mbd_balance.amount.value ); + + //BOOST_CHECK_EQUAL( 100000, suzy_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, uhura_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, paula_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, penny_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, martha_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, muriel_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, colette_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, veronica_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, vici_id(db).vesting_shares.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, penny_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); + } + validate_database(); } From e8660c658883eeb285b7cc1f5bfe28bda34d313e Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 16 Nov 2017 22:17:24 +0100 Subject: [PATCH 22/74] Added authority checks for content operations - need some clarifications --- tests/tests/muse_tests.cpp | 318 +++++++++++++++++++++++++++++++++++++ 1 file changed, 318 insertions(+) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 29fb228..9b5f9e9 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -760,10 +760,328 @@ BOOST_AUTO_TEST_CASE( multi_test ) BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); } + validate_database(); + } + FC_LOG_AND_RETHROW() +} + +BOOST_AUTO_TEST_CASE( simple_authority_test ) +{ + try + { + generate_blocks( time_point_sec( MUSE_HARDFORK_0_1_TIME ) ); + BOOST_CHECK( db.has_hardfork( MUSE_HARDFORK_0_1 ) ); + + BOOST_TEST_MESSAGE( "Testing: streaming platform contract authority" ); + + muse::app::database_api dbapi(db); + + ACTORS( (suzy)(uhura)(paula)(martha)(muriel)(colette) ); + + generate_block(); + + signed_transaction tx; + tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); + + // --------- Create streaming platform ------------ + { + fund( "suzy", MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE ); + streaming_platform_update_operation spuo; + spuo.fee = asset( MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE, MUSE_SYMBOL ); + spuo.owner = "suzy"; + spuo.url = "http://www.google.de"; + tx.operations.push_back( spuo ); + tx.sign( uhura_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.signatures.clear(); + tx.sign( suzy_private_key, db.get_chain_id() ); + db.push_transaction( tx, 0 ); + } + + // --------- Create content ------------ + { + content_operation cop; + cop.uploader = "uhura"; + cop.url = "ipfs://abcdef1"; + cop.album_meta.album_title = "First test song"; + cop.track_meta.track_title = "First test song"; + cop.comp_meta.third_party_publishers = false; + distribution dist; + dist.payee = "paula"; + dist.bp = MUSE_100_PERCENT; + cop.distributions.push_back( dist ); + management_vote mgmt; + mgmt.voter = "martha"; + mgmt.percentage = 100; + cop.management.push_back( mgmt ); + cop.management_threshold = 100; + cop.playing_reward = 10; + cop.publishers_share = 0; + tx.operations.clear(); + tx.operations.push_back( cop ); + tx.sign( suzy_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.signatures.clear(); + tx.sign( uhura_private_key, db.get_chain_id() ); + db.push_transaction( tx, 0 ); + } + + // --------- Publish playtime ------------ + { + streaming_platform_report_operation spro; + spro.streaming_platform = "suzy"; + spro.consumer = "colette"; + spro.content = "ipfs://abcdef1"; + spro.play_time = 100; + tx.operations.clear(); + tx.operations.push_back( spro ); + tx.sign( colette_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.signatures.clear(); + tx.sign( suzy_private_key, db.get_chain_id() ); + db.push_transaction( tx, 0 ); + } + + // --------- Content update ------------ + { + content_update_operation cup; + cup.side = content_update_operation::side_t::master; + cup.url = "ipfs://abcdef1"; + cup.new_playing_reward = 11; + cup.new_publishers_share = 1; + cup.album_meta = content_metadata_album_master(); + cup.album_meta->album_title = "Simple test album"; + cup.track_meta = content_metadata_track_master(); + cup.track_meta->track_title = "Simple test track"; + management_vote mgmt; + mgmt.voter = "muriel"; + mgmt.percentage = 100; + cup.new_management.push_back( mgmt ); + tx.operations.clear(); + tx.operations.push_back( cup ); + tx.sign( uhura_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.signatures.clear(); + tx.sign( muriel_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.signatures.clear(); + tx.sign( martha_private_key, db.get_chain_id() ); + db.push_transaction( tx, 0 ); + } + + // --------- Content removal ------------ + { + content_remove_operation cro; + cro.url = "ipfs://abcdef1"; + tx.operations.clear(); + tx.signatures.clear(); + tx.operations.push_back( cro ); + tx.sign( uhura_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.signatures.clear(); + tx.sign( martha_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.signatures.clear(); + tx.sign( muriel_private_key, db.get_chain_id() ); + db.push_transaction( tx, 0 ); + } + + // --------- Wait for payout time and verify zero payout ------------ + + generate_blocks( db.head_block_time() + 86400 - MUSE_BLOCK_INTERVAL ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).balance.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).mbd_balance.amount.value ); + + BOOST_CHECK_EQUAL( 100000, suzy_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, uhura_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, paula_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, martha_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, muriel_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, colette_id(db).vesting_shares.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).curation_rewards.value ); + + generate_block(); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).balance.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).mbd_balance.amount.value ); + + BOOST_CHECK_EQUAL( 100000, suzy_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, uhura_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, paula_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, martha_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, muriel_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, colette_id(db).vesting_shares.amount.value ); + + BOOST_CHECK_EQUAL( 0, suzy_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, uhura_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, paula_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, martha_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, muriel_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).curation_rewards.value ); validate_database(); } FC_LOG_AND_RETHROW() } +BOOST_AUTO_TEST_CASE( multi_authority_test ) +{ + try + { + generate_blocks( time_point_sec( MUSE_HARDFORK_0_1_TIME ) ); + BOOST_CHECK( db.has_hardfork( MUSE_HARDFORK_0_1 ) ); + + BOOST_TEST_MESSAGE( "Testing: streaming platform contract authority" ); + + muse::app::database_api dbapi(db); + + ACTORS( (suzy)(uhura)(paula)(martha)(miranda)(muriel)(colette) ); + + generate_block(); + + signed_transaction tx; + tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); + + // --------- Create streaming platform ------------ + { + fund( "suzy", MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE ); + streaming_platform_update_operation spuo; + spuo.fee = asset( MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE, MUSE_SYMBOL ); + spuo.owner = "suzy"; + spuo.url = "http://www.google.de"; + tx.operations.push_back( spuo ); + tx.sign( uhura_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.signatures.clear(); + tx.sign( suzy_private_key, db.get_chain_id() ); + db.push_transaction( tx, 0 ); + } + + // --------- Create content ------------ + { + content_operation cop; + cop.uploader = "uhura"; + cop.url = "ipfs://abcdef1"; + cop.album_meta.album_title = "First test song"; + cop.track_meta.track_title = "First test song"; + cop.comp_meta.third_party_publishers = true; + distribution dist; + dist.payee = "paula"; + dist.bp = MUSE_100_PERCENT; + cop.distributions.push_back( dist ); + management_vote mgmt; + mgmt.voter = "martha"; + mgmt.percentage = 34; + cop.management.push_back( mgmt ); + mgmt.voter = "miranda"; + mgmt.percentage = 33; + cop.management.push_back( mgmt ); + mgmt.voter = "muriel"; + mgmt.percentage = 33; + cop.management.push_back( mgmt ); + cop.management_threshold = 50; + cop.playing_reward = 10; + cop.publishers_share = 0; + tx.operations.clear(); + tx.signatures.clear(); + tx.operations.push_back( cop ); + tx.sign( uhura_private_key, db.get_chain_id() ); + db.push_transaction( tx, 0 ); + } + + // --------- Content update ------------ + { + content_update_operation cup; + cup.side = content_update_operation::side_t::master; + cup.url = "ipfs://abcdef1"; + cup.album_meta = content_metadata_album_master(); + cup.album_meta->album_title = "Simple test album"; + cup.track_meta = content_metadata_track_master(); + cup.track_meta->track_title = "Simple test track"; + management_vote mgmt; + mgmt.voter = "muriel"; + mgmt.percentage = 100; + cup.new_management.push_back( mgmt ); + // FIXME + mgmt.voter = "martha"; + cup.comp_meta = content_metadata_publisher(); + tx.operations.clear(); + tx.signatures.clear(); + tx.operations.push_back( cup ); + tx.sign( uhura_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.signatures.clear(); + tx.sign( muriel_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.sign( martha_private_key, db.get_chain_id() ); + db.push_transaction( tx, 0 ); + } + + // --------- Another update ------------ + { + content_update_operation cup; + cup.side = content_update_operation::side_t::publisher; + cup.url = "ipfs://abcdef1"; + tx.operations.clear(); + tx.signatures.clear(); + tx.operations.push_back( cup ); + tx.sign( muriel_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.signatures.clear(); + tx.sign( martha_private_key, db.get_chain_id() ); + db.push_transaction( tx, 0 ); + } + + // --------- Content removal ------------ + { + content_remove_operation cro; + cro.url = "ipfs://abcdef1"; + tx.operations.clear(); + tx.signatures.clear(); + tx.operations.push_back( cro ); + tx.sign( uhura_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.signatures.clear(); + tx.sign( martha_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); + tx.signatures.clear(); + tx.sign( muriel_private_key, db.get_chain_id() ); + db.push_transaction( tx, 0 ); + } + + validate_database(); + } + FC_LOG_AND_RETHROW() +} + + BOOST_AUTO_TEST_SUITE_END() From 258e2aed9b4539d57f2bc0482c00cd42d8484bdb Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 17 Nov 2017 15:42:17 +0100 Subject: [PATCH 23/74] Added price test from BTS --- tests/tests/basic_tests.cpp | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/tests/basic_tests.cpp b/tests/tests/basic_tests.cpp index fd0223d..b627921 100644 --- a/tests/tests/basic_tests.cpp +++ b/tests/tests/basic_tests.cpp @@ -105,6 +105,46 @@ BOOST_AUTO_TEST_CASE( valid_name_test ) BOOST_CHECK( !is_valid_account_name( "none.of.these.labels.has.more.than-63.chars--but.still.not.valid" ) ); } +BOOST_AUTO_TEST_CASE( price_test ) +{ + auto price_max = []( uint32_t a, uint32_t b ) + { return price::max( asset_id_type(a), asset_id_type(b) ); }; + auto price_min = []( uint32_t a, uint32_t b ) + { return price::min( asset_id_type(a), asset_id_type(b) ); }; + + BOOST_CHECK( price_max(0,1) > price_min(0,1) ); + BOOST_CHECK( price_max(1,0) > price_min(1,0) ); + BOOST_CHECK( price_max(0,1) >= price_min(0,1) ); + BOOST_CHECK( price_max(1,0) >= price_min(1,0) ); + BOOST_CHECK( price_max(0,1) >= price_max(0,1) ); + BOOST_CHECK( price_max(1,0) >= price_max(1,0) ); + BOOST_CHECK( price_min(0,1) < price_max(0,1) ); + BOOST_CHECK( price_min(1,0) < price_max(1,0) ); + BOOST_CHECK( price_min(0,1) <= price_max(0,1) ); + BOOST_CHECK( price_min(1,0) <= price_max(1,0) ); + BOOST_CHECK( price_min(0,1) <= price_min(0,1) ); + BOOST_CHECK( price_min(1,0) <= price_min(1,0) ); + BOOST_CHECK( price_min(1,0) != price_max(1,0) ); + BOOST_CHECK( ~price_max(0,1) != price_min(0,1) ); + BOOST_CHECK( ~price_min(0,1) != price_max(0,1) ); + BOOST_CHECK( ~price_max(0,1) == price_min(1,0) ); + BOOST_CHECK( ~price_min(0,1) == price_max(1,0) ); + BOOST_CHECK( ~price_max(0,1) < ~price_min(0,1) ); + BOOST_CHECK( ~price_max(0,1) <= ~price_min(0,1) ); + price a(asset(1), asset(2,asset_id_type(1))); + price b(asset(2), asset(2,asset_id_type(1))); + price c(asset(1), asset(2,asset_id_type(1))); + BOOST_CHECK(a < b); + BOOST_CHECK(b > a); + BOOST_CHECK(a == c); + BOOST_CHECK(!(b == c)); +} + +BOOST_AUTO_TEST_CASE( exceptions ) +{ + MUSE_CHECK_THROW( FC_THROW_EXCEPTION(fc::timeout_exception, "Etc"), fc::timeout_exception ); +} + BOOST_AUTO_TEST_CASE( merkle_root ) { signed_block block; From a25784622d61f84cb73abdb1361e7d7eb448954b Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 17 Nov 2017 18:59:39 +0100 Subject: [PATCH 24/74] Added initial balance claim test + database fix --- libraries/chain/database.cpp | 8 +-- tests/CMakeLists.txt | 2 +- tests/tests/muse_tests.cpp | 105 +++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 5 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 226d5de..a4dbfe8 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -2377,15 +2377,15 @@ void database::init_genesis( const genesis_state_type& initial_allocation ) } for( const genesis_state_type::initial_vesting_balance_type& vest : initial_allocation.initial_vesting_balances ) { - asset new_vesting = asset( vest.amount, VESTS_SYMBOL ); - auto to_account = get( vest.owner ); + const asset new_vesting = asset( vest.amount, VESTS_SYMBOL ); + const auto& to_account = get(vest.owner); - modify( to_account, [&]( account_object& to ) + modify( to_account, [&new_vesting]( account_object& to ) { to.vesting_shares += new_vesting; } ); - modify( gpo, [&]( dynamic_global_property_object& props ) + modify( gpo, [&new_vesting]( dynamic_global_property_object& props ) { props.total_vesting_shares += new_vesting; } ); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f3c2ef4..67ade82 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,7 +8,7 @@ endif() file(GLOB UNIT_TESTS "tests/*.cpp") add_executable( chain_test ${UNIT_TESTS} ${COMMON_SOURCES} ) -target_link_libraries( chain_test muse_chain muse_app muse_egenesis_full muse_account_history muse_market_history fc ${PLATFORM_SPECIFIC_LIBS} ) +target_link_libraries( chain_test muse_chain muse_app muse_egenesis_full muse_account_history muse_market_history graphene_utilities fc ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB PLUGIN_TESTS "plugin_tests/*.cpp") add_executable( plugin_test ${PLUGIN_TESTS} ${COMMON_SOURCES} ) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 9b5f9e9..a6ae7c2 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -26,6 +26,8 @@ #include +#include + #include "../common/database_fixture.hpp" using namespace muse::chain; @@ -1083,5 +1085,108 @@ BOOST_AUTO_TEST_CASE( multi_authority_test ) FC_LOG_AND_RETHROW() } +BOOST_AUTO_TEST_CASE( balance_object_test ) +{ try { + const auto n_key = generate_private_key("n"); + const auto x_key = generate_private_key("x"); + + // Intentionally overriding the fixture's db; I need to control genesis on this one. + database db; + fc::temp_directory td( graphene::utilities::temp_directory_path() ); + genesis_state_type genesis_state; + { + genesis_state_type::initial_balance_type balance; + balance.owner = n_key.get_public_key(); + balance.asset_symbol = MUSE_SYMBOL; + balance.amount = 1; + genesis_state.initial_balances.push_back( balance ); + balance.owner = x_key.get_public_key(); + balance.amount = 10; + genesis_state.initial_balances.push_back( balance ); + } + fc::time_point_sec starting_time = genesis_state.initial_timestamp + 3000; + + genesis_state.initial_accounts.emplace_back("nina", n_key.get_public_key()); + genesis_state.initial_accounts.emplace_back("xana", x_key.get_public_key()); + + genesis_state_type::initial_vesting_balance_type vest; + vest.owner = account_id_type( 3 + MUSE_NUM_INIT_MINERS ); + vest.asset_symbol = MUSE_SYMBOL; + vest.amount = 500; + vest.begin_balance = vest.amount; + vest.begin_timestamp = starting_time; + vest.vesting_duration_seconds = 60; + genesis_state.initial_vesting_balances.push_back(vest); + vest.owner = account_id_type( 3 + MUSE_NUM_INIT_MINERS + 1); + vest.begin_timestamp -= fc::seconds(30); + vest.amount = 400; + genesis_state.initial_vesting_balances.push_back(vest); + + auto _sign = [&]( signed_transaction& tx, const private_key_type& key ) + { tx.sign( key, db.get_chain_id() ); }; + + db.open( td.path(), genesis_state ); + const balance_object& balance = balance_id_type()(db); + BOOST_CHECK_EQUAL(1, balance.balance.amount.value); + BOOST_CHECK_EQUAL(10, balance_id_type(1)(db).balance.amount.value); + + const auto& account_n = db.get_account("nina"); + const auto& account_x = db.get_account("xana"); + ilog( "n: ${n_id}, x: ${x_id}", ("n_id",account_n.id)("x_id",account_x.id) ); + + BOOST_CHECK_EQUAL(0, account_n.balance.amount.value); + BOOST_CHECK_EQUAL(0, account_x.balance.amount.value); + BOOST_CHECK_EQUAL(0, account_n.mbd_balance.amount.value); + BOOST_CHECK_EQUAL(0, account_x.mbd_balance.amount.value); + BOOST_CHECK_EQUAL(500, account_n.vesting_shares.amount.value); + BOOST_CHECK_EQUAL(400, account_x.vesting_shares.amount.value); + + balance_claim_operation op; + op.deposit_to_account = account_n.name; + op.total_claimed = asset(1); + op.balance_to_claim = balance_id_type(1); + op.balance_owner_key = x_key.get_public_key(); + trx.operations = {op}; + _sign( trx, n_key ); + // Fail because I'm claiming from an address which hasn't signed + MUSE_CHECK_THROW(db.push_transaction(trx), tx_missing_other_auth); + trx.clear(); + op.balance_to_claim = balance_id_type(); + trx.operations = {op}; + _sign( trx, x_key ); + // Fail because I'm claiming from a wrong address + MUSE_CHECK_THROW(db.push_transaction(trx), fc::assert_exception); + trx.clear(); + op.balance_owner_key = n_key.get_public_key(); + trx.operations = {op}; + _sign( trx, x_key ); + // Fail because I'm claiming from an address which hasn't signed + MUSE_CHECK_THROW(db.push_transaction(trx), tx_missing_other_auth); + trx.clear(); + op.total_claimed = asset(2); + trx.operations = {op}; + _sign( trx, n_key ); + // Fail because I'm claiming more than available + MUSE_CHECK_THROW(db.push_transaction(trx), fc::assert_exception); + trx.clear(); + op.total_claimed = asset(1); + trx.operations = {op}; + _sign( trx, n_key ); + db.push_transaction(trx); + + BOOST_CHECK_EQUAL(account_n.balance.amount.value, 1); + BOOST_CHECK(db.find_object(balance_id_type()) == nullptr); + + op.balance_to_claim = balance_id_type(1); + op.balance_owner_key = x_key.get_public_key(); + trx.operations = {op}; + trx.signatures.clear(); + //_sign( trx, n_key ); + _sign( trx, x_key ); + db.push_transaction(trx); + + BOOST_CHECK_EQUAL(account_n.balance.amount.value, 2); + BOOST_CHECK(db.find_object(balance_id_type(1)) != nullptr); +} FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_SUITE_END() From cd0f951a1294b288a9578201b480cefc71b6aa60 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 18 Nov 2017 17:25:27 +0100 Subject: [PATCH 25/74] Moved streaming platform tests into separate function, test update too --- tests/tests/muse_tests.cpp | 74 +++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 5 deletions(-) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index a6ae7c2..c253631 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -41,18 +41,18 @@ BOOST_FIXTURE_TEST_SUITE( muse_tests, clean_database_fixture ) tx.operations.push_back( op ); \ MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_signatures ), fc::assert_exception ) -BOOST_AUTO_TEST_CASE( simple_test ) +BOOST_AUTO_TEST_CASE( streaming_platform_test ) { try { + muse::app::database_api dbapi(db); + generate_blocks( time_point_sec( MUSE_HARDFORK_0_1_TIME ) ); BOOST_CHECK( db.has_hardfork( MUSE_HARDFORK_0_1 ) ); BOOST_TEST_MESSAGE( "Testing: streaming platform contract" ); - muse::app::database_api dbapi(db); - - ACTORS( (suzy)(uhura)(paula)(penny)(martha)(muriel)(colette)(veronica)(vici) ); + ACTORS( (suzy) ); generate_block(); @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) FAIL( "when insufficient funds for fee", spuo ); - fund( "suzy", MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE ); + fund( "suzy", 2 * MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE ); spuo.fee = asset( 10, MUSE_SYMBOL ); FAIL( "when fee too low", spuo ); @@ -93,6 +93,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) tx.operations.push_back( spuo ); db.push_transaction( tx, database::skip_transaction_signatures ); } + // --------- Look up streaming platforms ------------ { set sps = dbapi.lookup_streaming_platform_accounts("x", 5); @@ -101,6 +102,69 @@ BOOST_AUTO_TEST_CASE( simple_test ) sps = dbapi.lookup_streaming_platform_accounts("", 5); BOOST_CHECK_EQUAL( 1, sps.size() ); BOOST_CHECK( sps.find("suzy") != sps.end() ); + const streaming_platform_object& suzys = db.get_streaming_platform( "suzy" ); + BOOST_CHECK_EQUAL( "suzy", suzys.owner ); + BOOST_CHECK_EQUAL( db.head_block_time().sec_since_epoch(), suzys.created.sec_since_epoch() ); + BOOST_CHECK_EQUAL( "http://www.google.de", suzys.url ); + } + + const auto creation_time = db.head_block_time(); + + generate_block(); + + const streaming_platform_object& suzys = db.get_streaming_platform( "suzy" ); + BOOST_CHECK_EQUAL( "suzy", suzys.owner ); + BOOST_CHECK_EQUAL( creation_time.sec_since_epoch(), suzys.created.sec_since_epoch() ); + BOOST_CHECK_EQUAL( "http://www.google.de", suzys.url ); + + // --------- Update streaming platform ------------ + { + streaming_platform_update_operation spuo; + spuo.fee = asset( MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE, MUSE_SYMBOL ); + spuo.owner = "suzy"; + spuo.url = "http://www.peertracks.com"; + tx.operations.clear(); + tx.operations.push_back( spuo ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + + BOOST_CHECK_EQUAL( "suzy", suzys.owner ); + BOOST_CHECK_EQUAL( creation_time.sec_since_epoch(), suzys.created.sec_since_epoch() ); + BOOST_CHECK_EQUAL( "http://www.peertracks.com", suzys.url ); + + validate_database(); + } + FC_LOG_AND_RETHROW() +} + +BOOST_AUTO_TEST_CASE( simple_test ) +{ + try + { + generate_blocks( time_point_sec( MUSE_HARDFORK_0_1_TIME ) ); + BOOST_CHECK( db.has_hardfork( MUSE_HARDFORK_0_1 ) ); + + BOOST_TEST_MESSAGE( "Testing: streaming platform contract" ); + + muse::app::database_api dbapi(db); + + ACTORS( (suzy)(uhura)(paula)(penny)(martha)(muriel)(colette)(veronica)(vici) ); + + generate_block(); + + signed_transaction tx; + tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); + + // --------- Create streaming platform ------------ + { + fund( "suzy", MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE ); + streaming_platform_update_operation spuo; + spuo.fee = asset( MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE, MUSE_SYMBOL ); + spuo.owner = "suzy"; + spuo.url = "http://www.google.de"; + tx.operations.clear(); + tx.operations.push_back( spuo ); + db.push_transaction( tx, database::skip_transaction_signatures ); } const streaming_platform_object& suzys = db.get_streaming_platform( "suzy" ); From 20f9b8cb9507f37339d97fa303f4b9ed19aa8300 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 18 Nov 2017 17:50:13 +0100 Subject: [PATCH 26/74] Added test for updating votes --- tests/tests/muse_tests.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index c253631..02fcdfc 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -414,6 +414,34 @@ BOOST_AUTO_TEST_CASE( simple_test ) tx.operations.clear(); tx.operations.push_back( vop ); db.push_transaction( tx, database::skip_transaction_signatures ); + + auto last_update = db.head_block_time(); + try + { + for( uint32_t i = 0; i < MUSE_MAX_VOTE_CHANGES + 2; i++ ) + { + generate_blocks( db.head_block_time() + MUSE_MIN_VOTE_INTERVAL_SEC + 1 ); + vop.weight++; + tx.operations.clear(); + tx.operations.push_back( vop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + last_update = db.head_block_time(); + } + } + catch( fc::assert_exception& ex ) + { + BOOST_CHECK_EQUAL( 1 + MUSE_MAX_VOTE_CHANGES + 1, vop.weight ); + } + + const content_object& song1 = db.get_content( "ipfs://abcdef1" ); + const auto& content_vote_idx = db.get_index_type< content_vote_index >().indices().get< by_content_voter >(); + const auto voted = content_vote_idx.find( std::make_tuple( song1.id, vici_id ) ); + BOOST_CHECK( voted != content_vote_idx.end() ); + BOOST_CHECK_EQUAL( vici_id, voted->voter ); + BOOST_CHECK_EQUAL( song1.id, voted->content ); + BOOST_CHECK_EQUAL( vop.weight - 1, voted->weight ); + BOOST_CHECK_EQUAL( MUSE_MAX_VOTE_CHANGES, voted->num_changes ); + BOOST_CHECK_EQUAL( last_update.sec_since_epoch(), voted->last_update.sec_since_epoch() ); } BOOST_CHECK_EQUAL( 0, suzy_id(db).balance.amount.value ); From 27f31edeb9d2f8d452d40f776a6bb70a8e205cd1 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 18 Nov 2017 21:38:50 +0100 Subject: [PATCH 27/74] Added test for content_approve --- tests/tests/muse_tests.cpp | 43 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 02fcdfc..74c80c4 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) muse::app::database_api dbapi(db); - ACTORS( (suzy)(uhura)(paula)(penny)(martha)(muriel)(colette)(veronica)(vici) ); + ACTORS( (alice)(suzy)(uhura)(paula)(penny)(martha)(muriel)(colette)(veronica)(vici) ); generate_block(); @@ -250,7 +250,38 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_TEST_MESSAGE( "--- Test success" ); tx.operations.clear(); tx.operations.push_back( cop ); - db.push_transaction( tx, database::skip_transaction_signatures ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + + // --------- Approve content ------------ + { + content_approve_operation cao; + cao.approver = "alice"; + cao.url = "ipfs://abcdef1"; + + cao.approver = "x"; + FAIL( "with bad account", cao ); + + cao.approver = "alice"; + cao.url = "http://abcdef1"; + FAIL( "with bad url protocol", cao ); + cao.url = ""; + FAIL( "with empty url", cao ); + cao.url = "ipfs://1234567890"; + for( int i = 0; i < MUSE_MAX_URL_LENGTH / 10; i++ ) + cao.url += "1234567890"; + FAIL( "with too long url", cao ); + + cao.url = "ipfs://abcdef1"; + BOOST_TEST_MESSAGE( "--- Test success" ); + tx.operations.clear(); + tx.operations.push_back( cao ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + BOOST_TEST_MESSAGE( "--- Test failure with double approval" ); + tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION - 1 ); + tx.sign( alice_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx ), fc::assert_exception ); } // --------- Publish playtime ------------ @@ -444,6 +475,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( last_update.sec_since_epoch(), voted->last_update.sec_since_epoch() ); } + BOOST_CHECK_EQUAL( 0, alice_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, suzy_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, uhura_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); @@ -454,6 +486,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 0, veronica_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, alice_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, suzy_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, uhura_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, paula_id(db).mbd_balance.amount.value ); @@ -464,6 +497,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 0, veronica_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 100000, alice_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, suzy_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, uhura_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, paula_id(db).vesting_shares.amount.value ); @@ -474,6 +508,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 100000, veronica_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, vici_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 0, alice_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, suzy_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, uhura_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, paula_id(db).curation_rewards.value ); @@ -508,6 +543,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( curation_reserve.amount.value / 10, veronica_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( ( curation_reserve.amount.value - curation_reserve.amount.value / 10 ) / 10, vici_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, alice_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, suzy_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, uhura_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); @@ -518,6 +554,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) //BOOST_CHECK_EQUAL( 0, veronica_id(db).balance.amount.value ); //BOOST_CHECK_EQUAL( 0, vici_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, alice_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, suzy_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, uhura_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, paula_id(db).mbd_balance.amount.value ); @@ -528,6 +565,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 0, veronica_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 100000, alice_id(db).vesting_shares.amount.value ); //BOOST_CHECK_EQUAL( 100000, suzy_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, uhura_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, paula_id(db).vesting_shares.amount.value ); @@ -538,6 +576,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 100000, veronica_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, vici_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 0, alice_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, suzy_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, uhura_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, paula_id(db).curation_rewards.value ); From 436de904e230cf8b27ca624b739a5464af0b704f Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 18 Nov 2017 23:11:21 +0100 Subject: [PATCH 28/74] Added test for streaming platform voting --- tests/tests/muse_tests.cpp | 50 +++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 74c80c4..0825675 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE( streaming_platform_test ) BOOST_TEST_MESSAGE( "Testing: streaming platform contract" ); - ACTORS( (suzy) ); + ACTORS( (suzy)(victoria) ); generate_block(); @@ -132,6 +132,54 @@ BOOST_AUTO_TEST_CASE( streaming_platform_test ) BOOST_CHECK_EQUAL( creation_time.sec_since_epoch(), suzys.created.sec_since_epoch() ); BOOST_CHECK_EQUAL( "http://www.peertracks.com", suzys.url ); + // --------- Vote for streaming platform ------------ + { + const account_object& vici = db.get_account( "victoria" ); + BOOST_CHECK_EQUAL( 0, vici.streaming_platforms_voted_for ); + BOOST_CHECK_EQUAL( 0, suzys.votes.value ); + + account_streaming_platform_vote_operation aspvo; + aspvo.account = "victoria"; + aspvo.streaming_platform = "suzy"; + aspvo.approve = true; + + aspvo.account = "x"; + FAIL( "with bad voting account", aspvo ); + + aspvo.account = "victoria"; + aspvo.streaming_platform = "x"; + FAIL( "with bad streaming platform", aspvo ); + + aspvo.streaming_platform = "suzy"; + aspvo.approve = false; + FAIL( "with missing approval", aspvo ); + + aspvo.approve = true; + tx.operations.clear(); + tx.operations.push_back( aspvo ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + const auto& by_account_streaming_platform_idx = db.get_index_type< streaming_platform_vote_index >().indices().get< by_account_streaming_platform >(); + auto itr = by_account_streaming_platform_idx.find( boost::make_tuple( victoria_id, suzys.get_id() ) ); + + BOOST_CHECK( itr != by_account_streaming_platform_idx.end() ); + BOOST_CHECK_EQUAL( victoria_id, itr->account ); + BOOST_CHECK_EQUAL( suzys.id, itr->streaming_platform ); + BOOST_CHECK_EQUAL( 1, vici.streaming_platforms_voted_for ); + BOOST_CHECK_EQUAL( vici.vesting_shares.amount.value, suzys.votes.value ); + + tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION - 1 ); + FAIL( "with missing disapproval", aspvo ); + + aspvo.approve = false; + tx.operations.clear(); + tx.operations.push_back( aspvo ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + BOOST_CHECK_EQUAL( 0, vici.streaming_platforms_voted_for ); + BOOST_CHECK_EQUAL( 0, suzys.votes.value ); + } + validate_database(); } FC_LOG_AND_RETHROW() From c26d8e047b3009bf5b31b45b426e50e042edccb2 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 21 Nov 2017 18:07:19 +0100 Subject: [PATCH 29/74] Added tests for friend/unfriend ops --- tests/common/database_fixture.cpp | 10 +- tests/tests/muse_tests.cpp | 316 ++++++++++++++++++++++++++++++ 2 files changed, 323 insertions(+), 3 deletions(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 1c01078..09c6ed3 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -480,9 +480,6 @@ void database_fixture::validate_database( void ) } } - fc::uint128_t total_rshares2; - fc::uint128_t total_children_rshares2; - auto gpo = db.get_dynamic_global_properties(); total_supply += gpo.total_vesting_fund_muse + gpo.total_reward_fund_muse; @@ -494,6 +491,13 @@ void database_fixture::validate_database( void ) if ( !db.get_feed_history().current_median_history.is_null() ) BOOST_REQUIRE( gpo.current_mbd_supply * db.get_feed_history().current_median_history + gpo.current_supply == gpo.virtual_supply ); + + for( auto itr = account_idx.begin(); itr != account_idx.end(); itr++ ) + { + uint64_t pre_score = itr->score; + db.recalculate_score( *itr ); + BOOST_CHECK_EQUAL( pre_score, itr->score ); + } } FC_LOG_AND_RETHROW(); } diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 0825675..fd56436 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -1366,6 +1366,322 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) BOOST_CHECK_EQUAL(account_n.balance.amount.value, 2); BOOST_CHECK(db.find_object(balance_id_type(1)) != nullptr); + + validate_database(); + } + FC_LOG_AND_RETHROW() +} + + +BOOST_AUTO_TEST_CASE( friends_test ) +{ try { + ACTORS( (alice)(brenda)(charlene)(dora)(eve) ); + + fund( "alice", 9000000 ); + fund( "brenda", 4000000 ); + fund( "charlene", 1000000 ); + fund( "dora", 810000 ); + fund( "eve", 640000 ); + + const auto& dgpo = db.get_dynamic_global_properties(); + const auto& vest_to = [&]( const string& who, const uint64_t target ) + { + const auto& acct = db.get_account( who ); + asset amount( target, VESTS_SYMBOL ); + amount = ( amount - acct.vesting_shares ) * dgpo.get_vesting_share_price(); + vest( who, amount.amount ); + + BOOST_CHECK_EQUAL( acct.vesting_shares.amount.value, target ); + }; + + vest_to( "alice", 900000000 ); + vest_to( "brenda", 400000000 ); + vest_to( "charlene", 100000000 ); + vest_to( "dora", 81000000 ); + vest_to( "eve", 64000000 ); + + signed_transaction tx; + tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); + + // --------- Make some friends ------------ + { + friendship_operation fop; + fop.who = "alice"; + fop.whom = "brenda"; + + fop.who = "x"; + FAIL( "with bad account name", fop ); + + fop.who = "bob"; + FAIL( "with non-existing account", fop ); + + fop.who = "alice"; + fop.whom = "x"; + FAIL( "with bad other account name", fop ); + + fop.whom = "bob"; + FAIL( "with non-existing other account", fop ); + + fop.whom = "brenda"; + tx.operations.clear(); + tx.operations.push_back( fop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + fop.who = "dora"; + tx.operations.clear(); + tx.operations.push_back( fop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + fop.whom = "charlene"; + tx.operations.clear(); + tx.operations.push_back( fop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + fop.whom = "eve"; + tx.operations.clear(); + tx.operations.push_back( fop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + fop.who = "alice"; + tx.operations.clear(); + tx.operations.push_back( fop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + + BOOST_CHECK( alice.waiting.empty() ); + BOOST_CHECK( brenda.waiting.find( alice_id ) != brenda.waiting.end() ); + BOOST_CHECK( brenda.waiting.find( dora_id ) != brenda.waiting.end() ); + BOOST_CHECK_EQUAL( 2, brenda.waiting.size() ); + BOOST_CHECK( charlene.waiting.find( dora_id ) != charlene.waiting.end() ); + BOOST_CHECK_EQUAL( 1, charlene.waiting.size() ); + BOOST_CHECK( dora.waiting.empty() ); + BOOST_CHECK( eve.waiting.find( dora_id ) != eve.waiting.end() ); + BOOST_CHECK( eve.waiting.find( alice_id ) != eve.waiting.end() ); + BOOST_CHECK_EQUAL( 2, eve.waiting.size() ); + + BOOST_CHECK( alice.friends.empty() ); + BOOST_CHECK( brenda.friends.empty() ); + BOOST_CHECK( charlene.friends.empty() ); + BOOST_CHECK( dora.friends.empty() ); + BOOST_CHECK( eve.friends.empty() ); + + BOOST_CHECK( alice.second_level.empty() ); + BOOST_CHECK( brenda.second_level.empty() ); + BOOST_CHECK( charlene.second_level.empty() ); + BOOST_CHECK( dora.second_level.empty() ); + BOOST_CHECK( eve.second_level.empty() ); + + { + friendship_operation fop; + fop.who = "brenda"; + fop.whom = "alice"; + tx.operations.clear(); + tx.operations.push_back( fop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + fop.whom = "dora"; + tx.operations.clear(); + tx.operations.push_back( fop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + fop.who = "charlene"; + tx.operations.clear(); + tx.operations.push_back( fop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + fop.who = "eve"; + tx.operations.clear(); + tx.operations.push_back( fop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + + BOOST_CHECK( alice.waiting.empty() ); + BOOST_CHECK( brenda.waiting.empty() ); + BOOST_CHECK( charlene.waiting.empty() ); + BOOST_CHECK( dora.waiting.empty() ); + BOOST_CHECK( eve.waiting.find( alice_id ) != eve.waiting.end() ); + BOOST_CHECK_EQUAL( 1, eve.waiting.size() ); + + BOOST_CHECK( alice.friends.find( brenda_id ) != alice.friends.end() ); + BOOST_CHECK_EQUAL( 1, alice.friends.size() ); + BOOST_CHECK( brenda.friends.find( alice_id ) != brenda.friends.end() ); + BOOST_CHECK( brenda.friends.find( dora_id ) != brenda.friends.end() ); + BOOST_CHECK_EQUAL( 2, brenda.friends.size() ); + BOOST_CHECK( charlene.friends.find( dora_id ) != charlene.friends.end() ); + BOOST_CHECK_EQUAL( 1, charlene.friends.size() ); + BOOST_CHECK( dora.friends.find( brenda_id ) != dora.friends.end() ); + BOOST_CHECK( dora.friends.find( charlene_id ) != dora.friends.end() ); + BOOST_CHECK( dora.friends.find( eve_id ) != dora.friends.end() ); + BOOST_CHECK_EQUAL( 3, dora.friends.size() ); + BOOST_CHECK( eve.friends.find( dora_id ) != eve.friends.end() ); + BOOST_CHECK_EQUAL( 1, eve.friends.size() ); + + BOOST_CHECK( alice.second_level.find( dora_id ) != alice.second_level.end() ); + BOOST_CHECK_EQUAL( 1, alice.second_level.size() ); + BOOST_CHECK( brenda.second_level.find( charlene_id ) != brenda.second_level.end() ); + BOOST_CHECK( brenda.second_level.find( eve_id ) != brenda.second_level.end() ); + BOOST_CHECK_EQUAL( 2, brenda.second_level.size() ); + BOOST_CHECK( charlene.second_level.find( brenda_id ) != charlene.second_level.end() ); + BOOST_CHECK( charlene.second_level.find( eve_id ) != charlene.second_level.end() ); + BOOST_CHECK_EQUAL( 2, charlene.second_level.size() ); + BOOST_CHECK( dora.second_level.find( alice_id ) != dora.second_level.end() ); + BOOST_CHECK_EQUAL( 1, dora.second_level.size() ); + BOOST_CHECK( eve.second_level.find( brenda_id ) != eve.second_level.end() ); + BOOST_CHECK( eve.second_level.find( charlene_id ) != eve.second_level.end() ); + BOOST_CHECK_EQUAL( 2, eve.second_level.size() ); + + BOOST_CHECK_EQUAL( 30000 + 200 * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 90 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, alice.score ); + BOOST_CHECK_EQUAL( 20000 + (300 + 90) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + (100 + 80) * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, brenda.score ); + BOOST_CHECK_EQUAL( 10000 + 90 * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + (200 + 80) * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, charlene.score ); + BOOST_CHECK_EQUAL( 9000 + (200 + 100 + 80) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 300 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, dora.score ); + BOOST_CHECK_EQUAL( 8000 + 90 * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + (200 + 100) * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, eve.score ); + + fund( "dora", 3000 ); + vest_to( "dora", 82810000 ); + + BOOST_CHECK_EQUAL( 30000 + 200 * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 91 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, alice.score ); + BOOST_CHECK_EQUAL( 20000 + (300 + 91) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + (100 + 80) * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, brenda.score ); + BOOST_CHECK_EQUAL( 10000 + 91 * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + (200 + 80) * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, charlene.score ); + BOOST_CHECK_EQUAL( 9100 + (200 + 100 + 80) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 300 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, dora.score ); + BOOST_CHECK_EQUAL( 8000 + 91 * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + (200 + 100) * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, eve.score ); + + { + friendship_operation fop; + fop.who = "eve"; + fop.whom = "alice"; + tx.operations.clear(); + tx.operations.push_back( fop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + + BOOST_CHECK( alice.waiting.empty() ); + BOOST_CHECK( brenda.waiting.empty() ); + BOOST_CHECK( charlene.waiting.empty() ); + BOOST_CHECK( dora.waiting.empty() ); + BOOST_CHECK( eve.waiting.empty() ); + + BOOST_CHECK( alice.friends.find( brenda_id ) != alice.friends.end() ); + BOOST_CHECK( alice.friends.find( eve_id ) != alice.friends.end() ); + BOOST_CHECK_EQUAL( 2, alice.friends.size() ); + BOOST_CHECK( brenda.friends.find( alice_id ) != brenda.friends.end() ); + BOOST_CHECK( brenda.friends.find( dora_id ) != brenda.friends.end() ); + BOOST_CHECK_EQUAL( 2, brenda.friends.size() ); + BOOST_CHECK( charlene.friends.find( dora_id ) != charlene.friends.end() ); + BOOST_CHECK_EQUAL( 1, charlene.friends.size() ); + BOOST_CHECK( dora.friends.find( brenda_id ) != dora.friends.end() ); + BOOST_CHECK( dora.friends.find( charlene_id ) != dora.friends.end() ); + BOOST_CHECK( dora.friends.find( eve_id ) != dora.friends.end() ); + BOOST_CHECK_EQUAL( 3, dora.friends.size() ); + BOOST_CHECK( eve.friends.find( alice_id ) != eve.friends.end() ); + BOOST_CHECK( eve.friends.find( dora_id ) != eve.friends.end() ); + BOOST_CHECK_EQUAL( 2, eve.friends.size() ); + + BOOST_CHECK( alice.second_level.find( dora_id ) != alice.second_level.end() ); + BOOST_CHECK_EQUAL( 1, alice.second_level.size() ); + BOOST_CHECK( brenda.second_level.find( charlene_id ) != brenda.second_level.end() ); + BOOST_CHECK( brenda.second_level.find( eve_id ) != brenda.second_level.end() ); + BOOST_CHECK_EQUAL( 2, brenda.second_level.size() ); + BOOST_CHECK( charlene.second_level.find( brenda_id ) != charlene.second_level.end() ); + BOOST_CHECK( charlene.second_level.find( eve_id ) != charlene.second_level.end() ); + BOOST_CHECK_EQUAL( 2, charlene.second_level.size() ); + BOOST_CHECK( dora.second_level.find( alice_id ) != dora.second_level.end() ); + BOOST_CHECK_EQUAL( 1, dora.second_level.size() ); + BOOST_CHECK( eve.second_level.find( brenda_id ) != eve.second_level.end() ); + BOOST_CHECK( eve.second_level.find( charlene_id ) != eve.second_level.end() ); + BOOST_CHECK_EQUAL( 2, eve.second_level.size() ); + + BOOST_CHECK_EQUAL( 30000 + (200 + 80) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 91 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, alice.score ); + BOOST_CHECK_EQUAL( 20000 + (300 + 91) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + (100 + 80) * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, brenda.score ); + BOOST_CHECK_EQUAL( 10000 + 91 * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + (200 + 80) * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, charlene.score ); + BOOST_CHECK_EQUAL( 9100 + (200 + 100 + 80) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 300 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, dora.score ); + BOOST_CHECK_EQUAL( 8000 + (300 + 91) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + (200 + 100) * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, eve.score ); + + // --------- Lose friends ------------ + { + unfriend_operation ufo; + ufo.who = "brenda"; + ufo.whom = "dora"; + + ufo.who = "x"; + FAIL( "with bad account name", ufo ); + + ufo.who = "bob"; + FAIL( "with non-existing account", ufo ); + + ufo.who = "brenda"; + ufo.whom = "x"; + FAIL( "with bad other account name", ufo ); + + ufo.whom = "bob"; + FAIL( "with non-existing other account", ufo ); + + ufo.whom = "dora"; + tx.operations.clear(); + tx.operations.push_back( ufo ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + + BOOST_CHECK( alice.waiting.empty() ); + BOOST_CHECK( brenda.waiting.empty() ); + BOOST_CHECK( charlene.waiting.empty() ); + BOOST_CHECK( dora.waiting.empty() ); + BOOST_CHECK( eve.waiting.empty() ); + + BOOST_CHECK( alice.friends.find( brenda_id ) != alice.friends.end() ); + BOOST_CHECK( alice.friends.find( eve_id ) != alice.friends.end() ); + BOOST_CHECK_EQUAL( 2, alice.friends.size() ); + BOOST_CHECK( brenda.friends.find( alice_id ) != brenda.friends.end() ); + BOOST_CHECK_EQUAL( 1, brenda.friends.size() ); + BOOST_CHECK( charlene.friends.find( dora_id ) != charlene.friends.end() ); + BOOST_CHECK_EQUAL( 1, charlene.friends.size() ); + BOOST_CHECK( dora.friends.find( charlene_id ) != dora.friends.end() ); + BOOST_CHECK( dora.friends.find( eve_id ) != dora.friends.end() ); + BOOST_CHECK_EQUAL( 2, dora.friends.size() ); + BOOST_CHECK( eve.friends.find( alice_id ) != eve.friends.end() ); + BOOST_CHECK( eve.friends.find( dora_id ) != eve.friends.end() ); + BOOST_CHECK_EQUAL( 2, eve.friends.size() ); + + BOOST_CHECK( alice.second_level.find( dora_id ) != alice.second_level.end() ); + BOOST_CHECK_EQUAL( 1, alice.second_level.size() ); + BOOST_CHECK( brenda.second_level.find( eve_id ) != brenda.second_level.end() ); + BOOST_CHECK_EQUAL( 1, brenda.second_level.size() ); + BOOST_CHECK( charlene.second_level.find( eve_id ) != charlene.second_level.end() ); + BOOST_CHECK_EQUAL( 1, charlene.second_level.size() ); + BOOST_CHECK( dora.second_level.find( alice_id ) != dora.second_level.end() ); + BOOST_CHECK_EQUAL( 1, dora.second_level.size() ); + BOOST_CHECK( eve.second_level.find( brenda_id ) != eve.second_level.end() ); + BOOST_CHECK( eve.second_level.find( charlene_id ) != eve.second_level.end() ); + BOOST_CHECK_EQUAL( 2, eve.second_level.size() ); + + BOOST_CHECK_EQUAL( 30000 + (200 + 80) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 91 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, alice.score ); + BOOST_CHECK_EQUAL( 20000 + 300 * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 80 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, brenda.score ); + BOOST_CHECK_EQUAL( 10000 + 91 * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 80 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, charlene.score ); + BOOST_CHECK_EQUAL( 9100 + (100 + 80) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 300 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, dora.score ); + BOOST_CHECK_EQUAL( 8000 + (300 + 91) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + (200 + 100) * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, eve.score ); + + { + withdraw_vesting_operation op; + op.account = "alice"; + op.vesting_shares = asset( 767000000, VESTS_SYMBOL ); + tx.operations.clear(); + tx.operations.push_back( op ); + tx.sign( alice_private_key, db.get_chain_id() ); + db.push_transaction( tx, 0 ); + + BOOST_CHECK_EQUAL( 59000000, alice.vesting_withdraw_rate.amount.value ); + } + + auto next_withdrawal = db.head_block_time() + MUSE_VESTING_WITHDRAW_INTERVAL_SECONDS; + generate_blocks( next_withdrawal - ( MUSE_BLOCK_INTERVAL / 2 ), true); + generate_block(); + + BOOST_CHECK_EQUAL( 29000 + (200 + 80) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 91 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, alice_id(db).score ); + BOOST_CHECK_EQUAL( 20000 + 290 * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 80 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, brenda_id(db).score ); + BOOST_CHECK_EQUAL( 10000 + 91 * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 80 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, charlene_id(db).score ); + BOOST_CHECK_EQUAL( 9100 + (100 + 80) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + 290 * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, dora_id(db).score ); + BOOST_CHECK_EQUAL( 8000 + (290 + 91) * MUSE_1ST_LEVEL_SCORING_PERCENTAGE + (200 + 100) * MUSE_2ST_LEVEL_SCORING_PERCENTAGE, eve_id(db).score ); + + validate_database(); } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_SUITE_END() From c8d7a6bd35ccea2657674e690ad081bc6e076d39 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 21 Nov 2017 22:34:56 +0100 Subject: [PATCH 30/74] Fixed asymmetric score recalculation in unfriend op --- libraries/chain/muse_evaluator.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/chain/muse_evaluator.cpp b/libraries/chain/muse_evaluator.cpp index e491c74..fb44c98 100644 --- a/libraries/chain/muse_evaluator.cpp +++ b/libraries/chain/muse_evaluator.cpp @@ -227,6 +227,7 @@ void unfriend_evaluator::do_apply( const unfriend_operation& o ) a.second_level = new_sl_list; }); db().recalculate_score(a1); + db().recalculate_score(a2); //rebuild second level lists of all friends. this is expensive for( auto aid : a1.friends ) From 543e99798a721c32998b0b975d4c9130ab8c8f90 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 21 Nov 2017 22:41:44 +0100 Subject: [PATCH 31/74] Fixed broken delta handling in score updates, plus some code smells --- libraries/chain/database.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index a4dbfe8..1b7a3c6 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -3489,22 +3489,22 @@ uint64_t database::get_scoring(const content_object& co ) const void database::recursive_recalculate_score(const account_object& a, share_type delta) { share_type old_amount = a.vesting_shares.amount - delta; - uint64_t score_delta = detail::isqrt(a.get_scoring_vesting()) - detail::isqrt(old_amount.value); + int64_t score_delta = ((int64_t) detail::isqrt(a.get_scoring_vesting())) - detail::isqrt(old_amount.value); - modify(a,[&](account_object& ao){ + modify(a,[score_delta](account_object& ao){ ao.score += score_delta; }); for( auto &f:a.friends ) { const auto& f_object = get(f); - modify(f_object,[&](account_object& ao){ + modify(f_object,[score_delta](account_object& ao){ ao.score += score_delta * MUSE_1ST_LEVEL_SCORING_PERCENTAGE / 100; }); } for( auto &f:a.second_level ) { const auto& f_object = get(f); - modify(f_object,[&](account_object& ao){ + modify(f_object,[score_delta](account_object& ao){ ao.score += score_delta * MUSE_2ST_LEVEL_SCORING_PERCENTAGE / 100; }); } From de3a0513a858990f937c7468d0c226a76d10d377 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 21 Oct 2017 20:54:11 +0200 Subject: [PATCH 32/74] Ported snapshot plugin from BTS #39f533 for testing --- libraries/plugins/snapshot/CMakeLists.txt | 17 +++ .../include/graphene/snapshot/snapshot.hpp | 56 ++++++++ libraries/plugins/snapshot/snapshot.cpp | 125 ++++++++++++++++++ programs/mused/CMakeLists.txt | 2 +- 4 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 libraries/plugins/snapshot/CMakeLists.txt create mode 100644 libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp create mode 100644 libraries/plugins/snapshot/snapshot.cpp diff --git a/libraries/plugins/snapshot/CMakeLists.txt b/libraries/plugins/snapshot/CMakeLists.txt new file mode 100644 index 0000000..251eb68 --- /dev/null +++ b/libraries/plugins/snapshot/CMakeLists.txt @@ -0,0 +1,17 @@ +file(GLOB HEADERS "include/graphene/snapshot/*.hpp") + +add_library( muse_snapshot + snapshot.cpp + ) + +target_link_libraries( muse_snapshot muse_chain muse_app ) +target_include_directories( muse_snapshot + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) + +install( TARGETS + muse_snapshot + + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) diff --git a/libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp b/libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp new file mode 100644 index 0000000..2757f77 --- /dev/null +++ b/libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 Peter Conrad, and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include +#include + +#include + +namespace muse { namespace snapshot_plugin { + +class snapshot_plugin : public muse::app::plugin { + public: + ~snapshot_plugin() {} + + std::string plugin_name()const override; + + virtual void plugin_set_program_options( + boost::program_options::options_description &command_line_options, + boost::program_options::options_description &config_file_options + ) override; + + virtual void plugin_initialize( const boost::program_options::variables_map& options ) override; + virtual void plugin_startup() override; + virtual void plugin_shutdown() override; + + private: + void check_snapshot( const muse::chain::signed_block& b); + + uint32_t snapshot_block = -1, last_block = 0; + fc::time_point_sec snapshot_time = fc::time_point_sec::maximum(), last_time = fc::time_point_sec(1); + fc::path dest; +}; + +} } //graphene::snapshot_plugin diff --git a/libraries/plugins/snapshot/snapshot.cpp b/libraries/plugins/snapshot/snapshot.cpp new file mode 100644 index 0000000..b54b7ab --- /dev/null +++ b/libraries/plugins/snapshot/snapshot.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2017 Peter Conrad, and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include + +#include + +#include + +using namespace muse::snapshot_plugin; +using std::string; +using std::vector; + +namespace bpo = boost::program_options; + +static const char* OPT_BLOCK_NUM = "snapshot-at-block"; +static const char* OPT_BLOCK_TIME = "snapshot-at-time"; +static const char* OPT_DEST = "snapshot-to"; + +void snapshot_plugin::plugin_set_program_options( + boost::program_options::options_description& command_line_options, + boost::program_options::options_description& config_file_options) +{ + command_line_options.add_options() + (OPT_BLOCK_NUM, bpo::value(), "Block number after which to do a snapshot") + (OPT_BLOCK_TIME, bpo::value(), "Block time (ISO format) after which to do a snapshot") + (OPT_DEST, bpo::value(), "Pathname of JSON file where to store the snapshot") + ; + config_file_options.add(command_line_options); +} + +std::string snapshot_plugin::plugin_name()const +{ + return "snapshot"; +} + +void snapshot_plugin::plugin_initialize(const boost::program_options::variables_map& options) +{ try { + ilog("snapshot plugin: plugin_initialize() begin"); + + if( options.count(OPT_BLOCK_NUM) || options.count(OPT_BLOCK_TIME) ) + { + FC_ASSERT( options.count(OPT_DEST), "Must specify snapshot-to in addition to snapshot-at-block or snapshot-at-time!" ); + dest = options[OPT_DEST].as(); + if( options.count(OPT_BLOCK_NUM) ) + snapshot_block = options[OPT_BLOCK_NUM].as(); + if( options.count(OPT_BLOCK_TIME) ) + snapshot_time = fc::time_point_sec::from_iso_string( options[OPT_BLOCK_TIME].as() ); + database().applied_block.connect( [&]( const muse::chain::signed_block& b ) { + check_snapshot( b ); + }); + } + else + FC_ASSERT( !options.count("snapshot-to"), "Must specify snapshot-at-block or snapshot-at-time in addition to snapshot-to!" ); + ilog("snapshot plugin: plugin_initialize() end"); +} FC_LOG_AND_RETHROW() } + +void snapshot_plugin::plugin_startup() {} + +void snapshot_plugin::plugin_shutdown() {} + +static void create_snapshot( const muse::chain::database& db, const fc::path& dest ) +{ + ilog("snapshot plugin: creating snapshot"); + fc::ofstream out; + try + { + out.open( dest ); + } + catch ( fc::exception e ) + { + wlog( "Failed to open snapshot destination: ${ex}", ("ex",e) ); + return; + } + for( uint32_t space_id = 0; space_id < 256; space_id++ ) + for( uint32_t type_id = 0; type_id < 256; type_id++ ) + { + try + { + db.get_index( (uint8_t)space_id, (uint8_t)type_id ); + } + catch (fc::assert_exception e) + { + continue; + } + auto& index = db.get_index( (uint8_t)space_id, (uint8_t)type_id ); + index.inspect_all_objects( [&out]( const graphene::db::object& o ) { + out << fc::json::to_string( o.to_variant() ) << '\n'; + }); + } + out.close(); + ilog("snapshot plugin: created snapshot"); +} + +void snapshot_plugin::check_snapshot( const muse::chain::signed_block& b ) +{ try { + uint32_t current_block = b.block_num(); + if( (last_block < snapshot_block && snapshot_block <= current_block) + || (last_time < snapshot_time && snapshot_time <= b.timestamp) ) + create_snapshot( database(), dest ); + last_block = current_block; + last_time = b.timestamp; +} FC_LOG_AND_RETHROW() } + +MUSE_DEFINE_PLUGIN( snapshot, muse::snapshot_plugin::snapshot_plugin ) diff --git a/programs/mused/CMakeLists.txt b/programs/mused/CMakeLists.txt index 243f169..dd86a55 100644 --- a/programs/mused/CMakeLists.txt +++ b/programs/mused/CMakeLists.txt @@ -10,7 +10,7 @@ if( GPERFTOOLS_FOUND ) endif() target_link_libraries( mused - PRIVATE muse_external_plugins muse_internal_plugins muse_mf_plugins muse_app muse_witness muse_account_history muse_chain muse_egenesis_full fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE muse_external_plugins muse_internal_plugins muse_mf_plugins muse_app muse_witness muse_account_history muse_chain muse_egenesis_full muse_snapshot fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) install( TARGETS mused From 23ac043d195de2063f574441bb56c6be81fcf04d Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 25 Nov 2017 17:12:37 +0100 Subject: [PATCH 33/74] Prepare for next hardfork --- libraries/chain/hardfork.d/0-2.hf | 6 ++++++ libraries/chain/hardfork.d/0-preamble.hf | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 libraries/chain/hardfork.d/0-2.hf diff --git a/libraries/chain/hardfork.d/0-2.hf b/libraries/chain/hardfork.d/0-2.hf new file mode 100644 index 0000000..5019b6d --- /dev/null +++ b/libraries/chain/hardfork.d/0-2.hf @@ -0,0 +1,6 @@ +#ifndef MUSE_HARDFORK_0_2 +#define MUSE_HARDFORK_0_2 2 +// 2020-01-01T00:00:00Z +#define MUSE_HARDFORK_0_2_TIME 1577836800 +#define MUSE_HARDFORK_0_2_VERSION hardfork_version( 0, 2 ) +#endif diff --git a/libraries/chain/hardfork.d/0-preamble.hf b/libraries/chain/hardfork.d/0-preamble.hf index f4fc851..d842cbc 100644 --- a/libraries/chain/hardfork.d/0-preamble.hf +++ b/libraries/chain/hardfork.d/0-preamble.hf @@ -33,5 +33,5 @@ FC_REFLECT_DERIVED( muse::chain::hardfork_property_object, (graphene::db::object (processed_hardforks)(last_hardfork)(current_hardfork_version) (next_hardfork)(next_hardfork_time) ) -#define MUSE_NUM_HARDFORKS 1 +#define MUSE_NUM_HARDFORKS 2 From ea6d399baa67e712aa67a92843b108a4f27760d9 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 25 Nov 2017 17:43:03 +0100 Subject: [PATCH 34/74] Prepare to remove check --- libraries/chain/database.cpp | 3 ++- libraries/chain/include/muse/chain/config.hpp | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 1b7a3c6..ef660f5 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1442,7 +1442,8 @@ void database::clear_streaming_platform_votes( const account_object& a ) void database::update_owner_authority( const account_object& account, const authority& owner_authority ) { - if( head_block_num() >= MUSE_OWNER_AUTH_HISTORY_TRACKING_START_BLOCK_NUM ) + if( head_block_num() >= 3186477 // remove check after this block has passed + || has_hardfork(MUSE_HARDFORK_0_2) ) { create< owner_authority_history_object >( [&]( owner_authority_history_object& hist ) { diff --git a/libraries/chain/include/muse/chain/config.hpp b/libraries/chain/include/muse/chain/config.hpp index fcaa77a..ba028b9 100644 --- a/libraries/chain/include/muse/chain/config.hpp +++ b/libraries/chain/include/muse/chain/config.hpp @@ -93,7 +93,6 @@ #define MUSE_OWNER_AUTH_RECOVERY_PERIOD fc::days(30) #define MUSE_ACCOUNT_RECOVERY_REQUEST_EXPIRATION_PERIOD fc::days(1) #define MUSE_OWNER_UPDATE_LIMIT fc::minutes(60) -#define MUSE_OWNER_AUTH_HISTORY_TRACKING_START_BLOCK_NUM 3186477 #endif From edfc499575d8e960bb3275c0da6afdb8ae704364 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 25 Nov 2017 18:53:23 +0100 Subject: [PATCH 35/74] Fixed test timing --- tests/tests/operation_tests.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 7b7dff4..4eb798c 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -3001,6 +3001,8 @@ BOOST_AUTO_TEST_CASE( account_recovery ) { BOOST_TEST_MESSAGE( "Testing: account recovery" ); + generate_blocks( fc::time_point_sec(MUSE_HARDFORK_0_2_TIME) ); + ACTORS( (alice) ); fund( "alice", 1000000000 ); @@ -3023,13 +3025,17 @@ BOOST_AUTO_TEST_CASE( account_recovery ) tx.sign( alice_private_key, db.get_chain_id() ); db.push_transaction( tx, 0 ); + account_update_operation acc_update; + request_account_recovery_operation request; + recover_account_operation recover; + + { const auto& bob = db.get_account( "bob" ); BOOST_REQUIRE( bob.owner == acc_create.owner ); BOOST_TEST_MESSAGE( "Changing bob's owner authority" ); - account_update_operation acc_update; acc_update.account = "bob"; acc_update.owner = authority( 1, generate_private_key( "bad_key" ).get_public_key(), 1 ); acc_update.memo_key = acc_create.memo_key; @@ -3047,7 +3053,6 @@ BOOST_AUTO_TEST_CASE( account_recovery ) BOOST_TEST_MESSAGE( "Creating recover request for bob with alice" ); - request_account_recovery_operation request; request.recovery_account = "alice"; request.account_to_recover = "bob"; request.new_owner_authority = authority( 1, generate_private_key( "new_key" ).get_public_key(), 1 ); @@ -3064,7 +3069,6 @@ BOOST_AUTO_TEST_CASE( account_recovery ) BOOST_TEST_MESSAGE( "Recovering bob's account with original owner auth and new secret" ); - recover_account_operation recover; recover.account_to_recover = "bob"; recover.new_owner_authority = request.new_owner_authority; recover.recent_owner_authority = acc_create.owner; @@ -3090,8 +3094,13 @@ BOOST_AUTO_TEST_CASE( account_recovery ) tx.operations.push_back( request ); tx.sign( alice_private_key, db.get_chain_id() ); db.push_transaction( tx, 0 ); + } + generate_blocks( db.head_block_time() + MUSE_OWNER_UPDATE_LIMIT + fc::seconds(MUSE_BLOCK_INTERVAL) ); + tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); + { + const auto& bob = db.get_account( "bob" ); BOOST_TEST_MESSAGE( "Testing failure when bob does not have new authority" ); recover.new_owner_authority = authority( 1, generate_private_key( "idontknow" ).get_public_key(), 1 ); @@ -3158,6 +3167,7 @@ BOOST_AUTO_TEST_CASE( account_recovery ) BOOST_REQUIRE( req_itr == request_idx.end() ); generate_blocks( time_point_sec( expires - MUSE_BLOCK_INTERVAL ), true ); + } const auto& new_request_idx = db.get_index_type< account_recovery_request_index >().indices(); BOOST_REQUIRE( new_request_idx.begin() != new_request_idx.end() ); @@ -3218,6 +3228,8 @@ BOOST_AUTO_TEST_CASE( account_recovery ) MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); BOOST_REQUIRE( db.get_account( "bob" ).owner == authority( 1, generate_private_key( "new_key" ).get_public_key(), 1 ) ); + generate_blocks( db.head_block_time() + MUSE_OWNER_UPDATE_LIMIT + fc::seconds(MUSE_BLOCK_INTERVAL) ); + recover.recent_owner_authority = authority( 1, generate_private_key( "foo bar" ).get_public_key(), 1 ); tx.operations.clear(); From 7b4b31342a3d40de61f9fe7c53e095d740dcf5f7 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 25 Nov 2017 18:18:28 +0100 Subject: [PATCH 36/74] Turned content_remove into content_disable --- libraries/chain/database.cpp | 2 +- .../include/muse/chain/base_evaluator.hpp | 2 +- .../include/muse/chain/content_object.hpp | 5 ++- .../muse/chain/protocol/muse_operations.hpp | 6 ++-- .../muse/chain/protocol/operations.hpp | 2 +- libraries/chain/muse_evaluator.cpp | 34 +++++++++---------- libraries/chain/protocol/muse_operations.cpp | 2 +- tests/tests/muse_tests.cpp | 4 +-- 8 files changed, 30 insertions(+), 27 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 1b7a3c6..09a08d5 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -2110,7 +2110,7 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); - register_evaluator(); + register_evaluator(); register_evaluator(); register_evaluator(); diff --git a/libraries/chain/include/muse/chain/base_evaluator.hpp b/libraries/chain/include/muse/chain/base_evaluator.hpp index 7edc46e..78f330a 100644 --- a/libraries/chain/include/muse/chain/base_evaluator.hpp +++ b/libraries/chain/include/muse/chain/base_evaluator.hpp @@ -32,7 +32,7 @@ DEFINE_EVALUATOR( withdraw_vesting ) DEFINE_EVALUATOR( set_withdraw_vesting_route ) DEFINE_EVALUATOR( content ) DEFINE_EVALUATOR( content_update ) -DEFINE_EVALUATOR( content_remove ) +DEFINE_EVALUATOR( content_disable ) DEFINE_EVALUATOR( content_approve ) DEFINE_EVALUATOR( vote ) DEFINE_EVALUATOR( custom ) diff --git a/libraries/chain/include/muse/chain/content_object.hpp b/libraries/chain/include/muse/chain/content_object.hpp index d249393..f0e44a4 100644 --- a/libraries/chain/include/muse/chain/content_object.hpp +++ b/libraries/chain/include/muse/chain/content_object.hpp @@ -65,7 +65,10 @@ namespace muse { namespace chain { bool curation_rewards=true; time_point_sec curation_reward_expiration; - bool allow_votes = true; /// allows a post to receive votes; + bool allow_votes = true; /// allows a post to receive votes; + + bool disabled = false; + friend bool operator<(const content_object& a, const content_object& b) { return a.id& a )const{ a.insert(url); } + void get_required_master_content_authorities( flat_set& a )const{ a.insert(url); } }; /** @@ -374,7 +374,7 @@ FC_REFLECT( muse::chain::content_operation, (uploader)(url)(album_meta)(track_me (playing_reward)(publishers_share) ) FC_REFLECT( muse::chain::content_update_operation, (url)(side)(album_meta)(track_meta)(comp_meta)(new_distributions)(new_management)(new_threshold)(new_playing_reward)(new_publishers_share) ) FC_REFLECT( muse::chain::content_approve_operation, (approver)(url) ) -FC_REFLECT( muse::chain::content_remove_operation, (url) ) +FC_REFLECT( muse::chain::content_disable_operation, (url) ) FC_REFLECT( muse::chain::friendship_operation, (who)(whom) ) FC_REFLECT( muse::chain::unfriend_operation, (who)(whom) ) FC_REFLECT( muse::chain::content_reward_operation, (payee)(url)(mbd_payout)(vesting_payout) ) diff --git a/libraries/chain/include/muse/chain/protocol/operations.hpp b/libraries/chain/include/muse/chain/protocol/operations.hpp index 11c1c75..48613c2 100644 --- a/libraries/chain/include/muse/chain/protocol/operations.hpp +++ b/libraries/chain/include/muse/chain/protocol/operations.hpp @@ -15,7 +15,7 @@ namespace muse { namespace chain { content_operation, content_update_operation, content_approve_operation, - content_remove_operation, + content_disable_operation, transfer_operation, transfer_to_vesting_operation, diff --git a/libraries/chain/muse_evaluator.cpp b/libraries/chain/muse_evaluator.cpp index fb44c98..47cb9a9 100644 --- a/libraries/chain/muse_evaluator.cpp +++ b/libraries/chain/muse_evaluator.cpp @@ -66,6 +66,7 @@ void streaming_platform_report_evaluator::do_apply ( const streaming_platform_re FC_ASSERT ( db().is_voted_streaming_platform( o.streaming_platform )); const auto& content = db().get_content( o.content ); + FC_ASSERT( !content.disabled ); db().create< report_object>( [&](report_object& ro) { ro.consumer = consumer.id; @@ -336,11 +337,10 @@ void content_evaluator::do_apply( const content_operation& o ) void content_update_evaluator::do_apply( const content_update_operation& o ) { try { + const auto& content = db().get_content( o.url ); + FC_ASSERT( !content.disabled ); + const content_object* itr = &content; - const auto& by_url_idx = db().get_index_type< content_index >().indices().get< by_url >(); - auto itr = by_url_idx.find( o.url ); - - FC_ASSERT( itr != by_url_idx.end(), "Content does not exist" ); bool two_sides = itr->comp_meta.third_party_publishers; if(db().has_hardfork(MUSE_HARDFORK_0_1)) FC_ASSERT( two_sides || o.side == o.master, "Cannot edit composition side data when only one side has been defined" ); @@ -428,31 +428,30 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) db().pay_to_content(itr->id, accumulated_balances, muse::chain::streaming_platform_id_type()); } FC_CAPTURE_AND_RETHROW( (o) ) } -void content_remove_evaluator::do_apply( const content_remove_operation& o ) +void content_disable_evaluator::do_apply( const content_disable_operation& o ) { try{ - const auto& by_url_idx = db().get_index_type< content_index >().indices().get< by_url >(); - auto itr = by_url_idx.find( o.url ); + FC_ASSERT( db().has_hardfork( MUSE_HARDFORK_0_2 ) ); // remove after HF time - FC_ASSERT( itr != by_url_idx.end(), "Content does not exist" ); + const auto& content = db().get_content( o.url ); - //FC_ASSERT( o.force || itr->accumulated_balance_master.amount == share_type(0), "There is still accumulated balance associated to the object"); + FC_ASSERT( !content.disabled ); - db().remove( *itr ); + db().modify( content, []( content_object& co ) { + co.disabled = true; + }); - } FC_CAPTURE_AND_RETHROW( (o) ) } +} FC_CAPTURE_AND_RETHROW( (o) ) } void content_approve_evaluator::do_apply( const content_approve_operation& o ) {try{ - const auto& by_url_idx = db().get_index_type< content_index >().indices().get< by_url >(); - auto itr = by_url_idx.find( o.url ); - - FC_ASSERT( itr != by_url_idx.end(), "Content does not exist" ); + const auto& content = db().get_content( o.url ); + FC_ASSERT( !content.disabled ); const auto& appr = db().get_account( o.approver ); - db().create ( [&](content_approve_object& con){ + db().create ( [&appr,&o](content_approve_object& con){ con.approver=appr.id; - con.content=itr->url; + con.content=o.url; }); } FC_CAPTURE_AND_RETHROW( (o) ) } @@ -504,6 +503,7 @@ void vote_evaluator::do_apply( const vote_operation& o ) if( o.url.length() > 0 ) //vote for content { const auto&content = db().get_content( o.url ); + FC_ASSERT( !content.disabled ); if( o.weight > 0 ) FC_ASSERT( content.allow_votes ); const auto& content_vote_idx = db().get_index_type< content_vote_index >().indices().get< by_content_voter >(); auto itr = content_vote_idx.find( std::make_tuple( content.id, voter.id ) ); diff --git a/libraries/chain/protocol/muse_operations.cpp b/libraries/chain/protocol/muse_operations.cpp index 1e0672a..23f8696 100644 --- a/libraries/chain/protocol/muse_operations.cpp +++ b/libraries/chain/protocol/muse_operations.cpp @@ -128,7 +128,7 @@ void content_update_operation::validate() const { } -void content_remove_operation::validate() const { +void content_disable_operation::validate() const { validate_url(url); } diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index fd56436..ed41942 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -1052,7 +1052,7 @@ BOOST_AUTO_TEST_CASE( simple_authority_test ) // --------- Content removal ------------ { - content_remove_operation cro; + content_disable_operation cro; cro.url = "ipfs://abcdef1"; tx.operations.clear(); tx.signatures.clear(); @@ -1244,7 +1244,7 @@ BOOST_AUTO_TEST_CASE( multi_authority_test ) // --------- Content removal ------------ { - content_remove_operation cro; + content_disable_operation cro; cro.url = "ipfs://abcdef1"; tx.operations.clear(); tx.signatures.clear(); From 148aa8cb81fbb2907d3189f08af4008b8714fa8c Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 26 Nov 2017 16:15:13 +0100 Subject: [PATCH 37/74] Added test case for disabling content --- tests/tests/muse_tests.cpp | 118 +++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index ed41942..030d4fd 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -1684,4 +1684,122 @@ BOOST_AUTO_TEST_CASE( friends_test ) validate_database(); } FC_LOG_AND_RETHROW() } +BOOST_AUTO_TEST_CASE( disable_test ) +{ try { + generate_blocks( time_point_sec( MUSE_HARDFORK_0_1_TIME ) ); + BOOST_CHECK( db.has_hardfork( MUSE_HARDFORK_0_1 ) ); + + BOOST_TEST_MESSAGE( "Testing: streaming platform contract disable" ); + + ACTORS( (alice)(suzy)(uhura)(paula)(martha)(colette)(veronica) ); + + generate_block(); + + signed_transaction tx; + tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION ); + + // --------- Create streaming platform ------------ + { + fund( "suzy", MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE ); + streaming_platform_update_operation spuo; + spuo.fee = asset( MUSE_MIN_STREAMING_PLATFORM_CREATION_FEE, MUSE_SYMBOL ); + spuo.owner = "suzy"; + spuo.url = "http://www.google.de"; + tx.operations.clear(); + tx.operations.push_back( spuo ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + const streaming_platform_object& suzys = db.get_streaming_platform( "suzy" ); + + // --------- Create content ------------ + { + content_operation cop; + cop.uploader = "uhura"; + cop.url = "ipfs://abcdef1"; + cop.album_meta.album_title = "First test song"; + cop.track_meta.track_title = "First test song"; + cop.comp_meta.third_party_publishers = false; + distribution dist; + dist.payee = "paula"; + dist.bp = MUSE_100_PERCENT; + cop.distributions.push_back( dist ); + management_vote mgmt; + mgmt.voter = "martha"; + mgmt.percentage = 100; + cop.management.push_back( mgmt ); + cop.management_threshold = 100; + cop.playing_reward = 10; + cop.publishers_share = 0; + tx.operations.clear(); + tx.operations.push_back( cop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + + // --------- Publish playtime ------------ + { + streaming_platform_report_operation spro; + spro.streaming_platform = "suzy"; + spro.consumer = "colette"; + spro.content = "ipfs://abcdef1"; + spro.play_time = 100; + tx.operations.clear(); + tx.operations.push_back( spro ); + db.push_transaction( tx, database::skip_transaction_signatures ); + } + + // --------- Content removal ------------ + { + content_disable_operation cro; + cro.url = "ipfs://abcdef1"; + + cro.url = "http://abcdef1"; + FAIL( "with bad url protocol", cro ); + cro.url = ""; + FAIL( "with empty url", cro ); + cro.url = "ipfs://1234567890"; + for( int i = 0; i < MUSE_MAX_URL_LENGTH / 10; i++ ) + cro.url += "1234567890"; + FAIL( "with too long url", cro ); + + cro.url = "ipfs://abcdef1"; + tx.operations.clear(); + tx.operations.push_back( cro ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + tx.set_expiration( db.head_block_time() + MUSE_MAX_TIME_UNTIL_EXPIRATION - 1 ); + FAIL( "double disable", cro ); + } + + // --------- Approve content ------------ + { + content_approve_operation cao; + cao.approver = "alice"; + cao.url = "ipfs://abcdef1"; + FAIL( "approve after disable", cao ); + } + + // --------- Content update ------------ + { + content_update_operation cup; + cup.side = content_update_operation::side_t::master; + cup.url = "ipfs://abcdef1"; + cup.new_publishers_share = 1; + cup.album_meta = content_metadata_album_master(); + cup.album_meta->album_title = "Simple test album"; + cup.track_meta = content_metadata_track_master(); + cup.track_meta->track_title = "Simple test track"; + FAIL( "update after disable", cup ); + } + + // --------- Vote ------------ + { + vote_operation vop; + vop.voter = "veronica"; + vop.url = "ipfs://abcdef1"; + vop.weight = 1; + FAIL( "vote after disable", vop ); + } + +} FC_LOG_AND_RETHROW() } + BOOST_AUTO_TEST_SUITE_END() From c9ee99bd730375e828c56338ca94e7cd6f17816b Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 26 Nov 2017 23:40:39 +0100 Subject: [PATCH 38/74] Fixed hardfork_versions initialization --- libraries/chain/database.cpp | 9 +++++++++ libraries/chain/include/muse/chain/config.hpp | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 1b7a3c6..d3c2dec 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -3221,6 +3221,13 @@ void database::init_hardforks() { _hardfork_times[ 0 ] = fc::time_point_sec( MUSE_GENESIS_TIME ); _hardfork_versions[ 0 ] = hardfork_version( 0, 0 ); + FC_ASSERT( MUSE_HARDFORK_0_1 == 1, "Invalid hardfork configuration" ); + _hardfork_times[ MUSE_HARDFORK_0_1 ] = fc::time_point_sec( MUSE_HARDFORK_0_1_TIME ); + _hardfork_versions[ MUSE_HARDFORK_0_1 ] = MUSE_HARDFORK_0_1_VERSION; + FC_ASSERT( MUSE_HARDFORK_0_2 == 2, "Invalid hardfork configuration" ); + _hardfork_times[ MUSE_HARDFORK_0_2 ] = fc::time_point_sec( MUSE_HARDFORK_0_2_TIME ); + _hardfork_versions[ MUSE_HARDFORK_0_2 ] = MUSE_HARDFORK_0_2_VERSION; + const auto& hardforks = hardfork_property_id_type()( *this ); FC_ASSERT( hardforks.last_hardfork <= MUSE_NUM_HARDFORKS, "Chain knows of more hardforks than configuration", ("hardforks.last_hardfork",hardforks.last_hardfork)("MUSE_NUM_HARDFORKS",MUSE_NUM_HARDFORKS) ); FC_ASSERT( _hardfork_versions[ hardforks.last_hardfork ] <= MUSE_BLOCKCHAIN_VERSION, "Blockchain version is older than last applied hardfork" ); @@ -3290,6 +3297,8 @@ void database::set_hardfork( uint32_t hardfork, bool apply_now ) void database::apply_hardfork( uint32_t hardfork ) { + ilog("Applying hardfork ${i} at #${n} / ${t}", ("i",hardfork)("n",head_block_num())("t",head_block_time()) ); + switch( hardfork ) { default: diff --git a/libraries/chain/include/muse/chain/config.hpp b/libraries/chain/include/muse/chain/config.hpp index fcaa77a..a4a2ed1 100644 --- a/libraries/chain/include/muse/chain/config.hpp +++ b/libraries/chain/include/muse/chain/config.hpp @@ -3,7 +3,7 @@ */ #pragma once -#define MUSE_BLOCKCHAIN_VERSION ( version(0, 0, 1) ) +#define MUSE_BLOCKCHAIN_VERSION ( version(0, 2, 0) ) #define MUSE_BLOCKCHAIN_HARDFORK_VERSION ( hardfork_version( MUSE_BLOCKCHAIN_VERSION ) ) #ifdef IS_TEST_NET // This is the muse test net mode. Some feature may behave differently From 67254b808196f0e330c9e3bb2ff9fc1a92b24c11 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 26 Nov 2017 23:41:16 +0100 Subject: [PATCH 39/74] Made block_tests work --- libraries/chain/database.cpp | 17 ++++++++++++++++- tests/tests/block_tests.cpp | 17 ++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index d3c2dec..eeb99a6 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -3301,7 +3301,22 @@ void database::apply_hardfork( uint32_t hardfork ) switch( hardfork ) { - default: + case MUSE_HARDFORK_0_1: + { + // This is for unit tests only. Evil. + const auto& initminer = get_account( MUSE_INIT_MINER_NAME ); + if ( initminer.balance.amount.value >= 10 * asset::static_precision() ) + { + custom_operation test_op; + string op_msg = "Test: Hardfork applied"; + test_op.data = vector< char >( op_msg.begin(), op_msg.end() ); + test_op.required_auths.insert( MUSE_INIT_MINER_NAME ); + push_applied_operation( test_op ); + } + } + break; + + default: break; } diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index c15bf05..4afc4b3 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -790,7 +790,6 @@ BOOST_FIXTURE_TEST_CASE( skip_block, clean_database_fixture ) FC_LOG_AND_RETHROW(); } -#ifdef MUSE_HARDFORK_0_1 BOOST_FIXTURE_TEST_CASE( hardfork_test, database_fixture ) { try @@ -814,6 +813,17 @@ BOOST_FIXTURE_TEST_CASE( hardfork_test, database_fixture ) open_database(); + { + const account_object& init_acct = db.get_account( MUSE_INIT_MINER_NAME ); + db.modify( init_acct, [&]( account_object& acct ) { + acct.active.add_authority( init_account_pub_key, acct.active.weight_threshold ); + }); + const witness_object& init_witness = db.get_witness( MUSE_INIT_MINER_NAME ); + db.modify( init_witness, [&]( witness_object& witness ) { + witness.signing_key = init_account_pub_key; + }); + } + // app.initialize(); ahplugin->plugin_set_app( &app ); ahplugin->plugin_initialize( options ); @@ -829,6 +839,8 @@ BOOST_FIXTURE_TEST_CASE( hardfork_test, database_fixture ) witness_create( MUSE_INIT_MINER_NAME + fc::to_string( i ), init_account_priv_key, "foo.bar", init_account_pub_key, MUSE_MIN_PRODUCER_REWARD.amount ); } + generate_blocks( 2 * MUSE_MAX_MINERS ); + validate_database(); } catch ( const fc::exception& e ) { @@ -849,7 +861,7 @@ BOOST_FIXTURE_TEST_CASE( hardfork_test, database_fixture ) BOOST_TEST_MESSAGE( "Generate a block and check hardfork is applied" ); generate_block(); - string op_msg = "Testnet: Hardfork applied"; + string op_msg = "Test: Hardfork applied"; auto itr = db.get_index_type< account_history_index >().indices().get< by_id >().end(); itr--; @@ -871,6 +883,5 @@ BOOST_FIXTURE_TEST_CASE( hardfork_test, database_fixture ) } FC_LOG_AND_RETHROW() } -#endif BOOST_AUTO_TEST_SUITE_END() From 21fb9c63c433884ea08a797b6be90dd8d174a302 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 6 Dec 2017 21:35:21 +0100 Subject: [PATCH 40/74] Fixed wrong amount in fill_vesting_withdraw virtual op --- libraries/chain/database.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 1b7a3c6..1b24d98 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1578,7 +1578,7 @@ void database::process_vesting_withdrawals() recursive_recalculate_score(from_account, -to_withdraw); } - push_applied_operation( fill_vesting_withdraw_operation( from_account.name, from_account.name, asset( to_withdraw, VESTS_SYMBOL ), converted_muse ) ); + push_applied_operation( fill_vesting_withdraw_operation( from_account.name, from_account.name, asset( to_convert, VESTS_SYMBOL ), converted_muse ) ); } } From 535e481fd9abd7f5b5115dfd3eb5635fa03f9eac Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 7 Dec 2017 18:41:29 +0100 Subject: [PATCH 41/74] Added test for issue #24 --- tests/tests/muse_tests.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 030d4fd..fdf3dcd 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -443,6 +443,9 @@ BOOST_AUTO_TEST_CASE( simple_test ) cup.new_management[0].percentage = 101; FAIL( "with invalid voter percentage", cup ); + cup.comp_meta = content_metadata_publisher(); + cup.comp_meta->third_party_publishers = true; + cup.new_management[0].percentage = 100; BOOST_TEST_MESSAGE( "--- Test success" ); tx.operations.clear(); @@ -452,6 +455,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) // --------- Verify update ------------ { const content_object& song1 = db.get_content( "ipfs://abcdef1" ); + BOOST_CHECK( ! song1.comp_meta.third_party_publishers ); BOOST_CHECK_EQUAL( "Simple test album", song1.album_meta.album_title ); BOOST_CHECK_EQUAL( "Simple test track", song1.track_meta.track_title ); BOOST_CHECK_EQUAL( "penny", song1.distributions_master[0].payee ); From b59f0506d1919f359a39b983cb3b6fe3ee7690e6 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 7 Dec 2017 18:55:05 +0100 Subject: [PATCH 42/74] Fixed issue #24 --- libraries/chain/muse_evaluator.cpp | 18 ++++++++++-------- tests/tests/muse_tests.cpp | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libraries/chain/muse_evaluator.cpp b/libraries/chain/muse_evaluator.cpp index 47cb9a9..d3cd97c 100644 --- a/libraries/chain/muse_evaluator.cpp +++ b/libraries/chain/muse_evaluator.cpp @@ -362,9 +362,10 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) bool redistribute_comp = ( o.side == o.publisher && o.new_distributions.size() > 0 && itr->distributions_comp.size() == 0 ); - auto now = db().head_block_time(); asset accumulated_balances = (o.side==content_update_operation::side_t::master)?itr->accumulated_balance_master : itr->accumulated_balance_comp; - db().modify< content_object >( *itr, [&]( content_object& con ) { + db().modify< content_object >( *itr, [&o,this]( content_object& con ) { + //the third_party_publishers flag cannot be changed. EVER. + bool third_party_flag = con.comp_meta.third_party_publishers; if( o.side == o.master ) { if( o.album_meta ) con.album_meta = *o.album_meta; @@ -372,15 +373,18 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) con.track_meta = *o.track_meta; con.track_title = o.track_meta->track_title; } - if( !two_sides && o.comp_meta ) + if( !third_party_flag && o.comp_meta ) { con.comp_meta = *o.comp_meta; + if(!db().has_hardfork(MUSE_HARDFORK_0_2)) { + third_party_flag = con.comp_meta.third_party_publishers; + } + } if( o.new_distributions.size() > 0 ) { con.distributions_master = o.new_distributions; con.accumulated_balance_master.amount = 0; } - con.last_update = now; if( o.new_management.size() > 0 ) { con.manage_master.account_auths.clear(); for( const management_vote &m : o.new_management ) { @@ -390,16 +394,12 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) } }else{ if( o.comp_meta ) { - //the third_party_publishers flag cannot be changed. EVER. - bool third_party_flag = con.comp_meta.third_party_publishers; con.comp_meta = *o.comp_meta; - con.comp_meta.third_party_publishers = third_party_flag; } if( o.new_distributions.size() > 0 ) { con.distributions_comp = o.new_distributions; con.accumulated_balance_comp.amount = 0; } - con.last_update = now; if( o.new_management.size() > 0 ) { con.manage_comp.account_auths.clear(); for( const management_vote &m : o.new_management ) { @@ -408,6 +408,7 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) con.manage_comp.weight_threshold = o.new_threshold; } } + con.comp_meta.third_party_publishers = third_party_flag; if(db().has_hardfork(MUSE_HARDFORK_0_1)) { if( o.new_playing_reward > 0 ) con.playing_reward = o.new_playing_reward; @@ -420,6 +421,7 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) if( o.new_publishers_share != con.publishers_share ) con.publishers_share = o.new_publishers_share; } + con.last_update = db().head_block_time(); }); //TODO_MUSE - the redistribute shall affect only the respective side... delete the accumulated balance afterwards if( redistribute_master ) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index fdf3dcd..2866e53 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -189,8 +189,8 @@ BOOST_AUTO_TEST_CASE( simple_test ) { try { - generate_blocks( time_point_sec( MUSE_HARDFORK_0_1_TIME ) ); - BOOST_CHECK( db.has_hardfork( MUSE_HARDFORK_0_1 ) ); + generate_blocks( time_point_sec( MUSE_HARDFORK_0_2_TIME ) ); + BOOST_CHECK( db.has_hardfork( MUSE_HARDFORK_0_2 ) ); BOOST_TEST_MESSAGE( "Testing: streaming platform contract" ); From 489d9a5a31c9339942a725aa1a64b5a111c0facd Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 13 Dec 2017 18:01:41 +0100 Subject: [PATCH 43/74] Relabel track_meta.copyright field to json_metadata --- .../chain/include/muse/chain/protocol/muse_operations.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/include/muse/chain/protocol/muse_operations.hpp b/libraries/chain/include/muse/chain/protocol/muse_operations.hpp index 2f9e931..8dc2d2d 100644 --- a/libraries/chain/include/muse/chain/protocol/muse_operations.hpp +++ b/libraries/chain/include/muse/chain/protocol/muse_operations.hpp @@ -135,7 +135,7 @@ struct content_metadata_track_master{ string p_line; uint32_t track_no; uint32_t track_volume; - optional copyright; + optional json_metadata; uint32_t track_duration; bool samples; void validate_meta()const; @@ -363,7 +363,7 @@ FC_REFLECT(muse::chain::content_metadata_publisher::publisher,(publisher)(IPI_CA FC_REFLECT(muse::chain::content_metadata_publisher::writer,(writer)(IPI_CAE)(ISNI)(role)(publisher)) FC_REFLECT(muse::chain::content_metadata_track_master::track_artist,(artist)(aliases)(ISNI)) FC_REFLECT(muse::chain::content_metadata_track_master,(track_title)(ISRC)(track_artists)(featured_artist)(featured_artist_ISNI) - (track_producer)(genre_1)(genre_2)(p_line)(track_no)(track_volume)(copyright)(track_duration)(samples) ) + (track_producer)(genre_1)(genre_2)(p_line)(track_no)(track_volume)(json_metadata)(track_duration)(samples) ) FC_REFLECT(muse::chain::content_metadata_publisher,(composition_title)(alternate_composition_title)(ISWC)(third_party_publishers) (publishers)(writers)(PRO)) From e063826de8fb5c95fa45f3d22f747f38c6259fc7 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 13 Dec 2017 20:58:05 +0100 Subject: [PATCH 44/74] Added HF to validate json_metadata in content --- libraries/chain/muse_evaluator.cpp | 6 ++++++ tests/tests/muse_tests.cpp | 24 ++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/libraries/chain/muse_evaluator.cpp b/libraries/chain/muse_evaluator.cpp index 47cb9a9..116cc9a 100644 --- a/libraries/chain/muse_evaluator.cpp +++ b/libraries/chain/muse_evaluator.cpp @@ -278,6 +278,9 @@ void content_evaluator::do_apply( const content_operation& o ) FC_ASSERT( !(auth.owner_challenged || auth.active_challenged ) ); + if( o.track_meta.json_metadata && db().has_hardfork( MUSE_HARDFORK_0_2 ) ) + FC_ASSERT( fc::is_utf8(*o.track_meta.json_metadata) && fc::json::is_valid(*o.track_meta.json_metadata), "JSON Metadata not valid JSON" ); + auto now = db().head_block_time(); for( const distribution& d : o.distributions ) const auto& payee = db().get_account( d.payee ); @@ -347,6 +350,9 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) else FC_ASSERT( !two_sides || o.side == o.master, "Cannot edit composition side data when only one side has been defined" ); + if( o.track_meta && o.track_meta->json_metadata && db().has_hardfork( MUSE_HARDFORK_0_2 ) ) + FC_ASSERT( fc::is_utf8(*o.track_meta->json_metadata) && fc::json::is_valid(*o.track_meta->json_metadata), "JSON Metadata not valid JSON" ); + for( const distribution& d : o.new_distributions ) { const auto& payee = db().get_account( d.payee ); diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 030d4fd..64a9ce3 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -35,11 +35,13 @@ using namespace graphene::db; BOOST_FIXTURE_TEST_SUITE( muse_tests, clean_database_fixture ) -#define FAIL( msg, op ) \ +#define FAIL( msg, op ) FAIL_WITH( msg, op, fc::assert_exception ) + +#define FAIL_WITH( msg, op, ex ) \ BOOST_TEST_MESSAGE( "--- Test failure " # msg ); \ tx.operations.clear(); \ tx.operations.push_back( op ); \ - MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_signatures ), fc::assert_exception ) + MUSE_REQUIRE_THROW( db.push_transaction( tx, database::skip_transaction_signatures ), ex ) BOOST_AUTO_TEST_CASE( streaming_platform_test ) { @@ -267,6 +269,14 @@ BOOST_AUTO_TEST_CASE( simple_test ) FAIL( "with long track title", cop ); cop.track_meta.track_title = "First test song"; + cop.track_meta.json_metadata = ""; + FAIL( "with empty json metadata", cop ); + cop.track_meta.json_metadata = "{123: 123}"; + FAIL_WITH( "with invalid json metadata", cop, fc::parse_error_exception ); + cop.track_meta.json_metadata = "{\"id\": \"\200\"}"; + FAIL( "with non-utf8 json metadata", cop ); + cop.track_meta.json_metadata.reset(); + cop.distributions.begin()->payee = "x"; FAIL( "with invalid payee name", cop ); cop.distributions.begin()->payee = "bob"; @@ -416,6 +426,14 @@ BOOST_AUTO_TEST_CASE( simple_test ) FAIL( "with long track title", cup ); cup.track_meta->track_title = "Simple test track"; + cup.track_meta->json_metadata = ""; + FAIL( "with empty json metadata", cup ); + cup.track_meta->json_metadata = "{123: 123}"; + FAIL_WITH( "with invalid json metadata", cup, fc::parse_error_exception ); + cup.track_meta->json_metadata = "{\"id\": \"\200\"}"; + FAIL( "with non-utf8 json metadata", cup ); + cup.track_meta->json_metadata.reset(); + distribution dist; dist.payee = "penny"; dist.bp = MUSE_100_PERCENT; @@ -680,6 +698,7 @@ BOOST_AUTO_TEST_CASE( multi_test ) cop.url = "ipfs://abcdef9"; cop.album_meta.album_title = "Multi test song"; cop.track_meta.track_title = "Multi test song"; + cop.track_meta.json_metadata = "{\"id\": 1}"; cop.comp_meta.third_party_publishers = true; distribution dist; dist.payee = "paula"; @@ -1034,6 +1053,7 @@ BOOST_AUTO_TEST_CASE( simple_authority_test ) cup.album_meta->album_title = "Simple test album"; cup.track_meta = content_metadata_track_master(); cup.track_meta->track_title = "Simple test track"; + cup.track_meta->json_metadata = "{\"id\": 1}"; management_vote mgmt; mgmt.voter = "muriel"; mgmt.percentage = 100; From 037f80f182144c2ae79e0312d790a5566ea1b67c Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 15 Dec 2017 21:24:24 +0100 Subject: [PATCH 45/74] Added test for HF 2 --- tests/tests/block_tests.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 4afc4b3..53d874f 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -880,6 +880,19 @@ BOOST_FIXTURE_TEST_CASE( hardfork_test, database_fixture ) BOOST_REQUIRE( db.has_hardfork( MUSE_HARDFORK_0_1 ) ); BOOST_REQUIRE( get_last_operations( 1 )[0].get< custom_operation >().data == vector< char >( op_msg.begin(), op_msg.end() ) ); BOOST_REQUIRE( itr->op(db).timestamp == db.head_block_time() - MUSE_BLOCK_INTERVAL ); + + generate_blocks( MUSE_MAX_MINERS ); + generate_blocks( fc::time_point_sec( MUSE_HARDFORK_0_2_TIME - MUSE_BLOCK_INTERVAL ), true ); + + BOOST_REQUIRE( db.has_hardfork( 0 ) ); + BOOST_REQUIRE( db.has_hardfork( MUSE_HARDFORK_0_1 ) ); + BOOST_REQUIRE( !db.has_hardfork( MUSE_HARDFORK_0_2 ) ); + + generate_block(); + + BOOST_REQUIRE( db.has_hardfork( 0 ) ); + BOOST_REQUIRE( db.has_hardfork( MUSE_HARDFORK_0_1 ) ); + BOOST_REQUIRE( db.has_hardfork( MUSE_HARDFORK_0_2 ) ); } FC_LOG_AND_RETHROW() } From cb73372f43906aefaae4aeed2fd4882d030ac216 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 15 Dec 2017 21:26:44 +0100 Subject: [PATCH 46/74] Removed unused vars --- tests/tests/block_tests.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 53d874f..c4a6396 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -383,8 +383,6 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions ) auto skip_sigs = database::skip_transaction_signatures | database::skip_authority_check; - const graphene::db::index& account_idx = db1.get_index(implementation_ids, impl_account_object_type); - signed_transaction trx; account_create_operation cop; cop.new_account_name = "alice"; @@ -433,8 +431,6 @@ BOOST_AUTO_TEST_CASE( tapos ) db1.open(dir1.path(), genesis ); init_witness_keys( db1 ); - const graphene::db::index& account_idx = db1.get_index(implementation_ids, impl_account_object_type); - auto b = db1.generate_block( db1.get_slot_time(1), db1.get_scheduled_witness( 1 ), init_account_priv_key(), database::skip_nothing); BOOST_TEST_MESSAGE( "Creating a transaction with reference block" ); @@ -612,7 +608,6 @@ BOOST_FIXTURE_TEST_CASE( pop_block_twice, clean_database_fixture ) transaction tx; signed_transaction ptx; - const account_object& witness_account = db.get_account( MUSE_INIT_MINER_NAME ); // transfer from committee account to Sam account transfer( MUSE_INIT_MINER_NAME, "sam", 100000 ); From 871c00abdd41bc6d38daa62f1fe2ac90346ec0df Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 16 Dec 2017 18:27:25 +0100 Subject: [PATCH 47/74] Fix: represent content_disable in cli_wallet --- libraries/wallet/include/muse/wallet/wallet.hpp | 7 +++---- libraries/wallet/wallet.cpp | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libraries/wallet/include/muse/wallet/wallet.hpp b/libraries/wallet/include/muse/wallet/wallet.hpp index d696b4d..b6f1940 100644 --- a/libraries/wallet/include/muse/wallet/wallet.hpp +++ b/libraries/wallet/include/muse/wallet/wallet.hpp @@ -814,12 +814,11 @@ class wallet_api /** - * Delete existing content object - * @param publisher the creating account + * Disable existing content object * @param url URL of the content * @param broadcast true if you wish to broadcast the transaction */ - annotated_signed_transaction remove_content( string url, bool broadcast ); + annotated_signed_transaction disable_content( string url, bool broadcast ); /** * Get reports for a given consumer. @@ -1155,7 +1154,7 @@ FC_API( muse::wallet::wallet_api, (update_content_master) (update_content_publishing) (update_content_global) - (remove_content) + (disable_content) (get_content_by_account) (get_content_by_url) (lookup_content) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 7581cf4..71a75c7 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2397,10 +2397,10 @@ annotated_signed_transaction wallet_api::update_content_global(string url, uint3 return my->sign_transaction( tx, broadcast ); } -annotated_signed_transaction wallet_api::remove_content( string url, bool broadcast ) +annotated_signed_transaction wallet_api::disable_content( string url, bool broadcast ) { FC_ASSERT( !is_locked() ); - content_remove_operation op; + content_disable_operation op; op.url = url; signed_transaction tx; From 320454327075063b7c9d820b0f958d0a0f6229de Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 16 Dec 2017 23:18:39 +0100 Subject: [PATCH 48/74] Fix streaming_platform_vote_object creation --- libraries/chain/muse_evaluator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/muse_evaluator.cpp b/libraries/chain/muse_evaluator.cpp index 56ab37e..9aa22cb 100644 --- a/libraries/chain/muse_evaluator.cpp +++ b/libraries/chain/muse_evaluator.cpp @@ -102,12 +102,12 @@ void account_streaming_platform_vote_evaluator::do_apply( const account_streamin if( itr == by_account_streaming_platform_idx.end() ) { FC_ASSERT( o.approve, "vote doesn't exist, user must be indicate a desire to approve the streaming_platform" ); FC_ASSERT( voter.streaming_platforms_voted_for < MUSE_MAX_ACCOUNT_WITNESS_VOTES, "account has voted for too many streaming_platforms"); - db().create ( [&](streaming_platform_vote_object v) { + db().create ( [&streaming_platform,&voter](streaming_platform_vote_object& v) { v.streaming_platform = streaming_platform.id; v.account = voter.id; }); db().adjust_streaming_platform_vote( streaming_platform, voter.witness_vote_weight()); - db().modify( voter, [&]( account_object& a ) { + db().modify( voter, []( account_object& a ) { a.streaming_platforms_voted_for++; }); From ab50a3c3f1bb2bb6dc220972afd5ea3b19ca2137 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 16 Dec 2017 23:28:44 +0100 Subject: [PATCH 49/74] Added HF protection for fix --- libraries/chain/muse_evaluator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/muse_evaluator.cpp b/libraries/chain/muse_evaluator.cpp index 9aa22cb..337449a 100644 --- a/libraries/chain/muse_evaluator.cpp +++ b/libraries/chain/muse_evaluator.cpp @@ -99,7 +99,7 @@ void account_streaming_platform_vote_evaluator::do_apply( const account_streamin const auto& by_account_streaming_platform_idx = db().get_index_type< streaming_platform_vote_index >().indices().get< by_account_streaming_platform >(); auto itr = by_account_streaming_platform_idx.find( boost::make_tuple( voter.get_id(), streaming_platform.get_id() ) ); - if( itr == by_account_streaming_platform_idx.end() ) { + if( itr == by_account_streaming_platform_idx.end() || !db().has_hardfork( MUSE_HARDFORK_0_2 ) ) { // TODO remove check after HF activation FC_ASSERT( o.approve, "vote doesn't exist, user must be indicate a desire to approve the streaming_platform" ); FC_ASSERT( voter.streaming_platforms_voted_for < MUSE_MAX_ACCOUNT_WITNESS_VOTES, "account has voted for too many streaming_platforms"); db().create ( [&streaming_platform,&voter](streaming_platform_vote_object& v) { From 14d0d7702eeaf579838a10e1708a0a5fc87a6415 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 16 Dec 2017 23:29:22 +0100 Subject: [PATCH 50/74] Fixed compiler warning --- tests/tests/muse_tests.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index a261dc5..e4d8851 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -1733,7 +1733,6 @@ BOOST_AUTO_TEST_CASE( disable_test ) tx.operations.push_back( spuo ); db.push_transaction( tx, database::skip_transaction_signatures ); } - const streaming_platform_object& suzys = db.get_streaming_platform( "suzy" ); // --------- Create content ------------ { From 06804ade1d62e19f1ff9159bda023b5bb2e44a29 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 9 Dec 2017 22:39:38 +0100 Subject: [PATCH 51/74] Fixed supply calculation --- libraries/chain/database.cpp | 115 +++++++++++------- .../chain/include/muse/chain/database.hpp | 25 ++-- .../muse/chain/global_property_object.hpp | 6 +- tests/common/database_fixture.cpp | 10 +- tests/tests/muse_tests.cpp | 27 ++-- 5 files changed, 111 insertions(+), 72 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 4fd0f29..a5632c5 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1583,14 +1583,13 @@ void database::process_vesting_withdrawals() } } - -asset database::process_content_cashout() -{try{ +asset database::process_content_cashout( const asset& content_reward ) +{ try { auto now = head_block_time(); auto cashing_time = now - fc::seconds(60*24*60); asset paid(0); - asset total_payout = get_content_reward(); + asset total_payout = has_hardfork( MUSE_HARDFORK_0_2 ) ? content_reward : get_content_reward(); //find thresholds const auto& cridx = get_index_type< content_index >().indices().get< by_popularity >(); @@ -1616,7 +1615,7 @@ asset database::process_content_cashout() current_plays_threshold2 = critr->times_played_24; auto& c_stat = get (content_stats_id_type(0)); - modify(c_stat, [&](content_stats_object& cso){ + modify(c_stat, [current_plays_threshold1,current_plays_threshold2](content_stats_object& cso){ cso.current_plays_threshold1 = current_plays_threshold1; cso.current_plays_threshold2 = current_plays_threshold2; }); @@ -1637,32 +1636,32 @@ asset database::process_content_cashout() FC_ASSERT( consumer.total_listening_time > 0 ); asset pay_reserve = total_payout * itr->play_time / customers.size() / consumer.total_listening_time; paid += pay_to_content(itr->content, pay_reserve, itr->streaming_platform ); - modify(consumer, [&](account_object & a){ + modify(consumer, [&itr](account_object & a){ a.total_listening_time -= itr->play_time; }); remove(*itr); itr = ridx.begin(); } return paid; -}FC_LOG_AND_RETHROW() } +} FC_LOG_AND_RETHROW() } -void database::pay_to_content_master(const content_object &co, asset payout) +void database::pay_to_content_master(const content_object &co, const asset& payout) {try{ if ( co.distributions_master.size() == 0) { - modify(co, [&]( content_object& c ){ - if(c.accumulated_balance_master.amount == 0 ) - c.accumulated_balance_master = payout; - else - c.accumulated_balance_master += payout; + modify(co, [&payout]( content_object& c ){ + c.accumulated_balance_master += payout; }); } else { + asset to_pay = payout + co.accumulated_balance_master; + asset total_paid = asset( 0, to_pay.asset_id ); for ( const auto& di : co.distributions_master ) { - asset author_reward = payout; - author_reward.amount = payout.amount * di.bp / 10000; + asset author_reward = to_pay; + author_reward.amount = author_reward.amount * di.bp / 10000; + total_paid += author_reward; auto mbd_muse = author_reward; auto vesting_muse = author_reward - mbd_muse; @@ -1673,26 +1672,34 @@ void database::pay_to_content_master(const content_object &co, asset payout) push_applied_operation( content_reward_operation( di.payee, co.url, mbd_created, vest_created ) ); } + if( total_paid > to_pay ) + elog( "Paid out too much for content ${co}: ${paid} > ${to_pay}", + ("co",co)("paid",total_paid)("to_pay",to_pay) ); + to_pay -= total_paid; + if( co.accumulated_balance_master != to_pay ) + modify(co, [&to_pay]( content_object& c ){ + c.accumulated_balance_master = to_pay; + }); } }FC_LOG_AND_RETHROW() } -void database::pay_to_content_comp(const content_object &co, asset payout) +void database::pay_to_content_comp(const content_object &co, const asset& payout) {try{ if ( co.distributions_comp.size() == 0) { - modify(co, [&]( content_object& c ){ - if(c.accumulated_balance_comp.amount == 0 ) - c.accumulated_balance_comp = payout; - else - c.accumulated_balance_comp += payout; + modify(co, [&payout]( content_object& c ){ + c.accumulated_balance_comp += payout; }); } else { + asset to_pay = payout + co.accumulated_balance_comp; + asset total_paid = asset( 0, to_pay.asset_id ); for ( const auto& di : co.distributions_comp ) { - asset author_reward = payout; - author_reward.amount = payout.amount * di.bp / 10000; + asset author_reward = to_pay; + author_reward.amount = author_reward.amount * di.bp / 10000; + total_paid += author_reward; auto mbd_muse = author_reward; auto vesting_muse = author_reward - mbd_muse; @@ -1703,10 +1710,18 @@ void database::pay_to_content_comp(const content_object &co, asset payout) push_applied_operation( content_reward_operation( di.payee, co.url, mbd_created, vest_created ) ); } + if( total_paid > to_pay ) + elog( "Paid out too much for content composer ${co}: ${paid} > ${to_pay}", + ("co",co)("paid",total_paid)("to_pay",to_pay) ); + to_pay -= total_paid; + if( co.accumulated_balance_comp != to_pay ) + modify(co, [&to_pay]( content_object& c ){ + c.accumulated_balance_comp = to_pay; + }); } }FC_LOG_AND_RETHROW() } -void database::pay_to_platform( streaming_platform_id_type platform, asset payout, string url ) +void database::pay_to_platform( streaming_platform_id_type platform, const asset& payout, const string& url ) {try{ const streaming_platform_object& pl = get( platform ); const auto& owner = get_account(pl.owner); @@ -1718,7 +1733,7 @@ void database::pay_to_platform( streaming_platform_id_type platform, asset payou }FC_LOG_AND_RETHROW() } -void database::pay_to_curator(const content_object &co, account_id_type cur, asset pay) +void database::pay_to_curator(const content_object &co, account_id_type cur, const asset& pay) {try{ const auto& curator = get(cur); auto vesting_muse = asset(0, MUSE_SYMBOL); @@ -1750,12 +1765,12 @@ asset database::pay_to_content(content_id_type content, asset payout, streaming_ paid += platform_reward; const content_stats_object& c_stat = get (content_stats_id_type(0)); - bool above_thr1 = (c_stat.current_plays_threshold1 <= co.times_played_24); - bool above_thr2 = (c_stat.current_plays_threshold2 <= co.times_played_24); + const bool above_thr1 = (c_stat.current_plays_threshold1 <= co.times_played_24); + const bool above_thr2 = (c_stat.current_plays_threshold2 <= co.times_played_24); bool pay_curators = false; bool reset_curation_rewards = false; - modify(co,[&](content_object& c){ + modify(co,[above_thr1,above_thr2,&pay_curators,&reset_curation_rewards,this](content_object& c){ if(c.curation_rewards){ if(above_thr2) { //still in top 2000 if(head_block_time() < c.curation_reward_expiration) @@ -1778,7 +1793,6 @@ asset database::pay_to_content(content_id_type content, asset payout, streaming_ }); const auto& vidx = get_index_type().indices().get< by_reward_flag_update > (); - auto vitr = vidx.lower_bound( boost::make_tuple( true, time_point_sec(0) ) ); if(reset_curation_rewards){ auto vitr = vidx.lower_bound( boost::make_tuple( true, time_point_sec(0) ) ); while( vitr!=vidx.end() && vitr->marked_for_curation_reward == true ) { @@ -1814,19 +1828,11 @@ asset database::pay_to_content(content_id_type content, asset payout, streaming_ * This method pays out vesting and reward shares every block, and liquidity shares once per day. * This method does not pay out witnesses. */ -void database::process_funds() +void database::process_funds( const asset& content_reward, const asset& witness_pay, const asset& vesting_reward ) { const auto& props = get_dynamic_global_properties(); - auto content_reward = get_content_reward(); - auto witness_pay = get_producer_reward(); - auto vesting_reward = get_vesting_reward(); - - - if( props.head_block_number < MUSE_START_VESTING_BLOCK ) - vesting_reward.amount = 0; - - modify( props, [&]( dynamic_global_property_object& p ) + modify( props, [&content_reward, &witness_pay, &vesting_reward]( dynamic_global_property_object& p ) { p.total_vesting_fund_muse += vesting_reward; p.total_reward_fund_muse += content_reward ; @@ -1835,16 +1841,18 @@ void database::process_funds() } ); } -void database::adjust_funds(asset paid_to_content) +void database::adjust_funds(const asset& content_reward, const asset& paid_to_content) { - auto initial_content_allocation = get_content_reward(); - asset delta = initial_content_allocation - paid_to_content; + const auto initial_content_allocation = has_hardfork( MUSE_HARDFORK_0_2 ) ? content_reward : get_content_reward(); + const asset delta = initial_content_allocation - paid_to_content; + const asset true_delta = content_reward - paid_to_content; const auto& props = get_dynamic_global_properties(); - modify( props, [&]( dynamic_global_property_object& p ) + modify( props, [&delta, &true_delta]( dynamic_global_property_object& p ) { p.total_reward_fund_muse -= delta; p.current_supply -= delta; p.virtual_supply -= delta; + p.supply_delta += delta - true_delta; } ); } @@ -2520,10 +2528,15 @@ void database::_apply_block( const signed_block& next_block ) update_median_feed(); update_virtual_supply(); - process_funds(); + const auto content_reward = get_content_reward(); + const auto witness_pay = get_producer_reward(); + const auto vesting_reward = head_block_num() < MUSE_START_VESTING_BLOCK ? asset( 0, MUSE_SYMBOL ) + : get_vesting_reward(); + + process_funds( content_reward, witness_pay, vesting_reward ); process_conversions(); - asset paid_for_conent = process_content_cashout(); - adjust_funds(paid_for_conent); + asset paid_for_content = process_content_cashout( content_reward ); + adjust_funds( content_reward, paid_for_content ); process_vesting_withdrawals(); pay_liquidity_reward(); update_virtual_supply(); @@ -3400,7 +3413,15 @@ void database::validate_invariants()const } } - total_supply += gpo.total_vesting_fund_muse + gpo.total_reward_fund_muse; + const auto& content_idx = db.get_index_type< content_index >().indices().get< by_id >(); + + for( auto itr = content_idx.begin(); itr != content_idx.end(); itr++ ) + { + total_supply += itr->accumulated_balance_master; + total_supply += itr->accumulated_balance_comp; + } + + total_supply += gpo.total_vesting_fund_muse; FC_ASSERT( gpo.current_supply == total_supply, "", ("gpo.current_supply",gpo.current_supply)("total_supply",total_supply) ); FC_ASSERT( gpo.current_mbd_supply == total_mbd, "", ("gpo.current_mbd_supply",gpo.current_mbd_supply)("total_mbd",total_mbd) ); diff --git a/libraries/chain/include/muse/chain/database.hpp b/libraries/chain/include/muse/chain/database.hpp index d4d003f..9d2c066 100644 --- a/libraries/chain/include/muse/chain/database.hpp +++ b/libraries/chain/include/muse/chain/database.hpp @@ -306,14 +306,10 @@ namespace muse { namespace chain { void process_vesting_withdrawals(); asset pay_to_content(content_id_type content, asset payout, streaming_platform_id_type platform); - void pay_to_content_master(const content_object &content, asset payout); - void pay_to_content_comp(const content_object &content, asset payout); - void pay_to_platform( streaming_platform_id_type platform, asset payout, string url ); - void pay_to_curator(const content_object &co, account_id_type cur, asset pay); - - asset process_content_cashout(); - void process_funds(); - void adjust_funds(asset paid_to_content); + + asset process_content_cashout(const asset& content_reward); + void process_funds(const asset& content_reward, const asset& witness_pay, const asset& vesting_reward); + void adjust_funds(const asset& content_reward, const asset& paid_to_content); void process_conversions(); void account_recovery_processing(); void update_median_feed(); @@ -321,8 +317,6 @@ namespace muse { namespace chain { asset get_liquidity_reward()const; asset get_content_reward()const; - asset get_producer_reward(); - asset get_vesting_reward()const; asset get_curation_reward()const; asset get_pow_reward()const; @@ -442,6 +436,13 @@ namespace muse { namespace chain { void process_hardforks(); void apply_hardfork( uint32_t hardfork ); + asset get_producer_reward(); + asset get_vesting_reward()const; + + void pay_to_content_master(const content_object &content, const asset& payout); + void pay_to_content_comp(const content_object &content, const asset& payout); + void pay_to_platform( streaming_platform_id_type platform, const asset& payout, const string& url ); + void pay_to_curator(const content_object &co, account_id_type cur, const asset& pay); ///@} vector< signed_transaction > _pending_tx; @@ -469,9 +470,5 @@ namespace muse { namespace chain { flat_map _checkpoints; node_property_object _node_property_object; - - }; - - } } diff --git a/libraries/chain/include/muse/chain/global_property_object.hpp b/libraries/chain/include/muse/chain/global_property_object.hpp index 365edcf..768cff8 100644 --- a/libraries/chain/include/muse/chain/global_property_object.hpp +++ b/libraries/chain/include/muse/chain/global_property_object.hpp @@ -35,9 +35,10 @@ namespace muse { namespace chain { asset confidential_supply = asset( 0, MUSE_SYMBOL ); ///< total asset held in confidential balances asset current_mbd_supply = asset( 0, MBD_SYMBOL ); asset confidential_mbd_supply = asset( 0, MBD_SYMBOL ); ///< total asset held in confidential balances - asset total_vesting_fund_muse = asset( 0, MUSE_SYMBOL ); + asset total_vesting_fund_muse = asset( 0, MUSE_SYMBOL ); asset total_vesting_shares = asset( 0, VESTS_SYMBOL ); - asset total_reward_fund_muse = asset( 0, MUSE_SYMBOL ); + asset total_reward_fund_muse = asset( 0, MUSE_SYMBOL ); + asset supply_delta = asset( 0, MUSE_SYMBOL ); uint32_t maximum_proposal_lifetime = 86400; @@ -125,6 +126,7 @@ FC_REFLECT_DERIVED( muse::chain::dynamic_global_property_object, (graphene::db:: (total_vesting_fund_muse) (total_vesting_shares) (total_reward_fund_muse) + (supply_delta) (mbd_interest_rate) (average_block_size) (maximum_block_size) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 09c6ed3..6caf085 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -480,9 +480,17 @@ void database_fixture::validate_database( void ) } } + const auto& content_idx = db.get_index_type< content_index >().indices().get< by_id >(); + + for( auto itr = content_idx.begin(); itr != content_idx.end(); itr++ ) + { + total_supply += itr->accumulated_balance_master; + total_supply += itr->accumulated_balance_comp; + } + auto gpo = db.get_dynamic_global_properties(); - total_supply += gpo.total_vesting_fund_muse + gpo.total_reward_fund_muse; + total_supply += gpo.total_vesting_fund_muse; FC_ASSERT( gpo.current_supply == total_supply, "", ("gpo.current_supply",gpo.current_supply)("total_supply",total_supply) ); FC_ASSERT( gpo.current_mbd_supply == total_mbd, "", ("gpo.current_mbd_supply",gpo.current_mbd_supply)("total_mbd",total_mbd) ); diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index e4d8851..783bb11 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -386,6 +386,8 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( db.head_block_time().sec_since_epoch(), reports[0].created.sec_since_epoch() ); BOOST_CHECK_EQUAL( 100, reports[0].play_time ); } + const auto& played_at = db.head_block_time(); + // --------- Content update ------------ { content_update_operation cup; @@ -545,6 +547,9 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( last_update.sec_since_epoch(), voted->last_update.sec_since_epoch() ); } + BOOST_REQUIRE( played_at + 86400 - MUSE_BLOCK_INTERVAL > db.head_block_time() ); + generate_blocks( played_at + 86400 - MUSE_BLOCK_INTERVAL ); + BOOST_CHECK_EQUAL( 0, alice_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, suzy_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, uhura_id(db).balance.amount.value ); @@ -589,9 +594,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); - generate_blocks( db.head_block_time() + 86400 - MUSE_BLOCK_INTERVAL ); - - asset daily_content_reward = asset( 1863530, MUSE_SYMBOL ); //db.get_content_reward(); + asset daily_content_reward = db.get_content_reward(); generate_block(); @@ -667,8 +670,8 @@ BOOST_AUTO_TEST_CASE( multi_test ) { try { - generate_blocks( time_point_sec( MUSE_HARDFORK_0_1_TIME ) ); - BOOST_CHECK( db.has_hardfork( MUSE_HARDFORK_0_1 ) ); + generate_blocks( time_point_sec( MUSE_HARDFORK_0_2_TIME ) ); + BOOST_CHECK( db.has_hardfork( MUSE_HARDFORK_0_2 ) ); BOOST_TEST_MESSAGE( "Testing: streaming platform contract" ); @@ -901,7 +904,7 @@ BOOST_AUTO_TEST_CASE( multi_test ) generate_blocks( db.head_block_time() + 86400 - MUSE_BLOCK_INTERVAL ); - asset daily_content_reward = asset( 1863530, MUSE_SYMBOL ); //db.get_content_reward(); + asset daily_content_reward = db.get_content_reward(); generate_block(); @@ -915,7 +918,7 @@ BOOST_AUTO_TEST_CASE( multi_test ) asset master_reward = daily_content_reward - comp_reward; const content_object& song1 = db.get_content( "ipfs://abcdef9" ); - BOOST_CHECK_EQUAL( 0, song1.accumulated_balance_master.amount.value ); + BOOST_CHECK_EQUAL( 1, song1.accumulated_balance_master.amount.value ); BOOST_CHECK_EQUAL( 0, song1.accumulated_balance_comp.amount.value ); BOOST_CHECK_EQUAL( master_reward.amount.value * (MUSE_100_PERCENT/3) / MUSE_100_PERCENT, paula_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( comp_reward.amount.value + master_reward.amount.value * (MUSE_100_PERCENT - MUSE_100_PERCENT/3) / MUSE_100_PERCENT, penny_id(db).balance.amount.value ); @@ -1214,8 +1217,14 @@ BOOST_AUTO_TEST_CASE( multi_authority_test ) mgmt.percentage = 33; cop.management.push_back( mgmt ); cop.management_threshold = 50; + cop.management_comp = vector(); + mgmt.percentage = 50; + cop.management_comp->push_back(mgmt); + mgmt.voter = "miranda"; + cop.management_comp->push_back(mgmt); + cop.management_threshold_comp = 50; cop.playing_reward = 10; - cop.publishers_share = 0; + cop.publishers_share = 100; tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( cop ); @@ -1236,9 +1245,11 @@ BOOST_AUTO_TEST_CASE( multi_authority_test ) mgmt.voter = "muriel"; mgmt.percentage = 100; cup.new_management.push_back( mgmt ); + cup.new_threshold = 40; // FIXME mgmt.voter = "martha"; cup.comp_meta = content_metadata_publisher(); + cup.new_publishers_share = 101; tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( cup ); From a4c9893b282a6bbc1a2a48c9e870c91474c377a8 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 10 Dec 2017 22:01:50 +0100 Subject: [PATCH 52/74] Added HF-protection for some changes --- libraries/chain/database.cpp | 42 +++++++++++++++++++++++-------- tests/common/database_fixture.cpp | 16 +++++++----- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index a5632c5..eb3883a 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1655,7 +1655,9 @@ void database::pay_to_content_master(const content_object &co, const asset& payo } else { - asset to_pay = payout + co.accumulated_balance_master; + asset to_pay = payout; + if (has_hardfork( MUSE_HARDFORK_0_2 )) + to_pay += co.accumulated_balance_master; asset total_paid = asset( 0, to_pay.asset_id ); for ( const auto& di : co.distributions_master ) { @@ -1673,10 +1675,17 @@ void database::pay_to_content_master(const content_object &co, const asset& payo push_applied_operation( content_reward_operation( di.payee, co.url, mbd_created, vest_created ) ); } if( total_paid > to_pay ) - elog( "Paid out too much for content ${co}: ${paid} > ${to_pay}", + elog( "Paid out too much for content master ${co}: ${paid} > ${to_pay}", ("co",co)("paid",total_paid)("to_pay",to_pay) ); to_pay -= total_paid; - if( co.accumulated_balance_master != to_pay ) + if( !has_hardfork( MUSE_HARDFORK_0_2 ) ) + { + if( to_pay.amount != 0 ) + modify(co, [&to_pay]( content_object& c ){ + c.accumulated_balance_master += to_pay; + }); + } + else if( co.accumulated_balance_master != to_pay ) modify(co, [&to_pay]( content_object& c ){ c.accumulated_balance_master = to_pay; }); @@ -1693,7 +1702,9 @@ void database::pay_to_content_comp(const content_object &co, const asset& payout } else { - asset to_pay = payout + co.accumulated_balance_comp; + asset to_pay = payout; + if (has_hardfork( MUSE_HARDFORK_0_2 )) + to_pay += co.accumulated_balance_comp; asset total_paid = asset( 0, to_pay.asset_id ); for ( const auto& di : co.distributions_comp ) { @@ -1714,7 +1725,14 @@ void database::pay_to_content_comp(const content_object &co, const asset& payout elog( "Paid out too much for content composer ${co}: ${paid} > ${to_pay}", ("co",co)("paid",total_paid)("to_pay",to_pay) ); to_pay -= total_paid; - if( co.accumulated_balance_comp != to_pay ) + if( !has_hardfork( MUSE_HARDFORK_0_2 ) ) + { + if( to_pay.amount != 0 ) + modify(co, [&to_pay]( content_object& c ){ + c.accumulated_balance_comp += to_pay; + }); + } + else if( co.accumulated_balance_comp != to_pay ) modify(co, [&to_pay]( content_object& c ){ c.accumulated_balance_comp = to_pay; }); @@ -3413,13 +3431,17 @@ void database::validate_invariants()const } } - const auto& content_idx = db.get_index_type< content_index >().indices().get< by_id >(); - - for( auto itr = content_idx.begin(); itr != content_idx.end(); itr++ ) + if( has_hardfork( MUSE_HARDFORK_0_2 ) ) { - total_supply += itr->accumulated_balance_master; - total_supply += itr->accumulated_balance_comp; + const auto& content_idx = get_index_type< content_index >().indices(); + for( auto itr = content_idx.begin(); itr != content_idx.end(); itr++ ) + { + total_supply += itr->accumulated_balance_master; + total_supply += itr->accumulated_balance_comp; + } } + else + total_supply += gpo.total_reward_fund_muse; total_supply += gpo.total_vesting_fund_muse; diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 6caf085..9b9254a 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -480,15 +480,19 @@ void database_fixture::validate_database( void ) } } - const auto& content_idx = db.get_index_type< content_index >().indices().get< by_id >(); + auto gpo = db.get_dynamic_global_properties(); - for( auto itr = content_idx.begin(); itr != content_idx.end(); itr++ ) + if( db.has_hardfork( MUSE_HARDFORK_0_2 ) ) { - total_supply += itr->accumulated_balance_master; - total_supply += itr->accumulated_balance_comp; + const auto& content_idx = db.get_index_type< content_index >().indices().get< by_id >(); + for( auto itr = content_idx.begin(); itr != content_idx.end(); itr++ ) + { + total_supply += itr->accumulated_balance_master; + total_supply += itr->accumulated_balance_comp; + } } - - auto gpo = db.get_dynamic_global_properties(); + else + total_supply += gpo.total_reward_fund_muse; total_supply += gpo.total_vesting_fund_muse; From be65782edc391d2483a2b99562d76242c87896dc Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 14 Dec 2017 21:55:51 +0100 Subject: [PATCH 53/74] Fixed issue #26, part 3 --- .../chain/include/muse/chain/database.hpp | 4 ++-- libraries/chain/muse_evaluator.cpp | 22 +++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/libraries/chain/include/muse/chain/database.hpp b/libraries/chain/include/muse/chain/database.hpp index 9d2c066..9e40777 100644 --- a/libraries/chain/include/muse/chain/database.hpp +++ b/libraries/chain/include/muse/chain/database.hpp @@ -306,6 +306,8 @@ namespace muse { namespace chain { void process_vesting_withdrawals(); asset pay_to_content(content_id_type content, asset payout, streaming_platform_id_type platform); + void pay_to_content_master(const content_object &content, const asset& payout); + void pay_to_content_comp(const content_object &content, const asset& payout); asset process_content_cashout(const asset& content_reward); void process_funds(const asset& content_reward, const asset& witness_pay, const asset& vesting_reward); @@ -439,8 +441,6 @@ namespace muse { namespace chain { asset get_producer_reward(); asset get_vesting_reward()const; - void pay_to_content_master(const content_object &content, const asset& payout); - void pay_to_content_comp(const content_object &content, const asset& payout); void pay_to_platform( streaming_platform_id_type platform, const asset& payout, const string& url ); void pay_to_curator(const content_object &co, account_id_type cur, const asset& pay); ///@} diff --git a/libraries/chain/muse_evaluator.cpp b/libraries/chain/muse_evaluator.cpp index 337449a..0a55372 100644 --- a/libraries/chain/muse_evaluator.cpp +++ b/libraries/chain/muse_evaluator.cpp @@ -388,7 +388,8 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) if( o.new_distributions.size() > 0 ) { con.distributions_master = o.new_distributions; - con.accumulated_balance_master.amount = 0; + if( !db().has_hardfork( MUSE_HARDFORK_0_2 ) ) + con.accumulated_balance_master.amount = 0; } if( o.new_management.size() > 0 ) { @@ -404,7 +405,8 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) } if( o.new_distributions.size() > 0 ) { con.distributions_comp = o.new_distributions; - con.accumulated_balance_comp.amount = 0; + if( !db().has_hardfork( MUSE_HARDFORK_0_2 ) ) + con.accumulated_balance_comp.amount = 0; } if( o.new_management.size() > 0 ) { con.manage_comp.account_auths.clear(); @@ -429,11 +431,17 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) } con.last_update = db().head_block_time(); }); - //TODO_MUSE - the redistribute shall affect only the respective side... delete the accumulated balance afterwards - if( redistribute_master ) - db().pay_to_content(itr->id, accumulated_balances, muse::chain::streaming_platform_id_type()); - if( redistribute_comp ) - db().pay_to_content(itr->id, accumulated_balances, muse::chain::streaming_platform_id_type()); + if( !db().has_hardfork( MUSE_HARDFORK_0_2 ) ) { + if( redistribute_master ) + db().pay_to_content(itr->id, accumulated_balances, muse::chain::streaming_platform_id_type()); + if( redistribute_comp ) + db().pay_to_content(itr->id, accumulated_balances, muse::chain::streaming_platform_id_type()); + } else if( o.new_distributions.size() > 0 && accumulated_balances.amount > 0 ) { + if( o.side == o.master ) + db().pay_to_content_master( *itr, asset( 0, MUSE_SYMBOL ) ); + else + db().pay_to_content_comp( *itr, asset( 0, MUSE_SYMBOL ) ); + } } FC_CAPTURE_AND_RETHROW( (o) ) } void content_disable_evaluator::do_apply( const content_disable_operation& o ) From ebadec4ca45ef7989f88faf591eeecff7ae9e4e5 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 21 Dec 2017 17:11:05 +0100 Subject: [PATCH 54/74] Added unit test --- tests/tests/muse_tests.cpp | 100 ++++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 7 deletions(-) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 783bb11..7290a77 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -260,7 +260,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) cop.album_meta.album_title += " are sixteen tons"; FAIL( "with long album title", cop ); - cop.album_meta.album_title = "First test song"; + cop.album_meta.album_title = "First test album"; cop.track_meta.track_title = ""; FAIL( "with empty track title", cop ); cop.track_meta.track_title = "Sixteen tons"; @@ -310,6 +310,42 @@ BOOST_AUTO_TEST_CASE( simple_test ) tx.operations.push_back( cop ); db.push_transaction( tx, database::skip_transaction_signatures ); } + // --------- Verify content ------------ + { + const content_object& song = db.get_content( "ipfs://abcdef1" ); + BOOST_CHECK_EQUAL( "uhura", song.uploader ); + BOOST_CHECK_EQUAL( "ipfs://abcdef1", song.url ); + BOOST_CHECK_EQUAL( 0, song.accumulated_balance_master.amount.value ); + BOOST_CHECK_EQUAL( MUSE_SYMBOL, song.accumulated_balance_master.asset_id ); + BOOST_CHECK_EQUAL( 0, song.accumulated_balance_comp.amount.value ); + BOOST_CHECK_EQUAL( MUSE_SYMBOL, song.accumulated_balance_comp.asset_id ); + BOOST_CHECK_EQUAL( "First test album", song.album_meta.album_title ); + BOOST_CHECK_EQUAL( "First test song", song.track_meta.track_title ); + BOOST_CHECK( !song.comp_meta.third_party_publishers ); + BOOST_CHECK_EQUAL( "First test song", song.track_title ); + BOOST_CHECK_EQUAL( db.head_block_time().sec_since_epoch(), song.last_update.sec_since_epoch() ); + BOOST_CHECK_EQUAL( db.head_block_time().sec_since_epoch(), song.created.sec_since_epoch() ); + BOOST_CHECK_EQUAL( 0, song.last_played.sec_since_epoch() ); + BOOST_CHECK_EQUAL( 1, song.distributions_master.size() ); + BOOST_CHECK_EQUAL( "paula", song.distributions_master[0].payee ); + BOOST_CHECK_EQUAL( MUSE_100_PERCENT, song.distributions_master[0].bp ); + BOOST_CHECK_EQUAL( 0, song.distributions_comp.size() ); + BOOST_CHECK_EQUAL( 10, song.playing_reward ); + BOOST_CHECK_EQUAL( 0, song.publishers_share ); + BOOST_CHECK_EQUAL( 100, song.manage_master.weight_threshold ); + BOOST_CHECK_EQUAL( 1, song.manage_master.account_auths.size() ); + const auto& tmp = song.manage_master.account_auths.find("martha"); + BOOST_CHECK( tmp != song.manage_master.account_auths.end() ); + BOOST_CHECK_EQUAL( 100, tmp->second ); + BOOST_CHECK_EQUAL( 0, song.manage_master.key_auths.size() ); + BOOST_CHECK_EQUAL( 0, song.manage_comp.weight_threshold ); + BOOST_CHECK_EQUAL( 0, song.manage_comp.account_auths.size() ); + BOOST_CHECK_EQUAL( 0, song.manage_comp.key_auths.size() ); + BOOST_CHECK_EQUAL( 0, song.times_played ); + BOOST_CHECK_EQUAL( 0, song.times_played_24 ); + BOOST_CHECK( song.allow_votes ); + BOOST_CHECK( !song.disabled ); + } // --------- Approve content ------------ { @@ -703,7 +739,7 @@ BOOST_AUTO_TEST_CASE( multi_test ) content_operation cop; cop.uploader = "uhura"; cop.url = "ipfs://abcdef9"; - cop.album_meta.album_title = "Multi test song"; + cop.album_meta.album_title = "Multi test album"; cop.track_meta.track_title = "Multi test song"; cop.track_meta.json_metadata = "{\"id\": 1}"; cop.comp_meta.third_party_publishers = true; @@ -760,12 +796,62 @@ BOOST_AUTO_TEST_CASE( multi_test ) tx.operations.push_back( cop ); db.push_transaction( tx, database::skip_transaction_signatures ); } + // --------- Verify content ------------ { - const content_object& song1 = db.get_content( "ipfs://abcdef9" ); - BOOST_CHECK_EQUAL( 2, song1.distributions_master.size() ); - BOOST_CHECK_EQUAL( 1, song1.distributions_comp.size() ); - BOOST_CHECK_EQUAL( 3, song1.manage_master.num_auths() ); - BOOST_CHECK_EQUAL( 1, song1.manage_comp.num_auths() ); + const content_object& song = db.get_content( "ipfs://abcdef9" ); + BOOST_CHECK_EQUAL( "uhura", song.uploader ); + BOOST_CHECK_EQUAL( "ipfs://abcdef9", song.url ); + BOOST_CHECK_EQUAL( 0, song.accumulated_balance_master.amount.value ); + BOOST_CHECK_EQUAL( MUSE_SYMBOL, song.accumulated_balance_master.asset_id ); + BOOST_CHECK_EQUAL( 0, song.accumulated_balance_comp.amount.value ); + BOOST_CHECK_EQUAL( MUSE_SYMBOL, song.accumulated_balance_comp.asset_id ); + BOOST_CHECK_EQUAL( "Multi test album", song.album_meta.album_title ); + BOOST_CHECK_EQUAL( "Multi test song", song.track_meta.track_title ); + BOOST_CHECK( song.comp_meta.third_party_publishers ); + BOOST_CHECK_EQUAL( "Multi test song", song.track_title ); + BOOST_CHECK_EQUAL( db.head_block_time().sec_since_epoch(), song.last_update.sec_since_epoch() ); + BOOST_CHECK_EQUAL( db.head_block_time().sec_since_epoch(), song.created.sec_since_epoch() ); + BOOST_CHECK_EQUAL( 0, song.last_played.sec_since_epoch() ); + BOOST_CHECK_EQUAL( 2, song.distributions_master.size() ); + BOOST_CHECK_EQUAL( "paula", song.distributions_master[0].payee ); + BOOST_CHECK_EQUAL( MUSE_100_PERCENT / 3, song.distributions_master[0].bp ); + BOOST_CHECK_EQUAL( "penny", song.distributions_master[1].payee ); + BOOST_CHECK_EQUAL( MUSE_100_PERCENT - MUSE_100_PERCENT / 3, song.distributions_master[1].bp ); + BOOST_CHECK_EQUAL( 1, song.distributions_comp.size() ); + BOOST_CHECK_EQUAL( "penny", song.distributions_comp[0].payee ); + BOOST_CHECK_EQUAL( MUSE_100_PERCENT, song.distributions_comp[0].bp ); + BOOST_CHECK_EQUAL( 10, song.playing_reward ); + BOOST_CHECK_EQUAL( 1000, song.publishers_share ); + BOOST_CHECK_EQUAL( 50, song.manage_master.weight_threshold ); + BOOST_CHECK_EQUAL( 3, song.manage_master.account_auths.size() ); + { + const auto& tmp = song.manage_master.account_auths.find("martha"); + BOOST_CHECK( tmp != song.manage_master.account_auths.end() ); + BOOST_CHECK_EQUAL( 34, tmp->second ); + } + { + const auto& tmp = song.manage_master.account_auths.find("miranda"); + BOOST_CHECK( tmp != song.manage_master.account_auths.end() ); + BOOST_CHECK_EQUAL( 33, tmp->second ); + } + { + const auto& tmp = song.manage_master.account_auths.find("muriel"); + BOOST_CHECK( tmp != song.manage_master.account_auths.end() ); + BOOST_CHECK_EQUAL( 33, tmp->second ); + } + BOOST_CHECK_EQUAL( 0, song.manage_master.key_auths.size() ); + BOOST_CHECK_EQUAL( 100, song.manage_comp.weight_threshold ); + BOOST_CHECK_EQUAL( 1, song.manage_comp.account_auths.size() ); + { + const auto& tmp = song.manage_comp.account_auths.find("martha"); + BOOST_CHECK( tmp != song.manage_comp.account_auths.end() ); + BOOST_CHECK_EQUAL( 100, tmp->second ); + } + BOOST_CHECK_EQUAL( 0, song.manage_comp.key_auths.size() ); + BOOST_CHECK_EQUAL( 0, song.times_played ); + BOOST_CHECK_EQUAL( 0, song.times_played_24 ); + BOOST_CHECK( song.allow_votes ); + BOOST_CHECK( !song.disabled ); } // --------- Publish playtime ------------ { From befbb9b3141c95cfb401f13b32d7159e8b1aa80e Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 21 Dec 2017 21:00:40 +0100 Subject: [PATCH 55/74] Fixed #42 --- libraries/chain/muse_evaluator.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/chain/muse_evaluator.cpp b/libraries/chain/muse_evaluator.cpp index 0a55372..c347018 100644 --- a/libraries/chain/muse_evaluator.cpp +++ b/libraries/chain/muse_evaluator.cpp @@ -298,7 +298,7 @@ void content_evaluator::do_apply( const content_operation& o ) const auto& voter = db().get_account(m.voter); } - const auto& new_content = db().create< content_object >( [&]( content_object& con ) { + db().create< content_object >( [&o,this]( content_object& con ) { //validate_url con.uploader = o.uploader; con.url = o.url; @@ -326,16 +326,20 @@ void content_evaluator::do_apply( const content_operation& o ) if( o.distributions_comp ) con.distributions_comp = *(o.distributions_comp); + if( db().has_hardfork( MUSE_HARDFORK_0_2 ) ) + con.publishers_share = o.publishers_share; } + else if( db().has_hardfork( MUSE_HARDFORK_0_2 ) ) + con.publishers_share = 0; con.accumulated_balance_master = asset(0); con.accumulated_balance_comp = asset(0); con.created = db().head_block_time(); con.last_update = con.created; con.last_played = time_point_sec(0); con.times_played = 0; + if( db().has_hardfork( MUSE_HARDFORK_0_2 ) ) + con.playing_reward = o.playing_reward; }); - - } FC_CAPTURE_AND_RETHROW( (o) ) } void content_update_evaluator::do_apply( const content_update_operation& o ) From bf2e76ee33816adaa9ecb13cf4d2c160703f5e53 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 17 Dec 2017 13:42:41 +0100 Subject: [PATCH 56/74] Removed unused reward functions + constants --- libraries/chain/database.cpp | 73 ------------------- libraries/chain/get_config.cpp | 17 +---- .../chain/include/muse/chain/compound.hpp | 12 --- libraries/chain/include/muse/chain/config.hpp | 37 +--------- .../chain/include/muse/chain/database.hpp | 9 --- 5 files changed, 8 insertions(+), 140 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index eb3883a..5bf98e3 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1875,18 +1875,6 @@ void database::adjust_funds(const asset& content_reward, const asset& paid_to_co } - -asset database::get_liquidity_reward()const -{ - if( true ) //TODO_MUSE - review during reward calculation modificaton - return asset( 0, MUSE_SYMBOL ); - - const auto& props = get_dynamic_global_properties(); - static_assert( MUSE_LIQUIDITY_REWARD_PERIOD_SEC == 60*60, "this code assumes a 1 hour time interval" ); - asset percent( calc_percent_reward_per_hour< MUSE_LIQUIDITY_APR_PERCENT >( props.virtual_supply.amount ), MUSE_SYMBOL ); - return std::max( percent, MUSE_MIN_LIQUIDITY_REWARD ); -} - asset database::get_content_reward()const { const auto& props = get_dynamic_global_properties(); @@ -1945,39 +1933,6 @@ asset database::get_producer_reward() return pay; } -void database::pay_liquidity_reward() -{ -#ifdef IS_TEST_NET - if( !liquidity_rewards_enabled ) - return; -#endif - - if( (head_block_num() % MUSE_LIQUIDITY_REWARD_BLOCKS) == 0 ) - { - auto reward = get_liquidity_reward(); - - if( reward.amount == 0 ) - return; - - const auto& ridx = get_index_type().indices().get(); - auto itr = ridx.begin(); - if( itr != ridx.end() && itr->volume_weight() > 0 ) - { - adjust_supply( reward, true ); - adjust_balance( itr->owner(*this), reward ); - modify( *itr, [&]( liquidity_reward_balance_object& obj ) - { - obj.muse_volume = 0; - obj.mbd_volume = 0; - obj.last_update = head_block_time(); - obj.weight = 0; - } ); - push_applied_operation( liquidity_reward_operation( itr->owner( *this ).name, reward ) ); - } - } -} - - /** * Iterates over all conversion requests with a conversion date before * the head block time and then converts them to/from muse/mbd at the @@ -2556,7 +2511,6 @@ void database::_apply_block( const signed_block& next_block ) asset paid_for_content = process_content_cashout( content_reward ); adjust_funds( content_reward, paid_for_content ); process_vesting_withdrawals(); - pay_liquidity_reward(); update_virtual_supply(); account_recovery_processing(); @@ -3048,33 +3002,6 @@ int database::match( const limit_order_object& new_order, const limit_order_obje } -void database::adjust_liquidity_reward( const account_object& owner, const asset& volume, bool is_sdb ) -{ - const auto& ridx = get_index_type().indices().get(); - auto itr = ridx.find( owner.id ); - if( itr != ridx.end() ) - { - modify( *itr, [&]( liquidity_reward_balance_object& r ) - { - if( head_block_time() - r.last_update >= MUSE_LIQUIDITY_TIMEOUT_SEC ) - { - r.mbd_volume = 0; - r.muse_volume = 0; - r.weight = 0; - } - - if( is_sdb ) - r.mbd_volume += volume.amount.value; - else - r.muse_volume += volume.amount.value; - - r.update_weight( true ); - r.last_update = head_block_time(); - } ); - } -} - - bool database::fill_order( const limit_order_object& order, const asset& pays, const asset& receives ) { try diff --git a/libraries/chain/get_config.cpp b/libraries/chain/get_config.cpp index 2776845..0525ebe 100644 --- a/libraries/chain/get_config.cpp +++ b/libraries/chain/get_config.cpp @@ -27,12 +27,10 @@ fc::variant_object get_config() result["MUSE_100_PERCENT"] = MUSE_100_PERCENT; result["MUSE_1_PERCENT"] = MUSE_1_PERCENT; result["MUSE_ADDRESS_PREFIX"] = MUSE_ADDRESS_PREFIX; - result["MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK"] = MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK; - result["MUSE_APR_PERCENT_MULTIPLY_PER_HOUR"] = MUSE_APR_PERCENT_MULTIPLY_PER_HOUR; - result["MUSE_APR_PERCENT_MULTIPLY_PER_ROUND"] = MUSE_APR_PERCENT_MULTIPLY_PER_ROUND; - result["MUSE_APR_PERCENT_SHIFT_PER_BLOCK"] = MUSE_APR_PERCENT_SHIFT_PER_BLOCK; - result["MUSE_APR_PERCENT_SHIFT_PER_HOUR"] = MUSE_APR_PERCENT_SHIFT_PER_HOUR; - result["MUSE_APR_PERCENT_SHIFT_PER_ROUND"] = MUSE_APR_PERCENT_SHIFT_PER_ROUND; + result["MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK"] = MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK_N; + result["MUSE_APR_PERCENT_MULTIPLY_PER_DAY"] = MUSE_APR_PERCENT_MULTIPLY_PER_DAY_N; + result["MUSE_APR_PERCENT_SHIFT_PER_BLOCK"] = MUSE_APR_PERCENT_SHIFT_PER_BLOCK_N; + result["MUSE_APR_PERCENT_SHIFT_PER_DAY"] = MUSE_APR_PERCENT_SHIFT_PER_DAY_N; result["MUSE_BANDWIDTH_AVERAGE_WINDOW_SECONDS"] = MUSE_BANDWIDTH_AVERAGE_WINDOW_SECONDS; result["MUSE_BANDWIDTH_PRECISION"] = MUSE_BANDWIDTH_PRECISION; result["MUSE_BLOCKCHAIN_HARDFORK_VERSION"] = MUSE_BLOCKCHAIN_HARDFORK_VERSION; @@ -57,10 +55,6 @@ fc::variant_object get_config() result["MUSE_INIT_SUPPLY"] = MUSE_INIT_SUPPLY; result["MUSE_INIT_TIME"] = MUSE_INIT_TIME; result["MUSE_IRREVERSIBLE_THRESHOLD"] = MUSE_IRREVERSIBLE_THRESHOLD; - result["MUSE_LIQUIDITY_APR_PERCENT"] = MUSE_LIQUIDITY_APR_PERCENT; - result["MUSE_LIQUIDITY_REWARD_BLOCKS"] = MUSE_LIQUIDITY_REWARD_BLOCKS; - result["MUSE_LIQUIDITY_REWARD_PERIOD_SEC"] = MUSE_LIQUIDITY_REWARD_PERIOD_SEC; - result["MUSE_LIQUIDITY_TIMEOUT_SEC"] = MUSE_LIQUIDITY_TIMEOUT_SEC; result["MUSE_MAX_ACCOUNT_NAME_LENGTH"] = MUSE_MAX_ACCOUNT_NAME_LENGTH; result["MUSE_MAX_ACCOUNT_WITNESS_VOTES"] = MUSE_MAX_ACCOUNT_WITNESS_VOTES; result["MUSE_MAX_ASSET_WHITELIST_AUTHORITIES"] = MUSE_MAX_ASSET_WHITELIST_AUTHORITIES; @@ -96,10 +90,7 @@ fc::variant_object get_config() result["MUSE_MIN_FEEDS"] = MUSE_MIN_FEEDS; result["MUSE_MINING_REWARD"] = MUSE_MINING_REWARD; result["MUSE_MINING_TIME"] = MUSE_MINING_TIME; - result["MUSE_MIN_LIQUIDITY_REWARD"] = MUSE_MIN_LIQUIDITY_REWARD; - result["MUSE_MIN_LIQUIDITY_REWARD_PERIOD_SEC"] = MUSE_MIN_LIQUIDITY_REWARD_PERIOD_SEC; result["MUSE_MIN_PAYOUT_SBD"] = MUSE_MIN_PAYOUT_SBD; - result["MUSE_MIN_POW_REWARD"] = MUSE_MIN_POW_REWARD; result["MUSE_MIN_PRODUCER_REWARD"] = MUSE_MIN_PRODUCER_REWARD; result["MUSE_MIN_RATION"] = MUSE_MIN_RATION; result["MUSE_MIN_TRANSACTION_EXPIRATION_LIMIT"] = MUSE_MIN_TRANSACTION_EXPIRATION_LIMIT; diff --git a/libraries/chain/include/muse/chain/compound.hpp b/libraries/chain/include/muse/chain/compound.hpp index fda55c2..1c3411f 100644 --- a/libraries/chain/include/muse/chain/compound.hpp +++ b/libraries/chain/include/muse/chain/compound.hpp @@ -35,12 +35,6 @@ share_type calc_percent_reward( share_type current_supply ) // Block per year - 10512000 -template< uint16_t percent > -inline share_type calc_percent_reward_per_hour( share_type current_supply ) -{ - return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_HOUR, MUSE_APR_PERCENT_SHIFT_PER_HOUR >( current_supply ); -} - template< uint16_t percent > inline share_type calc_percent_reward_per_block_new( share_type current_supply ) { @@ -53,12 +47,6 @@ inline share_type calc_percent_reward_per_block( share_type current_supply ) return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK, MUSE_APR_PERCENT_SHIFT_PER_BLOCK >( current_supply ); } -template< uint16_t percent > -inline share_type calc_percent_reward_per_round( share_type current_supply ) -{ - return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_ROUND, MUSE_APR_PERCENT_SHIFT_PER_ROUND >( current_supply ); -} - template< uint16_t percent > inline share_type calc_percent_reward_per_day( share_type current_supply ) { diff --git a/libraries/chain/include/muse/chain/config.hpp b/libraries/chain/include/muse/chain/config.hpp index c08ac25..05de545 100644 --- a/libraries/chain/include/muse/chain/config.hpp +++ b/libraries/chain/include/muse/chain/config.hpp @@ -153,15 +153,9 @@ #define MUSE_MINING_REWARD asset( 100, MUSE_SYMBOL ) -#define MUSE_LIQUIDITY_TIMEOUT_SEC (fc::seconds(60*60*24*7)) // After one week volume is set to 0 -#define MUSE_MIN_LIQUIDITY_REWARD_PERIOD_SEC (fc::seconds(60)) // 1 minute required on books to receive volume -#define MUSE_LIQUIDITY_REWARD_PERIOD_SEC (60*60) -#define MUSE_LIQUIDITY_REWARD_BLOCKS (MUSE_LIQUIDITY_REWARD_PERIOD_SEC/MUSE_BLOCK_INTERVAL) -#define MUSE_MIN_LIQUIDITY_REWARD (asset( 1000000*MUSE_LIQUIDITY_REWARD_BLOCKS, MUSE_SYMBOL )) // Minumum reward to be paid out to liquidity providers #define MUSE_MIN_CONTENT_REWARD MUSE_MINING_REWARD #define MUSE_MIN_CURATE_REWARD MUSE_MINING_REWARD #define MUSE_MIN_PRODUCER_REWARD MUSE_MINING_REWARD -#define MUSE_MIN_POW_REWARD MUSE_MINING_REWARD #define MUSE_ACTIVE_CHALLENGE_FEE asset( 20000, MUSE_SYMBOL ) #define MUSE_OWNER_CHALLENGE_FEE asset( 300000, MUSE_SYMBOL ) @@ -182,48 +176,25 @@ // chosen to be the maximal value such that MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK * 2**64 * 100000 < 2**128 #define MUSE_APR_PERCENT_SHIFT_PER_BLOCK 87 -#define MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK_N ( (uint64_t( 0x1E60 ) << 0x20) \ +#define MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK_N ( (uint64_t( 0x1E60 ) << 0x20) \ | (uint64_t( 0x47E3 ) << 0x10) \ | (uint64_t( 0x17B2 ) ) \ ) -#define MUSE_APR_PERCENT_SHIFT_PER_BLOCK_N 85 - - - -#define MUSE_APR_PERCENT_MULTIPLY_PER_ROUND ( (uint64_t( 0x79cc ) << 0x20 ) \ - | (uint64_t( 0xf5c7 ) << 0x10 ) \ - | (uint64_t( 0x3480 ) ) \ - ) - -#define MUSE_APR_PERCENT_SHIFT_PER_ROUND 83 - -// We have different constants for hourly rewards -// i.e. hex(int(math.expm1( math.log1p( 1 ) / HOURS_PER_YEAR ) * 2**MUSE_APR_PERCENT_SHIFT_PER_HOUR / 100000 + 0.5)) -#define MUSE_APR_PERCENT_MULTIPLY_PER_HOUR ( (uint64_t( 0x6cc1 ) << 0x20) \ - | (uint64_t( 0x39a1 ) << 0x10) \ - | (uint64_t( 0x5cbd ) ) \ - ) - -// chosen to be the maximal value such that MUSE_APR_PERCENT_MULTIPLY_PER_HOUR * 2**64 * 100000 < 2**128 -#define MUSE_APR_PERCENT_SHIFT_PER_HOUR 77 +#define MUSE_APR_PERCENT_SHIFT_PER_BLOCK_N 85 #define MUSE_APR_PERCENT_MULTIPLY_PER_DAY ( (uint64_t( 0x1347 ) << 20 ) \ | (uint64_t( 0xdcd1 ) << 10 ) \ | (uint64_t( 0x906D ) ) ) - #define MUSE_APR_PERCENT_SHIFT_PER_DAY 73 -#define MUSE_APR_PERCENT_MULTIPLY_PER_DAY_N (uint64_t( 0x1AB378B55670 ) ) - - -#define MUSE_APR_PERCENT_SHIFT_PER_DAY_N 70 +#define MUSE_APR_PERCENT_MULTIPLY_PER_DAY_N uint64_t( 0x1AB378B55670 ) +#define MUSE_APR_PERCENT_SHIFT_PER_DAY_N 70 #define MUSE_CURATE_APR_PERCENT_RESERVE 10 #define MUSE_CONTENT_APR_PERCENT 712 #define MUSE_CONTENT_APR_PERCENT_N 7500 -#define MUSE_LIQUIDITY_APR_PERCENT 0 #define MUSE_VESTING_ARP_PERCENT 143 #define MUSE_VESTING_ARP_PERCENT_N 1500 #define MUSE_PRODUCER_APR_PERCENT 95 diff --git a/libraries/chain/include/muse/chain/database.hpp b/libraries/chain/include/muse/chain/database.hpp index 9e40777..2c4af0b 100644 --- a/libraries/chain/include/muse/chain/database.hpp +++ b/libraries/chain/include/muse/chain/database.hpp @@ -260,7 +260,6 @@ namespace muse { namespace chain { void update_witness_schedule(); - void adjust_liquidity_reward( const account_object& owner, const asset& volume, bool is_bid ); string to_pretty_string( const asset& a )const; void adjust_balance( const account_object& a, const asset& delta ); void adjust_supply( const asset& delta, bool adjust_vesting = false ); @@ -317,15 +316,11 @@ namespace muse { namespace chain { void update_median_feed(); share_type claim_rshare_reward( share_type rshares, uint16_t reward_weight, asset max_muse ); - asset get_liquidity_reward()const; asset get_content_reward()const; asset get_curation_reward()const; - asset get_pow_reward()const; uint16_t get_curation_rewards_percent() const; - void pay_liquidity_reward(); - //////////////////// db_getter.cpp //////////////////// @@ -394,10 +389,6 @@ namespace muse { namespace chain { * @} */ -#ifdef IS_TEST_NET - bool liquidity_rewards_enabled = true; -#endif - protected: //Mark pop_undo() as protected -- we do not want outside calling pop_undo(); it should call pop_block() instead void pop_undo() { object_database::pop_undo(); } From 3225ec97093bae2ce7328af816f46589636926e5 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 17 Dec 2017 14:09:46 +0100 Subject: [PATCH 57/74] Replaced inflation changes from HF_1 with new inflation rate in HF_2 --- libraries/chain/database.cpp | 34 ++++++------------- libraries/chain/get_config.cpp | 8 ++--- .../chain/include/muse/chain/compound.hpp | 29 ++++++---------- libraries/chain/include/muse/chain/config.hpp | 24 ++++++------- libraries/chain/muse_evaluator.cpp | 14 +++----- programs/util/calc_inflation_constants.js | 2 +- tests/tests/reward_tests.cpp | 16 +++++---- 7 files changed, 50 insertions(+), 77 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 5bf98e3..183bbdf 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1874,31 +1874,23 @@ void database::adjust_funds(const asset& content_reward, const asset& paid_to_co } ); } - asset database::get_content_reward()const { const auto& props = get_dynamic_global_properties(); static_assert( MUSE_BLOCK_INTERVAL == 3, "this code assumes a 3-second time interval" ); - if(has_hardfork(MUSE_HARDFORK_0_1)){ - asset percent( calc_percent_reward_per_day_new< MUSE_CONTENT_APR_PERCENT_N >( props.virtual_supply.amount ), MUSE_SYMBOL ); - return std::max( percent, MUSE_MIN_CONTENT_REWARD ); - } - asset percent( calc_percent_reward_per_day< MUSE_CONTENT_APR_PERCENT >( props.virtual_supply.amount ), MUSE_SYMBOL ); - return std::max( percent, MUSE_MIN_CONTENT_REWARD ); + const auto amount = has_hardfork(MUSE_HARDFORK_0_2) ? calc_percent_reward_per_day_0_2< MUSE_CONTENT_APR_PERCENT_0_2 >( props.virtual_supply.amount ) + : calc_percent_reward_per_day< MUSE_CONTENT_APR_PERCENT >( props.virtual_supply.amount ); + return std::max( asset( amount, MUSE_SYMBOL ), MUSE_MIN_CONTENT_REWARD ); } asset database::get_vesting_reward()const { const auto& props = get_dynamic_global_properties(); static_assert( MUSE_BLOCK_INTERVAL == 3, "this code assumes a 3-second time interval" ); - - if(has_hardfork(MUSE_HARDFORK_0_1)){ - asset percent( calc_percent_reward_per_block_new< MUSE_VESTING_ARP_PERCENT_N >( props.virtual_supply.amount ), MUSE_SYMBOL ); - return percent; - } - asset percent( calc_percent_reward_per_block< MUSE_VESTING_ARP_PERCENT >( props.virtual_supply.amount ), MUSE_SYMBOL ); - return percent; + const auto amount = has_hardfork(MUSE_HARDFORK_0_2) ? calc_percent_reward_per_block_0_2< MUSE_VESTING_ARP_PERCENT_0_2 >( props.virtual_supply.amount ) + : calc_percent_reward_per_block< MUSE_VESTING_ARP_PERCENT >( props.virtual_supply.amount ); + return asset( amount, MUSE_SYMBOL ); } asset database::get_producer_reward() @@ -1906,15 +1898,9 @@ asset database::get_producer_reward() const auto& props = get_dynamic_global_properties(); static_assert( MUSE_BLOCK_INTERVAL == 3, "this code assumes a 3-second time interval" ); - asset percent; - if( has_hardfork(MUSE_HARDFORK_0_1)){ - asset p (calc_percent_reward_per_block_new< MUSE_PRODUCER_APR_PERCENT_N >( props.virtual_supply.amount), MUSE_SYMBOL ); - percent = p; - }else { - asset p (calc_percent_reward_per_block< MUSE_PRODUCER_APR_PERCENT >( props.virtual_supply.amount ), MUSE_SYMBOL); - percent = p; - } - auto pay = std::max( percent, MUSE_MIN_PRODUCER_REWARD ); + const auto amount = has_hardfork(MUSE_HARDFORK_0_2) ? calc_percent_reward_per_block_0_2< MUSE_PRODUCER_APR_PERCENT_0_2 >( props.virtual_supply.amount) + : calc_percent_reward_per_block< MUSE_PRODUCER_APR_PERCENT >( props.virtual_supply.amount ); + const auto pay = std::max( asset( amount, MUSE_SYMBOL ), MUSE_MIN_PRODUCER_REWARD ); const auto& witness_account = get_account( props.current_witness ); /// pay witness in vesting shares @@ -1924,7 +1910,7 @@ asset database::get_producer_reward() } else { - modify( get_account( witness_account.name), [&]( account_object& a ) + modify( get_account( witness_account.name), [&pay]( account_object& a ) { a.balance += pay; } ); diff --git a/libraries/chain/get_config.cpp b/libraries/chain/get_config.cpp index 0525ebe..3b7f179 100644 --- a/libraries/chain/get_config.cpp +++ b/libraries/chain/get_config.cpp @@ -27,10 +27,10 @@ fc::variant_object get_config() result["MUSE_100_PERCENT"] = MUSE_100_PERCENT; result["MUSE_1_PERCENT"] = MUSE_1_PERCENT; result["MUSE_ADDRESS_PREFIX"] = MUSE_ADDRESS_PREFIX; - result["MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK"] = MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK_N; - result["MUSE_APR_PERCENT_MULTIPLY_PER_DAY"] = MUSE_APR_PERCENT_MULTIPLY_PER_DAY_N; - result["MUSE_APR_PERCENT_SHIFT_PER_BLOCK"] = MUSE_APR_PERCENT_SHIFT_PER_BLOCK_N; - result["MUSE_APR_PERCENT_SHIFT_PER_DAY"] = MUSE_APR_PERCENT_SHIFT_PER_DAY_N; + result["MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK"] = MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK_0_2; + result["MUSE_APR_PERCENT_MULTIPLY_PER_DAY"] = MUSE_APR_PERCENT_MULTIPLY_PER_DAY_0_2; + result["MUSE_APR_PERCENT_SHIFT_PER_BLOCK"] = MUSE_APR_PERCENT_SHIFT_PER_BLOCK_0_2; + result["MUSE_APR_PERCENT_SHIFT_PER_DAY"] = MUSE_APR_PERCENT_SHIFT_PER_DAY_0_2; result["MUSE_BANDWIDTH_AVERAGE_WINDOW_SECONDS"] = MUSE_BANDWIDTH_AVERAGE_WINDOW_SECONDS; result["MUSE_BANDWIDTH_PRECISION"] = MUSE_BANDWIDTH_PRECISION; result["MUSE_BLOCKCHAIN_HARDFORK_VERSION"] = MUSE_BLOCKCHAIN_HARDFORK_VERSION; diff --git a/libraries/chain/include/muse/chain/compound.hpp b/libraries/chain/include/muse/chain/compound.hpp index 1c3411f..1104a65 100644 --- a/libraries/chain/include/muse/chain/compound.hpp +++ b/libraries/chain/include/muse/chain/compound.hpp @@ -15,36 +15,28 @@ share_type calc_percent_reward( share_type current_supply ) static_assert( shift_constant > 0, "shift constant cannot be zero" ); static_assert( shift_constant < 128, "shift constant is implausibly large, re-check your arguments" ); static_assert( multiply_constant > 256, "multiply constant is implausibly small, re-check your arguments" ); - static_assert( multiply_constant < UINT64_MAX / (10 * uint64_t( MUSE_100_PERCENT )), "multiply constant is too large, we may be in danger of overflow" ); - //static_assert( (percent == 0) || (percent > MUSE_1_PERCENT), "percent is smaller than 1%, re-check your arguments" ); + static_assert( multiply_constant < UINT64_MAX / uint64_t( MUSE_100_PERCENT ), "multiply constant is too large, we may be in danger of overflow" ); static_assert( percent <= MUSE_100_PERCENT, "percent is implausibly large, re-check your arguments (if you really mean to do this, you should revise the overflow check above accordingly)" ); static const uint128_t half = uint128_t(1) << (shift_constant - 1); - uint128_t reward = current_supply.value; //18000000000000 - reward *= (percent * multiply_constant); // compile-time constant, fits in 64 bits //95*18000000000000*133921203762304 + uint128_t reward = current_supply.value; + reward *= (percent * multiply_constant); // compile-time constant, fits in 64 bits reward += half; // round to nearest whole integer instead of truncating - reward >>= shift_constant; //1480 + reward >>= shift_constant; return reward.to_uint64(); } -// (1+x)^REWARDS_PER_YEAR = 1.095 -// ln (1+x) * REWARDS_PER_YEAR = ln(1.095) -// ln (1+x) = ln(1.095) / REWARDS_PER_YEAR -// x = exp( ln(1.095) / REWARDS_PER_YEAR ) - 1 -// Block per year - 10512000 - - template< uint16_t percent > -inline share_type calc_percent_reward_per_block_new( share_type current_supply ) +inline share_type calc_percent_reward_per_block( share_type current_supply ) { - return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK_N, MUSE_APR_PERCENT_SHIFT_PER_BLOCK_N >( current_supply ); + return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK, MUSE_APR_PERCENT_SHIFT_PER_BLOCK >( current_supply ); } template< uint16_t percent > -inline share_type calc_percent_reward_per_block( share_type current_supply ) +inline share_type calc_percent_reward_per_block_0_2( share_type current_supply ) { - return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK, MUSE_APR_PERCENT_SHIFT_PER_BLOCK >( current_supply ); + return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK_0_2, MUSE_APR_PERCENT_SHIFT_PER_BLOCK_0_2 >( current_supply ); } template< uint16_t percent > @@ -53,11 +45,10 @@ inline share_type calc_percent_reward_per_day( share_type current_supply ) return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_DAY, MUSE_APR_PERCENT_SHIFT_PER_DAY >( current_supply ); } - template< uint16_t percent > -inline share_type calc_percent_reward_per_day_new( share_type current_supply ) +inline share_type calc_percent_reward_per_day_0_2( share_type current_supply ) { - return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_DAY_N, MUSE_APR_PERCENT_SHIFT_PER_DAY_N >( current_supply ); + return calc_percent_reward< percent, MUSE_APR_PERCENT_MULTIPLY_PER_DAY_0_2, MUSE_APR_PERCENT_SHIFT_PER_DAY_0_2 >( current_supply ); } } } diff --git a/libraries/chain/include/muse/chain/config.hpp b/libraries/chain/include/muse/chain/config.hpp index 05de545..5d22bdb 100644 --- a/libraries/chain/include/muse/chain/config.hpp +++ b/libraries/chain/include/muse/chain/config.hpp @@ -166,6 +166,9 @@ #define MUSE_PAYOUT_TIME_OF_DAY 2 #define MUSE_MAX_LISTENING_PERIOD 3600 +// For the following constants, see comments in compound.hpp and the +// script programs/util/calc_inflation_constants.js + // 5ccc e802 de5f // int(expm1( log1p( 1 ) / BLOCKS_PER_YEAR ) * 2**MUSE_APR_PERCENT_SHIFT_PER_BLOCK / 100000 + 0.5) // we use 100000 here instead of 10000 because we end up creating an additional 9x for vesting @@ -176,29 +179,24 @@ // chosen to be the maximal value such that MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK * 2**64 * 100000 < 2**128 #define MUSE_APR_PERCENT_SHIFT_PER_BLOCK 87 -#define MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK_N ( (uint64_t( 0x1E60 ) << 0x20) \ - | (uint64_t( 0x47E3 ) << 0x10) \ - | (uint64_t( 0x17B2 ) ) \ - ) -#define MUSE_APR_PERCENT_SHIFT_PER_BLOCK_N 85 - +#define MUSE_APR_PERCENT_MULTIPLY_PER_BLOCK_0_2 (0x3e214e64a7380ULL) +#define MUSE_APR_PERCENT_SHIFT_PER_BLOCK_0_2 91 #define MUSE_APR_PERCENT_MULTIPLY_PER_DAY ( (uint64_t( 0x1347 ) << 20 ) \ | (uint64_t( 0xdcd1 ) << 10 ) \ | (uint64_t( 0x906D ) ) ) #define MUSE_APR_PERCENT_SHIFT_PER_DAY 73 -#define MUSE_APR_PERCENT_MULTIPLY_PER_DAY_N uint64_t( 0x1AB378B55670 ) -#define MUSE_APR_PERCENT_SHIFT_PER_DAY_N 70 - +#define MUSE_APR_PERCENT_MULTIPLY_PER_DAY_0_2 (0x369c2966a19c8ULL) +#define MUSE_APR_PERCENT_SHIFT_PER_DAY_0_2 76 #define MUSE_CURATE_APR_PERCENT_RESERVE 10 -#define MUSE_CONTENT_APR_PERCENT 712 -#define MUSE_CONTENT_APR_PERCENT_N 7500 +#define MUSE_CONTENT_APR_PERCENT 712 +#define MUSE_CONTENT_APR_PERCENT_0_2 5000 #define MUSE_VESTING_ARP_PERCENT 143 -#define MUSE_VESTING_ARP_PERCENT_N 1500 +#define MUSE_VESTING_ARP_PERCENT_0_2 3000 #define MUSE_PRODUCER_APR_PERCENT 95 -#define MUSE_PRODUCER_APR_PERCENT_N 1000 +#define MUSE_PRODUCER_APR_PERCENT_0_2 2000 #define MUSE_CURATION_THRESHOLD1 1000 #define MUSE_CURATION_THRESHOLD2 2000 diff --git a/libraries/chain/muse_evaluator.cpp b/libraries/chain/muse_evaluator.cpp index c347018..f646c6e 100644 --- a/libraries/chain/muse_evaluator.cpp +++ b/libraries/chain/muse_evaluator.cpp @@ -349,7 +349,7 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) const content_object* itr = &content; bool two_sides = itr->comp_meta.third_party_publishers; - if(db().has_hardfork(MUSE_HARDFORK_0_1)) + if( db().has_hardfork(MUSE_HARDFORK_0_2) ) FC_ASSERT( two_sides || o.side == o.master, "Cannot edit composition side data when only one side has been defined" ); else FC_ASSERT( !two_sides || o.side == o.master, "Cannot edit composition side data when only one side has been defined" ); @@ -358,14 +358,10 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) FC_ASSERT( fc::is_utf8(*o.track_meta->json_metadata) && fc::json::is_valid(*o.track_meta->json_metadata), "JSON Metadata not valid JSON" ); for( const distribution& d : o.new_distributions ) - { - const auto& payee = db().get_account( d.payee ); - } + db().get_account( d.payee ); // just to ensure that d.payee account exists for( const management_vote& m : o.new_management ) - { - const auto& voter = db().get_account(m.voter); - } + db().get_account(m.voter); // just to ensure that m.voter account exists bool redistribute_master = ( o.side == o.master && o.new_distributions.size() > 0 && itr->distributions_master.size() == 0 ); @@ -421,7 +417,7 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) } } con.comp_meta.third_party_publishers = third_party_flag; - if(db().has_hardfork(MUSE_HARDFORK_0_1)) { + if( db().has_hardfork(MUSE_HARDFORK_0_2) ) { if( o.new_playing_reward > 0 ) con.playing_reward = o.new_playing_reward; if( o.new_publishers_share > 0 ) @@ -450,7 +446,7 @@ void content_update_evaluator::do_apply( const content_update_operation& o ) void content_disable_evaluator::do_apply( const content_disable_operation& o ) { try{ - FC_ASSERT( db().has_hardfork( MUSE_HARDFORK_0_2 ) ); // remove after HF time + FC_ASSERT( db().has_hardfork( MUSE_HARDFORK_0_2 ) ); // TODO remove after HF time const auto& content = db().get_content( o.url ); diff --git a/programs/util/calc_inflation_constants.js b/programs/util/calc_inflation_constants.js index 0873638..6f00712 100755 --- a/programs/util/calc_inflation_constants.js +++ b/programs/util/calc_inflation_constants.js @@ -6,7 +6,7 @@ require("console"); var MUSE_100_PCT = 10000; //var TOTAL_INFLATION = 1; -var TOTAL_INFLATION = .095; +var TOTAL_INFLATION = .0475; var MAX_MULT = Math.pow(2,64) / MUSE_100_PCT; diff --git a/tests/tests/reward_tests.cpp b/tests/tests/reward_tests.cpp index 1dfa4a1..51a94e8 100644 --- a/tests/tests/reward_tests.cpp +++ b/tests/tests/reward_tests.cpp @@ -45,13 +45,15 @@ BOOST_AUTO_TEST_SUITE( reward_tests ) * slightly lower). */ +#define TARGET_INFLATION_PERCENT (4.75) + BOOST_AUTO_TEST_CASE( witness_reward_test ) { int64_t supply = 18000000LL * 1000000; int64_t expected_witness_reward = supply * .0095; - int64_t avg_supply = 1.0475 * supply; - int64_t avg_witness_reward = calc_percent_reward_per_block_new( avg_supply ).value; + int64_t avg_supply = (1 + TARGET_INFLATION_PERCENT / 200) * supply; + int64_t avg_witness_reward = calc_percent_reward_per_block_0_2( avg_supply ).value; int64_t witness_reward_per_year = avg_witness_reward * MUSE_BLOCKS_PER_YEAR; std::cerr << "Expected witness reward: " << expected_witness_reward @@ -66,8 +68,8 @@ BOOST_AUTO_TEST_CASE( vesting_reward_test ) int64_t supply = 18000000LL * 1000000; int64_t expected_vesting_reward = supply * .01425; - int64_t avg_supply = 1.0475 * supply; - int64_t avg_vesting_reward = calc_percent_reward_per_block_new( avg_supply ).value; + int64_t avg_supply = (1 + TARGET_INFLATION_PERCENT / 200) * supply; + int64_t avg_vesting_reward = calc_percent_reward_per_block_0_2( avg_supply ).value; int64_t vesting_reward_per_year = avg_vesting_reward * MUSE_BLOCKS_PER_YEAR; std::cerr << "Expected vesting reward: " << expected_vesting_reward @@ -80,10 +82,10 @@ BOOST_AUTO_TEST_CASE( vesting_reward_test ) BOOST_AUTO_TEST_CASE( content_reward_test ) { int64_t supply = 18000000LL * 1000000; - int64_t expected_content_reward = supply * .07125; + int64_t expected_content_reward = supply * .02375; - int64_t avg_supply = 1.0475 * supply; - int64_t avg_content_reward = calc_percent_reward_per_day_new( avg_supply ).value; + int64_t avg_supply = (1 + TARGET_INFLATION_PERCENT / 200) * supply; + int64_t avg_content_reward = calc_percent_reward_per_day_0_2( avg_supply ).value; int64_t content_reward_per_year = avg_content_reward * 365; std::cerr << "Expected content reward: " << expected_content_reward From 5db6e537296857640f52aa58a13157d43ff380e5 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 17 Dec 2017 14:11:26 +0100 Subject: [PATCH 58/74] Fixed compiler warnings --- libraries/chain/database.cpp | 8 ++++---- libraries/chain/hardfork.d/0-preamble.hf | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 183bbdf..07e59c9 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -3227,9 +3227,9 @@ void database::set_hardfork( uint32_t hardfork, bool apply_now ) { auto const& hardforks = hardfork_property_id_type()( *this ); - for( int i = hardforks.last_hardfork + 1; i <= hardfork && i <= MUSE_NUM_HARDFORKS; i++ ) + for( uint32_t i = hardforks.last_hardfork + 1; i <= hardfork && i <= MUSE_NUM_HARDFORKS; i++ ) { - modify( hardforks, [&]( hardfork_property_object& hpo ) + modify( hardforks, [i,this]( hardfork_property_object& hpo ) { hpo.next_hardfork = _hardfork_versions[i]; hpo.next_hardfork_time = head_block_time(); @@ -3250,7 +3250,7 @@ void database::apply_hardfork( uint32_t hardfork ) { // This is for unit tests only. Evil. const auto& initminer = get_account( MUSE_INIT_MINER_NAME ); - if ( initminer.balance.amount.value >= 10 * asset::static_precision() ) + if ( initminer.balance.amount.value >= 10 * asset::static_precision() ) // not true in mainnet { custom_operation test_op; string op_msg = "Test: Hardfork applied"; @@ -3265,7 +3265,7 @@ void database::apply_hardfork( uint32_t hardfork ) break; } - modify( hardfork_property_id_type()( *this ), [&]( hardfork_property_object& hfp ) + modify( hardfork_property_id_type()( *this ), [hardfork,this]( hardfork_property_object& hfp ) { FC_ASSERT( hardfork == hfp.last_hardfork + 1, "Hardfork being applied out of order", ("hardfork",hardfork)("hfp.last_hardfork",hfp.last_hardfork) ); FC_ASSERT( hfp.processed_hardforks.size() == hardfork, "Hardfork being applied out of order" ); diff --git a/libraries/chain/hardfork.d/0-preamble.hf b/libraries/chain/hardfork.d/0-preamble.hf index d842cbc..91135f9 100644 --- a/libraries/chain/hardfork.d/0-preamble.hf +++ b/libraries/chain/hardfork.d/0-preamble.hf @@ -21,7 +21,7 @@ class hardfork_property_object : public abstract_object< hardfork_property_objec static const uint8_t type_id = impl_hardfork_property_object_type; vector< fc::time_point_sec > processed_hardforks; - int last_hardfork = 0; + unsigned int last_hardfork = 0; hardfork_version current_hardfork_version; hardfork_version next_hardfork; fc::time_point_sec next_hardfork_time; From e5d2d5e365a9ed0ceaa3a42401c96eb5b6c3f09a Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 19 Dec 2017 10:43:03 +0100 Subject: [PATCH 59/74] Disable curation rewards --- libraries/chain/database.cpp | 94 +++++++++++++++++++----------------- tests/tests/muse_tests.cpp | 4 +- 2 files changed, 51 insertions(+), 47 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 07e59c9..1528a63 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1765,7 +1765,9 @@ asset database::pay_to_content(content_id_type content, asset payout, streaming_ {try{ asset paid (0); const content_object& co = get( content ); //content_id_type(content)(*this); //*get_index_type().indices().get().find(content); - asset curation_reserve = payout * MUSE_CURATE_APR_PERCENT_RESERVE / 100; + asset curation_reserve; + if( !has_hardfork(MUSE_HARDFORK_0_2) ) + curation_reserve = payout * MUSE_CURATE_APR_PERCENT_RESERVE / 100; payout = payout - curation_reserve; asset platform_reward = payout; platform_reward.amount = platform_reward.amount * co.playing_reward / 10000; @@ -1782,53 +1784,55 @@ asset database::pay_to_content(content_id_type content, asset payout, streaming_ paid += comp_reward; paid += platform_reward; - const content_stats_object& c_stat = get (content_stats_id_type(0)); - const bool above_thr1 = (c_stat.current_plays_threshold1 <= co.times_played_24); - const bool above_thr2 = (c_stat.current_plays_threshold2 <= co.times_played_24); - bool pay_curators = false; - bool reset_curation_rewards = false; - - modify(co,[above_thr1,above_thr2,&pay_curators,&reset_curation_rewards,this](content_object& c){ - if(c.curation_rewards){ - if(above_thr2) { //still in top 2000 - if(head_block_time() < c.curation_reward_expiration) - { - pay_curators = true; - } - }else{ - c.curation_rewards = false; - reset_curation_rewards = true; - } - }else{ //not in top 1000 yet... - if(above_thr1){ - c.curation_rewards = true; - c.curation_reward_expiration = head_block_time() + MUSE_CURATION_DURATION; - pay_curators = true; - } - } - if(c.times_played_24) - --c.times_played_24; - }); + if( !has_hardfork(MUSE_HARDFORK_0_2) ) { + const content_stats_object& c_stat = get (content_stats_id_type(0)); + const bool above_thr1 = (c_stat.current_plays_threshold1 <= co.times_played_24); + const bool above_thr2 = (c_stat.current_plays_threshold2 <= co.times_played_24); + bool pay_curators = false; + bool reset_curation_rewards = false; + + modify(co,[above_thr1,above_thr2,&pay_curators,&reset_curation_rewards,this](content_object& c){ + if(c.curation_rewards){ + if(above_thr2) { //still in top 2000 + if(head_block_time() < c.curation_reward_expiration) + { + pay_curators = true; + } + }else{ + c.curation_rewards = false; + reset_curation_rewards = true; + } + }else{ //not in top 1000 yet... + if(above_thr1){ + c.curation_rewards = true; + c.curation_reward_expiration = head_block_time() + MUSE_CURATION_DURATION; + pay_curators = true; + } + } + if(c.times_played_24) + --c.times_played_24; + }); - const auto& vidx = get_index_type().indices().get< by_reward_flag_update > (); - if(reset_curation_rewards){ - auto vitr = vidx.lower_bound( boost::make_tuple( true, time_point_sec(0) ) ); - while( vitr!=vidx.end() && vitr->marked_for_curation_reward == true ) { - modify(*vitr, [](content_vote_object &vo) { - vo.marked_for_curation_reward = false; - }); - ++vitr; + const auto& vidx = get_index_type().indices().get< by_reward_flag_update > (); + if(reset_curation_rewards){ + auto vitr = vidx.lower_bound( boost::make_tuple( true, time_point_sec(0) ) ); + while( vitr!=vidx.end() && vitr->marked_for_curation_reward == true ) { + modify(*vitr, [](content_vote_object &vo) { + vo.marked_for_curation_reward = false; + }); + ++vitr; + } } - } - if(pay_curators){ - auto vitr = vidx.lower_bound( boost::make_tuple( true, time_point_sec(0) ) ); + if(pay_curators){ + auto vitr = vidx.lower_bound( boost::make_tuple( true, time_point_sec(0) ) ); - while( vitr!=vidx.end() && vitr->marked_for_curation_reward == true ) { - asset cp = curation_reserve / 10; - curation_reserve = curation_reserve - cp; - pay_to_curator(co, vitr->voter, cp ); - paid += cp; - ++vitr; + while( vitr!=vidx.end() && vitr->marked_for_curation_reward == true ) { + asset cp = curation_reserve / 10; + curation_reserve = curation_reserve - cp; + pay_to_curator(co, vitr->voter, cp ); + paid += cp; + ++vitr; + } } } return paid; diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 7290a77..e65192f 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -636,7 +636,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) { const auto& dgpo = db.get_dynamic_global_properties(); - asset curation_reserve = asset( daily_content_reward.amount.value / 10, MUSE_SYMBOL ); + asset curation_reserve = db.has_hardfork(MUSE_HARDFORK_0_2) ? asset(0) : asset( daily_content_reward.amount.value / 10, MUSE_SYMBOL ); daily_content_reward -= curation_reserve; asset platform_reward = asset( daily_content_reward.amount.value * 11 / MUSE_100_PERCENT, MUSE_SYMBOL ); // playing reward daily_content_reward -= platform_reward; @@ -996,7 +996,7 @@ BOOST_AUTO_TEST_CASE( multi_test ) { const auto& dgpo = db.get_dynamic_global_properties(); - asset curation_reserve = asset( daily_content_reward.amount.value / 10, MUSE_SYMBOL ); + asset curation_reserve = db.has_hardfork(MUSE_HARDFORK_0_2) ? asset(0) : asset( daily_content_reward.amount.value / 10, MUSE_SYMBOL ); daily_content_reward -= curation_reserve; asset platform_reward = asset( daily_content_reward.amount.value * 11 / MUSE_100_PERCENT, MUSE_SYMBOL ); // playing reward daily_content_reward -= platform_reward; From 4e43dad585bb44490662ba4791b6631b47fbb902 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 22 Dec 2017 17:35:22 +0100 Subject: [PATCH 60/74] Dont compute thresholds after HF_2, they are no longer required --- libraries/chain/database.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 1528a63..f727706 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1591,12 +1591,14 @@ asset database::process_content_cashout( const asset& content_reward ) asset total_payout = has_hardfork( MUSE_HARDFORK_0_2 ) ? content_reward : get_content_reward(); - //find thresholds - const auto& cridx = get_index_type< content_index >().indices().get< by_popularity >(); - auto critr = cridx.rbegin(); - uint32_t i = 0; - uint32_t current_plays_threshold1; - uint32_t current_plays_threshold2; + if( !has_hardfork( MUSE_HARDFORK_0_2 ) ) + { + //find thresholds + const auto& cridx = get_index_type< content_index >().indices().get< by_popularity >(); + auto critr = cridx.rbegin(); + uint32_t i = 0; + uint32_t current_plays_threshold1; + uint32_t current_plays_threshold2; while ( i < MUSE_CURATION_THRESHOLD1 && critr != cridx.rend() ) { ++i; ++critr; @@ -1619,6 +1621,7 @@ asset database::process_content_cashout( const asset& content_reward ) cso.current_plays_threshold1 = current_plays_threshold1; cso.current_plays_threshold2 = current_plays_threshold2; }); + } const auto& ridx = get_index_type().indices().get(); auto itr = ridx.begin(); From 37439f856a0d4aaad88746c38f131889bb5d3201 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 22 Dec 2017 18:05:06 +0100 Subject: [PATCH 61/74] Allow more than one streaming report per block --- .../include/muse/chain/streaming_platform_objects.hpp | 7 ++++++- libraries/chain/muse_evaluator.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libraries/chain/include/muse/chain/streaming_platform_objects.hpp b/libraries/chain/include/muse/chain/streaming_platform_objects.hpp index 5b4080b..cc2740c 100644 --- a/libraries/chain/include/muse/chain/streaming_platform_objects.hpp +++ b/libraries/chain/include/muse/chain/streaming_platform_objects.hpp @@ -136,7 +136,12 @@ namespace muse { namespace chain { member > >, - ordered_unique< tag, member > + ordered_unique< tag, + composite_key< report_object, + member, + member + > + > > > report_object_multi_index_type; typedef generic_index< report_object, report_object_multi_index_type > report_index; diff --git a/libraries/chain/muse_evaluator.cpp b/libraries/chain/muse_evaluator.cpp index f646c6e..c8206f8 100644 --- a/libraries/chain/muse_evaluator.cpp +++ b/libraries/chain/muse_evaluator.cpp @@ -68,6 +68,14 @@ void streaming_platform_report_evaluator::do_apply ( const streaming_platform_re const auto& content = db().get_content( o.content ); FC_ASSERT( !content.disabled ); + if ( !db().has_hardfork(MUSE_HARDFORK_0_2) ) + { + // TODO: remove after HF date + const auto& reports = db().get_index_type().indices().get(); + const auto& now = reports.find( db().head_block_time() ); + FC_ASSERT( now == reports.end() ); + } + db().create< report_object>( [&](report_object& ro) { ro.consumer = consumer.id; ro.streaming_platform = sp.id; From 15e16ec3633908c72534adb6a18d0b0928d1679d Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 22 Dec 2017 18:24:00 +0100 Subject: [PATCH 62/74] Implemented separation of full / part-time users --- libraries/chain/database.cpp | 17 +++++-- tests/tests/muse_tests.cpp | 98 +++++++++++++++++++++++++++++------- 2 files changed, 93 insertions(+), 22 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index f727706..ffa3b30 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1626,8 +1626,14 @@ asset database::process_content_cashout( const asset& content_reward ) const auto& ridx = get_index_type().indices().get(); auto itr = ridx.begin(); std::set customers; - while ( itr != ridx.end() && itr->created <= now ){ - customers.insert(itr->consumer); + uint64_t full_time = 0; + while ( itr != ridx.end() && itr->created <= now ) // FIXME: doesn't scale + { + if( customers.insert(itr->consumer).second ) + { + const auto& user = get( itr->consumer ); + full_time += std::min( user.total_listening_time, uint32_t(3600) ); + } ++itr; } itr = ridx.begin(); @@ -1637,7 +1643,12 @@ asset database::process_content_cashout( const asset& content_reward ) ilog("process content cashout ", ("consumer.total_listening_time", consumer.total_listening_time)); edump((consumer)); FC_ASSERT( consumer.total_listening_time > 0 ); - asset pay_reserve = total_payout * itr->play_time / customers.size() / consumer.total_listening_time; + asset pay_reserve = total_payout * itr->play_time; + if( !has_hardfork( MUSE_HARDFORK_0_2 ) ) + pay_reserve = pay_reserve / customers.size(); + else + pay_reserve = pay_reserve * std::min( consumer.total_listening_time, uint32_t(3600) ) / full_time; + pay_reserve = pay_reserve / consumer.total_listening_time; paid += pay_to_content(itr->content, pay_reserve, itr->streaming_platform ); modify(consumer, [&itr](account_object & a){ a.total_listening_time -= itr->play_time; diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index e65192f..4cf4afa 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) muse::app::database_api dbapi(db); - ACTORS( (alice)(suzy)(uhura)(paula)(penny)(martha)(muriel)(colette)(veronica)(vici) ); + ACTORS( (alice)(suzy)(uhura)(paula)(penny)(priscilla)(martha)(muriel)(colette)(cora)(coreen)(veronica)(vici) ); generate_block(); @@ -309,6 +309,19 @@ BOOST_AUTO_TEST_CASE( simple_test ) tx.operations.clear(); tx.operations.push_back( cop ); db.push_transaction( tx, database::skip_transaction_signatures ); + + cop.url = "ipfs://abcdef2"; + cop.playing_reward = 11; + cop.publishers_share = 1; + tx.operations.clear(); + tx.operations.push_back( cop ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + cop.url = "ipfs://abcdef3"; + cop.distributions.begin()->payee = "priscilla"; + tx.operations.clear(); + tx.operations.push_back( cop ); + db.push_transaction( tx, database::skip_transaction_signatures ); } // --------- Verify content ------------ { @@ -384,7 +397,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) spro.streaming_platform = "suzy"; spro.consumer = "colette"; spro.content = "ipfs://abcdef1"; - spro.play_time = 100; + spro.play_time = 7200; spro.streaming_platform = "x"; FAIL( "with invalid platform name", spro ); @@ -406,11 +419,25 @@ BOOST_AUTO_TEST_CASE( simple_test ) tx.operations.clear(); tx.operations.push_back( spro ); db.push_transaction( tx, database::skip_transaction_signatures ); + + spro.content = "ipfs://abcdef2"; + spro.consumer = "cora"; + spro.play_time = 3600; + tx.operations.clear(); + tx.operations.push_back( spro ); + db.push_transaction( tx, database::skip_transaction_signatures ); + + spro.content = "ipfs://abcdef3"; + spro.consumer = "coreen"; + spro.play_time = 1800; + tx.operations.clear(); + tx.operations.push_back( spro ); + db.push_transaction( tx, database::skip_transaction_signatures ); } // --------- Verify playtime ------------ { const content_object& song1 = db.get_content( "ipfs://abcdef1" ); - BOOST_CHECK_EQUAL( 100, colette_id(db).total_listening_time ); + BOOST_CHECK_EQUAL( 7200, colette_id(db).total_listening_time ); BOOST_CHECK_EQUAL( 1, song1.times_played ); BOOST_CHECK_EQUAL( 1, song1.times_played_24 ); @@ -420,7 +447,7 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( colette_id, reports[0].consumer ); BOOST_CHECK_EQUAL( song1.id, reports[0].content ); BOOST_CHECK_EQUAL( db.head_block_time().sec_since_epoch(), reports[0].created.sec_since_epoch() ); - BOOST_CHECK_EQUAL( 100, reports[0].play_time ); + BOOST_CHECK_EQUAL( 7200, reports[0].play_time ); } const auto& played_at = db.head_block_time(); @@ -591,9 +618,12 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 0, uhura_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, penny_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, priscilla_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, martha_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, muriel_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, colette_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, cora_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, coreen_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, veronica_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).balance.amount.value ); @@ -602,9 +632,12 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 0, uhura_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, paula_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, penny_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, priscilla_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, martha_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, muriel_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, colette_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, cora_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, coreen_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, veronica_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).mbd_balance.amount.value ); @@ -613,9 +646,12 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 100000, uhura_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, paula_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, penny_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, priscilla_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, martha_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, muriel_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, colette_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, cora_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, coreen_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, veronica_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, vici_id(db).vesting_shares.amount.value ); @@ -624,9 +660,12 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 0, uhura_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, paula_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, penny_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, priscilla_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, martha_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, muriel_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, colette_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, cora_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, coreen_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); @@ -636,41 +675,56 @@ BOOST_AUTO_TEST_CASE( simple_test ) { const auto& dgpo = db.get_dynamic_global_properties(); - asset curation_reserve = db.has_hardfork(MUSE_HARDFORK_0_2) ? asset(0) : asset( daily_content_reward.amount.value / 10, MUSE_SYMBOL ); - daily_content_reward -= curation_reserve; - asset platform_reward = asset( daily_content_reward.amount.value * 11 / MUSE_100_PERCENT, MUSE_SYMBOL ); // playing reward - daily_content_reward -= platform_reward; - asset comp_reward = asset( daily_content_reward.amount.value * 1 / MUSE_100_PERCENT, MUSE_SYMBOL ); // publishers_share - asset master_reward = daily_content_reward - comp_reward; + asset full_reward = daily_content_reward * 2 / 5; + asset half_reward = daily_content_reward * 1 / 5; + asset full_platform_reward = asset( full_reward.amount.value * 11 / MUSE_100_PERCENT, MUSE_SYMBOL ); // playing reward + asset half_platform_reward = asset( half_reward.amount.value * 11 / MUSE_100_PERCENT, MUSE_SYMBOL ); // playing reward + full_reward -= full_platform_reward; + half_reward -= half_platform_reward; + asset full_comp_reward = asset( full_reward.amount.value * 1 / MUSE_100_PERCENT, MUSE_SYMBOL ); // publishers_share + asset master_reward = full_reward - full_comp_reward; const content_object& song1 = db.get_content( "ipfs://abcdef1" ); + const content_object& song2 = db.get_content( "ipfs://abcdef2" ); + const content_object& song3 = db.get_content( "ipfs://abcdef3" ); BOOST_CHECK_EQUAL( 0, song1.accumulated_balance_master.amount.value ); - BOOST_CHECK_EQUAL( comp_reward.amount.value, song1.accumulated_balance_comp.amount.value ); - BOOST_CHECK_EQUAL( comp_reward.asset_id, song1.accumulated_balance_comp.asset_id ); + BOOST_CHECK_EQUAL( 0, song2.accumulated_balance_master.amount.value ); + BOOST_CHECK_EQUAL( 0, song3.accumulated_balance_master.amount.value ); + BOOST_CHECK_EQUAL( full_comp_reward.amount.value, song1.accumulated_balance_comp.amount.value ); + BOOST_CHECK_EQUAL( full_comp_reward.asset_id, song1.accumulated_balance_comp.asset_id ); + BOOST_CHECK_EQUAL( 0, song2.accumulated_balance_comp.amount.value ); + BOOST_CHECK_EQUAL( 0, song3.accumulated_balance_comp.amount.value ); BOOST_CHECK_EQUAL( master_reward.amount.value, penny_id(db).balance.amount.value ); - BOOST_CHECK_EQUAL( 100000 + (platform_reward * dgpo.get_vesting_share_price()).amount.value, suzy_id(db).vesting_shares.amount.value ); - BOOST_CHECK_EQUAL( curation_reserve.amount.value / 10, veronica_id(db).balance.amount.value ); - BOOST_CHECK_EQUAL( ( curation_reserve.amount.value - curation_reserve.amount.value / 10 ) / 10, vici_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( full_reward.amount.value, paula_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( half_reward.amount.value, priscilla_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 100000 + 2 * (full_platform_reward * dgpo.get_vesting_share_price()).amount.value + + (half_platform_reward * dgpo.get_vesting_share_price()).amount.value, suzy_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 0, alice_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, suzy_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, uhura_id(db).balance.amount.value ); - BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); + //BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); //BOOST_CHECK_EQUAL( 0, penny_id(db).balance.amount.value ); + //BOOST_CHECK_EQUAL( 0, priscilla_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, martha_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, muriel_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, colette_id(db).balance.amount.value ); - //BOOST_CHECK_EQUAL( 0, veronica_id(db).balance.amount.value ); - //BOOST_CHECK_EQUAL( 0, vici_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, cora_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, coreen_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, veronica_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 0, vici_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, alice_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, suzy_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, uhura_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, paula_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, penny_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, priscilla_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, martha_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, muriel_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, colette_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, cora_id(db).mbd_balance.amount.value ); + BOOST_CHECK_EQUAL( 0, coreen_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, veronica_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).mbd_balance.amount.value ); @@ -679,9 +733,12 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 100000, uhura_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, paula_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, penny_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, priscilla_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, martha_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, muriel_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, colette_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, cora_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 100000, coreen_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, veronica_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, vici_id(db).vesting_shares.amount.value ); @@ -690,9 +747,12 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 0, uhura_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, paula_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, penny_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, priscilla_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, martha_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, muriel_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, colette_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, cora_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, coreen_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); } @@ -859,7 +919,7 @@ BOOST_AUTO_TEST_CASE( multi_test ) spro.streaming_platform = "suzy"; spro.consumer = "colette"; spro.content = "ipfs://abcdef9"; - spro.play_time = 100; + spro.play_time = 3600; BOOST_TEST_MESSAGE( "--- Test success" ); tx.operations.clear(); From 0f729384b44c9e08e2537d6ce06c61d832dd75f5 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 23 Dec 2017 14:42:37 +0100 Subject: [PATCH 63/74] Fixed memory leak, see steem PR 372 --- libraries/chain/database.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 1b24d98..ed457a7 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -3095,8 +3095,8 @@ void database::clear_expired_transactions() //Transactions must have expired by at least two forking windows in order to be removed. auto& transaction_idx = static_cast(get_mutable_index(implementation_ids, impl_transaction_object_type)); const auto& dedupe_index = transaction_idx.indices().get(); - while( (!dedupe_index.empty()) && (head_block_time() > dedupe_index.rbegin()->trx.expiration) ) - transaction_idx.remove(*dedupe_index.rbegin()); + while( (!dedupe_index.empty()) && (head_block_time() > dedupe_index.begin()->trx.expiration) ) + transaction_idx.remove(*dedupe_index.begin()); } void database::clear_expired_orders() From e447110dde7ad2cda827aa006c306665eed21418 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 28 Dec 2017 18:00:36 +0100 Subject: [PATCH 64/74] Capped playing time at 86400 per day --- .../muse/chain/protocol/muse_operations.hpp | 2 +- libraries/chain/muse_evaluator.cpp | 5 +++++ libraries/chain/protocol/muse_operations.cpp | 2 ++ tests/tests/muse_tests.cpp | 20 +++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libraries/chain/include/muse/chain/protocol/muse_operations.hpp b/libraries/chain/include/muse/chain/protocol/muse_operations.hpp index ae75a87..d1a26a4 100644 --- a/libraries/chain/include/muse/chain/protocol/muse_operations.hpp +++ b/libraries/chain/include/muse/chain/protocol/muse_operations.hpp @@ -309,7 +309,7 @@ struct streaming_platform_report_operation : public base_operation string streaming_platform; // 0, "Reported time must be greater than 0" ); + FC_ASSERT( o.play_time + consumer.total_listening_time <= 86400, "User cannot cannot listen for more than 86400 seconds per day" ); + } const auto& spidx = db().get_index_type().indices().get(); auto spitr = spidx.find(o.streaming_platform); FC_ASSERT(spitr != spidx.end()); diff --git a/libraries/chain/protocol/muse_operations.cpp b/libraries/chain/protocol/muse_operations.cpp index 23f8696..d0ab702 100644 --- a/libraries/chain/protocol/muse_operations.cpp +++ b/libraries/chain/protocol/muse_operations.cpp @@ -152,6 +152,8 @@ void account_streaming_platform_vote_operation::validate() const { void streaming_platform_report_operation::validate() const { FC_ASSERT(is_valid_account_name(streaming_platform), "Invalid account"); FC_ASSERT(is_valid_account_name(consumer), "Invalid account"); + // FC_ASSERT( play_time > 0, "Reported time must be greater than 0" ); // TODO uncomment after HF_2 + // FC_ASSERT( play_time <= 86400, "Reported time cannot exceed 1 day" ); // TODO uncomment after HF_2 } void friendship_operation::validate() const { diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 4cf4afa..60fa1ba 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -415,6 +415,12 @@ BOOST_AUTO_TEST_CASE( simple_test ) FAIL( "with non-existing content", spro ); spro.content = "ipfs://abcdef1"; + spro.play_time = 86401; + FAIL( "with more than 1 day listening time", spro ); + spro.play_time = 0; + FAIL( "with zero listening time", spro ); + + spro.play_time = 7200; BOOST_TEST_MESSAGE( "--- Test success" ); tx.operations.clear(); tx.operations.push_back( spro ); @@ -1193,6 +1199,20 @@ BOOST_AUTO_TEST_CASE( simple_authority_test ) tx.signatures.clear(); tx.sign( suzy_private_key, db.get_chain_id() ); db.push_transaction( tx, 0 ); + + spro.play_time = 86300; + tx.operations.clear(); + tx.operations.push_back( spro ); + tx.signatures.clear(); + tx.sign( suzy_private_key, db.get_chain_id() ); + db.push_transaction( tx, 0 ); + + spro.play_time = 1; + tx.operations.clear(); + tx.operations.push_back( spro ); + tx.signatures.clear(); + tx.sign( suzy_private_key, db.get_chain_id() ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), assert_exception ); } // --------- Content update ------------ From 7216c9b1bf7a606310f0228d41f50b49964a274b Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 28 Dec 2017 21:39:46 +0100 Subject: [PATCH 65/74] Make it compile --- tests/tests/muse_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 60fa1ba..2e5a644 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -1212,7 +1212,7 @@ BOOST_AUTO_TEST_CASE( simple_authority_test ) tx.operations.push_back( spro ); tx.signatures.clear(); tx.sign( suzy_private_key, db.get_chain_id() ); - MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), assert_exception ); + MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception ); } // --------- Content update ------------ From 1345614b0040ce4181e96b8f74bfeae9eea73a6a Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 29 Dec 2017 11:20:24 +0100 Subject: [PATCH 66/74] Fixed some tests --- tests/tests/muse_tests.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index 2e5a644..aa2cd07 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -1231,6 +1231,7 @@ BOOST_AUTO_TEST_CASE( simple_authority_test ) mgmt.voter = "muriel"; mgmt.percentage = 100; cup.new_management.push_back( mgmt ); + cup.new_threshold = 100; tx.operations.clear(); tx.operations.push_back( cup ); tx.sign( uhura_private_key, db.get_chain_id() ); @@ -1380,7 +1381,6 @@ BOOST_AUTO_TEST_CASE( multi_authority_test ) mgmt.percentage = 33; cop.management.push_back( mgmt ); mgmt.voter = "muriel"; - mgmt.percentage = 33; cop.management.push_back( mgmt ); cop.management_threshold = 50; cop.management_comp = vector(); @@ -1388,7 +1388,7 @@ BOOST_AUTO_TEST_CASE( multi_authority_test ) cop.management_comp->push_back(mgmt); mgmt.voter = "miranda"; cop.management_comp->push_back(mgmt); - cop.management_threshold_comp = 50; + cop.management_threshold_comp = 100; cop.playing_reward = 10; cop.publishers_share = 100; tx.operations.clear(); @@ -1408,14 +1408,15 @@ BOOST_AUTO_TEST_CASE( multi_authority_test ) cup.track_meta = content_metadata_track_master(); cup.track_meta->track_title = "Simple test track"; management_vote mgmt; + mgmt.voter = "martha"; + mgmt.percentage = 50; + cup.new_management.push_back( mgmt ); mgmt.voter = "muriel"; - mgmt.percentage = 100; cup.new_management.push_back( mgmt ); - cup.new_threshold = 40; - // FIXME - mgmt.voter = "martha"; + cup.new_threshold = 51; cup.comp_meta = content_metadata_publisher(); - cup.new_publishers_share = 101; + cup.new_playing_reward = 0; + cup.new_publishers_share = 0; tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( cup ); @@ -1433,13 +1434,14 @@ BOOST_AUTO_TEST_CASE( multi_authority_test ) content_update_operation cup; cup.side = content_update_operation::side_t::publisher; cup.url = "ipfs://abcdef1"; + cup.new_playing_reward = 0; + cup.new_publishers_share = 0; tx.operations.clear(); tx.signatures.clear(); tx.operations.push_back( cup ); tx.sign( muriel_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); - tx.signatures.clear(); - tx.sign( martha_private_key, db.get_chain_id() ); + tx.sign( miranda_private_key, db.get_chain_id() ); db.push_transaction( tx, 0 ); } @@ -1455,7 +1457,6 @@ BOOST_AUTO_TEST_CASE( multi_authority_test ) tx.signatures.clear(); tx.sign( martha_private_key, db.get_chain_id() ); MUSE_REQUIRE_THROW( db.push_transaction( tx, 0 ), tx_missing_active_auth ); - tx.signatures.clear(); tx.sign( muriel_private_key, db.get_chain_id() ); db.push_transaction( tx, 0 ); } From b89d5f4245a32a63496a2c916708dfb8b31c6276 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 29 Dec 2017 13:12:52 +0100 Subject: [PATCH 67/74] Fixed payouts when multiple listens are reported simultaneously for a single consumer --- libraries/chain/database.cpp | 23 +++++++++++++--- tests/tests/muse_tests.cpp | 51 +++++++++++++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 001eb99..dcc97cf 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1636,6 +1636,7 @@ asset database::process_content_cashout( const asset& content_reward ) } ++itr; } + flat_map listening_times; itr = ridx.begin(); while ( itr != ridx.end() && itr->created <= cashing_time ) { @@ -1650,12 +1651,28 @@ asset database::process_content_cashout( const asset& content_reward ) pay_reserve = pay_reserve * std::min( consumer.total_listening_time, uint32_t(3600) ) / full_time; pay_reserve = pay_reserve / consumer.total_listening_time; paid += pay_to_content(itr->content, pay_reserve, itr->streaming_platform ); - modify(consumer, [&itr](account_object & a){ - a.total_listening_time -= itr->play_time; - }); + auto listened = listening_times.find(consumer.id); + if( listened == listening_times.end() ) + listening_times[consumer.id] = itr->play_time; + else + listened->second += itr->play_time; + if( !has_hardfork( MUSE_HARDFORK_0_2 ) ) + modify(consumer, [&itr](account_object & a){ + a.total_listening_time -= itr->play_time; + }); remove(*itr); itr = ridx.begin(); } + if( has_hardfork( MUSE_HARDFORK_0_2 ) ) + { + for ( const auto& listened : listening_times ) + { + const account_object& consumer = get( listened.first ); + modify(consumer, [&listened](account_object & a){ + a.total_listening_time -= listened.second; + }); + } + } return paid; } FC_LOG_AND_RETHROW() } diff --git a/tests/tests/muse_tests.cpp b/tests/tests/muse_tests.cpp index aa2cd07..9f4863d 100644 --- a/tests/tests/muse_tests.cpp +++ b/tests/tests/muse_tests.cpp @@ -675,6 +675,10 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 7200, colette_id(db).total_listening_time ); + BOOST_CHECK_EQUAL( 3600, cora_id(db).total_listening_time ); + BOOST_CHECK_EQUAL( 1800, coreen_id(db).total_listening_time ); + asset daily_content_reward = db.get_content_reward(); generate_block(); @@ -761,6 +765,10 @@ BOOST_AUTO_TEST_CASE( simple_test ) BOOST_CHECK_EQUAL( 0, coreen_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); + + BOOST_CHECK_EQUAL( 0, colette_id(db).total_listening_time ); + BOOST_CHECK_EQUAL( 0, cora_id(db).total_listening_time ); + BOOST_CHECK_EQUAL( 0, coreen_id(db).total_listening_time ); } validate_database(); @@ -1054,6 +1062,8 @@ BOOST_AUTO_TEST_CASE( multi_test ) BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 3600, colette_id(db).total_listening_time ); + generate_blocks( db.head_block_time() + 86400 - MUSE_BLOCK_INTERVAL ); asset daily_content_reward = db.get_content_reward(); @@ -1117,6 +1127,8 @@ BOOST_AUTO_TEST_CASE( multi_test ) BOOST_CHECK_EQUAL( 0, colette_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, veronica_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, vici_id(db).curation_rewards.value ); + + BOOST_CHECK_EQUAL( 0, colette_id(db).total_listening_time ); } validate_database(); @@ -1261,7 +1273,7 @@ BOOST_AUTO_TEST_CASE( simple_authority_test ) db.push_transaction( tx, 0 ); } - // --------- Wait for payout time and verify zero payout ------------ + // --------- Wait for payout time and verify payout ------------ generate_blocks( db.head_block_time() + 86400 - MUSE_BLOCK_INTERVAL ); @@ -1293,11 +1305,31 @@ BOOST_AUTO_TEST_CASE( simple_authority_test ) BOOST_CHECK_EQUAL( 0, muriel_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, colette_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 86400, colette_id(db).total_listening_time ); + + asset daily_content_reward = db.get_content_reward(); + generate_block(); + const auto& dgpo = db.get_dynamic_global_properties(); + asset payout1 = asset( daily_content_reward.amount.value * 100 / 86400, MUSE_SYMBOL ); + asset payout2 = asset( daily_content_reward.amount.value * 86300 / 86400, MUSE_SYMBOL ); + asset platform_reward1 = asset( payout1.amount.value * 11 / MUSE_100_PERCENT, MUSE_SYMBOL ); // playing reward + asset platform_reward2 = asset( payout2.amount.value * 11 / MUSE_100_PERCENT, MUSE_SYMBOL ); // playing reward + payout1 -= platform_reward1; + payout2 -= platform_reward2; + asset comp_reward = asset( (payout1.amount.value + payout2.amount.value) * 1 / MUSE_100_PERCENT, MUSE_SYMBOL ); // publishers_share + asset master_reward = payout1 + payout2 - comp_reward; + + const content_object& song1 = db.get_content( "ipfs://abcdef1" ); + BOOST_CHECK_EQUAL( 0, song1.accumulated_balance_master.amount.value ); + BOOST_CHECK_EQUAL( comp_reward.amount.value, song1.accumulated_balance_comp.amount.value ); + BOOST_CHECK_EQUAL( master_reward.amount.value, paula_id(db).balance.amount.value ); + BOOST_CHECK_EQUAL( 100000 + (platform_reward1 * dgpo.get_vesting_share_price()).amount.value + (platform_reward2 * dgpo.get_vesting_share_price()).amount.value, suzy_id(db).vesting_shares.amount.value ); + BOOST_CHECK_EQUAL( 0, suzy_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, uhura_id(db).balance.amount.value ); - BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); + //BOOST_CHECK_EQUAL( 0, paula_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, martha_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, muriel_id(db).balance.amount.value ); BOOST_CHECK_EQUAL( 0, colette_id(db).balance.amount.value ); @@ -1309,7 +1341,7 @@ BOOST_AUTO_TEST_CASE( simple_authority_test ) BOOST_CHECK_EQUAL( 0, muriel_id(db).mbd_balance.amount.value ); BOOST_CHECK_EQUAL( 0, colette_id(db).mbd_balance.amount.value ); - BOOST_CHECK_EQUAL( 100000, suzy_id(db).vesting_shares.amount.value ); + //BOOST_CHECK_EQUAL( 100000, suzy_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, uhura_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, paula_id(db).vesting_shares.amount.value ); BOOST_CHECK_EQUAL( 100000, martha_id(db).vesting_shares.amount.value ); @@ -1323,6 +1355,8 @@ BOOST_AUTO_TEST_CASE( simple_authority_test ) BOOST_CHECK_EQUAL( 0, muriel_id(db).curation_rewards.value ); BOOST_CHECK_EQUAL( 0, colette_id(db).curation_rewards.value ); + BOOST_CHECK_EQUAL( 0, colette_id(db).total_listening_time ); + validate_database(); } FC_LOG_AND_RETHROW() @@ -2001,6 +2035,17 @@ BOOST_AUTO_TEST_CASE( disable_test ) FAIL( "vote after disable", vop ); } + // --------- Publish playtime ------------ + { + streaming_platform_report_operation spro; + spro.streaming_platform = "suzy"; + spro.consumer = "colette"; + spro.content = "ipfs://abcdef1"; + spro.play_time = 100; + FAIL( "report after disable", spro ); + } + + } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_SUITE_END() From 0d4b836b3d90975eacbe2dc047c4cd0e4c057eb2 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 30 Dec 2017 12:29:17 +0100 Subject: [PATCH 68/74] Removed one obsolete HF check --- libraries/chain/database.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index dcc97cf..f9e6cd4 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1442,8 +1442,7 @@ void database::clear_streaming_platform_votes( const account_object& a ) void database::update_owner_authority( const account_object& account, const authority& owner_authority ) { - if( head_block_num() >= 3186477 // remove check after this block has passed - || has_hardfork(MUSE_HARDFORK_0_2) ) + if( head_block_num() >= 3186477 ) // FIXME: needs to be removed, but usage must be HF-protected { create< owner_authority_history_object >( [&]( owner_authority_history_object& hist ) { From 7e9cb618c336e16f70f7467c290734597f5deffd Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 30 Dec 2017 16:39:09 +0100 Subject: [PATCH 69/74] Minor fix, affects test cases only --- libraries/chain/base_evaluator.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/chain/base_evaluator.cpp b/libraries/chain/base_evaluator.cpp index a080739..1e54721 100644 --- a/libraries/chain/base_evaluator.cpp +++ b/libraries/chain/base_evaluator.cpp @@ -93,11 +93,11 @@ void account_create_evaluator::do_apply( const account_create_operation& o ) FC_ASSERT( o.fee >= wso.median_props.account_creation_fee, "Insufficient Fee: ${f} required, ${p} provided", ("f", wso.median_props.account_creation_fee) ("p", o.fee) ); + } - db().modify( creator, [&]( account_object& c ){ - c.balance -= o.fee; - }); - } + db().modify( creator, [&o]( account_object& c ){ + c.balance -= o.fee; + }); const auto& new_account = db().create< account_object >( [&]( account_object& acc ) { From a9e25f95b74dc62beaf584861fe61c1cae64de4a Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 30 Dec 2017 17:06:01 +0100 Subject: [PATCH 70/74] Fixed invariant validation --- libraries/chain/database.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index f9e6cd4..b13949c 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -3324,7 +3324,6 @@ void database::retally_liquidity_weight() { */ void database::validate_invariants()const { -//TODO_MUSE - rework! try { const auto& account_idx = get_index_type().indices().get(); @@ -3378,6 +3377,10 @@ void database::validate_invariants()const } } + const auto& balances = get_index_type< balance_index >().indices(); + for( auto itr = balances.begin(); itr != balances.end(); itr++ ) + total_supply += itr->balance; + if( has_hardfork( MUSE_HARDFORK_0_2 ) ) { const auto& content_idx = get_index_type< content_index >().indices(); From 05fca5dcbb186a97f7b422b7865d4bfbbcc0a846 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 30 Dec 2017 22:29:12 +0100 Subject: [PATCH 71/74] Fix supply at time of HF_2 --- libraries/chain/database.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index b13949c..0e9f4ef 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -3295,6 +3295,17 @@ void database::apply_hardfork( uint32_t hardfork ) } break; + case MUSE_HARDFORK_0_2: + { + const auto& gpo = get_dynamic_global_properties(); + modify( gpo, []( dynamic_global_property_object& dgpo ) { + dgpo.current_supply += dgpo.supply_delta; + dgpo.virtual_supply += dgpo.supply_delta; + dgpo.supply_delta = asset(); + } ); + } + break; + default: break; } @@ -3324,6 +3335,7 @@ void database::retally_liquidity_weight() { */ void database::validate_invariants()const { + if( !has_hardfork(MUSE_HARDFORK_0_2) ) return; // total_supply tracking is incorrect before HF2 try { const auto& account_idx = get_index_type().indices().get(); From 05fdb7f36a67bad51a542ace8d10aa063ef8f682 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 30 Dec 2017 22:53:02 +0100 Subject: [PATCH 72/74] Set HF_2 time to 2018-01-17 15:40:00 UTC --- libraries/chain/hardfork.d/0-2.hf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/hardfork.d/0-2.hf b/libraries/chain/hardfork.d/0-2.hf index 5019b6d..3e1a9e0 100644 --- a/libraries/chain/hardfork.d/0-2.hf +++ b/libraries/chain/hardfork.d/0-2.hf @@ -1,6 +1,6 @@ #ifndef MUSE_HARDFORK_0_2 #define MUSE_HARDFORK_0_2 2 -// 2020-01-01T00:00:00Z -#define MUSE_HARDFORK_0_2_TIME 1577836800 +// 2018-01-17T15:40:00Z +#define MUSE_HARDFORK_0_2_TIME 1516203600 #define MUSE_HARDFORK_0_2_VERSION hardfork_version( 0, 2 ) #endif From 6570932fd4112c863e7274b5f80a5a3d0d275463 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 31 Dec 2017 11:29:03 +0100 Subject: [PATCH 73/74] Changed DB version --- libraries/chain/include/muse/chain/config.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/include/muse/chain/config.hpp b/libraries/chain/include/muse/chain/config.hpp index 5d22bdb..e6b6add 100644 --- a/libraries/chain/include/muse/chain/config.hpp +++ b/libraries/chain/include/muse/chain/config.hpp @@ -242,7 +242,7 @@ #define MUSE_MAX_ASSET_WHITELIST_AUTHORITIES 10 #define MUSE_MAX_URL_LENGTH 127 -#define GRAPHENE_CURRENT_DB_VERSION "GPH2.4" +#define GRAPHENE_CURRENT_DB_VERSION "MUSE_0_2" #define MUSE_IRREVERSIBLE_THRESHOLD (51 * MUSE_1_PERCENT) From bf745450bd56a2c5dd80c327871d316745298792 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 31 Dec 2017 12:12:47 +0100 Subject: [PATCH 74/74] Added default seed and checkpoint --- libraries/app/application.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 094e1cc..1dbd2cf 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -854,6 +854,9 @@ application::~application() } } +static const string DEFAULT_SEED = "138.197.68.175:33333"; +static const string DEFAULT_CHECKPOINT = "[3900000,\"003b8260970ee1d4e97f7a18aac40d51d0882365\"]"; + void application::set_program_options(boost::program_options::options_description& command_line_options, boost::program_options::options_description& configuration_file_options) const { @@ -870,8 +873,8 @@ void application::set_program_options(boost::program_options::options_descriptio configuration_file_options.add_options() ("p2p-endpoint", bpo::value(), "Endpoint for P2P node to listen on") ("p2p-max-connections", bpo::value(), "Maxmimum number of incoming connections on P2P endpoint") - ("seed-node,s", bpo::value>()->composing(), "P2P nodes to connect to on startup (may specify multiple times)") - ("checkpoint,c", bpo::value>()->composing(), "Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints.") + ("seed-node,s", bpo::value>()->composing()->default_value(vector(1,DEFAULT_SEED), DEFAULT_SEED), "P2P nodes to connect to on startup (may specify multiple times)") + ("checkpoint,c", bpo::value>()->composing()->default_value(vector(1,DEFAULT_CHECKPOINT), DEFAULT_CHECKPOINT), "Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints.") ("rpc-endpoint", bpo::value()->implicit_value("127.0.0.1:8090"), "Endpoint for websocket RPC to listen on") ("rpc-tls-endpoint", bpo::value()->implicit_value("127.0.0.1:8089"), "Endpoint for TLS websocket RPC to listen on") ("server-pem,p", bpo::value()->implicit_value("server.pem"), "The TLS certificate file for this server")