From 8b5182e53ea9d9f5c10b6d436fa8692ae6828a12 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 12 Jul 2017 02:10:46 +0200 Subject: [PATCH] Created unit test for #325 --- tests/tests/database_tests.cpp | 35 +++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/tests/database_tests.cpp b/tests/tests/database_tests.cpp index 5dc35f27..18ea8e40 100644 --- a/tests/tests/database_tests.cpp +++ b/tests/tests/database_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * Copyright (c) 2017 Cryptonomex, Inc., and contributors. * * The MIT License * @@ -34,6 +34,8 @@ using namespace graphene::chain; +BOOST_FIXTURE_TEST_SUITE( database_tests, database_fixture ) + BOOST_AUTO_TEST_CASE( undo_test ) { try { @@ -59,3 +61,34 @@ BOOST_AUTO_TEST_CASE( undo_test ) throw; } } + +BOOST_AUTO_TEST_CASE( flat_index_test ) +{ + ACTORS((sam)); + const auto& bitusd = create_bitasset("USDBIT", sam.id); + update_feed_producers(bitusd, {sam.id}); + price_feed current_feed; + current_feed.settlement_price = bitusd.amount(100) / asset(100); + publish_feed(bitusd, sam, current_feed); + FC_ASSERT( bitusd.bitasset_data_id->instance == 0 ); + FC_ASSERT( !(*bitusd.bitasset_data_id)(db).current_feed.settlement_price.is_null() ); + try { + auto ses = db._undo_db.start_undo_session(); + const auto& obj1 = db.create( [&]( asset_bitasset_data_object& obj ){ + obj.settlement_fund = 17; + }); + FC_ASSERT( obj1.settlement_fund == 17 ); + throw std::string("Expected"); + // With flat_index, obj1 will not really be removed from the index + } catch ( const std::string& e ) + { // ignore + } + + // force maintenance + const auto& dynamic_global_props = db.get(dynamic_global_property_id_type()); + generate_blocks(dynamic_global_props.next_maintenance_time, true); + + FC_ASSERT( !(*bitusd.bitasset_data_id)(db).current_feed.settlement_price.is_null() ); +} + +BOOST_AUTO_TEST_SUITE_END()