Skip to content

Commit

Permalink
set reward pool
Browse files Browse the repository at this point in the history
  • Loading branch information
Swastik47 committed Sep 25, 2024
1 parent 5bf3add commit 0cf0d9f
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
Expand Down Expand Up @@ -765,6 +767,72 @@ void setCouncilManagers() {
}
}

@Test
public void testSetRewardPool() {
setCPSScoreMethod(score_address);

final String AVAILABLE_BALANCE = "availableBalance";

String initialFundKey = "INITIAL_FUND";
String finalFundKey = "FINAL_FUND";
String invalidKey = "INVALID_KEY";
BigInteger availableBalance = BigInteger.valueOf(1000);

Map<String, BigInteger> totalFund = new HashMap<>();
totalFund.put(AVAILABLE_BALANCE, availableBalance);

VarDB<BigInteger> rewardPoolMock = mock(VarDB.class);

CPFTreasury cpsScore = mock(CPFTreasury.class);

when(rewardPoolMock.get()).thenReturn(availableBalance);

cpsScore.setRewardPool(initialFundKey);

assertEquals(availableBalance, rewardPoolMock.get());

cpsScore.setRewardPool(finalFundKey);

assertEquals(availableBalance, rewardPoolMock.get());

// IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
// cpsScore.setRewardPool(invalidKey);
// });
// assertTrue(exception.getMessage().contains("incorrectKeyForPool"));
}

// @Test
// void setRewardPoolTest() {
// String validKeyInitial = "INITIAL_FUND";
// String validKeyFinal = "FINAL_FUND";
// String invalidKey = "INVALID_FUND";

// try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {

// // Mock the valid key scenario for INITIAL_FUND
// theMock.when(() -> Context.require(validKeyInitial.equals("INITIAL_FUND") || validKeyInitial.equals("FINAL_FUND"), "TAG: incorrectKeyForPool"))
// .thenAnswer(invocation -> null); // Just pass

// // Invoke the method with valid INITIAL_FUND key
// tokenScore.invoke(owner, "setRewardPool", validKeyInitial);

// // Mock the valid key scenario for FINAL_FUND
// theMock.when(() -> Context.require(validKeyFinal.equals("INITIAL_FUND") || validKeyFinal.equals("FINAL_FUND"), "TAG: incorrectKeyForPool"))
// .thenAnswer(invocation -> null); // Just pass

// // Invoke the method with valid FINAL_FUND key
// tokenScore.invoke(owner, "setRewardPool", validKeyFinal);

// // Mock the invalid key scenario
// theMock.when(() -> Context.require(invalidKey.equals("INITIAL_FUND") || invalidKey.equals("FINAL_FUND"), "TAG: incorrectKeyForPool"))
// .thenThrow(new AssertionError("TAG: incorrectKeyForPool"));

// // Test the invalid key and expect an AssertionError
// assertThrows(AssertionError.class, () -> tokenScore.invoke(owner, "setRewardPool", invalidKey));
// }
// }


// @Test
// public void testSetRewardPool() {
// setCPSScoreMethod(score_address);
Expand Down

0 comments on commit 0cf0d9f

Please sign in to comment.