use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.
the class BridgeSupportReleaseBtcTest method handmade_release_after_rskip_146_rejected_contractCaller.
@Test
public void handmade_release_after_rskip_146_rejected_contractCaller() throws IOException {
when(activationMock.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
when(activationMock.isActive(ConsensusRule.RSKIP185)).thenReturn(false);
List<LogInfo> logInfo = new ArrayList<>();
BridgeEventLoggerImpl eventLogger = new BridgeEventLoggerImpl(bridgeConstants, activationMock, logInfo);
bridgeSupport = initBridgeSupport(eventLogger, activationMock);
releaseTx = buildReleaseRskTx_fromContract(Coin.COIN);
try {
bridgeSupport.releaseBtc(releaseTx);
fail();
} catch (Program.OutOfGasException e) {
assertTrue(e.getMessage().contains("Contract calling releaseBTC"));
}
}
use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.
the class BridgeSupportReleaseBtcTest method release_after_rskip_219_minimum_inclusive.
@Test
public void release_after_rskip_219_minimum_inclusive() throws IOException {
when(activationMock.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
when(activationMock.isActive(ConsensusRule.RSKIP185)).thenReturn(true);
when(activationMock.isActive(ConsensusRule.RSKIP219)).thenReturn(true);
List<LogInfo> logInfo = new ArrayList<>();
BridgeEventLoggerImpl eventLogger = spy(new BridgeEventLoggerImpl(bridgeConstants, activationMock, logInfo));
bridgeSupport = initBridgeSupport(eventLogger, activationMock);
// Get a value exactly to current minimum
Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis();
bridgeSupport.releaseBtc(buildReleaseRskTx(value));
Transaction rskTx = buildUpdateTx();
rskTx.sign(SENDER.getPrivKeyBytes());
verify(repository, never()).transfer(any(), any(), any());
assertEquals(1, provider.getReleaseRequestQueue().getEntries().size());
assertEquals(1, logInfo.size());
verify(eventLogger, times(1)).logReleaseBtcRequestReceived(any(), any(), any());
}
use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.
the class BridgeSupportReleaseBtcTest method testPegoutMinimumWithFeeVerification.
private void testPegoutMinimumWithFeeVerification(Coin feePerKB, Coin value, boolean shouldPegout) throws IOException {
when(activationMock.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
when(activationMock.isActive(ConsensusRule.RSKIP185)).thenReturn(true);
when(activationMock.isActive(ConsensusRule.RSKIP219)).thenReturn(true);
List<LogInfo> logInfo = new ArrayList<>();
BridgeEventLoggerImpl eventLogger = spy(new BridgeEventLoggerImpl(bridgeConstants, activationMock, logInfo));
bridgeSupport = initBridgeSupport(eventLogger, activationMock);
provider.setFeePerKb(feePerKB);
int pegoutSize = BridgeUtils.getRegularPegoutTxSize(provider.getNewFederation());
Coin minValueAccordingToFee = provider.getFeePerKb().div(1000).times(pegoutSize);
Coin minValueWithGapAboveFee = minValueAccordingToFee.add(minValueAccordingToFee.times(bridgeConstants.getMinimumPegoutValuePercentageToReceiveAfterFee()).div(100));
// if shouldPegout true then value should be greater or equals than both required fee plus gap and min pegout value
// if shouldPegout false then value should be smaller than any of those minimums
assertEquals(!shouldPegout, value.isLessThan(minValueWithGapAboveFee) || value.isLessThan(bridgeConstants.getMinimumPegoutTxValueInSatoshis()));
bridgeSupport.releaseBtc(buildReleaseRskTx(value));
Transaction rskTx = buildUpdateTx();
rskTx.sign(SENDER.getPrivKeyBytes());
verify(repository, shouldPegout ? never() : times(1)).transfer(any(), any(), any());
assertEquals(shouldPegout ? 1 : 0, provider.getReleaseRequestQueue().getEntries().size());
assertEquals(1, logInfo.size());
verify(eventLogger, shouldPegout ? times(1) : never()).logReleaseBtcRequestReceived(any(), any(), any());
ArgumentCaptor<RejectedPegoutReason> argumentCaptor = ArgumentCaptor.forClass(RejectedPegoutReason.class);
verify(eventLogger, shouldPegout ? never() : times(1)).logReleaseBtcRequestRejected(any(), any(), argumentCaptor.capture());
if (!shouldPegout) {
// Verify rejected pegout reason using value in comparison with fee and pegout minimum
Assert.assertEquals(value.isLessThan(minValueWithGapAboveFee) ? RejectedPegoutReason.FEE_ABOVE_VALUE : RejectedPegoutReason.LOW_AMOUNT, argumentCaptor.getValue());
}
}
use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.
the class BridgeSupportReleaseBtcTest method handmade_release_after_rskip_146.
@Test
public void handmade_release_after_rskip_146() throws IOException {
when(activationMock.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
when(activationMock.isActive(ConsensusRule.RSKIP185)).thenReturn(false);
List<LogInfo> logInfo = new ArrayList<>();
BridgeEventLoggerImpl eventLogger = spy(new BridgeEventLoggerImpl(bridgeConstants, activationMock, logInfo));
bridgeSupport = initBridgeSupport(eventLogger, activationMock);
bridgeSupport.releaseBtc(releaseTx);
Transaction rskTx = buildUpdateTx();
rskTx.sign(new ECKey().getPrivKeyBytes());
bridgeSupport.updateCollections(rskTx);
verify(repository, never()).transfer(any(), any(), any());
assertEquals(1, provider.getReleaseTransactionSet().getEntries().size());
assertEquals(0, provider.getReleaseRequestQueue().getEntries().size());
ReleaseTransactionSet.Entry entry = (ReleaseTransactionSet.Entry) provider.getReleaseTransactionSet().getEntries().toArray()[0];
verify(eventLogger, times(1)).logReleaseBtcRequested(any(byte[].class), any(BtcTransaction.class), any(Coin.class));
}
use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.
the class BridgeSupportReleaseBtcTest method handmade_release_after_rskip_146_rejected_lowAmount.
@Test
public void handmade_release_after_rskip_146_rejected_lowAmount() throws IOException {
when(activationMock.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
when(activationMock.isActive(ConsensusRule.RSKIP185)).thenReturn(false);
List<LogInfo> logInfo = new ArrayList<>();
BridgeEventLoggerImpl eventLogger = spy(new BridgeEventLoggerImpl(bridgeConstants, activationMock, logInfo));
bridgeSupport = initBridgeSupport(eventLogger, activationMock);
releaseTx = buildReleaseRskTx(Coin.ZERO);
bridgeSupport.releaseBtc(releaseTx);
Transaction rskTx = buildUpdateTx();
rskTx.sign(SENDER.getPrivKeyBytes());
bridgeSupport.updateCollections(rskTx);
verify(repository, never()).transfer(any(), any(), any());
assertEquals(0, provider.getReleaseTransactionSet().getEntries().size());
assertEquals(0, provider.getReleaseRequestQueue().getEntries().size());
verify(eventLogger, never()).logReleaseBtcRequestRejected(any(), any(), any());
assertEquals(1, logInfo.size());
verify(eventLogger, times(1)).logUpdateCollections(any());
}
Aggregations