use of co.rsk.db.importer.provider.BootstrapDataProvider in project rskj by rsksmart.
the class BootstrapImporterTest method importData.
@Test
public void importData() throws IOException, URISyntaxException {
BlockStore blockStore = mock(BlockStore.class);
when(blockStore.getMaxNumber()).thenReturn(0L);
when(blockStore.isEmpty()).thenReturn(false);
BlockFactory blockFactory = mock(BlockFactory.class);
TrieStore trieStore = mock(TrieStore.class);
BootstrapDataProvider bootstrapDataProvider = mock(BootstrapDataProvider.class);
// using toURI() instead of getPath() prevent some errors on Windows
// (https://stackoverflow.com/questions/38887853/java-nio-file-invalidpathexception-with-getpath/38888561)
Path path = Paths.get(getClass().getClassLoader().getResource("import/bootstrap-data.bin").toURI());
byte[] oneBlockAndState = Files.readAllBytes(path);
when(bootstrapDataProvider.getBootstrapData()).thenReturn(oneBlockAndState);
when(bootstrapDataProvider.getSelectedHeight()).thenReturn(1L);
BootstrapImporter bootstrapImporter = new BootstrapImporter(blockStore, trieStore, blockFactory, bootstrapDataProvider);
bootstrapImporter.importData();
verify(blockFactory, atLeastOnce()).decodeBlock(any());
}
use of co.rsk.db.importer.provider.BootstrapDataProvider in project rskj by rsksmart.
the class RskContext method getBootstrapImporter.
public synchronized BootstrapImporter getBootstrapImporter() {
checkIfNotClosed();
if (bootstrapImporter == null) {
RskSystemProperties systemProperties = getRskSystemProperties();
List<String> publicKeys = systemProperties.importTrustedKeys();
int minimumRequired = publicKeys.size() / 2 + 1;
if (minimumRequired < 2) {
logger.warn("Configuration has less trusted sources than the minimum required {} of 2", minimumRequired);
minimumRequired = 2;
}
BootstrapURLProvider bootstrapUrlProvider = new BootstrapURLProvider(systemProperties.importUrl());
bootstrapImporter = new BootstrapImporter(getBlockStore(), getTrieStore(), blockFactory, new BootstrapDataProvider(new BootstrapDataVerifier(), new BootstrapFileHandler(bootstrapUrlProvider, new Unzipper()), new BootstrapIndexCandidateSelector(publicKeys, minimumRequired), new BootstrapIndexRetriever(publicKeys, bootstrapUrlProvider, new ObjectMapper()), minimumRequired));
}
return bootstrapImporter;
}
Aggregations