Skip to content

Commit

Permalink
inittoken with require_auth(get_self()). Tests adapted
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioyuhjtman committed Sep 28, 2020
1 parent d43ccb9 commit 3536f1a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
1 change: 1 addition & 0 deletions evolutiondex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
32 changes: 16 additions & 16 deletions tests/contracts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
namespace eosio { namespace testing {

struct contracts {
static std::vector<uint8_t> system_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.system/eosio.system.wasm"); }
static std::vector<char> system_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.system/eosio.system.abi"); }
static std::vector<uint8_t> system_wasm() { return read_wasm("{CONTRACTS_BUILD_FOLDER}/contracts/eosio.system/eosio.system.wasm"); }
static std::vector<char> system_abi() { return read_abi("{CONTRACTS_BUILD_FOLDER}/contracts/eosio.system/eosio.system.abi"); }

static std::vector<uint8_t> token_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.token/eosio.token.wasm"); }
static std::vector<char> token_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.token/eosio.token.abi"); }
static std::vector<uint8_t> token_wasm() { return read_wasm("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.token/eosio.token.wasm"); }
static std::vector<char> token_abi() { return read_abi("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.token/eosio.token.abi"); }

static std::vector<uint8_t> msig_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.msig/eosio.msig.wasm"); }
static std::vector<char> msig_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.msig/eosio.msig.abi"); }
static std::vector<uint8_t> msig_wasm() { return read_wasm("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.msig/eosio.msig.wasm"); }
static std::vector<char> msig_abi() { return read_abi("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.msig/eosio.msig.abi"); }

static std::vector<uint8_t> wrap_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.wrap/eosio.wrap.wasm"); }
static std::vector<char> wrap_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.wrap/eosio.wrap.abi"); }
static std::vector<uint8_t> wrap_wasm() { return read_wasm("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.wrap/eosio.wrap.wasm"); }
static std::vector<char> wrap_abi() { return read_abi("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.wrap/eosio.wrap.abi"); }

static std::vector<uint8_t> bios_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.bios/eosio.bios.wasm"); }
static std::vector<char> bios_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/eosio.contracts/build/contracts/eosio.bios/eosio.bios.abi"); }
static std::vector<uint8_t> bios_wasm() { return read_wasm("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.bios/eosio.bios.wasm"); }
static std::vector<char> bios_abi() { return read_abi("${CONTRACTS_BUILD_FOLDER}/contracts/eosio.bios/eosio.bios.abi"); }

static std::vector<uint8_t> evolutiondex_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/evo/tests/../evolutiondex.wasm"); }
static std::vector<char> evolutiondex_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/evo/tests/../evolutiondex.abi"); }
static std::vector<uint8_t> evolutiondex_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/../evolutiondex.wasm"); }
static std::vector<char> evolutiondex_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/../evolutiondex.abi"); }

static std::vector<uint8_t> badtoken_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/evo/tests/../badtoken.wasm"); }
static std::vector<char> badtoken_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/evo/tests/../badtoken.abi"); }
static std::vector<uint8_t> badtoken_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/badtoken.wasm"); }
static std::vector<char> badtoken_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/badtoken.abi"); }

static std::vector<uint8_t> wevotethefee_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/evo/wevotethefee/wevotethefee.wasm"); }
static std::vector<char> wevotethefee_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/evo/wevotethefee/wevotethefee.abi"); }
static std::vector<uint8_t> wevotethefee_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/../wevotethefee/wevotethefee.wasm"); }
static std::vector<char> wevotethefee_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/../wevotethefee/wevotethefee.abi"); }
};
}} //ns eosio::testing
8 changes: 4 additions & 4 deletions tests/contracts.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ struct contracts {
static std::vector<uint8_t> evolutiondex_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/../evolutiondex.wasm"); }
static std::vector<char> evolutiondex_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/../evolutiondex.abi"); }

static std::vector<uint8_t> badtoken_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/../badtoken.wasm"); }
static std::vector<char> badtoken_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/../badtoken.abi"); }
static std::vector<uint8_t> badtoken_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/badtoken/badtoken.wasm"); }
static std::vector<char> badtoken_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/badtoken/badtoken.abi"); }

static std::vector<uint8_t> wevotethefee_wasm() { return read_wasm("/home/sergio/Dropbox/eos/contracts/evo/wevotethefee/wevotethefee.wasm"); }
static std::vector<char> wevotethefee_abi() { return read_abi("/home/sergio/Dropbox/eos/contracts/evo/wevotethefee/wevotethefee.abi"); }
static std::vector<uint8_t> wevotethefee_wasm() { return read_wasm("${CMAKE_CURRENT_SOURCE_DIR}/../wevotethefee/wevotethefee.wasm"); }
static std::vector<char> wevotethefee_abi() { return read_abi("${CMAKE_CURRENT_SOURCE_DIR}/../wevotethefee/wevotethefee.abi"); }
};
}} //ns eosio::testing
22 changes: 19 additions & 3 deletions tests/evolutiondex_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<name> 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()
Expand Down Expand Up @@ -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<account_object,by_name>( N(evolutiondex) );
abi_def abi_evo;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)) );
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3536f1a

Please sign in to comment.