Search in sources :

Example 61 with LogInfo

use of org.ethereum.vm.LogInfo in project rskj by rsksmart.

the class BridgeEventLoggerImplTest method assertEvent.

/**
 ********************************
 *  -------     UTILS     ------- *
 ********************************
 */
private static void assertEvent(List<LogInfo> logs, int index, CallTransaction.Function event, Object[] topics, Object[] params) {
    final LogInfo log = logs.get(index);
    assertEquals(LogInfo.byteArrayToList(event.encodeEventTopics(topics)), log.getTopics());
    assertArrayEquals(event.encodeEventData(params), log.getData());
}
Also used : LogInfo(org.ethereum.vm.LogInfo)

Example 62 with LogInfo

use of org.ethereum.vm.LogInfo in project rskj by rsksmart.

the class BridgeEventLoggerImplTest method logUnrefundablePegin.

@Test
public void logUnrefundablePegin() {
    // Setup event logger
    ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
    List<LogInfo> eventLogs = new LinkedList<>();
    BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(null, activations, eventLogs);
    BtcTransaction btcTx = new BtcTransaction(BridgeRegTestConstants.getInstance().getBtcParams());
    eventLogger.logUnrefundablePegin(btcTx, UnrefundablePeginReason.LEGACY_PEGIN_UNDETERMINED_SENDER);
    Assert.assertEquals(1, eventLogs.size());
    LogInfo entry = eventLogs.get(0);
    Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(entry.getAddress()));
    // Assert address that made the log
    LogInfo result = eventLogs.get(0);
    Assert.assertArrayEquals(PrecompiledContracts.BRIDGE_ADDR.getBytes(), result.getAddress());
    // Assert log topics
    Assert.assertEquals(2, result.getTopics().size());
    CallTransaction.Function event = BridgeEvents.UNREFUNDABLE_PEGIN.getEvent();
    byte[][] topics = event.encodeEventTopics(btcTx.getHash().getBytes());
    for (int i = 0; i < topics.length; i++) {
        Assert.assertArrayEquals(topics[i], result.getTopics().get(i).getData());
    }
    // Assert log data
    Assert.assertArrayEquals(event.encodeEventData(UnrefundablePeginReason.LEGACY_PEGIN_UNDETERMINED_SENDER.getValue()), result.getData());
}
Also used : LogInfo(org.ethereum.vm.LogInfo) LinkedList(java.util.LinkedList) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) RskAddress(co.rsk.core.RskAddress) CallTransaction(org.ethereum.core.CallTransaction) Test(org.junit.Test)

Example 63 with LogInfo

use of org.ethereum.vm.LogInfo in project rskj by rsksmart.

the class RemascFeesPayerTest method payMiningFees.

@Test
public void payMiningFees() {
    // Setup objects
    Repository repositoryMock = Mockito.mock(Repository.class);
    RemascFeesPayer feesPayer = new RemascFeesPayer(repositoryMock, PrecompiledContracts.REMASC_ADDR);
    byte[] blockHash = { 0x1, 0x2 };
    Coin value = Coin.valueOf(7L);
    RskAddress toAddress = new RskAddress("6c386a4b26f73c802f34673f7248bb118f97424a");
    List<LogInfo> logs = new ArrayList<>();
    // Do call
    feesPayer.payMiningFees(blockHash, value, toAddress, logs);
    Assert.assertEquals(1, feesPayer.getSubtraces().size());
    ProgramSubtrace subtrace = feesPayer.getSubtraces().get(0);
    Assert.assertEquals(DataWord.valueOf(PrecompiledContracts.REMASC_ADDR.getBytes()), subtrace.getInvokeData().getCallerAddress());
    Assert.assertEquals(DataWord.valueOf(toAddress.getBytes()), subtrace.getInvokeData().getOwnerAddress());
    Assert.assertEquals(DataWord.valueOf(value.getBytes()), subtrace.getInvokeData().getCallValue());
    Assert.assertEquals(1, logs.size());
    // Assert address that made the log
    LogInfo result = logs.get(0);
    Assert.assertArrayEquals(PrecompiledContracts.REMASC_ADDR.getBytes(), result.getAddress());
    // Assert log topics
    Assert.assertEquals(2, result.getTopics().size());
    Assert.assertEquals("000000000000000000000000000000006d696e696e675f6665655f746f706963", result.getTopics().get(0).toString());
    Assert.assertEquals("0000000000000000000000006c386a4b26f73c802f34673f7248bb118f97424a", result.getTopics().get(1).toString());
    // Assert log data
    Assert.assertNotNull(result.getData());
    List<RLPElement> rlpData = RLP.decode2(result.getData());
    Assert.assertEquals(1, rlpData.size());
    RLPList dataList = (RLPList) rlpData.get(0);
    Assert.assertEquals(2, dataList.size());
    Assert.assertArrayEquals(blockHash, dataList.get(0).getRLPData());
    Assert.assertEquals(value, RLP.parseCoin(dataList.get(1).getRLPData()));
    // Assert repository calls are made right
    verify(repositoryMock, times(1)).addBalance(PrecompiledContracts.REMASC_ADDR, value.negate());
    verify(repositoryMock, times(1)).addBalance(toAddress, value);
}
Also used : Coin(co.rsk.core.Coin) Repository(org.ethereum.core.Repository) LogInfo(org.ethereum.vm.LogInfo) ProgramSubtrace(co.rsk.rpc.modules.trace.ProgramSubtrace) RLPElement(org.ethereum.util.RLPElement) RskAddress(co.rsk.core.RskAddress) ArrayList(java.util.ArrayList) RLPList(org.ethereum.util.RLPList) Test(org.junit.Test)

Example 64 with LogInfo

use of org.ethereum.vm.LogInfo in project rskj by rsksmart.

the class RemascRskAddressActivationTest method testActivation.

@Test
public void testActivation() {
    final RskAddress rskLabsAddress = new RskAddress("14d3065c8Eb89895f4df12450EC6b130049F8034");
    final RskAddress rskLabsAddressRskip218 = new RskAddress("dcb12179ba4697350f66224c959bdd9c282818df");
    final RemascTransaction txMock = mock(RemascTransaction.class);
    final Repository repositoryMock = mock(Repository.class);
    final BlockStore blockStoreMock = mock(BlockStore.class);
    final List<LogInfo> logs = Collections.emptyList();
    final ActivationConfig activationConfig = mock(ActivationConfig.class);
    final Block blockMock = mock(Block.class);
    final RemascConfig remascConfig = spy(new RemascConfigFactory(RemascContract.REMASC_CONFIG).createRemascConfig("regtest"));
    final Remasc remasc = new Remasc(Constants.regtest(), activationConfig, repositoryMock, blockStoreMock, remascConfig, txMock, PrecompiledContracts.REMASC_ADDR, blockMock, logs);
    when(remascConfig.getRskLabsAddress()).thenReturn(rskLabsAddress);
    when(remascConfig.getRskLabsAddressRskip218()).thenReturn(rskLabsAddressRskip218);
    when(activationConfig.isActive(ConsensusRule.RSKIP218, 1)).thenReturn(false);
    when(activationConfig.isActive(ConsensusRule.RSKIP218, 2)).thenReturn(true);
    when(blockMock.getNumber()).thenReturn(1L);
    RskAddress actualAddress = remasc.getRskLabsAddress();
    Assert.assertEquals(rskLabsAddress, actualAddress);
    Assert.assertEquals(blockMock.getNumber(), 1L);
    Assert.assertFalse(activationConfig.isActive(ConsensusRule.RSKIP218, blockMock.getNumber()));
    verify(remascConfig).getRskLabsAddress();
    when(blockMock.getNumber()).thenReturn(2L);
    actualAddress = remasc.getRskLabsAddress();
    Assert.assertEquals(rskLabsAddressRskip218, actualAddress);
    Assert.assertEquals(blockMock.getNumber(), 2L);
    Assert.assertTrue(activationConfig.isActive(ConsensusRule.RSKIP218, blockMock.getNumber()));
    verify(remascConfig).getRskLabsAddressRskip218();
}
Also used : RemascConfig(co.rsk.config.RemascConfig) Repository(org.ethereum.core.Repository) BlockStore(org.ethereum.db.BlockStore) LogInfo(org.ethereum.vm.LogInfo) RemascConfigFactory(co.rsk.config.RemascConfigFactory) RskAddress(co.rsk.core.RskAddress) Block(org.ethereum.core.Block) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test)

Example 65 with LogInfo

use of org.ethereum.vm.LogInfo in project rskj by rsksmart.

the class LogFilter method onTransaction.

void onTransaction(Transaction tx, Block b, int txIndex) {
    TransactionInfo txInfo = blockchain.getTransactionInfo(tx.getHash().getBytes());
    TransactionReceipt receipt = txInfo.getReceipt();
    LogFilterElement[] logs = new LogFilterElement[receipt.getLogInfoList().size()];
    for (int i = 0; i < logs.length; i++) {
        LogInfo logInfo = receipt.getLogInfoList().get(i);
        if (addressesTopicsFilter.matchesExactly(logInfo)) {
            onLogMatch(logInfo, b, txIndex, receipt.getTransaction(), i);
        }
    }
}
Also used : LogInfo(org.ethereum.vm.LogInfo) TransactionInfo(org.ethereum.db.TransactionInfo)

Aggregations

LogInfo (org.ethereum.vm.LogInfo)74 DataWord (org.ethereum.vm.DataWord)36 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)25 CallTransaction (org.ethereum.core.CallTransaction)23 Transaction (org.ethereum.core.Transaction)17 RskAddress (co.rsk.core.RskAddress)13 BridgeEventLoggerImpl (co.rsk.peg.utils.BridgeEventLoggerImpl)12 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)11 InternalTransaction (org.ethereum.vm.program.InternalTransaction)11 Block (org.ethereum.core.Block)9 Repository (org.ethereum.core.Repository)9 RepositoryImpl (co.rsk.db.RepositoryImpl)8 Keccak256 (co.rsk.crypto.Keccak256)7 BigInteger (java.math.BigInteger)7 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)7 RLPList (org.ethereum.util.RLPList)6 LinkedList (java.util.LinkedList)4 RLPElement (org.ethereum.util.RLPElement)4 Coin (co.rsk.core.Coin)3