Search in sources :

Example 76 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class TraceModuleImplTest method retrieveUnknownTransactionAsNull.

@Test
public void retrieveUnknownTransactionAsNull() throws Exception {
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    TraceModuleImpl traceModule = new TraceModuleImpl(world.getBlockChain(), world.getBlockStore(), receiptStore, world.getBlockExecutor());
    JsonNode result = traceModule.traceTransaction("0x00");
    Assert.assertNull(result);
}
Also used : ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 77 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class TraceModuleImplTest method retrieveSimpleAccountTransfer.

@Test
public void retrieveSimpleAccountTransfer() throws Exception {
    DslParser parser = DslParser.fromResource("dsl/transfers01.txt");
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    Transaction transaction = world.getTransactionByName("tx01");
    TraceModuleImpl traceModule = new TraceModuleImpl(world.getBlockChain(), world.getBlockStore(), receiptStore, world.getBlockExecutor());
    JsonNode result = traceModule.traceTransaction(transaction.getHash().toJsonString());
    Assert.assertNotNull(result);
    Assert.assertTrue(result.isArray());
    ArrayNode aresult = (ArrayNode) result;
    Assert.assertEquals(1, aresult.size());
    Assert.assertTrue(result.get(0).isObject());
    ObjectNode oresult = (ObjectNode) result.get(0);
    Assert.assertNotNull(oresult.get("type"));
    Assert.assertEquals("\"call\"", oresult.get("type").toString());
}
Also used : ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Transaction(org.ethereum.core.Transaction) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DslParser(co.rsk.test.dsl.DslParser) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 78 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class BlockUnclesValidationRuleTest method rejectBlockWithSiblingUncle.

@Test
public void rejectBlockWithSiblingUncle() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block1 = blockGenerator.createChildBlock(genesis);
    Block uncle = blockGenerator.createChildBlock(block1);
    List<BlockHeader> uncles = new ArrayList<>();
    uncles.add(uncle.getHeader());
    Block block = blockGenerator.createChildBlock(block1, null, uncles, 1, null);
    BlockStore blockStore = new IndexedBlockStore(null, new HashMapDB(), new HashMapBlocksIndex());
    blockStore.saveBlock(genesis, new BlockDifficulty(BigInteger.valueOf(1)), true);
    blockStore.saveBlock(block1, new BlockDifficulty(BigInteger.valueOf(2)), true);
    BlockUnclesValidationRule rule = new BlockUnclesValidationRule(blockStore, 10, 10, new BlockHeaderCompositeRule(), new BlockHeaderParentCompositeRule());
    Assert.assertFalse(rule.isValid(block));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) ArrayList(java.util.ArrayList) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockDifficulty(co.rsk.core.BlockDifficulty) Block(org.ethereum.core.Block) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 79 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class TrieSaveRetrieveTest method updateSaveRetrieveAndGetOneThousandKeyLongValuesUsingBinaryTree.

@Test
public void updateSaveRetrieveAndGetOneThousandKeyLongValuesUsingBinaryTree() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new Trie(store);
    for (int k = 0; k < 1000; k++) trie = trie.put(k + "", TrieValueTest.makeValue(k + 200));
    store.save(trie);
    Trie trie2 = store.retrieve(trie.getHash().getBytes()).get();
    Assert.assertNotNull(trie2);
    Assert.assertEquals(trie.getHash(), trie2.getHash());
    for (int k = 0; k < 1000; k++) {
        String key = k + "";
        byte[] expected = trie.get(key);
        byte[] value = trie2.get(key);
        Assert.assertArrayEquals(expected, value);
    }
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 80 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class TrieSaveRetrieveTest method updateSaveRetrieveAndGetOneThousandKeyValuesInverseOrder.

@Test
public void updateSaveRetrieveAndGetOneThousandKeyValuesInverseOrder() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new Trie(store);
    for (int k = 1000; k > 0; k--) trie = trie.put(k + "", (k + "").getBytes());
    store.save(trie);
    Trie trie2 = store.retrieve(trie.getHash().getBytes()).get();
    Assert.assertNotNull(trie2);
    Assert.assertEquals(trie.getHash(), trie2.getHash());
    for (int k = 1000; k > 0; k--) {
        String key = k + "";
        byte[] expected = trie.get(key);
        byte[] value = trie2.get(key);
        Assert.assertArrayEquals(expected, value);
    }
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Aggregations

HashMapDB (org.ethereum.datasource.HashMapDB)208 Test (org.junit.Test)181 World (co.rsk.test.World)45 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)34 ReceiptStore (org.ethereum.db.ReceiptStore)34 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)34 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)29 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)27 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)27 TrieStore (co.rsk.trie.TrieStore)26 HashMapBlocksIndex (co.rsk.db.HashMapBlocksIndex)23 Trie (co.rsk.trie.Trie)21 Blockchain (org.ethereum.core.Blockchain)17 RskAddress (co.rsk.core.RskAddress)16 Transaction (org.ethereum.core.Transaction)16 DslParser (co.rsk.test.dsl.DslParser)15 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12