Skip to content

Commit

Permalink
Merge pull request #28 from icon-community/fix/send-installment-error…
Browse files Browse the repository at this point in the history
…-cps-treasury

looks good
  • Loading branch information
naneey authored Jan 26, 2024
2 parents 2724e9a + 512389a commit fc39096
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CPSTreasury/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = '1.3.3'
version = '1.3.5'

dependencies {
compileOnly 'foundation.icon:javaee-api:0.9.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ public void updateProposalFund(String ipfsKey, BigInteger addedBudget, BigIntege
public void sendInstallmentToContributor(String ipfsKey, BigInteger milestoneBudget) {
validateCpsScore();
Context.require(proposalExists(ipfsKey), TAG + ": Invalid IPFS Hash.");
BigInteger installmentAmount;
String prefix = proposalPrefix(ipfsKey);
Map<String, ?> proposalData = getDataFromProposalDB(prefix);

Expand All @@ -343,20 +342,17 @@ public void sendInstallmentToContributor(String ipfsKey, BigInteger milestoneBud
Address contributorAddress = (Address) proposalData.get(consts.CONTRIBUTOR_ADDRESS);
String flag = (String) proposalData.get(consts.TOKEN);


Context.require(milestoneBudget.compareTo(remainingAmount) <= 0, TAG + "Requested budget is greater than remaining amount.");

installmentAmount = milestoneBudget;


setRemainingAmount(prefix, remainingAmount.subtract(installmentAmount));
setWithdrawAmount(prefix, withdrawAmount.add(installmentAmount));
if (milestoneBudget.compareTo(remainingAmount) >= 0){
milestoneBudget = remainingAmount;
}
setRemainingAmount(prefix, remainingAmount.subtract(milestoneBudget));
setWithdrawAmount(prefix, withdrawAmount.add(milestoneBudget));
DictDB<String, BigInteger> installmentFund = this.installmentFundRecord.at(contributorAddress.toString());
BigInteger installmentFundAmount = installmentFund.getOrDefault(flag, BigInteger.ZERO);
installmentFund.set(flag, installmentFundAmount.add(installmentAmount));
ProposalFundSent(contributorAddress, "new installment " + installmentAmount + " " + flag + " sent to contributors address.");
installmentFund.set(flag, installmentFundAmount.add(milestoneBudget));
ProposalFundSent(contributorAddress, "new installment " + milestoneBudget + " " + flag + " sent to contributors address.");

if (remainingAmount.subtract(installmentAmount).equals(BigInteger.ZERO)) {
if (remainingAmount.subtract(milestoneBudget).equals(BigInteger.ZERO)) {
setStatus(prefix, COMPLETED);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,41 @@ void sendInstallmentToContributor_Completed(){

}

@Test
void lastReportWithIncorrectMilestone(){
/* total Milestone = 4, remaining milestone = 2
* each milestone = 22.5 , for 2 milestone = 45 */
sendInstallmentToContributor_SecondInstallment();

Map<String, ?> proposalDataDetails = (Map<String, ?>) tokenScore.call("getContributorProjectedFund", testing_account2.getAddress());
System.out.println("proposal details "+ proposalDataDetails);
assertEquals(proposalDataDetails.get("withdraw_amount_bnUSD"), BigInteger.valueOf(55).multiply(ICX));

List<Map<String, ?>> proposalDetailsData = (List<Map<String, ?>>) proposalDataDetails.get("data");
assertEquals(proposalDetailsData.get(0).get("total_budget"), BigInteger.valueOf(100).multiply(ICX));

BigInteger remainingAmount = BigInteger.valueOf(100).multiply(ICX).subtract(BigInteger.valueOf(55).multiply(ICX));
assertEquals(remainingAmount,BigInteger.valueOf(45).multiply(ICX));

// requesting more than 45ICX
tokenScore.invoke(owner, "sendInstallmentToContributor", "Proposal 1", BigInteger.valueOf(50).multiply(ICX));
tokenScore.invoke(owner, "sendRewardToSponsor", "Proposal 1", 2);
@SuppressWarnings("unchecked")
Map<String, ?> proposalDataDetails_after = (Map<String, ?>) tokenScore.call("getContributorProjectedFund", testing_account2.getAddress());
assertEquals(proposalDataDetails_after.get("withdraw_amount_bnUSD"), BigInteger.valueOf(100).multiply(ICX));


proposalDetailsData = (List<Map<String, ?>>) proposalDataDetails_after.get("data");
assertEquals(proposalDetailsData.size(),0);

assertEquals(proposalDataDetails_after.get(PROJECT_COUNT),0);
// at the completion of proposal the withdrawn amount is still 100ICX
assertEquals(proposalDataDetails_after.get(WITHDRAWN_BNUSD),BigInteger.valueOf(100).multiply(ICX));

Map<String,BigInteger> totalAmount = Map.of(consts.bnUSD,BigInteger.ZERO);
assertEquals(proposalDataDetails_after.get(TOTAL_AMOUNT),totalAmount);
}

@Test
void sendRewardToSponsor() {
setOnsetPayment();
Expand Down

0 comments on commit fc39096

Please sign in to comment.