Search in sources :

Example 1 with SimpleWallet

use of co.rsk.peg.simples.SimpleWallet in project rskj by rsksmart.

the class BridgeSupportTest method callUpdateCollectionsWithTransactionsWaitingForConfirmationWithEnoughConfirmations.

@Test
public void callUpdateCollectionsWithTransactionsWaitingForConfirmationWithEnoughConfirmations() throws IOException, BlockStoreException {
    // Bridge constants and btc context
    BridgeConstants bridgeConstants = config.getBlockchainConfig().getCommonConstants().getBridgeConstants();
    Context context = new Context(bridgeConstants.getBtcParams());
    // Fake wallet returned every time
    PowerMockito.mockStatic(BridgeUtils.class);
    PowerMockito.when(BridgeUtils.getFederationSpendWallet(any(Context.class), any(Federation.class), any(List.class))).thenReturn(new SimpleWallet(context));
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    BtcTransaction txs = new BtcTransaction(btcParams);
    txs.addOutput(Coin.FIFTY_COINS, new BtcECKey());
    BtcTransaction tx1 = new BtcTransaction(btcParams);
    tx1.addInput(txs.getOutput(0));
    tx1.getInput(0).disconnect();
    tx1.addOutput(Coin.COIN, new BtcECKey());
    BtcTransaction tx2 = new BtcTransaction(btcParams);
    tx2.addInput(txs.getOutput(0));
    tx2.getInput(0).disconnect();
    tx2.addOutput(Coin.COIN, new BtcECKey());
    BtcTransaction tx3 = new BtcTransaction(btcParams);
    tx3.addInput(txs.getOutput(0));
    tx3.getInput(0).disconnect();
    tx3.addOutput(Coin.COIN, new BtcECKey());
    provider0.getReleaseTransactionSet().add(tx1, 1L);
    provider0.getReleaseTransactionSet().add(tx2, 1L);
    provider0.getReleaseTransactionSet().add(tx3, 1L);
    provider0.save();
    track.commit();
    track = repository.startTracking();
    BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    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 rskTx = Transaction.create(config, TO_ADDRESS, DUST_AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
    rskTx.sign(new ECKey().getPrivKeyBytes());
    BridgeSupport bridgeSupport = new BridgeSupport(config, track, mock(BridgeEventLogger.class), provider, rskCurrentBlock);
    bridgeSupport.updateCollections(rskTx);
    bridgeSupport.save();
    track.commit();
    BridgeStorageProvider provider2 = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    Assert.assertEquals(0, provider2.getReleaseRequestQueue().getEntries().size());
    Assert.assertEquals(2, provider2.getReleaseTransactionSet().getEntries().size());
    Assert.assertEquals(1, provider2.getRskTxsWaitingForSignatures().size());
}
Also used : SimpleWallet(co.rsk.peg.simples.SimpleWallet) 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) RLPList(org.ethereum.util.RLPList) BridgeConstants(co.rsk.config.BridgeConstants) BridgeEventLogger(co.rsk.peg.utils.BridgeEventLogger) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)1 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)1 BridgeConstants (co.rsk.config.BridgeConstants)1 RepositoryImpl (co.rsk.db.RepositoryImpl)1 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)1 SimpleWallet (co.rsk.peg.simples.SimpleWallet)1 BridgeEventLogger (co.rsk.peg.utils.BridgeEventLogger)1 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)1 org.ethereum.core (org.ethereum.core)1 ECKey (org.ethereum.crypto.ECKey)1 RLPList (org.ethereum.util.RLPList)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1