Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception cases added for integration test #30

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class CPFTTreasuryTest extends TestBase {
public static final String TAG = "CPF_TREASURY";
private static final BigInteger MULTIPLIER = new BigInteger("1000000000000000000");

VarDB<Address> cpsScore = mock(VarDB.class);


private static final ServiceManager sm = getServiceManager();
private static final Account owner = sm.createAccount();
Expand All @@ -49,7 +51,7 @@ public class CPFTTreasuryTest extends TestBase {

@BeforeEach
public void setup() throws Exception {
tokenScore = sm.deploy(owner, CPFTreasury.class);
tokenScore = sm.deploy(owner, CPFTreasury.class,cpsScore.get());
}

@Test
Expand All @@ -76,7 +78,6 @@ public void setMaximumTreasuryFundBNUSDExceptions(Account address) {

@Test
void setCPSScore() {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setCpsScore", score_address);
Expand All @@ -86,7 +87,6 @@ void setCPSScore() {

@Test
void setCPSTreasuryScore() {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setCpsTreasuryScore", score_address);
Expand All @@ -96,7 +96,6 @@ void setCPSTreasuryScore() {

@Test
void setBMUSDScore() {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setBnUSDScore", score_address);
Expand All @@ -106,7 +105,6 @@ void setBMUSDScore() {

@Test
void setSICXScore() {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setSicxScore", score_address);
Expand All @@ -116,7 +114,6 @@ void setSICXScore() {

@Test
void setDEXScore() {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setDexScore", score_address);
Expand All @@ -126,7 +123,6 @@ void setDEXScore() {

@Test
void setRouterScore() {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setRouterScore", score_address);
Expand Down Expand Up @@ -175,7 +171,6 @@ void setDEXScoreExceptions(Account address, Address _score) {
}

void setRouterScoreExceptions(Account address, Address _score) {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(false);
tokenScore.invoke(address, "setRouterScore", _score);
Expand All @@ -186,7 +181,6 @@ void setRouterScoreExceptions(Account address, Address _score) {

@Test
void setCPSScoreNotAdmin() {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)){
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(false);
tokenScore.invoke(testing_account, "setCpsScore", score_address);
Expand Down Expand Up @@ -290,7 +284,6 @@ void updateProposalFund() {
}

void setMaxCapIcxAndBnusd() {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setMaximumTreasuryFundIcx", BigInteger.valueOf(2000).multiply(MULTIPLIER));
Expand All @@ -301,7 +294,6 @@ void setMaxCapIcxAndBnusd() {

@Test
void setMaxCapIcxAndBnusdTest() {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setMaximumTreasuryFundIcx", BigInteger.valueOf(2000).multiply(MULTIPLIER));
Expand All @@ -313,7 +305,6 @@ void setMaxCapIcxAndBnusdTest() {
void swapIcxBnusd() {
setSICXScoreMethod(sicxScore);
setBNUSDScoreMethod(bnUSDScore);
VarDB<Address> cpsScore = mock(VarDB.class);
VarDB<Address> routerScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
Expand Down Expand Up @@ -687,7 +678,6 @@ void fallbackSenderIsNotDex() {

@Test
void toggleSwapFlag(){
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner,"toggleSwapFlag");
Expand All @@ -697,7 +687,6 @@ void toggleSwapFlag(){

@Test
void transferToEmergencyFund(){
VarDB<Address> cpsScore = mock(VarDB.class);
VarDB<Address> balanceDollar = mock(VarDB.class);
BigInteger emergencyFund = BigInteger.valueOf(10).multiply(ICX);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)){
Expand All @@ -712,7 +701,6 @@ void transferToEmergencyFund(){
@Test
void withdrawFromEmergencyFund(){
transferToEmergencyFund();
VarDB<Address> cpsScore = mock(VarDB.class);
VarDB<Address> balanceDollar = mock(VarDB.class);
BigInteger withdrawAmount = BigInteger.valueOf(4).multiply(ICX);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)){
Expand All @@ -727,7 +715,6 @@ void withdrawFromEmergencyFund(){

@Test
void slippagePercentage() {
VarDB<Address> cpsScore = mock(VarDB.class);
int value = 10;
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
Expand All @@ -746,55 +733,48 @@ public void expectErrorMessage(Executable contractCall, String errorMessage) {
}

void setCPSScoreMethod(Address scoreAddress) {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setCpsScore", scoreAddress);
}
}

void setCPSTreasuryScoreMetod(Address scoreAddress) {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setCpsTreasuryScore", scoreAddress);
}
}

void setBNUSDScoreMethod(Address scoreAddress) {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setBnUSDScore", scoreAddress);
}
}

void setOracleAddressMethod(Address scoreAddress) {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setOracleAddress", scoreAddress);
}
}

void setSICXScoreMethod(Address scoreAddress) {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setSicxScore", scoreAddress);
}
}

void setDEXScoreMethod(Address scoreAddress) {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setDexScore", scoreAddress);
}
}

void setRouterScoreMethod(Address scoreAddress) {
VarDB<Address> cpsScore = mock(VarDB.class);
try (MockedStatic<Context> theMock = Mockito.mockStatic(Context.class)) {
theMock.when(() -> Context.call(cpsScore.get(), "isAdmin", Context.getCaller())).thenReturn(true);
tokenScore.invoke(owner, "setRouterScore", score_address);
Expand Down
Loading