use of co.rsk.peg.utils.RejectedPegoutReason 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());
}
}
Aggregations