use of co.rsk.peg.pegininstructions.PeginInstructionsVersion1 in project rskj by rsksmart.
the class BridgeSupportTest method getPeginInstructionsProviderForVersion1.
private PeginInstructionsProvider getPeginInstructionsProviderForVersion1(RskAddress rskDestinationAddress, Optional<Address> btcRefundAddress) throws PeginInstructionsException {
PeginInstructionsVersion1 peginInstructions = mock(PeginInstructionsVersion1.class);
when(peginInstructions.getProtocolVersion()).thenReturn(1);
when(peginInstructions.getRskDestinationAddress()).thenReturn(rskDestinationAddress);
when(peginInstructions.getBtcRefundAddress()).thenReturn(btcRefundAddress);
PeginInstructionsProvider peginInstructionsProvider = mock(PeginInstructionsProvider.class);
when(peginInstructionsProvider.buildPeginInstructions(any())).thenReturn(Optional.of(peginInstructions));
return peginInstructionsProvider;
}
use of co.rsk.peg.pegininstructions.PeginInstructionsVersion1 in project rskj by rsksmart.
the class PeginInformationTest method parse_fromPeginInstructions_invalidProtocolVersion.
@Test(expected = PeginInstructionsException.class)
public void parse_fromPeginInstructions_invalidProtocolVersion() throws PeginInstructionsException {
// Arrange
BtcECKey address1Key = new BtcECKey();
RskAddress rskDestinationAddressFromBtcLockSender = new RskAddress(ECKey.fromPublicOnly(address1Key.getPubKey()).getAddress());
Address btcRefundAddressFromBtcLockSender = address1Key.toAddress(networkParameters);
BtcTransaction btcTx = new BtcTransaction(networkParameters);
BtcLockSender btcLockSenderMock = mock(P2pkhBtcLockSender.class);
when(btcLockSenderMock.getRskAddress()).thenReturn(rskDestinationAddressFromBtcLockSender);
when(btcLockSenderMock.getBTCAddress()).thenReturn(btcRefundAddressFromBtcLockSender);
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(0);
when(peginInstructionsMock.getRskDestinationAddress()).thenReturn(rskDestinationAddressFromPeginInstructions);
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);
}
use of co.rsk.peg.pegininstructions.PeginInstructionsVersion1 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());
}
use of co.rsk.peg.pegininstructions.PeginInstructionsVersion1 in project rskj by rsksmart.
the class PeginInformation method parseFromPeginInstructions.
private void parseFromPeginInstructions(PeginInstructions peginInstructions) throws PeginInstructionsException {
this.protocolVersion = peginInstructions.getProtocolVersion();
this.rskDestinationAddress = peginInstructions.getRskDestinationAddress();
logger.trace("[parseFromPeginInstructions] Protocol version: {}", peginInstructions.getProtocolVersion());
logger.trace("[parseFromPeginInstructions] RSK destination address: {}", peginInstructions.getRskDestinationAddress());
switch(protocolVersion) {
case 1:
PeginInstructionsVersion1 peginInstructionsV1 = (PeginInstructionsVersion1) peginInstructions;
parseFromPeginInstructionsVersion1(peginInstructionsV1);
break;
default:
String message = String.format("Invalid protocol version: %d", protocolVersion);
logger.warn("[parseFromPeginInstructions] {}", message);
throw new PeginInstructionsException(message);
}
}
Aggregations