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());
}
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());
}
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());
}
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;
}
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;
}
Aggregations