From 3536f1a76e3c88950895009c31bdc5aa9c985298 Mon Sep 17 00:00:00 2001 From: sergio Date: Mon, 28 Sep 2020 15:41:24 -0300 Subject: [PATCH] inittoken with require_auth(get_self()). Tests adapted --- evolutiondex.cpp | 1 + tests/contracts.hpp | 32 ++++++++++++++++---------------- tests/contracts.hpp.in | 8 ++++---- tests/evolutiondex_tests.cpp | 22 +++++++++++++++++++--- 4 files changed, 40 insertions(+), 23 deletions(-) diff --git a/evolutiondex.cpp b/evolutiondex.cpp index 92ec383..aa072d5 100644 --- a/evolutiondex.cpp +++ b/evolutiondex.cpp @@ -200,6 +200,7 @@ void evolutiondex::inittoken(name user, symbol new_symbol, extended_asset initia extended_asset initial_pool2, int initial_fee, name fee_contract) { require_auth( user ); + require_auth( get_self() ); check((initial_pool1.quantity.amount > 0) && (initial_pool2.quantity.amount > 0), "Both assets must be positive"); check((initial_pool1.quantity.amount < INIT_MAX) && (initial_pool2.quantity.amount < INIT_MAX), "Initial amounts must be less than 10^15"); int128_t geometric_mean = sqrt(int128_t(initial_pool1.quantity.amount) * int128_t(initial_pool2.quantity.amount)); diff --git a/tests/contracts.hpp b/tests/contracts.hpp index 8407539..00f15ee 100644 --- a/tests/contracts.hpp +++ b/tests/contracts.hpp @@ -4,28 +4,28 @@ namespace eosio { namespace testing { struct contracts { - static std::vector system_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.system/eosio.system.wasm"); } - static std::vector system_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.system/eosio.system.abi"); } + static std::vector system_wasm() { return read_wasm("{CONTRACTS_BUILD_FOLDER}/contracts/eosio.system/eosio.system.wasm"); } + static std::vector system_abi() { return read_abi("{CONTRACTS_BUILD_FOLDER}/contracts/eosio.system/eosio.system.abi"); } - static std::vector token_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.token/eosio.token.wasm"); } - static std::vector token_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.token/eosio.token.abi"); } + static std::vector token_wasm() { return read_wasm("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.token/eosio.token.wasm"); } + static std::vector token_abi() { return read_abi("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.token/eosio.token.abi"); } - static std::vector msig_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.msig/eosio.msig.wasm"); } - static std::vector msig_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.msig/eosio.msig.abi"); } + static std::vector msig_wasm() { return read_wasm("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.msig/eosio.msig.wasm"); } + static std::vector msig_abi() { return read_abi("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.msig/eosio.msig.abi"); } - static std::vector wrap_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.wrap/eosio.wrap.wasm"); } - static std::vector wrap_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.wrap/eosio.wrap.abi"); } + static std::vector wrap_wasm() { return read_wasm("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.wrap/eosio.wrap.wasm"); } + static std::vector wrap_abi() { return read_abi("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.wrap/eosio.wrap.abi"); } - static std::vector bios_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.bios/eosio.bios.wasm"); } - static std::vector bios_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.bios/eosio.bios.abi"); } + static std::vector bios_wasm() { return read_wasm("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.bios/eosio.bios.wasm"); } + static std::vector bios_abi() { return read_abi("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.bios/eosio.bios.abi"); } - static std::vector evolutiondex_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/evo/tests/../evolutiondex.wasm"); } - static std::vector evolutiondex_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/evo/tests/../evolutiondex.abi"); } + static std::vector evolutiondex_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/../evolutiondex.wasm"); } + static std::vector evolutiondex_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/../evolutiondex.abi"); } - static std::vector badtoken_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/evo/tests/../badtoken.wasm"); } - static std::vector badtoken_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/evo/tests/../badtoken.abi"); } + static std::vector badtoken_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/badtoken.wasm"); } + static std::vector badtoken_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/badtoken.abi"); } - static std::vector wevotethefee_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/evo/wevotethefee/wevotethefee.wasm"); } - static std::vector wevotethefee_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/evo/wevotethefee/wevotethefee.abi"); } + static std::vector wevotethefee_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/../wevotethefee/wevotethefee.wasm"); } + static std::vector wevotethefee_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/../wevotethefee/wevotethefee.abi"); } }; }} //ns eosio::testing diff --git a/tests/contracts.hpp.in b/tests/contracts.hpp.in index b06fdb0..cfa925b 100644 --- a/tests/contracts.hpp.in +++ b/tests/contracts.hpp.in @@ -22,10 +22,10 @@ struct contracts { static std::vector evolutiondex_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/../evolutiondex.wasm"); } static std::vector evolutiondex_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/../evolutiondex.abi"); } - static std::vector badtoken_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/../badtoken.wasm"); } - static std::vector badtoken_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/../badtoken.abi"); } + static std::vector badtoken_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/badtoken/badtoken.wasm"); } + static std::vector badtoken_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/badtoken/badtoken.abi"); } - static std::vector wevotethefee_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/evo/wevotethefee/wevotethefee.wasm"); } - static std::vector wevotethefee_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/evo/wevotethefee/wevotethefee.abi"); } + static std::vector wevotethefee_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/../wevotethefee/wevotethefee.wasm"); } + static std::vector wevotethefee_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/../wevotethefee/wevotethefee.abi"); } }; }} //ns eosio::testing \ No newline at end of file diff --git a/tests/evolutiondex_tests.cpp b/tests/evolutiondex_tests.cpp index 3841753..ab8d401 100644 --- a/tests/evolutiondex_tests.cpp +++ b/tests/evolutiondex_tests.cpp @@ -127,14 +127,22 @@ class evolutiondex_tester : public tester { } action_result inittoken( name user, symbol new_symbol, extended_asset initial_pool1, extended_asset initial_pool2, int initial_fee, name fee_contract){ - return push_action( N(evolutiondex), user, N(inittoken), mvo() + std::vector auths{user, N(evolutiondex)}; + try { + eosio::testing::base_tester::push_action( N(evolutiondex), N(inittoken), auths, mvo() ( "user", user) ("new_symbol", new_symbol) ("initial_pool1", initial_pool1) ("initial_pool2", initial_pool2) ("initial_fee", initial_fee) ("fee_contract", fee_contract) - ); + , 100, 0); + } catch (const fc::exception& ex) { + edump((ex)); + edump((ex.to_detail_string())); + return error(ex.top_message()); + } + return success(); } action_result addliquidity(name user, asset to_buy, asset max_asset1, asset max_asset2) { return push_action( N(evolutiondex), user, N(addliquidity), mvo() @@ -671,6 +679,7 @@ BOOST_FIXTURE_TEST_CASE( increasing_parameter_zero_fee, evolutiondex_tester ) tr BOOST_REQUIRE_EQUAL(is_increasing(old_vec, system_balance(EVO.value)), true); } FC_LOG_AND_RETHROW() + BOOST_FIXTURE_TEST_CASE( memoexchange_test, evolutiondex_tester ) try { const auto& accnt2 = control->db().get( N(evolutiondex) ); abi_def abi_evo; @@ -805,6 +814,13 @@ BOOST_FIXTURE_TEST_CASE( the_other_actions, evolutiondex_tester ) try { extend(asset::from_string("0.0003 EOS")) )); // INITTOKEN + BOOST_REQUIRE_EQUAL( error("missing authority of evolutiondex"), + push_action( N(evolutiondex), N(alice), N(inittoken), mvo() + ("user", N(alice)) ("new_symbol", EVO4) + ("initial_pool1", extend(asset::from_string("1.0000 EOS"))) + ("initial_pool2", extend(asset::from_string("1.0000 ECO"))) + ("initial_fee", 1) ("fee_contract", N(carol)) ) + ); BOOST_REQUIRE_EQUAL( error("missing authority of alice"), push_action( N(evolutiondex), N(bob), N(inittoken), mvo() ("user", N(alice)) ("new_symbol", EVO4) @@ -838,6 +854,7 @@ BOOST_FIXTURE_TEST_CASE( the_other_actions, evolutiondex_tester ) try { BOOST_REQUIRE_EQUAL( success(), inittoken( N(alice), EVO4, extend(asset::from_string("0.0001 EOS")), extend(asset::from_string("0.1000 VOICE")), 10, N(wevotethefee)) ); + produce_blocks(); BOOST_REQUIRE_EQUAL( wasm_assert_msg("token symbol already exists"), inittoken( N(alice), EVO4, extend(asset::from_string("0.0001 EOS")), extend(asset::from_string("0.1000 VOICE")), 10, N(wevotethefee)) ); @@ -913,7 +930,6 @@ BOOST_FIXTURE_TEST_CASE( the_other_actions, evolutiondex_tester ) try { } FC_LOG_AND_RETHROW() - BOOST_FIXTURE_TEST_CASE( we_vote_the_fee, evolutiondex_tester ) try { create_tokens_and_issue();