2022-10-04 16:29:24 +02:00
// Copyright (c) 2014-2018 Zano Project
// Copyright (c) 2014-2018 The Louisdor Project
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
# include "chaingen.h"
# include "multiassets_test.h"
# include "wallet_test_core_proxy.h"
# include "random_helper.h"
# define AMOUNT_TO_TRANSFER_MULTIASSETS_BASIC (TESTS_DEFAULT_FEE)
# define AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC 500000000000000000
using namespace currency ;
2022-10-07 21:44:43 +02:00
uint64_t multiassets_basic_test : : ts_starter = 0 ;
2022-10-04 16:29:24 +02:00
//------------------------------------------------------------------------------
multiassets_basic_test : : multiassets_basic_test ( )
{
2022-10-06 22:59:00 +02:00
// TODO: remove the following line
2022-10-07 21:44:43 +02:00
2022-10-12 17:01:58 +02:00
LOG_PRINT_MAGENTA ( " STARTER TS: " < < ts_starter , LOG_LEVEL_0 ) ;
random_state_test_restorer : : reset_random ( ts_starter ) ;
2022-10-06 22:59:00 +02:00
2022-10-04 16:29:24 +02:00
REGISTER_CALLBACK_METHOD ( multiassets_basic_test , configure_core ) ;
REGISTER_CALLBACK_METHOD ( multiassets_basic_test , c1 ) ;
m_hardforks . set_hardfork_height ( 1 , 1 ) ;
m_hardforks . set_hardfork_height ( 2 , 1 ) ;
m_hardforks . set_hardfork_height ( 3 , 1 ) ;
m_hardforks . set_hardfork_height ( 4 , 1 ) ;
}
bool multiassets_basic_test : : generate ( std : : vector < test_event_entry > & events ) const
{
m_accounts . resize ( MINER_ACC_IDX + 1 ) ;
account_base & miner_acc = m_accounts [ MINER_ACC_IDX ] ;
miner_acc . generate ( ) ;
2022-10-06 22:59:00 +02:00
uint64_t ts = 145000000 ;
MAKE_GENESIS_BLOCK ( events , blk_0 , miner_acc , ts ) ;
2022-10-04 16:29:24 +02:00
DO_CALLBACK ( events , " configure_core " ) ; // default configure_core callback will initialize core runtime config with m_hardforks
set_hard_fork_heights_to_generator ( generator ) ;
//TODO: Need to make sure REWIND_BLOCKS_N and other coretests codebase are capable of following hardfork4 rules
//in this test hardfork4 moment moved to runtime section
2022-10-06 22:59:00 +02:00
REWIND_BLOCKS_N_WITH_TIME ( events , blk_0r , blk_0 , miner_acc , CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3 ) ;
2022-10-04 16:29:24 +02:00
DO_CALLBACK ( events , " c1 " ) ;
return true ;
}
bool multiassets_basic_test : : c1 ( currency : : core & c , size_t ev_index , const std : : vector < test_event_entry > & events )
{
bool r = false ;
std : : shared_ptr < tools : : wallet2 > miner_wlt = init_playtime_test_wallet ( events , c , MINER_ACC_IDX ) ;
2022-10-06 22:59:00 +02:00
miner_wlt - > get_account ( ) . set_createtime ( 0 ) ;
2022-10-04 16:29:24 +02:00
account_base alice_acc ;
alice_acc . generate ( ) ;
std : : shared_ptr < tools : : wallet2 > alice_wlt = init_playtime_test_wallet ( events , c , alice_acc ) ;
2022-10-06 22:59:00 +02:00
alice_wlt - > get_account ( ) . set_createtime ( 0 ) ;
2022-10-04 16:29:24 +02:00
miner_wlt - > refresh ( ) ;
asset_descriptor_base adb = AUTO_VAL_INIT ( adb ) ;
adb . total_max_supply = 1000000000000000000 ; //1M coins
adb . full_name = " Test coins " ;
adb . ticker = " TCT " ;
adb . decimal_point = 12 ;
std : : vector < currency : : tx_destination_entry > destinations ( 2 ) ;
destinations [ 0 ] . addr . push_back ( miner_wlt - > get_account ( ) . get_public_address ( ) ) ;
destinations [ 0 ] . amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC ;
destinations [ 0 ] . asset_id = currency : : ffff_hash ;
destinations [ 1 ] . addr . push_back ( alice_wlt - > get_account ( ) . get_public_address ( ) ) ;
destinations [ 1 ] . amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC ;
destinations [ 1 ] . asset_id = currency : : ffff_hash ;
2022-10-12 20:03:42 +02:00
2022-10-12 20:09:56 +02:00
LOG_PRINT_MAGENTA ( " destinations[0].asset_id: " < < destinations [ 0 ] . asset_id , LOG_LEVEL_0 ) ;
LOG_PRINT_MAGENTA ( " destinations[1].asset_id: " < < destinations [ 1 ] . asset_id , LOG_LEVEL_0 ) ;
LOG_PRINT_MAGENTA ( " currency::ffff_hash: " < < currency : : ffff_hash , LOG_LEVEL_0 ) ;
2022-10-04 16:29:24 +02:00
currency : : transaction tx = AUTO_VAL_INIT ( tx ) ;
crypto : : hash asset_id = currency : : null_hash ;
miner_wlt - > publish_new_asset ( adb , destinations , tx , asset_id ) ;
2022-10-05 21:31:21 +02:00
LOG_PRINT_L0 ( " Published new asset: " < < asset_id < < " , tx_id: " < < currency : : get_transaction_hash ( tx ) ) ;
2022-10-04 16:29:24 +02:00
//pass over hardfork
r = mine_next_pow_blocks_in_playtime ( miner_wlt - > get_account ( ) . get_public_address ( ) , c , CURRENCY_MINED_MONEY_UNLOCK_WINDOW ) ;
CHECK_AND_ASSERT_MES ( r , false , " mine_next_pow_blocks_in_playtime failed " ) ;
miner_wlt - > refresh ( ) ;
alice_wlt - > refresh ( ) ;
uint64_t mined = 0 ;
std : : unordered_map < crypto : : hash , tools : : wallet_public : : asset_balance_entry_base > balances ;
miner_wlt - > balance ( balances , mined ) ;
auto it_asset = balances . find ( asset_id ) ;
auto it_native = balances . find ( currency : : null_hash ) ;
CHECK_AND_ASSERT_MES ( it_asset ! = balances . end ( ) & & it_native ! = balances . end ( ) , false , " Failed to find needed asset in result balances " ) ;
CHECK_AND_ASSERT_MES ( it_asset - > second . total = = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC , false , " Failed to find needed asset in result balances " ) ;
2022-10-11 20:19:24 +02:00
CHECK_AND_ASSERT_MES ( it_native - > second . total = = uint64_t ( 17517226 ) * COIN , false , " Failed to find needed asset in result balances " ) ;
2022-10-04 16:29:24 +02:00
balances . clear ( ) ;
alice_wlt - > balance ( balances , mined ) ;
it_asset = balances . find ( asset_id ) ;
it_native = balances . find ( currency : : null_hash ) ;
2022-10-05 21:31:21 +02:00
CHECK_AND_ASSERT_MES ( it_asset ! = balances . end ( ) , false , " Failed to find needed asset in result balances " ) ;
CHECK_AND_ASSERT_MES ( it_native = = balances . end ( ) , false , " Failed to find needed asset in result balances " ) ;
2022-10-04 16:29:24 +02:00
CHECK_AND_ASSERT_MES ( it_asset - > second . total = = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC , false , " Failed to find needed asset in result balances " ) ;
2022-10-05 21:31:21 +02:00
2022-10-06 22:59:00 +02:00
miner_wlt - > transfer ( AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC / 2 , alice_wlt - > get_account ( ) . get_public_address ( ) , asset_id ) ;
//pass over hardfork
r = mine_next_pow_blocks_in_playtime ( miner_wlt - > get_account ( ) . get_public_address ( ) , c , CURRENCY_MINED_MONEY_UNLOCK_WINDOW ) ;
CHECK_AND_ASSERT_MES ( r , false , " mine_next_pow_blocks_in_playtime failed " ) ;
alice_wlt - > refresh ( ) ;
balances . clear ( ) ;
alice_wlt - > balance ( balances , mined ) ;
it_asset = balances . find ( asset_id ) ;
CHECK_AND_ASSERT_MES ( it_asset ! = balances . end ( ) , false , " Failed to find needed asset in result balances " ) ;
CHECK_AND_ASSERT_MES ( it_asset - > second . total = = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC + AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC / 2 , false , " Failed to find needed asset in result balances " ) ;
try {
miner_wlt - > transfer ( AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC / 2 , alice_wlt - > get_account ( ) . get_public_address ( ) , asset_id ) ;
//pass over hardfork
CHECK_AND_ASSERT_MES ( false , false , " Transfer with 0 Zano worked(fail) " ) ;
}
catch ( . . . )
{
2022-10-07 21:44:43 +02:00
return true ;
2022-10-06 22:59:00 +02:00
}
2022-10-04 16:29:24 +02:00
return true ;
}