Search in sources :

Example 11 with BtcLockSender

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

the class PeginInformationTest method parse_fromPeginInstructions_withoutBtcRefundAddress.

@Test
public void parse_fromPeginInstructions_withoutBtcRefundAddress() throws PeginInstructionsException {
    // Arrange
    BtcECKey address1Key = new BtcECKey();
    RskAddress rskDestinationAddressFromBtcLockSender = new RskAddress(ECKey.fromPublicOnly(address1Key.getPubKey()).getAddress());
    Address btcRefundAddressFromBtcLockSender = address1Key.toAddress(networkParameters);
    TxSenderAddressType senderBtcAddressType = TxSenderAddressType.P2PKH;
    BtcTransaction btcTx = new BtcTransaction(networkParameters);
    BtcLockSender btcLockSenderMock = mock(P2pkhBtcLockSender.class);
    when(btcLockSenderMock.getRskAddress()).thenReturn(rskDestinationAddressFromBtcLockSender);
    when(btcLockSenderMock.getBTCAddress()).thenReturn(btcRefundAddressFromBtcLockSender);
    when(btcLockSenderMock.getTxSenderAddressType()).thenReturn(senderBtcAddressType);
    BtcLockSenderProvider btcLockSenderProviderMock = mock(BtcLockSenderProvider.class);
    when(btcLockSenderProviderMock.tryGetBtcLockSender(btcTx)).thenReturn(Optional.of(btcLockSenderMock));
    BtcECKey address2Key = new BtcECKey();
    RskAddress rskDestinationAddressFromPeginInstructions = new RskAddress(ECKey.fromPublicOnly(address2Key.getPubKey()).getAddress());
    PeginInstructionsVersion1 peginInstructionsMock = mock(PeginInstructionsVersion1.class);
    when(peginInstructionsMock.getProtocolVersion()).thenReturn(1);
    when(peginInstructionsMock.getRskDestinationAddress()).thenReturn(rskDestinationAddressFromPeginInstructions);
    when(peginInstructionsMock.getBtcRefundAddress()).thenReturn(Optional.empty());
    PeginInstructionsProvider peginInstructionsProviderMock = mock(PeginInstructionsProvider.class);
    when(peginInstructionsProviderMock.buildPeginInstructions(btcTx)).thenReturn(Optional.of(peginInstructionsMock));
    ActivationConfig.ForBlock activationsMock = mock(ActivationConfig.ForBlock.class);
    when(activationsMock.isActive(ConsensusRule.RSKIP170)).thenReturn(true);
    // Act
    PeginInformation peginInformation = new PeginInformation(btcLockSenderProviderMock, peginInstructionsProviderMock, activationsMock);
    peginInformation.parse(btcTx);
    // Assert
    Assert.assertEquals(1, peginInformation.getProtocolVersion());
    Assert.assertEquals(rskDestinationAddressFromPeginInstructions, peginInformation.getRskDestinationAddress());
    Assert.assertEquals(btcRefundAddressFromBtcLockSender, peginInformation.getBtcRefundAddress());
    Assert.assertEquals(btcRefundAddressFromBtcLockSender, peginInformation.getSenderBtcAddress());
    Assert.assertEquals(senderBtcAddressType, peginInformation.getSenderBtcAddressType());
    Assert.assertNotEquals(rskDestinationAddressFromBtcLockSender, peginInformation.getRskDestinationAddress());
}
Also used : BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) PeginInstructionsVersion1(co.rsk.peg.pegininstructions.PeginInstructionsVersion1) Address(co.rsk.bitcoinj.core.Address) RskAddress(co.rsk.core.RskAddress) P2pkhBtcLockSender(co.rsk.peg.btcLockSender.P2pkhBtcLockSender) BtcLockSender(co.rsk.peg.btcLockSender.BtcLockSender) TxSenderAddressType(co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) RskAddress(co.rsk.core.RskAddress) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test)

Aggregations

BtcLockSender (co.rsk.peg.btcLockSender.BtcLockSender)11 BtcLockSenderProvider (co.rsk.peg.btcLockSender.BtcLockSenderProvider)10 RskAddress (co.rsk.core.RskAddress)8 PeginInstructionsProvider (co.rsk.peg.pegininstructions.PeginInstructionsProvider)8 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)8 Test (org.junit.Test)8 Address (co.rsk.bitcoinj.core.Address)5 BtcECKey (co.rsk.bitcoinj.core.BtcECKey)5 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)5 P2pkhBtcLockSender (co.rsk.peg.btcLockSender.P2pkhBtcLockSender)5 TxSenderAddressType (co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType)4 PeginInstructionsVersion1 (co.rsk.peg.pegininstructions.PeginInstructionsVersion1)4 Keccak256 (co.rsk.crypto.Keccak256)3 BigInteger (java.math.BigInteger)3 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)3 Repository (org.ethereum.core.Repository)3 ECKey (org.ethereum.crypto.ECKey)3 MutableRepository (org.ethereum.db.MutableRepository)3 InternalTransaction (org.ethereum.vm.program.InternalTransaction)3 PeginInstructions (co.rsk.peg.pegininstructions.PeginInstructions)1