Skip to content

Commit

Permalink
feat(funds): add action to modify the max months to withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
leisterfrancisco committed Mar 17, 2023
1 parent 5830acd commit 61b5504
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 18 deletions.
2 changes: 2 additions & 0 deletions contracts/eden/include/eden.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ namespace eden

void setdistpct(uint8_t pct);
void collectfunds(uint32_t max_steps);
void setcoltime(uint8_t months);

void fundtransfer(eosio::name from,
eosio::block_timestamp distribution_time,
Expand Down Expand Up @@ -299,6 +300,7 @@ namespace eden
action(givesbt, max_steps),
action(setdistpct, pct),
action(collectfunds, max_steps),
action(setcoltime, months),
action(inductdonate, payer, id, quantity, ricardian_contract(inductdonate_ricardian)),
eden_verb(inductcancel, 9, account, id, ricardian_contract(inductcancel_ricardian)),
action(inducted, inductee, ricardian_contract(inducted_ricardian)),
Expand Down
1 change: 1 addition & 0 deletions contracts/eden/include/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ namespace eden
void set_election_start_time(uint32_t time);
void set_election_round_duration(uint32_t duration);
void set_minimum_donation_fee(eosio::asset new_minimum_donation);
void set_max_month_widthdraw(uint8_t months);
};
} // namespace eden
11 changes: 8 additions & 3 deletions contracts/eden/src/actions/distributions.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <accounts.hpp>
#include <distributions.hpp>
#include <eden.hpp>
#include <migrations.hpp>
#include <globals.hpp>

namespace eden
{
Expand All @@ -15,10 +15,15 @@ namespace eden

void eden::collectfunds(uint32_t max_steps)
{
// eosio::check(migrations{get_self()}.is_completed<migrate_global_v0>(),
// "Global must be migrated to enable collecting funds");
eosio::check(distributions{get_self()}.on_collectfunds(max_steps) != max_steps,
"Nothing to do");
}

void eden::setcoltime(uint8_t months)
{
require_auth(get_self());
// validate if it is required that no distribution is in progress
globals{get_self()}.set_max_month_widthdraw(months);
}

} // namespace eden
8 changes: 0 additions & 8 deletions contracts/eden/src/distributions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,6 @@ namespace eden

uint32_t distributions::on_collectfunds(uint32_t max_steps)
{
eosio::print("ON_COLLECTFUNDS\n\n");

// TODO: validate if is required that there is no pending distribution
// CHECK: unit-test "budget distribution triggered by donation"

Expand All @@ -520,12 +518,6 @@ namespace eden
if (iter->distribution_time() <
eosio::current_time_point() - eosio::days(30 * months_to_withdraw))
{
eosio::print("distribution_time: ",
iter->distribution_time().to_time_point().sec_since_epoch(), "\n");
eosio::print("curr - 90 days: ",
(eosio::current_time_point() - eosio::days(30 * months_to_withdraw))
.sec_since_epoch(),
"\n\n");
push_event(
distribution_event_return{
.owner = iter->owner(),
Expand Down
6 changes: 6 additions & 0 deletions contracts/eden/src/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,10 @@ namespace eden
data.minimum_donation = new_minimum_donation;
get_global_singleton(contract).set(data, eosio::same_payer);
}

void globals::set_max_month_widthdraw(uint8_t months)
{
data.max_month_withdraw = months;
get_global_singleton(contract).set(data, eosio::same_payer);
}
} // namespace eden
28 changes: 21 additions & 7 deletions contracts/eden/tests/test-eden.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1496,18 +1496,17 @@ TEST_CASE("migrate to include max_month_withdraw")
CHECK(get_globals().max_month_withdraw == default_max_month_withdraw);
}

TEST_CASE("change the max month withdraw")
TEST_CASE("change the max month to transfer funds")
{
eden_tester t;
t.genesis();

// TOOD: implement the action to modify the max months to withdraw

// const uint8_t new_max_month_withdraw = 5;

// t.eden_gm.act<actions::setmaxmonthwithdraw>(new_max_month_withdraw);
const uint8_t default_max_month_withdraw = 3;
const uint8_t new_max_month_withdraw = 6;

// CHECK(get_globals().max_month_withdraw == new_max_month_withdraw);
CHECK(get_globals().max_month_withdraw == default_max_month_withdraw);
t.eden_gm.act<actions::setcoltime>(new_max_month_withdraw);
CHECK(get_globals().max_month_withdraw == new_max_month_withdraw);
}

TEST_CASE("return funds to master by collecting them")
Expand Down Expand Up @@ -1546,6 +1545,21 @@ TEST_CASE("return funds to master by collecting them")
CHECK(t.get_budgets_by_period() == expected);
// validate funds are returned to master: 31.0734 EOS + 1.7100 EOS = 32.7834 EOS - 1.5536 EOS = 31.2298 EOS
CHECK(accounts{"eden.gm"_n, "owned"_n}.get_account("master"_n)->balance() == s2a("31.2298 EOS"));

t.eden_gm.act<actions::setcoltime>(4);
t.skip_to("2020-09-02T15:30:00.000");
t.egeon.act<actions::collectfunds>(100);
// no deletion is required since the max month to transfer funds has changed to 4
expected[s2t("2020-09-02T15:30:00.000")] = s2a("1.5614 EOS");
CHECK(t.get_budgets_by_period() == expected);
CHECK(accounts{"eden.gm"_n, "owned"_n}.get_account("master"_n)->balance() == s2a("29.6684 EOS"));

t.skip_to("2020-10-02T15:30:00.000");
t.egeon.act<actions::collectfunds>(100);
expected.erase(s2t("2020-06-03T15:30:00.000"));
expected[s2t("2020-10-02T15:30:00.000")] = s2a("1.4834 EOS");
CHECK(t.get_budgets_by_period() == expected);
CHECK(accounts{"eden.gm"_n, "owned"_n}.get_account("master"_n)->balance() == s2a("29.8095 EOS"));
}

TEST_CASE("account migration")
Expand Down

0 comments on commit 61b5504

Please sign in to comment.