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