Search in sources :

Example 1 with BtcLockSenderProvider

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

the class BridgeSupportTestPowerMock method getBtcLockSenderProvider.

private BtcLockSenderProvider getBtcLockSenderProvider(TxSenderAddressType txSenderAddressType, Address btcAddress, RskAddress rskAddress) {
    BtcLockSender btcLockSender = mock(BtcLockSender.class);
    when(btcLockSender.getTxSenderAddressType()).thenReturn(txSenderAddressType);
    when(btcLockSender.getBTCAddress()).thenReturn(btcAddress);
    when(btcLockSender.getRskAddress()).thenReturn(rskAddress);
    BtcLockSenderProvider btcLockSenderProvider = mock(BtcLockSenderProvider.class);
    when(btcLockSenderProvider.tryGetBtcLockSender(any())).thenReturn(Optional.of(btcLockSender));
    return btcLockSenderProvider;
}
Also used : BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) BtcLockSender(co.rsk.peg.btcLockSender.BtcLockSender)

Example 2 with BtcLockSenderProvider

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

the class PeginInformationTest method parse_fromPeginInstructions.

@Test
public void parse_fromPeginInstructions() 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());
    Address btcRefundAddressFromPeginInstructions = address2Key.toAddress(networkParameters);
    PeginInstructionsVersion1 peginInstructionsMock = mock(PeginInstructionsVersion1.class);
    when(peginInstructionsMock.getProtocolVersion()).thenReturn(1);
    when(peginInstructionsMock.getRskDestinationAddress()).thenReturn(rskDestinationAddressFromPeginInstructions);
    when(peginInstructionsMock.getBtcRefundAddress()).thenReturn(Optional.of(btcRefundAddressFromPeginInstructions));
    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(btcRefundAddressFromPeginInstructions, peginInformation.getBtcRefundAddress());
    Assert.assertEquals(btcRefundAddressFromBtcLockSender, peginInformation.getSenderBtcAddress());
    Assert.assertEquals(senderBtcAddressType, peginInformation.getSenderBtcAddressType());
    Assert.assertNotEquals(rskDestinationAddressFromBtcLockSender, peginInformation.getRskDestinationAddress());
    Assert.assertNotEquals(btcRefundAddressFromBtcLockSender, peginInformation.getBtcRefundAddress());
}
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)

Example 3 with BtcLockSenderProvider

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

the class PeginInformationTest method parse_fromPeginInstructions_withoutBtcLockSender.

@Test
public void parse_fromPeginInstructions_withoutBtcLockSender() throws PeginInstructionsException {
    // Arrange
    BtcTransaction btcTx = new BtcTransaction(networkParameters);
    BtcLockSenderProvider btcLockSenderProviderMock = mock(BtcLockSenderProvider.class);
    when(btcLockSenderProviderMock.tryGetBtcLockSender(btcTx)).thenReturn(Optional.empty());
    BtcECKey address2Key = new BtcECKey();
    RskAddress rskDestinationAddressFromPeginInstructions = new RskAddress(ECKey.fromPublicOnly(address2Key.getPubKey()).getAddress());
    Address btcRefundAddressFromPeginInstructions = address2Key.toAddress(networkParameters);
    PeginInstructionsVersion1 peginInstructionsMock = mock(PeginInstructionsVersion1.class);
    when(peginInstructionsMock.getProtocolVersion()).thenReturn(1);
    when(peginInstructionsMock.getRskDestinationAddress()).thenReturn(rskDestinationAddressFromPeginInstructions);
    when(peginInstructionsMock.getBtcRefundAddress()).thenReturn(Optional.of(btcRefundAddressFromPeginInstructions));
    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(btcRefundAddressFromPeginInstructions, peginInformation.getBtcRefundAddress());
    Assert.assertNull(peginInformation.getSenderBtcAddress());
    Assert.assertEquals(TxSenderAddressType.UNKNOWN, peginInformation.getSenderBtcAddressType());
}
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) 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)

Example 4 with BtcLockSenderProvider

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

the class PeginInformationTest method parse_withoutBtcLockSender_withoutPeginInstructions.

@Test(expected = PeginInstructionsException.class)
public void parse_withoutBtcLockSender_withoutPeginInstructions() throws PeginInstructionsException {
    // Arrange
    BtcTransaction btcTx = new BtcTransaction(networkParameters);
    BtcLockSenderProvider btcLockSenderProviderMock = mock(BtcLockSenderProvider.class);
    when(btcLockSenderProviderMock.tryGetBtcLockSender(btcTx)).thenReturn(Optional.empty());
    PeginInstructionsProvider peginInstructionsProviderMock = mock(PeginInstructionsProvider.class);
    when(peginInstructionsProviderMock.buildPeginInstructions(btcTx)).thenReturn(Optional.empty());
    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);
}
Also used : BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test)

Example 5 with BtcLockSenderProvider

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

the class PeginInformationTest method parse_withoutBtcLockSender_withPeginInstructions_preIris.

@Test(expected = PeginInstructionsException.class)
public void parse_withoutBtcLockSender_withPeginInstructions_preIris() throws PeginInstructionsException {
    // Arrange
    BtcTransaction btcTx = new BtcTransaction(networkParameters);
    BtcLockSenderProvider btcLockSenderProviderMock = mock(BtcLockSenderProvider.class);
    when(btcLockSenderProviderMock.tryGetBtcLockSender(btcTx)).thenReturn(Optional.empty());
    BtcECKey address2Key = new BtcECKey();
    RskAddress rskDestinationAddressFromPeginInstructions = new RskAddress(ECKey.fromPublicOnly(address2Key.getPubKey()).getAddress());
    Address btcRefundAddressFromPeginInstructions = address2Key.toAddress(networkParameters);
    PeginInstructionsVersion1 peginInstructionsMock = mock(PeginInstructionsVersion1.class);
    when(peginInstructionsMock.getProtocolVersion()).thenReturn(1);
    when(peginInstructionsMock.getRskDestinationAddress()).thenReturn(rskDestinationAddressFromPeginInstructions);
    when(peginInstructionsMock.getBtcRefundAddress()).thenReturn(Optional.of(btcRefundAddressFromPeginInstructions));
    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(false);
    // Act
    PeginInformation peginInformation = new PeginInformation(btcLockSenderProviderMock, peginInstructionsProviderMock, activationsMock);
    peginInformation.parse(btcTx);
}
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) 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

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