Skip to content

Commit

Permalink
chore: added tests on cps treasury
Browse files Browse the repository at this point in the history
  • Loading branch information
naneey committed Mar 28, 2024
1 parent f9211c7 commit a64bfdf
Showing 1 changed file with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class CPSTreasuryTest extends TestBase {

@BeforeEach
public void setup() throws Exception {
tokenScore = sm.deploy(owner, CPSTreasury.class);
tokenScore = sm.deploy(owner, CPSTreasury.class, score_address);
CPSTreasury instance = (CPSTreasury) tokenScore.getInstance();
scoreSpy = spy(instance);
tokenScore.setInstance(scoreSpy);
Expand Down Expand Up @@ -569,4 +569,47 @@ void claimReward(){


}

@Test
void updateAddress(){
setOnsetPayment();
setCpsScoreMethod();

contextMock.when(caller()).thenReturn(score_address);
depositProposalFundMethod();

Address newContributorAddress = sm.createAccount().getAddress();
Address newSponsorAddress = sm.createAccount().getAddress();

contextMock.when(caller()).thenReturn(score_address);
tokenScore.invoke(testing_account,"updateContributorSponsorAddress", "Proposal 1",
newContributorAddress,newSponsorAddress);


Map<String,? > oldContributorData = (Map<String, ?>) tokenScore.call("getContributorProjectedFund", testing_account2.getAddress());
System.out.println("The data is empty: "+oldContributorData.get(DATA));

Map<String,? > oldSponsorData = (Map<String, ?>) tokenScore.call("getSponsorProjectedFund", testing_account.getAddress());
System.out.println("The data is empty: "+oldSponsorData.get(DATA));

doReturn(List.of(Map.of(
BUDGET,BigInteger.valueOf(50).multiply(ICX)
))).when(scoreSpy).callScore(List.class,score_address,"getRemainingMilestones","Proposal 1");
Map<String,? > newContributorData = (Map<String, ?>) tokenScore.call("getContributorProjectedFund", newContributorAddress);

List<Map<String, ?>> data = (List<Map<String, ?>>) newContributorData.get(DATA);
assertEquals(data.get(0).get("ipfs_hash"),"Proposal 1");
assertEquals(data.get(0).get("total_installment_paid"), new BigInteger("10000000000000000000"));


Map<String,? > newSponsorData = (Map<String, ?>) tokenScore.call("getSponsorProjectedFund", newSponsorAddress);
System.out.println(newSponsorData);
data = (List<Map<String, ?>>) newSponsorData.get(DATA);
assertEquals(data.get(0).get("ipfs_hash"),"Proposal 1");
assertEquals(data.get(0).get("total_installment_paid"), new BigInteger("200000000000000000"));
assertEquals(data.get(0).get("sponsor_bond_amount"), new BigInteger("15000000000000000000"));


}

}

0 comments on commit a64bfdf

Please sign in to comment.