Skip to content

Commit

Permalink
test: unit test successful after refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
naneey committed Sep 1, 2023
1 parent 1813d3f commit 34db8df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void setRouterScoreExceptions(Account address, Address _score) {
// }

@Test
void transferProposalFundToCPSTreasury() {
void transfer_proposal_fund_to_cps_treasury() {

setBNUSDScoreMethod(bnUSDScore);
setCPSTreasuryScoreMetod(cpsTreasuryScore);
Expand Down Expand Up @@ -273,7 +273,7 @@ void updateProposalFund() {
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(1000).multiply(MULTIPLIER));
theMock.when(() -> Context.call(balancedDollar.get(), "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(1000).multiply(MULTIPLIER));
tokenScore.invoke(owner, "update_proposal_fund", "Proposal 1", "bnUSD", BigInteger.valueOf(100).multiply(MULTIPLIER), 1);
Map<String, Object> details = (Map<String, Object>) tokenScore.call("get_proposal_details", 0, 5);
Map<String, Object> details = (Map<String, Object>) tokenScore.call("getProposalDetails", 0, 5);
List<Map<String, Object>> proposalsList = new ArrayList<>();
proposalsList.add(Map.of("_ipfs_hash", "Proposal 1", "_budget_transfer", BigInteger.valueOf(204).multiply(MULTIPLIER).toString()));
proposalsList.add(Map.of("_ipfs_hash", "Proposal 2", "_budget_transfer", BigInteger.valueOf(1122).multiply(MULTIPLIER).divide(BigInteger.TEN).toString()));
Expand Down Expand Up @@ -344,7 +344,7 @@ void swapTokensRemainingToSwapLessThanTen() {
theMock.when(() -> Context.call(balancedDollar.get(), "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(1995).multiply(MULTIPLIER));
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(10000).multiply(MULTIPLIER));
tokenScore.invoke(owner, "swap_tokens", 10);
assertEquals(tokenScore.call("get_swap_state_status"), Map.of("count", 0, "state", 1));
assertEquals(tokenScore.call("getSwapStateStatus"), Map.of("count", 0, "state", 1));
}
}

Expand All @@ -362,7 +362,7 @@ void swapTokensRemainingToSwapMoreThanTen() {
theMock.when(() -> Context.call(balancedDollar.get(), "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(1000).multiply(MULTIPLIER));
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(2000).multiply(MULTIPLIER));
tokenScore.invoke(owner, "swap_tokens", 10);
assertEquals(tokenScore.call("get_swap_state_status"), Map.of("count", 1, "state", 0));
assertEquals(tokenScore.call("getSwapStateStatus"), Map.of("count", 1, "state", 0));
}
}

Expand All @@ -380,7 +380,7 @@ void swapTokensRemainingToSwapMoreThanTenCountIsZeroFromCPSScore() {
theMock.when(() -> Context.call(balancedDollar.get(), "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(1000).multiply(MULTIPLIER));
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(2000).multiply(MULTIPLIER));
tokenScore.invoke(owner, "swap_tokens", 0);
assertEquals(tokenScore.call("get_swap_state_status"), Map.of("count", 0, "state", 1));
assertEquals(tokenScore.call("getSwapStateStatus"), Map.of("count", 0, "state", 1));
}
}

Expand All @@ -394,7 +394,7 @@ void resetSwapState() {
theMock.when(() -> Context.getCaller()).thenReturn(testing_account.getAddress());
theMock.when(() -> Context.call(score_address, "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "reset_swap_state");
assertEquals(tokenScore.call("get_swap_state_status"), Map.of("state", 0, "count", 0));
assertEquals(tokenScore.call("getSwapStateStatus"), Map.of("state", 0, "count", 0));
}
}

Expand Down Expand Up @@ -423,7 +423,7 @@ void addFundExtraICX() {
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(2001).multiply(MULTIPLIER));
theMock.when(() -> Context.call(bnUSDScore, "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(2000).multiply(MULTIPLIER));
tokenScore.invoke(owner, "add_fund");
tokenScore.invoke(owner, "addFund");
theMock.verify(() -> Context.call(BigInteger.valueOf(1).multiply(MULTIPLIER), score_address, "burn"), times(1));

}
Expand All @@ -445,7 +445,7 @@ private void addFundMethod() {
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getBalance(Context.getAddress())).thenReturn(BigInteger.valueOf(2000).multiply(MULTIPLIER));
theMock.when(() -> Context.call(bnUSDScore, "balanceOf", Context.getAddress())).thenReturn(BigInteger.valueOf(2001).multiply(MULTIPLIER));
tokenScore.invoke(owner, "add_fund");
tokenScore.invoke(owner, "addFund");
JsonObject swapData = new JsonObject();
swapData.add("method", "_swap");
JsonObject params = new JsonObject();
Expand Down Expand Up @@ -604,7 +604,7 @@ void tokenFallBackFromIsCpsTreasuryScore() {
params_.add("toToken", sicxScore.toString());
swapData.add("params", params_);
theMock.verify(() -> Context.call(bnUSDScore, "transfer", dexScore, BigInteger.ONE.multiply(MULTIPLIER), swapData.toString().getBytes()));
Map<String, Object> details = (Map<String, Object>) tokenScore.call("get_proposal_details", 0, 5);
Map<String, Object> details = (Map<String, Object>) tokenScore.call("getProposalDetails", 0, 5);
List<Map<String, Object>> proposalsList = new ArrayList<>();
proposalsList.add(Map.of("_ipfs_hash", "Proposal 1", "_budget_transfer", BigInteger.valueOf(2).multiply(MULTIPLIER).toString()));
proposalsList.add(Map.of("_ipfs_hash", "Proposal 2", "_budget_transfer", BigInteger.valueOf(1122).multiply(MULTIPLIER).divide(BigInteger.TEN).toString()));
Expand Down Expand Up @@ -685,7 +685,7 @@ void fallbackSenderIsNotDex() {
theMock.when(() -> Context.getCaller()).thenReturn(sicxScore);
theMock.when(() -> Context.getValue()).thenReturn(BigInteger.valueOf(1000).multiply(MULTIPLIER));
tokenScore.invoke(owner, "fallback");
theMock.verify(() -> Context.revert(TAG + ": Please send fund using add_fund()."));
theMock.verify(() -> Context.revert(TAG + ": Please send fund using addFund()."));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void setBnUSDScoreNotContract() {
void depositProposalFund() {
depositProposalFundMethod();
@SuppressWarnings("unchecked")
Map<String, ?> proposalDataDetails = (Map<String, ?>) tokenScore.call("get_contributor_projected_fund", testing_account2.getAddress());
Map<String, ?> proposalDataDetails = (Map<String, ?>) tokenScore.call("getContributorProjectedFund", testing_account2.getAddress());
@SuppressWarnings("unchecked")
List<Map<String, ?>> proposalDetails = (List<Map<String, ?>>) proposalDataDetails.get("data");
Map<String, ?> expectedData = Map.of(
Expand Down Expand Up @@ -237,7 +237,7 @@ void updateProposalFund() {
tokenScore.invoke(owner, "tokenFallback", cpfTreasury, BigInteger.valueOf(102).multiply(MULTIPLIER), budgetAdjustmentData.toString().getBytes());

@SuppressWarnings("unchecked")
Map<String, ?> proposalDataDetails = (Map<String, ?>) tokenScore.call("get_contributor_projected_fund", testing_account2.getAddress());
Map<String, ?> proposalDataDetails = (Map<String, ?>) tokenScore.call("getContributorProjectedFund", testing_account2.getAddress());
@SuppressWarnings("unchecked")
List<Map<String, ?>> proposalDetails = (List<Map<String, ?>>) proposalDataDetails.get("data");
Map<String, ?> expectedData = Map.of(
Expand Down Expand Up @@ -285,15 +285,15 @@ void sendInstallmentToContributor() {
tokenScore.invoke(owner, "send_installment_to_contributor", "Proposal 1");
}
@SuppressWarnings("unchecked")
Map<String, ?> proposalDataDetails = (Map<String, ?>) tokenScore.call("get_contributor_projected_fund", testing_account2.getAddress());
Map<String, ?> proposalDataDetails = (Map<String, ?>) tokenScore.call("getContributorProjectedFund", testing_account2.getAddress());
assertEquals(proposalDataDetails.get("withdraw_amount_bnUSD"), BigInteger.valueOf(50).multiply(MULTIPLIER));

try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(score_address);
tokenScore.invoke(owner, "send_installment_to_contributor", "Proposal 1");
}
@SuppressWarnings("unchecked")
Map<String, ?> proposalDataDetails2 = (Map<String, ?>) tokenScore.call("get_contributor_projected_fund", testing_account2.getAddress());
Map<String, ?> proposalDataDetails2 = (Map<String, ?>) tokenScore.call("getContributorProjectedFund", testing_account2.getAddress());
assertEquals(proposalDataDetails2.get("withdraw_amount_bnUSD"), BigInteger.valueOf(100).multiply(MULTIPLIER));
}

Expand All @@ -303,15 +303,15 @@ void sendRewardToSponsor() {
setCpsScoreMethod();
sendRewardToSponsorMethod();
@SuppressWarnings("unchecked")
Map<String, ?> proposalDataDetails = (Map<String, ?>) tokenScore.call("get_sponsor_projected_fund", testing_account.getAddress());
Map<String, ?> proposalDataDetails = (Map<String, ?>) tokenScore.call("getSponsorProjectedFund", testing_account.getAddress());
assertEquals(proposalDataDetails.get("withdraw_amount_bnUSD"), BigInteger.valueOf(1).multiply(MULTIPLIER));

try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(score_address);
tokenScore.invoke(owner, "send_reward_to_sponsor", "Proposal 1");
}
@SuppressWarnings("unchecked")
Map<String, ?> proposalDataDetails2 = (Map<String, ?>) tokenScore.call("get_sponsor_projected_fund", testing_account.getAddress());
Map<String, ?> proposalDataDetails2 = (Map<String, ?>) tokenScore.call("getSponsorProjectedFund", testing_account.getAddress());
assertEquals(proposalDataDetails2.get("withdraw_amount_bnUSD"), BigInteger.valueOf(2).multiply(MULTIPLIER));
}

Expand Down Expand Up @@ -347,7 +347,7 @@ void claimReward(){
setBnUSDScoreMethod();
try(MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.getCaller()).thenReturn(testing_account.getAddress());
tokenScore.invoke(testing_account, "claim_reward");
tokenScore.invoke(testing_account, "claimReward");
theMock.verify(() -> Context.call(bnUSDScore, "transfer", testing_account.getAddress(), BigInteger.valueOf(1).multiply(MULTIPLIER)), times(1));
}
}
Expand Down

0 comments on commit 34db8df

Please sign in to comment.