Search in sources :

Example 46 with DataWord

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);
}
Also used : Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) ContractDetails(org.ethereum.db.ContractDetails) Test(org.junit.Test)

Example 47 with DataWord

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]}");
}
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 48 with DataWord

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;
}
Also used : DataWord(org.ethereum.vm.DataWord) BlockHeader(org.ethereum.core.BlockHeader)

Example 49 with DataWord

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;
}
Also used : DataWord(org.ethereum.vm.DataWord) BlockHeader(org.ethereum.core.BlockHeader)

Example 50 with DataWord

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()));
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) DslParser(co.rsk.test.dsl.DslParser) Block(org.ethereum.core.Block) TransactionInfo(org.ethereum.db.TransactionInfo) BlockChainStatus(co.rsk.core.bc.BlockChainStatus) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Aggregations

DataWord (org.ethereum.vm.DataWord)133 Test (org.junit.Test)88 Repository (org.ethereum.core.Repository)41 RskAddress (co.rsk.core.RskAddress)25 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)22 BigInteger (java.math.BigInteger)19 LogInfo (org.ethereum.vm.LogInfo)17 HashMapDB (org.ethereum.datasource.HashMapDB)14 Program (org.ethereum.vm.program.Program)13 Stack (org.ethereum.vm.program.Stack)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)11 RepositoryImpl (co.rsk.db.RepositoryImpl)9 ContractDetails (org.ethereum.db.ContractDetails)9 Trie (co.rsk.trie.Trie)8 CallTransaction (org.ethereum.core.CallTransaction)8 TrieImpl (co.rsk.trie.TrieImpl)7 TrieStore (co.rsk.trie.TrieStore)7 Coin (co.rsk.core.Coin)5