peerplays_migrated/tests/tests/uia_tests.cpp
pbattu123 0b280882af
Merge beatrice(GPOS changes) with master (#270)
* Created unit test for #325

* remove needless find()

* issue - 154: Don't allow to vote when vesting balance is 0

* Increase block creation timeout to 2500ms

* increase delay for node connection

* remove cache from cli get_account

* add cli tests framework

* Adjust newly merged code to new API

* Merged changes from Bitshares PR 1036

* GRPH-76 - Short-cut long sequences of missed blocks

Fixes database::update_global_dynamic_data to speed up counting missed blocks.
(This also fixes a minor issue with counting - the previous algorithm would skip missed blocks for the witness who signed the first block after the gap.)

* Improved resilience of block database against corruption

* Moved reindex logic into database / chain_database, make use of additional blocks in block_database

Fixed tests wrt db.open

* Enable undo + fork database for final blocks in a replay

Dont remove blocks from block db when popping blocks, handle edge case in replay wrt fork_db, adapted unit tests

* Log starting block number of replay

* Prevent unsigned integer underflow

* Fixed lock detection

* Dont leave _data_dir empty if db is locked

* Writing the object_database is now almost atomic

* Improved consistency check for block_log

* Cut back block_log index file if inconsistent

* Fixed undo_database

* Added test case for broken merge on empty undo_db

* exclude second undo_db.enable() call in some cases

* Add missing change

* change bitshares to core in message

* Merge pull request #938 from bitshares/fix-block-storing

Store correct block ID when switching forks

* Fixed integer overflow issue

* Fix for for history ID mismatch ( Bitshares PR #875 )

* Update the FC submodule with the changes for GRPH-4

* Merged Bitshares PR #1462 and compilation fixes

* Support/gitlab (#123)

* Updated gitlab process

* Fix undefined references in cli test

* Updated GitLab CI

* Fix #436 object_database created outside of witness data directory

* supplement more comments on database::_opened variable

* prevent segfault when destructing application obj

* Fixed test failures and compilation issue

* minor performance improvement

* Added comment

* Fix compilation in debug mode

* Fixed duplicate ops returned from get_account_history

* Fixed account_history_pagination test

* Removed unrelated comment

* Update to fixed version of fc

* Skip auth check when pushing self-generated blocks

* Extract public keys before pushing a transaction

* Dereference chain_database shared_ptr

* Updated transaction::signees to mutable

and
* updated get_signature_keys() to return a const reference,
* get_signature_keys() will update signees on first call,
* modified test cases and wallet.cpp accordingly,
* no longer construct a new signed_transaction object before pushing

* Added get_asset_count API

* No longer extract public keys before pushing a trx

and removed unused new added constructor and _get_signature_keys() function from signed_transaction struct

* changes to withdraw_vesting feature(for both cdd and GPOS)

* Comments update

* update to GPOS hardfork ref

* Remove leftover comment from merge

* fix for get_vesting_balance API call

* braces update

* Allow sufficient space for new undo_session

* Throw for deep nesting

* node.cpp: Check the attacker/buggy client before updating items ids

The peer is an attacker or buggy, which means the item_hashes_received is
not correct.

Move the check before updating items ids to save some time in this case.

* Create .gitlab-ci.yml

* Added cli_test to CI

* fixing build errors (#150)

* fixing build errors

vest type correction

* fixing build errors

vest type correction

* fixes 

new Dockerfile

* vesting_balance_type correction

vesting_balance_type changed to normal

* gcc5 support to Dockerfile

gcc5 support to Dockerfile

* use random port numbers in app_test (#154)

* Changes to compiple with GCC 7(Ubuntu 18.04)

* proposal fail_reason bug fixed (#157)

* Added Sonarcloud code_quality to CI (#159)

* Added sonarcloud analysis (#158)

* changes to have separate methods and single withdrawl fee for multiple vest objects

* 163-fix, Return only non-zero vesting balances

* Support/gitlab develop (#168)

* Added code_quality to CI

* Update .gitlab-ci.yml

* Point to PBSA/peerplays-fc commit f13d063 (#167)

* [GRPH-3] Additional cli tests (#155)

* Additional cli tests

* Compatible with latest fc changes

* Fixed Spacing issues

* [GRPH-106] Added voting tests (#136)

* Added more voting tests

* Added additional option

* Adjust p2p log level (#180)

* merge gpos to develop (#186)

* issue - 154: Don't allow to vote when vesting balance is 0

* changes to withdraw_vesting feature(for both cdd and GPOS)

* Comments update

* update to GPOS hardfork ref

* fix for get_vesting_balance API call

* braces update

* Create .gitlab-ci.yml

* fixing build errors (#150)

* fixing build errors

vest type correction

* fixing build errors

vest type correction

* fixes 

new Dockerfile

* vesting_balance_type correction

vesting_balance_type changed to normal

* gcc5 support to Dockerfile

gcc5 support to Dockerfile

* Changes to compiple with GCC 7(Ubuntu 18.04)

* changes to have separate methods and single withdrawl fee for multiple vest objects

* 163-fix, Return only non-zero vesting balances

* Revert "Revert "GPOS protocol""

This reverts commit 67616417b7.

* add new line needed to gpos hardfork file

* comment temporally cli_vote_for_2_witnesses until refactor or delete

* fix gpos tests

* fix gitlab-ci conflict

* Fixed few error messages

* error message corrections at other places

* Updated FC repository to peerplays-network/peerplays-fc (#189)

Point to fc commit hash 6096e94 [latest-fc branch]

* Project name update in Doxyfile (#146)

* changes to allow user to vote in each sub-period

* Fixed GPOS vesting factor issue when proxy is set

* Added unit test for proxy voting

* Review changes

* changes to update last voting time

* resolve merge conflict

* unit test changes and also separated GPOS test suite

* delete unused variables

* removed witness check

* eliminate time gap between two consecutive vesting periods

* deleted GPOS specific test suite and updated gpos tests

* updated GPOS hf

* Fixed dividend distribution issue and added test case

* fix flag

* clean newlines gpos_tests

* adapt gpos_tests to changed flag

* Fix to roll in GPOS rules, carry votes from 6th sub-period

* check was already modified

* comments updated

* updated comments to the benefit of reviewer

* Added token symbol name in error messages

* Added token symbol name in error messages (#204)

* case 1: Fixed last voting time issue

* get_account bug fixed

* Fixed flag issue

* Fixed spelling issue

* remove non needed gcc5 changes to dockerfile

* GRPH134- High CPU Issue, websocket changes (#213)

* update submodule branch to refer to the latest commit on latest-fc branch (#214)

* Improve account maintenance performance (#130)

* Improve account maintenance performance

* merge fixes

* Fixed merge issue

* Fixed indentations and extra ';'

* Update CI for syncing gitmodules (#216)

* Added logging for the old update_expired_feeds bug

The old bug is https://github.com/cryptonomex/graphene/issues/615 .

Due to the bug, `update_median_feeds()` and `check_call_orders()`
will be called when a feed is not actually expired, normally this
should not affect consensus since calling them should not change
any data in the state.

However, the logging indicates that `check_call_orders()` did
change some data under certain circumstances, specifically, when
multiple limit order matching issue (#453) occurred at same block.
* https://github.com/bitshares/bitshares-core/issues/453

* Minor performance improvement for price::is_null()

* Use static refs in db_getter for immutable objects

* Minor performance improvement for db_maint

* Minor code updates for asset_evaluator.cpp

* changed an `assert()` to `FC_ASSERT()`
* replaced one `db.get(asset_id_type())` with `db.get_core_asset()`
* capture only required variables for lambda

* Improve update_expired_feeds performance #1093

* Change static refs to member pointers of db class

* Added getter for witness schedule object

* Added getter for core dynamic data object

* Use getters

* Removed unused variable

* Add comments for update_expired_feeds in db_block

* Minor refactory asset_create_evaluator::do_apply()

* Added FC_ASSERT for dynamic data id of core asset

* Added header inclusions in db_management.cpp

* fix global objects usage during replay

* Logging config parsing issue

* added new files

* compilation fix

* Simplified code in database::pay_workers()

* issue with withdrawl

* Added unit test for empty account history

* set extensions default values

* Update GPOS hardfork date and don't allow GPOS features before hardfork time

* refer to latest commit of latest-fc branch (#224)

* account name or id support in all database api

* asset id or name support in all asset APIs

* Fixed compilation issues

* Fixed alignment issues

* Externalized some API templates

* Externalize serialization of blocks, tx, ops

* Externalized db objects

* Externalized genesis serialization

* Externalized serialization in protocol library

* Undo superfluous change

* remove default value for extension parameter

* fix compilation issues

* GRPH-46-Quit_command_cliwallet

* removed multiple function definition

* Fixed chainparameter update proposal issue

* Move GPOS withdraw logic to have single transaction(also single fee) and update API

* Added log for authorization failure of proposal operations

* Votes consideration on GPOS activation

* bump fc version

* fix gpos tests

* Bump fc version

* Updated gpos/voting_tests

* Fixed withdraw vesting bug

* Added unit test

* Update hardfork date for TESTNET, sync fc module and update logs

* avoid wlog as it filling up space

* Beatrice hot fix(sync issue fix)

* gpos tests fix

* Set hardfork date to Jan5th on TESTNET

Co-authored-by: Peter Conrad <github.com@quisquis.de>
Co-authored-by: John M. Jones <jmjatlanta@gmail.com>
Co-authored-by: obucinac <obucinac@users.noreply.github.com>
Co-authored-by: Bobinson K B <bobinson@gmail.com>
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
Co-authored-by: Miha Čančula <miha@noughmad.eu>
Co-authored-by: Abit <abitmore@users.noreply.github.com>
Co-authored-by: Roshan Syed <r.syed@pbsa.info>
Co-authored-by: Sandip Patel <sandip@knackroot.com>
Co-authored-by: RichardWeiYang <richard.weiyang@gmail.com>
Co-authored-by: gladcow <jahr@yandex.ru>
Co-authored-by: satyakoneru <satyakoneru.iiith@gmail.com>
2020-02-07 21:23:08 +05:30

480 lines
19 KiB
C++

/*
* Copyright (c) 2015 Cryptonomex, 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 <boost/test/unit_test.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/hardfork.hpp>
#include <graphene/chain/is_authorized_asset.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <fc/crypto/digest.hpp>
#include "../common/database_fixture.hpp"
using namespace graphene::chain;
using namespace graphene::chain::test;
BOOST_FIXTURE_TEST_SUITE( uia_tests, database_fixture )
BOOST_AUTO_TEST_CASE( create_advanced_uia )
{
try {
asset_id_type test_asset_id = db.get_index<asset_object>().get_next_id();
asset_create_operation creator;
creator.issuer = account_id_type();
creator.fee = asset();
creator.symbol = "ADVANCED";
creator.common_options.max_supply = 100000000;
creator.precision = 2;
creator.common_options.market_fee_percent = GRAPHENE_MAX_MARKET_FEE_PERCENT/100; /*1%*/
creator.common_options.issuer_permissions = charge_market_fee|white_list|override_authority|transfer_restricted|disable_confidential;
creator.common_options.flags = charge_market_fee|white_list|override_authority|disable_confidential;
creator.common_options.core_exchange_rate = price({asset(2),asset(1,asset_id_type(1))});
creator.common_options.whitelist_authorities = creator.common_options.blacklist_authorities = {account_id_type()};
trx.operations.push_back(std::move(creator));
PUSH_TX( db, trx, ~0 );
const asset_object& test_asset = test_asset_id(db);
BOOST_CHECK(test_asset.symbol == "ADVANCED");
BOOST_CHECK(asset(1, test_asset_id) * test_asset.options.core_exchange_rate == asset(2));
BOOST_CHECK(test_asset.options.flags & white_list);
BOOST_CHECK(test_asset.options.max_supply == 100000000);
BOOST_CHECK(!test_asset.bitasset_data_id.valid());
BOOST_CHECK(test_asset.options.market_fee_percent == GRAPHENE_MAX_MARKET_FEE_PERCENT/100);
const asset_dynamic_data_object& test_asset_dynamic_data = test_asset.dynamic_asset_data_id(db);
BOOST_CHECK(test_asset_dynamic_data.current_supply == 0);
BOOST_CHECK(test_asset_dynamic_data.accumulated_fees == 0);
BOOST_CHECK(test_asset_dynamic_data.fee_pool == 0);
} catch(fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}
BOOST_AUTO_TEST_CASE( override_transfer_test )
{ try {
ACTORS( (dan)(eric)(sam) );
const asset_object& advanced = create_user_issued_asset( "ADVANCED", sam, override_authority );
BOOST_TEST_MESSAGE( "Issuing 1000 ADVANCED to dan" );
issue_uia( dan, advanced.amount( 1000 ) );
BOOST_TEST_MESSAGE( "Checking dan's balance" );
BOOST_REQUIRE_EQUAL( get_balance( dan, advanced ), 1000 );
override_transfer_operation otrans;
otrans.issuer = advanced.issuer;
otrans.from = dan.id;
otrans.to = eric.id;
otrans.amount = advanced.amount(100);
trx.operations.push_back(otrans);
BOOST_TEST_MESSAGE( "Require throwing without signature" );
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), tx_missing_active_auth );
BOOST_TEST_MESSAGE( "Require throwing with dan's signature" );
sign( trx, dan_private_key );
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), tx_missing_active_auth );
BOOST_TEST_MESSAGE( "Pass with issuer's signature" );
trx.clear_signatures();
sign( trx, sam_private_key );
PUSH_TX( db, trx, 0 );
BOOST_REQUIRE_EQUAL( get_balance( dan, advanced ), 900 );
BOOST_REQUIRE_EQUAL( get_balance( eric, advanced ), 100 );
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE( override_transfer_test2 )
{ try {
ACTORS( (dan)(eric)(sam) );
const asset_object& advanced = create_user_issued_asset( "ADVANCED", sam, 0 );
issue_uia( dan, advanced.amount( 1000 ) );
BOOST_REQUIRE_EQUAL( get_balance( dan, advanced ), 1000 );
trx.operations.clear();
override_transfer_operation otrans;
otrans.issuer = advanced.issuer;
otrans.from = dan.id;
otrans.to = eric.id;
otrans.amount = advanced.amount(100);
trx.operations.push_back(otrans);
BOOST_TEST_MESSAGE( "Require throwing without signature" );
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), fc::exception);
BOOST_TEST_MESSAGE( "Require throwing with dan's signature" );
sign( trx, dan_private_key );
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), fc::exception);
BOOST_TEST_MESSAGE( "Fail because overide_authority flag is not set" );
trx.clear_signatures();
sign( trx, sam_private_key );
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), fc::exception );
BOOST_REQUIRE_EQUAL( get_balance( dan, advanced ), 1000 );
BOOST_REQUIRE_EQUAL( get_balance( eric, advanced ), 0 );
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE( issue_whitelist_uia )
{
try {
account_id_type izzy_id = create_account("izzy").id;
const asset_id_type uia_id = create_user_issued_asset(
"ADVANCED", izzy_id(db), white_list ).id;
account_id_type nathan_id = create_account("nathan").id;
account_id_type vikram_id = create_account("vikram").id;
trx.clear();
asset_issue_operation op;
op.issuer = uia_id(db).issuer;
op.asset_to_issue = asset(1000, uia_id);
op.issue_to_account = nathan_id;
trx.operations.emplace_back(op);
set_expiration( db, trx );
//Fail because nathan is not whitelisted, but only before hardfork time
if( db.head_block_time() <= HARDFORK_415_TIME )
{
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
generate_blocks( HARDFORK_415_TIME );
generate_block();
set_expiration( db, trx );
}
PUSH_TX( db, trx, ~0 );
BOOST_CHECK(is_authorized_asset( db, nathan_id(db), uia_id(db) ));
BOOST_CHECK_EQUAL(get_balance(nathan_id, uia_id), 1000);
// Make a whitelist, now it should fail
{
BOOST_TEST_MESSAGE( "Changing the whitelist authority" );
asset_update_operation uop;
uop.issuer = izzy_id;
uop.asset_to_update = uia_id;
uop.new_options = uia_id(db).options;
uop.new_options.whitelist_authorities.insert(izzy_id);
trx.operations.back() = uop;
PUSH_TX( db, trx, ~0 );
BOOST_CHECK( uia_id(db).options.whitelist_authorities.find(izzy_id) != uia_id(db).options.whitelist_authorities.end() );
}
// Fail because there is a whitelist authority and I'm not whitelisted
trx.operations.back() = op;
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, ~0 ), fc::exception );
account_whitelist_operation wop;
wop.authorizing_account = izzy_id;
wop.account_to_list = vikram_id;
wop.new_listing = account_whitelist_operation::white_listed;
trx.operations.back() = wop;
// Fail because whitelist function is restricted to members only
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, ~0 ), fc::exception );
upgrade_to_lifetime_member( izzy_id );
trx.operations.clear();
trx.operations.push_back( wop );
PUSH_TX( db, trx, ~0 );
// Still fail after an irrelevant account was added
trx.operations.back() = op;
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, ~0 ), fc::exception );
wop.account_to_list = nathan_id;
trx.operations.back() = wop;
PUSH_TX( db, trx, ~0 );
trx.operations.back() = op;
BOOST_CHECK_EQUAL(get_balance(nathan_id, uia_id), 1000);
// Finally succeed when we were whitelisted
PUSH_TX( db, trx, ~0 );
BOOST_CHECK_EQUAL(get_balance(nathan_id, uia_id), 2000);
} catch(fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}
BOOST_AUTO_TEST_CASE( transfer_whitelist_uia )
{
try {
INVOKE(issue_whitelist_uia);
const asset_object& advanced = get_asset("ADVANCED");
const account_object& nathan = get_account("nathan");
const account_object& dan = create_account("dan");
account_id_type izzy_id = get_account("izzy").id;
upgrade_to_lifetime_member(dan);
trx.clear();
BOOST_TEST_MESSAGE( "Atempting to transfer asset ADVANCED from nathan to dan when dan is not whitelisted, should fail" );
transfer_operation op;
op.fee = advanced.amount(0);
op.from = nathan.id;
op.to = dan.id;
op.amount = advanced.amount(100); //({advanced.amount(0), nathan.id, dan.id, advanced.amount(100)});
trx.operations.push_back(op);
//Fail because dan is not whitelisted.
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), transfer_to_account_not_whitelisted );
BOOST_TEST_MESSAGE( "Adding dan to whitelist for asset ADVANCED" );
account_whitelist_operation wop;
wop.authorizing_account = izzy_id;
wop.account_to_list = dan.id;
wop.new_listing = account_whitelist_operation::white_listed;
trx.operations.back() = wop;
PUSH_TX( db, trx, ~0 );
BOOST_TEST_MESSAGE( "Attempting to transfer from nathan to dan after whitelisting dan, should succeed" );
trx.operations.back() = op;
PUSH_TX( db, trx, ~0 );
BOOST_CHECK_EQUAL(get_balance(nathan, advanced), 1900);
BOOST_CHECK_EQUAL(get_balance(dan, advanced), 100);
BOOST_TEST_MESSAGE( "Attempting to blacklist nathan" );
{
BOOST_TEST_MESSAGE( "Changing the blacklist authority" );
asset_update_operation uop;
uop.issuer = izzy_id;
uop.asset_to_update = advanced.id;
uop.new_options = advanced.options;
uop.new_options.blacklist_authorities.insert(izzy_id);
trx.operations.back() = uop;
PUSH_TX( db, trx, ~0 );
BOOST_CHECK( advanced.options.blacklist_authorities.find(izzy_id) != advanced.options.blacklist_authorities.end() );
}
wop.new_listing |= account_whitelist_operation::black_listed;
wop.account_to_list = nathan.id;
trx.operations.back() = wop;
PUSH_TX( db, trx, ~0 );
BOOST_CHECK( !(is_authorized_asset( db, nathan, advanced )) );
BOOST_TEST_MESSAGE( "Attempting to transfer from nathan after blacklisting, should fail" );
op.amount = advanced.amount(50);
trx.operations.back() = op;
//Fail because nathan is blacklisted
if( db.head_block_time() <= HARDFORK_419_TIME )
{
// before the hardfork time, it fails because the whitelist check fails
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), transfer_from_account_not_whitelisted );
}
else
{
// after the hardfork time, it fails because the fees are not in a whitelisted asset
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception );
}
BOOST_TEST_MESSAGE( "Attempting to burn from nathan after blacklisting, should fail" );
asset_reserve_operation burn;
burn.payer = nathan.id;
burn.amount_to_reserve = advanced.amount(10);
trx.operations.back() = burn;
//Fail because nathan is blacklisted
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
BOOST_TEST_MESSAGE( "Attempting transfer from dan back to nathan, should fail because nathan is blacklisted" );
std::swap(op.from, op.to);
trx.operations.back() = op;
//Fail because nathan is blacklisted
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
{
BOOST_TEST_MESSAGE( "Changing the blacklist authority to dan" );
asset_update_operation op;
op.issuer = izzy_id;
op.asset_to_update = advanced.id;
op.new_options = advanced.options;
op.new_options.blacklist_authorities.clear();
op.new_options.blacklist_authorities.insert(dan.id);
trx.operations.back() = op;
PUSH_TX( db, trx, ~0 );
BOOST_CHECK(advanced.options.blacklist_authorities.find(dan.id) != advanced.options.blacklist_authorities.end());
}
BOOST_TEST_MESSAGE( "Attempting to transfer from dan back to nathan" );
trx.operations.back() = op;
PUSH_TX( db, trx, ~0 );
BOOST_CHECK_EQUAL(get_balance(nathan, advanced), 1950);
BOOST_CHECK_EQUAL(get_balance(dan, advanced), 50);
BOOST_TEST_MESSAGE( "Blacklisting nathan by dan" );
wop.authorizing_account = dan.id;
wop.account_to_list = nathan.id;
wop.new_listing = account_whitelist_operation::black_listed;
trx.operations.back() = wop;
PUSH_TX( db, trx, ~0 );
trx.operations.back() = op;
//Fail because nathan is blacklisted
BOOST_CHECK(!is_authorized_asset( db, nathan, advanced ));
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
//Remove nathan from committee's whitelist, add him to dan's. This should not authorize him to hold ADVANCED.
wop.authorizing_account = izzy_id;
wop.account_to_list = nathan.id;
wop.new_listing = account_whitelist_operation::no_listing;
trx.operations.back() = wop;
PUSH_TX( db, trx, ~0 );
wop.authorizing_account = dan.id;
wop.account_to_list = nathan.id;
wop.new_listing = account_whitelist_operation::white_listed;
trx.operations.back() = wop;
PUSH_TX( db, trx, ~0 );
trx.operations.back() = op;
//Fail because nathan is not whitelisted
BOOST_CHECK(!is_authorized_asset( db, nathan, advanced ));
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
burn.payer = dan.id;
burn.amount_to_reserve = advanced.amount(10);
trx.operations.back() = burn;
PUSH_TX(db, trx, ~0);
BOOST_CHECK_EQUAL(get_balance(dan, advanced), 40);
} catch(fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}
/**
* verify that issuers can halt transfers
*/
BOOST_AUTO_TEST_CASE( transfer_restricted_test )
{
try
{
ACTORS( (sam)(alice)(bob) );
BOOST_TEST_MESSAGE( "Issuing 1000 UIA to Alice" );
auto _issue_uia = [&]( const account_object& recipient, asset amount )
{
asset_issue_operation op;
op.issuer = amount.asset_id(db).issuer;
op.asset_to_issue = amount;
op.issue_to_account = recipient.id;
transaction tx;
tx.operations.push_back( op );
set_expiration( db, tx );
PUSH_TX( db, tx, database::skip_authority_check | database::skip_tapos_check | database::skip_transaction_signatures );
} ;
const asset_object& uia = create_user_issued_asset( "TXRX", sam, transfer_restricted );
_issue_uia( alice, uia.amount( 1000 ) );
auto _restrict_xfer = [&]( bool xfer_flag )
{
asset_update_operation op;
op.issuer = sam_id;
op.asset_to_update = uia.id;
op.new_options = uia.options;
if( xfer_flag )
op.new_options.flags |= transfer_restricted;
else
op.new_options.flags &= ~transfer_restricted;
transaction tx;
tx.operations.push_back( op );
set_expiration( db, tx );
PUSH_TX( db, tx, database::skip_authority_check | database::skip_tapos_check | database::skip_transaction_signatures );
} ;
BOOST_TEST_MESSAGE( "Enable transfer_restricted, send fails" );
transfer_operation xfer_op;
xfer_op.from = alice_id;
xfer_op.to = bob_id;
xfer_op.amount = uia.amount(100);
signed_transaction xfer_tx;
xfer_tx.operations.push_back( xfer_op );
set_expiration( db, xfer_tx );
sign( xfer_tx, alice_private_key );
_restrict_xfer( true );
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, xfer_tx ), transfer_restricted_transfer_asset );
BOOST_TEST_MESSAGE( "Disable transfer_restricted, send succeeds" );
_restrict_xfer( false );
PUSH_TX( db, xfer_tx );
xfer_op.amount = uia.amount(101);
}
catch(fc::exception& e)
{
edump((e.to_detail_string()));
throw;
}
}
BOOST_AUTO_TEST_CASE( asset_name_test )
{
try
{
ACTORS( (alice)(bob) );
auto has_asset = [&]( std::string symbol ) -> bool
{
const auto& assets_by_symbol = db.get_index_type<asset_index>().indices().get<by_symbol>();
return assets_by_symbol.find( symbol ) != assets_by_symbol.end();
};
// Alice creates asset "ALPHA"
BOOST_CHECK( !has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") );
create_user_issued_asset( "ALPHA", alice_id(db), 0 );
BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") );
// Nobody can create another asset named ALPHA
GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA", bob_id(db), 0 ), fc::exception );
BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") );
GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA", alice_id(db), 0 ), fc::exception );
BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") );
// Bob can't create ALPHA.ONE
//generate_blocks( HARDFORK_385_TIME );
// no assertion if d.head_block_time() <= HARDFORK_385_TIME in asset_evaluator.cpp
//GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA.ONE", bob_id(db), 0 ), fc::exception );
BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") );
if( db.head_block_time() <= HARDFORK_409_TIME )
{
// Alice can't create ALPHA.ONE before hardfork
// no assertion if d.head_block_time() <= HARDFORK_385_TIME in asset_evaluator.cpp
//GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA.ONE", alice_id(db), 0 ), fc::exception );
BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") );
generate_blocks( HARDFORK_409_TIME );
generate_block();
// Bob can't create ALPHA.ONE after hardfork
GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA.ONE", bob_id(db), 0 ), fc::exception );
BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") );
}
// Alice can create it
create_user_issued_asset( "ALPHA.ONE", alice_id(db), 0 );
BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( has_asset("ALPHA.ONE") );
}
catch(fc::exception& e)
{
edump((e.to_detail_string()));
throw;
}
}
BOOST_AUTO_TEST_SUITE_END()