From 4a176cb96868b7ce95abb90e5f65bbb24974ba2b Mon Sep 17 00:00:00 2001 From: Quoc Le Date: Tue, 9 Jul 2024 09:25:10 +0000 Subject: [PATCH] move create_slim_account to eosio contract --- libraries/chain/controller.cpp | 9 +- libraries/chain/eosio_contract.cpp | 55 +++++++++ libraries/chain/eosio_contract_abi.cpp | 9 ++ .../include/eosio/chain/contract_types.hpp | 15 +++ .../eos-vm-oc/intrinsic_mapping.hpp | 3 +- .../eosio/chain/webassembly/interface.hpp | 11 -- libraries/chain/webassembly/privileged.cpp | 69 ----------- .../chain/webassembly/runtimes/eos-vm.cpp | 1 - .../testing/include/eosio/testing/tester.hpp | 5 + libraries/testing/tester.cpp | 33 +++++ unittests/abi_tests.cpp | 68 +++++++++++ unittests/delay_tests.cpp | 34 ++++++ unittests/dry_run_trx_tests.cpp | 20 +++ unittests/protocol_feature_tests.cpp | 34 ++---- unittests/read_only_trx_tests.cpp | 15 +++ unittests/slim_account_tests.cpp | 50 +------- unittests/test-contracts/CMakeLists.txt | 1 - .../create_slim_account_test/CMakeLists.txt | 6 - .../create_slim_account_test.abi | 114 ------------------ .../create_slim_account_test.cpp | 8 -- .../create_slim_account_test.hpp | 74 ------------ .../create_slim_account_test.wasm | Bin 10180 -> 0 bytes unittests/test_contracts.hpp.in | 1 - 23 files changed, 268 insertions(+), 367 deletions(-) delete mode 100644 unittests/test-contracts/create_slim_account_test/CMakeLists.txt delete mode 100644 unittests/test-contracts/create_slim_account_test/create_slim_account_test.abi delete mode 100644 unittests/test-contracts/create_slim_account_test/create_slim_account_test.cpp delete mode 100644 unittests/test-contracts/create_slim_account_test/create_slim_account_test.hpp delete mode 100755 unittests/test-contracts/create_slim_account_test/create_slim_account_test.wasm diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index fffca0fd5f..ee7ba34720 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -347,7 +347,6 @@ struct controller_impl { set_activation_handler(); set_activation_handler(); set_activation_handler(); - set_activation_handler(); self.irreversible_block.connect([this](const block_signal_params& t) { const auto& [ block, id] = t; @@ -360,6 +359,7 @@ struct controller_impl { &BOOST_PP_CAT(apply_, BOOST_PP_CAT(contract, BOOST_PP_CAT(_,action) ) ) ) SET_APP_HANDLER( eosio, eosio, newaccount ); + SET_APP_HANDLER( eosio, eosio, newslimacc ); SET_APP_HANDLER( eosio, eosio, setcode ); SET_APP_HANDLER( eosio, eosio, setabi ); SET_APP_HANDLER( eosio, eosio, updateauth ); @@ -3935,13 +3935,6 @@ void controller_impl::on_activation -void controller_impl::on_activation() { - db.modify( db.get(), [&]( auto& ps ) { - add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "create_slim_account" ); - } ); -} - /// End of protocol feature activation handlers } } /// eosio::chain diff --git a/libraries/chain/eosio_contract.cpp b/libraries/chain/eosio_contract.cpp index dee097993d..b050271b50 100644 --- a/libraries/chain/eosio_contract.cpp +++ b/libraries/chain/eosio_contract.cpp @@ -127,6 +127,61 @@ void apply_eosio_newaccount(apply_context& context) { } FC_CAPTURE_AND_RETHROW( (create) ) } +/** + * This method is called assuming precondition_system_newslimacc succeeds + */ +void apply_eosio_newslimacc(apply_context& context) { + EOS_ASSERT( !context.trx_context.is_read_only(), action_validate_exception, "newslimacc not allowed in read-only transaction" ); + if(!context.control.is_builtin_activated( builtin_protocol_feature_t::slim_account )) { + EOS_THROW( protocol_feature_validation_exception, + "Unsupported protocol_feature_t: ${type}", + ("type", static_cast(builtin_protocol_feature_t::slim_account)) + ); + } + auto create = context.get_action().data_as(); + try { + context.require_authorization(create.creator); + auto& authorization = context.control.get_mutable_authorization_manager(); + EOS_ASSERT( validate(create.active), action_validate_exception, "Invalid active authority"); + auto& db = context.db; + + auto name_str = name(create.name).to_string(); + EOS_ASSERT( !create.name.empty(), action_validate_exception, "account name cannot be empty" ); + EOS_ASSERT( name_str.size() <= 12, action_validate_exception, "account names can only be 12 chars long" ); + + // system account only can be created by newaccount + EOS_ASSERT( name_str.find( "eosio." ) != 0, action_validate_exception, + "only newaccount action can create account with name start with 'eosio.'" ); + + auto existing_account = db.find(create.name); + EOS_ASSERT(existing_account == nullptr, account_name_exists_exception, + "Cannot create account named ${name}, as that name is already taken", + ("name", create.name)); + + db.create([&](auto& a) { + a.name = create.name; + a.creation_date = context.control.pending_block_time(); + }); + + for (const auto& auth : { create.active }) { + validate_authority_precondition( context, auth ); + } + + const auto& active_permission = authorization.create_permission( create.name, config::active_name, 0, + std::move(create.active), context.trx_context.is_transient() ); + int64_t ram_delta = config::overhead_per_account_ram_bytes; + ram_delta -= config::billable_size_v; + ram_delta += config::billable_size_v; + ram_delta += active_permission.auth.get_billable_size(); + context.control.get_mutable_resource_limits_manager().initialize_account(create.name, context.trx_context.is_transient()); + + if (auto dm_logger = context.control.get_deep_mind_logger(context.trx_context.is_transient())) { + dm_logger->on_ram_trace(RAM_EVENT_ID("${name}", ("name", create.name)), "account", "add", "newslimacc"); + } + + context.add_ram_usage(create.name, ram_delta); +} FC_CAPTURE_AND_RETHROW( (create) ) } + void apply_eosio_setcode(apply_context& context) { EOS_ASSERT( !context.trx_context.is_read_only(), action_validate_exception, "setcode not allowed in read-only transaction" ); auto& db = context.db; diff --git a/libraries/chain/eosio_contract_abi.cpp b/libraries/chain/eosio_contract_abi.cpp index 24a93682c1..8ca1ec4966 100644 --- a/libraries/chain/eosio_contract_abi.cpp +++ b/libraries/chain/eosio_contract_abi.cpp @@ -144,6 +144,14 @@ abi_def eosio_contract_abi(const abi_def& eosio_system_abi) } }); + eos_abi.structs.emplace_back( struct_def { + "newslimacc", "", { + {"creator", "account_name"}, + {"name", "account_name"}, + {"active", "authority"}, + } + }); + eos_abi.structs.emplace_back( struct_def { "setcode", "", { {"account", "account_name"}, @@ -215,6 +223,7 @@ abi_def eosio_contract_abi(const abi_def& eosio_system_abi) // TODO add ricardian contracts eos_abi.actions.push_back( action_def{name("newaccount"), "newaccount",""} ); + eos_abi.actions.push_back( action_def{name("newslimacc"), "newslimacc",""} ); eos_abi.actions.push_back( action_def{name("setcode"), "setcode",""} ); eos_abi.actions.push_back( action_def{name("setabi"), "setabi",""} ); eos_abi.actions.push_back( action_def{name("updateauth"), "updateauth",""} ); diff --git a/libraries/chain/include/eosio/chain/contract_types.hpp b/libraries/chain/include/eosio/chain/contract_types.hpp index 54c0f8212b..8f4788119e 100644 --- a/libraries/chain/include/eosio/chain/contract_types.hpp +++ b/libraries/chain/include/eosio/chain/contract_types.hpp @@ -22,6 +22,20 @@ struct newaccount { } }; +struct newslimacc { + account_name creator; + account_name name; + authority active; + + static account_name get_account() { + return config::system_account_name; + } + + static action_name get_name() { + return "newslimacc"_n; + } +}; + struct setcode { account_name account; uint8_t vmtype = 0; @@ -155,6 +169,7 @@ struct onerror { } } /// namespace eosio::chain FC_REFLECT( eosio::chain::newaccount , (creator)(name)(owner)(active) ) +FC_REFLECT( eosio::chain::newslimacc , (creator)(name)(active) ) FC_REFLECT( eosio::chain::setcode , (account)(vmtype)(vmversion)(code) ) FC_REFLECT( eosio::chain::setabi , (account)(abi) ) FC_REFLECT( eosio::chain::updateauth , (account)(permission)(parent)(auth) ) diff --git a/libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/intrinsic_mapping.hpp b/libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/intrinsic_mapping.hpp index 729047e19e..8577ec9958 100644 --- a/libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/intrinsic_mapping.hpp +++ b/libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/intrinsic_mapping.hpp @@ -277,8 +277,7 @@ inline constexpr auto get_intrinsic_table() { "env.bls_g2_map", "env.bls_fp_mod", "env.bls_fp_mul", - "env.bls_fp_exp", - "env.create_slim_account" + "env.bls_fp_exp" ); } inline constexpr std::size_t find_intrinsic_index(std::string_view hf) { diff --git a/libraries/chain/include/eosio/chain/webassembly/interface.hpp b/libraries/chain/include/eosio/chain/webassembly/interface.hpp index a9f52bf5e5..7a5123f3ca 100644 --- a/libraries/chain/include/eosio/chain/webassembly/interface.hpp +++ b/libraries/chain/include/eosio/chain/webassembly/interface.hpp @@ -249,17 +249,6 @@ namespace webassembly { */ void set_privileged(account_name account, bool is_priv); - /** - * create a slim account. - * - * @ingroup privileged - * - * @param account - account creator. - * @param name - new slim account name. - * @param pubkey - publickey. - */ - void create_slim_account(account_name creator, account_name name, legacy_span packed_authority); - // softfloat api float _eosio_f32_add(float, float) const; float _eosio_f32_sub(float, float) const; diff --git a/libraries/chain/webassembly/privileged.cpp b/libraries/chain/webassembly/privileged.cpp index c8f86db1e6..c7be046bab 100644 --- a/libraries/chain/webassembly/privileged.cpp +++ b/libraries/chain/webassembly/privileged.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include @@ -225,72 +224,4 @@ namespace eosio { namespace chain { namespace webassembly { ma.set_privileged( is_priv ); }); } - void interface::create_slim_account(account_name creator, account_name name, legacy_span packed_authority){ - EOS_ASSERT( !context.trx_context.is_read_only(), wasm_execution_error, "create_slim_account not allowed in read-only transaction" ); - authority active_auth; - fc::datastream pubds ( packed_authority.data(), packed_authority.size() ); - - fc::raw::unpack( pubds, active_auth ); - - auto& authorization = context.control.get_mutable_authorization_manager(); - - EOS_ASSERT( validate(active_auth), action_validate_exception, "Invalid active authority"); - - auto& db = context.db; - - auto name_str = name.to_string(); - - EOS_ASSERT( !name.empty(), action_validate_exception, "account name cannot be empty" ); - EOS_ASSERT( name_str.size() <= 12, action_validate_exception, "account names can only be 12 chars long" ); - - // system account only can be created by newaccount - EOS_ASSERT( name_str.find( "eosio." ) != 0, action_validate_exception, - "only newaccount action can create account with name start with 'eosio.'" ); - - auto existing_account = db.find(name); - EOS_ASSERT(existing_account == nullptr, account_name_exists_exception, - "Cannot create account named ${name}, as that name is already taken", - ("name", name)); - - db.create([&](auto& a) { - a.name = name; - a.creation_date = context.control.pending_block_time(); - }); - - for (const auto& a : active_auth.accounts) { - auto* acct = context.db.find(a.permission.actor); - EOS_ASSERT( acct != nullptr, action_validate_exception, - "account '${account}' does not exist", - ("account", a.permission.actor) - ); - if( a.permission.permission == config::active_name ) - continue; // account was already checked to exist, so its active permissions should exist - - if( a.permission.permission == config::eosio_code_name ) // virtual eosio.code permission does not really exist but is allowed - continue; - - try { - context.control.get_authorization_manager().get_permission({a.permission.actor, a.permission.permission}); - } catch( const permission_query_exception& ) { - EOS_THROW( action_validate_exception, - "permission '${perm}' does not exist", - ("perm", a.permission) - ); - } - } - - const auto& active_permission = authorization.create_permission( name, config::active_name, 0, - std::move(active_auth), context.trx_context.is_transient() ); - int64_t ram_delta = config::overhead_per_account_ram_bytes; - ram_delta -= config::billable_size_v; - ram_delta += config::billable_size_v; - ram_delta += active_permission.auth.get_billable_size(); - context.control.get_mutable_resource_limits_manager().initialize_account(name, context.trx_context.is_transient()); - - if (auto dm_logger = context.control.get_deep_mind_logger(context.trx_context.is_transient())) { - dm_logger->on_ram_trace(RAM_EVENT_ID("${name}", ("name", name)), "account", "add", "newslimacc"); - } - - context.add_ram_usage(name, ram_delta); - } }}} // ns eosio::chain::webassembly diff --git a/libraries/chain/webassembly/runtimes/eos-vm.cpp b/libraries/chain/webassembly/runtimes/eos-vm.cpp index c945b0938b..025cb19515 100644 --- a/libraries/chain/webassembly/runtimes/eos-vm.cpp +++ b/libraries/chain/webassembly/runtimes/eos-vm.cpp @@ -366,7 +366,6 @@ REGISTER_LEGACY_HOST_FUNCTION(get_blockchain_parameters_packed, privileged_check REGISTER_LEGACY_HOST_FUNCTION(set_blockchain_parameters_packed, privileged_check); REGISTER_HOST_FUNCTION(is_privileged, privileged_check); REGISTER_HOST_FUNCTION(set_privileged, privileged_check); -REGISTER_LEGACY_HOST_FUNCTION(create_slim_account, privileged_check); // softfloat api REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_add); diff --git a/libraries/testing/include/eosio/testing/tester.hpp b/libraries/testing/include/eosio/testing/tester.hpp index a29a024ccf..880492cdf2 100644 --- a/libraries/testing/include/eosio/testing/tester.hpp +++ b/libraries/testing/include/eosio/testing/tester.hpp @@ -267,6 +267,11 @@ namespace eosio { namespace testing { bool multisig = false, bool include_code = true ); + transaction_trace_ptr create_slim_account( account_name name, + account_name creator = config::system_account_name, + bool multisig = false, + bool include_code = true + ); transaction_trace_ptr push_reqauth( account_name from, const vector& auths, const vector& keys ); transaction_trace_ptr push_reqauth(account_name from, string role, bool multi_sig = false); // use when just want any old non-context free action diff --git a/libraries/testing/tester.cpp b/libraries/testing/tester.cpp index d7f4b571c4..903d2b8d93 100644 --- a/libraries/testing/tester.cpp +++ b/libraries/testing/tester.cpp @@ -598,6 +598,39 @@ namespace eosio { namespace testing { return push_transaction( trx ); } + transaction_trace_ptr base_tester::create_slim_account( account_name a, account_name creator, bool multisig, bool include_code ) { + signed_transaction trx; + set_transaction_headers(trx); + + authority active_auth( get_public_key( a, "active" ) ); + + auto sort_permissions = []( authority& auth ) { + std::sort( auth.accounts.begin(), auth.accounts.end(), + []( const permission_level_weight& lhs, const permission_level_weight& rhs ) { + return lhs.permission < rhs.permission; + } + ); + }; + + if( include_code ) { + FC_ASSERT( active_auth.threshold <= std::numeric_limits::max(), "threshold is too high" ); + active_auth.accounts.push_back( permission_level_weight{ {a, config::eosio_code_name}, + static_cast(active_auth.threshold) } ); + sort_permissions(active_auth); + } + + trx.actions.emplace_back( vector{{creator,config::active_name}}, + newslimacc{ + .creator = creator, + .name = a, + .active = active_auth, + }); + + set_transaction_headers(trx); + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); + return push_transaction( trx ); + } + transaction_trace_ptr base_tester::push_transaction( packed_transaction& trx, fc::time_point deadline, uint32_t billed_cpu_time_us diff --git a/unittests/abi_tests.cpp b/unittests/abi_tests.cpp index d3a936fc46..2c609a3fd7 100644 --- a/unittests/abi_tests.cpp +++ b/unittests/abi_tests.cpp @@ -1115,6 +1115,74 @@ BOOST_AUTO_TEST_CASE(newaccount_test) } FC_LOG_AND_RETHROW() } +BOOST_AUTO_TEST_CASE(newslimacc_test) +{ try { + + abi_serializer abis(eosio_contract_abi(abi_def()), abi_serializer::create_yield_function( max_serialization_time )); + + BOOST_CHECK(true); + const char* test_data = R"=====( + { + "creator" : "newacct.crtr", + "name" : "newacct.name", + "active" : { + "threshold" : 2146483145, + "keys" : [ {"key" : "EOS65rXebLhtk2aTTzP4e9x1AQZs7c5NNXJp89W8R3HyaA6Zyd4im", "weight" : 57005}, + {"key" : "EOS5eVr9TVnqwnUBNwf9kwMTbrHvX5aPyyEG97dz2b2TNeqWRzbJf", "weight" : 57605} ], + "accounts" : [ {"permission" : {"actor" : "prm.acct1", "permission" : "prm.prm1"}, "weight" : 53005 }, + {"permission" : {"actor" : "prm.acct2", "permission" : "prm.prm2"}, "weight" : 53405 }], + "waits" : [] + } } + )====="; + + auto var = fc::json::from_string(test_data); + + auto newslimacct = var.as(); + BOOST_TEST(name("newacct.crtr") == newslimacct.creator); + BOOST_TEST(name("newacct.name") == newslimacct.name); + + BOOST_TEST(2146483145u == newslimacct.active.threshold); + + BOOST_TEST_REQUIRE(2u == newslimacct.active.keys.size()); + BOOST_TEST("EOS65rXebLhtk2aTTzP4e9x1AQZs7c5NNXJp89W8R3HyaA6Zyd4im" == newslimacct.active.keys[0].key.to_string({})); + BOOST_TEST(57005u == newslimacct.active.keys[0].weight); + BOOST_TEST("EOS5eVr9TVnqwnUBNwf9kwMTbrHvX5aPyyEG97dz2b2TNeqWRzbJf" == newslimacct.active.keys[1].key.to_string({})); + BOOST_TEST(57605u == newslimacct.active.keys[1].weight); + + BOOST_TEST_REQUIRE(2u == newslimacct.active.accounts.size()); + BOOST_TEST(name("prm.acct1") == newslimacct.active.accounts[0].permission.actor); + BOOST_TEST(name("prm.prm1") == newslimacct.active.accounts[0].permission.permission); + BOOST_TEST(53005u == newslimacct.active.accounts[0].weight); + BOOST_TEST(name("prm.acct2") == newslimacct.active.accounts[1].permission.actor); + BOOST_TEST(name("prm.prm2") == newslimacct.active.accounts[1].permission.permission); + BOOST_TEST(53405u == newslimacct.active.accounts[1].weight); + + + auto var2 = verify_byte_round_trip_conversion( abis, "newslimacc", var ); + auto newslimacc2 = var2.as(); + BOOST_TEST(newslimacct.creator == newslimacc2.creator); + BOOST_TEST(newslimacct.name == newslimacc2.name); + + BOOST_TEST(newslimacct.active.threshold == newslimacc2.active.threshold); + + BOOST_TEST_REQUIRE(newslimacct.active.keys.size() == newslimacc2.active.keys.size()); + BOOST_TEST(newslimacct.active.keys[0].key == newslimacc2.active.keys[0].key); + BOOST_TEST(newslimacct.active.keys[0].weight == newslimacc2.active.keys[0].weight); + BOOST_TEST(newslimacct.active.keys[1].key == newslimacc2.active.keys[1].key); + BOOST_TEST(newslimacct.active.keys[1].weight == newslimacc2.active.keys[1].weight); + + BOOST_TEST_REQUIRE(newslimacct.active.accounts.size() == newslimacc2.active.accounts.size()); + BOOST_TEST(newslimacct.active.accounts[0].permission.actor == newslimacc2.active.accounts[0].permission.actor); + BOOST_TEST(newslimacct.active.accounts[0].permission.permission == newslimacc2.active.accounts[0].permission.permission); + BOOST_TEST(newslimacct.active.accounts[0].weight == newslimacc2.active.accounts[0].weight); + BOOST_TEST(newslimacct.active.accounts[1].permission.actor == newslimacc2.active.accounts[1].permission.actor); + BOOST_TEST(newslimacct.active.accounts[1].permission.permission == newslimacc2.active.accounts[1].permission.permission); + BOOST_TEST(newslimacct.active.accounts[1].weight == newslimacc2.active.accounts[1].weight); + + + verify_type_round_trip_conversion( abis, "newslimacc", var); + +} FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_CASE(setcode_test) { try { diff --git a/unittests/delay_tests.cpp b/unittests/delay_tests.cpp index 2a98ba3db9..74e1c72ce5 100644 --- a/unittests/delay_tests.cpp +++ b/unittests/delay_tests.cpp @@ -210,6 +210,40 @@ BOOST_FIXTURE_TEST_CASE( delay_error_create_account, validating_tester_no_disabl } FC_LOG_AND_RETHROW() } +BOOST_FIXTURE_TEST_CASE( delay_error_create_slim_account, validating_tester_no_disable_deferred_trx) { try { + + produce_blocks(2); + signed_transaction trx; + + account_name a = "newco"_n; + account_name creator = config::system_account_name; + + trx.actions.emplace_back( vector{{creator,config::active_name}}, + newslimacc{ + .creator = "bad"_n, /// a does not exist, this should error when execute + .name = a, + .active = authority( get_public_key( a, "active" ) ) + }); + set_transaction_headers(trx); + trx.delay_sec = 3; + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); + + ilog( fc::json::to_pretty_string(trx) ); + auto trace = push_transaction( trx ); + edump((*trace)); + + produce_blocks(6); + + auto scheduled_trxs = get_scheduled_transactions(); + BOOST_REQUIRE_EQUAL(scheduled_trxs.size(), 1u); + + auto billed_cpu_time_us = control->get_global_properties().configuration.min_transaction_cpu_usage; + auto dtrace = control->push_scheduled_transaction(scheduled_trxs.front(), fc::time_point::maximum(), fc::microseconds::maximum(), billed_cpu_time_us, true); + BOOST_REQUIRE_EQUAL(dtrace->except.has_value(), true); + BOOST_REQUIRE_EQUAL(dtrace->except->code(), missing_auth_exception::code_value); + +} FC_LOG_AND_RETHROW() } + // test link to permission with delay directly on it BOOST_AUTO_TEST_CASE( link_delay_direct_test ) { try { validating_tester chain; diff --git a/unittests/dry_run_trx_tests.cpp b/unittests/dry_run_trx_tests.cpp index 920b910868..0a5e2fc191 100644 --- a/unittests/dry_run_trx_tests.cpp +++ b/unittests/dry_run_trx_tests.cpp @@ -119,6 +119,26 @@ BOOST_FIXTURE_TEST_CASE(newaccount_test, dry_run_trx_tester) { try { BOOST_CHECK_THROW(control->get_account("alice"_n), fc::exception); // not actually created } FC_LOG_AND_RETHROW() } +BOOST_FIXTURE_TEST_CASE(newslimacc_test, dry_run_trx_tester) { try { + produce_blocks( 1 ); + + action act = { + vector{{config::system_account_name,config::active_name}}, + newslimacc{ + .creator = config::system_account_name, + .name = "alice"_n, + .active = authority( get_public_key( "alice"_n, "active" ) ) + } + }; + + send_action(act, false); // should not throw + send_action(act, false); // should not throw + send_action(act, true); // should not throw + BOOST_CHECK_THROW(control->get_account("alice"_n), fc::exception); // not actually created + produce_blocks( 1 ); + BOOST_CHECK_THROW(control->get_account("alice"_n), fc::exception); // not actually created +} FC_LOG_AND_RETHROW() } + BOOST_FIXTURE_TEST_CASE(setcode_test, dry_run_trx_tester) { try { produce_blocks( 1 ); diff --git a/unittests/protocol_feature_tests.cpp b/unittests/protocol_feature_tests.cpp index e19e37140e..07d4226f3a 100644 --- a/unittests/protocol_feature_tests.cpp +++ b/unittests/protocol_feature_tests.cpp @@ -2277,36 +2277,16 @@ BOOST_AUTO_TEST_CASE( slim_account_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::slim_account); BOOST_REQUIRE(d); - - BOOST_CHECK_EXCEPTION( c.set_code( config::system_account_name, test_contracts::create_slim_account_test_wasm() ), - wasm_exception, - fc_exception_message_is( "env.create_slim_account unresolveable" ) ); + BOOST_CHECK( ! c.control->is_builtin_activated( builtin_protocol_feature_t::slim_account ) ); + const auto alice_account = account_name("alice"); + BOOST_CHECK_EXCEPTION( c.create_slim_account( alice_account ), + protocol_feature_validation_exception, + fc_exception_message_is( "Unsupported protocol_feature_t: " + std::to_string(static_cast(builtin_protocol_feature_t::slim_account))) ); c.preactivate_protocol_features( {*d} ); - const auto bob_account = account_name("bob"); - c.create_accounts( {bob_account} ); c.produce_block(); - - // ensure it now resolves - c.set_code( config::system_account_name, test_contracts::create_slim_account_test_wasm() ); - c.set_abi( config::system_account_name, test_contracts::create_slim_account_test_abi().data()); - c.push_action( config::system_account_name, "testcreate"_n, bob_account, fc::mutable_variant_object() - ("creator", bob_account.to_string()) - ("account", "alice") - ("active_auth", authority(get_public_key(name("alice"), "active"))) - ); - - const auto test_account = account_name("test"); - c.create_accounts( {test_account} ); - c.produce_block(); - // shoudl throw - c.set_code( test_account, test_contracts::create_slim_account_test_wasm() ); - c.set_abi( test_account, test_contracts::create_slim_account_test_abi().data()); - BOOST_CHECK_THROW(c.push_action( test_account, "testcreate"_n, bob_account, fc::mutable_variant_object() - ("creator", bob_account.to_string()) - ("account", "hello") - ("active_auth", authority(get_public_key(name("hello"), "active"))) - ), unaccessible_api); + BOOST_CHECK( c.control->is_builtin_activated( builtin_protocol_feature_t::slim_account ) ); + BOOST_CHECK_NO_THROW( c.create_slim_account( alice_account ) ); } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_SUITE_END() diff --git a/unittests/read_only_trx_tests.cpp b/unittests/read_only_trx_tests.cpp index 123c4ed134..6e899f5c87 100644 --- a/unittests/read_only_trx_tests.cpp +++ b/unittests/read_only_trx_tests.cpp @@ -88,6 +88,21 @@ BOOST_FIXTURE_TEST_CASE(newaccount_test, read_only_trx_tester) { try { BOOST_CHECK_THROW( send_action(act), action_validate_exception ); } FC_LOG_AND_RETHROW() } +BOOST_FIXTURE_TEST_CASE(newslimacc_test, read_only_trx_tester) { try { + produce_blocks( 1 ); + + action act = { + {}, + newslimacc{ + .creator = config::system_account_name, + .name = "alice"_n, + .active = authority( get_public_key( "alice"_n, "active" ) ) + } + }; + + BOOST_CHECK_THROW( send_action(act), action_validate_exception ); +} FC_LOG_AND_RETHROW() } + BOOST_FIXTURE_TEST_CASE(setcode_test, read_only_trx_tester) { try { produce_blocks( 1 ); diff --git a/unittests/slim_account_tests.cpp b/unittests/slim_account_tests.cpp index d96fd13bfc..e8195aa454 100644 --- a/unittests/slim_account_tests.cpp +++ b/unittests/slim_account_tests.cpp @@ -18,49 +18,9 @@ using namespace eosio; using namespace eosio::chain; using namespace eosio::testing; -class slim_account_tester : public validating_tester -{ -public: - slim_account_tester() : validating_tester() { - } - - void setup() - { - set_code( config::system_account_name, test_contracts::create_slim_account_test_wasm() ); - set_abi( config::system_account_name, test_contracts::create_slim_account_test_abi().data()); - - produce_block(); - } - - transaction_trace_ptr create_slim_account(account_name a, name creator = config::system_account_name, bool include_code = true ) - { - authority active_auth( get_public_key( a, "active" ) ); - - auto sort_permissions = []( authority& auth ) { - std::sort( auth.accounts.begin(), auth.accounts.end(), - []( const permission_level_weight& lhs, const permission_level_weight& rhs ) { - return lhs.permission < rhs.permission; - } - ); - }; - - if( include_code ) { - FC_ASSERT( active_auth.threshold <= std::numeric_limits::max(), "threshold is too high" ); - active_auth.accounts.push_back( permission_level_weight{ {a, config::eosio_code_name}, - static_cast(active_auth.threshold) } ); - sort_permissions(active_auth); - } - return push_action( config::system_account_name, "testcreate"_n, creator, fc::mutable_variant_object() - ("creator", creator.to_string()) - ("account", a) - ("active_auth", active_auth) - ); - } -}; - BOOST_AUTO_TEST_SUITE(slim_account_tests) -BOOST_FIXTURE_TEST_CASE(newslimacc_test, slim_account_tester) +BOOST_FIXTURE_TEST_CASE(newslimacc_test, validating_tester) { try { @@ -125,7 +85,7 @@ BOOST_FIXTURE_TEST_CASE(newslimacc_test, slim_account_tester) } FC_LOG_AND_RETHROW() } -BOOST_FIXTURE_TEST_CASE(updateaut_test, slim_account_tester) +BOOST_FIXTURE_TEST_CASE(updateaut_test, validating_tester) { try { @@ -266,7 +226,7 @@ BOOST_FIXTURE_TEST_CASE(updateaut_test, slim_account_tester) FC_LOG_AND_RETHROW() } -BOOST_FIXTURE_TEST_CASE(deleteauth_test, slim_account_tester) +BOOST_FIXTURE_TEST_CASE(deleteauth_test, validating_tester) { const auto& tester_account = "tester"_n; @@ -379,7 +339,7 @@ BOOST_FIXTURE_TEST_CASE(deleteauth_test, slim_account_tester) BOOST_REQUIRE_EQUAL(asset::from_string("4.0000 CUR"), liquid_balance); } -BOOST_FIXTURE_TEST_CASE(setcode_test, slim_account_tester) +BOOST_FIXTURE_TEST_CASE(setcode_test, validating_tester) { try { @@ -425,7 +385,7 @@ BOOST_FIXTURE_TEST_CASE(setcode_test, slim_account_tester) FC_LOG_AND_RETHROW() } -BOOST_FIXTURE_TEST_CASE(setabi_test, slim_account_tester) +BOOST_FIXTURE_TEST_CASE(setabi_test, validating_tester) { try { diff --git a/unittests/test-contracts/CMakeLists.txt b/unittests/test-contracts/CMakeLists.txt index 089ec6e9c8..a62d82809c 100644 --- a/unittests/test-contracts/CMakeLists.txt +++ b/unittests/test-contracts/CMakeLists.txt @@ -45,4 +45,3 @@ add_subdirectory( crypto_primitives_test ) add_subdirectory( bls_primitives_test ) add_subdirectory( get_block_num_test ) add_subdirectory( nested_container_multi_index ) -add_subdirectory( create_slim_account_test ) \ No newline at end of file diff --git a/unittests/test-contracts/create_slim_account_test/CMakeLists.txt b/unittests/test-contracts/create_slim_account_test/CMakeLists.txt deleted file mode 100644 index 58d9958058..0000000000 --- a/unittests/test-contracts/create_slim_account_test/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -if( EOSIO_COMPILE_TEST_CONTRACTS ) - add_contract( create_slim_account_test create_slim_account_test create_slim_account_test.cpp ) -else() - configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/create_slim_account_test.wasm ${CMAKE_CURRENT_BINARY_DIR}/create_slim_account_test.wasm COPYONLY ) - configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/create_slim_account_test.abi ${CMAKE_CURRENT_BINARY_DIR}/create_slim_account_test.abi COPYONLY ) -endif() diff --git a/unittests/test-contracts/create_slim_account_test/create_slim_account_test.abi b/unittests/test-contracts/create_slim_account_test/create_slim_account_test.abi deleted file mode 100644 index d6b8930e07..0000000000 --- a/unittests/test-contracts/create_slim_account_test/create_slim_account_test.abi +++ /dev/null @@ -1,114 +0,0 @@ -{ - "____comment": "This file was generated with eosio-abigen. DO NOT EDIT ", - "version": "eosio::abi/1.2", - "types": [], - "structs": [ - { - "name": "authority", - "base": "", - "fields": [ - { - "name": "threshold", - "type": "uint32" - }, - { - "name": "keys", - "type": "key_weight[]" - }, - { - "name": "accounts", - "type": "permission_level_weight[]" - }, - { - "name": "waits", - "type": "wait_weight[]" - } - ] - }, - { - "name": "key_weight", - "base": "", - "fields": [ - { - "name": "key", - "type": "public_key" - }, - { - "name": "weight", - "type": "uint16" - } - ] - }, - { - "name": "permission_level", - "base": "", - "fields": [ - { - "name": "actor", - "type": "name" - }, - { - "name": "permission", - "type": "name" - } - ] - }, - { - "name": "permission_level_weight", - "base": "", - "fields": [ - { - "name": "permission", - "type": "permission_level" - }, - { - "name": "weight", - "type": "uint16" - } - ] - }, - { - "name": "testcreate", - "base": "", - "fields": [ - { - "name": "creator", - "type": "name" - }, - { - "name": "account", - "type": "name" - }, - { - "name": "active_auth", - "type": "authority" - } - ] - }, - { - "name": "wait_weight", - "base": "", - "fields": [ - { - "name": "wait_sec", - "type": "uint32" - }, - { - "name": "weight", - "type": "uint16" - } - ] - } - ], - "actions": [ - { - "name": "testcreate", - "type": "testcreate", - "ricardian_contract": "" - } - ], - "tables": [], - "ricardian_clauses": [], - "variants": [], - "action_results": [] -} \ No newline at end of file diff --git a/unittests/test-contracts/create_slim_account_test/create_slim_account_test.cpp b/unittests/test-contracts/create_slim_account_test/create_slim_account_test.cpp deleted file mode 100644 index 8cbdca81e9..0000000000 --- a/unittests/test-contracts/create_slim_account_test/create_slim_account_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "create_slim_account_test.hpp" - -using namespace eosio; -[[eosio::action]] -void create_slim_account_test::testcreate(eosio::name creator, eosio::name account, authority active_auth ) { - auto packed_authority = pack(active_auth); - eosio::internal_use_do_not_use::create_slim_account(creator.value , account.value , packed_authority.data(), packed_authority.size()); -} diff --git a/unittests/test-contracts/create_slim_account_test/create_slim_account_test.hpp b/unittests/test-contracts/create_slim_account_test/create_slim_account_test.hpp deleted file mode 100644 index 8bbce84056..0000000000 --- a/unittests/test-contracts/create_slim_account_test/create_slim_account_test.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -#include -#include -#include - -using eosio::ignore; -using eosio::name; -using eosio::permission_level; -using eosio::public_key; - -namespace eosio { - namespace internal_use_do_not_use { - extern "C" { - __attribute__((eosio_wasm_import)) - void create_slim_account(uint64_t creator, uint64_t account, const void* data, uint32_t len); - } - } -} - -struct permission_level_weight -{ - permission_level permission; - uint16_t weight; - - // explicit serialization macro is not necessary, used here only to improve compilation time - EOSLIB_SERIALIZE(permission_level_weight, (permission)(weight)) -}; - -/** - * Weighted key. - * - * A weighted key is defined by a public key and an associated weight. - */ -struct key_weight -{ - eosio::public_key key; - uint16_t weight; - - // explicit serialization macro is not necessary, used here only to improve compilation time - EOSLIB_SERIALIZE(key_weight, (key)(weight)) -}; - -/** - * Wait weight. - * - * A wait weight is defined by a number of seconds to wait for and a weight. - */ -struct wait_weight -{ - uint32_t wait_sec; - uint16_t weight; - - // explicit serialization macro is not necessary, used here only to improve compilation time - EOSLIB_SERIALIZE(wait_weight, (wait_sec)(weight)) -}; -struct authority -{ - uint32_t threshold = 0; - std::vector keys; - std::vector accounts; - std::vector waits; - - // explicit serialization macro is not necessary, used here only to improve compilation time - EOSLIB_SERIALIZE(authority, (threshold)(keys)(accounts)(waits)) -}; - -class [[eosio::contract]] create_slim_account_test : public eosio::contract -{ -public: - using eosio::contract::contract; - - [[eosio::action]] void testcreate(eosio::name creator, eosio::name account, authority active_auth); -}; diff --git a/unittests/test-contracts/create_slim_account_test/create_slim_account_test.wasm b/unittests/test-contracts/create_slim_account_test/create_slim_account_test.wasm deleted file mode 100755 index 942d00b7798ab8804690f8d23dbbebe11fa6f98e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10180 zcmc&)TZ|oL9se#fb53`5yVJ73x~=-1Vbv`bS)gnyXxy(61VpPOCit{H>>lZ!v$yV^ zuEpS;HcHM%7p5wNgrdAv>wmNz>`5leWX(Xl;!*r8{iJFPn>(H8iiGc@2Zt*6^#@ zqcL3LCF)=*)Y=&C>DKhA`s~8gQhm8T-)J|MSMWI9YRrTk+{2d}CQDz()s~hQmljtVGklmiGmWKG zg;!H#BvA5o$ z`qF-t_V@S41O0nr9S_F%(^?y2@SyO7KQy2VO=yc^y`-}&wp!`rI@{5H{ent6%K!Dn z?ya&%$MvP9xkuFAJ=bdGbvl^eF#3THe(3N`AGvw_mSZ2iqwj@#Z;4d4Fa4@=D!V=# zaLVb=N0Z0b*Uvrw>No!K+I`O8m95!(W2exLzY9Nq>Y{oen)LGiyWjrgACJAEvi>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