From 4a881dad1d4b4dad0f12afe619cebffdf9d9dc7e Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Fri, 11 Aug 2017 09:50:39 -0500 Subject: [PATCH 01/11] Merge apply_staked_claim into apply_eos_claim The apply_staked_claim function appears to be defunct, a leftover of a bygone era. It's logic, however, was not included in the still-active apply_eos_claim, and that is a problem. Move that missing logic into apply_eos_claim, pretty it up a bit, and get rid of the vestigial apply_staked_claim. --- libraries/native_contract/eos_contract.cpp | 26 +++++-------------- .../staked_balance_objects.hpp | 9 +++++++ .../staked_balance_objects.cpp | 6 +++++ 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/libraries/native_contract/eos_contract.cpp b/libraries/native_contract/eos_contract.cpp index 4c5d337bd91..232243c5ed2 100644 --- a/libraries/native_contract/eos_contract.cpp +++ b/libraries/native_contract/eos_contract.cpp @@ -93,21 +93,6 @@ void apply_eos_newaccount(apply_context& context) { }); } -/** - * This method is called when the claim message is delivered to @staked - * staked::validate_staked_claim must require that @eos be notified. - * - * This method trusts that staked::precondition_staked_claim verifies that claim.amount is - * available. - */ -void apply_staked_claim(apply_context& context) { - auto claim = context.msg.as(); - const auto& claimant = context.db.get(claim.account); - context.mutable_db.modify(claimant, [&claim](BalanceObject& a) { - a.balance += claim.amount; - }); -} - /** * * @ingroup native_eos @@ -230,16 +215,19 @@ void apply_eos_claim(apply_context& context) { EOS_ASSERT(balance != nullptr, message_precondition_exception, "Could not find staked balance for ${name}", ("name", claim.account)); auto balanceReleaseTime = balance->lastUnstakingTime + config::StakedBalanceCooldownSeconds; - auto now = context.db.get(dynamic_global_property_object::id_type()).time; + auto now = context.controller.head_block_time(); EOS_ASSERT(now >= balanceReleaseTime, message_precondition_exception, "Cannot claim balance until ${releaseDate}", ("releaseDate", balanceReleaseTime)); EOS_ASSERT(balance->unstakingBalance >= claim.amount, message_precondition_exception, "Cannot claim ${claimAmount} as only ${available} is available for claim", ("claimAmount", claim.amount)("available", balance->unstakingBalance)); - context.mutable_db.modify(context.db.get(claim.account), - [&claim](StakedBalanceObject& sbo) { - sbo.unstakingBalance -= claim.amount; + const auto& stakedBalance = context.db.get(claim.account); + stakedBalance.finishUnstakingTokens(claim.amount, context.mutable_db); + + const auto& liquidBalance = context.db.get(claim.account); + context.mutable_db.modify(liquidBalance, [&claim](BalanceObject& a) { + a.balance += claim.amount; }); } diff --git a/libraries/native_contract/include/eos/native_contract/staked_balance_objects.hpp b/libraries/native_contract/include/eos/native_contract/staked_balance_objects.hpp index 9e7775eedd5..447b953e8d5 100644 --- a/libraries/native_contract/include/eos/native_contract/staked_balance_objects.hpp +++ b/libraries/native_contract/include/eos/native_contract/staked_balance_objects.hpp @@ -74,6 +74,15 @@ class StakedBalanceObject : public chainbase::object()) // This account votes for producers directly; update their stakes From 5021140a191bcaecc32df21fa443c0faaf986df4 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Fri, 11 Aug 2017 10:28:31 -0500 Subject: [PATCH 02/11] adding slow_test to travis build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 7733e2828c2..7897f82e968 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,3 +26,4 @@ script: - WASM_LLVM_CONFIG=$TRAVIS_BUILD_DIR/ext/wasm-compiler/bin/llvm-config ext/cmake-3.9.0-Linux-x86_64/bin/cmake -G Ninja -DCMAKE_CXX_COMPILER=clang++-4.0 -DCMAKE_C_COMPILER=clang-4.0 -DBOOST_ROOT=$TRAVIS_BUILD_DIR/ext -DSecp256k1_ROOT_DIR=$TRAVIS_BUILD_DIR/ext - ninja -j4 - tests/chain_test + - tests/slow_test From 345c409ab253d6c74529f8358a66e6e8cab20e78 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Fri, 11 Aug 2017 10:33:36 -0500 Subject: [PATCH 03/11] Fixed scope for STAKE and removed unneeded permissions --- tests/common/macro_support.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/common/macro_support.hpp b/tests/common/macro_support.hpp index bfec2829676..ad3fa430e26 100644 --- a/tests/common/macro_support.hpp +++ b/tests/common/macro_support.hpp @@ -146,8 +146,8 @@ inline std::vector sort_names( std::vector&& names ) { #define STAKE4(chain, sender, recipient, amount) \ { \ eos::chain::SignedTransaction trx; \ - trx.scope = sort_names( { #sender, #recipient } ); \ - trx.emplaceMessage(config::EosContractName, vector{{#sender, "active"}}, \ + trx.scope = sort_names( { #sender, #recipient, "eos" } ); \ + 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()); \ @@ -161,7 +161,7 @@ inline std::vector sort_names( std::vector&& names ) { eos::chain::SignedTransaction trx; \ trx.scope = sort_names( { "eos" } ); \ trx.emplaceMessage(config::EosContractName, \ - vector{{#account, "active"}}, \ + vector{}, \ "unlock", types::unlock{#account, amount}); \ trx.expiration = chain.head_block_time() + 100; \ trx.set_reference_block(chain.head_block_id()); \ @@ -173,7 +173,7 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( { "eos", #account } ); \ - trx.emplaceMessage(config::EosContractName, vector{{#account, "active"}}, \ + 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()); \ From 1051b6df7a9fe2ffd71ca9b4caf083008ab3b01f Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Fri, 11 Aug 2017 10:36:22 -0500 Subject: [PATCH 04/11] Fixed tests based off of new requirement that account be created in and in a block before it is used. --- tests/slow_tests/slow_tests.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/slow_tests/slow_tests.cpp b/tests/slow_tests/slow_tests.cpp index f64a26e25ff..1bf464862f6 100644 --- a/tests/slow_tests/slow_tests.cpp +++ b/tests/slow_tests/slow_tests.cpp @@ -171,7 +171,10 @@ BOOST_FIXTURE_TEST_CASE(multiindex, testing_fixture) BOOST_FIXTURE_TEST_CASE(tapos_wrap, testing_fixture) { try { Make_Blockchain(chain) + Make_Account(chain, system); Make_Account(chain, acct); + chain.produce_blocks(1); + Transfer_Asset(chain, inita, system, Asset(1000) ); Transfer_Asset(chain, system, acct, Asset(5)); Stake_Asset(chain, acct, Asset(5).amount); wlog("Hang on, this will take a minute..."); @@ -185,6 +188,9 @@ BOOST_FIXTURE_TEST_CASE(stake, testing_fixture) // Create account sam with default balance of 100, and stake 55 of it Make_Blockchain(chain); Make_Account(chain, sam); + + chain.produce_blocks(); + Transfer_Asset(chain, inita, sam, Asset(55) ); // MakeAccount should start sam out with some staked balance @@ -426,6 +432,7 @@ BOOST_FIXTURE_TEST_CASE(create_exchange, testing_fixture) { try { Make_Blockchain(chain); chain.produce_blocks(2); + Make_Account(chain, system); Make_Account(chain, currency); Make_Account(chain, exchange); chain.produce_blocks(1); From 848071c22663a58de90748e263a7fba6bc483ded Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Fri, 11 Aug 2017 13:39:33 -0500 Subject: [PATCH 05/11] Fixed account name use of _ and fixed wast string. --- contracts/test_api/test_message.cpp | 4 ++-- tests/api_tests/api_tests.cpp | 37 ++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/contracts/test_api/test_message.cpp b/contracts/test_api/test_message.cpp index 2eaaa63f4f1..79040537593 100644 --- a/contracts/test_api/test_message.cpp +++ b/contracts/test_api/test_message.cpp @@ -7,7 +7,7 @@ unsigned int test_message::read_message() { char buffer[100]; uint32_t total = 0; - WASM_ASSERT( currentCode() == N(test_api), "currentCode() == N(test_api)" ); + WASM_ASSERT( currentCode() == N(testapi), "currentCode() == N(testapi)" ); WASM_ASSERT(messageSize() == sizeof(dummy_message), "messageSize() == sizeof(dummy_message)"); @@ -42,7 +42,7 @@ unsigned int test_message::read_message_to_64k() { } unsigned int test_message::require_notice() { - if( currentCode() == N(test_api) ) { + if( currentCode() == N(testapi) ) { eos::requireNotice( N(acc1) ); eos::requireNotice( N(acc2) ); eos::requireNotice( N(acc1), N(acc2) ); diff --git a/tests/api_tests/api_tests.cpp b/tests/api_tests/api_tests.cpp index 0db81f4609b..8f547303a35 100644 --- a/tests/api_tests/api_tests.cpp +++ b/tests/api_tests/api_tests.cpp @@ -99,7 +99,7 @@ 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& data, const vector& scope = {N(test_api)}) { +uint32_t CallFunction( testing_blockchain& chain, const types::Message& msg, const vector& data, const vector& scope = {N(testapi)}) { static int expiration = 1; eos::chain::SignedTransaction trx; trx.scope = scope; @@ -148,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", AUTH, TYPE}, DATA) -#define CALL_TEST_FUNCTION_SCOPE(TYPE, AUTH, DATA, SCOPE) CallFunction(chain, Message{"test_api", AUTH, TYPE}, DATA, SCOPE) +#define CALL_TEST_FUNCTION(TYPE, AUTH, DATA) CallFunction(chain, Message{"testapi", AUTH, TYPE}, DATA) +#define CALL_TEST_FUNCTION_SCOPE(TYPE, AUTH, DATA, SCOPE) CallFunction(chain, Message{"testapi", AUTH, TYPE}, DATA, SCOPE) bool is_access_violation(fc::unhandled_exception const & e) { try { @@ -192,17 +192,28 @@ uint32_t last_fnc_err = 0; std::STREAM.rdbuf(oldbuf); \ } +void send_set_code_message(testing_blockchain& chain, types::setcode& handler, AccountName account) +{ + eos::chain::SignedTransaction trx; + handler.account = account; + trx.scope = { account }; + trx.messages.resize(1); + trx.messages[0].code = config::EosContractName; + trx.setMessage(0, "setcode", handler); + trx.expiration = chain.head_block_time() + 100; + trx.set_reference_block(chain.head_block_id()); + chain.push_transaction(trx); + chain.produce_blocks(1); +} BOOST_FIXTURE_TEST_CASE(test_all, testing_fixture) { try { - //std::string test_api_wast_str(test_api_wast); - auto test_api_wast_str = readFile2("/home/matu/Documents/Dev/eos/contracts/test_api/test_api.wast"); - //std::cout << test_api_wast << std::endl; + auto wasm = assemble_wast( test_api_wast ); Make_Blockchain(chain); chain.produce_blocks(2); - Make_Account(chain, test_api); + Make_Account(chain, testapi); Make_Account(chain, another); Make_Account(chain, acc1); Make_Account(chain, acc2); @@ -211,9 +222,13 @@ BOOST_FIXTURE_TEST_CASE(test_all, testing_fixture) chain.produce_blocks(1); //Set test code - SetCode(chain, "test_api", test_api_wast_str.c_str()); - SetCode(chain, "acc1", test_api_wast_str.c_str()); - SetCode(chain, "acc2", test_api_wast_str.c_str()); + types::setcode handler; + handler.code.resize(wasm.size()); + memcpy( handler.code.data(), wasm.data(), wasm.size() ); + + send_set_code_message(chain, handler, "testapi"); + send_set_code_message(chain, handler, "acc1"); + send_set_code_message(chain, handler, "acc2"); //Test types BOOST_CHECK_MESSAGE( CALL_TEST_FUNCTION( TEST_METHOD("test_types", "types_size"), {}, {} ) == WASM_TEST_PASS, "test_types::types_size()" ); @@ -341,7 +356,7 @@ BOOST_FIXTURE_TEST_CASE(test_all, testing_fixture) BOOST_CHECK_MESSAGE( CALL_TEST_FUNCTION( TEST_METHOD("test_db", "key_i64_general"), {}, {} ) == WASM_TEST_PASS, "test_db::key_i64_general()" ); BOOST_CHECK_EQUAL( std::distance(idx.begin(), idx.end()) , 4); - auto itr = idx.lower_bound( boost::make_tuple( N(test_api), N(test_api), N(test_table)) ); + auto itr = idx.lower_bound( boost::make_tuple( N(testapi), N(testapi), N(test_table)) ); BOOST_CHECK_EQUAL((uint64_t)itr->key, N(alice)); ++itr; BOOST_CHECK_EQUAL((uint64_t)itr->key, N(bob)); ++itr; From 97103de195bccf62132a946dafe92e3b868aee59 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Fri, 11 Aug 2017 13:41:23 -0500 Subject: [PATCH 06/11] Added api_test to travis build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 7897f82e968..a8ca40bd08d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,3 +27,4 @@ script: - ninja -j4 - tests/chain_test - tests/slow_test + - tests/api_test From 5d74854212cb253a40aa82fcf9dc100e7c2053d9 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Fri, 11 Aug 2017 14:17:42 -0500 Subject: [PATCH 07/11] Replacing eos string with config::EosContractName. --- tests/common/macro_support.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/common/macro_support.hpp b/tests/common/macro_support.hpp index ad3fa430e26..1ab9223e840 100644 --- a/tests/common/macro_support.hpp +++ b/tests/common/macro_support.hpp @@ -45,7 +45,7 @@ inline std::vector sort_names( std::vector&& names ) { #define MKACCT_IMPL(chain, name, creator, active, owner, recovery, deposit) \ { \ eos::chain::SignedTransaction trx; \ - trx.scope = sort_names({ #creator, "eos" }); \ + trx.scope = sort_names({ #creator, config::EosContractName }); \ trx.emplaceMessage(config::EosContractName, \ vector{{#creator, "active"}}, \ "newaccount", types::newaccount{#creator, #name, owner, active, recovery, deposit}); \ @@ -146,7 +146,7 @@ inline std::vector sort_names( std::vector&& names ) { #define STAKE4(chain, sender, recipient, amount) \ { \ eos::chain::SignedTransaction trx; \ - trx.scope = sort_names( { #sender, #recipient, "eos" } ); \ + trx.scope = sort_names( { #sender, #recipient, config::EosContractName } ); \ trx.emplaceMessage(config::EosContractName, vector{}, \ "lock", types::lock{#sender, #recipient, amount}); \ trx.expiration = chain.head_block_time() + 100; \ @@ -159,7 +159,7 @@ inline std::vector sort_names( std::vector&& names ) { #define BEGIN_UNSTAKE3(chain, account, amount) \ { \ eos::chain::SignedTransaction trx; \ - trx.scope = sort_names( { "eos" } ); \ + trx.scope = sort_names( { config::EosContractName } ); \ trx.emplaceMessage(config::EosContractName, \ vector{}, \ "unlock", types::unlock{#account, amount}); \ @@ -172,7 +172,7 @@ inline std::vector sort_names( std::vector&& names ) { #define FINISH_UNSTAKE3(chain, account, amount) \ { \ eos::chain::SignedTransaction trx; \ - trx.scope = sort_names( { "eos", #account } ); \ + trx.scope = sort_names( { config::EosContractName, #account } ); \ trx.emplaceMessage(config::EosContractName, vector{}, \ "claim", types::claim{#account, amount}); \ trx.expiration = chain.head_block_time() + 100; \ @@ -184,7 +184,7 @@ inline std::vector sort_names( std::vector&& names ) { #define MKPDCR4(chain, owner, key, cfg) \ { \ eos::chain::SignedTransaction trx; \ - trx.scope = sort_names( {#owner, "eos"} ); \ + trx.scope = sort_names( {#owner, config::EosContractName} ); \ trx.emplaceMessage(config::EosContractName, \ vector{{#owner, "active"}}, \ "setproducer", types::setproducer{#owner, key, cfg}); \ @@ -201,7 +201,7 @@ inline std::vector sort_names( std::vector&& names ) { #define APPDCR4(chain, voter, producer, approved) \ { \ eos::chain::SignedTransaction trx; \ - trx.scope = sort_names( {#voter, "eos"} ); \ + trx.scope = sort_names( {#voter, config::EosContractName} ); \ trx.emplaceMessage(config::EosContractName, \ vector{{#voter, "active"}}, \ "okproducer", types::okproducer{#voter, #producer, approved? 1 : 0}); \ @@ -214,7 +214,7 @@ inline std::vector sort_names( std::vector&& names ) { #define UPPDCR4(chain, owner, key, cfg) \ { \ eos::chain::SignedTransaction trx; \ - trx.scope = sort_names( {owner, "eos"} ); \ + trx.scope = sort_names( {owner, config::EosContractName} ); \ trx.emplaceMessage(config::EosContractName, \ vector{{owner, "active"}}, \ "setproducer", types::setproducer{owner, key, cfg}); \ From 0817c411d06a424316dd8a40d7f9a51414861a50 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Tue, 15 Aug 2017 11:49:47 -0500 Subject: [PATCH 08/11] Fix peer review error --- tests/api_tests/api_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api_tests/api_tests.cpp b/tests/api_tests/api_tests.cpp index 8f547303a35..72b3bae2409 100644 --- a/tests/api_tests/api_tests.cpp +++ b/tests/api_tests/api_tests.cpp @@ -224,7 +224,7 @@ BOOST_FIXTURE_TEST_CASE(test_all, testing_fixture) //Set test code types::setcode handler; handler.code.resize(wasm.size()); - memcpy( handler.code.data(), wasm.data(), wasm.size() ); + handler.code.assign(wasm.begin(), wasm.end()); send_set_code_message(chain, handler, "testapi"); send_set_code_message(chain, handler, "acc1"); From 0289d48a4cfe03b04482905bc0cc65b6afc91768 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Tue, 15 Aug 2017 11:50:26 -0500 Subject: [PATCH 09/11] Fixes to get create_exchange to actually run and pass. --- tests/slow_tests/slow_tests.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/slow_tests/slow_tests.cpp b/tests/slow_tests/slow_tests.cpp index 1bf464862f6..9b169af5e2b 100644 --- a/tests/slow_tests/slow_tests.cpp +++ b/tests/slow_tests/slow_tests.cpp @@ -428,7 +428,6 @@ void BuyCurrency( testing_blockchain& chain, AccountName buyer, AccountName exch } BOOST_FIXTURE_TEST_CASE(create_exchange, testing_fixture) { - try { try { Make_Blockchain(chain); chain.produce_blocks(2); @@ -446,8 +445,6 @@ BOOST_FIXTURE_TEST_CASE(create_exchange, testing_fixture) { TransferCurrency( chain, "currency", "inita", 1000 ); TransferCurrency( chain, "currency", "initb", 2000 ); - Transfer_Asset(chain, system, inita, Asset(50)); - Transfer_Asset(chain, system, initb, Asset(50)); chain.produce_blocks(1); ilog( "transfering funds to the exchange" ); TransferCurrency( chain, "inita", "exchange", 1000 ); @@ -471,23 +468,21 @@ BOOST_FIXTURE_TEST_CASE(create_exchange, testing_fixture) { chain.produce_blocks(1); wlog( "start buy and sell" ); - SellCurrency( chain, "initb", "exchange", 1, 100, .5 ); - SellCurrency( chain, "initb", "exchange", 1, 100, .75 ); - SellCurrency( chain, "initb", "exchange", 1, 100, .85 ); + uint64_t order_num = 1; + SellCurrency( chain, "initb", "exchange", order_num++, 100, .5 ); + SellCurrency( chain, "initb", "exchange", order_num++, 100, .75 ); + SellCurrency( chain, "initb", "exchange", order_num++, 100, .85 ); //BOOST_REQUIRE_THROW( SellCurrency( chain, "initb", "exchange", 1, 100, .5 ), fc::exception ); // order id already exists //SellCurrency( chain, "initb", "exchange", 2, 100, .75 ); // BuyCurrency( chain, "initb", "exchange", 1, 50, .25 ); - BuyCurrency( chain, "initb", "exchange", 1, 50, .5 ); + BuyCurrency( chain, "initb", "exchange", order_num++, 50, .5 ); //BOOST_REQUIRE_THROW( BuyCurrency( chain, "initb", "exchange", 1, 50, .25 ), fc::exception ); // order id already exists /// this should buy 5 from initb order 2 at a price of .75 //BuyCurrency( chain, "initb", "exchange", 2, 50, .8 ); } FC_LOG_AND_RETHROW() - }catch(...) { - elog( "unexpected exception" ); - } } //Test account script float rejection From adc8fd009d325c1cee9bf3ddeae4b07522f26614 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Tue, 15 Aug 2017 15:23:29 -0500 Subject: [PATCH 10/11] Requiring the correct authorities --- libraries/native_contract/eos_contract.cpp | 6 ++++++ tests/api_tests/api_tests.cpp | 1 + tests/common/macro_support.hpp | 6 +++--- tests/slow_tests/slow_tests.cpp | 4 ++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libraries/native_contract/eos_contract.cpp b/libraries/native_contract/eos_contract.cpp index 232243c5ed2..c975f91bac9 100644 --- a/libraries/native_contract/eos_contract.cpp +++ b/libraries/native_contract/eos_contract.cpp @@ -149,6 +149,8 @@ void apply_eos_lock(apply_context& context) { context.require_recipient(lock.to); context.require_recipient(lock.from); + context.require_authorization(lock.from); + const auto& locker = context.db.get(lock.from); EOS_ASSERT( locker.balance >= lock.amount, message_precondition_exception, @@ -165,6 +167,8 @@ void apply_eos_lock(apply_context& context) { void apply_eos_unlock(apply_context& context) { auto unlock = context.msg.as(); + context.require_authorization(unlock.account); + EOS_ASSERT(unlock.amount >= 0, message_validate_exception, "Unlock amount cannot be negative"); const auto& balance = context.db.get(unlock.account); @@ -211,6 +215,8 @@ void apply_eos_claim(apply_context& context) { EOS_ASSERT(claim.amount > 0, message_validate_exception, "Claim amount must be positive"); + context.require_authorization(claim.account); + auto balance = context.db.find(claim.account); EOS_ASSERT(balance != nullptr, message_precondition_exception, "Could not find staked balance for ${name}", ("name", claim.account)); diff --git a/tests/api_tests/api_tests.cpp b/tests/api_tests/api_tests.cpp index 72b3bae2409..92249797d30 100644 --- a/tests/api_tests/api_tests.cpp +++ b/tests/api_tests/api_tests.cpp @@ -199,6 +199,7 @@ void send_set_code_message(testing_blockchain& chain, types::setcode& handler, A trx.scope = { account }; 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); trx.expiration = chain.head_block_time() + 100; trx.set_reference_block(chain.head_block_id()); diff --git a/tests/common/macro_support.hpp b/tests/common/macro_support.hpp index 1ab9223e840..1c43d7c7c9c 100644 --- a/tests/common/macro_support.hpp +++ b/tests/common/macro_support.hpp @@ -147,7 +147,7 @@ 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{}, \ + trx.emplaceMessage(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()); \ @@ -161,7 +161,7 @@ inline std::vector sort_names( std::vector&& names ) { eos::chain::SignedTransaction trx; \ trx.scope = sort_names( { config::EosContractName } ); \ trx.emplaceMessage(config::EosContractName, \ - vector{}, \ + vector{{#account, "active"}}, \ "unlock", types::unlock{#account, amount}); \ trx.expiration = chain.head_block_time() + 100; \ trx.set_reference_block(chain.head_block_id()); \ @@ -173,7 +173,7 @@ inline std::vector sort_names( std::vector&& names ) { { \ eos::chain::SignedTransaction trx; \ trx.scope = sort_names( { config::EosContractName, #account } ); \ - trx.emplaceMessage(config::EosContractName, vector{}, \ + trx.emplaceMessage(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()); \ diff --git a/tests/slow_tests/slow_tests.cpp b/tests/slow_tests/slow_tests.cpp index 9b169af5e2b..12e56137c8f 100644 --- a/tests/slow_tests/slow_tests.cpp +++ b/tests/slow_tests/slow_tests.cpp @@ -296,6 +296,7 @@ void SetCode( testing_blockchain& chain, AccountName account, const char* wast ) trx.scope = {account}; 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); trx.expiration = chain.head_block_time() + 100; trx.set_reference_block(chain.head_block_id()); @@ -349,6 +350,7 @@ BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture) trx.scope = {"currency"}; 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); trx.expiration = chain.head_block_time() + 100; trx.set_reference_block(chain.head_block_id()); @@ -1113,6 +1115,7 @@ R"( trx.scope = {"simplecoin"}; 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); trx.expiration = chain.head_block_time() + 100; trx.set_reference_block(chain.head_block_id()); @@ -1149,6 +1152,7 @@ BOOST_FIXTURE_TEST_CASE(create_script_w_loop, testing_fixture) trx.scope = {"currency"}; 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); trx.expiration = chain.head_block_time() + 100; trx.set_reference_block(chain.head_block_id()); From 15487cbbf3b38ca0669cf39862f9ea9031ab1325 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Tue, 15 Aug 2017 16:01:28 -0500 Subject: [PATCH 11/11] Increasing the allotted time for contracts to complete. --- libraries/chain/wasm_interface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/wasm_interface.cpp b/libraries/chain/wasm_interface.cpp index 70a395bbb82..a8f6485df34 100644 --- a/libraries/chain/wasm_interface.cpp +++ b/libraries/chain/wasm_interface.cpp @@ -21,9 +21,9 @@ namespace eos { namespace chain { } #ifdef NDEBUG - const int CHECKTIME_LIMIT = 2000; + const int CHECKTIME_LIMIT = 3000; #else - const int CHECKTIME_LIMIT = 12000; + const int CHECKTIME_LIMIT = 18000; #endif DEFINE_INTRINSIC_FUNCTION0(env,checktime,checktime,none) {