Search in sources :

Example 1 with BootstrapDataEntry

use of co.rsk.db.importer.provider.index.data.BootstrapDataEntry in project rskj by rsksmart.

the class BootstrapDataProviderTest method retrieveData.

@Test
public void retrieveData() {
    BootstrapDataVerifier bootstrapDataVerifier = mock(BootstrapDataVerifier.class);
    when(bootstrapDataVerifier.verifyEntries(any())).thenReturn(2);
    BootstrapFileHandler bootstrapFileHandler = mock(BootstrapFileHandler.class);
    BootstrapIndexCandidateSelector bootstrapIndexCandidateSelector = mock(BootstrapIndexCandidateSelector.class);
    Map<String, BootstrapDataEntry> entries = new HashMap<>();
    BootstrapIndexCandidateSelector.HeightCandidate mchd = new BootstrapIndexCandidateSelector.HeightCandidate(1L, entries);
    when(bootstrapIndexCandidateSelector.getHeightData(any())).thenReturn(mchd);
    BootstrapDataProvider bootstrapDataProvider = new BootstrapDataProvider(bootstrapDataVerifier, bootstrapFileHandler, bootstrapIndexCandidateSelector, mock(BootstrapIndexRetriever.class), 2);
    bootstrapDataProvider.retrieveData();
}
Also used : BootstrapIndexRetriever(co.rsk.db.importer.provider.index.BootstrapIndexRetriever) HashMap(java.util.HashMap) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) BootstrapIndexCandidateSelector(co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector) Test(org.junit.Test)

Example 2 with BootstrapDataEntry

use of co.rsk.db.importer.provider.index.data.BootstrapDataEntry in project rskj by rsksmart.

the class BootstrapDataProviderTest method retrieveDataInsufficientsSources.

@Test(expected = BootstrapImportException.class)
public void retrieveDataInsufficientsSources() {
    BootstrapDataVerifier bootstrapDataVerifier = mock(BootstrapDataVerifier.class);
    when(bootstrapDataVerifier.verifyEntries(any())).thenReturn(1);
    BootstrapFileHandler bootstrapFileHandler = mock(BootstrapFileHandler.class);
    BootstrapIndexCandidateSelector bootstrapIndexCandidateSelector = mock(BootstrapIndexCandidateSelector.class);
    Map<String, BootstrapDataEntry> entries = new HashMap<>();
    BootstrapIndexCandidateSelector.HeightCandidate mchd = new BootstrapIndexCandidateSelector.HeightCandidate(1L, entries);
    when(bootstrapIndexCandidateSelector.getHeightData(any())).thenReturn(mchd);
    BootstrapDataProvider bootstrapDataProvider = new BootstrapDataProvider(bootstrapDataVerifier, bootstrapFileHandler, bootstrapIndexCandidateSelector, mock(BootstrapIndexRetriever.class), 2);
    bootstrapDataProvider.retrieveData();
}
Also used : BootstrapIndexRetriever(co.rsk.db.importer.provider.index.BootstrapIndexRetriever) HashMap(java.util.HashMap) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) BootstrapIndexCandidateSelector(co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector) Test(org.junit.Test)

Example 3 with BootstrapDataEntry

use of co.rsk.db.importer.provider.index.data.BootstrapDataEntry in project rskj by rsksmart.

the class BootstrapIndexCandidateSelectorTest method getMaximumCommonHeightDataThreeEntries.

@Test
public void getMaximumCommonHeightDataThreeEntries() {
    List<String> keys = Arrays.asList("key1", "key2");
    BootstrapIndexCandidateSelector indexMCH = new BootstrapIndexCandidateSelector(keys, 2);
    List<BootstrapDataIndex> indexes = new ArrayList<>();
    ArrayList<BootstrapDataEntry> entries = new ArrayList<>();
    ArrayList<BootstrapDataEntry> entries2 = new ArrayList<>();
    entries.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
    entries.add(new BootstrapDataEntry(2, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
    entries2.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
    indexes.add(new BootstrapDataIndex(entries));
    indexes.add(new BootstrapDataIndex(entries2));
    BootstrapIndexCandidateSelector.HeightCandidate heightCandidate = indexMCH.getHeightData(indexes);
    assertEquals(1, heightCandidate.getHeight());
}
Also used : BootstrapDataSignature(co.rsk.db.importer.provider.index.data.BootstrapDataSignature) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) ArrayList(java.util.ArrayList) BootstrapDataIndex(co.rsk.db.importer.provider.index.data.BootstrapDataIndex) Test(org.junit.Test)

Example 4 with BootstrapDataEntry

use of co.rsk.db.importer.provider.index.data.BootstrapDataEntry in project rskj by rsksmart.

the class BootstrapDataVerifierTest method verifyFileMany.

@Test
public void verifyFileMany() {
    BootstrapDataVerifier bootstrapDataVerifier = new BootstrapDataVerifier();
    HashMap<String, BootstrapDataEntry> entries = new HashMap<>();
    List<String> keys = new ArrayList<>();
    keys.add("04330037e82c177d7108077c80440821e13c1c62105f85e030214b48d7b5dff0b8e7c158b171546a71139e4de56c8535c964514033b89a669a8e87a5e8770c147c");
    keys.add("0473602083afe175e7cae12dbc27da54ec5ac77f99920787f3e891e7af303aaed480770c0de4c991aea1712729260175e158fa73f63c60f0f1de057139c52714de");
    keys.add("04bf74915a14e96df0b520a659acc28ae21aada3b0415e35f82f0c7b546338fc48bbfdce858ce3e4690feeb443d7f4955881ba0b793999e4fef7e46732e7fedf02");
    String hash = "53cb8e93030183c5ba198433e8cd1f013f3d113e0f4d1756de0d1f124ead155a";
    String r1 = "8dba957877d5bdcb26d551dfa2fa509dfe3fe327caf0166130b9f467a0a0c249";
    String s1 = "dab3fdf2031515d2de1d420310c69153fcc356f22b50dfd53c6e13e74e346eee";
    String r2 = "f0e8aab4fdd83382292a1bbc5480e2ae8084dc245f000f4bc4534d383a3a7919";
    String s2 = "a30891f2176bd87b4a3ac5c75167f2442453c17c6e2fbfb36c3b972ee67a4c2d";
    String r3 = "00";
    String s3 = "00";
    entries.put(keys.get(0), new BootstrapDataEntry(1, "", "dbPath", hash, new BootstrapDataSignature(r1, s1)));
    entries.put(keys.get(1), new BootstrapDataEntry(1, "", "dbPath", hash, new BootstrapDataSignature(r2, s2)));
    entries.put(keys.get(2), new BootstrapDataEntry(1, "", "dbPath", hash, new BootstrapDataSignature(r3, s3)));
    assertEquals(2, bootstrapDataVerifier.verifyEntries(entries));
}
Also used : BootstrapDataSignature(co.rsk.db.importer.provider.index.data.BootstrapDataSignature) HashMap(java.util.HashMap) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with BootstrapDataEntry

use of co.rsk.db.importer.provider.index.data.BootstrapDataEntry in project rskj by rsksmart.

the class BootstrapIndexRetrieverTest method retrievePublicKey.

@Test
public void retrievePublicKey() throws IOException {
    ObjectMapper objectMapper = mock(ObjectMapper.class);
    BootstrapDataIndex bdi = new BootstrapDataIndex(Collections.singletonList(new BootstrapDataEntry(1, "", "db", "hash", new BootstrapDataSignature("r", "s"))));
    when(objectMapper.readValue(any(URL.class), eq(BootstrapDataIndex.class))).thenReturn(bdi);
    BootstrapURLProvider bootstrapUrlProvider = mock(BootstrapURLProvider.class);
    when(bootstrapUrlProvider.getFullURL(any())).thenReturn(new URL("http://localhost"));
    BootstrapIndexRetriever bootstrapIndexRetriever = new BootstrapIndexRetriever(Collections.singletonList("key1"), bootstrapUrlProvider, objectMapper);
    List<BootstrapDataIndex> indices = bootstrapIndexRetriever.retrieve();
    Assert.assertTrue(indices.contains(bdi));
}
Also used : BootstrapDataSignature(co.rsk.db.importer.provider.index.data.BootstrapDataSignature) BootstrapDataEntry(co.rsk.db.importer.provider.index.data.BootstrapDataEntry) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BootstrapDataIndex(co.rsk.db.importer.provider.index.data.BootstrapDataIndex) URL(java.net.URL) BootstrapURLProvider(co.rsk.db.importer.BootstrapURLProvider) Test(org.junit.Test)

Aggregations

BootstrapDataEntry (co.rsk.db.importer.provider.index.data.BootstrapDataEntry)12 Test (org.junit.Test)10 BootstrapDataSignature (co.rsk.db.importer.provider.index.data.BootstrapDataSignature)9 BootstrapDataIndex (co.rsk.db.importer.provider.index.data.BootstrapDataIndex)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)4 BootstrapImportException (co.rsk.db.importer.BootstrapImportException)2 BootstrapIndexCandidateSelector (co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector)2 BootstrapIndexRetriever (co.rsk.db.importer.provider.index.BootstrapIndexRetriever)2 BootstrapURLProvider (co.rsk.db.importer.BootstrapURLProvider)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BigInteger (java.math.BigInteger)1 URL (java.net.URL)1 Map (java.util.Map)1 ECDSASignature (org.ethereum.crypto.signature.ECDSASignature)1