Search in sources :

Example 1 with BridgeEventLoggerImpl

use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.

the class BridgeSupportTest method callUpdateCollectionsGenerateEventLog.

@Test
public void callUpdateCollectionsGenerateEventLog() throws IOException, BlockStoreException {
    Repository track = new RepositoryImpl(config).startTracking();
    BlockGenerator blockGenerator = new BlockGenerator();
    List<Block> blocks = blockGenerator.getSimpleBlockChain(blockGenerator.getGenesisBlock(), 10);
    org.ethereum.core.Block rskCurrentBlock = blocks.get(9);
    List<LogInfo> eventLogs = new LinkedList<>();
    BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(bridgeConstants, eventLogs);
    BridgeSupport bridgeSupport = new BridgeSupport(config, track, eventLogger, PrecompiledContracts.BRIDGE_ADDR, rskCurrentBlock);
    Transaction tx = Transaction.create(config, TO_ADDRESS, DUST_AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
    ECKey key = new ECKey();
    tx.sign(key.getPrivKeyBytes());
    bridgeSupport.updateCollections(tx);
    Assert.assertEquals(1, eventLogs.size());
    // Assert address that made the log
    LogInfo result = eventLogs.get(0);
    Assert.assertArrayEquals(PrecompiledContracts.BRIDGE_ADDR.getBytes(), result.getAddress());
    // Assert log topics
    Assert.assertEquals(1, result.getTopics().size());
    Assert.assertEquals(Bridge.UPDATE_COLLECTIONS_TOPIC, result.getTopics().get(0));
    // Assert log data
    Assert.assertArrayEquals(key.getAddress(), RLP.decode2(result.getData()).get(0).getRLPData());
}
Also used : BridgeEventLoggerImpl(co.rsk.peg.utils.BridgeEventLoggerImpl) LogInfo(org.ethereum.vm.LogInfo) ECKey(org.ethereum.crypto.ECKey) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) org.ethereum.core(org.ethereum.core) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) RepositoryImpl(co.rsk.db.RepositoryImpl) BridgeEventLogger(co.rsk.peg.utils.BridgeEventLogger) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 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 3 with BridgeEventLoggerImpl

use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.

the class BridgeSupportReleaseBtcTest method handmade_release_after_rskip_146_185.

@Test
public void handmade_release_after_rskip_146_185() throws IOException {
    when(activationMock.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
    when(activationMock.isActive(ConsensusRule.RSKIP185)).thenReturn(true);
    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(SENDER.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];
    assertEquals(3, logInfo.size());
    verify(eventLogger, times(1)).logReleaseBtcRequested(any(byte[].class), any(BtcTransaction.class), any(Coin.class));
    verify(eventLogger, times(1)).logReleaseBtcRequestReceived(any(), any(), any());
    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)

Example 4 with BridgeEventLoggerImpl

use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.

the class BridgeSupportReleaseBtcTest method release_after_rskip_219.

@Test
public void release_after_rskip_219() 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 between old and new minimum pegout values
    Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis().subtract(bridgeConstants.getMinimumPegoutTxValueInSatoshis()).div(2);
    Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(middle);
    assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis()));
    assertTrue(value.isGreaterThan(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 5 with BridgeEventLoggerImpl

use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.

the class BridgeSupportReleaseBtcTest method handmade_release_after_rskip_146_185_rejected_lowAmount.

@Test
public void handmade_release_after_rskip_146_185_rejected_lowAmount() throws IOException {
    when(activationMock.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
    when(activationMock.isActive(ConsensusRule.RSKIP185)).thenReturn(true);
    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, times(1)).transfer(argThat((a) -> a.equals(PrecompiledContracts.BRIDGE_ADDR)), argThat((a) -> a.equals(new RskAddress(SENDER.getAddress()))), argThat((a) -> a.equals(co.rsk.core.Coin.fromBitcoin(Coin.ZERO))));
    assertEquals(0, provider.getReleaseTransactionSet().getEntries().size());
    assertEquals(0, provider.getReleaseRequestQueue().getEntries().size());
    assertEquals(2, logInfo.size());
    verify(eventLogger, never()).logReleaseBtcRequestReceived(any(), any(), any());
    verify(eventLogger, times(1)).logReleaseBtcRequestRejected(any(), any(), any());
    verify(eventLogger, times(1)).logUpdateCollections(any());
}
Also used : BridgeEventLoggerImpl(co.rsk.peg.utils.BridgeEventLoggerImpl) RejectedPegoutReason(co.rsk.peg.utils.RejectedPegoutReason) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) RskAddress(co.rsk.core.RskAddress) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) BridgeEventLoggerImpl(co.rsk.peg.utils.BridgeEventLoggerImpl) Hex(org.bouncycastle.util.encoders.Hex) Block(org.ethereum.core.Block) ArrayList(java.util.ArrayList) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) MutableTrieCache(co.rsk.db.MutableTrieCache) ArgumentCaptor(org.mockito.ArgumentCaptor) BridgeConstants(co.rsk.config.BridgeConstants) co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) BigInteger(java.math.BigInteger) BridgeRegTestConstants(co.rsk.config.BridgeRegTestConstants) Before(org.junit.Before) LogInfo(org.ethereum.vm.LogInfo) HashUtil(org.ethereum.crypto.HashUtil) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test) IOException(java.io.IOException) MutableTrieImpl(co.rsk.db.MutableTrieImpl) Instant(java.time.Instant) Repository(org.ethereum.core.Repository) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) MutableRepository(org.ethereum.db.MutableRepository) Program(org.ethereum.vm.program.Program) Mockito(org.mockito.Mockito) List(java.util.List) InternalTransaction(org.ethereum.vm.program.InternalTransaction) BridgeEventLogger(co.rsk.peg.utils.BridgeEventLogger) Transaction(org.ethereum.core.Transaction) Assert(org.junit.Assert) Trie(co.rsk.trie.Trie) ConsensusRule(org.ethereum.config.blockchain.upgrades.ConsensusRule) Constants(org.ethereum.config.Constants) ECKey(org.ethereum.crypto.ECKey) LogInfo(org.ethereum.vm.LogInfo) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) RskAddress(co.rsk.core.RskAddress) 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