diff --git a/libraries/chain/block.cpp b/libraries/chain/block.cpp index 7dddbf9cc2d57fce4f3ddb70208ea3284c562602..9d56df749862608c7c7ddb4008ad7356892b254a 100644 --- a/libraries/chain/block.cpp +++ b/libraries/chain/block.cpp @@ -102,7 +102,7 @@ namespace eos { namespace chain { */ for( const auto& trx : user_input ) - ids.push_back( trx.digest() ); + ids.push_back( transaction_helpers::digest(trx) ); /** * When generating the merkle hash of an output transaction we hash it diff --git a/libraries/chain/chain_controller.cpp b/libraries/chain/chain_controller.cpp index 72d9888a79ac7030ee0245cf152a070d19e18a16..07886cc026118b359b7efa2fd80a472b95536895 100644 --- a/libraries/chain/chain_controller.cpp +++ b/libraries/chain/chain_controller.cpp @@ -23,7 +23,6 @@ */ #include -#include #include #include @@ -57,7 +56,6 @@ #include //#include - namespace eos { namespace chain { @@ -585,18 +583,7 @@ ProcessedTransaction chain_controller::apply_transaction(const SignedTransaction return with_skip_flags( skip, [&]() { return _apply_transaction(trx); }); } -void chain_controller::validate_transaction(const SignedTransaction& trx)const { -try { - EOS_ASSERT(trx.messages.size() > 0, transaction_exception, "A transaction must have at least one message"); - - validate_scope(trx); - validate_expiration(trx); - validate_uniqueness(trx); - validate_tapos(trx); - -} FC_CAPTURE_AND_RETHROW( (trx) ) } - -void chain_controller::validate_scope( const SignedTransaction& trx )const { +void chain_controller::validate_scope( const Transaction& trx )const { EOS_ASSERT(trx.scope.size() > 0, transaction_exception, "No scope specified by transaction" ); for( uint32_t i = 1; i < trx.scope.size(); ++i ) EOS_ASSERT( trx.scope[i-1] < trx.scope[i], transaction_exception, "Scopes must be sorted and unique" ); @@ -630,18 +617,22 @@ void chain_controller::validate_uniqueness( const SignedTransaction& trx )const EOS_ASSERT(transaction == nullptr, tx_duplicate, "Transaction is not unique"); } -void chain_controller::validate_tapos(const SignedTransaction& trx)const { +void chain_controller::validate_uniqueness( const GeneratedTransaction& trx )const { + if( !should_check_for_duplicate_transactions() ) return; +} + +void chain_controller::validate_tapos(const Transaction& trx)const { if (!should_check_tapos()) return; const auto& tapos_block_summary = _db.get((uint16_t)trx.refBlockNum); //Verify TaPoS block summary has correct ID prefix, and that this block's time is not past the expiration - EOS_ASSERT(trx.verify_reference_block(tapos_block_summary.block_id), transaction_exception, + EOS_ASSERT(transaction_helpers::verify_reference_block(trx, tapos_block_summary.block_id), transaction_exception, "Transaction's reference block did not match. Is this transaction from a different fork?", ("tapos_summary", tapos_block_summary)); } -void chain_controller::validate_referenced_accounts(const SignedTransaction& trx)const { +void chain_controller::validate_referenced_accounts(const Transaction& trx)const { for (const auto& scope : trx.scope) require_account(scope); for (const auto& msg : trx.messages) { @@ -651,7 +642,7 @@ void chain_controller::validate_referenced_accounts(const SignedTransaction& trx } } -void chain_controller::validate_expiration(const SignedTransaction& trx) const +void chain_controller::validate_expiration(const Transaction& trx) const { try { fc::time_point_sec now = head_block_time(); const BlockchainConfiguration& chain_configuration = get_global_properties().configuration; diff --git a/libraries/chain/include/eos/chain/chain_controller.hpp b/libraries/chain/include/eos/chain/chain_controller.hpp index 9114a84de46f08defc0603dfc4bfd28526206e87..63d39c01578436877bb2f002524eab092d81bd1f 100644 --- a/libraries/chain/include/eos/chain/chain_controller.hpp +++ b/libraries/chain/include/eos/chain/chain_controller.hpp @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -282,15 +283,27 @@ namespace eos { namespace chain { /** * This method performs some consistency checks on a transaction. - * @return true if the transaction would validate + * @thow transaction_exception if the transaction is invalid */ - void validate_transaction(const SignedTransaction& trx)const; + template + void validate_transaction(const T& trx) const { + try { + EOS_ASSERT(trx.messages.size() > 0, transaction_exception, "A transaction must have at least one message"); + + validate_scope(trx); + validate_expiration(trx); + validate_uniqueness(trx); + validate_tapos(trx); + + } FC_CAPTURE_AND_RETHROW( (trx) ) } + /// Validate transaction helpers @{ void validate_uniqueness(const SignedTransaction& trx)const; - void validate_tapos(const SignedTransaction& trx)const; - void validate_referenced_accounts(const SignedTransaction& trx)const; - void validate_expiration(const SignedTransaction& trx) const; - void validate_scope(const SignedTransaction& trx) const; + void validate_uniqueness(const GeneratedTransaction& trx)const; + void validate_tapos(const Transaction& trx)const; + void validate_referenced_accounts(const Transaction& trx)const; + void validate_expiration(const Transaction& trx) const; + void validate_scope(const Transaction& trx) const; /// @} /** diff --git a/libraries/chain/include/eos/chain/transaction.hpp b/libraries/chain/include/eos/chain/transaction.hpp index af2200a6a0bd09c11317cbb7e7a07bf9fde33193..2daae7bfe841e14a4734615c74a65accc3de776a 100644 --- a/libraries/chain/include/eos/chain/transaction.hpp +++ b/libraries/chain/include/eos/chain/transaction.hpp @@ -52,6 +52,49 @@ namespace eos { namespace chain { * @{ */ + + + /** + * @brief A base transaction without any explicit or implied authorizations. + * + * This is a utility class for sharing common operations between inheriting types which defines + * additional features and requirements. + */ + namespace transaction_helpers { + /// Calculate the digest for a transaction + digest_type digest(const Transaction& t); + + void set_reference_block(Transaction& t, const block_id_type& reference_block); + + bool verify_reference_block(const Transaction& t, const block_id_type& reference_block); + + template + void set_message(Transaction& t, int index, const types::FuncName& type, T&& value) { + Message m(t.messages[index]); + m.set(type, std::forward(value)); + t.messages[index] = m; + } + + template + T message_as(Transaction& t, int index) { + Message m(t.messages[index]); + return m.as(); + } + + template + void emplace_message(Transaction& t, Args&&... a) { + t.messages.emplace_back(Message(std::forward(a)...)); + } + + /** + * clear all common data + */ + inline + void clear(Transaction& t) { + t.messages.clear(); + } + } + /** * @brief A generated_transaction is a transaction which was internally generated by the blockchain, typically as a * result of running a contract. @@ -65,7 +108,7 @@ namespace eos { namespace chain { * sequential ID, then stored in the block that generated them. These generated transactions can then be included in * subsequent blocks by referencing this ID. */ - struct GeneratedTransaction : public Transaction { + struct GeneratedTransaction : public types::Transaction { generated_transaction_id_type id; digest_type merkle_digest() const; @@ -78,17 +121,15 @@ namespace eos { namespace chain { * and the signatures backing those authorizations. */ struct SignedTransaction : public types::SignedTransaction { - using types::SignedTransaction::SignedTransaction; + typedef types::SignedTransaction super; + using super::super; - /// Calculate the digest for a transaction - digest_type digest()const; + /// Calculate the id of the transaction transaction_id_type id()const; + /// Calculate the digest used for signature validation digest_type sig_digest(const chain_id_type& chain_id)const; - void set_reference_block(const block_id_type& reference_block); - bool verify_reference_block(const block_id_type& reference_block)const; - /** signs and appends to signatures */ const signature_type& sign(const private_key_type& key, const chain_id_type& chain_id); @@ -97,28 +138,12 @@ namespace eos { namespace chain { flat_set get_signature_keys(const chain_id_type& chain_id)const; - template - void setMessage(int messageIndex, const types::FuncName& type, T&& value) { - Message m(messages[messageIndex]); - m.set(type, std::forward(value)); - messages[messageIndex] = m; - } - template - T messageAs(int messageIndex) { - Message m(messages[messageIndex]); - return m.as(); - } - template - void emplaceMessage(Args&&... a) { - messages.emplace_back(Message(std::forward(a)...)); - } - /** * Removes all messages, signatures, and authorizations */ - void clear() { messages.clear(); signatures.clear(); } + void clear() { transaction_helpers::clear(*this); signatures.clear(); } - digest_type merkle_digest()const; + digest_type merkle_digest() const; }; struct ProcessedTransaction; diff --git a/libraries/chain/transaction.cpp b/libraries/chain/transaction.cpp index 3d9c35d7285b3b2a2c62f9394cfbca95ebd2764f..aa78c8b11829c85dbbcc9e6df61d05432884bdaa 100644 --- a/libraries/chain/transaction.cpp +++ b/libraries/chain/transaction.cpp @@ -31,12 +31,26 @@ namespace eos { namespace chain { -digest_type SignedTransaction::digest()const { +namespace transaction_helpers { + +digest_type digest(const Transaction& t) { digest_type::encoder enc; - fc::raw::pack( enc, static_cast(*this) ); + fc::raw::pack( enc, t ); return enc.result(); } +void set_reference_block(Transaction& t, const block_id_type& reference_block) { + t.refBlockNum = fc::endian_reverse_u32(reference_block._hash[0]); + t.refBlockPrefix = reference_block._hash[1]; +} + +bool verify_reference_block(const Transaction& t, const block_id_type& reference_block) { + return t.refBlockNum == (decltype(t.refBlockNum))fc::endian_reverse_u32(reference_block._hash[0]) && + t.refBlockPrefix == (decltype(t.refBlockPrefix))reference_block._hash[1]; +} + +} // namespace transaction_helpers + digest_type SignedTransaction::sig_digest( const chain_id_type& chain_id )const { digest_type::encoder enc; fc::raw::pack( enc, chain_id ); @@ -45,7 +59,7 @@ digest_type SignedTransaction::sig_digest( const chain_id_type& chain_id )const } eos::chain::transaction_id_type SignedTransaction::id() const { - auto h = digest(); + auto h = transaction_helpers::digest(*this); transaction_id_type result; memcpy(result._hash, h._hash, std::min(sizeof(result), sizeof(h))); return result; @@ -60,16 +74,6 @@ signature_type eos::chain::SignedTransaction::sign(const private_key_type& key, return key.sign_compact(sig_digest(chain_id)); } -void SignedTransaction::set_reference_block(const block_id_type& reference_block) { - refBlockNum = fc::endian_reverse_u32(reference_block._hash[0]); - refBlockPrefix = reference_block._hash[1]; -} - -bool SignedTransaction::verify_reference_block(const block_id_type& reference_block) const { - return refBlockNum == (decltype(refBlockNum))fc::endian_reverse_u32(reference_block._hash[0]) && - refBlockPrefix == (decltype(refBlockPrefix))reference_block._hash[1]; -} - flat_set SignedTransaction::get_signature_keys( const chain_id_type& chain_id )const { try { using boost::adaptors::transformed; diff --git a/programs/eosc/main.cpp b/programs/eosc/main.cpp index bf6d3ae2d248e3e021b640a7039b4d5d1fabed4c..09a7e9803af288678869d92fc790674e94966ade 100644 --- a/programs/eosc/main.cpp +++ b/programs/eosc/main.cpp @@ -102,7 +102,7 @@ eos::chain_apis::read_only::get_info_results get_info() { fc::variant push_transaction( SignedTransaction& trx ) { auto info = get_info(); trx.expiration = info.head_block_time + 100; //chain.head_block_time() + 100; - trx.set_reference_block(info.head_block_id); + transaction_helpers::set_reference_block(trx, info.head_block_id); boost::sort( trx.scope ); return call( push_txn_func, trx ); @@ -127,7 +127,7 @@ void create_account( const vector& cmd_line ) { SignedTransaction trx; trx.scope = sort_names({creator,eosaccnt}); - trx.emplaceMessage(config::EosContractName, vector{{creator,"active"}}, "newaccount", + transaction_helpers::emplace_message(trx, config::EosContractName, vector{{creator,"active"}}, "newaccount", types::newaccount{creator, newaccount, owner_auth, active_auth, recovery_auth, deposit}); @@ -308,7 +308,7 @@ int send_command (const vector &cmd_line) SignedTransaction trx; trx.scope = { config::EosContractName, account }; - trx.emplaceMessage( config::EosContractName, vector{{account,"active"}}, + transaction_helpers::emplace_message(trx, config::EosContractName, vector{{account,"active"}}, "setcode", handler ); std::cout << fc::json::to_pretty_string( push_transaction(trx) ) << std::endl; @@ -322,11 +322,11 @@ int send_command (const vector &cmd_line) SignedTransaction trx; trx.scope = sort_names({sender,recipient}); - trx.emplaceMessage(config::EosContractName, vector{{sender,"active"}}, "transfer", + transaction_helpers::emplace_message(trx, config::EosContractName, vector{{sender,"active"}}, "transfer", types::transfer{sender, recipient, amount}); auto info = get_info(); trx.expiration = info.head_block_time + 100; //chain.head_block_time() + 100; - trx.set_reference_block(info.head_block_id); + transaction_helpers::set_reference_block(trx, info.head_block_id); std::cout << fc::json::to_pretty_string( call( push_txn_func, trx )) << std::endl; } diff --git a/tests/api_tests/api_tests.cpp b/tests/api_tests/api_tests.cpp index 9b1cac9d6894a7728f58964428c08f657c5c6fa4..2a552c5833f8bc4ca9981a3313574fa7ccc9b50a 100644 --- a/tests/api_tests/api_tests.cpp +++ b/tests/api_tests/api_tests.cpp @@ -86,10 +86,10 @@ uint32_t CallFunction( testing_blockchain& chain, const types::Message& msg, con std::copy(data.begin(), data.end(), std::back_inserter(dest)); //std::cout << "MANDO: " << msg.code << " " << msg.type << std::endl; - trx.emplaceMessage(msg); + transaction_helpers::emplace_message(trx, msg); trx.expiration = chain.head_block_time() + expiration++; - trx.set_reference_block(chain.head_block_id()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); //idump((trx)); chain.push_transaction(trx); @@ -177,9 +177,9 @@ void send_set_code_message(testing_blockchain& chain, types::setcode& handler, A trx.messages.resize(1); trx.messages[0].authorization = {{account,"active"}}; trx.messages[0].code = config::EosContractName; - trx.setMessage(0, "setcode", handler); + transaction_helpers::set_message(trx, 0, "setcode", handler); trx.expiration = chain.head_block_time() + 100; - trx.set_reference_block(chain.head_block_id()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); chain.push_transaction(trx); chain.produce_blocks(1); } diff --git a/tests/common/macro_support.hpp b/tests/common/macro_support.hpp index 1c43d7c7c9c26a984306c66694f0f0ebb6bd8860..bb468956a9fb263b4c8cc25f49a323b96949b2f8 100644 --- a/tests/common/macro_support.hpp +++ b/tests/common/macro_support.hpp @@ -46,11 +46,11 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names({ #creator, config::EosContractName }); \ - trx.emplaceMessage(config::EosContractName, \ + transaction_helpers::emplace_message(trx, config::EosContractName, \ vector{{#creator, "active"}}, \ "newaccount", types::newaccount{#creator, #name, owner, active, recovery, deposit}); \ trx.expiration = chain.head_block_time() + 100; \ - trx.set_reference_block(chain.head_block_id()); \ + transaction_helpers::set_reference_block(trx, chain.head_block_id()); \ chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Created account " << #name); \ } @@ -78,11 +78,11 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = {#account}; \ - trx.emplaceMessage(config::EosContractName, \ + transaction_helpers::emplace_message(trx, config::EosContractName, \ vector{{#account,"active"}}, \ "updateauth", types::updateauth{#account, authname, parentname, auth}); \ trx.expiration = chain.head_block_time() + 100; \ - trx.set_reference_block(chain.head_block_id()); \ + transaction_helpers::set_reference_block(trx, chain.head_block_id()); \ chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Set " << #account << "'s " << authname << " authority."); \ } @@ -91,11 +91,11 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = {#account}; \ - trx.emplaceMessage(config::EosContractName, \ + transaction_helpers::emplace_message(trx, config::EosContractName, \ vector{{#account,"active"}}, \ "deleteauth", types::deleteauth{#account, authname}); \ trx.expiration = chain.head_block_time() + 100; \ - trx.set_reference_block(chain.head_block_id()); \ + transaction_helpers::set_reference_block(trx, chain.head_block_id()); \ chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Deleted " << #account << "'s " << authname << " authority."); \ } @@ -104,11 +104,11 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = {#account}; \ - trx.emplaceMessage(config::EosContractName, \ + transaction_helpers::emplace_message(trx, config::EosContractName, \ vector{{#account,"active"}}, \ "linkauth", types::linkauth{#account, #codeacct, messagetype, authname}); \ trx.expiration = chain.head_block_time() + 100; \ - trx.set_reference_block(chain.head_block_id()); \ + transaction_helpers::set_reference_block(trx, chain.head_block_id()); \ chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Link " << #codeacct << "::" << messagetype << " to " << #account \ << "'s " << authname << " authority."); \ @@ -119,11 +119,11 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = {#account}; \ - trx.emplaceMessage(config::EosContractName, \ + transaction_helpers::emplace_message(trx, config::EosContractName, \ vector{{#account,"active"}}, \ "unlinkauth", types::unlinkauth{#account, #codeacct, messagetype}); \ trx.expiration = chain.head_block_time() + 100; \ - trx.set_reference_block(chain.head_block_id()); \ + transaction_helpers::set_reference_block(trx, chain.head_block_id()); \ chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Unlink " << #codeacct << "::" << messagetype << " from " << #account); \ } @@ -133,11 +133,11 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names({#sender,#recipient}); \ - trx.emplaceMessage(config::EosContractName, \ + transaction_helpers::emplace_message(trx, config::EosContractName, \ vector{ {#sender,"active"} }, \ "transfer", types::transfer{#sender, #recipient, Amount.amount}); \ trx.expiration = chain.head_block_time() + 100; \ - trx.set_reference_block(chain.head_block_id()); \ + transaction_helpers::set_reference_block(trx, chain.head_block_id()); \ chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Transfered " << Amount << " from " << #sender << " to " << #recipient); \ } @@ -147,10 +147,10 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( { #sender, #recipient, config::EosContractName } ); \ - trx.emplaceMessage(config::EosContractName, vector{{#sender, "active"}}, \ + transaction_helpers::emplace_message(trx, config::EosContractName, vector{{#sender, "active"}}, \ "lock", types::lock{#sender, #recipient, amount}); \ trx.expiration = chain.head_block_time() + 100; \ - trx.set_reference_block(chain.head_block_id()); \ + transaction_helpers::set_reference_block(trx, chain.head_block_id()); \ chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Staked " << amount << " to " << #recipient); \ } @@ -160,11 +160,11 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( { config::EosContractName } ); \ - trx.emplaceMessage(config::EosContractName, \ + transaction_helpers::emplace_message(trx, config::EosContractName, \ vector{{#account, "active"}}, \ "unlock", types::unlock{#account, amount}); \ trx.expiration = chain.head_block_time() + 100; \ - trx.set_reference_block(chain.head_block_id()); \ + transaction_helpers::set_reference_block(trx, chain.head_block_id()); \ chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Begin unstake " << amount << " to " << #account); \ } @@ -173,10 +173,10 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( { config::EosContractName, #account } ); \ - trx.emplaceMessage(config::EosContractName, vector{{#account, "active"}}, \ + transaction_helpers::emplace_message(trx, config::EosContractName, vector{{#account, "active"}}, \ "claim", types::claim{#account, amount}); \ trx.expiration = chain.head_block_time() + 100; \ - trx.set_reference_block(chain.head_block_id()); \ + transaction_helpers::set_reference_block(trx, chain.head_block_id()); \ chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Finish unstake " << amount << " to " << #account); \ } @@ -185,11 +185,11 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( {#owner, config::EosContractName} ); \ - trx.emplaceMessage(config::EosContractName, \ + transaction_helpers::emplace_message(trx, config::EosContractName, \ vector{{#owner, "active"}}, \ "setproducer", types::setproducer{#owner, key, cfg}); \ trx.expiration = chain.head_block_time() + 100; \ - trx.set_reference_block(chain.head_block_id()); \ + transaction_helpers::set_reference_block(trx, chain.head_block_id()); \ chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Create producer " << #owner); \ } @@ -202,11 +202,11 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( {#voter, config::EosContractName} ); \ - trx.emplaceMessage(config::EosContractName, \ + transaction_helpers::emplace_message(trx, config::EosContractName, \ vector{{#voter, "active"}}, \ "okproducer", types::okproducer{#voter, #producer, approved? 1 : 0}); \ trx.expiration = chain.head_block_time() + 100; \ - trx.set_reference_block(chain.head_block_id()); \ + transaction_helpers::set_reference_block(trx, chain.head_block_id()); \ chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Set producer approval from " << #voter << " for " << #producer << " to " << approved); \ } @@ -215,11 +215,11 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( {owner, config::EosContractName} ); \ - trx.emplaceMessage(config::EosContractName, \ + transaction_helpers::emplace_message(trx, config::EosContractName, \ vector{{owner, "active"}}, \ "setproducer", types::setproducer{owner, key, cfg}); \ trx.expiration = chain.head_block_time() + 100; \ - trx.set_reference_block(chain.head_block_id()); \ + transaction_helpers::set_reference_block(trx, chain.head_block_id()); \ chain.push_transaction(trx); \ BOOST_TEST_CHECKPOINT("Update producer " << owner); \ } diff --git a/tests/common/testing_macros.hpp b/tests/common/testing_macros.hpp index 2c1cd368a0b3c7d85bcf7e944f7acc25afddd59b..969d8ba90e57043c8735dc8d7e1c06fabaad2d4c 100644 --- a/tests/common/testing_macros.hpp +++ b/tests/common/testing_macros.hpp @@ -284,13 +284,13 @@ { \ eos::chain::SignedTransaction trx; \ if (std::string(#stakeholder) != std::string(#proxy)) \ - trx.emplaceMessage(config::EosContractName, \ + transaction_helpers::emplace_message(trx, config::EosContractName, \ vector{ {#stakeholder,"active"} }, "setproxy", types::setproxy{#stakeholder, #proxy}); \ else \ - trx.emplaceMessage(config::EosContractName, \ + transaction_helpers::emplace_message(trx, 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()); \ + transaction_helpers::set_reference_block(trx, 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 12e56137c8f29ad54f506370af5b9257d96e90f9..a41f472bcdfb9d9121f39999a54174ffd6c493d2 100644 --- a/tests/slow_tests/slow_tests.cpp +++ b/tests/slow_tests/slow_tests.cpp @@ -51,6 +51,7 @@ using namespace eos; using namespace chain; + struct OrderID { AccountName name; uint64_t number = 0; @@ -297,9 +298,9 @@ void SetCode( testing_blockchain& chain, AccountName account, const char* wast ) trx.messages.resize(1); trx.messages[0].code = config::EosContractName; trx.messages[0].authorization.emplace_back(types::AccountPermission{account,"active"}); - trx.setMessage(0, "setcode", handler); + transaction_helpers::set_message(trx, 0, "setcode", handler); trx.expiration = chain.head_block_time() + 100; - trx.set_reference_block(chain.head_block_id()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); chain.push_transaction(trx); chain.produce_blocks(1); } @@ -308,12 +309,12 @@ 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.emplaceMessage("currency", + transaction_helpers::emplace_message(trx, "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()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); idump((trx)); chain.push_transaction(trx); } @@ -321,11 +322,11 @@ 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.emplaceMessage("currency", + transaction_helpers::emplace_message(trx, "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()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); chain.push_transaction(trx); } @@ -351,9 +352,9 @@ BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture) trx.messages.resize(1); trx.messages[0].code = config::EosContractName; trx.messages[0].authorization.emplace_back(types::AccountPermission{"currency","active"}); - trx.setMessage(0, "setcode", handler); + transaction_helpers::set_message(trx, 0, "setcode", handler); trx.expiration = chain.head_block_time() + 100; - trx.set_reference_block(chain.head_block_id()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); chain.push_transaction(trx); chain.produce_blocks(1); } @@ -364,11 +365,11 @@ BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture) { eos::chain::SignedTransaction trx; trx.scope = sort_names({"currency","inita"}); - trx.emplaceMessage("currency", + transaction_helpers::emplace_message(trx, "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()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); //idump((trx)); chain.push_transaction(trx); } @@ -402,12 +403,12 @@ void SellCurrency( testing_blockchain& chain, AccountName seller, AccountName ex eos::chain::SignedTransaction trx; trx.scope = sort_names({"exchange"}); - trx.emplaceMessage("exchange", + transaction_helpers::emplace_message(trx, "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()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); chain.push_transaction(trx); } @@ -420,12 +421,12 @@ void BuyCurrency( testing_blockchain& chain, AccountName buyer, AccountName exch eos::chain::SignedTransaction trx; trx.scope = sort_names({"exchange"}); - trx.emplaceMessage("exchange", + transaction_helpers::emplace_message(trx, "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()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); chain.push_transaction(trx); } @@ -1116,9 +1117,9 @@ R"( trx.messages.resize(1); trx.messages[0].code = config::EosContractName; trx.messages[0].authorization.emplace_back(types::AccountPermission{"simplecoin","active"}); - trx.setMessage(0, "setcode", handler); + transaction_helpers::set_message(trx, 0, "setcode", handler); trx.expiration = chain.head_block_time() + 100; - trx.set_reference_block(chain.head_block_id()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); try { chain.push_transaction(trx); BOOST_FAIL("floating point instructions should be rejected"); @@ -1153,9 +1154,9 @@ BOOST_FIXTURE_TEST_CASE(create_script_w_loop, testing_fixture) trx.messages.resize(1); trx.messages[0].code = config::EosContractName; trx.messages[0].authorization.emplace_back(types::AccountPermission{"currency","active"}); - trx.setMessage(0, "setcode", handler); + transaction_helpers::set_message(trx, 0, "setcode", handler); trx.expiration = chain.head_block_time() + 100; - trx.set_reference_block(chain.head_block_id()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); chain.push_transaction(trx); chain.produce_blocks(1); } @@ -1164,11 +1165,11 @@ BOOST_FIXTURE_TEST_CASE(create_script_w_loop, testing_fixture) { eos::chain::SignedTransaction trx; trx.scope = sort_names({"currency","inita"}); - trx.emplaceMessage("currency", + transaction_helpers::emplace_message(trx, "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()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); try { wlog("starting long transaction"); diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 92447edbcdd2d814a90ce059cc14d49619090286..597602060e031849f400f9f6a42b344fafa49f0a 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -48,6 +48,7 @@ using namespace chain; + BOOST_AUTO_TEST_SUITE(block_tests) @@ -145,11 +146,11 @@ BOOST_FIXTURE_TEST_CASE(trx_variant, testing_fixture) { eos::chain::ProcessedTransaction trx; trx.scope = sort_names({from,to}); - trx.emplaceMessage("eos", + transaction_helpers::emplace_message(trx, "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()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); auto original = fc::raw::pack( trx ); auto var = chain.transaction_to_variant( trx ); @@ -178,10 +179,10 @@ BOOST_FIXTURE_TEST_CASE(irrelevant_auth, testing_fixture) { ProcessedTransaction trx; trx.scope = sort_names({"joe", "inita"}); - trx.emplaceMessage(config::EosContractName, vector{{"inita", "active"}}, + transaction_helpers::emplace_message(trx, config::EosContractName, vector{{"inita", "active"}}, "transfer", types::transfer{"inita", "joe", 50}); trx.expiration = chain.head_block_time() + 100; - trx.set_reference_block(chain.head_block_id()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); chain.push_transaction(trx, chain_controller::skip_transaction_signatures); chain.clear_pending(); diff --git a/tests/tests/native_contract_tests.cpp b/tests/tests/native_contract_tests.cpp index 4f3d17a70e48c9811014c739f87c46ab7e14202c..bdca681cb7bab6c07b63b02c199c3c1dccfcd26b 100644 --- a/tests/tests/native_contract_tests.cpp +++ b/tests/tests/native_contract_tests.cpp @@ -23,6 +23,7 @@ using namespace eos; using namespace chain; + BOOST_AUTO_TEST_SUITE(native_contract_tests) //Simple test of account creation @@ -91,7 +92,7 @@ BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture) SignedTransaction trx; BOOST_REQUIRE_THROW(chain.push_transaction(trx), transaction_exception); // no messages trx.messages.resize(1); - trx.set_reference_block(chain.head_block_id()); + transaction_helpers::set_reference_block(trx, chain.head_block_id()); trx.expiration = chain.head_block_time() + 100; trx.scope = sort_names( {"inita", "initb"} ); @@ -104,7 +105,7 @@ BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture) trx.messages[0].type = "transfer"; trx.messages[0].authorization = {{"inita", "active"}}; trx.messages[0].code = config::EosContractName; - trx.setMessage(0, "transfer", trans); + transaction_helpers::set_message(trx, 0, "transfer", trans); chain.push_transaction(trx, chain_controller::skip_transaction_signatures); BOOST_CHECK_EQUAL(chain.get_liquid_balance("inita"), Asset(100000 - 100));