use of org.aion.zero.impl.config.PruneConfig in project aion by aionnetwork.
the class TaskImportBlocksTest method testFilterBatch_wPruningRestrictions.
@Test
public void testFilterBatch_wPruningRestrictions() {
int current_count = 5, height = 10;
StandaloneBlockchain.Bundle bundle = builder.withValidatorConfiguration("simple").withDefaultAccounts(accounts).withRepoConfig(new RepositoryConfig() {
@Override
public String getDbPath() {
return "";
}
@Override
public PruneConfig getPruneConfig() {
// top pruning without archiving
return new PruneConfig() {
@Override
public boolean isEnabled() {
return true;
}
@Override
public boolean isArchived() {
return false;
}
@Override
public int getCurrentCount() {
return current_count;
}
@Override
public int getArchiveRate() {
return 0;
}
};
}
@Override
public Properties getDatabaseConfig(String db_name) {
Properties props = new Properties();
props.setProperty(DatabaseFactory.Props.DB_TYPE, DBVendor.MOCKDB.toValue());
return props;
}
}).build();
StandaloneBlockchain chain = bundle.bc;
// populate chain at random
generateRandomChain(chain, height, 1, accounts, 10);
// populate initial input lists
List<Block> allBlocks = new ArrayList<>();
Map<ByteArrayWrapper, Object> allHashes = new HashMap<>();
List<Block> unrestrictedBlocks = new ArrayList<>();
Map<ByteArrayWrapper, Object> unrestrictedHashes = new HashMap<>();
for (long i = 0; i <= height; i++) {
Block current = chain.getBlockByNumber(i);
allBlocks.add(current);
allHashes.put(ByteArrayWrapper.wrap(current.getHash()), true);
if (i >= height - current_count + 1) {
unrestrictedBlocks.add(current);
unrestrictedHashes.put(ByteArrayWrapper.wrap(current.getHash()), true);
}
}
// will filter out all blocks
assertThat(filterBatch(allBlocks, chain, allHashes)).isEmpty();
// will filter out all blocks
assertThat(filterBatch(allBlocks, chain, unrestrictedHashes)).isEmpty();
// will filter out the prune restricted blocks
assertThat(filterBatch(allBlocks, chain, new HashMap<>())).isEqualTo(unrestrictedBlocks);
}
Aggregations