Skip to content

Commit

Permalink
Merge pull request #55 from Alien-Worlds/DEMZNE-1091-fix-period-budge…
Browse files Browse the repository at this point in the history
…t-failing-test

fix period budget test by rounding to 4 decimals in javascript
  • Loading branch information
angelol authored Oct 5, 2022
2 parents c3d6f80 + 6974480 commit 3f8dfc9
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions contracts/daccustodian/daccustodian.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3165,10 +3165,14 @@ describe('Daccustodian', () => {
});
});
it('should transfer amount according to formula', async () => {
const expected_treasury_balance_after =
treasury_balance_before - expected_transfer_amount;
const expected_auth_balance_after =
auth_balance_before + expected_transfer_amount;
const expected_treasury_balance_after = round_to_decimals(
treasury_balance_before - expected_transfer_amount,
4
);
const expected_auth_balance_after = round_to_decimals(
auth_balance_before + expected_transfer_amount,
4
);

const actual_treasury_balance = await get_balance(
shared.eosio_token_contract,
Expand Down Expand Up @@ -3373,11 +3377,6 @@ async function expected_budget_transfer_amount(
dacId: string,
assert_manual: bool
) {
const auth_balance = await get_balance(
shared.eosio_token_contract,
shared.auth_account,
'TLM'
);
const treasury_balance = await get_balance(
shared.eosio_token_contract,
shared.treasury_account,
Expand All @@ -3400,8 +3399,13 @@ async function expected_budget_transfer_amount(
const nft_with_highest_value = budget_nfts[0];
percentage = nft_with_highest_value.value;
}
const allocation = (treasury_balance * percentage) / 10000;
return round_to_decimals(allocation, 4);
const allocation_for_period = (treasury_balance * percentage) / 10000;
const rounded_allocation = Math.max(allocation_for_period, 10);
const transfer_amount = Math.max(
0,
Math.min(treasury_balance, rounded_allocation)
);
return round_to_decimals(transfer_amount, 4);
}

function round_to_decimals(number, decimals) {
Expand Down

0 comments on commit 3f8dfc9

Please sign in to comment.