use of org.ethereum.core.Repository in project rskj by rsksmart.
the class UpdateCollectionsTest method updateCollections_buildReleaseTxs.
private void updateCollections_buildReleaseTxs(ExecutionStats stats, int numCases) throws IOException {
final int minUTXOs = 1;
final int maxUTXOs = 1000;
final int minMilliBtc = 1;
final int maxMilliBtc = 1000;
final int minReleaseRequests = 1;
final int maxReleaseRequests = 100;
final int minMilliReleaseBtc = 10;
final int maxMilliReleaseBtc = 2000;
final NetworkParameters parameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);
BridgeStorageProviderInitializer storageInitializer = (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
Random rnd = new Random();
List<UTXO> utxos;
ReleaseRequestQueue queue;
try {
utxos = provider.getNewFederationBtcUTXOs();
} catch (Exception e) {
throw new RuntimeException("Unable to gather active federation btc utxos");
}
try {
queue = provider.getReleaseRequestQueue();
} catch (Exception e) {
throw new RuntimeException("Unable to gather release request queue");
}
// Generate some utxos
int numUTXOs = Helper.randomInRange(minUTXOs, maxUTXOs);
Script federationScript = BridgeRegTestConstants.getInstance().getGenesisFederation().getP2SHScript();
for (int i = 0; i < numUTXOs; i++) {
Sha256Hash hash = Sha256Hash.wrap(HashUtil.sha256(BigInteger.valueOf(rnd.nextLong()).toByteArray()));
Coin value = Coin.MILLICOIN.multiply(Helper.randomInRange(minMilliBtc, maxMilliBtc));
utxos.add(new UTXO(hash, 0, value, 1, false, federationScript));
}
// Generate some release requests to process
for (int i = 0; i < Helper.randomInRange(minReleaseRequests, maxReleaseRequests); i++) {
Coin value = Coin.MILLICOIN.multiply(Helper.randomInRange(minMilliReleaseBtc, maxMilliReleaseBtc));
queue.add(new BtcECKey().toAddress(parameters), value);
}
};
final byte[] updateCollectionsEncoded = Bridge.UPDATE_COLLECTIONS.encode();
ABIEncoder abiEncoder = (int executionIndex) -> updateCollectionsEncoded;
executeAndAverage("updateCollections-releaseRequests", numCases, abiEncoder, storageInitializer, Helper.getZeroValueRandomSenderTxBuilder(), Helper.getRandomHeightProvider(10), stats);
}
use of org.ethereum.core.Repository in project rskj by rsksmart.
the class UpdateCollectionsTest method updateCollections_confirmTxs.
private void updateCollections_confirmTxs(ExecutionStats stats, int numCases) throws IOException {
final int minTxsWaitingForSigs = 0;
final int maxTxsWaitingForSigs = 10;
final int minReleaseTxs = 1;
final int maxReleaseTxs = 100;
final int minBlockNumber = 10;
final int maxBlockNumber = 100;
final int minHeight = 50;
final int maxHeight = 150;
final int minCentOutput = 1;
final int maxCentOutput = 100;
final NetworkParameters parameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);
BridgeStorageProviderInitializer storageInitializer = (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
Random rnd = new Random();
SortedMap<Keccak256, BtcTransaction> txsWaitingForSignatures;
ReleaseTransactionSet txSet;
try {
txsWaitingForSignatures = provider.getRskTxsWaitingForSignatures();
} catch (Exception e) {
throw new RuntimeException("Unable to gather txs waiting for signatures");
}
try {
txSet = provider.getReleaseTransactionSet();
} catch (Exception e) {
throw new RuntimeException("Unable to gather release tx set");
}
// Generate some txs waiting for signatures
Script genesisFederationScript = bridgeConstants.getGenesisFederation().getP2SHScript();
for (int i = 0; i < Helper.randomInRange(minTxsWaitingForSigs, maxTxsWaitingForSigs); i++) {
Keccak256 rskHash = new Keccak256(HashUtil.keccak256(BigInteger.valueOf(rnd.nextLong()).toByteArray()));
BtcTransaction btcTx = new BtcTransaction(networkParameters);
Sha256Hash inputHash = Sha256Hash.wrap(HashUtil.sha256(BigInteger.valueOf(rnd.nextLong()).toByteArray()));
btcTx.addInput(inputHash, 0, genesisFederationScript);
btcTx.addOutput(Helper.randomCoin(Coin.CENT, minCentOutput, maxCentOutput), new BtcECKey());
txsWaitingForSignatures.put(rskHash, btcTx);
}
// Generate some txs waiting for confirmations
for (int i = 0; i < Helper.randomInRange(minReleaseTxs, maxReleaseTxs); i++) {
BtcTransaction btcTx = new BtcTransaction(networkParameters);
Sha256Hash inputHash = Sha256Hash.wrap(HashUtil.sha256(BigInteger.valueOf(rnd.nextLong()).toByteArray()));
btcTx.addInput(inputHash, 0, genesisFederationScript);
btcTx.addOutput(Helper.randomCoin(Coin.CENT, minCentOutput, maxCentOutput), new BtcECKey());
long blockNumber = Helper.randomInRange(minBlockNumber, maxBlockNumber);
txSet.add(btcTx, blockNumber);
}
};
final byte[] updateCollectionsEncoded = Bridge.UPDATE_COLLECTIONS.encode();
ABIEncoder abiEncoder = (int executionIndex) -> updateCollectionsEncoded;
HeightProvider heightProvider = (int executionIndex) -> Helper.randomInRange(minHeight, maxHeight);
executeAndAverage("updateCollections-releaseTxs", numCases, abiEncoder, storageInitializer, Helper.getZeroValueRandomSenderTxBuilder(), heightProvider, stats);
}
use of org.ethereum.core.Repository in project rskj by rsksmart.
the class RemascStorageProviderTest method setAndGetBrokenSelectionRule.
@Test
public void setAndGetBrokenSelectionRule() {
RskAddress accountAddress = randomAddress();
Repository repository = new RepositoryImpl(config);
RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);
provider.setBrokenSelectionRule(Boolean.TRUE);
Assert.assertEquals(Boolean.TRUE, provider.getBrokenSelectionRule());
}
use of org.ethereum.core.Repository 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 org.ethereum.core.Repository in project rskj by rsksmart.
the class RemascStorageProviderTest method setAndGetBurnedBalance.
@Test
public void setAndGetBurnedBalance() {
RskAddress accountAddress = randomAddress();
Repository repository = new RepositoryImpl(config);
RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);
provider.setBurnedBalance(Coin.valueOf(1));
Assert.assertEquals(Coin.valueOf(1), provider.getBurnedBalance());
}
Aggregations