use of co.rsk.db.RepositoryImplForTesting in project rskj by rsksmart.
the class RemascStorageProviderTest method setSaveRetrieveAndGetManySiblings.
@Test
public void setSaveRetrieveAndGetManySiblings() throws IOException {
RskAddress accountAddress = randomAddress();
Repository repository = new RepositoryImplForTesting();
RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block block1 = blockGenerator.createChildBlock(genesis);
Block block2 = blockGenerator.createChildBlock(block1);
Block block3 = blockGenerator.createChildBlock(block2);
Block block4 = blockGenerator.createChildBlock(block3);
Block block5 = blockGenerator.createChildBlock(block4);
Sibling sibling1 = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1);
Sibling sibling2 = new Sibling(block1.getHeader(), block1.getCoinbase(), 2);
Sibling sibling3 = new Sibling(block2.getHeader(), block2.getCoinbase(), 3);
Sibling sibling4 = new Sibling(block3.getHeader(), block3.getCoinbase(), 4);
Sibling sibling5 = new Sibling(block4.getHeader(), block4.getCoinbase(), 5);
Sibling sibling6 = new Sibling(block5.getHeader(), block5.getCoinbase(), 6);
List<Sibling> siblings0 = new ArrayList<>();
List<Sibling> siblings1 = new ArrayList<>();
List<Sibling> siblings2 = new ArrayList<>();
siblings0.add(sibling1);
siblings0.add(sibling2);
siblings1.add(sibling3);
siblings1.add(sibling4);
siblings2.add(sibling5);
siblings2.add(sibling6);
provider.getSiblings().put(Long.valueOf(0), siblings0);
provider.getSiblings().put(Long.valueOf(1), siblings1);
provider.getSiblings().put(Long.valueOf(2), siblings2);
provider.save();
RemascStorageProvider newProvider = new RemascStorageProvider(repository, accountAddress);
SortedMap<Long, List<Sibling>> map = newProvider.getSiblings();
Assert.assertNotNull(map);
Assert.assertFalse(map.isEmpty());
Assert.assertTrue(map.containsKey(Long.valueOf(0)));
Assert.assertTrue(map.containsKey(Long.valueOf(1)));
Assert.assertTrue(map.containsKey(Long.valueOf(2)));
Assert.assertEquals(2, map.get(Long.valueOf(0)).size());
Assert.assertEquals(2, map.get(Long.valueOf(1)).size());
Assert.assertEquals(2, map.get(Long.valueOf(2)).size());
List<Sibling> list0 = map.get(Long.valueOf(0));
List<Sibling> list1 = map.get(Long.valueOf(1));
List<Sibling> list2 = map.get(Long.valueOf(2));
Assert.assertEquals(1, list0.get(0).getIncludedHeight());
Assert.assertArrayEquals(genesis.getHeader().getHash().getBytes(), list0.get(0).getHash());
Assert.assertEquals(2, list0.get(1).getIncludedHeight());
Assert.assertArrayEquals(block1.getHeader().getHash().getBytes(), list0.get(1).getHash());
Assert.assertEquals(3, list1.get(0).getIncludedHeight());
Assert.assertArrayEquals(block2.getHeader().getHash().getBytes(), list1.get(0).getHash());
Assert.assertEquals(4, list1.get(1).getIncludedHeight());
Assert.assertArrayEquals(block3.getHeader().getHash().getBytes(), list1.get(1).getHash());
Assert.assertEquals(5, list2.get(0).getIncludedHeight());
Assert.assertArrayEquals(block4.getHeader().getHash().getBytes(), list2.get(0).getHash());
Assert.assertEquals(6, list2.get(1).getIncludedHeight());
Assert.assertArrayEquals(block5.getHeader().getHash().getBytes(), list2.get(1).getHash());
}
use of co.rsk.db.RepositoryImplForTesting in project rskj by rsksmart.
the class RemascStorageProviderTest method setSaveRetrieveAndGetBurnedBalance.
@Test
public void setSaveRetrieveAndGetBurnedBalance() throws IOException {
RskAddress accountAddress = randomAddress();
Repository repository = new RepositoryImplForTesting();
RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);
provider.setBurnedBalance(Coin.valueOf(255));
provider.save();
RemascStorageProvider newProvider = new RemascStorageProvider(repository, accountAddress);
Assert.assertEquals(Coin.valueOf(255), newProvider.getBurnedBalance());
}
use of co.rsk.db.RepositoryImplForTesting in project rskj by rsksmart.
the class RemascStorageProviderTest method setSaveRetrieveAndGetBrokenSelectionRule.
@Test
public void setSaveRetrieveAndGetBrokenSelectionRule() throws IOException {
RskAddress accountAddress = randomAddress();
Repository repository = new RepositoryImplForTesting();
RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);
provider.setBrokenSelectionRule(Boolean.TRUE);
provider.save();
RemascStorageProvider newProvider = new RemascStorageProvider(repository, accountAddress);
Assert.assertEquals(Boolean.TRUE, newProvider.getBrokenSelectionRule());
}
use of co.rsk.db.RepositoryImplForTesting in project rskj by rsksmart.
the class RepositoryBlockStoreTest method test.
@Test
public void test() throws Exception {
// This Is how I produced RepositoryBlockStore_data.ser. I had a bitcoind in regtest with 613 blocks + genesis block
// NetworkParameters params = RegTestParams.get();
// Context context = new Context(params);
// Wallet wallet = new Wallet(context);
// BlockStore store = new SPVBlockStore(params, new File("spvBlockstore"));
// AbstractBlockChain chain = new BlockChain(context, wallet, store);
// PeerGroup peerGroup = new PeerGroup(context, chain);
// peerGroup.start();
// final DownloadProgressTracker listener = new DownloadProgressTracker();
// peerGroup.startBlockChainDownload(listener);
// listener.await();
// peerGroup.stop();
// StoredBlock storedBlock = chain.getChainHead();
// FileOutputStream fos = new FileOutputStream("RepositoryBlockStore_data.ser");
// ObjectOutputStream oos = new ObjectOutputStream(fos);
// for (int i = 0; i < 614; i++) {
// Triple<byte[], BigInteger , Integer> tripleStoredBlock = new ImmutableTriple<>(storedBlock.getHeader().bitcoinSerialize(), storedBlock.getChainWork(), storedBlock.getHeight());
// oos.writeObject(tripleStoredBlock);
// storedBlock = store.get(storedBlock.getHeader().getPrevBlockHash());
// }
// oos.close();
// Read original store
InputStream fileInputStream = ClassLoader.getSystemResourceAsStream("peg/RepositoryBlockStore_data.ser");
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
Repository repository = new RepositoryImplForTesting();
RskSystemProperties config = new RskSystemProperties();
RepositoryBlockStore store = new RepositoryBlockStore(config, repository, PrecompiledContracts.BRIDGE_ADDR);
for (int i = 0; i < 614; i++) {
Triple<byte[], BigInteger, Integer> tripleStoredBlock = (Triple<byte[], BigInteger, Integer>) objectInputStream.readObject();
BtcBlock header = RegTestParams.get().getDefaultSerializer().makeBlock(tripleStoredBlock.getLeft());
StoredBlock storedBlock = new StoredBlock(header, tripleStoredBlock.getMiddle(), tripleStoredBlock.getRight());
if (i == 0) {
store.setChainHead(storedBlock);
}
store.put(storedBlock);
}
// Create a new instance of the store
RepositoryBlockStore store2 = new RepositoryBlockStore(config, repository, PrecompiledContracts.BRIDGE_ADDR);
// Check a specific block that used to fail when we had a bug
assertEquals(store.get(Sha256Hash.wrap("373941fe83961cf70e181e468abc5f9f7cc440c711c3d06948fa66f3912ed27a")), store2.get(Sha256Hash.wrap("373941fe83961cf70e181e468abc5f9f7cc440c711c3d06948fa66f3912ed27a")));
// Check new instance content is identical to the original one
StoredBlock storedBlock = store.getChainHead();
StoredBlock storedBlock2 = store2.getChainHead();
int headHeight = storedBlock.getHeight();
for (int i = 0; i < headHeight; i++) {
assertNotNull(storedBlock);
assertEquals(storedBlock, storedBlock2);
Sha256Hash prevBlockHash = storedBlock.getHeader().getPrevBlockHash();
storedBlock = store.get(prevBlockHash);
storedBlock2 = store2.get(prevBlockHash);
}
}
use of co.rsk.db.RepositoryImplForTesting in project rskj by rsksmart.
the class RemascStorageProviderTest method setSaveRetrieveAndGetRewardBalance.
@Test
public void setSaveRetrieveAndGetRewardBalance() throws IOException {
RskAddress accountAddress = randomAddress();
Repository repository = new RepositoryImplForTesting();
RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);
provider.setRewardBalance(Coin.valueOf(255));
provider.save();
RemascStorageProvider newProvider = new RemascStorageProvider(repository, accountAddress);
Assert.assertEquals(Coin.valueOf(255), newProvider.getRewardBalance());
}
Aggregations