diff --git a/libraries/chain/chain_controller.cpp b/libraries/chain/chain_controller.cpp index da96bb55a91..16f51d2bc2c 100644 --- a/libraries/chain/chain_controller.cpp +++ b/libraries/chain/chain_controller.cpp @@ -567,9 +567,8 @@ void chain_controller::validate_expiration(const SignedTransaction& trx) const * The order of execution of precondition and apply can impact the validity of the * entire message. */ -void chain_controller::process_message( const ProcessedTransaction& trx, AccountName code, const Message& message, - TransactionAuthorizationChecker* authChecker, MessageOutput& output) { - apply_context apply_ctx(*this, _db, trx, message, code, authChecker); +void chain_controller::process_message( const ProcessedTransaction& trx, AccountName code, const Message& message, MessageOutput& output) { + apply_context apply_ctx(*this, _db, trx, message, code); apply_message(apply_ctx); output.notify.reserve( apply_ctx.notified.size() ); @@ -578,7 +577,7 @@ void chain_controller::process_message( const ProcessedTransaction& trx, Account try { auto notify_code = apply_ctx.notified[i]; output.notify.push_back( {notify_code} ); - process_message( trx, notify_code, message, authChecker, output.notify.back().output ); + process_message( trx, notify_code, message, output.notify.back().output ); } FC_CAPTURE_AND_RETHROW((apply_ctx.notified[i])) } @@ -637,44 +636,13 @@ ProcessedTransaction chain_controller::_apply_transaction(const SignedTransactio */ ProcessedTransaction chain_controller::process_transaction( const SignedTransaction& trx ) { try { - // This lambda takes an AccountPermission, and returns its parent. It caches the permission_object it last returned, - // which allows it to simplify the database lookups when it is next used to fetch that object's parent. - auto getParentPermission = - [&index = _db.get_index().indices(), cache = static_cast(nullptr)] - (const types::AccountPermission& child) mutable -> fc::optional { - // Ensure cache points to permission_object corresponding to child - if (!(cache && cache->owner == child.account && cache->name == child.permission)) { - auto& ownerIndex = index.get(); - auto itr = ownerIndex.find(boost::make_tuple(child.account, child.permission)); - FC_ASSERT(itr != ownerIndex.end(), "Unable to find permission_object for AccountPermission '${perm}'", - ("perm", child)); - cache = &*itr; - } - - // Make cache point to the parent of child and return result - if (cache) { - if (cache->parent._id == 0) { - cache = nullptr; - return {}; - } else { - cache = &*index.get().find(cache->parent); - return types::AccountPermission(cache->owner, cache->name); - } - } - return {}; - }; - ProcessedTransaction ptrx( trx ); - TransactionAuthorizationChecker authChecker(trx.authorizations, getParentPermission); ptrx.output.resize( trx.messages.size() ); for( uint32_t i = 0; i < ptrx.messages.size(); ++i ) { - process_message(ptrx, ptrx.messages[i].code, ptrx.messages[i], &authChecker, ptrx.output[i] ); + process_message(ptrx, ptrx.messages[i].code, ptrx.messages[i], ptrx.output[i] ); } - EOS_ASSERT(authChecker.allPermissionsUsed(), tx_irrelevant_auth, - "Transaction declared an authorization it did not need"); - return ptrx; } FC_CAPTURE_AND_RETHROW( (trx) ) } @@ -830,11 +798,11 @@ void chain_controller::initialize_chain(chain_initializer_interface& starter) auto messages = starter.prepare_database(*this, _db); std::for_each(messages.begin(), messages.end(), [&](const Message& m) { MessageOutput output; - ProcessedTransaction trx; /// dummy transaction required for scope validation + ProcessedTransaction trx; /// dummy tranaction required for scope validation trx.scope = { config::EosContractName, "inita" }; std::sort(trx.scope.begin(), trx.scope.end() ); with_skip_flags( skip_scope_check, [&](){ - process_message(trx,m.code,m,nullptr,output); + process_message(trx,m.code,m,output); } ); }); }); @@ -1103,7 +1071,6 @@ ProcessedTransaction chain_controller::transaction_from_variant( const fc::varia GET_FIELD( vo, expiration, result ); GET_FIELD( vo, scope, result ); GET_FIELD( vo, signatures, result ); - GET_FIELD( vo, authorizations, result ); if( vo.contains( "messages" ) ) { const vector& msgs = vo["messages"].get_array(); @@ -1112,6 +1079,7 @@ ProcessedTransaction chain_controller::transaction_from_variant( const fc::varia const auto& vo = msgs[i].get_object(); GET_FIELD( vo, code, result.messages[i] ); GET_FIELD( vo, type, result.messages[i] ); + GET_FIELD( vo, authorization, result.messages[i] ); if( vo.contains( "data" ) ) { const auto& data = vo["data"]; @@ -1172,7 +1140,6 @@ fc::variant chain_controller::transaction_to_variant( const ProcessedTransactio SET_FIELD( trx_mvo, trx, expiration ); SET_FIELD( trx_mvo, trx, scope ); SET_FIELD( trx_mvo, trx, signatures ); - SET_FIELD( trx_mvo, trx, authorizations ); vector msgs( trx.messages.size() ); vector msgsv(msgs.size()); @@ -1182,6 +1149,7 @@ fc::variant chain_controller::transaction_to_variant( const ProcessedTransactio auto& msg = trx.messages[i]; SET_FIELD( msg_mvo, msg, code ); SET_FIELD( msg_mvo, msg, type ); + SET_FIELD( msg_mvo, msg, authorization ); const auto& code_account = _db.get( msg.code ); if( code_account.abi.size() > 4 ) { /// 4 == packsize of empty Abi diff --git a/libraries/chain/include/eos/chain/chain_controller.hpp b/libraries/chain/include/eos/chain/chain_controller.hpp index 6b79c1d3843..5657455fc0f 100644 --- a/libraries/chain/include/eos/chain/chain_controller.hpp +++ b/libraries/chain/include/eos/chain/chain_controller.hpp @@ -275,8 +275,7 @@ namespace eos { namespace chain { void validate_authority(const SignedTransaction& trx )const; /// @} - void process_message(const ProcessedTransaction& trx, AccountName code, const Message& message, - TransactionAuthorizationChecker* authChecker, MessageOutput& output); + void process_message(const ProcessedTransaction& trx, AccountName code, const Message& message, MessageOutput& output); void apply_message(apply_context& c); bool should_check_for_duplicate_transactions()const { return !(_skip_flags&skip_transaction_dupe_check); } diff --git a/libraries/chain/include/eos/chain/message.hpp b/libraries/chain/include/eos/chain/message.hpp index 30f1211a3f1..050b4978484 100644 --- a/libraries/chain/include/eos/chain/message.hpp +++ b/libraries/chain/include/eos/chain/message.hpp @@ -22,13 +22,13 @@ namespace eos { namespace chain { struct Message : public types::Message { Message() = default; template - Message(const AccountName& code, const types::FuncName& type, T&& value) - :types::Message(code, type, Bytes()) { + Message(const AccountName& code, const vector& authorization, const types::FuncName& type, T&& value) + :types::Message(code, type, authorization, Bytes()) { set(type, std::forward(value)); } - Message(const AccountName& code, const types::FuncName& type) - :types::Message(code, type, Bytes()) {} + Message(const AccountName& code, const vector& authorization, const types::FuncName& type) + :types::Message(code, type, authorization, Bytes()) {} Message(const types::Message& m) : types::Message(m) {} diff --git a/libraries/chain/include/eos/chain/message_handling_contexts.hpp b/libraries/chain/include/eos/chain/message_handling_contexts.hpp index 4ff0402f3cf..3e05e78610f 100644 --- a/libraries/chain/include/eos/chain/message_handling_contexts.hpp +++ b/libraries/chain/include/eos/chain/message_handling_contexts.hpp @@ -15,9 +15,8 @@ class message_validate_context { const chainbase::database& d, const chain::Transaction& t, const chain::Message& m, - types::AccountName c, - TransactionAuthorizationChecker* authChecker) - :controller(control),db(d),trx(t),msg(m),code(c),authChecker(authChecker){} + types::AccountName c ) + :controller(control),db(d),trx(t),msg(m),code(c),used_authorizations(msg.authorization.size(), false){} /** * @brief Require @ref account to have approved of this message @@ -37,8 +36,6 @@ class message_validate_context { const chain::Message& msg; ///< message being applied types::AccountName code; ///< the code that is currently running - TransactionAuthorizationChecker* authChecker; - int32_t load_i64( Name scope, Name code, Name table, Name Key, char* data, uint32_t maxlen ); @@ -59,6 +56,9 @@ class message_validate_context { uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen ); int32_t lowerbound_secondary_i128i128( Name scope, Name code, Name table, uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen ); + + ///< Parallel to msg.authorization; tracks which permissions have been used while processing the message + vector used_authorizations; }; class precondition_validate_context : public message_validate_context { @@ -67,9 +67,8 @@ class precondition_validate_context : public message_validate_context { const chainbase::database& db, const chain::Transaction& t, const chain::Message& m, - const types::AccountName& code, - TransactionAuthorizationChecker* authChecker) - :message_validate_context(con, db, t, m, code, authChecker){} + const types::AccountName& code) + :message_validate_context(con, db, t, m, code){} }; class apply_context : public precondition_validate_context { @@ -78,9 +77,8 @@ class apply_context : public precondition_validate_context { chainbase::database& db, const chain::Transaction& t, const chain::Message& m, - const types::AccountName& code, - TransactionAuthorizationChecker* authChecker) - :precondition_validate_context(con,db,t,m,code,authChecker),mutable_controller(con),mutable_db(db){} + const types::AccountName& code) + :precondition_validate_context(con,db,t,m,code),mutable_controller(con),mutable_db(db){} int32_t store_i64( Name scope, Name table, Name key, const char* data, uint32_t len); int32_t remove_i64( Name scope, Name table, Name key ); diff --git a/libraries/chain/include/eos/chain/transaction.hpp b/libraries/chain/include/eos/chain/transaction.hpp index 773df23dc9c..f686b3ed665 100644 --- a/libraries/chain/include/eos/chain/transaction.hpp +++ b/libraries/chain/include/eos/chain/transaction.hpp @@ -146,80 +146,6 @@ namespace eos { namespace chain { vector output; }; - /** - * @brief This class aids in checking that a transaction is properly authorized, and that no unnecessary - * authorizations are present in it. - * - * In order for a transaction to be valid, it must declare the permissions it requires to execute all of its - * contained messages (@see SignedTransaction::authorizations). The blockchain can verify that the transaction bears - * signatures necessary and sufficient to satisfy its declared permissions before the transaction is executed; - * however, the blockchain cannot know whether the declared permissions are necessary and sufficient to authorize - * the transaction until the transaction is fully executed. This is because the permissions required is a - * contract-layer concern, so the way we discover what permissions are required is by executing the messages, and as - * the message handlers execute, they assert that certain permissions are required. - * - * This class takes the list of declared permissions provided by a transaction at construction. As the transaction - * is subsequently executed, and the message handlers assert that permissions are required, and these required - * permissions can be passed to @ref requirePermission which will verify that the declared permissions satisfy the - * required permissions. This class also tracks which of the declared permissions have been used to satisfy a - * permission passed to @ref requirePermission and which ones have not. - * - * When the transaction is finished executing, call @ref allPermissionsUsed to determine whether any declared - * permissions were unnecessary to fully authorize the transaction. - */ - class TransactionAuthorizationChecker { - public: - using ParentGetter = std::function(const types::AccountPermission&)>; - - /** - * @param declaredPermissions The permissions declared by the transaction as necessary and sufficient to - * authorize it - * @param getParentPermission A callable which takes a @ref types::AccountPermission and returns its parent, or - * an empty optional if no parent exists - */ - TransactionAuthorizationChecker(const vector& declaredPermissions, - ParentGetter getParentPermission) - : declaredPermissions(declaredPermissions), getParentPermission(getParentPermission) {} - - bool requirePermission(const types::AccountPermission& permission) { - auto Matches = [](const types::AccountPermission& permission) { - return [&permission](const types::AccountPermission& other) { - return permission.account == other.account && permission.permission == other.permission; - }; - }; - - auto itr = std::find_if(declaredPermissions.begin(), declaredPermissions.end(), Matches(permission)); - if (itr != declaredPermissions.end()) { - usedPermissions[itr - declaredPermissions.begin()] = true; - return true; - } - - auto parent = getParentPermission(permission); - while (parent) { - itr = std::find_if(declaredPermissions.begin(), declaredPermissions.end(), Matches(*parent)); - if (itr != declaredPermissions.end()) { - usedPermissions[itr - declaredPermissions.begin()] = true; - return true; - } - parent = getParentPermission(*parent); - } - - return false; - } - - bool allPermissionsUsed() const { - return std::all_of(usedPermissions.begin(), usedPermissions.end(), [](bool b){return b;}); - } - - private: - /// The list of permissions declared by the transaction - const vector declaredPermissions; - /// Parallel to @ref declaredPermissions; usedPermissions[N] is true iff declaredPermissions[N] has been required - vector usedPermissions = vector(declaredPermissions.size(), false); - - ParentGetter getParentPermission; - }; - /// @} transactions group } } // eos::chain diff --git a/libraries/chain/message_handling_contexts.cpp b/libraries/chain/message_handling_contexts.cpp index 8574224cf03..acab6c6c8dc 100644 --- a/libraries/chain/message_handling_contexts.cpp +++ b/libraries/chain/message_handling_contexts.cpp @@ -10,10 +10,7 @@ namespace eos { namespace chain { void message_validate_context::require_authorization(const types::AccountName& account) { -#warning TODO: Look up the permission_object that account has specified to use for this message type - if (authChecker) - EOS_ASSERT(authChecker->requirePermission({account, "active"}), tx_missing_auth, - "Transaction does not declare required authority '${auth}'", ("auth", account)); +#warning TODO } void message_validate_context::require_scope(const types::AccountName& account)const { diff --git a/libraries/native_contract/eos_contract.cpp b/libraries/native_contract/eos_contract.cpp index 73cf5b5ae22..cf8ea4d943a 100644 --- a/libraries/native_contract/eos_contract.cpp +++ b/libraries/native_contract/eos_contract.cpp @@ -212,8 +212,7 @@ void apply_eos_setcode(apply_context& context) { a.set_abi( msg.abi ); }); - apply_context init_context( context.mutable_controller, context.mutable_db, context.trx, context.msg, msg.account, - context.authChecker); + apply_context init_context( context.mutable_controller, context.mutable_db, context.trx, context.msg, msg.account ); wasm_interface::get().init( init_context ); } diff --git a/libraries/native_contract/native_contract_chain_initializer.cpp b/libraries/native_contract/native_contract_chain_initializer.cpp index 90d0d3dab81..aff9daf8e65 100644 --- a/libraries/native_contract/native_contract_chain_initializer.cpp +++ b/libraries/native_contract/native_contract_chain_initializer.cpp @@ -85,6 +85,7 @@ std::vector native_contract_chain_initializer::prepare_database( }; for (const auto& acct : genesis.initial_accounts) { chain::Message message(config::EosContractName, + vector{{config::EosContractName, "active"}}, "newaccount", types::newaccount(config::EosContractName, acct.name, KeyAuthority(acct.owner_key), KeyAuthority(acct.active_key), @@ -92,7 +93,8 @@ std::vector native_contract_chain_initializer::prepare_database( acct.staking_balance)); messages_to_process.emplace_back(std::move(message)); if (acct.liquid_balance > 0) { - message = chain::Message(config::EosContractName, + message = chain::Message(config::EosContractName, + vector{{config::EosContractName, "active"}}, "transfer", types::transfer(config::EosContractName, acct.name, acct.liquid_balance.amount/*, "Genesis Allocation"*/)); messages_to_process.emplace_back(std::move(message)); @@ -101,7 +103,7 @@ std::vector native_contract_chain_initializer::prepare_database( // Create initial producers auto CreateProducer = boost::adaptors::transformed([config = genesis.initial_configuration](const auto& p) { - return chain::Message(config::EosContractName, + return chain::Message(config::EosContractName, vector{{p.owner_name, "active"}}, "setproducer", types::setproducer(p.owner_name, p.block_signing_key, config)); }); boost::copy(genesis.initial_producers | CreateProducer, std::back_inserter(messages_to_process)); diff --git a/libraries/types/types.eos b/libraries/types/types.eos index d562830863e..96384e9d8e2 100644 --- a/libraries/types/types.eos +++ b/libraries/types/types.eos @@ -12,7 +12,8 @@ struct AccountPermission struct Message code AccountName # the contract defining the primary code to execute for code/type - type FuncName # the action to be taken + type FuncName # the action to be taken + authorization AccountPermission[] # the accounts and permission levels provided data Bytes # opaque data processed by code struct AccountPermissionWeight diff --git a/programs/eosc/main.cpp b/programs/eosc/main.cpp index 8ffaea9b866..9bf6cc2192a 100644 --- a/programs/eosc/main.cpp +++ b/programs/eosc/main.cpp @@ -108,8 +108,8 @@ void create_account( const vector& args ) { SignedTransaction trx; trx.scope = sort_names({creator,eosaccnt}); - trx.authorizations = vector{{creator,"active"}}; - trx.emplaceMessage(config::EosContractName, + trx.emplaceMessage(config::EosContractName, + vector{{creator, "active"}}, "newaccount", types::newaccount{creator, newaccount, owner_auth, active_auth, recovery_auth, deposit}); @@ -159,10 +159,10 @@ int main( int argc, char** argv ) { SignedTransaction trx; trx.messages.resize(1); - trx.authorizations = fc::json::from_string( args[6] ).as>(); auto& msg = trx.messages.back(); msg.code = code; msg.type = action; + msg.authorization = fc::json::from_string( args[6] ).as>(); msg.data = result.get_object()["binargs"].as(); trx.scope = fc::json::from_string( args[5] ).as>(); @@ -202,8 +202,8 @@ int main( int argc, char** argv ) { SignedTransaction trx; trx.scope = { config::EosContractName, account }; - trx.authorizations = vector{{account,"active"}}; trx.emplaceMessage( config::EosContractName, + vector{ {account,"active"} }, "setcode", handler ); std::cout << fc::json::to_pretty_string( push_transaction(trx) ); @@ -217,8 +217,9 @@ int main( int argc, char** argv ) { SignedTransaction trx; trx.scope = sort_names({sender,recipient}); - trx.authorizations = vector{{sender,"active"}}; - trx.emplaceMessage(config::EosContractName, "transfer", types::transfer{sender, recipient, amount}); + trx.emplaceMessage(config::EosContractName, + vector{ {sender,"active"} }, + "transfer", types::transfer{sender, recipient, amount/*, memo*/}); auto info = get_info(); trx.expiration = info.head_block_time + 100; //chain.head_block_time() + 100; trx.set_reference_block(info.head_block_id); diff --git a/tests/api_tests/api_tests.cpp b/tests/api_tests/api_tests.cpp index 941a017d72d..b3d14f7d46f 100644 --- a/tests/api_tests/api_tests.cpp +++ b/tests/api_tests/api_tests.cpp @@ -99,10 +99,9 @@ void SetCode( testing_blockchain& chain, AccountName account, const char* wast ) } } FC_LOG_AND_RETHROW( ) } -uint32_t CallFunction( testing_blockchain& chain, const types::Message& msg, const vector& auths, const vector& data, const vector& scope = {N(test_api)}) { +uint32_t CallFunction( testing_blockchain& chain, const types::Message& msg, const vector& data, const vector& scope = {N(test_api)}) { static int expiration = 1; eos::chain::SignedTransaction trx; - trx.authorizations = auths; trx.scope = scope; //msg.data.clear(); @@ -149,8 +148,8 @@ uint64_t TEST_METHOD(const char* CLASS, const char *METHOD) { return ( (uint64_t(DJBH(CLASS))<<32) | uint32_t(DJBH(METHOD)) ); } -#define CALL_TEST_FUNCTION(TYPE, AUTH, DATA) CallFunction(chain, Message{"test_api", TYPE}, AUTH, DATA) -#define CALL_TEST_FUNCTION_SCOPE(TYPE, AUTH, DATA, SCOPE) CallFunction(chain, Message{"test_api", TYPE}, AUTH, DATA, SCOPE) +#define CALL_TEST_FUNCTION(TYPE, AUTH, DATA) CallFunction(chain, Message{"test_api", AUTH, TYPE}, DATA) +#define CALL_TEST_FUNCTION_SCOPE(TYPE, AUTH, DATA, SCOPE) CallFunction(chain, Message{"test_api", AUTH, TYPE}, DATA, SCOPE) bool is_access_violation(fc::unhandled_exception const & e) { try { @@ -230,23 +229,23 @@ BOOST_FIXTURE_TEST_CASE(test_all, testing_fixture) BOOST_CHECK_MESSAGE( CALL_TEST_FUNCTION( TEST_METHOD("test_message", "read_message_to_0"), {}, raw_bytes) == WASM_TEST_PASS, "test_message::read_message_to_0()" ); raw_bytes.resize((1<<16)+1); - BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( TEST_METHOD("test_message", "read_message_to_0"), {}, raw_bytes), + BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( TEST_METHOD("test_message", "read_message_to_0"), {}, raw_bytes), fc::unhandled_exception, is_access_violation ); raw_bytes.resize(1); BOOST_CHECK_MESSAGE( CALL_TEST_FUNCTION( TEST_METHOD("test_message", "read_message_to_64k"), {}, raw_bytes) == WASM_TEST_PASS, "test_message::read_message_to_64k()" ); raw_bytes.resize(2); - BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( TEST_METHOD("test_message", "read_message_to_64k"), {}, raw_bytes), + BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( TEST_METHOD("test_message", "read_message_to_64k"), {}, raw_bytes), fc::unhandled_exception, is_access_violation ); BOOST_CHECK_MESSAGE( CALL_TEST_FUNCTION( TEST_METHOD("test_message", "require_notice"), {}, raw_bytes) == WASM_TEST_PASS, "test_message::require_notice()" ); - BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( TEST_METHOD("test_message", "require_auth"), {}, {}), + BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( TEST_METHOD("test_message", "require_auth"), {}, {}), tx_missing_auth, is_tx_missing_auth ); auto a3only = vector{{"acc3","active"}}; - BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( TEST_METHOD("test_message", "require_auth"), a3only, {}), + BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( TEST_METHOD("test_message", "require_auth"), a3only, {}), tx_missing_auth, is_tx_missing_auth ); auto a4only = vector{{"acc4","active"}}; diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 4e141050fb3..b5f940fd66e 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -417,8 +417,12 @@ class testing_network { #define Set_Proxy(chain, stakeholder, proxy) \ { \ eos::chain::SignedTransaction trx; \ - trx.authorizations = vector{{#stakeholder,"active"}}; \ - trx.emplaceMessage(config::EosContractName, "setproxy", types::setproxy{#stakeholder, #proxy}); \ + if (std::string(#stakeholder) != std::string(#proxy)) \ + trx.emplaceMessage(config::EosContractName, \ + vector{ {#stakeholder,"active"} }, "setproxy", types::setproxy{#stakeholder, #proxy}); \ + else \ + trx.emplaceMessage(config::EosContractName, \ + vector{ {#stakeholder,"active"} }, "setproxy", types::setproxy{#stakeholder, #proxy}); \ trx.expiration = chain.head_block_time() + 100; \ trx.set_reference_block(chain.head_block_id()); \ chain.push_transaction(trx); \ diff --git a/tests/common/macro_support.hpp b/tests/common/macro_support.hpp index 39a125ec17d..81240f0ab4b 100644 --- a/tests/common/macro_support.hpp +++ b/tests/common/macro_support.hpp @@ -34,11 +34,12 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names({ #creator, "eos" }); \ - trx.authorizations = vector{{#creator,"active"}}; \ - trx.emplaceMessage(config::EosContractName, "newaccount", types::newaccount{#creator, #name, owner, active, recovery, deposit}); \ + trx.emplaceMessage(config::EosContractName, \ + vector{}, \ + "newaccount", types::newaccount{#creator, #name, owner, active, recovery, deposit}); \ trx.expiration = chain.head_block_time() + 100; \ trx.set_reference_block(chain.head_block_id()); \ - chain.push_transaction(trx, chain_controller::skip_transaction_signatures); \ + chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Created account " << #name); \ } #define MKACCT2(chain, name) \ @@ -65,8 +66,9 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names({#sender,#recipient}); \ - trx.authorizations = vector{{#sender,"active"}}; \ - trx.emplaceMessage(config::EosContractName, "transfer", types::transfer{#sender, #recipient, Amount.amount}); \ + trx.emplaceMessage(config::EosContractName, \ + vector{ {#sender,"active"} }, \ + "transfer", types::transfer{#sender, #recipient, Amount.amount/*, memo*/}); \ trx.expiration = chain.head_block_time() + 100; \ trx.set_reference_block(chain.head_block_id()); \ chain.push_transaction(trx); \ @@ -78,8 +80,8 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( { #sender, #recipient } ); \ - trx.authorizations = vector{{#sender,"active"}}; \ - trx.emplaceMessage(config::EosContractName, "lock", types::lock{#sender, #recipient, amount}); \ + trx.emplaceMessage(config::EosContractName, \ + vector{}, "lock", types::lock{#sender, #recipient, amount}); \ trx.expiration = chain.head_block_time() + 100; \ trx.set_reference_block(chain.head_block_id()); \ chain.push_transaction(trx); \ @@ -91,8 +93,9 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( { "eos" } ); \ - trx.authorizations.emplace_back(types::AccountPermission{#account,"active"}); \ - trx.emplaceMessage(config::EosContractName, "unlock", types::unlock{#account, amount}); \ + trx.emplaceMessage(config::EosContractName, \ + vector{}, \ + "unlock", types::unlock{#account, amount}); \ trx.expiration = chain.head_block_time() + 100; \ trx.set_reference_block(chain.head_block_id()); \ chain.push_transaction(trx); \ @@ -103,8 +106,8 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( { "eos", #account } ); \ - trx.authorizations.emplace_back(types::AccountPermission{#account,"active"}); \ - trx.emplaceMessage(config::EosContractName, "claim", types::claim{#account, amount}); \ + trx.emplaceMessage(config::EosContractName, \ + vector{}, "claim", types::claim{#account, amount}); \ trx.expiration = chain.head_block_time() + 100; \ trx.set_reference_block(chain.head_block_id()); \ chain.push_transaction(trx); \ @@ -115,8 +118,9 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( {#owner, "eos"} ); \ - trx.authorizations = vector{{#owner,"active"}}; \ - trx.emplaceMessage(config::EosContractName, "setproducer", types::setproducer{#owner, key, cfg}); \ + trx.emplaceMessage(config::EosContractName, \ + vector{}, \ + "setproducer", types::setproducer{#owner, key, cfg}); \ trx.expiration = chain.head_block_time() + 100; \ trx.set_reference_block(chain.head_block_id()); \ chain.push_transaction(trx); \ @@ -131,8 +135,9 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( {#voter, "eos"} ); \ - trx.authorizations = vector{{#voter,"active"}}; \ - trx.emplaceMessage(config::EosContractName, "okproducer", types::okproducer{#voter, #producer, approved? 1:0}); \ + trx.emplaceMessage(config::EosContractName, \ + vector{}, \ + "okproducer", types::okproducer{#voter, #producer, approved? 1 : 0}); \ trx.expiration = chain.head_block_time() + 100; \ trx.set_reference_block(chain.head_block_id()); \ chain.push_transaction(trx); \ @@ -143,8 +148,9 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( {#owner, "eos"} ); \ - trx.authorizations = vector{{owner,"active"}}; \ - trx.emplaceMessage(config::EosContractName, "setproducer", types::setproducer{owner, key, cfg}); \ + trx.emplaceMessage(config::EosContractName, \ + vector{}, \ + "setproducer", types::setproducer{owner, key, cfg}); \ trx.expiration = chain.head_block_time() + 100; \ trx.set_reference_block(chain.head_block_id()); \ chain.push_transaction(trx); \ diff --git a/tests/slow_tests/slow_tests.cpp b/tests/slow_tests/slow_tests.cpp index 4f4a0e7c4a7..f64a26e25ff 100644 --- a/tests/slow_tests/slow_tests.cpp +++ b/tests/slow_tests/slow_tests.cpp @@ -301,8 +301,9 @@ void SetCode( testing_blockchain& chain, AccountName account, const char* wast ) void TransferCurrency( testing_blockchain& chain, AccountName from, AccountName to, uint64_t amount ) { eos::chain::SignedTransaction trx; trx.scope = sort_names({from,to}); - trx.authorizations = vector{{from,"active"}}; - trx.emplaceMessage("currency", "transfer", types::transfer{from, to, amount}); + trx.emplaceMessage("currency", + vector{ {from,"active"} }, + "transfer", types::transfer{from, to, amount}); trx.expiration = chain.head_block_time() + 100; trx.set_reference_block(chain.head_block_id()); @@ -313,8 +314,9 @@ void TransferCurrency( testing_blockchain& chain, AccountName from, AccountName void WithdrawCurrency( testing_blockchain& chain, AccountName from, AccountName to, uint64_t amount ) { eos::chain::SignedTransaction trx; trx.scope = sort_names({from,to}); - trx.authorizations = vector{{from,"active"},{to,"active"}}; - trx.emplaceMessage("currency", "transfer", types::transfer{from, to, amount}); + trx.emplaceMessage("currency", + vector{ {from,"active"},{to,"active"} }, + "transfer", types::transfer{from, to, amount}); trx.expiration = chain.head_block_time() + 100; trx.set_reference_block(chain.head_block_id()); chain.push_transaction(trx); @@ -354,8 +356,9 @@ BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture) { eos::chain::SignedTransaction trx; trx.scope = sort_names({"currency","inita"}); - trx.authorizations = vector{{"currency","active"}}; - trx.emplaceMessage("currency", "transfer", types::transfer{"currency", "inita", 1+i}); + trx.emplaceMessage("currency", + vector{ {"currency","active"} }, + "transfer", types::transfer{"currency", "inita", 1+i}); trx.expiration = chain.head_block_time() + 100; trx.set_reference_block(chain.head_block_id()); //idump((trx)); @@ -391,8 +394,9 @@ void SellCurrency( testing_blockchain& chain, AccountName seller, AccountName ex eos::chain::SignedTransaction trx; trx.scope = sort_names({"exchange"}); - trx.authorizations = vector{{seller,"active"}}; - trx.emplaceMessage("exchange", "sell", b ); + trx.emplaceMessage("exchange", + vector{ {seller,"active"} }, + "sell", b ); //trx.messages.back().set_packed( "sell", b); trx.expiration = chain.head_block_time() + 100; trx.set_reference_block(chain.head_block_id()); @@ -408,8 +412,9 @@ void BuyCurrency( testing_blockchain& chain, AccountName buyer, AccountName exch eos::chain::SignedTransaction trx; trx.scope = sort_names({"exchange"}); - trx.authorizations = vector{{buyer,"active"}}; - trx.emplaceMessage("exchange", "buy", b ); + trx.emplaceMessage("exchange", + vector{ {buyer,"active"} }, + "buy", b ); //trx.messages.back().set_packed( "buy", b); trx.expiration = chain.head_block_time() + 100; trx.set_reference_block(chain.head_block_id()); @@ -1153,8 +1158,9 @@ BOOST_FIXTURE_TEST_CASE(create_script_w_loop, testing_fixture) { eos::chain::SignedTransaction trx; trx.scope = sort_names({"currency","inita"}); - trx.authorizations = vector{{"currency","active"}}; - trx.emplaceMessage("currency", "transfer", types::transfer{"currency", "inita", 1}); + trx.emplaceMessage("currency", + vector{ {"currency","active"} }, + "transfer", types::transfer{"currency", "inita", 1}); trx.expiration = chain.head_block_time() + 100; trx.set_reference_block(chain.head_block_id()); try diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 3b774aaf8fd..44ab8fe0957 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -145,8 +145,9 @@ BOOST_FIXTURE_TEST_CASE(trx_variant, testing_fixture) { eos::chain::ProcessedTransaction trx; trx.scope = sort_names({from,to}); - trx.authorizations = vector{{from,"active"}}; - trx.emplaceMessage("eos", "transfer", types::transfer{from, to, amount}); + trx.emplaceMessage("eos", + vector{ {from,"active"} }, + "transfer", types::transfer{from, to, amount/*, ""*/}); trx.expiration = chain.head_block_time() + 100; trx.set_reference_block(chain.head_block_id()); @@ -155,11 +156,13 @@ BOOST_FIXTURE_TEST_CASE(trx_variant, testing_fixture) { auto from_var = chain.transaction_from_variant( var ); auto _process = fc::raw::pack( from_var ); + /* idump((trx)); idump((var)); idump((from_var)); idump((original)); idump((_process)); + */ FC_ASSERT( original == _process, "Transaction seralization not reversible" ); } catch ( const fc::exception& e ) { edump((e.to_detail_string())); diff --git a/tests/tests/native_contract_tests.cpp b/tests/tests/native_contract_tests.cpp index b162c9593a1..2a58af116af 100644 --- a/tests/tests/native_contract_tests.cpp +++ b/tests/tests/native_contract_tests.cpp @@ -91,9 +91,8 @@ BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture) trx.set_reference_block(chain.head_block_id()); trx.expiration = chain.head_block_time() + 100; trx.scope = sort_names( {"inita", "initb"} ); - trx.authorizations = {{"inita", "active"}}; - types::transfer trans = {"inita", "initb", (100)}; + types::transfer trans = { "inita", "initb", (100) }; UInt64 value(5); auto packed = fc::raw::pack(value);