diff --git a/contracts/CMakeLists.txt b/contracts/CMakeLists.txt index bd84d155e8552844e7400df9f7a1a6ce73a1d84b..443330c886a307053ccadc97ae65fc37e1803ab3 100644 --- a/contracts/CMakeLists.txt +++ b/contracts/CMakeLists.txt @@ -7,7 +7,6 @@ set(STANDARD_INCLUDE_FOLDERS ${CMAKE_SOURCE_DIR}/contracts ${CMAKE_BINARY_DIR}/c add_subdirectory(eosiolib) add_subdirectory(musl) add_subdirectory(libc++) -add_subdirectory(simple.token) add_subdirectory(eosio.token) add_subdirectory(eosio.msig) add_subdirectory(eosio.sudo) @@ -18,17 +17,14 @@ add_subdirectory(identity) add_subdirectory(stltest) add_subdirectory(test.inline) -#add_subdirectory(bancor) add_subdirectory(hello) add_subdirectory(asserter) -add_subdirectory(infinite) add_subdirectory(proxy) add_subdirectory(test_api) add_subdirectory(test_api_mem) add_subdirectory(test_api_db) add_subdirectory(test_api_multi_index) add_subdirectory(test_ram_limit) -#add_subdirectory(social) add_subdirectory(eosio.bios) add_subdirectory(noop) add_subdirectory(tic_tac_toe) diff --git a/contracts/bancor/CMakeLists.txt b/contracts/bancor/CMakeLists.txt deleted file mode 100644 index b845361e8f0cd50faf2b3248a090eaca12e1406c..0000000000000000000000000000000000000000 --- a/contracts/bancor/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -file(GLOB ABI_FILES "*.abi") -configure_file("${ABI_FILES}" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY) - -add_wast_executable(TARGET bancor - INCLUDE_FOLDERS "${STANDARD_INCLUDE_FOLDERS}" - LIBRARIES libc libc++ eosiolib - DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR} -) diff --git a/contracts/bancor/bancor.cpp b/contracts/bancor/bancor.cpp deleted file mode 100644 index 15bc9e802c8a6be318694b8a2589da483906f202..0000000000000000000000000000000000000000 --- a/contracts/bancor/bancor.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @file - * @copyright defined in eos/LICENSE.txt - */ - -#include - -namespace bancor { - -extern "C" { - - /// The apply method implements the dispatch of events to this contract - void apply( uint64_t r, uint64_t c, uint64_t a ) { - bancor::example_converter::apply( c, a ); - } -} - -} diff --git a/contracts/bancor/bancor.hpp b/contracts/bancor/bancor.hpp deleted file mode 100644 index b6030908b81b2a2592a9fde4ff3c986ef35ca102..0000000000000000000000000000000000000000 --- a/contracts/bancor/bancor.hpp +++ /dev/null @@ -1,22 +0,0 @@ -/** - * @file - * @copyright defined in eos/LICENSE.txt - */ -#pragma once - -#include -#include -#include -#include - -#include -#include - -namespace bancor { - typedef eosio::generic_currency< eosio::token > other_currency; - typedef eosio::generic_currency< eosio::token > relay_currency; - typedef eosio::generic_currency< eosio::token > cur_currency; - - typedef converter example_converter; -} /// bancor - diff --git a/contracts/bancor/converter.hpp b/contracts/bancor/converter.hpp deleted file mode 100644 index 774fc910e32768453536a4e495b55c934985e26d..0000000000000000000000000000000000000000 --- a/contracts/bancor/converter.hpp +++ /dev/null @@ -1,166 +0,0 @@ -#pragma once -namespace bancor { - template - class converter_contract { - public: - typedef ConverterCurrency converter_currency; - typedef FirstCurrency first_currency; - typedef SecondCurrency second_currency; - - - static const account_name converter_account = converter_currency::code; - - struct converter_state { - typename converter_currency::token_type supply; /// total supply held by all users - typename converter_currency::token_type balance; /// supply held by converter in its own balance - }; - - struct converter_args { - eosio::account_name to_currency_account; - eosio::symbol_name to_currency_symbol; - uint64_t min_return_currency; - }; - - - template - struct connector { - typedef CurrencyType currency_type; - typedef typename converter_currency::token_type converter_token_type; - typedef typename currency_type::token_type in_token_type; - - converter_token_type convert_to_converter( in_token_type in, converter_state& state ) { - in_token_type balance = currency_type::get_balance( converter_account ); - - /// balance already changed when transfer executed, get pre-transfer balance - in_token_type previous_balance = balance - in; - - auto init_price = (previous_balance * Base) / (Weight * state.supply); - auto init_out = init_price * in; - - auto out_price = (balance*Base) / (Weight * (state.supply+init_out) ); - auto final_out = out_price * in; - - state.balance += final_out; - state.supply += final_out; - - return final_out; - } - - - in_token_type convert_from_converter( converter_token_type converter_in, converter_state& state ) { - in_token_type to_balance = CurrencyType::get_balance( converter_account ); - - auto init_price = (to_balance * Base) / (Weight * state.supply); - in_token_type init_out = init_price * converter_in; - - state.supply -= converter_in; - state.balance -= converter_in; - - auto out_price = ((to_balance-init_out) * Base) / ( Weight * (state.supply) ); - - return out_price * converter_in; - } - - }; - - - - /** - * This is called when we receive RELAY tokens from user and wish to - * convert to one of the connector currencies. - */ - static void on_convert( const typename converter_currency::transfer& trans, - const converter_args& args, - converter_state& state ) { - - if( args.to_currency_type == first_currency ) { - auto output = first_connector::convert_from_converter( trans.quantity, state ); - save_and_send( trans.from, state, output, args.min_return ); - } - else if( args.to_currency_type == second_currency ) { - auto output = second_connector::convert_from_converter( trans.quantity, state ); - save_and_send( trans.from, state, output, args.min_return ); - } - else { - eosio_assert( false, "invalid to currency" ); - } - } - - - /** - * This is called when the converter receives one of the connector currencies and it - * will send either converter tokens or a different connector currency in response. - */ - template - static void on_convert( const typename ConnectorType::currency_type::transfer& trans, - const converter_args& args, - converter_state& state ) - { - /// convert to converter - auto converter_out = ConnectorType::convert_to_converter( trans.quantity, state ); - - if( args.to_currency_type == converter_currency ) - { - save_and_send( trans.from, state, converter_out, args.min_return ); - } - else - { - auto output = ConnectorType::convert_from_converter( converter_out, state ); - save_and_send( trans.from, state, output, args.min_return ); - } - } - - - /** - * This method factors out the boiler plate for parsing args and loading the - * initial state before dispatching to the proper on_convert case - */ - template - static void start_convert( const typename CurrencyType::transfer_memo& trans ) { - auto args = unpack( trans.memo ); - eosio_assert( args.to_currency_type != trans.quantity.token_type(), "cannot convert to self" ); - - auto state = read_converter_state(); - on_convert( trans, args, state ); - } - - - /** - * converter_account first needs to call the currency handler to perform - * user-to-user transfers of the converter token, then if a transfer is sending - * the token back to the converter contract, it should convert like everything else. - * - * This method should be called from apply( code, action ) for each of the - * transfer types that we support (for each currency) - */ - static void on( const typename converter_currency::transfer_memo& trans ) { - converter_currency::on( trans ); - if( trans.to == converter_account ) { - start_convert( trans ); - } - } - - /** - * All other currencies simply call start_convert if to == converter_account - */ - template - static void on( const typename Currency::transfer_memo& trans ) { - if( trans.to == converter_account ) { - start_convert( trans ); - } else { - eosio_assert( trans.from == converter_account, - "received unexpected notification of transfer" ); - } - } - - static void apply( account_name code, action_name action ) { - if( !dispatch( converter_contract, - converter_currency::transfer, - converter_currency::issue, - first_currency::transfer, - second_currency::transfer ) { - eosio_assert( false, "received unexpected action" ); - } - } - }; /// converter_contract -} /// namespace bancor diff --git a/contracts/bancor/eosio.system.abi b/contracts/bancor/eosio.system.abi deleted file mode 100644 index c8d8e4b16e908bcede68ba02f90bd7d86d7ed391..0000000000000000000000000000000000000000 --- a/contracts/bancor/eosio.system.abi +++ /dev/null @@ -1,37 +0,0 @@ -{ - "types": [{ - "new_type_name": "account_name", - "type": "name" - } - ], - "structs": [{ - "name": "transfer", - "base": "", - "fields": [ - {"name":"from", "type":"account_name"}, - {"name":"to", "type":"account_name"}, - {"name":"quantity", "type":"uint64"} - ] - },{ - "name": "account", - "base": "", - "fields": [ - {"name":"key", "type":"name"}, - {"name":"balance", "type":"uint64"} - ] - } - ], - "actions": [{ - "name": "transfer", - "type": "transfer" - } - ], - "tables": [{ - "name": "account", - "type": "account", - "index_type": "i64", - "key_names" : ["key"], - "key_types" : ["name"] - } - ] -} \ No newline at end of file diff --git a/contracts/eosiolib/currency.hpp b/contracts/eosiolib/currency.hpp deleted file mode 100644 index 1328c493876a829fc52df1d434343194815f3114..0000000000000000000000000000000000000000 --- a/contracts/eosiolib/currency.hpp +++ /dev/null @@ -1,254 +0,0 @@ -#pragma once -#include -#include -#include - -namespace eosio { - using std::string; - using std::array; - - /** - * This contract enables the creation, issuance, and transfering of many different tokens. - * @deprecated This class is deprecated in favor of eosio.token in Dawn 3.0 - */ - class currency { - public: - currency( account_name contract ) - :_contract(contract) - { } - - struct create { - account_name issuer; - asset maximum_supply; - // array issuer_agreement_hash; - uint8_t issuer_can_freeze = true; - uint8_t issuer_can_recall = true; - uint8_t issuer_can_whitelist = true; - - /*(issuer_agreement_hash)*/ - EOSLIB_SERIALIZE( create, (issuer)(maximum_supply)(issuer_can_freeze)(issuer_can_recall)(issuer_can_whitelist) ) - }; - - struct transfer - { - account_name from; - account_name to; - asset quantity; - string memo; - - EOSLIB_SERIALIZE( transfer, (from)(to)(quantity)(memo) ) - }; - - struct issue { - account_name to; - asset quantity; - string memo; - - EOSLIB_SERIALIZE( issue, (to)(quantity)(memo) ) - }; - - struct fee_schedule { - uint64_t primary_key()const { return 0; } - - array fee_per_length; - EOSLIB_SERIALIZE( fee_schedule, (fee_per_length) ) - }; - - struct account { - asset balance; - bool frozen = false; - bool whitelist = true; - - uint64_t primary_key()const { return balance.symbol.name(); } - - EOSLIB_SERIALIZE( account, (balance)(frozen)(whitelist) ) - }; - - struct currency_stats { - asset supply; - asset max_supply; - account_name issuer; - bool can_freeze = true; - bool can_recall = true; - bool can_whitelist = true; - bool is_frozen = false; - bool enforce_whitelist = false; - - uint64_t primary_key()const { return supply.symbol.name(); } - - EOSLIB_SERIALIZE( currency_stats, (supply)(max_supply)(issuer)(can_freeze)(can_recall)(can_whitelist)(is_frozen)(enforce_whitelist) ) - }; - - typedef eosio::multi_index accounts; - typedef eosio::multi_index stats; - - - asset get_balance( account_name owner, symbol_name symbol )const { - accounts t( _contract, owner ); - return t.get(symbol).balance; - } - - asset get_supply( symbol_name symbol )const { - accounts t( _contract, symbol ); - return t.get(symbol).balance; - } - - static void inline_transfer( account_name from, account_name to, extended_asset amount, string memo = string(), permission_name perm = N(active) ) { - action act( permission_level( from, perm ), amount.contract, N(transfer), transfer{from,to,amount,memo} ); - act.send(); - } - - void inline_transfer( account_name from, account_name to, asset amount, string memo = string(), permission_name perm = N(active) ) { - action act( permission_level( from, perm ), _contract, N(transfer), transfer{from,to,amount,memo} ); - act.send(); - } - - - bool apply( account_name contract, action_name act ) { - if( contract != _contract ) - return false; - - switch( act ) { - case N(issue): - print( "issue\n"); - on( unpack_action_data() ); - return true; - case N(transfer): - print( "transfer\n"); - on( unpack_action_data() ); - return true; - case N(create): - print( "create\n"); - on( unpack_action_data() ); - return true; - } - return false; - } - - /** - * This is factored out so it can be used as a building block - */ - void create_currency( const create& c ) { - auto sym = c.maximum_supply.symbol; - eosio_assert( sym.is_valid(), "invalid symbol name" ); - - stats statstable( _contract, sym.name() ); - auto existing = statstable.find( sym.name() ); - eosio_assert( existing == statstable.end(), "token with symbol already exists" ); - - statstable.emplace( c.issuer, [&]( auto& s ) { - s.supply.symbol = c.maximum_supply.symbol; - s.max_supply = c.maximum_supply; - s.issuer = c.issuer; - s.can_freeze = c.issuer_can_freeze; - s.can_recall = c.issuer_can_recall; - s.can_whitelist = c.issuer_can_whitelist; - }); - } - - void issue_currency( const issue& i ) { - auto sym = i.quantity.symbol.name(); - stats statstable( _contract, sym ); - const auto& st = statstable.get( sym ); - - statstable.modify( st, 0, [&]( auto& s ) { - s.supply.amount += i.quantity.amount; - eosio_assert( s.supply.amount >= 0, "underflow" ); - }); - - add_balance( st.issuer, i.quantity, st, st.issuer ); - } - - - void on( const create& c ) { - require_auth( c.issuer ); - create_currency( c ); - - /* - auto fee = get_fee_schedule()[c.maximum_supply.name_length()]; - if( fee.amount > 0 ) { - inline_transfer( c.issuer, _contract, fee, "symbol registration fee" ); - } - */ - } - - void on( const issue& i ) { - auto sym = i.quantity.symbol.name(); - stats statstable( _contract, sym ); - const auto& st = statstable.get( sym ); - - require_auth( st.issuer ); - eosio_assert( i.quantity.is_valid(), "invalid quantity" ); - eosio_assert( i.quantity.amount > 0, "must issue positive quantity" ); - - statstable.modify( st, 0, [&]( auto& s ) { - s.supply.amount += i.quantity.amount; - }); - - add_balance( st.issuer, i.quantity, st, st.issuer ); - - if( i.to != st.issuer ) - { - inline_transfer( st.issuer, i.to, i.quantity, i.memo ); - } - } - - void on( const transfer& t ) { - require_auth(t.from); - auto sym = t.quantity.symbol.name(); - stats statstable( _contract, sym ); - const auto& st = statstable.get( sym ); - - require_recipient( t.to ); - - eosio_assert( t.quantity.is_valid(), "invalid quantity" ); - eosio_assert( t.quantity.amount > 0, "must transfer positive quantity" ); - sub_balance( t.from, t.quantity, st ); - add_balance( t.to, t.quantity, st, t.from ); - } - - - private: - void sub_balance( account_name owner, asset value, const currency_stats& st ) { - accounts from_acnts( _contract, owner ); - - const auto& from = from_acnts.get( value.symbol.name() ); - eosio_assert( from.balance.amount >= value.amount, "overdrawn balance" ); - - if( has_auth( owner ) ) { - eosio_assert( !st.can_freeze || !from.frozen, "account is frozen by issuer" ); - eosio_assert( !st.can_freeze || !st.is_frozen, "all transfers are frozen by issuer" ); - eosio_assert( !st.enforce_whitelist || from.whitelist, "account is not white listed" ); - } else if( has_auth( st.issuer ) ) { - eosio_assert( st.can_recall, "issuer may not recall token" ); - } else { - eosio_assert( false, "insufficient authority" ); - } - - from_acnts.modify( from, owner, [&]( auto& a ) { - a.balance.amount -= value.amount; - }); - } - - void add_balance( account_name owner, asset value, const currency_stats& st, account_name ram_payer ) - { - accounts to_acnts( _contract, owner ); - auto to = to_acnts.find( value.symbol.name() ); - if( to == to_acnts.end() ) { - eosio_assert( !st.enforce_whitelist, "can only transfer to white listed accounts" ); - to_acnts.emplace( ram_payer, [&]( auto& a ){ - a.balance = value; - }); - } else { - eosio_assert( !st.enforce_whitelist || to->whitelist, "receiver requires whitelist by issuer" ); - to_acnts.modify( to, 0, [&]( auto& a ) { - a.balance.amount += value.amount; - }); - } - } - - private: - account_name _contract; - }; - -} diff --git a/contracts/infinite/CMakeLists.txt b/contracts/infinite/CMakeLists.txt deleted file mode 100644 index af3ec44f4967e8b1d65cfea82471b2d68a7f9048..0000000000000000000000000000000000000000 --- a/contracts/infinite/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_wast_executable(TARGET infinite - INCLUDE_FOLDERS "${STANDARD_INCLUDE_FOLDERS}" - LIBRARIES libc++ libc eosiolib - DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR} -) diff --git a/contracts/infinite/infinite.cpp b/contracts/infinite/infinite.cpp deleted file mode 100644 index 21a542c1a282ee9e5aa4584c34f7036667371459..0000000000000000000000000000000000000000 --- a/contracts/infinite/infinite.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/** - * @file - * @copyright defined in eos/LICENSE.txt - */ -#include /// defines transfer struct (abi) - -extern "C" { - - /// The apply method just prints forever - void apply( uint64_t, uint64_t, uint64_t ) { - int idx = 0; - while(true) { - eosio::print(idx++); - } - } -} diff --git a/contracts/simple.token/CMakeLists.txt b/contracts/simple.token/CMakeLists.txt deleted file mode 100644 index 1e755eabe2f49aa2ec424f1b1d4998bb043cfb7b..0000000000000000000000000000000000000000 --- a/contracts/simple.token/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ - -file(GLOB ABI_FILES "*.abi") -configure_file("${ABI_FILES}" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY) - -add_wast_executable(TARGET simple.token - INCLUDE_FOLDERS "${STANDARD_INCLUDE_FOLDERS}" - LIBRARIES libc++ libc eosiolib - DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR} -) diff --git a/contracts/simple.token/simple.token.abi b/contracts/simple.token/simple.token.abi deleted file mode 100644 index 2c63c0851048d8f7bff41ecf0f8cee05f52fd120..0000000000000000000000000000000000000000 --- a/contracts/simple.token/simple.token.abi +++ /dev/null @@ -1,2 +0,0 @@ -{ -} diff --git a/contracts/simple.token/simple.token.cpp b/contracts/simple.token/simple.token.cpp deleted file mode 100644 index 1f2ab97feca28e42881f22e0f5abcf8be089c108..0000000000000000000000000000000000000000 --- a/contracts/simple.token/simple.token.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include - -class simpletoken : public eosio::contract { - public: - simpletoken( account_name self ) - :contract(self),_accounts( _self, _self){} - - void transfer( account_name from, account_name to, uint64_t quantity ) { - require_auth( from ); - - const auto& fromacnt = _accounts.get( from ); - eosio_assert( fromacnt.balance >= quantity, "overdrawn balance" ); - _accounts.modify( fromacnt, from, [&]( auto& a ){ a.balance -= quantity; } ); - - add_balance( from, to, quantity ); - } - - void issue( account_name to, uint64_t quantity ) { - require_auth( _self ); - add_balance( _self, to, quantity ); - } - - private: - struct account { - account_name owner; - uint64_t balance; - - uint64_t primary_key()const { return owner; } - }; - - eosio::multi_index _accounts; - - void add_balance( account_name payer, account_name to, uint64_t q ) { - auto toitr = _accounts.find( to ); - if( toitr == _accounts.end() ) { - _accounts.emplace( payer, [&]( auto& a ) { - a.owner = to; - a.balance = q; - }); - } else { - _accounts.modify( toitr, 0, [&]( auto& a ) { - a.balance += q; - eosio_assert( a.balance >= q, "overflow detected" ); - }); - } - } -}; - -EOSIO_ABI( simpletoken, (transfer)(issue) ) diff --git a/contracts/social/CMakeLists.txt b/contracts/social/CMakeLists.txt deleted file mode 100644 index 72d5d9e059e10d0701cc03247835336d32b63db7..0000000000000000000000000000000000000000 --- a/contracts/social/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_wast_executable(TARGET social - INCLUDE_FOLDERS "${STANDARD_INCLUDE_FOLDERS}" - LIBRARIES eosiolib - DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR} -) diff --git a/contracts/social/social.cpp b/contracts/social/social.cpp deleted file mode 100644 index 7cee3dd1ddff5b690778316445d352c9f344f162..0000000000000000000000000000000000000000 --- a/contracts/social/social.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/** - * @file - * @copyright defined in eos/LICENSE.txt - */ -#include - -/** - * The purpose of this contract is to implement something like Steem on EOS, this - * means this contract defines its own currency, allows people to create posts, vote - * on posts, and stake their voting power. - * - * Unlike Steem, the goal is to enable maximum parallelism and enable the currency to - * be easily integrated with an exchange contract. - */ - -struct post_action { - account_name author; - post_name postid; - account_name reply_to_author; - int32_t reply_to_id; - uint8_t author; /// index in notify list - char[] data; /// ignored, title is embedded within - - account_name get_author()const { return get_notify(author); } -}; - -struct vote_action { - account_name voter; - account_name author; - post_name postid; - int32_t vote_power; -}; - -struct post_record { - uint64_t total_votes = 0; - uint64_t claimed_votes = 0; - uint32_t created; - - post_record( uint32_t c = now() ):created(c){} - static Name table_id() { return Name("post"); } -}; - -struct account { - uint64_t social = 0; - uint64_t social_power = 0; - int32_t vote_power = 0; - uint32_t last_vote = 0; - - static Name table_id() { return Name("account"); } -}; - - -/** - * When a user posts we create a record that tracks the total votes and the time it - * was created. A user can submit this action multiple times, but subsequent calls do - * nothing. - * - * This method only does something when called in the context of the author, if - * any other contexts are notified - */ -void apply_social_post() { - const auto& post = current_action(); - require_auth( post.author ); - - eosio_assert( current_context() == post.author, "cannot call from any other context" ); - - static post_record& existing; - if( !Db::get( post.postid, existing ) ) - Db::store( post.postid, post_record( now() ) ); -} - -/** - * This action is called when a user casts a vote, it requires that this code is executed - * in the context of both the voter and the author. When executed in the author's context it - * updates the vote total. When executed - */ -void apply_social_vote() { - const auto& vote = current_action(); - require_recipient( vote.voter, vote.author ); - disable_context_code( vote.author() ); /// prevent the author's code from rejecting the potentially negative vote - - auto context = current_context(); - auto voter = vote.getVoter(); - - if( context == vote.author ) { - static post_record post; - eosio_assert( Db::get( vote.postid, post ) > 0, "unable to find post" ); - eosio_assert( now() - post.created < days(7), "cannot vote after 7 days" ); - post.votes += vote.vote_power; - Db::store( vote.postid, post ); - } - else if( context == vote.voter ) { - static account vote_account; - Db::get( "account", vote_account ); - auto abs_vote = abs(vote.vote_power); - vote_account.vote_power = min( vote_account.social_power, - vote_account.vote_power + (vote_account.social_power * (now()-last_vote)) / days(7)); - eosio_assert( abs_vote <= vote_account.vote_power, "insufficient vote power" ); - post.votes += vote.vote_power; - vote_account.vote_power -= abs_vote; - vote_account.last_vote = now(); - Db::store( "account", vote_account ); - } else { - eosio_assert( false, "invalid context for execution of this vote" ); - } -} - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ad77d85028577854cd548d048d81032536678b81..203a7cdd023537b76dd451a4290d3784a3b31ad4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,7 +21,6 @@ target_link_libraries( plugin_test eosio_testing eosio_chain chainbase eos_utili target_include_directories( plugin_test PUBLIC ${CMAKE_SOURCE_DIR}/plugins/net_plugin/include ${CMAKE_SOURCE_DIR}/plugins/chain_plugin/include ) -add_dependencies(plugin_test asserter test_api test_api_mem test_api_db test_api_multi_index proxy identity identity_test stltest infinite eosio.system eosio.token eosio.bios test.inline multi_index_test noop eosio.msig) # configure_file(${CMAKE_CURRENT_SOURCE_DIR}/core_symbol.py.in ${CMAKE_CURRENT_BINARY_DIR}/core_symbol.py) diff --git a/tests/chain_plugin_tests.cpp b/tests/chain_plugin_tests.cpp index 2b7867a07e94b20d0b71dd02911ed8fb91a7bd50..5a489c255b4fd410ca69d9bb860e519f15839c03 100644 --- a/tests/chain_plugin_tests.cpp +++ b/tests/chain_plugin_tests.cpp @@ -12,15 +12,6 @@ #include #include -#include -#include - -#include -#include - -#include -#include - #include #include diff --git a/tests/chain_tests/proof_tests.cpp b/tests/chain_tests/proof_tests.cpp deleted file mode 100644 index 6240443d77d6cca72146478f6d48a8a9a6203844..0000000000000000000000000000000000000000 --- a/tests/chain_tests/proof_tests.cpp +++ /dev/null @@ -1,340 +0,0 @@ -#include -#include -#include -#include - -#ifdef NON_VALIDATING_TEST -#define TESTER tester -#else -#define TESTER validating_tester -#endif - -using namespace eosio; -using namespace eosio::chain; -using namespace eosio::testing; - -struct action_proof_data { - account_name receiver; - scope_name scope; - action_name name; - bytes data; - uint64_t region_id; - uint64_t cycle_index; - vector data_access; -}; -FC_REFLECT(action_proof_data, (receiver)(scope)(name)(data)(region_id)(cycle_index)(data_access)); - - -struct merkle_node { - digest_type digest; - optional left; - optional right; - optional parent; -}; - -digest_type process_merkle(vector& nodes, vector leaf_indices) { - size_t num_nodes = leaf_indices.size(); - size_t base = 0; - - if (num_nodes == 0) { - return digest_type(); - } else if (num_nodes == 1) { - return nodes[leaf_indices.front()].digest; - } - - while (num_nodes > 1) { - size_t new_nodes = (num_nodes / 2) + (num_nodes % 2); - for(size_t idx = 0; idx < new_nodes; idx++) { - size_t l_idx = idx * 2; - size_t r_idx = l_idx + 1; - size_t left = leaf_indices.at(base + l_idx); - if (r_idx >= num_nodes) { - nodes.emplace_back( - merkle_node{ - digest_type::hash(make_canonical_pair(nodes[left].digest, nodes[left].digest)), - left - }); - nodes[left].parent.emplace(nodes.size() - 1); - } else { - size_t right = leaf_indices.at(base + r_idx); - nodes.emplace_back( - merkle_node{ - digest_type::hash(make_canonical_pair(nodes[left].digest, nodes[right].digest)), - left, - right - }); - nodes[left].parent.emplace(nodes.size() - 1); - nodes[right].parent.emplace(nodes.size() - 1); - } - - leaf_indices.emplace_back(nodes.size() - 1); - } - - base += num_nodes; - num_nodes = new_nodes; - } - - return nodes.back().digest; -} - -auto get_proof_path(const vector& nodes, size_t leaf) { - vector path; - digest_type current = nodes[leaf].digest; - while (nodes[leaf].parent.valid()) { - size_t parent = *nodes[leaf].parent; - if (leaf == *nodes[parent].left) { - if (nodes[parent].right.valid()) { - size_t right = *nodes[parent].right; - path.emplace_back(make_canonical_right(nodes[right].digest)); - current = digest_type::hash(make_canonical_pair(nodes[leaf].digest, nodes[right].digest)); - } else { - path.emplace_back(make_canonical_right(nodes[leaf].digest)); - current = digest_type::hash(make_canonical_pair(nodes[leaf].digest, nodes[leaf].digest)); - } - } else { - size_t left = *nodes[parent].left; - path.emplace_back(make_canonical_left(nodes[left].digest)); - current = digest_type::hash(make_canonical_pair(nodes[left].digest, nodes[leaf].digest)); - } - - leaf = parent; - } - - return path; -} - -digest_type apply_path(const digest_type& digest, const vector& path) { - digest_type current = digest; - - for (const auto& p: path ) { - if (is_canonical_left(p)) { - current = digest_type::hash(make_canonical_pair(p, current)); - } else { - current = digest_type::hash(make_canonical_pair(current, p)); - } - } - - return current; -} - -bool proof_is_valid(const digest_type& digest, const vector& path, const digest_type& expected_root) { - return apply_path(digest, path) == expected_root; -} - -BOOST_AUTO_TEST_SUITE(proof_tests) - -BOOST_FIXTURE_TEST_CASE( prove_block_in_chain, validating_tester ) { try { - vector known_blocks; - known_blocks.reserve(100); - block_header last_block_header; - - // register a callback on new blocks to record block information - validating_node->applied_block.connect([&](const block_trace& bt){ - known_blocks.emplace_back(bt.block.id()); - last_block_header = bt.block; - }); - - produce_blocks(100); - return; - vector nodes; - vector ids; - vector block_leaves; - nodes.reserve(100); - ids.reserve(100); - for (const auto& blk_id: known_blocks) { - nodes.emplace_back(merkle_node{blk_id}); - ids.push_back(blk_id); - block_leaves.push_back(nodes.size() - 1); - } - - digest_type block_mroot = process_merkle(nodes, move(block_leaves)); - - BOOST_REQUIRE_EQUAL((std::string)block_mroot, (std::string)merkle(ids)); - - produce_block(); - - BOOST_REQUIRE_EQUAL((std::string)block_mroot, (std::string)last_block_header.block_mroot); - - for (int idx = 0; idx < 100; idx++) { - vector path = get_proof_path(nodes, idx); - - BOOST_REQUIRE_EQUAL(true, proof_is_valid(nodes[idx].digest, path, last_block_header.block_mroot)); - - /** UNCOMMENT TO PRODUCE PROOFS TO STD OUT - std::cout << idx << ":" << std::string(known_blocks.at(idx)) << " = "; - for (const auto& e: path) { - std::cout << std::string(e) << " "; - } - - std::cout << "-> " << std::string(last_block_header.block_mroot) << std::endl; - */ - } - -} FC_LOG_AND_RETHROW() } /// transfer_test - - -struct action_proof_info { - action_trace trace; - - size_t action_leaf; - size_t block_leaf; - - uint32_t cycle_index; - uint32_t region_id; -}; - -/** - * This test case will attempt to allow one account to transfer on behalf - * of another account by updating the active authority. - */ -BOOST_FIXTURE_TEST_CASE( prove_action_in_block, validating_tester ) { try { - vector nodes; - vector block_leaves; - vector known_actions; - map block_action_mroots; - block_header last_block_header; - block_id_type last_block_id; - - // register a callback on new blocks to record block information - validating_node->applied_block.connect([&](const block_trace& bt){ - nodes.emplace_back(merkle_node{bt.block.id()}); - size_t block_leaf = nodes.size() - 1; - block_leaves.push_back(block_leaf); - - vector region_leaves; - - for (uint32_t r_idx = 0; r_idx < bt.region_traces.size(); r_idx++) { - const auto& rt = bt.region_traces.at(r_idx); - - vector shard_leaves; - - for (uint32_t c_idx = 0; c_idx < rt.cycle_traces.size(); c_idx++) { - const auto& ct = rt.cycle_traces.at(c_idx); - - for (const auto& st: ct.shard_traces) { - vector action_leaves; - - for (const auto& tt: st.transaction_traces) { - for (const auto& at: tt.action_traces) { - digest_type::encoder enc; - - auto a_data = action_proof_data { - at.receiver, - at.act.account, - at.act.name, - at.act.data, - tt.region_id, - tt.cycle_index, - at.data_access - }; - fc::raw::pack(enc, a_data); - nodes.emplace_back(merkle_node{enc.result()}); - size_t action_leaf = nodes.size() - 1; - known_actions.emplace_back(action_proof_info{at, action_leaf, block_leaf, c_idx, r_idx }); - action_leaves.emplace_back(action_leaf); - } - } - - if (action_leaves.size() > 0) { - process_merkle(nodes, move(action_leaves)); - } else { - nodes.emplace_back(merkle_node{digest_type()}); - } - shard_leaves.emplace_back(nodes.size() - 1); - } - } - - if (shard_leaves.size() > 0) { - process_merkle(nodes, move(shard_leaves)); - } else { - nodes.emplace_back(merkle_node{digest_type()}); - } - - region_leaves.emplace_back(nodes.size() - 1); - } - - digest_type action_mroot = process_merkle(nodes, move(region_leaves)); - BOOST_REQUIRE_EQUAL((std::string)bt.block.action_mroot, (std::string)action_mroot); - - last_block_header = bt.block; - last_block_id = bt.block.id(); - block_action_mroots[bt.block.id()] = bt.block.action_mroot; - }); - - create_accounts( { N(alice), N(bob), N(carol), N(david), N(elvis) }); - - produce_blocks(50); - - push_dummy(N(alice), "AB"); - push_dummy(N(bob), "BC"); - push_dummy(N(carol), "CD"); - push_dummy(N(david), "DE"); - push_dummy(N(elvis), "EF"); - - produce_blocks(50); - digest_type block_mroot = process_merkle(nodes, move(block_leaves)); - - produce_block(); - BOOST_REQUIRE_EQUAL((std::string)block_mroot, (std::string)last_block_header.block_mroot); - - /* UNCOMMENT TO PRODUCE PROOFS TO STDOUT - std::cout << "Best Block ID: " << (std::string)last_block_id << std::endl; - std::cout << " Merkle Root: " << (std::string)last_block_header.block_mroot << std::endl; - - for(const auto& ai : known_actions) { - auto block_path = get_proof_path(nodes, ai.action_leaf); - auto chain_path = get_proof_path(nodes, ai.block_leaf); - - // prove action in block - auto shard_root = apply_path(nodes[ai.action_leaf].digest, block_path); - BOOST_REQUIRE_EQUAL((std::string)shard_root, (std::string)block_action_mroots[nodes[ai.block_leaf].digest]); - - // prove that block is part of the chain - auto expected_block_mroot = apply_path(nodes[ai.block_leaf].digest, chain_path); - BOOST_REQUIRE_EQUAL((std::string)expected_block_mroot, (std::string)last_block_header.block_mroot); - - std::cout << "Proof for Action:" << std::endl; - std::cout << std::setw(14) << "reciever" << ":" << (std::string) ai.trace.receiver << std::endl; - std::cout << std::setw(14) << "scope" << ":" << (std::string) ai.trace.act.scope << std::endl; - std::cout << std::setw(14) << "name" << ":" << (std::string) ai.trace.act.name << std::endl; - std::cout << std::setw(14) << "data" << ":" << fc::json::to_string(ai.trace.act.as()) << std::endl; - std::cout << std::setw(14) << "data_access" << ":" << fc::json::to_string(ai.trace.data_access) << std::endl; - std::cout << std::setw(14) << "region" << ":" << ai.region_id << std::endl; - std::cout << std::setw(14) << "cycle" << ":" << ai.cycle_index << std::endl; - std::cout << std::setw(14) << "block" << ":" << (std::string)nodes[ai.block_leaf].digest << std::endl; - std::cout << std::setw(14) << "am_root" << ":" << (std::string)block_action_mroots[nodes[ai.block_leaf].digest] << std::endl; - std::cout << std::endl; - - auto a_data = action_proof_data { - ai.trace.receiver, - ai.trace.act.scope, - ai.trace.act.name, - ai.trace.act.data, - ai.trace.region_id, - ai.trace.cycle_index, - ai.trace.data_access - }; - auto action_data = fc::raw::pack(a_data); - - std::cout << "Action Hex: " << fc::to_hex(action_data) << std::endl; - std::cout << "Action Hash: " << (std::string)nodes[ai.action_leaf].digest << std::endl; - - std::cout << "Action Path: "; - for (const auto& p: block_path) { - std::cout << (std::string)p << " "; - } - std::cout << std::endl; - - std::cout << "Block Path: "; - for (const auto& p: chain_path) { - std::cout << (std::string)p << " "; - } - std::cout << std::endl; - }*/ - - -} FC_LOG_AND_RETHROW() } - - - -BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/get_table_tests.cpp b/tests/get_table_tests.cpp index 818ca5562d23beb902b6446dddf9a612a481569b..634f736222ea6a48f00747804c82c02a52876f7d 100644 --- a/tests/get_table_tests.cpp +++ b/tests/get_table_tests.cpp @@ -12,12 +12,6 @@ #include #include -#include -#include - -#include -#include - #include #include diff --git a/tests/p2p_tests/fuzz_test_generic.sh b/tests/p2p_tests/fuzz_test_generic.sh deleted file mode 100644 index ae913565c867c388695b1b033c2de5bb445a6520..0000000000000000000000000000000000000000 --- a/tests/p2p_tests/fuzz_test_generic.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# -# This script captures the generic fuzz testing to which -# net_plugin has been subjected. It typically results in -# message buffers in excess of 1 gigabyte. -# -if ! pgrep nodeos > /dev/null; then - echo "Run nodeos with net_plugin configured for port 9876." - exit 1 -fi -for i in `seq 1 10000`; do netcat localhost 9876 < /dev/urandom; done diff --git a/tests/p2p_tests/pump/run_test.pl b/tests/p2p_tests/pump/run_test.pl deleted file mode 100755 index 11e467a5d2ea96fe17916d0e8bfb41b80d8d42ad..0000000000000000000000000000000000000000 --- a/tests/p2p_tests/pump/run_test.pl +++ /dev/null @@ -1,285 +0,0 @@ -#!/usr/bin/perl - -use strict; -use Getopt::Long; -use Env; -use File::Basename; -use File::copy; -use File::Spec; -use File::Path; -use Cwd; - -my $eos_home = defined $ENV{EOS_HOME} ? $ENV{EOS_HOME} : getcwd; -my $eosd = $eos_home . "/programs/eosd/eosd"; -my $eosc = $eos_home . "/programs/eosc/eosc"; - -my $nodes = defined $ENV{EOS_TEST_RING} ? $ENV{EOS_TEST_RING} : "1"; -my $pnodes = defined $ENV{EOS_TEST_PRODUCERS} ? $ENV{EOS_TEST_PRODUCERS} : "1"; - -my $prods = 21; -my $genesis = "$eos_home/genesis.json"; -my $http_port_base = 8888; -my $p2p_port_base = 9876; -my $data_dir_base = "tdn"; -my $hostname = "127.0.0.1"; -my $first_pause = 0; -my $launch_pause = 0; -my $run_duration = 60; -my $topo = "ring"; -my $override_gts = ""; -my $no_delay=0; -my $test=1; - -if (!GetOptions("nodes=i" => \$nodes, - "first-pause=i" => \$first_pause, - "launch-pause=i" => \$launch_pause, - "duration=i" => \$run_duration, - "topo=s" => \$topo, - "test=i" => \$test, - "time-stamp=s" => \$override_gts, - "pnodes=i" => \$pnodes)) { - print "usage: $ARGV[0] [--nodes=] [--pnodes=] [--topo=] [--first-pause=] [--launch-pause=] [--duration=] [--time-stamp=