Search in sources :

Example 6 with BridgeEventLoggerImpl

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"));
    }
}
Also used : BridgeEventLoggerImpl(co.rsk.peg.utils.BridgeEventLoggerImpl) LogInfo(org.ethereum.vm.LogInfo) Program(org.ethereum.vm.program.Program) ArrayList(java.util.ArrayList) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 7 with BridgeEventLoggerImpl

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());
}
Also used : BridgeEventLoggerImpl(co.rsk.peg.utils.BridgeEventLoggerImpl) LogInfo(org.ethereum.vm.LogInfo) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 8 with BridgeEventLoggerImpl

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());
    }
}
Also used : BridgeEventLoggerImpl(co.rsk.peg.utils.BridgeEventLoggerImpl) LogInfo(org.ethereum.vm.LogInfo) RejectedPegoutReason(co.rsk.peg.utils.RejectedPegoutReason) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList)

Example 9 with BridgeEventLoggerImpl

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));
}
Also used : BridgeEventLoggerImpl(co.rsk.peg.utils.BridgeEventLoggerImpl) LogInfo(org.ethereum.vm.LogInfo) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 10 with BridgeEventLoggerImpl

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());
}
Also used : BridgeEventLoggerImpl(co.rsk.peg.utils.BridgeEventLoggerImpl) LogInfo(org.ethereum.vm.LogInfo) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Aggregations

BridgeEventLoggerImpl (co.rsk.peg.utils.BridgeEventLoggerImpl)13 LogInfo (org.ethereum.vm.LogInfo)12 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)10 Transaction (org.ethereum.core.Transaction)10 InternalTransaction (org.ethereum.vm.program.InternalTransaction)10 BridgeEventLogger (co.rsk.peg.utils.BridgeEventLogger)3 ECKey (org.ethereum.crypto.ECKey)3 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)2 BtcLockSenderProvider (co.rsk.peg.btcLockSender.BtcLockSenderProvider)2 PeginInstructionsProvider (co.rsk.peg.pegininstructions.PeginInstructionsProvider)2 RejectedPegoutReason (co.rsk.peg.utils.RejectedPegoutReason)2 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)2 Program (org.ethereum.vm.program.Program)2 Context (co.rsk.bitcoinj.core.Context)1 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)1 BridgeConstants (co.rsk.config.BridgeConstants)1 BridgeRegTestConstants (co.rsk.config.BridgeRegTestConstants)1 RskAddress (co.rsk.core.RskAddress)1