Search in sources :

Example 1 with ReleaseTransactionSet

use of co.rsk.peg.ReleaseTransactionSet 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);
}
Also used : Script(co.rsk.bitcoinj.script.Script) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) Keccak256(co.rsk.crypto.Keccak256) IOException(java.io.IOException) Repository(org.ethereum.core.Repository) Random(java.util.Random) ReleaseTransactionSet(co.rsk.peg.ReleaseTransactionSet) SortedMap(java.util.SortedMap)

Aggregations

Script (co.rsk.bitcoinj.script.Script)1 Keccak256 (co.rsk.crypto.Keccak256)1 BridgeStorageProvider (co.rsk.peg.BridgeStorageProvider)1 ReleaseTransactionSet (co.rsk.peg.ReleaseTransactionSet)1 IOException (java.io.IOException)1 Random (java.util.Random)1 SortedMap (java.util.SortedMap)1 Repository (org.ethereum.core.Repository)1