Search in sources :

Example 31 with BtcLockSenderProvider

use of co.rsk.peg.btcLockSender.BtcLockSenderProvider in project rskj by rsksmart.

the class BridgeSupportTest method registerFastBridgeBtcTransaction_surpasses_locking_cap_and_shouldTransfer_is_true.

@Test
public void registerFastBridgeBtcTransaction_surpasses_locking_cap_and_shouldTransfer_is_true() throws IOException, BlockStoreException, BridgeIllegalArgumentException {
    ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
    when(activations.isActive(ConsensusRule.RSKIP176)).thenReturn(true);
    when(activations.isActive(ConsensusRule.RSKIP134)).thenReturn(true);
    BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
    ReleaseTransactionSet releaseTransactionSet = new ReleaseTransactionSet(new HashSet<>());
    when(provider.getReleaseTransactionSet()).thenReturn(releaseTransactionSet);
    BtcLockSender btcLockSender = mock(BtcLockSender.class);
    BtcLockSenderProvider btcLockSenderProvider = mock(BtcLockSenderProvider.class);
    when(btcLockSenderProvider.tryGetBtcLockSender(any())).thenReturn(Optional.of(btcLockSender));
    Repository repository = mock(Repository.class);
    when(repository.getBalance(any())).thenReturn(co.rsk.core.Coin.valueOf(1));
    Context btcContext = mock(Context.class);
    when(btcContext.getParams()).thenReturn(bridgeConstants.getBtcParams());
    BridgeSupport bridgeSupport = spy(new BridgeSupport(bridgeConstants, provider, mock(BridgeEventLogger.class), btcLockSenderProvider, new PeginInstructionsProvider(), repository, mock(Block.class), btcContext, mock(FederationSupport.class), mock(BtcBlockStoreWithCache.Factory.class), activations));
    doReturn(bridgeConstants.getGenesisFederation()).when(bridgeSupport).getActiveFederation();
    doReturn(true).when(bridgeSupport).validationsForRegisterBtcTransaction(any(), anyInt(), any(), any());
    doReturn(Coin.COIN).when(bridgeSupport).getLockingCap();
    doReturn(PegTestUtils.createHash3(1)).when(bridgeSupport).getFastBridgeDerivationHash(any(Keccak256.class), any(Address.class), any(Address.class), any(RskAddress.class));
    Address btcAddress = Address.fromBase58(btcParams, "n3PLxDiwWqa5uH7fSbHCxS6VAjD9Y7Rwkj");
    ECKey key = ECKey.fromPublicOnly(new BtcECKey().getPubKey());
    RskAddress lbcAddress = new RskAddress(key.getAddress());
    BtcTransaction tx = createBtcTransactionWithOutputToAddress(Coin.COIN, getFastBridgeFederationAddress());
    byte[] pmtSerialized = Hex.decode("ab");
    InternalTransaction rskTx = new InternalTransaction(Keccak256.ZERO_HASH.getBytes(), 0, 0, null, null, null, lbcAddress.getBytes(), null, null, null, null);
    BigInteger result = bridgeSupport.registerFastBridgeBtcTransaction(rskTx, tx.bitcoinSerialize(), 100, pmtSerialized, PegTestUtils.createHash3(0), btcAddress, lbcAddress, btcAddress, true);
    Assert.assertEquals(BigInteger.valueOf(BridgeSupport.FAST_BRIDGE_REFUNDED_LP_ERROR_CODE), result);
}
Also used : RskAddress(co.rsk.core.RskAddress) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) ECKey(org.ethereum.crypto.ECKey) Keccak256(co.rsk.crypto.Keccak256) InternalTransaction(org.ethereum.vm.program.InternalTransaction) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) BtcLockSender(co.rsk.peg.btcLockSender.BtcLockSender) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 32 with BtcLockSenderProvider

use of co.rsk.peg.btcLockSender.BtcLockSenderProvider in project rskj by rsksmart.

the class BridgeSupportTest method eventLoggerLogPeginBtc_after_rskip_170_activation.

@Test
public void eventLoggerLogPeginBtc_after_rskip_170_activation() throws Exception {
    ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
    when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
    when(activations.isActive(ConsensusRule.RSKIP170)).thenReturn(true);
    BridgeEventLogger mockedEventLogger = mock(BridgeEventLogger.class);
    BridgeStorageProvider mockBridgeStorageProvider = mock(BridgeStorageProvider.class);
    when(mockBridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(any(Sha256Hash.class))).thenReturn(Optional.empty());
    LockWhitelist lockWhitelist = mock(LockWhitelist.class);
    when(lockWhitelist.isWhitelistedFor(any(Address.class), any(Coin.class), any(int.class))).thenReturn(true);
    when(mockBridgeStorageProvider.getLockWhitelist()).thenReturn(lockWhitelist);
    when(mockBridgeStorageProvider.getNewFederation()).thenReturn(bridgeConstants.getGenesisFederation());
    Block executionBlock = mock(Block.class);
    BtcBlockStoreWithCache.Factory btcBlockStoreFactory = mock(BtcBlockStoreWithCache.Factory.class);
    BtcBlockStoreWithCache btcBlockStore = mock(BtcBlockStoreWithCache.class);
    when(btcBlockStoreFactory.newInstance(any(Repository.class), any(), any(), any())).thenReturn(btcBlockStore);
    // Create transaction
    Coin lockValue = Coin.COIN;
    BtcTransaction tx = new BtcTransaction(bridgeConstants.getBtcParams());
    tx.addOutput(lockValue, mockBridgeStorageProvider.getNewFederation().getAddress());
    BtcECKey srcKey = new BtcECKey();
    tx.addInput(PegTestUtils.createHash(1), 0, ScriptBuilder.createInputScript(null, srcKey));
    // Create header and PMT
    byte[] bits = new byte[1];
    bits[0] = 0x3f;
    List<Sha256Hash> hashes = new ArrayList<>();
    hashes.add(tx.getHash());
    PartialMerkleTree pmt = new PartialMerkleTree(bridgeConstants.getBtcParams(), bits, hashes, 1);
    Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(new ArrayList<>());
    co.rsk.bitcoinj.core.BtcBlock btcBlock = new co.rsk.bitcoinj.core.BtcBlock(bridgeConstants.getBtcParams(), 1, PegTestUtils.createHash(), merkleRoot, 1, 1, 1, new ArrayList<>());
    int height = 1;
    mockChainOfStoredBlocks(btcBlockStore, btcBlock, height + bridgeConstants.getBtc2RskMinimumAcceptableConfirmations(), height);
    BridgeSupport bridgeSupport = bridgeSupportBuilder.withBridgeConstants(bridgeConstants).withProvider(mockBridgeStorageProvider).withEventLogger(mockedEventLogger).withBtcLockSenderProvider(new BtcLockSenderProvider()).withPeginInstructionsProvider(new PeginInstructionsProvider()).withExecutionBlock(executionBlock).withBtcBlockStoreFactory(btcBlockStoreFactory).withActivations(activations).build();
    bridgeSupport.registerBtcTransaction(mock(Transaction.class), tx.bitcoinSerialize(), height, pmt.bitcoinSerialize());
    verify(mockedEventLogger, never()).logLockBtc(any(RskAddress.class), any(BtcTransaction.class), any(Address.class), any(Coin.class));
    verify(mockedEventLogger, atLeastOnce()).logPeginBtc(any(RskAddress.class), any(BtcTransaction.class), any(Coin.class), anyInt());
}
Also used : RskAddress(co.rsk.core.RskAddress) BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) LockWhitelist(co.rsk.peg.whitelist.LockWhitelist) RskAddress(co.rsk.core.RskAddress) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) Block(org.ethereum.core.Block) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 33 with BtcLockSenderProvider

use of co.rsk.peg.btcLockSender.BtcLockSenderProvider in project rskj by rsksmart.

the class BridgeSupportTest method eventLoggerLogPeginRejectionEvents_before_rskip_181_activation.

@Test
public void eventLoggerLogPeginRejectionEvents_before_rskip_181_activation() throws Exception {
    ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
    when(activations.isActive(ConsensusRule.RSKIP170)).thenReturn(true);
    when(activations.isActive(ConsensusRule.RSKIP181)).thenReturn(false);
    BridgeEventLogger mockedEventLogger = mock(BridgeEventLogger.class);
    BridgeStorageProvider mockBridgeStorageProvider = mock(BridgeStorageProvider.class);
    when(mockBridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(any(Sha256Hash.class))).thenReturn(Optional.empty());
    LockWhitelist lockWhitelist = mock(LockWhitelist.class);
    when(lockWhitelist.isWhitelistedFor(any(Address.class), any(Coin.class), any(int.class))).thenReturn(true);
    when(mockBridgeStorageProvider.getLockWhitelist()).thenReturn(lockWhitelist);
    when(mockBridgeStorageProvider.getNewFederation()).thenReturn(bridgeConstants.getGenesisFederation());
    Block executionBlock = mock(Block.class);
    BtcBlockStoreWithCache.Factory btcBlockStoreFactory = mock(BtcBlockStoreWithCache.Factory.class);
    BtcBlockStoreWithCache btcBlockStore = mock(BtcBlockStoreWithCache.class);
    when(btcBlockStoreFactory.newInstance(any(Repository.class), any(), any(), any())).thenReturn(btcBlockStore);
    // Create transaction
    Coin lockValue = Coin.COIN;
    BtcTransaction tx = new BtcTransaction(bridgeConstants.getBtcParams());
    tx.addOutput(lockValue, mockBridgeStorageProvider.getNewFederation().getAddress());
    BtcECKey srcKey = new BtcECKey();
    tx.addInput(PegTestUtils.createHash(1), 0, ScriptBuilder.createInputScript(null, srcKey));
    // Create header and PMT
    byte[] bits = new byte[1];
    bits[0] = 0x3f;
    List<Sha256Hash> hashes = new ArrayList<>();
    hashes.add(tx.getHash());
    PartialMerkleTree pmt = new PartialMerkleTree(bridgeConstants.getBtcParams(), bits, hashes, 1);
    Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(new ArrayList<>());
    co.rsk.bitcoinj.core.BtcBlock btcBlock = new co.rsk.bitcoinj.core.BtcBlock(bridgeConstants.getBtcParams(), 1, PegTestUtils.createHash(), merkleRoot, 1, 1, 1, new ArrayList<>());
    int height = 1;
    mockChainOfStoredBlocks(btcBlockStore, btcBlock, height + bridgeConstants.getBtc2RskMinimumAcceptableConfirmations(), height);
    BtcLockSenderProvider btcLockSenderProvider = mock(BtcLockSenderProvider.class);
    when(btcLockSenderProvider.tryGetBtcLockSender(any(BtcTransaction.class))).thenReturn(Optional.empty());
    PeginInstructionsProvider peginInstructionsProvider = mock(PeginInstructionsProvider.class);
    when(peginInstructionsProvider.buildPeginInstructions(any(BtcTransaction.class))).thenReturn(Optional.empty());
    BridgeSupport bridgeSupport = bridgeSupportBuilder.withBridgeConstants(bridgeConstants).withProvider(mockBridgeStorageProvider).withEventLogger(mockedEventLogger).withBtcLockSenderProvider(btcLockSenderProvider).withPeginInstructionsProvider(new PeginInstructionsProvider()).withExecutionBlock(executionBlock).withBtcBlockStoreFactory(btcBlockStoreFactory).withActivations(activations).build();
    bridgeSupport.registerBtcTransaction(mock(Transaction.class), tx.bitcoinSerialize(), height, pmt.bitcoinSerialize());
    verify(mockedEventLogger, never()).logRejectedPegin(any(BtcTransaction.class), any(RejectedPeginReason.class));
    verify(mockedEventLogger, never()).logUnrefundablePegin(any(BtcTransaction.class), any(UnrefundablePeginReason.class));
}
Also used : RskAddress(co.rsk.core.RskAddress) BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) LockWhitelist(co.rsk.peg.whitelist.LockWhitelist) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) Block(org.ethereum.core.Block) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 34 with BtcLockSenderProvider

use of co.rsk.peg.btcLockSender.BtcLockSenderProvider in project rskj by rsksmart.

the class BridgeSupportTest method registerBtcTransaction_sending_segwit_tx_twice_locks_just_once.

@Test
public void registerBtcTransaction_sending_segwit_tx_twice_locks_just_once() throws BlockStoreException, IOException, BridgeIllegalArgumentException {
    ActivationConfig.ForBlock mockedActivations = mock(ActivationConfig.ForBlock.class);
    when(mockedActivations.isActive(ConsensusRule.RSKIP143)).thenReturn(true);
    BtcTransaction txWithWitness = new BtcTransaction(btcParams);
    // first input spends P2PKH
    BtcECKey srcKey1 = new BtcECKey();
    txWithWitness.addInput(PegTestUtils.createHash(1), 0, ScriptBuilder.createInputScript(null, srcKey1));
    // second input spends P2SH-P2PWKH (actually, just has a witness doesn't matter if it truly spends a witness for the test's sake)
    txWithWitness.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[] {}));
    TransactionWitness txWit = new TransactionWitness(1);
    txWit.setPush(0, new byte[] {});
    txWithWitness.setWitness(0, txWit);
    List<BtcECKey> fedKeys = Arrays.asList(BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02")));
    Federation fed = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(fedKeys), Instant.ofEpochMilli(1000L), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST));
    txWithWitness.addOutput(Coin.COIN.multiply(5), fed.getAddress());
    // Create the pmt without witness and calculate the block merkle root
    byte[] bits = new byte[1];
    bits[0] = 0x3f;
    PartialMerkleTree pmtWithoutWitness = new PartialMerkleTree(btcParams, bits, Collections.singletonList(txWithWitness.getHash()), 1);
    Sha256Hash merkleRoot = pmtWithoutWitness.getTxnHashAndMerkleRoot(new ArrayList<>());
    PartialMerkleTree pmtWithWitness = new PartialMerkleTree(btcParams, bits, Collections.singletonList(txWithWitness.getHash(true)), 1);
    Sha256Hash witnessMerkleRoot = pmtWithWitness.getTxnHashAndMerkleRoot(new ArrayList<>());
    co.rsk.bitcoinj.core.BtcBlock registerHeader = new co.rsk.bitcoinj.core.BtcBlock(btcParams, 1, PegTestUtils.createHash(1), merkleRoot, 1, 1, 1, new ArrayList<>());
    BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
    when(provider.getNewFederation()).thenReturn(fed);
    when(provider.getCoinbaseInformation(registerHeader.getHash())).thenReturn(new CoinbaseInformation(witnessMerkleRoot));
    when(provider.getLockWhitelist()).thenReturn(new LockWhitelist(new HashMap<>(), 0));
    when(provider.getLockingCap()).thenReturn(Coin.FIFTY_COINS);
    // mock an actual store for the processed txs
    HashMap<Sha256Hash, Long> processedTxs = new HashMap<>();
    doAnswer(a -> {
        processedTxs.put(a.getArgument(0), a.getArgument(1));
        return null;
    }).when(provider).setHeightBtcTxhashAlreadyProcessed(any(), anyLong());
    doAnswer(a -> Optional.ofNullable(processedTxs.get(a.getArgument(0)))).when(provider).getHeightIfBtcTxhashIsAlreadyProcessed(any());
    BtcBlockStoreWithCache btcBlockStore = mock(BtcBlockStoreWithCache.class);
    BtcBlockStoreWithCache.Factory mockFactory = mock(BtcBlockStoreWithCache.Factory.class);
    when(mockFactory.newInstance(any(), any(), any(), any())).thenReturn(btcBlockStore);
    Block executionBlock = mock(Block.class);
    when(executionBlock.getNumber()).thenReturn(666L);
    BridgeSupport bridgeSupport = bridgeSupportBuilder.withBridgeConstants(bridgeConstants).withProvider(provider).withBtcLockSenderProvider(new BtcLockSenderProvider()).withPeginInstructionsProvider(new PeginInstructionsProvider()).withExecutionBlock(executionBlock).withBtcBlockStoreFactory(mockFactory).withActivations(mockedActivations).build();
    int height = 30;
    mockChainOfStoredBlocks(btcBlockStore, registerHeader, 35, height);
    // Tx is locked
    bridgeSupport.registerBtcTransaction(mock(Transaction.class), txWithWitness.bitcoinSerialize(), height, pmtWithWitness.bitcoinSerialize());
    verify(provider, never()).setHeightBtcTxhashAlreadyProcessed(txWithWitness.getHash(true), executionBlock.getNumber());
    verify(provider, times(1)).setHeightBtcTxhashAlreadyProcessed(txWithWitness.getHash(false), executionBlock.getNumber());
    BtcTransaction txWithoutWitness = new BtcTransaction(btcParams, txWithWitness.bitcoinSerialize());
    txWithoutWitness.setWitness(0, null);
    assertFalse(txWithoutWitness.hasWitness());
    // Tx is NOT locked again!
    bridgeSupport.registerBtcTransaction(mock(Transaction.class), txWithoutWitness.bitcoinSerialize(), height, pmtWithoutWitness.bitcoinSerialize());
    verify(provider, times(1)).setHeightBtcTxhashAlreadyProcessed(txWithoutWitness.getHash(), executionBlock.getNumber());
    assertNotEquals(txWithWitness.getHash(true), txWithoutWitness.getHash());
}
Also used : BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) LockWhitelist(co.rsk.peg.whitelist.LockWhitelist) PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(co.rsk.peg.PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation) PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation(co.rsk.peg.PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation) Script(co.rsk.bitcoinj.script.Script) CoinbaseInformation(co.rsk.peg.bitcoin.CoinbaseInformation) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) Block(org.ethereum.core.Block) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 35 with BtcLockSenderProvider

use of co.rsk.peg.btcLockSender.BtcLockSenderProvider in project rskj by rsksmart.

the class BridgeSupportTest method when_registerBtcTransaction_usesLegacyType_afterFork_lock_and_no_refund.

@Test
public void when_registerBtcTransaction_usesLegacyType_afterFork_lock_and_no_refund() throws Exception {
    ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
    when(activations.isActive(ConsensusRule.RSKIP143)).thenReturn(true);
    Federation federation1 = getFederation(bridgeConstants);
    Repository repository = createRepository();
    repository.addBalance(PrecompiledContracts.BRIDGE_ADDR, LIMIT_MONETARY_BASE);
    Block executionBlock = mock(Block.class);
    when(executionBlock.getNumber()).thenReturn(10L);
    BtcECKey srcKey1 = new BtcECKey();
    ECKey key = ECKey.fromPublicOnly(srcKey1.getPubKey());
    Address btcAddress = srcKey1.toAddress(btcParams);
    RskAddress rskAddress = new RskAddress(key.getAddress());
    // First transaction goes only to the first federation
    BtcTransaction tx1 = new BtcTransaction(btcParams);
    tx1.addOutput(Coin.COIN.multiply(5), federation1.getAddress());
    tx1.addInput(PegTestUtils.createHash(1), 0, ScriptBuilder.createInputScript(null, srcKey1));
    BtcBlockStoreWithCache btcBlockStore = mock(BtcBlockStoreWithCache.class);
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, contractAddress, bridgeConstants, activations);
    provider.setNewFederation(federation1);
    // Whitelist the addresses
    LockWhitelist whitelist = provider.getLockWhitelist();
    whitelist.put(btcAddress, new OneOffWhiteListEntry(btcAddress, Coin.COIN.multiply(5)));
    BtcBlockStoreWithCache.Factory mockFactory = mock(BtcBlockStoreWithCache.Factory.class);
    when(mockFactory.newInstance(repository, bridgeConstants, provider, activations)).thenReturn(btcBlockStore);
    BtcLockSenderProvider btcLockSenderProvider = getBtcLockSenderProvider(TxSenderAddressType.P2PKH, btcAddress, rskAddress);
    BridgeSupport bridgeSupport = getBridgeSupport(bridgeConstants, provider, repository, btcLockSenderProvider, new PeginInstructionsProvider(), executionBlock, mockFactory, activations);
    byte[] bits = new byte[1];
    bits[0] = 0x3f;
    List<Sha256Hash> hashes = new ArrayList<>();
    hashes.add(tx1.getHash());
    PartialMerkleTree pmt = new PartialMerkleTree(btcParams, bits, hashes, 1);
    List<Sha256Hash> hashlist = new ArrayList<>();
    Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashlist);
    co.rsk.bitcoinj.core.BtcBlock registerHeader = new co.rsk.bitcoinj.core.BtcBlock(btcParams, 1, PegTestUtils.createHash(1), merkleRoot, 1, 1, 1, new ArrayList<>());
    int height = 30;
    mockChainOfStoredBlocks(btcBlockStore, registerHeader, 35, height);
    bridgeSupport.registerBtcTransaction(mock(Transaction.class), tx1.bitcoinSerialize(), height, pmt.bitcoinSerialize());
    co.rsk.core.Coin totalAmountExpectedToHaveBeenLocked = co.rsk.core.Coin.fromBitcoin(Coin.valueOf(5, 0));
    Assert.assertThat(whitelist.isWhitelisted(btcAddress), is(false));
    Assert.assertEquals(totalAmountExpectedToHaveBeenLocked, repository.getBalance(rskAddress));
    Assert.assertEquals(LIMIT_MONETARY_BASE.subtract(totalAmountExpectedToHaveBeenLocked), repository.getBalance(PrecompiledContracts.BRIDGE_ADDR));
    Assert.assertEquals(1, provider.getNewFederationBtcUTXOs().size());
    Assert.assertEquals(Coin.COIN.multiply(5), provider.getNewFederationBtcUTXOs().get(0).getValue());
    Assert.assertEquals(0, provider.getReleaseRequestQueue().getEntries().size());
    Assert.assertEquals(0, provider.getReleaseTransactionSet().getEntries().size());
    Assert.assertTrue(provider.getRskTxsWaitingForSignatures().isEmpty());
    Assert.assertTrue(provider.getHeightIfBtcTxhashIsAlreadyProcessed(tx1.getHash()).isPresent());
}
Also used : RskAddress(co.rsk.core.RskAddress) ECKey(org.ethereum.crypto.ECKey) BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) LockWhitelist(co.rsk.peg.whitelist.LockWhitelist) PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(co.rsk.peg.PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation) PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation(co.rsk.peg.PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation) RskAddress(co.rsk.core.RskAddress) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) Block(org.ethereum.core.Block) OneOffWhiteListEntry(co.rsk.peg.whitelist.OneOffWhiteListEntry) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Aggregations

BtcLockSenderProvider (co.rsk.peg.btcLockSender.BtcLockSenderProvider)56 PeginInstructionsProvider (co.rsk.peg.pegininstructions.PeginInstructionsProvider)51 Test (org.junit.Test)49 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)47 RskAddress (co.rsk.core.RskAddress)41 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)40 MutableRepository (org.ethereum.db.MutableRepository)40 Repository (org.ethereum.core.Repository)38 Block (org.ethereum.core.Block)35 InternalTransaction (org.ethereum.vm.program.InternalTransaction)35 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)28 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)26 Transaction (org.ethereum.core.Transaction)26 PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation)22 PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation)22 ECKey (org.ethereum.crypto.ECKey)21 LockWhitelist (co.rsk.peg.whitelist.LockWhitelist)15 Script (co.rsk.bitcoinj.script.Script)14 BtcLockSender (co.rsk.peg.btcLockSender.BtcLockSender)10 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)9