Search in sources :

Example 31 with RepositoryImpl

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

the class BridgeStorageProviderTest method createInstance.

@Test
public void createInstance() throws IOException {
    Repository repository = new RepositoryImpl(config);
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    Map<Sha256Hash, Long> processed = provider.getBtcTxHashesAlreadyProcessed();
    Assert.assertNotNull(processed);
    Assert.assertTrue(processed.isEmpty());
    ReleaseRequestQueue releaseRequestQueue = provider.getReleaseRequestQueue();
    Assert.assertNotNull(releaseRequestQueue);
    Assert.assertEquals(0, releaseRequestQueue.getEntries().size());
    ReleaseTransactionSet releaseTransactionSet = provider.getReleaseTransactionSet();
    Assert.assertNotNull(releaseTransactionSet);
    Assert.assertEquals(0, releaseTransactionSet.getEntries().size());
    SortedMap<Keccak256, BtcTransaction> signatures = provider.getRskTxsWaitingForSignatures();
    Assert.assertNotNull(signatures);
    Assert.assertTrue(signatures.isEmpty());
    List<UTXO> utxos = provider.getNewFederationBtcUTXOs();
    Assert.assertNotNull(utxos);
    Assert.assertTrue(utxos.isEmpty());
}
Also used : Keccak256(co.rsk.crypto.Keccak256) Repository(org.ethereum.core.Repository) RepositoryImpl(co.rsk.db.RepositoryImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 32 with RepositoryImpl

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

the class BridgeStorageProviderTest method createSaveAndRecreateInstance.

@Test
public void createSaveAndRecreateInstance() throws IOException {
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    provider0.getBtcTxHashesAlreadyProcessed();
    provider0.getReleaseRequestQueue();
    provider0.getReleaseTransactionSet();
    provider0.getRskTxsWaitingForSignatures();
    provider0.getNewFederationBtcUTXOs();
    provider0.getOldFederationBtcUTXOs();
    provider0.save();
    track.commit();
    track = repository.startTracking();
    RskAddress contractAddress = PrecompiledContracts.BRIDGE_ADDR;
    Assert.assertNotNull(repository.getContractDetails(contractAddress));
    Assert.assertNotNull(repository.getStorageBytes(contractAddress, new DataWord("btcTxHashesAP".getBytes())));
    Assert.assertNotNull(repository.getStorageBytes(contractAddress, new DataWord("releaseRequestQueue".getBytes())));
    Assert.assertNotNull(repository.getStorageBytes(contractAddress, new DataWord("releaseTransactionSet".getBytes())));
    Assert.assertNotNull(repository.getStorageBytes(contractAddress, new DataWord("rskTxsWaitingFS".getBytes())));
    Assert.assertNotNull(repository.getStorageBytes(contractAddress, new DataWord("newFederationBtcUTXOs".getBytes())));
    Assert.assertNotNull(repository.getStorageBytes(contractAddress, new DataWord("oldFederationBtcUTXOs".getBytes())));
    BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    Map<Sha256Hash, Long> processed = provider.getBtcTxHashesAlreadyProcessed();
    Assert.assertNotNull(processed);
    Assert.assertTrue(processed.isEmpty());
    ReleaseRequestQueue releaseRequestQueue = provider.getReleaseRequestQueue();
    Assert.assertNotNull(releaseRequestQueue);
    Assert.assertEquals(0, releaseRequestQueue.getEntries().size());
    ReleaseTransactionSet releaseTransactionSet = provider.getReleaseTransactionSet();
    Assert.assertNotNull(releaseTransactionSet);
    Assert.assertEquals(0, releaseTransactionSet.getEntries().size());
    SortedMap<Keccak256, BtcTransaction> signatures = provider.getRskTxsWaitingForSignatures();
    Assert.assertNotNull(signatures);
    Assert.assertTrue(signatures.isEmpty());
    List<UTXO> newUtxos = provider.getNewFederationBtcUTXOs();
    Assert.assertNotNull(newUtxos);
    Assert.assertTrue(newUtxos.isEmpty());
    List<UTXO> oldUtxos = provider.getOldFederationBtcUTXOs();
    Assert.assertNotNull(oldUtxos);
    Assert.assertTrue(oldUtxos.isEmpty());
}
Also used : DataWord(org.ethereum.vm.DataWord) Keccak256(co.rsk.crypto.Keccak256) Repository(org.ethereum.core.Repository) RepositoryImpl(co.rsk.db.RepositoryImpl) RskAddress(co.rsk.core.RskAddress) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 33 with RepositoryImpl

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

the class BridgeStorageProviderTest method setFeePerKb_savedAndRecreated.

@Test
public void setFeePerKb_savedAndRecreated() {
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    Coin expectedCoin = Coin.valueOf(5325);
    provider0.setFeePerKb(expectedCoin);
    provider0.saveFeePerKb();
    track.commit();
    track = repository.startTracking();
    BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    assertThat(provider.getFeePerKb(), is(expectedCoin));
}
Also used : Repository(org.ethereum.core.Repository) RepositoryImpl(co.rsk.db.RepositoryImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 34 with RepositoryImpl

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

the class BridgeStorageProviderTest method createSaveAndRecreateInstanceWithUTXOS.

@Test
public void createSaveAndRecreateInstanceWithUTXOS() throws IOException {
    Sha256Hash hash1 = PegTestUtils.createHash();
    Sha256Hash hash2 = PegTestUtils.createHash();
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    BridgeConstants bridgeConstants = config.getBlockchainConfig().getCommonConstants().getBridgeConstants();
    // Federation is the genesis federation ATM
    Federation federation = bridgeConstants.getGenesisFederation();
    BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    provider0.getNewFederationBtcUTXOs().add(new UTXO(hash1, 1, Coin.COIN, 0, false, ScriptBuilder.createOutputScript(federation.getAddress())));
    provider0.getNewFederationBtcUTXOs().add(new UTXO(hash2, 2, Coin.FIFTY_COINS, 0, false, ScriptBuilder.createOutputScript(federation.getAddress())));
    provider0.save();
    track.commit();
    track = repository.startTracking();
    BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    List<UTXO> utxos = provider.getNewFederationBtcUTXOs();
    Assert.assertTrue(utxos.get(0).getHash().equals(hash1));
    Assert.assertTrue(utxos.get(1).getHash().equals(hash2));
}
Also used : Repository(org.ethereum.core.Repository) RepositoryImpl(co.rsk.db.RepositoryImpl) BridgeConstants(co.rsk.config.BridgeConstants) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 35 with RepositoryImpl

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

the class BridgeSupportTest method callUpdateCollectionsThrowsCouldNotAdjustDownwards.

@Test
public void callUpdateCollectionsThrowsCouldNotAdjustDownwards() throws IOException, BlockStoreException {
    // Federation is the genesis federation ATM
    Federation federation = bridgeConstants.getGenesisFederation();
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    provider0.getReleaseRequestQueue().add(new BtcECKey().toAddress(btcParams), Coin.valueOf(37500));
    provider0.setFeePerKb(Coin.MILLICOIN);
    provider0.getNewFederationBtcUTXOs().add(new UTXO(PegTestUtils.createHash(), 1, Coin.valueOf(1000000), 0, false, ScriptBuilder.createOutputScript(federation.getAddress())));
    provider0.save();
    track.commit();
    track = repository.startTracking();
    BlockGenerator blockGenerator = new BlockGenerator();
    List<Block> blocks = blockGenerator.getSimpleBlockChain(blockGenerator.getGenesisBlock(), 10);
    BlockChainBuilder builder = new BlockChainBuilder();
    Blockchain blockchain = builder.setTesting(true).build();
    for (Block block : blocks) blockchain.getBlockStore().saveBlock(block, TEST_DIFFICULTY, true);
    org.ethereum.core.Block rskCurrentBlock = blocks.get(9);
    Transaction tx = Transaction.create(config, TO_ADDRESS, DUST_AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
    tx.sign(new ECKey().getPrivKeyBytes());
    BridgeSupport bridgeSupport = new BridgeSupport(config, track, mock(BridgeEventLogger.class), PrecompiledContracts.BRIDGE_ADDR, rskCurrentBlock);
    bridgeSupport.updateCollections(tx);
    bridgeSupport.save();
    track.commit();
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    Assert.assertEquals(1, provider.getReleaseRequestQueue().getEntries().size());
    Assert.assertEquals(0, provider.getReleaseTransactionSet().getEntries().size());
    Assert.assertEquals(0, provider.getRskTxsWaitingForSignatures().size());
    // Check the wallet has not been emptied
    Assert.assertFalse(provider.getNewFederationBtcUTXOs().isEmpty());
}
Also used : ECKey(org.ethereum.crypto.ECKey) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) org.ethereum.core(org.ethereum.core) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) RepositoryImpl(co.rsk.db.RepositoryImpl) BridgeEventLogger(co.rsk.peg.utils.BridgeEventLogger) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

RepositoryImpl (co.rsk.db.RepositoryImpl)62 Test (org.junit.Test)54 Repository (org.ethereum.core.Repository)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 RskAddress (co.rsk.core.RskAddress)19 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)16 HashMapDB (org.ethereum.datasource.HashMapDB)15 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)13 org.ethereum.core (org.ethereum.core)13 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)12 LogInfo (org.ethereum.vm.LogInfo)12 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)11 BridgeConstants (co.rsk.config.BridgeConstants)10 BridgeEventLogger (co.rsk.peg.utils.BridgeEventLogger)10 DataWord (org.ethereum.vm.DataWord)9 ArrayList (java.util.ArrayList)8 BtcBlockStore (co.rsk.bitcoinj.store.BtcBlockStore)7 ECKey (org.ethereum.crypto.ECKey)7 Keccak256 (co.rsk.crypto.Keccak256)6 SimpleBlockChain (co.rsk.peg.simples.SimpleBlockChain)6