Commit 3cb9b67e authored by Mariusz's avatar Mariusz

Voting + delegations - unit-tests part 1

parent 03478f6c
......@@ -1022,6 +1022,37 @@ void sps_proposal_database_fixture::post_comment( std::string _authro, std::stri
trx.operations.clear();
}
void hf23_database_fixture::push_transaction( const operation& op, const fc::ecc::private_key& key )
{
signed_transaction tx;
tx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
tx.operations.push_back( op );
sign( tx, key );
db->push_transaction( tx, 0 );
}
void hf23_database_fixture::vest( const string& from, const string& to, const asset& amount, const fc::ecc::private_key& key )
{
FC_ASSERT( amount.symbol == STEEM_SYMBOL, "Can only vest TESTS" );
transfer_to_vesting_operation op;
op.from = from;
op.to = to;
op.amount = amount;
push_transaction( op, key );
}
void hf23_database_fixture::delegate_vest( const string& delegator, const string& delegatee, const asset& amount, const fc::ecc::private_key& key )
{
delegate_vesting_shares_operation op;
op.vesting_shares = amount;
op.delegator = delegator;
op.delegatee = delegatee;
push_transaction( op, key );
}
json_rpc_database_fixture::json_rpc_database_fixture()
{
try {
......
......@@ -369,10 +369,18 @@ struct sps_proposal_database_fixture_performance : public sps_proposal_database_
struct hf23_database_fixture : public clean_database_fixture
{
hf23_database_fixture( uint16_t shared_file_size_in_mb = 8 )
: clean_database_fixture( shared_file_size_in_mb ){}
virtual ~hf23_database_fixture(){}
private:
void push_transaction( const operation& op, const fc::ecc::private_key& key );
public:
hf23_database_fixture( uint16_t shared_file_size_in_mb = 8 )
: clean_database_fixture( shared_file_size_in_mb ){}
virtual ~hf23_database_fixture(){}
void vest( const string& from, const string& to, const asset& amount, const fc::ecc::private_key& key );
void delegate_vest( const string& delegator, const string& delegatee, const asset& amount, const fc::ecc::private_key& key );
};
struct json_rpc_database_fixture : public database_fixture
......
......@@ -31,6 +31,179 @@ using fc::string;
BOOST_FIXTURE_TEST_SUITE( hf23_tests, hf23_database_fixture )
BOOST_AUTO_TEST_CASE( basic_test_04 )
{
try
{
BOOST_TEST_MESSAGE( "VEST delegations" );
ACTORS( (alice)(bob)(carol) )
generate_block();
set_price_feed( price( ASSET( "1.000 TBD" ), ASSET( "1.000 TESTS" ) ) );
generate_block();
auto _10 = ASSET( "10.000 TESTS" );
auto _20 = ASSET( "20.000 TESTS" );
auto _1v = ASSET( "1.000000 VESTS" );
auto _2v = ASSET( "2.000000 VESTS" );
auto _1000 = ASSET( "1000.000 TESTS" );
FUND( "alice", _1000 );
FUND( "bob", _1000 );
FUND( "carol", _1000 );
{
vest( "alice", "alice", _10, alice_private_key );
vest( "alice", "alice", _20, alice_private_key );
delegate_vest( "alice", "bob", _1v, alice_private_key );
BOOST_REQUIRE( db->get_account( "alice" ).delegated_vesting_shares.amount.value != 0l );
BOOST_REQUIRE( db->get_account( "bob" ).delegated_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "carol" ).delegated_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "alice" ).received_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "bob" ).received_vesting_shares.amount.value != 0l );
BOOST_REQUIRE( db->get_account( "carol" ).received_vesting_shares.amount.value == 0l );
auto previous = db->get_account( "alice" ).delegated_vesting_shares.amount.value;
delegate_vest( "alice", "carol", _2v, alice_private_key );
auto next = db->get_account( "alice" ).delegated_vesting_shares.amount.value;
BOOST_REQUIRE( next > previous );
BOOST_REQUIRE( db->get_account( "alice" ).delegated_vesting_shares.amount.value != 0l );
BOOST_REQUIRE( db->get_account( "bob" ).delegated_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "carol" ).delegated_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "alice" ).received_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "bob" ).received_vesting_shares.amount.value != 0l );
BOOST_REQUIRE( db->get_account( "carol" ).received_vesting_shares.amount.value != 0l );
}
{
db->clear_account( db->get_account( "alice" ) );
BOOST_REQUIRE( db->get_account( "alice" ).delegated_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "bob" ).delegated_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "carol" ).delegated_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "alice" ).received_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "bob" ).received_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "carol" ).received_vesting_shares.amount.value == 0l );
db->clear_account( db->get_account( "bob" ) );
BOOST_REQUIRE( db->get_account( "alice" ).delegated_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "bob" ).delegated_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "carol" ).delegated_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "alice" ).received_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "bob" ).received_vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "carol" ).received_vesting_shares.amount.value == 0l );
}
database_fixture::validate_database();
}
FC_LOG_AND_RETHROW()
}
BOOST_AUTO_TEST_CASE( basic_test_03 )
{
try
{
BOOST_TEST_MESSAGE( "Vesting every account to anothers accounts" );
ACTORS( (alice)(bob)(carol) )
generate_block();
set_price_feed( price( ASSET( "1.000 TBD" ), ASSET( "1.000 TESTS" ) ) );
generate_block();
auto _1 = ASSET( "1.000 TESTS" );
auto _2 = ASSET( "2.000 TESTS" );
auto _3 = ASSET( "3.000 TESTS" );
auto _1000 = ASSET( "1000.000 TESTS" );
FUND( "alice", _1000 );
FUND( "bob", _1000 );
FUND( "carol", _1000 );
BOOST_REQUIRE( db->get_account( "alice" ).vesting_shares == db->get_account( "bob" ).vesting_shares );
BOOST_REQUIRE( db->get_account( "bob" ).vesting_shares == db->get_account( "carol" ).vesting_shares );
{
vest( "alice", "bob", _1, alice_private_key );
vest( "bob", "carol", _2, bob_private_key );
vest( "carol", "alice", _3, carol_private_key );
BOOST_REQUIRE_GT( db->get_account( "alice" ).vesting_shares.amount.value, db->get_account( "carol" ).vesting_shares.amount.value );
BOOST_REQUIRE_GT( db->get_account( "carol" ).vesting_shares.amount.value, db->get_account( "bob" ).vesting_shares.amount.value );
}
{
auto vest_bob = db->get_account( "bob" ).vesting_shares.amount.value;
auto vest_carol = db->get_account( "carol" ).vesting_shares.amount.value;
db->clear_account( db->get_account( "alice" ) );
BOOST_REQUIRE( db->get_account( "alice" ).vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "bob" ).vesting_shares.amount.value == vest_bob );
BOOST_REQUIRE( db->get_account( "carol" ).vesting_shares.amount.value == vest_carol );
db->clear_account( db->get_account( "bob" ) );
BOOST_REQUIRE( db->get_account( "alice" ).vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "bob" ).vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "carol" ).vesting_shares.amount.value == vest_carol );
db->clear_account( db->get_account( "carol" ) );
BOOST_REQUIRE( db->get_account( "alice" ).vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "bob" ).vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "carol" ).vesting_shares.amount.value == 0l );
}
database_fixture::validate_database();
}
FC_LOG_AND_RETHROW()
}
BOOST_AUTO_TEST_CASE( basic_test_02 )
{
try
{
BOOST_TEST_MESSAGE( "Vesting" );
ACTORS( (alice)(bob) )
generate_block();
set_price_feed( price( ASSET( "1.000 TBD" ), ASSET( "1.000 TESTS" ) ) );
generate_block();
auto _1 = ASSET( "1.000 TESTS" );
auto _1000 = ASSET( "1000.000 TESTS" );
FUND( "alice", _1000 );
FUND( "bob", _1000 );
BOOST_REQUIRE( db->get_account( "alice" ).vesting_shares == db->get_account( "bob" ).vesting_shares );
{
vest( "alice", "alice", _1, alice_private_key );
BOOST_REQUIRE_GT( db->get_account( "alice" ).vesting_shares.amount.value, db->get_account( "bob" ).vesting_shares.amount.value );
}
{
auto vest_bob = db->get_account( "bob" ).vesting_shares.amount.value;
db->clear_account( db->get_account( "alice" ) );
BOOST_REQUIRE( db->get_account( "alice" ).vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "bob" ).vesting_shares.amount.value == vest_bob );
db->clear_account( db->get_account( "bob" ) );
BOOST_REQUIRE( db->get_account( "alice" ).vesting_shares.amount.value == 0l );
BOOST_REQUIRE( db->get_account( "bob" ).vesting_shares.amount.value == 0l );
}
database_fixture::validate_database();
}
FC_LOG_AND_RETHROW()
}
BOOST_AUTO_TEST_CASE( basic_test_01 )
{
try
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment