Skip to content

Commit

Permalink
inittoken now checks fee_contract account exists or is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioyuhjtman committed Jun 2, 2020
1 parent ca0b685 commit 27f3a93
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion evolutiondex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void evolutiondex::add_signed_liq(name user, asset to_add, bool is_buying,
add_signed_ext_balance(user, -to_pay1);
add_signed_ext_balance(user, -to_pay2);
(to_add.amount > 0)? add_balance(user, to_add, user) : sub_balance(user, -to_add);
if (is_account(token->fee_contract)) require_recipient(token->fee_contract);
if (token->fee_contract) require_recipient(token->fee_contract);
statstable.modify( token, same_payer, [&]( auto& a ) {
a.supply += to_add;
a.pool1 += to_pay1;
Expand Down Expand Up @@ -209,6 +209,7 @@ extended_asset initial_pool2, int initial_fee, name fee_contract)
const auto& token = statstable.find( new_token.symbol.code().raw() );
check ( token == statstable.end(), "token symbol already exists" );
check( (0 <= initial_fee) && (initial_fee <= 500), "initial fee out of reasonable range");
check( is_account(fee_contract) || !fee_contract, "fee_contract account must exist or be empty");

statstable.emplace( user, [&]( auto& a ) {
a.supply = new_token;
Expand Down
28 changes: 18 additions & 10 deletions tests/evolutiondex_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,39 +781,47 @@ BOOST_FIXTURE_TEST_CASE( the_other_actions, evolutiondex_tester ) try {
);
BOOST_REQUIRE_EQUAL( wasm_assert_msg("Both assets must be positive"), inittoken( N(alice), EVO4,
extend(asset::from_string("-0.0001 EOS")),
extend(asset::from_string("0.1000 VOICE")), 10, N(foo)) );
extend(asset::from_string("0.1000 VOICE")), 10, N(wevotethefee)) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("Both assets must be positive"), inittoken( N(alice), EVO4,
extend(asset::from_string("0.0001 EOS")),
extend(asset::from_string("-0.1000 VOICE")), 10, N(foo)) );
extend(asset::from_string("-0.1000 VOICE")), 10, N(wevotethefee)) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("Initial amounts must be less than 10^15"), inittoken( N(alice), EVO4,
extend(asset::from_string("0.0001 EOS")),
extend(asset::from_string("100000000000.0001 VOICE")), 10, N(foo)) );
extend(asset::from_string("100000000000.0001 VOICE")), 10, N(wevotethefee)) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("Initial amounts must be less than 10^15"), inittoken( N(alice), EVO4,
extend(asset::from_string("100000000000.0001 EOS")),
extend(asset::from_string("1.0001 VOICE")), 10, N(foo)) );
extend(asset::from_string("1.0001 VOICE")), 10, N(wevotethefee)) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("extended symbols must be different"), inittoken( N(alice), EVO4,
extend(asset::from_string("0.0001 EOS")),
extend(asset::from_string("0.1000 EOS")), 10, N(foo)) );
extend(asset::from_string("0.1000 EOS")), 10, N(wevotethefee)) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("insufficient funds"),
inittoken( N(alice), ETUSD4,
extend(asset::from_string("0.0003 EOS")),
extend(asset::from_string("0.1000 VOICE")), 10, N(foo)) );
extend(asset::from_string("0.1000 VOICE")), 10, N(wevotethefee)) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("insufficient funds"),
inittoken( N(alice), ETUSD4,
extend(asset::from_string("0.0002 EOS")),
extend(asset::from_string("100000000.0000 VOICE")), 10, N(foo)) );
extend(asset::from_string("100000000.0000 VOICE")), 10, N(wevotethefee)) );
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)) );
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(foo)) );
extend(asset::from_string("0.1000 VOICE")), 10, N(wevotethefee)) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("initial fee out of reasonable range"), inittoken( N(alice), ETUSD4,
extend(asset::from_string("0.0001 EOS")),
extend(asset::from_string("0.1000 VOICE")), 501, N(foo)) );
extend(asset::from_string("0.1000 VOICE")), 501, N(wevotethefee)) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("initial fee out of reasonable range"), inittoken( N(alice), ETUSD4,
extend(asset::from_string("0.0001 EOS")),
extend(asset::from_string("0.1000 VOICE")), -1, N(foo)) );
extend(asset::from_string("0.1000 VOICE")), -1, N(wevotethefee)) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("fee_contract account must exist or be empty"), inittoken( N(alice), ETUSD4,
extend(asset::from_string("0.0001 EOS")),
extend(asset::from_string("0.1000 VOICE")), 1, N(nonexistent)) );
BOOST_REQUIRE_EQUAL( success(), inittoken( N(alice), ETUSD4,
extend(asset::from_string("0.0001 EOS")),
extend(asset::from_string("0.0001 VOICE")), 1, N( )) );
BOOST_REQUIRE_EQUAL( success(), remliquidity( N(alice), asset::from_string("0.0001 ETUSD"),
asset::from_string("0.0001 EOS"), asset::from_string("0.0001 VOICE")));

// TRANSFER
BOOST_REQUIRE_EQUAL( wasm_assert_msg("extended_symbol not registered for this user,\
Expand Down
2 changes: 1 addition & 1 deletion token_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void evolutiondex::transfer( const name& from, const name& to, const asset& quan

require_recipient( from );
require_recipient( to );
if (is_account(st.fee_contract)) require_recipient( st.fee_contract ); // line added to code from eosio.token
if (st.fee_contract) require_recipient( st.fee_contract ); // line added to code from eosio.token

check( quantity.is_valid(), "invalid quantity" );
check( quantity.amount > 0, "must transfer positive quantity" );
Expand Down

0 comments on commit 27f3a93

Please sign in to comment.