Search in sources :

Example 6 with RepositoryImplForTesting

use of co.rsk.db.RepositoryImplForTesting in project rskj by rsksmart.

the class RemascStorageProviderTest method setSaveRetrieveAndGetSiblings.

@Test
public void setSaveRetrieveAndGetSiblings() throws IOException {
    RskAddress accountAddress = randomAddress();
    Repository repository = new RepositoryImplForTesting();
    RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block = blockGenerator.createChildBlock(genesis);
    Sibling sibling1 = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1);
    Sibling sibling2 = new Sibling(block.getHeader(), block.getCoinbase(), 2);
    List<Sibling> siblings = new ArrayList<>();
    siblings.add(sibling1);
    siblings.add(sibling2);
    provider.getSiblings().put(Long.valueOf(1), siblings);
    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(1)));
    Assert.assertEquals(2, map.get(Long.valueOf(1)).size());
}
Also used : Repository(org.ethereum.core.Repository) RskAddress(co.rsk.core.RskAddress) RepositoryImplForTesting(co.rsk.db.RepositoryImplForTesting) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) ArrayList(java.util.ArrayList) List(java.util.List) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

RepositoryImplForTesting (co.rsk.db.RepositoryImplForTesting)6 Repository (org.ethereum.core.Repository)6 Test (org.junit.Test)6 RskAddress (co.rsk.core.RskAddress)5 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Block (org.ethereum.core.Block)2 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)1 Sha256Hash (co.rsk.bitcoinj.core.Sha256Hash)1 StoredBlock (co.rsk.bitcoinj.core.StoredBlock)1 RskSystemProperties (co.rsk.config.RskSystemProperties)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 BigInteger (java.math.BigInteger)1 Triple (org.apache.commons.lang3.tuple.Triple)1