Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Exchange your tokens method #1" #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Sell your evotokens and retire liquidity. The amount of evotoken is exact and th
Exchange your tokens.
There two methods. The first one is to do a transfer to the contract with a memo starting with "exchange:" and followed by the details of your operation, with the format "EVOTOKN, min_expected_asset, memo". Blank spaces before EVOTOKN, min_expected_asset and memo are ignored. The amount to be obtained by the user will be computed by the contract and executed only if it is at least min_expected_asset.

cleos push action eosio.token '["YOUR_ACCOUNT", "evolutiondex", "1.0000 EOS", "exchange: EOSPESO, 0.1000 PESO, memo for the transfer]' -p YOUR_ACCOUNT
cleos push action eosio.token transfer '["YOUR_ACCOUNT", "evolutiondex", "1.0000 EOS", "exchange: EOSPESO, 0.1000 PESO, memo for the transfer"]' -p YOUR_ACCOUNT

The other method operates between funds already deposited in the contract. The structure
of the input is account, evotoken, extended_asset to pay (exact), asset to receive (limiting).
Expand Down Expand Up @@ -165,4 +165,4 @@ Finally, to change the fee for operating through EOSPESO run:
and the fee will now be set to 0.37%. Or you can configure a contract to perform
the *changefee* action.

Check the commands of wevotethefee [here](wevotethefee/vote_commands.md).
Check the commands of wevotethefee [here](wevotethefee/vote_commands.md).
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