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());
}
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());
}
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));
}
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));
}
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());
}
Aggregations