use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlockValidatorTest method invalidUncleHasNoSavedParent.
@Test
public void invalidUncleHasNoSavedParent() {
IndexedBlockStore store = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block uncle1a = blockGenerator.createChildBlock(new BlockGenerator().createChildBlock(genesis));
List<BlockHeader> uncles1 = new ArrayList<>();
uncles1.add(uncle1a.getHeader());
Block block1 = blockGenerator.createChildBlock(genesis, null, uncles1, 1, null);
store.saveBlock(genesis, TEST_DIFFICULTY, true);
store.saveBlock(block1, TEST_DIFFICULTY, true);
BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store).blockStore(store).build();
Assert.assertFalse(validator.isValid(block1));
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class RepositoryImplOriginalTest method testMultiThread.
// testing for snapshot
@Test
public void testMultiThread() throws InterruptedException {
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
MutableTrieImpl mutableTrie = new MutableTrieImpl(trieStore, new Trie(trieStore));
final Repository repository = new MutableRepository(mutableTrie);
final DataWord cowKey1 = DataWord.valueFromHex("c1");
final DataWord cowKey2 = DataWord.valueFromHex("c2");
final DataWord cowVal0 = DataWord.valueFromHex("c0a0");
Repository track2 = repository.startTracking();
track2.addStorageRow(COW, cowKey2, cowVal0);
track2.commit();
// Changes commited to repository
assertThat(repository.getStorageValue(COW, cowKey2), is(cowVal0));
final CountDownLatch failSema = new CountDownLatch(1);
// First create the 10 snapshots. The snapshots should not be created while the
// repository is being changed.
Repository[] snaps = new Repository[10];
for (int i = 0; i < 10; ++i) {
snaps[i] = new MutableRepository(trieStore, trieStore.retrieve(repository.getRoot()).get());
}
for (int i = 0; i < 10; ++i) {
int finalI = i;
new Thread(() -> {
try {
int cnt = 1;
while (running) {
Repository snap = snaps[finalI].startTracking();
snap.addBalance(COW, Coin.valueOf(10L));
snap.addStorageRow(COW, cowKey1, DataWord.valueOf(cnt));
snap.rollback();
cnt++;
}
} catch (Throwable e) {
e.printStackTrace();
failSema.countDown();
}
}).start();
}
new Thread(() -> {
int cnt = 1;
try {
while (running) {
Repository track21 = repository.startTracking();
DataWord cVal = DataWord.valueOf(cnt);
track21.addStorageRow(COW, cowKey1, cVal);
track21.addBalance(COW, Coin.valueOf(1L));
track21.commit();
assertEquals(BigInteger.valueOf(cnt), repository.getBalance(COW).asBigInteger());
assertEquals(cVal, repository.getStorageValue(COW, cowKey1));
assertEquals(cowVal0, repository.getStorageValue(COW, cowKey2));
cnt++;
}
} catch (Throwable e) {
e.printStackTrace();
try {
repository.addStorageRow(COW, cowKey1, DataWord.valueOf(123));
} catch (Exception e1) {
e1.printStackTrace();
}
failSema.countDown();
}
}).start();
failSema.await(10, TimeUnit.SECONDS);
running = false;
if (failSema.getCount() == 0) {
throw new RuntimeException("Test failed.");
}
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class DebugModuleImplTest method debug_traceTransaction_retrieveSimpleContractCreationTrace.
@Test
public void debug_traceTransaction_retrieveSimpleContractCreationTrace() throws Exception {
DslParser parser = DslParser.fromResource("dsl/contracts01.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");
DebugModuleImpl debugModule = new DebugModuleImpl(world.getBlockStore(), receiptStore, messageHandler, world.getBlockExecutor());
JsonNode result = debugModule.traceTransaction(transaction.getHash().toJsonString(), null);
Assert.assertNotNull(result);
Assert.assertTrue(result.isObject());
ObjectNode oResult = (ObjectNode) result;
Assert.assertTrue(oResult.get("error").textValue().isEmpty());
Assert.assertTrue(oResult.get("result").isTextual());
JsonNode structLogs = oResult.get("structLogs");
Assert.assertTrue(structLogs.isArray());
Assert.assertTrue(structLogs.size() > 0);
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class TraceModuleImplTest method executeContractWithDelegateCall.
@Test
public void executeContractWithDelegateCall() throws Exception {
DslParser parser = DslParser.fromResource("dsl/delegatecall01.txt");
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);
Account delegateCallAccount = world.getAccountByName("delegatecall");
Account delegatedAccount = world.getAccountByName("delegated");
Assert.assertNotNull(delegateCallAccount);
Assert.assertNotNull(delegatedAccount);
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(2, aresult.size());
Assert.assertTrue(result.get(0).isObject());
ObjectNode oresult = (ObjectNode) result.get(1);
Assert.assertNotNull(oresult.get("action"));
Assert.assertNotNull(oresult.get("action").get("callType"));
Assert.assertEquals("\"delegatecall\"", oresult.get("action").get("callType").toString());
Assert.assertEquals("\"" + delegatedAccount.getAddress().toJsonString() + "\"", oresult.get("action").get("to").toString());
Assert.assertEquals("\"" + delegateCallAccount.getAddress().toJsonString() + "\"", oresult.get("action").get("from").toString());
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class TraceModuleImplTest method retrieveEmptyContractCreationTrace.
@Test
public void retrieveEmptyContractCreationTrace() throws Exception {
DslParser parser = DslParser.fromResource("dsl/contracts09.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("\"create\"", oresult.get("type").toString());
}
Aggregations