diff --git a/.cicd/test.sh b/.cicd/test.sh index 2c04626bd..d4e45617e 100755 --- a/.cicd/test.sh +++ b/.cicd/test.sh @@ -31,4 +31,4 @@ fi if [[ "$EXIT_STATUS" != 0 ]]; then echo "Failing due to non-zero exit status from ctest: $EXIT_STATUS" exit $EXIT_STATUS -fi +fi \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 5783e8319..08c995ed9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,9 @@ cmake_minimum_required(VERSION 3.5) project(eosio_contracts) set(VERSION_MAJOR 1) -set(VERSION_MINOR 8) -set(VERSION_PATCH 3) -#set(VERSION_SUFFIX develop) +set(VERSION_MINOR 9) +set(VERSION_PATCH 0) +#set(VERSION_SUFFIX rc4) if (VERSION_SUFFIX) set(VERSION_FULL "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_SUFFIX}") @@ -19,8 +19,8 @@ find_package(eosio.cdt) message(STATUS "Building eosio.contracts v${VERSION_FULL}") -set(EOSIO_CDT_VERSION_MIN "1.6") -set(EOSIO_CDT_VERSION_SOFT_MAX "1.6") +set(EOSIO_CDT_VERSION_MIN "1.7") +set(EOSIO_CDT_VERSION_SOFT_MAX "1.7") #set(EOSIO_CDT_VERSION_HARD_MAX "") ### Check the version of eosio.cdt diff --git a/README.md b/README.md index 34fb56efd..46070ba11 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # eosio.contracts -## Version : 1.8.3 +## Version : 1.9.0 The design of the EOSIO blockchain calls for a number of smart contracts that are run at a privileged permission level in order to support functions such as block producer registration and voting, token staking for CPU and network bandwidth, RAM purchasing, multi-sig, etc. These smart contracts are referred to as the bios, system, msig, wrap (formerly known as sudo) and token contracts. @@ -15,8 +15,8 @@ The following unprivileged contract(s) are also part of the system. * [eosio.token](./contracts/eosio.token) Dependencies: -* [eosio.cdt v1.6.x](https://github.com/EOSIO/eosio.cdt/releases/tag/v1.6.3) -* [eosio v1.8.x](https://github.com/EOSIO/eos/releases/tag/v1.8.6) (optional dependency only needed to build unit tests) +* [eosio.cdt v1.7.x](https://github.com/EOSIO/eosio.cdt/releases/tag/v1.7.0-rc1) +* [eosio v2.0.x](https://github.com/EOSIO/eos/releases/tag/v2.0.0-rc2) (optional dependency only needed to build unit tests) To build the contracts follow the instructions in [`Build and deploy` section](./docs/02_build-and-deploy.md). diff --git a/contracts/eosio.bios/include/eosio.bios/eosio.bios.hpp b/contracts/eosio.bios/include/eosio.bios/eosio.bios.hpp index 4f190b27d..76a2215e9 100644 --- a/contracts/eosio.bios/include/eosio.bios/eosio.bios.hpp +++ b/contracts/eosio.bios/include/eosio.bios/eosio.bios.hpp @@ -7,37 +7,6 @@ #include #include -// This header is needed until `is_feature_activiated` and `preactivate_feature` are added to `eosio.cdt` -#include - -namespace eosio { - namespace internal_use_do_not_use { - extern "C" { - __attribute__((eosio_wasm_import)) - bool is_feature_activated( const ::capi_checksum256* feature_digest ); - - __attribute__((eosio_wasm_import)) - void preactivate_feature( const ::capi_checksum256* feature_digest ); - } - } -} - -namespace eosio { - bool is_feature_activated( const eosio::checksum256& feature_digest ) { - auto feature_digest_data = feature_digest.extract_as_byte_array(); - return internal_use_do_not_use::is_feature_activated( - reinterpret_cast( feature_digest_data.data() ) - ); - } - - void preactivate_feature( const eosio::checksum256& feature_digest ) { - auto feature_digest_data = feature_digest.extract_as_byte_array(); - internal_use_do_not_use::preactivate_feature( - reinterpret_cast( feature_digest_data.data() ) - ); - } -} - /** * EOSIO Contracts * @@ -57,9 +26,13 @@ namespace eosio { * - eosio.token */ -namespace eosio { +namespace eosiobios { + using eosio::action_wrapper; + using eosio::check; + using eosio::checksum256; using eosio::ignore; + using eosio::name; using eosio::permission_level; using eosio::public_key; @@ -112,7 +85,7 @@ namespace eosio { (schedule_version)(new_producers)) }; - class [[eosio::contract("eosio.bios")]] bios : public contract { + class [[eosio::contract("eosio.bios")]] bios : public eosio::contract { public: using contract::contract; /** @@ -285,7 +258,7 @@ namespace eosio { * @param schedule - New list of active producers to set */ [[eosio::action]] - void setprods( std::vector schedule ); + void setprods( const std::vector& schedule ); /** * Set the blockchain parameters diff --git a/contracts/eosio.bios/ricardian/eosio.bios.contracts.md.in b/contracts/eosio.bios/ricardian/eosio.bios.contracts.md.in index 1acb02b6b..a08b66e43 100644 --- a/contracts/eosio.bios/ricardian/eosio.bios.contracts.md.in +++ b/contracts/eosio.bios/ricardian/eosio.bios.contracts.md.in @@ -154,7 +154,13 @@ icon: @ICON_BASE_URL@/@ADMIN_ICON_URI@ {{$action.account}} proposes a block producer schedule of: {{#each schedule}} - 1. {{this.producer_name}} with a block signing key of {{this.block_signing_key}} + 1. {{this.producer_name}} +{{/each}} + +The block signing authorities of each of the producers in the above schedule are listed below: +{{#each schedule}} +### {{this.producer_name}} +{{to_json this.authority}} {{/each}}

unlinkauth

diff --git a/contracts/eosio.bios/src/eosio.bios.cpp b/contracts/eosio.bios/src/eosio.bios.cpp index 8b9165cc7..69d6758f3 100644 --- a/contracts/eosio.bios/src/eosio.bios.cpp +++ b/contracts/eosio.bios/src/eosio.bios.cpp @@ -1,6 +1,6 @@ #include -namespace eosio { +namespace eosiobios { void bios::setabi( name account, const std::vector& abi ) { abi_hash_table table(get_self(), get_self().value); @@ -8,11 +8,11 @@ void bios::setabi( name account, const std::vector& abi ) { if( itr == table.end() ) { table.emplace( account, [&]( auto& row ) { row.owner = account; - row.hash = sha256(const_cast(abi.data()), abi.size()); + row.hash = eosio::sha256(const_cast(abi.data()), abi.size()); }); } else { - table.modify( itr, same_payer, [&]( auto& row ) { - row.hash = sha256(const_cast(abi.data()), abi.size()); + table.modify( itr, eosio::same_payer, [&]( auto& row ) { + row.hash = eosio::sha256(const_cast(abi.data()), abi.size()); }); } } @@ -31,7 +31,7 @@ void bios::setalimits( name account, int64_t ram_bytes, int64_t net_weight, int6 set_resource_limits( account, ram_bytes, net_weight, cpu_weight ); } -void bios::setprods( std::vector schedule ) { +void bios::setprods( const std::vector& schedule ) { require_auth( get_self() ); set_proposed_producers( schedule ); } diff --git a/contracts/eosio.msig/src/eosio.msig.cpp b/contracts/eosio.msig/src/eosio.msig.cpp index 8fd75213d..176921929 100644 --- a/contracts/eosio.msig/src/eosio.msig.cpp +++ b/contracts/eosio.msig/src/eosio.msig.cpp @@ -30,8 +30,7 @@ void multisig::propose( ignore proposer, check( proptable.find( _proposal_name.value ) == proptable.end(), "proposal with the same name exists" ); auto packed_requested = pack(_requested); - // TODO: Remove internal_use_do_not_use namespace after minimum eosio.cdt dependency becomes 1.7.x - auto res = internal_use_do_not_use::check_transaction_authorization( + auto res = check_transaction_authorization( trx_pos, size, (const char*)0, 0, packed_requested.data(), packed_requested.size() @@ -175,8 +174,7 @@ void multisig::exec( name proposer, name proposal_name, name executer ) { old_apptable.erase(apps); } auto packed_provided_approvals = pack(approvals); - // TODO: Remove internal_use_do_not_use namespace after minimum eosio.cdt dependency becomes 1.7.x - auto res = internal_use_do_not_use::check_transaction_authorization( + auto res = check_transaction_authorization( prop.packed_transaction.data(), prop.packed_transaction.size(), (const char*)0, 0, packed_provided_approvals.data(), packed_provided_approvals.size() diff --git a/contracts/eosio.system/include/eosio.system/eosio.system.hpp b/contracts/eosio.system/include/eosio.system/eosio.system.hpp index 3cfce3f42..fb7e8cdb1 100644 --- a/contracts/eosio.system/include/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/include/eosio.system/eosio.system.hpp @@ -1,7 +1,9 @@ #pragma once #include +#include #include +#include #include #include #include @@ -179,22 +181,24 @@ namespace eosiosystem { // Defines `producer_info` structure to be stored in `producer_info` table, added after version 1.0 struct [[eosio::table, eosio::contract("eosio.system")]] producer_info { - name owner; - double total_votes = 0; - eosio::public_key producer_key; /// a packed public key object - bool is_active = true; - std::string url; - uint32_t unpaid_blocks = 0; - time_point last_claim_time; - uint16_t location = 0; + name owner; + double total_votes = 0; + eosio::public_key producer_key; /// a packed public key object + bool is_active = true; + std::string url; + uint32_t unpaid_blocks = 0; + time_point last_claim_time; + uint16_t location = 0; + eosio::binary_extension producer_authority; // added in version 1.9.0 + uint64_t primary_key()const { return owner.value; } double by_votes()const { return is_active ? -total_votes : total_votes; } bool active()const { return is_active; } - void deactivate() { producer_key = public_key(); is_active = false; } + void deactivate() { producer_key = public_key(); producer_authority.reset(); is_active = false; } // explicit serialization macro is not necessary, used here only to improve compilation time EOSLIB_SERIALIZE( producer_info, (owner)(total_votes)(producer_key)(is_active)(url) - (unpaid_blocks)(last_claim_time)(location) ) + (unpaid_blocks)(last_claim_time)(location)(producer_authority) ) }; // Defines new producer info structure to be stored in new producer info table, added after version 1.3.0 @@ -936,13 +940,30 @@ namespace eosiosystem { * @param url - the url of the block producer, normally the url of the block producer presentation website, * @param location - is the country code as defined in the ISO 3166, https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes * - * @pre Producer is not already registered * @pre Producer to register is an account * @pre Authority of producer to register */ [[eosio::action]] void regproducer( const name& producer, const public_key& producer_key, const std::string& url, uint16_t location ); + /** + * Register producer action. + * + * @details Register producer action, indicates that a particular account wishes to become a producer, + * this action will create a `producer_config` and a `producer_info` object for `producer` scope + * in producers tables. + * + * @param producer - account registering to be a producer candidate, + * @param producer_authority - the weighted threshold multisig block signing authority of the block producer used to sign blocks, + * @param url - the url of the block producer, normally the url of the block producer presentation website, + * @param location - is the country code as defined in the ISO 3166, https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes + * + * @pre Producer to register is an account + * @pre Authority of producer to register + */ + [[eosio::action]] + void regproducer2( const name& producer, const eosio::block_signing_authority& producer_authority, const std::string& url, uint16_t location ); + /** * Unregister producer action. Deactivate the block producer with account name `producer`. * @@ -1132,6 +1153,7 @@ namespace eosiosystem { using sellram_action = eosio::action_wrapper<"sellram"_n, &system_contract::sellram>; using refund_action = eosio::action_wrapper<"refund"_n, &system_contract::refund>; using regproducer_action = eosio::action_wrapper<"regproducer"_n, &system_contract::regproducer>; + using regproducer2_action = eosio::action_wrapper<"regproducer2"_n, &system_contract::regproducer2>; using unregprod_action = eosio::action_wrapper<"unregprod"_n, &system_contract::unregprod>; using setram_action = eosio::action_wrapper<"setram"_n, &system_contract::setram>; using setramrate_action = eosio::action_wrapper<"setramrate"_n, &system_contract::setramrate>; @@ -1204,7 +1226,8 @@ namespace eosiosystem { const asset& stake_net_quantity, const asset& stake_cpu_quantity, bool transfer ); void update_voting_power( const name& voter, const asset& total_update ); - // defined in voting.hpp + // defined in voting.cpp + void register_producer( const name& producer, const eosio::block_signing_authority& producer_authority, const std::string& url, uint16_t location ); void update_elected_producers( const block_timestamp& timestamp ); void update_votes( const name& voter, const name& proxy, const std::vector& producers, bool voting ); void propagate_weight_change( const voter_info& voter ); diff --git a/contracts/eosio.system/include/eosio.system/native.hpp b/contracts/eosio.system/include/eosio.system/native.hpp index 40a428504..854a05444 100644 --- a/contracts/eosio.system/include/eosio.system/native.hpp +++ b/contracts/eosio.system/include/eosio.system/native.hpp @@ -9,24 +9,6 @@ #include #include -// This header is needed until `is_feature_activiated` and `preactivate_feature` are added to `eosio.cdt` -#include - -namespace eosio { - namespace internal_use_do_not_use { - extern "C" { - __attribute__((eosio_wasm_import)) - bool is_feature_activated( const ::capi_checksum256* feature_digest ); - - __attribute__((eosio_wasm_import)) - void preactivate_feature( const ::capi_checksum256* feature_digest ); - } - } - - bool is_feature_activated( const eosio::checksum256& feature_digest ); - void preactivate_feature( const eosio::checksum256& feature_digest ); -} - namespace eosiosystem { using eosio::checksum256; diff --git a/contracts/eosio.system/ricardian/eosio.system.clauses.md b/contracts/eosio.system/ricardian/eosio.system.clauses.md index 19be74f81..ef5bfc987 100644 --- a/contracts/eosio.system/ricardian/eosio.system.clauses.md +++ b/contracts/eosio.system/ricardian/eosio.system.clauses.md @@ -6,13 +6,13 @@ User agreement for the chain can go here. I, {{producer}}, hereby nominate myself for consideration as an elected block producer. -If {{producer}} is selected to produce blocks by the system contract, I will sign blocks with {{producer_key}} and I hereby attest that I will keep this key secret and secure. +If {{producer}} is selected to produce blocks by the system contract, I will sign blocks with my registered block signing keys and I hereby attest that I will keep these keys secret and secure. -If {{producer}} is unable to perform obligations under this contract I will resign my position by resubmitting this contract with the null producer key. +If {{producer}} is unable to perform obligations under this contract I will resign my position using the unregprod action. I acknowledge that a block is 'objectively valid' if it conforms to the deterministic blockchain rules in force at the time of its creation, and is 'objectively invalid' if it fails to conform to those rules. -{{producer}} hereby agrees to only use {{producer_key}} to sign messages under the following scenarios: +{{producer}} hereby agrees to only use my registered block signing keys to sign messages under the following scenarios: * proposing an objectively valid block at the time appointed by the block scheduling algorithm; * pre-confirming a block produced by another producer in the schedule when I find said block objectively valid; @@ -20,8 +20,8 @@ I acknowledge that a block is 'objectively valid' if it conforms to the determin I hereby accept liability for any and all provable damages that result from my: -* signing two different block proposals with the same timestamp with {{producer_key}}; -* signing two different block proposals with the same block number with {{producer_key}}; +* signing two different block proposals with the same timestamp; +* signing two different block proposals with the same block number; * signing any block proposal which builds off of an objectively invalid block; * signing a pre-confirmation for an objectively invalid block; * or, signing a confirmation for a block for which I do not possess pre-confirmation messages from more than two-thirds of the active block producers. diff --git a/contracts/eosio.system/ricardian/eosio.system.contracts.md.in b/contracts/eosio.system/ricardian/eosio.system.contracts.md.in index dc938ec0f..9ab33cd88 100644 --- a/contracts/eosio.system/ricardian/eosio.system.contracts.md.in +++ b/contracts/eosio.system/ricardian/eosio.system.contracts.md.in @@ -309,6 +309,30 @@ icon: @ICON_BASE_URL@/@VOTING_ICON_URI@ Register {{producer}} account as a block producer candidate. +URL: {{url}} +Location code: {{location}} +Block signing key: {{producer_key}} + +## Block Producer Agreement +{{$clauses.BlockProducerAgreement}} + +

regproducer2

+ +--- +spec_version: "0.2.0" +title: Register as a Block Producer Candidate +summary: 'Register {{nowrap producer}} account as a block producer candidate' +icon: @ICON_BASE_URL@/@VOTING_ICON_URI@ +--- + +Register {{producer}} account as a block producer candidate. + +URL: {{url}} +Location code: {{location}} +Block signing authority: +{{to_json producer_authority}} + +## Block Producer Agreement {{$clauses.BlockProducerAgreement}}

regproxy

diff --git a/contracts/eosio.system/src/native.cpp b/contracts/eosio.system/src/native.cpp index a8f763040..df98daabf 100644 --- a/contracts/eosio.system/src/native.cpp +++ b/contracts/eosio.system/src/native.cpp @@ -2,22 +2,6 @@ #include -namespace eosio { - bool is_feature_activated( const eosio::checksum256& feature_digest ) { - auto feature_digest_data = feature_digest.extract_as_byte_array(); - return internal_use_do_not_use::is_feature_activated( - reinterpret_cast( feature_digest_data.data() ) - ); - } - - void preactivate_feature( const eosio::checksum256& feature_digest ) { - auto feature_digest_data = feature_digest.extract_as_byte_array(); - internal_use_do_not_use::preactivate_feature( - reinterpret_cast( feature_digest_data.data() ) - ); - } -} - namespace eosiosystem { void native::onerror( ignore, ignore> ) { diff --git a/contracts/eosio.system/src/voting.cpp b/contracts/eosio.system/src/voting.cpp index 5386fb502..a42239db5 100644 --- a/contracts/eosio.system/src/voting.cpp +++ b/contracts/eosio.system/src/voting.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -9,6 +10,9 @@ #include #include +#include +#include +#include #include #include @@ -20,20 +24,30 @@ namespace eosiosystem { using eosio::microseconds; using eosio::singleton; - void system_contract::regproducer( const name& producer, const eosio::public_key& producer_key, const std::string& url, uint16_t location ) { - check( url.size() < 512, "url too long" ); - check( producer_key != eosio::public_key(), "public key should not be the default value" ); - require_auth( producer ); + eosio::block_signing_authority convert_to_block_signing_authority( const eosio::public_key& producer_key ) { + return eosio::block_signing_authority_v0{ .threshold = 1, .keys = {{producer_key, 1}} }; + } + void system_contract::register_producer( const name& producer, const eosio::block_signing_authority& producer_authority, const std::string& url, uint16_t location ) { auto prod = _producers.find( producer.value ); const auto ct = current_time_point(); + eosio::public_key producer_key{}; + + std::visit( [&](auto&& auth ) { + if( auth.keys.size() == 1 ) { + // if the producer_authority consists of a single key, use that key in the legacy producer_key field + producer_key = auth.keys[0].key; + } + }, producer_authority ); + if ( prod != _producers.end() ) { _producers.modify( prod, producer, [&]( producer_info& info ){ - info.producer_key = producer_key; - info.is_active = true; - info.url = url; - info.location = location; + info.producer_key = producer_key; + info.is_active = true; + info.url = url; + info.location = location; + info.producer_authority.emplace( producer_authority ); if ( info.last_claim_time == time_point() ) info.last_claim_time = ct; }); @@ -49,13 +63,14 @@ namespace eosiosystem { } } else { _producers.emplace( producer, [&]( producer_info& info ){ - info.owner = producer; - info.total_votes = 0; - info.producer_key = producer_key; - info.is_active = true; - info.url = url; - info.location = location; - info.last_claim_time = ct; + info.owner = producer; + info.total_votes = 0; + info.producer_key = producer_key; + info.is_active = true; + info.url = url; + info.location = location; + info.last_claim_time = ct; + info.producer_authority.emplace( producer_authority ); }); _producers2.emplace( producer, [&]( producer_info2& info ){ info.owner = producer; @@ -65,6 +80,24 @@ namespace eosiosystem { } + void system_contract::regproducer( const name& producer, const eosio::public_key& producer_key, const std::string& url, uint16_t location ) { + require_auth( producer ); + check( url.size() < 512, "url too long" ); + + register_producer( producer, convert_to_block_signing_authority( producer_key ), url, location ); + } + + void system_contract::regproducer2( const name& producer, const eosio::block_signing_authority& producer_authority, const std::string& url, uint16_t location ) { + require_auth( producer ); + check( url.size() < 512, "url too long" ); + + std::visit( [&](auto&& auth ) { + check( auth.is_valid(), "invalid producer authority" ); + }, producer_authority ); + + register_producer( producer, producer_authority, url, location ); + } + void system_contract::unregprod( const name& producer ) { require_auth( producer ); @@ -79,25 +112,35 @@ namespace eosiosystem { auto idx = _producers.get_index<"prototalvote"_n>(); - std::vector< std::pair > top_producers; + using value_type = std::pair; + std::vector< value_type > top_producers; top_producers.reserve(21); - for ( auto it = idx.cbegin(); it != idx.cend() && top_producers.size() < 21 && 0 < it->total_votes && it->active(); ++it ) { - top_producers.emplace_back( std::pair({{it->owner, it->producer_key}, it->location}) ); + for( auto it = idx.cbegin(); it != idx.cend() && top_producers.size() < 21 && 0 < it->total_votes && it->active(); ++it ) { + top_producers.emplace_back( + eosio::producer_authority{ + .producer_name = it->owner, + .authority = it->producer_authority.has_value() ? *it->producer_authority + : convert_to_block_signing_authority( it->producer_key ) + }, + it->location + ); } - if ( top_producers.size() == 0 || top_producers.size() < _gstate.last_producer_schedule_size ) { + if( top_producers.size() == 0 || top_producers.size() < _gstate.last_producer_schedule_size ) { return; } - /// sort by producer name - std::sort( top_producers.begin(), top_producers.end() ); + std::sort( top_producers.begin(), top_producers.end(), []( const value_type& lhs, const value_type& rhs ) { + return lhs.first.producer_name < rhs.first.producer_name; // sort by producer name + // return lhs.second < rhs.second; // sort by location + } ); - std::vector producers; + std::vector producers; producers.reserve(top_producers.size()); - for( const auto& item : top_producers ) - producers.push_back(item.first); + for( auto& item : top_producers ) + producers.push_back( std::move(item.first) ); if( set_proposed_producers( producers ) >= 0 ) { _gstate.last_producer_schedule_size = static_cast( top_producers.size() ); diff --git a/pipeline.jsonc b/pipeline.jsonc index ddf8f23b6..b9d36799a 100644 --- a/pipeline.jsonc +++ b/pipeline.jsonc @@ -4,8 +4,8 @@ "pipeline-branch": "master", "dependencies": // dependencies to pull for a build of contracts, by branch, tag, or commit hash { - "eosio": "release/1.8.x", - "eosio.cdt": "release/1.6.x" + "eosio": "release/2.0.x", + "eosio.cdt": "release/1.7.x" } } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a14236482..2048afffb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required( VERSION 3.5 ) -set(EOSIO_VERSION_MIN "1.8") -set(EOSIO_VERSION_SOFT_MAX "1.8") +set(EOSIO_VERSION_MIN "2.0") +set(EOSIO_VERSION_SOFT_MAX "2.0") #set(EOSIO_VERSION_HARD_MAX "") find_package(eosio) diff --git a/tests/eosio.msig_tests.cpp b/tests/eosio.msig_tests.cpp index e28e229c0..cbc614b9f 100644 --- a/tests/eosio.msig_tests.cpp +++ b/tests/eosio.msig_tests.cpp @@ -181,7 +181,7 @@ transaction eosio_msig_tester::reqauth( account_name from, const vector{ { N(alice), config::active_name }, { N(bob), config::active_name } }, abi_serializer_max_time ); + auto trx = reqauth( N(alice), vector{ { N(alice), config::active_name }, { N(bob), config::active_name } }, abi_serializer_max_time ); push_action( N(alice), N(propose), mvo() ("proposer", "alice") ("proposal_name", "first") @@ -313,7 +313,7 @@ BOOST_FIXTURE_TEST_CASE( propose_approve_by_two, eosio_msig_tester ) try { BOOST_FIXTURE_TEST_CASE( propose_with_wrong_requested_auth, eosio_msig_tester ) try { - auto trx = reqauth("alice", vector{ { N(alice), config::active_name }, { N(bob), config::active_name } }, abi_serializer_max_time ); + auto trx = reqauth( N(alice), vector{ { N(alice), config::active_name }, { N(bob), config::active_name } }, abi_serializer_max_time ); //try with not enough requested auth BOOST_REQUIRE_EXCEPTION( push_action( N(alice), N(propose), mvo() ("proposer", "alice") @@ -406,10 +406,17 @@ BOOST_FIXTURE_TEST_CASE( update_system_contract_all_approve, eosio_msig_tester ) // / | \ <--- implicitly updated in onblock action // alice active bob active carol active - set_authority(N(eosio), "active", authority(1, - vector{{get_private_key("eosio", "active").get_public_key(), 1}}, - vector{{{N(eosio.prods), config::active_name}, 1}}), "owner", - { { N(eosio), "active" } }, { get_private_key( N(eosio), "active" ) }); + set_authority( + config::system_account_name, + config::active_name, + authority( 1, + vector{{get_private_key(config::system_account_name, "active").get_public_key(), 1}}, + vector{{{N(eosio.prods), config::active_name}, 1}} + ), + config::owner_name, + {{config::system_account_name, config::active_name}}, + {get_private_key(config::system_account_name, "active")} + ); set_producers( {N(alice),N(bob),N(carol)} ); produce_blocks(50); @@ -421,7 +428,7 @@ BOOST_FIXTURE_TEST_CASE( update_system_contract_all_approve, eosio_msig_tester ) create_currency( N(eosio.token), config::system_account_name, core_sym::from_string("10000000000.0000") ); issue(config::system_account_name, core_sym::from_string("1000000000.0000")); BOOST_REQUIRE_EQUAL( core_sym::from_string("1000000000.0000"), - get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") + get_balance("eosio.ram") ); + get_balance(config::system_account_name) + get_balance(N(eosio.ramfee)) + get_balance(N(eosio.stake)) + get_balance(N(eosio.ram)) ); set_code( config::system_account_name, contracts::system_wasm() ); set_abi( config::system_account_name, contracts::system_abi().data() ); @@ -436,7 +443,7 @@ BOOST_FIXTURE_TEST_CASE( update_system_contract_all_approve, eosio_msig_tester ) create_account_with_resources( N(carol1111111), N(eosio), core_sym::from_string("1.0000"), false ); BOOST_REQUIRE_EQUAL( core_sym::from_string("1000000000.0000"), - get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") + get_balance("eosio.ram") ); + get_balance(config::system_account_name) + get_balance(N(eosio.ramfee)) + get_balance(N(eosio.stake)) + get_balance(N(eosio.ram)) ); vector perm = { { N(alice), config::active_name }, { N(bob), config::active_name }, {N(carol), config::active_name} }; @@ -524,10 +531,17 @@ BOOST_FIXTURE_TEST_CASE( update_system_contract_all_approve, eosio_msig_tester ) BOOST_FIXTURE_TEST_CASE( update_system_contract_major_approve, eosio_msig_tester ) try { // set up the link between (eosio active) and (eosio.prods active) - set_authority(N(eosio), "active", authority(1, - vector{{get_private_key("eosio", "active").get_public_key(), 1}}, - vector{{{N(eosio.prods), config::active_name}, 1}}), "owner", - { { N(eosio), "active" } }, { get_private_key( N(eosio), "active" ) }); + set_authority( + config::system_account_name, + config::active_name, + authority( 1, + vector{{get_private_key(config::system_account_name, "active").get_public_key(), 1}}, + vector{{{N(eosio.prods), config::active_name}, 1}} + ), + config::owner_name, + {{config::system_account_name, config::active_name}}, + {get_private_key(config::system_account_name, "active")} + ); create_accounts( { N(apple) } ); set_producers( {N(alice),N(bob),N(carol), N(apple)} ); @@ -539,7 +553,7 @@ BOOST_FIXTURE_TEST_CASE( update_system_contract_major_approve, eosio_msig_tester create_currency( N(eosio.token), config::system_account_name, core_sym::from_string("10000000000.0000") ); issue(config::system_account_name, core_sym::from_string("1000000000.0000")); - BOOST_REQUIRE_EQUAL( core_sym::from_string("1000000000.0000"), get_balance( "eosio" ) ); + BOOST_REQUIRE_EQUAL( core_sym::from_string("1000000000.0000"), get_balance( config::system_account_name ) ); set_code( config::system_account_name, contracts::system_wasm() ); set_abi( config::system_account_name, contracts::system_abi().data() ); @@ -555,7 +569,7 @@ BOOST_FIXTURE_TEST_CASE( update_system_contract_major_approve, eosio_msig_tester create_account_with_resources( N(carol1111111), N(eosio), core_sym::from_string("1.0000"), false ); BOOST_REQUIRE_EQUAL( core_sym::from_string("1000000000.0000"), - get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") + get_balance("eosio.ram") ); + get_balance(config::system_account_name) + get_balance(N(eosio.ramfee)) + get_balance(N(eosio.stake)) + get_balance(N(eosio.ram)) ); vector perm = { { N(alice), config::active_name }, { N(bob), config::active_name }, {N(carol), config::active_name}, {N(apple), config::active_name}}; @@ -653,7 +667,7 @@ BOOST_FIXTURE_TEST_CASE( update_system_contract_major_approve, eosio_msig_tester } FC_LOG_AND_RETHROW() BOOST_FIXTURE_TEST_CASE( propose_approve_invalidate, eosio_msig_tester ) try { - auto trx = reqauth("alice", {permission_level{N(alice), config::active_name}}, abi_serializer_max_time ); + auto trx = reqauth( N(alice), {permission_level{N(alice), config::active_name}}, abi_serializer_max_time ); push_action( N(alice), N(propose), mvo() ("proposer", "alice") @@ -696,7 +710,7 @@ BOOST_FIXTURE_TEST_CASE( propose_approve_invalidate, eosio_msig_tester ) try { } FC_LOG_AND_RETHROW() BOOST_FIXTURE_TEST_CASE( propose_invalidate_approve, eosio_msig_tester ) try { - auto trx = reqauth("alice", {permission_level{N(alice), config::active_name}}, abi_serializer_max_time ); + auto trx = reqauth( N(alice), {permission_level{N(alice), config::active_name}}, abi_serializer_max_time ); push_action( N(alice), N(propose), mvo() ("proposer", "alice") @@ -752,7 +766,7 @@ BOOST_FIXTURE_TEST_CASE( approve_execute_old, eosio_msig_tester ) try { produce_blocks(); //propose with old version of eosio.msig - auto trx = reqauth("alice", {permission_level{N(alice), config::active_name}}, abi_serializer_max_time ); + auto trx = reqauth( N(alice), {permission_level{N(alice), config::active_name}}, abi_serializer_max_time ); push_action( N(alice), N(propose), mvo() ("proposer", "alice") ("proposal_name", "first") @@ -797,7 +811,7 @@ BOOST_FIXTURE_TEST_CASE( approve_unapprove_old, eosio_msig_tester ) try { produce_blocks(); //propose with old version of eosio.msig - auto trx = reqauth("alice", {permission_level{N(alice), config::active_name}}, abi_serializer_max_time ); + auto trx = reqauth( N(alice), {permission_level{N(alice), config::active_name}}, abi_serializer_max_time ); push_action( N(alice), N(propose), mvo() ("proposer", "alice") ("proposal_name", "first") @@ -839,7 +853,7 @@ BOOST_FIXTURE_TEST_CASE( approve_by_two_old, eosio_msig_tester ) try { set_abi( N(eosio.msig), contracts::util::msig_abi_old().data() ); produce_blocks(); - auto trx = reqauth("alice", vector{ { N(alice), config::active_name }, { N(bob), config::active_name } }, abi_serializer_max_time ); + auto trx = reqauth( N(alice), vector{ { N(alice), config::active_name }, { N(bob), config::active_name } }, abi_serializer_max_time ); push_action( N(alice), N(propose), mvo() ("proposer", "alice") ("proposal_name", "first") @@ -895,7 +909,7 @@ BOOST_FIXTURE_TEST_CASE( approve_by_two_old, eosio_msig_tester ) try { } FC_LOG_AND_RETHROW() BOOST_FIXTURE_TEST_CASE( approve_with_hash, eosio_msig_tester ) try { - auto trx = reqauth("alice", {permission_level{N(alice), config::active_name}}, abi_serializer_max_time ); + auto trx = reqauth( N(alice), {permission_level{N(alice), config::active_name}}, abi_serializer_max_time ); auto trx_hash = fc::sha256::hash( trx ); auto not_trx_hash = fc::sha256::hash( trx_hash ); @@ -944,7 +958,7 @@ BOOST_FIXTURE_TEST_CASE( approve_with_hash, eosio_msig_tester ) try { } FC_LOG_AND_RETHROW() BOOST_FIXTURE_TEST_CASE( switch_proposal_and_fail_approve_with_hash, eosio_msig_tester ) try { - auto trx1 = reqauth("alice", {permission_level{N(alice), config::active_name}}, abi_serializer_max_time ); + auto trx1 = reqauth( N(alice), {permission_level{N(alice), config::active_name}}, abi_serializer_max_time ); auto trx1_hash = fc::sha256::hash( trx1 ); push_action( N(alice), N(propose), mvo() @@ -954,7 +968,7 @@ BOOST_FIXTURE_TEST_CASE( switch_proposal_and_fail_approve_with_hash, eosio_msig_ ("requested", vector{{ N(alice), config::active_name }}) ); - auto trx2 = reqauth("alice", + auto trx2 = reqauth( N(alice), { permission_level{N(alice), config::active_name}, permission_level{N(alice), config::owner_name} }, abi_serializer_max_time ); diff --git a/tests/eosio.system_tester.hpp b/tests/eosio.system_tester.hpp index 809361e8e..baf82bfda 100644 --- a/tests/eosio.system_tester.hpp +++ b/tests/eosio.system_tester.hpp @@ -23,9 +23,9 @@ using mvo = fc::mutable_variant_object; #endif #endif - namespace eosio_system { + class eosio_system_tester : public TESTER { public: @@ -249,13 +249,23 @@ class eosio_system_tester : public TESTER { action_result buyram( const account_name& payer, account_name receiver, const asset& eosin ) { return push_action( payer, N(buyram), mvo()( "payer",payer)("receiver",receiver)("quant",eosin) ); } + action_result buyram( std::string_view payer, std::string_view receiver, const asset& eosin ) { + return buyram( account_name(payer), account_name(receiver), eosin ); + } + action_result buyrambytes( const account_name& payer, account_name receiver, uint32_t numbytes ) { return push_action( payer, N(buyrambytes), mvo()( "payer",payer)("receiver",receiver)("bytes",numbytes) ); } + action_result buyrambytes( std::string_view payer, std::string_view receiver, uint32_t numbytes ) { + return buyrambytes( account_name(payer), account_name(receiver), numbytes ); + } action_result sellram( const account_name& account, uint64_t numbytes ) { return push_action( account, N(sellram), mvo()( "account", account)("bytes",numbytes) ); } + action_result sellram( std::string_view account, uint64_t numbytes ) { + return sellram( account_name(account), numbytes ); + } action_result push_action( const account_name& signer, const action_name &name, const variant_object &data, bool auth = true ) { string action_type_name = abi_ser.get_action_type(name); @@ -265,7 +275,7 @@ class eosio_system_tester : public TESTER { act.name = name; act.data = abi_ser.variant_to_binary( action_type_name, data, abi_serializer_max_time ); - return base_tester::push_action( std::move(act), auth ? uint64_t(signer) : signer == N(bob111111111) ? N(alice1111111) : N(bob111111111) ); + return base_tester::push_action( std::move(act), (auth ? signer : signer == N(bob111111111) ? N(alice1111111) : N(bob111111111)).to_uint64_t() ); } action_result stake( const account_name& from, const account_name& to, const asset& net, const asset& cpu ) { @@ -277,10 +287,16 @@ class eosio_system_tester : public TESTER { ("transfer", 0 ) ); } + action_result stake( std::string_view from, std::string_view to, const asset& net, const asset& cpu ) { + return stake( account_name(from), account_name(to), net, cpu ); + } action_result stake( const account_name& acnt, const asset& net, const asset& cpu ) { return stake( acnt, acnt, net, cpu ); } + action_result stake( std::string_view acnt, const asset& net, const asset& cpu ) { + return stake( account_name(acnt), net, cpu ); + } action_result stake_with_transfer( const account_name& from, const account_name& to, const asset& net, const asset& cpu ) { return push_action( name(from), N(delegatebw), mvo() @@ -291,10 +307,16 @@ class eosio_system_tester : public TESTER { ("transfer", true ) ); } + action_result stake_with_transfer( std::string_view from, std::string_view to, const asset& net, const asset& cpu ) { + return stake_with_transfer( account_name(from), account_name(to), net, cpu ); + } action_result stake_with_transfer( const account_name& acnt, const asset& net, const asset& cpu ) { return stake_with_transfer( acnt, acnt, net, cpu ); } + action_result stake_with_transfer( std::string_view acnt, const asset& net, const asset& cpu ) { + return stake_with_transfer( account_name(acnt), net, cpu ); + } action_result unstake( const account_name& from, const account_name& to, const asset& net, const asset& cpu ) { return push_action( name(from), N(undelegatebw), mvo() @@ -304,10 +326,16 @@ class eosio_system_tester : public TESTER { ("unstake_cpu_quantity", cpu) ); } + action_result unstake( std::string_view from, std::string_view to, const asset& net, const asset& cpu ) { + return unstake( account_name(from), account_name(to), net, cpu ); + } action_result unstake( const account_name& acnt, const asset& net, const asset& cpu ) { return unstake( acnt, acnt, net, cpu ); } + action_result unstake( std::string_view acnt, const asset& net, const asset& cpu ) { + return unstake( account_name(acnt), net, cpu ); + } int64_t bancor_convert( int64_t S, int64_t R, int64_t T ) { return double(R) * T / ( double(S) + T ); }; @@ -565,7 +593,7 @@ class eosio_system_tester : public TESTER { fc::variant get_loan_info( const uint64_t& loan_num, bool cpu ) const { name table_name = cpu ? N(cpuloan) : N(netloan); - vector data = get_row_by_account( config::system_account_name, config::system_account_name, table_name, loan_num ); + vector data = get_row_by_account( config::system_account_name, config::system_account_name, table_name, account_name(loan_num) ); return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "rex_loan", data, abi_serializer_max_time ); } @@ -711,6 +739,9 @@ class eosio_system_tester : public TESTER { ("bid", bid) ); } + action_result bidname( std::string_view bidder, std::string_view newname, const asset& bid ) { + return bidname( account_name(bidder), account_name(newname), bid ); + } static fc::variant_object producer_parameters_example( int n ) { return mutable_variant_object() @@ -752,35 +783,54 @@ class eosio_system_tester : public TESTER { ("proxy", proxy) ("producers", producers)); } + action_result vote( const account_name& voter, const std::vector& producers, std::string_view proxy ) { + return vote( voter, producers, account_name(proxy) ); + } uint32_t last_block_time() const { return time_point_sec( control->head_block_time() ).sec_since_epoch(); } asset get_balance( const account_name& act, symbol balance_symbol = symbol{CORE_SYM} ) { - vector data = get_row_by_account( N(eosio.token), act, N(accounts), balance_symbol.to_symbol_code().value ); + vector data = get_row_by_account( N(eosio.token), act, N(accounts), account_name(balance_symbol.to_symbol_code().value) ); return data.empty() ? asset(0, balance_symbol) : token_abi_ser.binary_to_variant("account", data, abi_serializer_max_time)["balance"].as(); } + asset get_balance( std::string_view act, symbol balance_symbol = symbol{CORE_SYM} ) { + return get_balance( account_name(act), balance_symbol ); + } + fc::variant get_total_stake( const account_name& act ) { vector data = get_row_by_account( config::system_account_name, act, N(userres), act ); return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "user_resources", data, abi_serializer_max_time ); } + fc::variant get_total_stake( std::string_view act ) { + return get_total_stake( account_name(act) ); + } fc::variant get_voter_info( const account_name& act ) { vector data = get_row_by_account( config::system_account_name, config::system_account_name, N(voters), act ); return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "voter_info", data, abi_serializer_max_time ); } + fc::variant get_voter_info( std::string_view act ) { + return get_voter_info( account_name(act) ); + } fc::variant get_producer_info( const account_name& act ) { vector data = get_row_by_account( config::system_account_name, config::system_account_name, N(producers), act ); return abi_ser.binary_to_variant( "producer_info", data, abi_serializer_max_time ); } + fc::variant get_producer_info( std::string_view act ) { + return get_producer_info( account_name(act) ); + } fc::variant get_producer_info2( const account_name& act ) { vector data = get_row_by_account( config::system_account_name, config::system_account_name, N(producers2), act ); return abi_ser.binary_to_variant( "producer_info2", data, abi_serializer_max_time ); } + fc::variant get_producer_info2( std::string_view act ) { + return get_producer_info2( account_name(act) ); + } void create_currency( name contract, name manager, asset maxsupply ) { auto act = mutable_variant_object() @@ -807,6 +857,18 @@ class eosio_system_tester : public TESTER { ); } + void transfer( const name& from, std::string_view to, const asset& amount, const name& manager = config::system_account_name ) { + transfer( from, name(to), amount, manager ); + } + + void transfer( std::string_view from, std::string_view to, const asset& amount, std::string_view manager ) { + transfer( name(from), name(to), amount, name(manager) ); + } + + void transfer( std::string_view from, std::string_view to, const asset& amount ) { + transfer( name(from), name(to), amount ); + } + void issue_and_transfer( const name& to, const asset& amount, const name& manager = config::system_account_name ) { signed_transaction trx; trx.actions.emplace_back( get_action( N(eosio.token), N(issue), @@ -833,6 +895,18 @@ class eosio_system_tester : public TESTER { push_transaction( trx ); } + void issue_and_transfer( std::string_view to, const asset& amount, std::string_view manager ) { + issue_and_transfer( name(to), amount, name(manager) ); + } + + void issue_and_transfer( std::string_view to, const asset& amount, const name& manager ) { + issue_and_transfer( name(to), amount, manager); + } + + void issue_and_transfer( std::string_view to, const asset& amount ) { + issue_and_transfer( name(to), amount ); + } + double stake2votes( asset stake ) { auto now = control->pending_block_time().time_since_epoch().count() / 1000000; return stake.get_amount() * pow(2, int64_t((now - (config::block_timestamp_epoch / 1000)) / (86400 * 7))/ double(52) ); // 52 week periods (i.e. ~years) @@ -845,7 +919,7 @@ class eosio_system_tester : public TESTER { fc::variant get_stats( const string& symbolname ) { auto symb = eosio::chain::symbol::from_string(symbolname); auto symbol_code = symb.to_symbol_code().value; - vector data = get_row_by_account( N(eosio.token), symbol_code, N(stat), symbol_code ); + vector data = get_row_by_account( N(eosio.token), name(symbol_code), N(stat), account_name(symbol_code) ); return data.empty() ? fc::variant() : token_abi_ser.binary_to_variant( "currency_stats", data, abi_serializer_max_time ); } @@ -882,7 +956,7 @@ class eosio_system_tester : public TESTER { abi_serializer msig_abi_ser; { create_account_with_resources( N(eosio.msig), config::system_account_name ); - BOOST_REQUIRE_EQUAL( success(), buyram( "eosio", "eosio.msig", core_sym::from_string("5000.0000") ) ); + BOOST_REQUIRE_EQUAL( success(), buyram( N(eosio), N(eosio.msig), core_sym::from_string("5000.0000") ) ); produce_block(); auto trace = base_tester::push_action(config::system_account_name, N(setpriv), @@ -905,8 +979,8 @@ class eosio_system_tester : public TESTER { vector active_and_vote_producers() { //stake more than 15% of total EOS supply to activate chain - transfer( "eosio", "alice1111111", core_sym::from_string("650000000.0000"), "eosio" ); - BOOST_REQUIRE_EQUAL( success(), stake( "alice1111111", "alice1111111", core_sym::from_string("300000000.0000"), core_sym::from_string("300000000.0000") ) ); + transfer( N(eosio), N(alice1111111), core_sym::from_string("650000000.0000"), config::system_account_name ); + BOOST_REQUIRE_EQUAL( success(), stake( N(alice1111111), N(alice1111111), core_sym::from_string("300000000.0000"), core_sym::from_string("300000000.0000") ) ); // create accounts {defproducera, defproducerb, ..., defproducerz} and register as producers std::vector producer_names; @@ -938,9 +1012,9 @@ class eosio_system_tester : public TESTER { //vote for producers { - transfer( config::system_account_name, "alice1111111", core_sym::from_string("100000000.0000"), config::system_account_name ); - BOOST_REQUIRE_EQUAL(success(), stake( "alice1111111", core_sym::from_string("30000000.0000"), core_sym::from_string("30000000.0000") ) ); - BOOST_REQUIRE_EQUAL(success(), buyram( "alice1111111", "alice1111111", core_sym::from_string("30000000.0000") ) ); + transfer( config::system_account_name, N(alice1111111), core_sym::from_string("100000000.0000"), config::system_account_name ); + BOOST_REQUIRE_EQUAL(success(), stake( N(alice1111111), core_sym::from_string("30000000.0000"), core_sym::from_string("30000000.0000") ) ); + BOOST_REQUIRE_EQUAL(success(), buyram( N(alice1111111), N(alice1111111), core_sym::from_string("30000000.0000") ) ); BOOST_REQUIRE_EQUAL(success(), push_action(N(alice1111111), N(voteproducer), mvo() ("voter", "alice1111111") ("proxy", name(0).to_string()) @@ -1023,14 +1097,23 @@ inline fc::mutable_variant_object voter( account_name acct ) { ("is_proxy", 0) ; } +inline fc::mutable_variant_object voter( std::string_view acct ) { + return voter( account_name(acct) ); +} inline fc::mutable_variant_object voter( account_name acct, const asset& vote_stake ) { return voter( acct )( "staked", vote_stake.get_amount() ); } +inline fc::mutable_variant_object voter( std::string_view acct, const asset& vote_stake ) { + return voter( account_name(acct), vote_stake ); +} inline fc::mutable_variant_object voter( account_name acct, int64_t vote_stake ) { return voter( acct )( "staked", vote_stake ); } +inline fc::mutable_variant_object voter( std::string_view acct, int64_t vote_stake ) { + return voter( account_name(acct), vote_stake ); +} inline fc::mutable_variant_object proxy( account_name acct ) { return voter( acct )( "is_proxy", 1 ); diff --git a/tests/eosio.system_tests.cpp b/tests/eosio.system_tests.cpp index 7021e927b..c2eab2ccc 100644 --- a/tests/eosio.system_tests.cpp +++ b/tests/eosio.system_tests.cpp @@ -127,17 +127,17 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try { BOOST_REQUIRE_EQUAL( success(), sellram( "alice1111111", bought_bytes ) ); BOOST_REQUIRE_EQUAL( false, get_row_by_account( config::system_account_name, config::system_account_name, - N(rammarket), symbol{SY(4,RAMCORE)}.value() ).empty() ); + N(rammarket), account_name(symbol{SY(4,RAMCORE)}.value()) ).empty() ); auto get_ram_market = [this]() -> fc::variant { vector data = get_row_by_account( config::system_account_name, config::system_account_name, - N(rammarket), symbol{SY(4,RAMCORE)}.value() ); + N(rammarket), account_name(symbol{SY(4,RAMCORE)}.value()) ); BOOST_REQUIRE( !data.empty() ); return abi_ser.binary_to_variant("exchange_state", data, abi_serializer_max_time); }; { - transfer( config::system_account_name, "alice1111111", core_sym::from_string("10000000.0000"), config::system_account_name ); + transfer( config::system_account_name, N(alice1111111), core_sym::from_string("10000000.0000"), config::system_account_name ); uint64_t bytes0 = get_total_stake( "alice1111111" )["ram_bytes"].as_uint64(); auto market = get_ram_market(); @@ -158,7 +158,7 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try { } { - transfer( config::system_account_name, "bob111111111", core_sym::from_string("100000.0000"), config::system_account_name ); + transfer( config::system_account_name, N(bob111111111), core_sym::from_string("100000.0000"), config::system_account_name ); BOOST_REQUIRE_EQUAL( wasm_assert_msg("must reserve a positive amount"), buyrambytes( "bob111111111", "bob111111111", 1 ) ); @@ -247,7 +247,7 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake_with_transfer, eosio_system_tester ) try //eosio stakes for alice with transfer flag transfer( "eosio", "bob111111111", core_sym::from_string("1000.0000"), "eosio" ); - BOOST_REQUIRE_EQUAL( success(), stake_with_transfer( "bob111111111", "alice1111111", core_sym::from_string("200.0000"), core_sym::from_string("100.0000") ) ); + BOOST_REQUIRE_EQUAL( success(), stake_with_transfer( N(bob111111111), N(alice1111111), core_sym::from_string("200.0000"), core_sym::from_string("100.0000") ) ); //check that alice has both bandwidth and voting power auto total = get_total_stake("alice1111111"); @@ -288,7 +288,7 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake_with_transfer, eosio_system_tester ) try REQUIRE_MATCHING_OBJECT( voter( "alice1111111", core_sym::from_string("0.0000")), get_voter_info( "alice1111111" ) ); // Now alice stakes to bob with transfer flag - BOOST_REQUIRE_EQUAL( success(), stake_with_transfer( "alice1111111", "bob111111111", core_sym::from_string("100.0000"), core_sym::from_string("100.0000") ) ); + BOOST_REQUIRE_EQUAL( success(), stake_with_transfer( N(alice1111111), N(bob111111111), core_sym::from_string("100.0000"), core_sym::from_string("100.0000") ) ); } FC_LOG_AND_RETHROW() @@ -299,7 +299,7 @@ BOOST_FIXTURE_TEST_CASE( stake_to_self_with_transfer, eosio_system_tester ) try transfer( "eosio", "alice1111111", core_sym::from_string("1000.0000"), "eosio" ); BOOST_REQUIRE_EQUAL( wasm_assert_msg("cannot use transfer flag if delegating to self"), - stake_with_transfer( "alice1111111", "alice1111111", core_sym::from_string("200.0000"), core_sym::from_string("100.0000") ) + stake_with_transfer( N(alice1111111), N(alice1111111), core_sym::from_string("200.0000"), core_sym::from_string("100.0000") ) ); } FC_LOG_AND_RETHROW() @@ -311,7 +311,7 @@ BOOST_FIXTURE_TEST_CASE( stake_while_pending_refund, eosio_system_tester ) try { //eosio stakes for alice with transfer flag transfer( "eosio", "bob111111111", core_sym::from_string("1000.0000"), "eosio" ); - BOOST_REQUIRE_EQUAL( success(), stake_with_transfer( "bob111111111", "alice1111111", core_sym::from_string("200.0000"), core_sym::from_string("100.0000") ) ); + BOOST_REQUIRE_EQUAL( success(), stake_with_transfer( N(bob111111111), N(alice1111111), core_sym::from_string("200.0000"), core_sym::from_string("100.0000") ) ); //check that alice has both bandwidth and voting power auto total = get_total_stake("alice1111111"); @@ -352,7 +352,7 @@ BOOST_FIXTURE_TEST_CASE( stake_while_pending_refund, eosio_system_tester ) try { REQUIRE_MATCHING_OBJECT( voter( "alice1111111", core_sym::from_string("0.0000")), get_voter_info( "alice1111111" ) ); // Now alice stakes to bob with transfer flag - BOOST_REQUIRE_EQUAL( success(), stake_with_transfer( "alice1111111", "bob111111111", core_sym::from_string("100.0000"), core_sym::from_string("100.0000") ) ); + BOOST_REQUIRE_EQUAL( success(), stake_with_transfer( N(alice1111111), N(bob111111111), core_sym::from_string("100.0000"), core_sym::from_string("100.0000") ) ); } FC_LOG_AND_RETHROW() @@ -635,7 +635,7 @@ BOOST_FIXTURE_TEST_CASE( stake_from_refund, eosio_system_tester ) try { BOOST_REQUIRE_EQUAL( core_sym::from_string("60.0000"), total["cpu_weight"].as()); REQUIRE_MATCHING_OBJECT( voter( "alice1111111", core_sym::from_string("250.0000") ), get_voter_info( "alice1111111" ) ); BOOST_REQUIRE_EQUAL( core_sym::from_string("600.0000"), get_balance( "alice1111111" ) ); - auto refund = get_refund_request( "alice1111111" ); + auto refund = get_refund_request( N(alice1111111) ); BOOST_REQUIRE_EQUAL( core_sym::from_string("100.0000"), refund["net_amount"].as() ); BOOST_REQUIRE_EQUAL( core_sym::from_string( "50.0000"), refund["cpu_amount"].as() ); //XXX auto request_time = refund["request_time"].as_int64(); @@ -647,7 +647,7 @@ BOOST_FIXTURE_TEST_CASE( stake_from_refund, eosio_system_tester ) try { BOOST_REQUIRE_EQUAL( core_sym::from_string("60.0000"), total["cpu_weight"].as()); REQUIRE_MATCHING_OBJECT( voter( "alice1111111", core_sym::from_string("350.0000") ), get_voter_info( "alice1111111" ) ); BOOST_REQUIRE_EQUAL( core_sym::from_string("500.0000"), get_balance( "alice1111111" ) ); - refund = get_refund_request( "alice1111111" ); + refund = get_refund_request( N(alice1111111) ); BOOST_REQUIRE_EQUAL( core_sym::from_string("100.0000"), refund["net_amount"].as() ); BOOST_REQUIRE_EQUAL( core_sym::from_string( "50.0000"), refund["cpu_amount"].as() ); @@ -656,7 +656,7 @@ BOOST_FIXTURE_TEST_CASE( stake_from_refund, eosio_system_tester ) try { total = get_total_stake( "alice1111111" ); BOOST_REQUIRE_EQUAL( core_sym::from_string("160.0000"), total["net_weight"].as()); BOOST_REQUIRE_EQUAL( core_sym::from_string("85.0000"), total["cpu_weight"].as()); - refund = get_refund_request( "alice1111111" ); + refund = get_refund_request( N(alice1111111) ); BOOST_REQUIRE_EQUAL( core_sym::from_string("50.0000"), refund["net_amount"].as() ); BOOST_REQUIRE_EQUAL( core_sym::from_string("25.0000"), refund["cpu_amount"].as() ); //request time should stay the same @@ -670,7 +670,7 @@ BOOST_FIXTURE_TEST_CASE( stake_from_refund, eosio_system_tester ) try { BOOST_REQUIRE_EQUAL( core_sym::from_string("210.0000"), total["net_weight"].as()); BOOST_REQUIRE_EQUAL( core_sym::from_string("110.0000"), total["cpu_weight"].as()); //pending refund should be removed - refund = get_refund_request( "alice1111111" ); + refund = get_refund_request( N(alice1111111) ); BOOST_TEST_REQUIRE( refund.is_null() ); //balance should stay the same BOOST_REQUIRE_EQUAL( core_sym::from_string("500.0000"), get_balance( "alice1111111" ) ); @@ -681,7 +681,7 @@ BOOST_FIXTURE_TEST_CASE( stake_from_refund, eosio_system_tester ) try { BOOST_REQUIRE_EQUAL( core_sym::from_string("10.0000"), total["net_weight"].as()); BOOST_REQUIRE_EQUAL( core_sym::from_string("10.0000"), total["cpu_weight"].as()); BOOST_REQUIRE_EQUAL( core_sym::from_string("500.0000"), get_balance( "alice1111111" ) ); - refund = get_refund_request( "alice1111111" ); + refund = get_refund_request( N(alice1111111) ); BOOST_REQUIRE_EQUAL( core_sym::from_string("200.0000"), refund["net_amount"].as() ); BOOST_REQUIRE_EQUAL( core_sym::from_string("100.0000"), refund["cpu_amount"].as() ); @@ -691,7 +691,7 @@ BOOST_FIXTURE_TEST_CASE( stake_from_refund, eosio_system_tester ) try { BOOST_REQUIRE_EQUAL( core_sym::from_string("310.0000"), total["net_weight"].as()); BOOST_REQUIRE_EQUAL( core_sym::from_string("210.0000"), total["cpu_weight"].as()); REQUIRE_MATCHING_OBJECT( voter( "alice1111111", core_sym::from_string("700.0000") ), get_voter_info( "alice1111111" ) ); - refund = get_refund_request( "alice1111111" ); + refund = get_refund_request( N(alice1111111) ); BOOST_TEST_REQUIRE( refund.is_null() ); //200 core tokens should be taken from alice's account BOOST_REQUIRE_EQUAL( core_sym::from_string("300.0000"), get_balance( "alice1111111" ) ); @@ -714,7 +714,7 @@ BOOST_FIXTURE_TEST_CASE( stake_to_another_user_not_from_refund, eosio_system_tes //unstake BOOST_REQUIRE_EQUAL( success(), unstake( "alice1111111", core_sym::from_string("200.0000"), core_sym::from_string("100.0000") ) ); - auto refund = get_refund_request( "alice1111111" ); + auto refund = get_refund_request( N(alice1111111) ); BOOST_REQUIRE_EQUAL( core_sym::from_string("200.0000"), refund["net_amount"].as() ); BOOST_REQUIRE_EQUAL( core_sym::from_string("100.0000"), refund["cpu_amount"].as() ); //auto orig_request_time = refund["request_time"].as_int64(); @@ -726,7 +726,7 @@ BOOST_FIXTURE_TEST_CASE( stake_to_another_user_not_from_refund, eosio_system_tes BOOST_REQUIRE_EQUAL( core_sym::from_string("110.0000"), total["cpu_weight"].as()); //stake should be taken from alices' balance, and refund request should stay the same BOOST_REQUIRE_EQUAL( core_sym::from_string("400.0000"), get_balance( "alice1111111" ) ); - refund = get_refund_request( "alice1111111" ); + refund = get_refund_request( N(alice1111111) ); BOOST_REQUIRE_EQUAL( core_sym::from_string("200.0000"), refund["net_amount"].as() ); BOOST_REQUIRE_EQUAL( core_sym::from_string("100.0000"), refund["cpu_amount"].as() ); //BOOST_REQUIRE_EQUAL( orig_request_time, refund["request_time"].as_int64() ); @@ -804,6 +804,101 @@ BOOST_FIXTURE_TEST_CASE( producer_register_unregister, eosio_system_tester ) try } FC_LOG_AND_RETHROW() +BOOST_FIXTURE_TEST_CASE( producer_wtmsig, eosio_system_tester ) try { + cross_15_percent_threshold(); + + BOOST_REQUIRE_EQUAL( control->active_producers().version, 0u ); + + issue_and_transfer( N(alice1111111), core_sym::from_string("200000000.0000"), config::system_account_name ); + block_signing_authority_v0 alice_signing_authority; + alice_signing_authority.threshold = 1; + alice_signing_authority.keys.push_back( {.key = get_public_key( N(alice1111111), "bs1"), .weight = 1} ); + alice_signing_authority.keys.push_back( {.key = get_public_key( N(alice1111111), "bs2"), .weight = 1} ); + producer_authority alice_producer_authority = {.producer_name = N(alice1111111), .authority = alice_signing_authority}; + BOOST_REQUIRE_EQUAL( success(), push_action( N(alice1111111), N(regproducer2), mvo() + ("producer", "alice1111111") + ("producer_authority", alice_producer_authority.get_abi_variant()["authority"]) + ("url", "http://block.one") + ("location", 0 ) + ) + ); + BOOST_REQUIRE_EQUAL( success(), stake( N(alice1111111), core_sym::from_string("100000000.0000"), core_sym::from_string("100000000.0000") ) ); + BOOST_REQUIRE_EQUAL( success(), vote( N(alice1111111), { N(alice1111111) } ) ); + + block_signing_private_keys.emplace(get_public_key(N(alice1111111), "bs1"), get_private_key(N(alice1111111), "bs1")); + + auto alice_prod_info = get_producer_info( N(alice1111111) ); + wdump((alice_prod_info)); + BOOST_REQUIRE_EQUAL( alice_prod_info["is_active"], true ); + + produce_block(); + produce_block( fc::minutes(2) ); + produce_blocks(2); + BOOST_REQUIRE_EQUAL( control->active_producers().version, 1u ); + produce_block(); + BOOST_REQUIRE_EQUAL( control->pending_block_producer(), N(alice1111111) ); + produce_block(); + + alice_signing_authority.threshold = 0; + alice_producer_authority.authority = alice_signing_authority; + + // Ensure an authority with a threshold of 0 is rejected. + BOOST_REQUIRE_EQUAL( error("assertion failure with message: invalid producer authority"), + push_action( N(alice1111111), N(regproducer2), mvo() + ("producer", "alice1111111") + ("producer_authority", alice_producer_authority.get_abi_variant()["authority"]) + ("url", "http://block.one") + ("location", 0 ) + ) + ); + + // Ensure an authority that is not satisfiable is rejected. + alice_signing_authority.threshold = 3; + alice_producer_authority.authority = alice_signing_authority; + BOOST_REQUIRE_EQUAL( error("assertion failure with message: invalid producer authority"), + push_action( N(alice1111111), N(regproducer2), mvo() + ("producer", "alice1111111") + ("producer_authority", alice_producer_authority.get_abi_variant()["authority"]) + ("url", "http://block.one") + ("location", 0 ) + ) + ); + + // Ensure an authority with duplicate keys is rejected. + alice_signing_authority.threshold = 1; + alice_signing_authority.keys[1] = alice_signing_authority.keys[0]; + alice_producer_authority.authority = alice_signing_authority; + BOOST_REQUIRE_EQUAL( error("assertion failure with message: invalid producer authority"), + push_action( N(alice1111111), N(regproducer2), mvo() + ("producer", "alice1111111") + ("producer_authority", alice_producer_authority.get_abi_variant()["authority"]) + ("url", "http://block.one") + ("location", 0 ) + ) + ); + + // However, an authority with an invalid key is okay. + alice_signing_authority.keys[1] = {}; + alice_producer_authority.authority = alice_signing_authority; + BOOST_REQUIRE_EQUAL( success(), + push_action( N(alice1111111), N(regproducer2), mvo() + ("producer", "alice1111111") + ("producer_authority", alice_producer_authority.get_abi_variant()["authority"]) + ("url", "http://block.one") + ("location", 0 ) + ) + ); + + produce_block(); + produce_block( fc::minutes(2) ); + produce_blocks(2); + BOOST_REQUIRE_EQUAL( control->active_producers().version, 2u ); + produce_block(); + BOOST_REQUIRE_EQUAL( control->pending_block_producer(), N(alice1111111) ); + produce_block(); + +} FC_LOG_AND_RETHROW() + BOOST_FIXTURE_TEST_CASE( vote_for_producer, eosio_system_tester, * boost::unit_test::tolerance(1e+5) ) try { cross_15_percent_threshold(); @@ -852,7 +947,7 @@ BOOST_FIXTURE_TEST_CASE( vote_for_producer, eosio_system_tester, * boost::unit_t //bob111111111 increases his stake BOOST_REQUIRE_EQUAL( success(), stake( "bob111111111", core_sym::from_string("33.0000"), core_sym::from_string("0.3333") ) ); //alice1111111 stake with transfer to bob111111111 - BOOST_REQUIRE_EQUAL( success(), stake_with_transfer( "alice1111111", "bob111111111", core_sym::from_string("22.0000"), core_sym::from_string("0.2222") ) ); + BOOST_REQUIRE_EQUAL( success(), stake_with_transfer( N(alice1111111), N(bob111111111), core_sym::from_string("22.0000"), core_sym::from_string("0.2222") ) ); //should increase alice1111111's total_votes prod = get_producer_info( "alice1111111" ); BOOST_TEST_REQUIRE( stake2votes(core_sym::from_string("88.8888")) == prod["total_votes"].as_double() ); @@ -1089,7 +1184,7 @@ BOOST_FIXTURE_TEST_CASE( proxy_register_unregister_keeps_stake, eosio_system_tes ("isproxy", true ) ) ); - REQUIRE_MATCHING_OBJECT( proxy( "alice1111111" ), get_voter_info( "alice1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(alice1111111) ), get_voter_info( "alice1111111" ) ); //unregister proxy BOOST_REQUIRE_EQUAL( success(), push_action(N(alice1111111), N(regproxy), mvo() @@ -1107,7 +1202,7 @@ BOOST_FIXTURE_TEST_CASE( proxy_register_unregister_keeps_stake, eosio_system_tes ("isproxy", true) ) ); - REQUIRE_MATCHING_OBJECT( proxy( "bob111111111" )( "staked", 3000003 ), get_voter_info( "bob111111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(bob111111111) )( "staked", 3000003 ), get_voter_info( "bob111111111" ) ); //unrgister and check that stake is still in place BOOST_REQUIRE_EQUAL( success(), push_action( N(bob111111111), N(regproxy), mvo() ("proxy", "bob111111111") @@ -1125,7 +1220,7 @@ BOOST_FIXTURE_TEST_CASE( proxy_register_unregister_keeps_stake, eosio_system_tes issue_and_transfer( "carol1111111", core_sym::from_string("1000.0000"), config::system_account_name ); BOOST_REQUIRE_EQUAL( success(), stake( "carol1111111", core_sym::from_string("246.0002"), core_sym::from_string("531.0001") ) ); //check that both proxy flag and stake a correct - REQUIRE_MATCHING_OBJECT( proxy( "carol1111111" )( "staked", 7770003 ), get_voter_info( "carol1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(carol1111111) )( "staked", 7770003 ), get_voter_info( "carol1111111" ) ); //unregister BOOST_REQUIRE_EQUAL( success(), push_action( N(carol1111111), N(regproxy), mvo() @@ -1147,25 +1242,25 @@ BOOST_FIXTURE_TEST_CASE( proxy_stake_unstake_keeps_proxy_flag, eosio_system_test ) ); issue_and_transfer( "alice1111111", core_sym::from_string("1000.0000"), config::system_account_name ); - REQUIRE_MATCHING_OBJECT( proxy( "alice1111111" ), get_voter_info( "alice1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(alice1111111) ), get_voter_info( "alice1111111" ) ); //stake BOOST_REQUIRE_EQUAL( success(), stake( "alice1111111", core_sym::from_string("100.0000"), core_sym::from_string("50.0000") ) ); //check that account is still a proxy - REQUIRE_MATCHING_OBJECT( proxy( "alice1111111" )( "staked", 1500000 ), get_voter_info( "alice1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(alice1111111) )( "staked", 1500000 ), get_voter_info( "alice1111111" ) ); //stake more BOOST_REQUIRE_EQUAL( success(), stake( "alice1111111", core_sym::from_string("30.0000"), core_sym::from_string("20.0000") ) ); //check that account is still a proxy - REQUIRE_MATCHING_OBJECT( proxy( "alice1111111" )("staked", 2000000 ), get_voter_info( "alice1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(alice1111111) )("staked", 2000000 ), get_voter_info( "alice1111111" ) ); //unstake more BOOST_REQUIRE_EQUAL( success(), unstake( "alice1111111", core_sym::from_string("65.0000"), core_sym::from_string("35.0000") ) ); - REQUIRE_MATCHING_OBJECT( proxy( "alice1111111" )("staked", 1000000 ), get_voter_info( "alice1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(alice1111111) )("staked", 1000000 ), get_voter_info( "alice1111111" ) ); //unstake the rest BOOST_REQUIRE_EQUAL( success(), unstake( "alice1111111", core_sym::from_string("65.0000"), core_sym::from_string("35.0000") ) ); - REQUIRE_MATCHING_OBJECT( proxy( "alice1111111" )( "staked", 0 ), get_voter_info( "alice1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(alice1111111) )( "staked", 0 ), get_voter_info( "alice1111111" ) ); } FC_LOG_AND_RETHROW() @@ -1174,9 +1269,9 @@ BOOST_FIXTURE_TEST_CASE( proxy_actions_affect_producers, eosio_system_tester, * cross_15_percent_threshold(); create_accounts_with_resources( { N(defproducer1), N(defproducer2), N(defproducer3) } ); - BOOST_REQUIRE_EQUAL( success(), regproducer( "defproducer1", 1) ); - BOOST_REQUIRE_EQUAL( success(), regproducer( "defproducer2", 2) ); - BOOST_REQUIRE_EQUAL( success(), regproducer( "defproducer3", 3) ); + BOOST_REQUIRE_EQUAL( success(), regproducer( N(defproducer1), 1) ); + BOOST_REQUIRE_EQUAL( success(), regproducer( N(defproducer2), 2) ); + BOOST_REQUIRE_EQUAL( success(), regproducer( N(defproducer3), 3) ); //register as a proxy BOOST_REQUIRE_EQUAL( success(), push_action( N(alice1111111), N(regproxy), mvo() @@ -1189,7 +1284,7 @@ BOOST_FIXTURE_TEST_CASE( proxy_actions_affect_producers, eosio_system_tester, * issue_and_transfer( "bob111111111", core_sym::from_string("1000.0000"), config::system_account_name ); BOOST_REQUIRE_EQUAL( success(), stake( "bob111111111", core_sym::from_string("100.0002"), core_sym::from_string("50.0001") ) ); BOOST_REQUIRE_EQUAL( success(), vote(N(bob111111111), vector(), N(alice1111111) ) ); - REQUIRE_MATCHING_OBJECT( proxy( "alice1111111" )( "proxied_vote_weight", stake2votes(core_sym::from_string("150.0003")) ), get_voter_info( "alice1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(alice1111111) )( "proxied_vote_weight", stake2votes(core_sym::from_string("150.0003")) ), get_voter_info( "alice1111111" ) ); //vote for producers BOOST_REQUIRE_EQUAL( success(), vote(N(alice1111111), { N(defproducer1), N(defproducer2) } ) ); @@ -1464,7 +1559,7 @@ BOOST_FIXTURE_TEST_CASE(change_inflation, eosio_system_tester) try { BOOST_REQUIRE_EQUAL(success(), vote( N(producvotera), { N(defproducera),N(defproducerb),N(defproducerc) })); auto run_for_1year = [this](int64_t annual_rate, int64_t inflation_pay_factor, int64_t votepay_factor) { - + double inflation = double(annual_rate)/double(10000); BOOST_REQUIRE_EQUAL(success(), setinflation( @@ -1486,7 +1581,7 @@ BOOST_FIXTURE_TEST_CASE(change_inflation, eosio_system_tester) try { } const asset final_supply = get_token_supply(); const int64_t final_savings = get_balance(N(eosio.saving)).get_amount(); - + double computed_new_tokens = double(final_supply.get_amount() - initial_supply.get_amount()); double theoretical_new_tokens = double(initial_supply.get_amount())*inflation; double diff_new_tokens = std::abs(theoretical_new_tokens-computed_new_tokens); @@ -1517,8 +1612,8 @@ BOOST_FIXTURE_TEST_CASE(change_inflation, eosio_system_tester) try { // 1% inflation for 1 year. 50% savings / 50% bp reward. 10000 / 50000 = 0.2 => 20% blockpay, 80% votepay run_for_1year(100, 20000, 50000); - // 3% inflation for 1 year. 66.6% savings / 33.33% bp reward. 10000/13333 = 0.75 => 75% blockpay, 25% votepay - run_for_1year(300, 30000, 13333); + // 3% inflation for 1 year. 66.6% savings / 33.33% bp reward. 10000/13333 = 0.75 => 75% blockpay, 25% votepay + run_for_1year(300, 30000, 13333); // 0% inflation for 1 year run_for_1year(0, 30000, 50000); @@ -1545,7 +1640,7 @@ BOOST_AUTO_TEST_CASE(extreme_inflation) try { t.produce_block(); asset current_supply; { - vector data = t.get_row_by_account( N(eosio.token), core_symbol.to_symbol_code().value, N(stat), core_symbol.to_symbol_code().value ); + vector data = t.get_row_by_account( N(eosio.token), name(core_symbol.to_symbol_code().value), N(stat), account_name(core_symbol.to_symbol_code().value) ); current_supply = t.token_abi_ser.binary_to_variant("currency_stats", data, eosio_system_tester::abi_serializer_max_time)["supply"].template as(); } t.issue( asset((1ll << 62) - 1, core_symbol) - current_supply ); @@ -2542,7 +2637,7 @@ BOOST_FIXTURE_TEST_CASE(producers_upgrade_system_contract, eosio_system_tester) act.name = name; act.data = msig_abi_ser.variant_to_binary( action_type_name, data, abi_serializer_max_time ); - return base_tester::push_action( std::move(act), auth ? uint64_t(signer) : signer == N(bob111111111) ? N(alice1111111) : N(bob111111111) ); + return base_tester::push_action( std::move(act), (auth ? signer : signer == N(bob111111111) ? N(alice1111111) : N(bob111111111)).to_uint64_t() ); }; // test begins vector prod_perms; @@ -2739,9 +2834,9 @@ BOOST_FIXTURE_TEST_CASE( voters_actions_affect_proxy_and_producers, eosio_system cross_15_percent_threshold(); create_accounts_with_resources( { N(donald111111), N(defproducer1), N(defproducer2), N(defproducer3) } ); - BOOST_REQUIRE_EQUAL( success(), regproducer( "defproducer1", 1) ); - BOOST_REQUIRE_EQUAL( success(), regproducer( "defproducer2", 2) ); - BOOST_REQUIRE_EQUAL( success(), regproducer( "defproducer3", 3) ); + BOOST_REQUIRE_EQUAL( success(), regproducer( N(defproducer1), 1) ); + BOOST_REQUIRE_EQUAL( success(), regproducer( N(defproducer2), 2) ); + BOOST_REQUIRE_EQUAL( success(), regproducer( N(defproducer3), 3) ); //alice1111111 becomes a producer BOOST_REQUIRE_EQUAL( success(), push_action( N(alice1111111), N(regproxy), mvo() @@ -2749,7 +2844,7 @@ BOOST_FIXTURE_TEST_CASE( voters_actions_affect_proxy_and_producers, eosio_system ("isproxy", true) ) ); - REQUIRE_MATCHING_OBJECT( proxy( "alice1111111" ), get_voter_info( "alice1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(alice1111111) ), get_voter_info( "alice1111111" ) ); //alice1111111 makes stake and votes issue_and_transfer( "alice1111111", core_sym::from_string("1000.0000"), config::system_account_name ); @@ -2764,7 +2859,7 @@ BOOST_FIXTURE_TEST_CASE( voters_actions_affect_proxy_and_producers, eosio_system ("isproxy", true) ) ); - REQUIRE_MATCHING_OBJECT( proxy( "donald111111" ), get_voter_info( "donald111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(donald111111) ), get_voter_info( "donald111111" ) ); //bob111111111 chooses alice1111111 as a proxy issue_and_transfer( "bob111111111", core_sym::from_string("1000.0000"), config::system_account_name ); @@ -2823,10 +2918,10 @@ BOOST_FIXTURE_TEST_CASE( vote_both_proxy_and_producers, eosio_system_tester ) tr ("isproxy", true) ) ); - REQUIRE_MATCHING_OBJECT( proxy( "alice1111111" ), get_voter_info( "alice1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(alice1111111) ), get_voter_info( "alice1111111" ) ); //carol1111111 becomes a producer - BOOST_REQUIRE_EQUAL( success(), regproducer( "carol1111111", 1) ); + BOOST_REQUIRE_EQUAL( success(), regproducer( N(carol1111111), 1) ); //bob111111111 chooses alice1111111 as a proxy @@ -2864,13 +2959,13 @@ BOOST_FIXTURE_TEST_CASE( double_register_unregister_proxy_keeps_votes, eosio_sys issue_and_transfer( "alice1111111", core_sym::from_string("1000.0000"), config::system_account_name ); BOOST_REQUIRE_EQUAL( success(), stake( "alice1111111", core_sym::from_string("5.0000"), core_sym::from_string("5.0000") ) ); edump((get_voter_info("alice1111111"))); - REQUIRE_MATCHING_OBJECT( proxy( "alice1111111" )( "staked", 100000 ), get_voter_info( "alice1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(alice1111111) )( "staked", 100000 ), get_voter_info( "alice1111111" ) ); //bob111111111 stakes and selects alice1111111 as a proxy issue_and_transfer( "bob111111111", core_sym::from_string("1000.0000"), config::system_account_name ); BOOST_REQUIRE_EQUAL( success(), stake( "bob111111111", core_sym::from_string("100.0002"), core_sym::from_string("50.0001") ) ); BOOST_REQUIRE_EQUAL( success(), vote( N(bob111111111), vector(), "alice1111111" ) ); - REQUIRE_MATCHING_OBJECT( proxy( "alice1111111" )( "proxied_vote_weight", stake2votes( core_sym::from_string("150.0003") ))( "staked", 100000 ), get_voter_info( "alice1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(alice1111111) )( "proxied_vote_weight", stake2votes( core_sym::from_string("150.0003") ))( "staked", 100000 ), get_voter_info( "alice1111111" ) ); //double regestering should fail without affecting total votes and stake BOOST_REQUIRE_EQUAL( wasm_assert_msg( "action has no effect" ), @@ -2879,7 +2974,7 @@ BOOST_FIXTURE_TEST_CASE( double_register_unregister_proxy_keeps_votes, eosio_sys ("isproxy", 1) ) ); - REQUIRE_MATCHING_OBJECT( proxy( "alice1111111" )( "proxied_vote_weight", stake2votes(core_sym::from_string("150.0003")) )( "staked", 100000 ), get_voter_info( "alice1111111" ) ); + REQUIRE_MATCHING_OBJECT( proxy( N(alice1111111) )( "proxied_vote_weight", stake2votes(core_sym::from_string("150.0003")) )( "staked", 100000 ), get_voter_info( "alice1111111" ) ); //uregister BOOST_REQUIRE_EQUAL( success(), push_action( N(alice1111111), N(regproxy), mvo() @@ -2961,9 +3056,9 @@ fc::mutable_variant_object config_to_variant( const eosio::chain::chain_config& BOOST_FIXTURE_TEST_CASE( elect_producers /*_and_parameters*/, eosio_system_tester ) try { create_accounts_with_resources( { N(defproducer1), N(defproducer2), N(defproducer3) } ); - BOOST_REQUIRE_EQUAL( success(), regproducer( "defproducer1", 1) ); - BOOST_REQUIRE_EQUAL( success(), regproducer( "defproducer2", 2) ); - BOOST_REQUIRE_EQUAL( success(), regproducer( "defproducer3", 3) ); + BOOST_REQUIRE_EQUAL( success(), regproducer( N(defproducer1), 1) ); + BOOST_REQUIRE_EQUAL( success(), regproducer( N(defproducer2), 2) ); + BOOST_REQUIRE_EQUAL( success(), regproducer( N(defproducer3), 3) ); //stake more than 15% of total EOS supply to activate chain transfer( "eosio", "alice1111111", core_sym::from_string("600000000.0000"), "eosio" ); @@ -3030,8 +3125,8 @@ BOOST_FIXTURE_TEST_CASE( buyname, eosio_system_tester ) try { create_accounts_with_resources( { N(dan), N(sam) } ); transfer( config::system_account_name, "dan", core_sym::from_string( "10000.0000" ) ); transfer( config::system_account_name, "sam", core_sym::from_string( "10000.0000" ) ); - stake_with_transfer( config::system_account_name, "sam", core_sym::from_string( "80000000.0000" ), core_sym::from_string( "80000000.0000" ) ); - stake_with_transfer( config::system_account_name, "dan", core_sym::from_string( "80000000.0000" ), core_sym::from_string( "80000000.0000" ) ); + stake_with_transfer( config::system_account_name, N(sam), core_sym::from_string( "80000000.0000" ), core_sym::from_string( "80000000.0000" ) ); + stake_with_transfer( config::system_account_name, N(dan), core_sym::from_string( "80000000.0000" ), core_sym::from_string( "80000000.0000" ) ); regproducer( config::system_account_name ); BOOST_REQUIRE_EQUAL( success(), vote( N(sam), { config::system_account_name } ) ); @@ -3095,8 +3190,8 @@ BOOST_FIXTURE_TEST_CASE( multiple_namebids, eosio_system_tester ) try { produce_block(); // stake but but not enough to go live - stake_with_transfer( config::system_account_name, "bob", core_sym::from_string( "35000000.0000" ), core_sym::from_string( "35000000.0000" ) ); - stake_with_transfer( config::system_account_name, "carl", core_sym::from_string( "35000000.0000" ), core_sym::from_string( "35000000.0000" ) ); + stake_with_transfer( config::system_account_name, N(bob), core_sym::from_string( "35000000.0000" ), core_sym::from_string( "35000000.0000" ) ); + stake_with_transfer( config::system_account_name, N(carl), core_sym::from_string( "35000000.0000" ), core_sym::from_string( "35000000.0000" ) ); BOOST_REQUIRE_EQUAL( success(), vote( N(bob), { N(producer) } ) ); BOOST_REQUIRE_EQUAL( success(), vote( N(carl), { N(producer) } ) ); @@ -3152,7 +3247,7 @@ BOOST_FIXTURE_TEST_CASE( multiple_namebids, eosio_system_tester ) try { fc::exception, fc_assert_exception_message_is( not_closed_message ) ); // stake enough to go above the 15% threshold - stake_with_transfer( config::system_account_name, "alice", core_sym::from_string( "10000000.0000" ), core_sym::from_string( "10000000.0000" ) ); + stake_with_transfer( config::system_account_name, N(alice), core_sym::from_string( "10000000.0000" ), core_sym::from_string( "10000000.0000" ) ); BOOST_REQUIRE_EQUAL(0, get_producer_info("producer")["unpaid_blocks"].as()); BOOST_REQUIRE_EQUAL( success(), vote( N(alice), { N(producer) } ) ); @@ -3324,7 +3419,7 @@ BOOST_FIXTURE_TEST_CASE( setparams, eosio_system_tester ) try { act.name = name; act.data = msig_abi_ser.variant_to_binary( action_type_name, data, abi_serializer_max_time ); - return base_tester::push_action( std::move(act), auth ? uint64_t(signer) : signer == N(bob111111111) ? N(alice1111111) : N(bob111111111) ); + return base_tester::push_action( std::move(act), (auth ? signer : signer == N(bob111111111) ? N(alice1111111) : N(bob111111111)).to_uint64_t() ); }; // test begins @@ -3488,7 +3583,7 @@ BOOST_FIXTURE_TEST_CASE( ram_inflation, eosio_system_tester ) try { BOOST_REQUIRE_EQUAL( cur_ram_size + 2 * rate, get_global_state()["max_ram_size"].as_uint64() ); BOOST_REQUIRE_EQUAL( error("missing authority of eosio"), - push_action( "alice1111111", N(setramrate), mvo()("bytes_per_block", rate) ) ); + push_action( N(alice1111111), N(setramrate), mvo()("bytes_per_block", rate) ) ); cur_ram_size = get_global_state()["max_ram_size"].as_uint64(); produce_blocks(10); @@ -3511,14 +3606,14 @@ BOOST_FIXTURE_TEST_CASE( eosioram_ramusage, eosio_system_tester ) try { const asset initial_ramfee_balance = get_balance(N(eosio.ramfee)); BOOST_REQUIRE_EQUAL( success(), buyram( "alice1111111", "alice1111111", core_sym::from_string("1000.0000") ) ); - BOOST_REQUIRE_EQUAL( false, get_row_by_account( N(eosio.token), N(alice1111111), N(accounts), symbol{CORE_SYM}.to_symbol_code() ).empty() ); + BOOST_REQUIRE_EQUAL( false, get_row_by_account( N(eosio.token), N(alice1111111), N(accounts), account_name(symbol{CORE_SYM}.to_symbol_code()) ).empty() ); //remove row base_tester::push_action( N(eosio.token), N(close), N(alice1111111), mvo() ( "owner", "alice1111111" ) ( "symbol", symbol{CORE_SYM} ) ); - BOOST_REQUIRE_EQUAL( true, get_row_by_account( N(eosio.token), N(alice1111111), N(accounts), symbol{CORE_SYM}.to_symbol_code() ).empty() ); + BOOST_REQUIRE_EQUAL( true, get_row_by_account( N(eosio.token), N(alice1111111), N(accounts), account_name(symbol{CORE_SYM}.to_symbol_code()) ).empty() ); auto rlm = control->get_resource_limits_manager(); auto eosioram_ram_usage = rlm.get_account_ram_usage(N(eosio.ram)); @@ -5318,8 +5413,10 @@ BOOST_FIXTURE_TEST_CASE( rex_return, eosio_system_tester ) try { BOOST_AUTO_TEST_CASE( setabi_bios ) try { - validating_tester t( validating_tester::default_config() ); - t.execute_setup_policy( setup_policy::preactivate_feature_only ); + fc::temp_directory tempdir; + validating_tester t( tempdir, true ); + t.execute_setup_policy( setup_policy::full ); + abi_serializer abi_ser(fc::json::from_string( (const char*)contracts::bios_abi().data()).template as(), base_tester::abi_serializer_max_time); t.set_code( config::system_account_name, contracts::bios_wasm() ); t.set_abi( config::system_account_name, contracts::bios_abi().data() ); diff --git a/tests/eosio.token_tests.cpp b/tests/eosio.token_tests.cpp index acca038a6..9a1d82193 100644 --- a/tests/eosio.token_tests.cpp +++ b/tests/eosio.token_tests.cpp @@ -44,14 +44,14 @@ class eosio_token_tester : public tester { act.name = name; act.data = abi_ser.variant_to_binary( action_type_name, data,abi_serializer_max_time ); - return base_tester::push_action( std::move(act), uint64_t(signer)); + return base_tester::push_action( std::move(act), signer.to_uint64_t() ); } fc::variant get_stats( const string& symbolname ) { auto symb = eosio::chain::symbol::from_string(symbolname); auto symbol_code = symb.to_symbol_code().value; - vector data = get_row_by_account( N(eosio.token), symbol_code, N(stat), symbol_code ); + vector data = get_row_by_account( N(eosio.token), name(symbol_code), N(stat), account_name(symbol_code) ); return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "currency_stats", data, abi_serializer_max_time ); } @@ -59,7 +59,7 @@ class eosio_token_tester : public tester { { auto symb = eosio::chain::symbol::from_string(symbolname); auto symbol_code = symb.to_symbol_code().value; - vector data = get_row_by_account( N(eosio.token), acc, N(accounts), symbol_code ); + vector data = get_row_by_account( N(eosio.token), acc, N(accounts), account_name(symbol_code) ); return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "account", data, abi_serializer_max_time ); } diff --git a/tests/eosio.wrap_tests.cpp b/tests/eosio.wrap_tests.cpp index 4e24a48ff..e7b7cb03e 100644 --- a/tests/eosio.wrap_tests.cpp +++ b/tests/eosio.wrap_tests.cpp @@ -184,7 +184,7 @@ BOOST_FIXTURE_TEST_CASE( wrap_exec_direct, eosio_wrap_tester ) try { ) ); */ wrap_trx.sign( get_private_key( N(alice), "active" ), control->get_chain_id() ); - for( const auto& actor : {"prod1", "prod2", "prod3", "prod4"} ) { + for( const auto& actor : {N(prod1), N(prod2), N(prod3), N(prod4)} ) { wrap_trx.sign( get_private_key( actor, "active" ), control->get_chain_id() ); } push_transaction( wrap_trx ); @@ -194,8 +194,8 @@ BOOST_FIXTURE_TEST_CASE( wrap_exec_direct, eosio_wrap_tester ) try { BOOST_REQUIRE( bool(trace) ); BOOST_REQUIRE_EQUAL( 1, trace->action_traces.size() ); - BOOST_REQUIRE_EQUAL( "eosio", name{trace->action_traces[0].act.account} ); - BOOST_REQUIRE_EQUAL( "reqauth", name{trace->action_traces[0].act.name} ); + BOOST_REQUIRE_EQUAL( config::system_account_name, name{trace->action_traces[0].act.account} ); + BOOST_REQUIRE_EQUAL( N(reqauth), name{trace->action_traces[0].act.name} ); BOOST_REQUIRE_EQUAL( transaction_receipt::executed, trace->receipt->status ); } FC_LOG_AND_RETHROW() @@ -238,13 +238,13 @@ BOOST_FIXTURE_TEST_CASE( wrap_with_msig, eosio_wrap_tester ) try { BOOST_REQUIRE_EQUAL( 2, traces.size() ); BOOST_REQUIRE_EQUAL( 1, traces[0]->action_traces.size() ); - BOOST_REQUIRE_EQUAL( "eosio.wrap", name{traces[0]->action_traces[0].act.account} ); - BOOST_REQUIRE_EQUAL( "exec", name{traces[0]->action_traces[0].act.name} ); + BOOST_REQUIRE_EQUAL( N(eosio.wrap), name{traces[0]->action_traces[0].act.account} ); + BOOST_REQUIRE_EQUAL( N(exec), name{traces[0]->action_traces[0].act.name} ); BOOST_REQUIRE_EQUAL( transaction_receipt::executed, traces[0]->receipt->status ); BOOST_REQUIRE_EQUAL( 1, traces[1]->action_traces.size() ); - BOOST_REQUIRE_EQUAL( "eosio", name{traces[1]->action_traces[0].act.account} ); - BOOST_REQUIRE_EQUAL( "reqauth", name{traces[1]->action_traces[0].act.name} ); + BOOST_REQUIRE_EQUAL( config::system_account_name, name{traces[1]->action_traces[0].act.account} ); + BOOST_REQUIRE_EQUAL( N(reqauth), name{traces[1]->action_traces[0].act.name} ); BOOST_REQUIRE_EQUAL( transaction_receipt::executed, traces[1]->receipt->status ); } FC_LOG_AND_RETHROW() @@ -354,13 +354,13 @@ BOOST_FIXTURE_TEST_CASE( wrap_with_msig_producers_change, eosio_wrap_tester ) tr BOOST_REQUIRE_EQUAL( 2, traces.size() ); BOOST_REQUIRE_EQUAL( 1, traces[0]->action_traces.size() ); - BOOST_REQUIRE_EQUAL( "eosio.wrap", name{traces[0]->action_traces[0].act.account} ); - BOOST_REQUIRE_EQUAL( "exec", name{traces[0]->action_traces[0].act.name} ); + BOOST_REQUIRE_EQUAL( N(eosio.wrap), name{traces[0]->action_traces[0].act.account} ); + BOOST_REQUIRE_EQUAL( N(exec), name{traces[0]->action_traces[0].act.name} ); BOOST_REQUIRE_EQUAL( transaction_receipt::executed, traces[0]->receipt->status ); BOOST_REQUIRE_EQUAL( 1, traces[1]->action_traces.size() ); - BOOST_REQUIRE_EQUAL( "eosio", name{traces[1]->action_traces[0].act.account} ); - BOOST_REQUIRE_EQUAL( "reqauth", name{traces[1]->action_traces[0].act.name} ); + BOOST_REQUIRE_EQUAL( config::system_account_name, name{traces[1]->action_traces[0].act.account} ); + BOOST_REQUIRE_EQUAL( N(reqauth), name{traces[1]->action_traces[0].act.name} ); BOOST_REQUIRE_EQUAL( transaction_receipt::executed, traces[1]->receipt->status ); } FC_LOG_AND_RETHROW() diff --git a/tests/main.cpp b/tests/main.cpp index 2c658f31a..e3d617509 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -31,7 +31,12 @@ boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { break; } } - if(!is_verbose) fc::logger::get(DEFAULT_LOGGER).set_log_level(fc::log_level::off); + + if(is_verbose) { + fc::logger::get(DEFAULT_LOGGER).set_log_level(fc::log_level::debug); + } else { + fc::logger::get(DEFAULT_LOGGER).set_log_level(fc::log_level::off); + } // Register fc::exception translator boost::unit_test::unit_test_monitor.template register_exception_translator(&translate_fc_exception);