Skip to content

Commit

Permalink
Refactor sorting and logging in JupiterDca tests
Browse files Browse the repository at this point in the history
Updated the sorting criterion in `getMostRecentJupiterDcaAccounts` to use creation timestamp and enhanced logging details. Added filtering to display only active JupiterDca accounts based on specific conditions and included the size of the filtered list in the logs.
  • Loading branch information
skynetcap committed Oct 2, 2024
1 parent 24abd1e commit 5c3780e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions jupiter/src/test/java/JupiterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public void testJupiterTestOracleDeserialization() throws RpcException {
assertTrue(testOracle.getPublishTime() > 0);
// Add more assertions as needed
}

@Test
public void testJupiterManager() {
JupiterManager manager = new JupiterManager(client);
Expand Down Expand Up @@ -357,10 +357,20 @@ public void testGetAllJupiterDcaAccounts() {
public void getMostRecentJupiterDcaAccounts() {
JupiterManager manager = new JupiterManager(client);
List<JupiterDca> dcaAccounts = manager.getAllDcaAccounts();
dcaAccounts.sort(Comparator.comparingLong(JupiterDca::getIdx).reversed());
dcaAccounts.sort(Comparator.comparingLong(JupiterDca::getCreatedAt).reversed());

for (int i = 0; i < 10; i++) {
JupiterDca dca = dcaAccounts.get(i);
log.info("DCA #{}: {}", i + 1, dca);
log.info("DCA {} #{}: {}", Instant.ofEpochSecond(dca.getCreatedAt()),i + 1, dca);
}

log.info("Only showing ones where nextCycleAt > createdAt && nextCycleAt > now && inUsed < inDeposited");
List<JupiterDca> activeDcas = dcaAccounts.stream()
.filter(dca -> dca.getNextCycleAt() > dca.getCreatedAt() && dca.getNextCycleAt() > Instant.now().getEpochSecond())
.filter(dca -> dca.getInUsed() < dca.getInDeposited())
.toList();

activeDcas.forEach(dca -> log.info("DCA {} #{}: {}", Instant.ofEpochSecond(dca.getCreatedAt()), dcaAccounts.indexOf(dca) + 1, dca));
log.info("Size: {}", activeDcas.size());
}
}

0 comments on commit 5c3780e

Please sign in to comment.