Search in sources :

Example 11 with LogInfo

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

the class BridgeEventLoggerImplTest method commonAssertLogs.

private void commonAssertLogs(List<LogInfo> logs) {
    assertEquals(1, logs.size());
    LogInfo entry = logs.get(0);
    // Assert address that made the log
    assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(entry.getAddress()));
    assertArrayEquals(PrecompiledContracts.BRIDGE_ADDR.getBytes(), entry.getAddress());
}
Also used : LogInfo(org.ethereum.vm.LogInfo) RskAddress(co.rsk.core.RskAddress)

Example 12 with LogInfo

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

the class BridgeEventLoggerImplTest method logAddSignatureBeforeRskip146HardFork.

@Test
public void logAddSignatureBeforeRskip146HardFork() {
    when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(false);
    // Setup logAddSignature params
    BtcECKey federatorPubKey = BtcECKey.fromPrivate(BigInteger.valueOf(2L));
    Keccak256 rskTxHash = PegTestUtils.createHash3(1);
    when(btcTxMock.getHashAsString()).thenReturn("3e72fdbae7bbd103f08e876c765e3d5ba35db30ea46cb45ab52803f987ead9fb");
    // Act
    eventLogger.logAddSignature(federatorPubKey, btcTxMock, rskTxHash.getBytes());
    // Assert log size
    Assert.assertEquals(1, eventLogs.size());
    LogInfo logResult = eventLogs.get(0);
    // Assert address that made the log
    Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(logResult.getAddress()));
    // Assert log topics
    Assert.assertEquals(1, logResult.getTopics().size());
    Assert.assertEquals(Bridge.ADD_SIGNATURE_TOPIC, logResult.getTopics().get(0));
    // Assert log data
    Assert.assertNotNull(logResult.getData());
    List<RLPElement> rlpData = RLP.decode2(logResult.getData());
    Assert.assertEquals(1, rlpData.size());
    RLPList dataList = (RLPList) rlpData.get(0);
    Assert.assertEquals(3, dataList.size());
    Assert.assertArrayEquals(btcTxMock.getHashAsString().getBytes(), dataList.get(0).getRLPData());
    Assert.assertArrayEquals(federatorPubKey.getPubKeyHash(), dataList.get(1).getRLPData());
    Assert.assertArrayEquals(rskTxHash.getBytes(), dataList.get(2).getRLPData());
}
Also used : LogInfo(org.ethereum.vm.LogInfo) RLPElement(org.ethereum.util.RLPElement) RskAddress(co.rsk.core.RskAddress) Keccak256(co.rsk.crypto.Keccak256) RLPList(org.ethereum.util.RLPList) Test(org.junit.Test)

Example 13 with LogInfo

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

the class BridgeEventLoggerImplTest method logCommitFederationBeforeRskip146.

@Test
public void logCommitFederationBeforeRskip146() {
    when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(false);
    when(constantsMock.getFederationActivationAge()).thenReturn(CONSTANTS.getFederationActivationAge());
    // Setup parameters for test method call
    Block executionBlock = mock(Block.class);
    when(executionBlock.getTimestamp()).thenReturn(15005L);
    when(executionBlock.getNumber()).thenReturn(15L);
    List<BtcECKey> oldFederationKeys = Arrays.asList(BtcECKey.fromPublicOnly(Hex.decode("036bb9eab797eadc8b697f0e82a01d01cabbfaaca37e5bafc06fdc6fdd38af894a")), BtcECKey.fromPublicOnly(Hex.decode("031da807c71c2f303b7f409dd2605b297ac494a563be3b9ca5f52d95a43d183cc5")), BtcECKey.fromPublicOnly(Hex.decode("025eefeeeed5cdc40822880c7db1d0a88b7b986945ed3fc05a0b45fe166fe85e12")), BtcECKey.fromPublicOnly(Hex.decode("03c67ad63527012fd4776ae892b5dc8c56f80f1be002dc65cd520a2efb64e37b49")));
    List<FederationMember> oldFederationMembers = FederationTestUtils.getFederationMembersWithBtcKeys(oldFederationKeys);
    Federation oldFederation = new Federation(oldFederationMembers, Instant.ofEpochMilli(15005L), 15L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST));
    List<BtcECKey> newFederationKeys = Arrays.asList(BtcECKey.fromPublicOnly(Hex.decode("0346cb6b905e4dee49a862eeb2288217d06afcd4ace4b5ca77ebedfbc6afc1c19d")), BtcECKey.fromPublicOnly(Hex.decode("0269a0dbe7b8f84d1b399103c466fb20531a56b1ad3a7b44fe419e74aad8c46db7")), BtcECKey.fromPublicOnly(Hex.decode("026192d8ab41bd402eb0431457f6756a3f3ce15c955c534d2b87f1e0372d8ba338")));
    List<FederationMember> newFederationMembers = FederationTestUtils.getFederationMembersWithBtcKeys(newFederationKeys);
    Federation newFederation = new Federation(newFederationMembers, Instant.ofEpochMilli(5005L), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST));
    // Act
    eventLogger.logCommitFederation(executionBlock, oldFederation, newFederation);
    // Assert log size
    Assert.assertEquals(1, eventLogs.size());
    LogInfo logResult = eventLogs.get(0);
    // Assert address that made the log
    Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(logResult.getAddress()));
    // Assert log topics
    Assert.assertEquals(1, logResult.getTopics().size());
    Assert.assertEquals(Bridge.COMMIT_FEDERATION_TOPIC, logResult.getTopics().get(0));
    // Assert log data
    Assert.assertNotNull(logResult.getData());
    List<RLPElement> rlpData = RLP.decode2(logResult.getData());
    Assert.assertEquals(1, rlpData.size());
    RLPList dataList = (RLPList) rlpData.get(0);
    Assert.assertEquals(3, dataList.size());
    // Assert old federation data
    RLPList oldFedData = (RLPList) dataList.get(0);
    Assert.assertEquals(2, oldFedData.size());
    Assert.assertArrayEquals(oldFederation.getAddress().getHash160(), oldFedData.get(0).getRLPData());
    RLPList oldFedPubKeys = (RLPList) oldFedData.get(1);
    Assert.assertEquals(4, oldFedPubKeys.size());
    for (int i = 0; i < 4; i++) {
        Assert.assertEquals(oldFederation.getBtcPublicKeys().get(i), BtcECKey.fromPublicOnly(oldFedPubKeys.get(i).getRLPData()));
    }
    // Assert new federation data
    RLPList newFedData = (RLPList) dataList.get(1);
    Assert.assertEquals(2, newFedData.size());
    Assert.assertArrayEquals(newFederation.getAddress().getHash160(), newFedData.get(0).getRLPData());
    RLPList newFedPubKeys = (RLPList) newFedData.get(1);
    Assert.assertEquals(3, newFedPubKeys.size());
    for (int i = 0; i < 3; i++) {
        Assert.assertEquals(newFederation.getBtcPublicKeys().get(i), BtcECKey.fromPublicOnly(newFedPubKeys.get(i).getRLPData()));
    }
    // Assert new federation activation block number
    Assert.assertEquals(15L + CONSTANTS.getFederationActivationAge(), Long.valueOf(new String(dataList.get(2).getRLPData(), StandardCharsets.UTF_8)).longValue());
}
Also used : LogInfo(org.ethereum.vm.LogInfo) RLPList(org.ethereum.util.RLPList) RLPElement(org.ethereum.util.RLPElement) RskAddress(co.rsk.core.RskAddress) Block(org.ethereum.core.Block) Test(org.junit.Test)

Example 14 with LogInfo

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

the class StateTestRunner method runImpl.

public List<String> runImpl() {
    vStats = new ValidationStats();
    logger.info("");
    trieStore = new TrieStoreImpl(new HashMapDB());
    repository = RepositoryBuilder.build(trieStore, stateTestCase.getPre());
    logger.info("loaded repository");
    transaction = TransactionBuilder.build(stateTestCase.getTransaction());
    logger.info("transaction: {}", transaction.toString());
    BlockStore blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
    StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    blockchain = new BlockChainImpl(blockStore, null, null, null, null, new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(trieStore, stateRootHandler), new TransactionExecutorFactory(config, blockStore, null, blockFactory, new ProgramInvokeFactoryImpl(), precompiledContracts, new BlockTxSignatureCache(new ReceivedTxSignatureCache()))), stateRootHandler);
    env = EnvBuilder.build(stateTestCase.getEnv());
    invokeFactory = new TestProgramInvokeFactory(env);
    block = build(env);
    block.setStateRoot(repository.getRoot());
    block.flushRLP();
    blockchain.setStatus(block, block.getCumulativeDifficulty());
    // blockchain.setProgramInvokeFactory(invokeFactory);
    // blockchain.startTracking();
    ProgramResult programResult = executeTransaction(transaction);
    trieStore.flush();
    List<LogInfo> origLogs = programResult.getLogInfoList();
    List<LogInfo> postLogs = LogBuilder.build(stateTestCase.getLogs());
    List<String> logsResult = LogsValidator.valid(origLogs, postLogs, vStats);
    Repository postRepository = RepositoryBuilder.build(stateTestCase.getPost());
    // Balances cannot be validated because has consumption for CALLs differ.
    List<String> repoResults = RepositoryValidator.valid(repository, postRepository, false, false, vStats);
    logger.info("--------- POST Validation---------");
    List<String> outputResults = OutputValidator.valid(ByteUtil.toHexString(programResult.getHReturn()), stateTestCase.getOut(), vStats);
    List<String> results = new ArrayList<>();
    results.addAll(repoResults);
    results.addAll(logsResult);
    results.addAll(outputResults);
    for (String result : results) {
        logger.error(result);
    }
    if ((vStats.storageChecks == 0) && (vStats.logChecks == 0) && (vStats.balancetChecks == 0) && (vStats.outputChecks == 0) && (vStats.blockChecks == 0)) {
        // This generally mean that the test didn't check anything
        // AccountChecks are considered not indicative of the result of the test
        logger.info("IRRELEVANT\n");
    }
    logger.info("\n\n");
    return results;
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) LogInfo(org.ethereum.vm.LogInfo) StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) ProgramResult(org.ethereum.vm.program.ProgramResult) ArrayList(java.util.ArrayList) HashMapDB(org.ethereum.datasource.HashMapDB) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryLocator(co.rsk.db.RepositoryLocator) TestProgramInvokeFactory(org.ethereum.jsontestsuite.TestProgramInvokeFactory) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) ValidationStats(org.ethereum.jsontestsuite.validators.ValidationStats)

Example 15 with LogInfo

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

the class Logs method compareToReal.

public List<String> compareToReal(List<LogInfo> logs) {
    List<String> results = new ArrayList<>();
    int i = 0;
    for (LogInfo postLog : this.logs) {
        LogInfo realLog = logs.get(i);
        String postAddress = ByteUtil.toHexString(postLog.getAddress());
        String realAddress = ByteUtil.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 = ByteUtil.toHexString(postLog.getData());
        String realData = ByteUtil.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 = ByteUtil.toHexString(postLog.getBloom().getData());
        String realBloom = ByteUtil.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)

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