use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class RepositoryTest method test19.
@Test
public void test19() {
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
DataWord cowKey1 = new DataWord("c1");
byte[] cowVal1 = Hex.decode("c0a1");
byte[] cowVal0 = Hex.decode("c0a0");
DataWord horseKey1 = new DataWord("e1");
byte[] horseVal1 = Hex.decode("c0a1");
byte[] horseVal0 = Hex.decode("c0a0");
track.addStorageBytes(COW, cowKey1, cowVal0);
track.addStorageBytes(HORSE, horseKey1, horseVal0);
track.commit();
// track
Repository track2 = repository.startTracking();
track2.addStorageBytes(HORSE, horseKey1, horseVal0);
Repository track3 = track2.startTracking();
ContractDetails cowDetails = track3.getContractDetails(COW);
cowDetails.putBytes(cowKey1, cowVal1);
ContractDetails horseDetails = track3.getContractDetails(HORSE);
horseDetails.putBytes(horseKey1, horseVal1);
track3.commit();
track2.rollback();
ContractDetails cowDetailsOrigin = repository.getContractDetails(COW);
byte[] cowValOrin = cowDetailsOrigin.getBytes(cowKey1);
ContractDetails horseDetailsOrigin = repository.getContractDetails(HORSE);
byte[] horseValOrin = horseDetailsOrigin.getBytes(horseKey1);
assertArrayEquals(cowVal0, cowValOrin);
assertArrayEquals(horseVal0, horseValOrin);
}
use of org.ethereum.vm.DataWord 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]}");
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class DifficultyRuleTest method getHeader.
private static BlockHeader getHeader(long difficultyValue) {
byte[] difficulty = new DataWord(difficultyValue).getData();
BlockHeader header = new BlockHeader(null, null, RskAddress.nullAddress().getBytes(), null, difficulty, 0, null, 0, 0, null, null, 0);
return header;
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class ParentGasLimitRuleTest method getHeader.
// Used also by GasLimitCalculatorTest
public static BlockHeader getHeader(long gasLimitValue) {
byte[] gasLimit = new DataWord(gasLimitValue).getData();
BlockHeader header = new BlockHeader(null, null, RskAddress.nullAddress().getBytes(), null, BlockDifficulty.ZERO.getBytes(), 0, gasLimit, 0, 0, null, null, 0);
return header;
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class DslFilesTest method runLogs01Resource.
@Test
public void runLogs01Resource() throws FileNotFoundException, DslProcessorException {
DslParser parser = DslParser.fromResource("dsl/logs01.txt");
World world = new World();
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);
// the transaction receipt should have three logs
BlockChainStatus status = world.getBlockChain().getStatus();
Assert.assertEquals(1, status.getBestBlockNumber());
Block block = status.getBestBlock();
Assert.assertEquals(1, block.getTransactionsList().size());
byte[] txhash = block.getTransactionsList().get(0).getHash().getBytes();
TransactionInfo txinfo = world.getBlockChain().getTransactionInfo(txhash);
// only three events, raised by
// Counter constructor
// Counter getValue
// Creator constructor
Assert.assertEquals(3, txinfo.getReceipt().getLogInfoList().size());
// only one topic in each event
Assert.assertEquals(1, txinfo.getReceipt().getLogInfoList().get(0).getTopics().size());
Assert.assertEquals(1, txinfo.getReceipt().getLogInfoList().get(1).getTopics().size());
Assert.assertEquals(1, txinfo.getReceipt().getLogInfoList().get(2).getTopics().size());
// the topics are different
DataWord topic1 = txinfo.getReceipt().getLogInfoList().get(0).getTopics().get(0);
DataWord topic2 = txinfo.getReceipt().getLogInfoList().get(1).getTopics().get(0);
DataWord topic3 = txinfo.getReceipt().getLogInfoList().get(2).getTopics().get(0);
Assert.assertNotEquals(topic1, topic2);
Assert.assertNotEquals(topic1, topic3);
Assert.assertNotEquals(topic2, topic3);
// only the third log was directly produced by the created contract
byte[] contractAddress = txinfo.getReceipt().getTransaction().getContractAddress().getBytes();
Assert.assertFalse(Arrays.equals(contractAddress, txinfo.getReceipt().getLogInfoList().get(0).getAddress()));
Assert.assertFalse(Arrays.equals(contractAddress, txinfo.getReceipt().getLogInfoList().get(1).getAddress()));
Assert.assertTrue(Arrays.equals(contractAddress, txinfo.getReceipt().getLogInfoList().get(2).getAddress()));
}
Aggregations