Search in sources :

Example 6 with LogInfo

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

the class LogsValidator method valid.

public static List<String> valid(List<LogInfo> origLogs, List<LogInfo> postLogs) {
    List<String> results = new ArrayList<>();
    int i = 0;
    for (LogInfo postLog : postLogs) {
        if (origLogs == null || origLogs.size() - 1 < i) {
            String formattedString = String.format("Log: %s: was expected but doesn't exist: address: %s", i, Hex.toHexString(postLog.getAddress()));
            results.add(formattedString);
            continue;
        }
        LogInfo realLog = origLogs.get(i);
        String postAddress = Hex.toHexString(postLog.getAddress());
        String realAddress = Hex.toHexString(realLog.getAddress());
        if (!postAddress.equals(realAddress)) {
            String formattedString = String.format("Log: %s: has unexpected address, expected address: %s found address: %s", i, postAddress, realAddress);
            results.add(formattedString);
        }
        String postData = Hex.toHexString(postLog.getData());
        String realData = Hex.toHexString(realLog.getData());
        if (!postData.equals(realData)) {
            String formattedString = String.format("Log: %s: has unexpected data, expected data: %s found data: %s", i, postData, realData);
            results.add(formattedString);
        }
        String postBloom = Hex.toHexString(postLog.getBloom().getData());
        String realBloom = Hex.toHexString(realLog.getBloom().getData());
        if (!postData.equals(realData)) {
            String formattedString = String.format("Log: %s: has unexpected bloom, expected bloom: %s found bloom: %s", i, postBloom, realBloom);
            results.add(formattedString);
        }
        List<DataWord> postTopics = postLog.getTopics();
        List<DataWord> realTopics = realLog.getTopics();
        int j = 0;
        for (DataWord postTopic : postTopics) {
            DataWord realTopic = realTopics.get(j);
            if (!postTopic.equals(realTopic)) {
                String formattedString = String.format("Log: %s: has unexpected topic: %s, expected topic: %s found topic: %s", i, j, postTopic, realTopic);
                results.add(formattedString);
            }
            ++j;
        }
        ++i;
    }
    return results;
}
Also used : LogInfo(org.ethereum.vm.LogInfo) ArrayList(java.util.ArrayList) DataWord(org.ethereum.vm.DataWord)

Example 7 with LogInfo

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

the class Web3RskImplTest method web3_LogFilterElement_toString.

@Test
public void web3_LogFilterElement_toString() {
    LogInfo logInfo = Mockito.mock(LogInfo.class);
    byte[] valueToTest = HashUtil.keccak256(new byte[] { 1 });
    Mockito.when(logInfo.getData()).thenReturn(valueToTest);
    List<DataWord> topics = new ArrayList<>();
    topics.add(new DataWord("c1"));
    topics.add(new DataWord("c2"));
    Mockito.when(logInfo.getTopics()).thenReturn(topics);
    Block block = Mockito.mock(Block.class);
    Mockito.when(block.getHash()).thenReturn(new Keccak256(valueToTest));
    Mockito.when(block.getNumber()).thenReturn(1L);
    int txIndex = 1;
    Transaction tx = Mockito.mock(Transaction.class);
    byte[] bytes = new byte[32];
    bytes[0] = 2;
    Mockito.when(tx.getHash()).thenReturn(new Keccak256(bytes));
    int logIdx = 5;
    LogFilterElement logFilterElement = new LogFilterElement(logInfo, block, txIndex, tx, logIdx);
    Assert.assertEquals(logFilterElement.toString(), "LogFilterElement{logIndex='0x5', blockNumber='0x1', blockHash='0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2', transactionHash='0x0200000000000000000000000000000000000000000000000000000000000000', transactionIndex='0x1', address='0x00', data='0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2', topics=[0x00000000000000000000000000000000000000000000000000000000000000c1, 0x00000000000000000000000000000000000000000000000000000000000000c2]}");
}
Also used : LogFilterElement(org.ethereum.rpc.LogFilterElement) LogInfo(org.ethereum.vm.LogInfo) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) DataWord(org.ethereum.vm.DataWord) Keccak256(co.rsk.crypto.Keccak256) Test(org.junit.Test)

Example 8 with LogInfo

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

the class BridgeEventLoggerImpl method logReleaseBtc.

public void logReleaseBtc(BtcTransaction btcTx) {
    List<DataWord> topics = Collections.singletonList(Bridge.RELEASE_BTC_TOPIC);
    byte[] data = RLP.encodeList(RLP.encodeString(btcTx.getHashAsString()), RLP.encodeElement(btcTx.bitcoinSerialize()));
    this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, topics, data));
}
Also used : LogInfo(org.ethereum.vm.LogInfo) DataWord(org.ethereum.vm.DataWord)

Example 9 with LogInfo

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

the class BridgePerformanceTestCase method executeAndAverage.

protected ExecutionStats executeAndAverage(String name, int times, ABIEncoder abiEncoder, BridgeStorageProviderInitializer storageInitializer, TxBuilder txBuilder, HeightProvider heightProvider, ExecutionStats stats, ResultCallback resultCallback, PostInitCallback postInitCallback) throws VMException {
    EnvironmentBuilder environmentBuilder = new EnvironmentBuilder() {

        private Bridge bridge;

        private RepositoryTrackWithBenchmarking benchmarkerTrack;

        private BridgeStorageProvider storageProvider;

        private TrieStore createTrieStore() {
            return new TrieStoreImpl(new HashMapDB());
        }

        @Override
        public Environment build(int executionIndex, TxBuilder txBuilder, int height) throws VMException {
            TrieStore trieStore = createTrieStore();
            Trie trie = new Trie(trieStore);
            benchmarkerTrack = new RepositoryTrackWithBenchmarking(trieStore, trie);
            Repository repository = benchmarkerTrack.startTracking();
            storageProvider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, activationConfig.forBlock((long) executionIndex));
            BtcBlockStore btcBlockStore = btcBlockStoreFactory.newInstance(repository, bridgeConstants, storageProvider, activationConfig.forBlock((long) executionIndex));
            storageInitializer.initialize(storageProvider, repository, executionIndex, btcBlockStore);
            repository.addBalance(PrecompiledContracts.BRIDGE_ADDR, co.rsk.core.Coin.fromBitcoin(Coin.COIN.multiply(21_000_000L)));
            try {
                storageProvider.save();
            } catch (Exception e) {
                throw new RuntimeException("Error trying to save the storage after initialization", e);
            }
            repository.commit();
            benchmarkerTrack.commit();
            benchmarkerTrack = new RepositoryTrackWithBenchmarking(trieStore, benchmarkerTrack.getTrie());
            List<LogInfo> logs = new ArrayList<>();
            // TODO: This was commented to make registerBtcCoinbaseTransactionTest & getBtcTransactionConfirmationTest work.
            // Cache is not being populated.
            // Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(
            // constants.getBridgeConstants().getBtcParams());
            BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(btcBlockStoreFactory, constants.getBridgeConstants(), activationConfig);
            bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactory);
            BlockChainBuilder blockChainBuilder = new BlockChainBuilder();
            Blockchain blockchain = blockChainBuilder.ofSize(height);
            Transaction tx = txBuilder.build(executionIndex);
            bridge.init(tx, blockchain.getBestBlock(), benchmarkerTrack, blockChainBuilder.getBlockStore(), null, logs);
            // Execute a random method so that bridge support initialization
            // does its initial writes to the repo for e.g. genesis block,
            // federation, etc, etc. and we don't get
            // those recorded in the actual execution.
            boolean oldLocalCall = tx.isLocalCallTransaction();
            tx.setLocalCallTransaction(true);
            bridge.execute(Bridge.GET_FEDERATION_SIZE.encode());
            tx.setLocalCallTransaction(oldLocalCall);
            benchmarkerTrack.getStatistics().clear();
            Environment environment = new Environment() {

                @Override
                public PrecompiledContracts.PrecompiledContract getContract() {
                    return bridge;
                }

                @Override
                public BenchmarkedRepository getBenchmarkedRepository() {
                    return benchmarkerTrack;
                }

                @Override
                public void finalise() {
                    benchmarkerTrack.commit();
                }
            };
            if (postInitCallback != null) {
                postInitCallback.afterInit(environment);
            }
            return environment;
        }
    };
    return super.executeAndAverage(name, times, environmentBuilder, abiEncoder, txBuilder, heightProvider, stats, resultCallback);
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) LogInfo(org.ethereum.vm.LogInfo) Blockchain(org.ethereum.core.Blockchain) BtcBlockStore(co.rsk.bitcoinj.store.BtcBlockStore) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) RepositoryTrackWithBenchmarking(co.rsk.db.RepositoryTrackWithBenchmarking) VMException(org.ethereum.vm.exception.VMException) BenchmarkedRepository(co.rsk.db.BenchmarkedRepository) Repository(org.ethereum.core.Repository) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) Trie(co.rsk.trie.Trie)

Example 10 with LogInfo

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

the class BridgeEventLoggerImplTest method logUpdateCollectionsBeforeRskip146HardFork.

@Test
public void logUpdateCollectionsBeforeRskip146HardFork() {
    when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(false);
    // Setup Rsk transaction
    Transaction tx = mock(Transaction.class);
    RskAddress sender = mock(RskAddress.class);
    when(sender.toString()).thenReturn("0x0000000000000000000000000000000000000001");
    when(tx.getSender()).thenReturn(sender);
    // Act
    eventLogger.logUpdateCollections(tx);
    commonAssertLogs(eventLogs);
    assertTopics(1, eventLogs);
    LogInfo logResult = eventLogs.get(0);
    List<DataWord> topics = Collections.singletonList(Bridge.UPDATE_COLLECTIONS_TOPIC);
    for (int i = 0; i < topics.size(); i++) {
        Assert.assertEquals(topics.get(i), logResult.getTopics().get(i));
    }
    // Assert log data
    byte[] encodedData = RLP.encodeElement(tx.getSender().getBytes());
    Assert.assertArrayEquals(encodedData, logResult.getData());
}
Also used : LogInfo(org.ethereum.vm.LogInfo) CallTransaction(org.ethereum.core.CallTransaction) Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

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