Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for existing tests after hf1270 #1493

Merged
1 change: 1 addition & 0 deletions tests/common/database_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ struct database_fixture {
optional<fc::temp_directory> data_dir;
bool skip_key_index_test = false;
uint32_t anon_acct_count;
bool hf1270 = false;

database_fixture();
~database_fixture();
Expand Down
54 changes: 38 additions & 16 deletions tests/tests/bitasset_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,18 @@ BOOST_AUTO_TEST_CASE( hf_890_test )
generate_blocks(HARDFORK_615_TIME, true, skip); // get around Graphene issue #615 feed expiration bug
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time, true, skip);

auto hf_time = HARDFORK_CORE_868_890_TIME;
if(hf1270)
hf_time = HARDFORK_CORE_1270_TIME;

for( int i=0; i<2; ++i )
{
int blocks = 0;
auto mi = db.get_global_properties().parameters.maintenance_interval;

if( i == 1 ) // go beyond hard fork
{
blocks += generate_blocks(HARDFORK_CORE_868_890_TIME - mi, true, skip);
blocks += generate_blocks(hf_time - mi, true, skip);
blocks += generate_blocks(db.get_dynamic_global_properties().next_maintenance_time, true, skip);
}
set_expiration( db, trx );
Expand Down Expand Up @@ -526,7 +530,7 @@ BOOST_AUTO_TEST_CASE( hf_890_test )
ba_op.asset_to_update = usd_id;
ba_op.issuer = asset_to_update.issuer;
ba_op.new_options = asset_to_update.bitasset_data(db).options;
ba_op.new_options.feed_lifetime_sec = HARDFORK_CORE_868_890_TIME.sec_since_epoch()
ba_op.new_options.feed_lifetime_sec = hf_time.sec_since_epoch()
- db.head_block_time().sec_since_epoch()
+ mi
+ 1800;
Expand All @@ -542,7 +546,7 @@ BOOST_AUTO_TEST_CASE( hf_890_test )
BOOST_CHECK( db.find<limit_order_object>( sell_id ) );

// go beyond hard fork
blocks += generate_blocks(HARDFORK_CORE_868_890_TIME - mi, true, skip);
blocks += generate_blocks(hf_time - mi, true, skip);
blocks += generate_blocks(db.get_dynamic_global_properties().next_maintenance_time, true, skip);
}

Expand Down Expand Up @@ -924,7 +928,7 @@ BOOST_AUTO_TEST_CASE( hf_935_test )
generate_blocks( db.get_dynamic_global_properties().next_maintenance_time, true, skip );
generate_block( skip );

for( int i = 0; i < 6; ++i )
for( int i = 0; i < 8; ++i )
{
idump( (i) );
int blocks = 0;
Expand All @@ -940,6 +944,10 @@ BOOST_AUTO_TEST_CASE( hf_935_test )
generate_blocks( HARDFORK_CORE_935_TIME - mi, true, skip );
generate_blocks( db.get_dynamic_global_properties().next_maintenance_time, true, skip );
}
else if( i == 6 ) // go beyond hard fork 1270
{
generate_blocks( HARDFORK_CORE_1270_TIME, true, skip );
abitmore marked this conversation as resolved.
Show resolved Hide resolved
}
set_expiration( db, trx );

ACTORS( (seller)(borrower)(feedproducer)(feedproducer2)(feedproducer3) );
Expand Down Expand Up @@ -1050,7 +1058,7 @@ BOOST_AUTO_TEST_CASE( hf_935_test )
ba_op.asset_to_update = usd_id;
ba_op.issuer = asset_to_update.issuer;
ba_op.new_options = asset_to_update.bitasset_data(db).options;
ba_op.new_options.feed_lifetime_sec = HARDFORK_CORE_935_TIME.sec_since_epoch()
ba_op.new_options.feed_lifetime_sec = HARDFORK_CORE_1270_TIME.sec_since_epoch()
+ mi * 3 + 86400 * 2
- db.head_block_time().sec_since_epoch();
trx.operations.push_back(ba_op);
Expand Down Expand Up @@ -1103,22 +1111,30 @@ BOOST_AUTO_TEST_CASE( hf_935_test )
blocks += generate_blocks(db.get_dynamic_global_properties().next_maintenance_time, true, skip);
}

// after hard fork 935, the limit order should be filled
// after hard fork 935, the limit order is filled only for the MSSR test
if( db.get_dynamic_global_properties().next_maintenance_time > HARDFORK_CORE_935_TIME &&
db.get_dynamic_global_properties().next_maintenance_time <= HARDFORK_CORE_1270_TIME )
{
// check median
BOOST_CHECK( usd_id(db).bitasset_data(db).current_feed.settlement_price == current_feed.settlement_price );
if( i % 2 == 0 ) // MCR test, median MCR should be 350%
BOOST_CHECK_EQUAL( usd_id(db).bitasset_data(db).current_feed.maintenance_collateral_ratio, 3500 );
else // MSSR test, MSSR should be 125%
BOOST_CHECK_EQUAL( usd_id(db).bitasset_data(db).current_feed.maximum_short_squeeze_ratio, 1250 );
// the limit order should have been filled
// TODO FIXME this test case is failing for MCR test,
// because call_order's call_price didn't get updated after MCR changed
// BOOST_CHECK( !db.find<limit_order_object>( sell_id ) );
if( i % 2 == 1 ) // MSSR test
BOOST_CHECK( !db.find<limit_order_object>( sell_id ) );
if( i % 2 != 0 ) { // MSSR test, MSSR should be 125%, order filled
BOOST_CHECK_EQUAL(usd_id(db).bitasset_data(db).current_feed.maximum_short_squeeze_ratio, 1250);
BOOST_CHECK(!db.find<limit_order_object>(sell_id));
}
abitmore marked this conversation as resolved.
Show resolved Hide resolved
// go beyond hard fork 1270
blocks += generate_blocks(HARDFORK_CORE_1270_TIME, true, skip);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more accurate, here should be

         blocks += generate_blocks(HARDFORK_CORE_1270_TIME - mi, true, skip);
         blocks += generate_blocks(db.get_dynamic_global_properties().next_maintenance_time, true, skip);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the suggestion, i actually tried to make it like that everywhere but there are some problems not sure why.

in the case of this particular test(hf_935_test) when i make the generate block chains i get error:

83898ms th_a       bitasset_tests.cpp:1150       test_method          ] 10 assert_exception: Assert Exception
prev: popping block would leave head block null
    {}
    th_a  fork_database.cpp:41 pop_block

    {}
    th_a  db_block.cpp:477 pop_block

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you increased blocks here, aka blocks += generate_blocks(...).

}

// after hard fork 1270
if( db.get_dynamic_global_properties().next_maintenance_time > HARDFORK_CORE_1270_TIME)
{
// check median
BOOST_CHECK( usd_id(db).bitasset_data(db).current_feed.settlement_price == current_feed.settlement_price );
if( i % 2 == 0 ) { // MCR test, median MCR should be 350%, order filled
BOOST_CHECK_EQUAL(usd_id(db).bitasset_data(db).current_feed.maintenance_collateral_ratio, 3500);
BOOST_CHECK(!db.find<limit_order_object>(sell_id)); // MCR bug fixed
}
}

// undo above tx's and reset
generate_block( skip );
Expand Down Expand Up @@ -1376,5 +1392,11 @@ BOOST_AUTO_TEST_CASE( reset_backing_asset_switching_to_witness_fed )
}
}
*/
BOOST_AUTO_TEST_CASE(hf_890_test_hf1270)
{ try {
hf1270 = true;
INVOKE(hf_890_test);

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_SUITE_END()
85 changes: 66 additions & 19 deletions tests/tests/market_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ BOOST_AUTO_TEST_CASE(issue_338_etc)
*/
BOOST_AUTO_TEST_CASE(hardfork_core_338_test)
{ try {
auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_343_TIME - mi); // assume all hard forks occur at same time
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

if(hf1270)
generate_blocks(HARDFORK_CORE_1270_TIME);
else
generate_blocks(HARDFORK_CORE_343_TIME);
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved

set_expiration( db, trx );

Expand Down Expand Up @@ -325,7 +327,8 @@ BOOST_AUTO_TEST_CASE(hardfork_core_338_test)

// call's call_price will be updated after the match, to 741/31/1.75 CORE/USD = 2964/217
// it's above settlement price (10/1) so won't be margin called again
BOOST_CHECK( price(asset(2964),asset(217,usd_id)) == call.call_price );
if(!hf1270) // can use call price only if we are before hf1270
BOOST_CHECK( price(asset(2964),asset(217,usd_id)) == call.call_price );

// This would match with call before, but would match with call2 after #343 fixed
BOOST_CHECK( !create_sell_order(seller, bitusd.amount(700), core.amount(6000) ) );
Expand All @@ -342,7 +345,8 @@ BOOST_AUTO_TEST_CASE(hardfork_core_338_test)
BOOST_CHECK_EQUAL( 1000, call3.debt.value );
BOOST_CHECK_EQUAL( 16000, call3.collateral.value );
// call2's call_price will be updated after the match, to 78/3/1.75 CORE/USD = 312/21
BOOST_CHECK( price(asset(312),asset(21,usd_id)) == call2.call_price );
if(!hf1270) // can use call price only if we are before hf1270
BOOST_CHECK( price(asset(312),asset(21,usd_id)) == call2.call_price );
// it's above settlement price (10/1) so won't be margin called

// at this moment, collateralization of call is 7410 / 310 = 23.9
Expand Down Expand Up @@ -406,9 +410,11 @@ BOOST_AUTO_TEST_CASE(hardfork_core_338_test)
*/
BOOST_AUTO_TEST_CASE(hardfork_core_453_test)
{ try {
auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_453_TIME - mi); // assume all hard forks occur at same time
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

if(hf1270)
generate_blocks(HARDFORK_CORE_1270_TIME);
else
generate_blocks(HARDFORK_CORE_343_TIME);
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved

set_expiration( db, trx );

Expand Down Expand Up @@ -478,17 +484,18 @@ BOOST_AUTO_TEST_CASE(hardfork_core_453_test)
// generate a block
generate_block();


} FC_LOG_AND_RETHROW() }

/***
* Tests (big) limit order matching logic after #625 got fixed
*/
BOOST_AUTO_TEST_CASE(hardfork_core_625_big_limit_order_test)
{ try {
auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_625_TIME - mi); // assume all hard forks occur at same time
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

if(hf1270)
generate_blocks(HARDFORK_CORE_1270_TIME);
else
generate_blocks(HARDFORK_CORE_625_TIME);
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved

set_expiration( db, trx );

Expand Down Expand Up @@ -1195,9 +1202,11 @@ BOOST_AUTO_TEST_CASE(hard_fork_343_cross_test)
*/
BOOST_AUTO_TEST_CASE(target_cr_test_limit_call)
{ try {
auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_834_TIME - mi);
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

if(hf1270)
generate_blocks(HARDFORK_CORE_1270_TIME);
else
generate_blocks(HARDFORK_CORE_834_TIME);
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved

set_expiration( db, trx );

Expand Down Expand Up @@ -1283,7 +1292,7 @@ BOOST_AUTO_TEST_CASE(target_cr_test_limit_call)
BOOST_CHECK_LT( call2_to_cover.value, call2_id(db).debt.value );
// even though call2 has a higher CR, since call's TCR is less than call2's TCR, so we expect call will cover less when called
BOOST_CHECK_LT( call_to_cover.value, call2_to_cover.value );

abitmore marked this conversation as resolved.
Show resolved Hide resolved
// Create a big sell order slightly below the call price, will be matched with several orders
BOOST_CHECK( !create_sell_order(seller, bitusd.amount(700*4), core.amount(5900*4) ) );

Expand Down Expand Up @@ -1373,9 +1382,11 @@ BOOST_AUTO_TEST_CASE(target_cr_test_limit_call)
*/
BOOST_AUTO_TEST_CASE(target_cr_test_call_limit)
{ try {
auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_834_TIME - mi);
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

if(hf1270)
generate_blocks(HARDFORK_CORE_1270_TIME);
else
generate_blocks(HARDFORK_CORE_834_TIME);
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved

set_expiration( db, trx );

Expand Down Expand Up @@ -1817,4 +1828,40 @@ BOOST_AUTO_TEST_CASE(mcr_bug_cross1270)

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(hardfork_core_338_test_after_hf1270)
{ try {
hf1270 = true;
INVOKE(hardfork_core_338_test);

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(hardfork_core_453_test_after_hf1270)
{ try {
hf1270 = true;
INVOKE(hardfork_core_453_test);

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(hardfork_core_625_big_limit_order_test_after_hf1270)
{ try {
hf1270 = true;
INVOKE(hardfork_core_625_big_limit_order_test);

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(target_cr_test_limit_call_after_hf1270)
{ try {
hf1270 = true;
INVOKE(target_cr_test_limit_call);

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(target_cr_test_call_limit_after_hf1270)
{ try {
hf1270 = true;
INVOKE(target_cr_test_call_limit);

} FC_LOG_AND_RETHROW() }


BOOST_AUTO_TEST_SUITE_END()
Loading