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
67 changes: 20 additions & 47 deletions tests/tests/bitasset_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,26 +928,22 @@ 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 < 8; ++i )
for( int i = 0; i < 6; ++i )
{
idump( (i) );
int blocks = 0;
auto mi = db.get_global_properties().parameters.maintenance_interval;

if( i == 2 ) // go beyond hard fork 890
if( i == 2 ) // go beyond hard fork 890, 343, 935
abitmore marked this conversation as resolved.
Show resolved Hide resolved
{
generate_blocks( HARDFORK_CORE_868_890_TIME - mi, true, skip );
generate_blocks( db.get_dynamic_global_properties().next_maintenance_time, true, skip );
}
else if( i == 4 ) // go beyond hard fork 935
else if( i == 4 ) // go beyond hard fork 1270
{
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 );
generate_blocks( HARDFORK_CORE_1270_TIME - mi, true, skip );
}
generate_blocks( db.get_dynamic_global_properties().next_maintenance_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 @@ -1066,45 +1062,12 @@ BOOST_AUTO_TEST_CASE( hf_935_test )
trx.clear();
}

bool affected_by_hf_343 = false;

// check
if( i / 2 == 0 ) // before hard fork 890
if( db.get_dynamic_global_properties().next_maintenance_time <= HARDFORK_CORE_935_TIME )
{
// median feed won't change (issue 890)
BOOST_CHECK( usd_id(db).bitasset_data(db).current_feed.settlement_price == current_feed.settlement_price );
BOOST_CHECK_EQUAL( usd_id(db).bitasset_data(db).current_feed.maintenance_collateral_ratio, 1750 );
BOOST_CHECK_EQUAL( usd_id(db).bitasset_data(db).current_feed.maximum_short_squeeze_ratio, 1100 );
// limit order is still there
BOOST_CHECK( db.find<limit_order_object>( sell_id ) );

// go beyond hard fork 890
blocks += generate_blocks( HARDFORK_CORE_868_890_TIME - mi, true, skip );
bool was_before_hf_343 = ( db.get_dynamic_global_properties().next_maintenance_time <= HARDFORK_CORE_343_TIME );

blocks += generate_blocks( db.get_dynamic_global_properties().next_maintenance_time, true, skip );
bool now_after_hf_343 = ( db.get_dynamic_global_properties().next_maintenance_time > HARDFORK_CORE_343_TIME );

if( was_before_hf_343 && now_after_hf_343 ) // if hf 343 executed at same maintenance interval, actually after hf 890
affected_by_hf_343 = true;
}

// after hard fork 890, if it's before hard fork 935
if( db.get_dynamic_global_properties().next_maintenance_time <= HARDFORK_CORE_935_TIME )
{
// median should have changed
BOOST_CHECK( usd_id(db).bitasset_data(db).current_feed.settlement_price == current_feed.settlement_price );
if( i % 2 == 0 ) // MCR test, 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 );

if( affected_by_hf_343 ) // if updated bitasset before hf 890, and hf 343 executed after hf 890
// the limit order should have been filled
BOOST_CHECK( !db.find<limit_order_object>( sell_id ) );
else // if not affected by hf 343
// the limit order should be still there, because `check_call_order` was incorrectly skipped
BOOST_CHECK( db.find<limit_order_object>( sell_id ) );
abitmore marked this conversation as resolved.
Show resolved Hide resolved

// go beyond hard fork 935
blocks += generate_blocks(HARDFORK_CORE_935_TIME - mi, true, skip);
Expand All @@ -1113,16 +1076,21 @@ BOOST_AUTO_TEST_CASE( hf_935_test )

// 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 )
db.get_dynamic_global_properties().next_maintenance_time <= HARDFORK_CORE_1270_TIME && i > 4)
abitmore marked this conversation as resolved.
Show resolved Hide resolved
{
// check median
BOOST_CHECK( usd_id(db).bitasset_data(db).current_feed.settlement_price == current_feed.settlement_price );
if( i % 2 != 0 ) { // MSSR test, MSSR should be 125%, order filled
if( i % 2 == 0 ) { // MCR bug
BOOST_CHECK_EQUAL(usd_id(db).bitasset_data(db).current_feed.maintenance_collateral_ratio, 3500);
BOOST_CHECK(db.find<limit_order_object>(sell_id)); // order still here
}
else { // 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);
blocks += generate_blocks(HARDFORK_CORE_1270_TIME - mi, true, skip);
blocks += generate_blocks(db.get_dynamic_global_properties().next_maintenance_time, true, skip);
}

// after hard fork 1270
Expand All @@ -1134,11 +1102,16 @@ BOOST_AUTO_TEST_CASE( hf_935_test )
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
}
else { // 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));
}
}

// undo above tx's and reset
generate_block( skip );
++blocks;

while( blocks > 0 )
{
db.pop_block();
Expand Down