use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class TransactionTest method multiSuicideTest.
@Test
public void multiSuicideTest() throws IOException, InterruptedException {
/*
Original contract
pragma solidity ^0.4.3;
contract PsychoKiller {
function () payable {}
function homicide() {
suicide(msg.sender);
}
function multipleHomicide() {
PsychoKiller k = this;
k.homicide();
k.homicide();
k.homicide();
k.homicide();
}
}
*/
BigInteger nonce = config.getNetworkConstants().getInitialNonce();
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
MutableRepository repository = new MutableRepository(new MutableTrieImpl(trieStore, new Trie(trieStore)));
IndexedBlockStore blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());
Blockchain blockchain = ImportLightTest.createBlockchain(new TestGenesisLoader(trieStore, getClass().getResourceAsStream("/genesis/genesis-light.json"), nonce, false, true, true).load(), config, repository, blockStore, trieStore);
ECKey sender = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c"));
System.out.println("address: " + ByteUtil.toHexString(sender.getAddress()));
String code = "6060604052341561000c57fe5b5b6102938061001c6000396000f3006060604052361561004a576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806309e587a514610053578063de990da914610065575b6100515b5b565b005b341561005b57fe5b610063610077565b005b341561006d57fe5b610075610092565b005b3373ffffffffffffffffffffffffffffffffffffffff16ff5b565b60003090508073ffffffffffffffffffffffffffffffffffffffff166309e587a56040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401809050600060405180830381600087803b15156100fa57fe5b60325a03f1151561010757fe5b5050508073ffffffffffffffffffffffffffffffffffffffff166309e587a56040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401809050600060405180830381600087803b151561016d57fe5b60325a03f1151561017a57fe5b5050508073ffffffffffffffffffffffffffffffffffffffff166309e587a56040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401809050600060405180830381600087803b15156101e057fe5b60325a03f115156101ed57fe5b5050508073ffffffffffffffffffffffffffffffffffffffff166309e587a56040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401809050600060405180830381600087803b151561025357fe5b60325a03f1151561026057fe5b5050505b505600a165627a7a72305820084e74021c556522723b6725354378df2fb4b6732f82dd33f5daa29e2820b37c0029";
String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"homicide\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"multipleHomicide\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"payable\":true,\"type\":\"fallback\"}]";
Transaction tx = createTx(sender, new byte[0], Hex.decode(code), repository);
executeTransaction(blockchain, blockStore, tx, repository, blockTxSignatureCache);
byte[] contractAddress = tx.getContractAddress().getBytes();
CallTransaction.Contract contract1 = new CallTransaction.Contract(abi);
byte[] callData = contract1.getByName("multipleHomicide").encode();
Assert.assertNull(contract1.getConstructor());
Assert.assertNotNull(contract1.parseInvocation(callData));
Assert.assertNotNull(contract1.parseInvocation(callData).toString());
try {
contract1.parseInvocation(new byte[32]);
Assert.fail();
} catch (RuntimeException ex) {
}
try {
contract1.parseInvocation(new byte[2]);
Assert.fail();
} catch (RuntimeException ex) {
}
Transaction tx1 = createTx(sender, contractAddress, callData, repository);
ProgramResult programResult = executeTransaction(blockchain, blockStore, tx1, repository, blockTxSignatureCache).getResult();
// suicide of a single account should be counted only once
Assert.assertEquals(24000, programResult.getFutureRefund());
}
use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class RskContextTest method shouldBuildSimpleTrieStore.
@Test
public void shouldBuildSimpleTrieStore() throws IOException {
doReturn(new GarbageCollectorConfig(false, 1000, 3)).when(testProperties).garbageCollectorConfig();
TrieStore trieStore = rskContext.getTrieStore();
assertThat(trieStore, is(instanceOf(TrieStoreImpl.class)));
assertThat(Files.list(databaseDir.toPath()).count(), is(1L));
}
use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class RskContextTest method shouldBuildMultiTrieStoreFromExistingDirectories.
@Test
public void shouldBuildMultiTrieStoreFromExistingDirectories() throws IOException {
int numberOfEpochs = 3;
Path testDatabasesDirectory = databaseDir.toPath();
doReturn(false).when(testProperties).databaseReset();
doReturn(new GarbageCollectorConfig(true, 1000, numberOfEpochs)).when(testProperties).garbageCollectorConfig();
int initialEpoch = 3;
for (int i = initialEpoch; i < initialEpoch + numberOfEpochs; i++) {
Files.createDirectory(testDatabasesDirectory.resolve(String.format("unitrie_%d", i)));
}
rskContext.close();
rskContext = makeRskContext();
TrieStore trieStore = rskContext.getTrieStore();
assertThat(trieStore, is(instanceOf(MultiTrieStore.class)));
assertThat(Files.list(testDatabasesDirectory).count(), is((long) numberOfEpochs));
int[] directorySuffixes = Files.list(testDatabasesDirectory).map(Path::getFileName).map(Path::toString).map(fileName -> fileName.replaceAll("unitrie_", "")).mapToInt(Integer::valueOf).sorted().toArray();
assertThat(directorySuffixes, is(IntStream.range(initialEpoch, initialEpoch + numberOfEpochs).toArray()));
}
use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class RskContextTest method shouldBuildSimpleTrieStoreCleaningUpMultiTrieStore.
@Test
public void shouldBuildSimpleTrieStoreCleaningUpMultiTrieStore() throws IOException {
Path testDatabasesDirectory = databaseDir.toPath();
doReturn(new GarbageCollectorConfig(false, 1000, 3)).when(testProperties).garbageCollectorConfig();
long preExistingEpochs = 4;
for (int i = 0; i < preExistingEpochs; i++) {
Files.createDirectory(testDatabasesDirectory.resolve(String.format("unitrie_%d", i)));
}
assertThat(Files.list(testDatabasesDirectory).count(), is(preExistingEpochs));
TrieStore trieStore = rskContext.getTrieStore();
assertThat(trieStore, is(instanceOf(TrieStoreImpl.class)));
assertThat(Files.list(testDatabasesDirectory).count(), is(1L));
}
use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class TransactionModuleTest method sendRawTransactionWithAutoMining.
@Test
public void sendRawTransactionWithAutoMining() throws Exception {
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
BlockChainImpl blockchain = world.getBlockChain();
TrieStore trieStore = world.getTrieStore();
RepositoryLocator repositoryLocator = world.getRepositoryLocator();
BlockStore blockStore = world.getBlockStore();
TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, buildTransactionExecutorFactory(blockStore, receiptStore, world.getBlockTxSignatureCache()), world.getReceivedTxSignatureCache(), 10, 100);
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
Web3Impl web3 = createEnvironment(blockchain, receiptStore, trieStore, transactionPool, blockStore, true, world.getBlockTxSignatureCache(), transactionGateway);
String txHash = sendRawTransaction(web3);
Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
Assert.assertEquals(2, blockchain.getBestBlock().getTransactionsList().size());
Transaction txInBlock = getTransactionFromBlockWhichWasSend(blockchain, txHash);
// Transaction tx must be in the block mined.
Assert.assertEquals(txHash, txInBlock.getHash().toJsonString());
}
Aggregations