use of co.rsk.trie.TrieStoreImpl in project rskj by rsksmart.
the class BridgeStateTest method recreateFromEmptyStorageProvider.
@Test
public void recreateFromEmptyStorageProvider() throws IOException {
TestSystemProperties config = new TestSystemProperties();
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
Repository repository = new MutableRepository(new MutableTrieImpl(trieStore, new Trie(trieStore)));
BridgeConstants bridgeConstants = config.getNetworkConstants().getBridgeConstants();
BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, config.getActivationConfig().forBlock(0L));
BridgeState state = new BridgeState(42, provider, null);
BridgeState clone = BridgeState.create(bridgeConstants, state.getEncoded(), null);
Assert.assertNotNull(clone);
Assert.assertEquals(42, clone.getBtcBlockchainBestChainHeight());
Assert.assertTrue(clone.getActiveFederationBtcUTXOs().isEmpty());
Assert.assertTrue(clone.getRskTxsWaitingForSignatures().isEmpty());
}
use of co.rsk.trie.TrieStoreImpl in project rskj by rsksmart.
the class RskTestFactory method getGenesisInstance.
public static Genesis getGenesisInstance(RskSystemProperties config) {
boolean useRskip92Encoding = config.getActivationConfig().isActive(ConsensusRule.RSKIP92, 0L);
boolean isRskip126Enabled = config.getActivationConfig().isActive(ConsensusRule.RSKIP126, 0L);
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
return new TestGenesisLoader(trieStore, config.genesisInfo(), config.getNetworkConstants().getInitialNonce(), false, useRskip92Encoding, isRskip126Enabled).load();
}
use of co.rsk.trie.TrieStoreImpl in project rskj by rsksmart.
the class BlockExecutorTest method executeBlockWithTxThatMakesBlockInvalidSenderHasNoBalance.
@Test
public void executeBlockWithTxThatMakesBlockInvalidSenderHasNoBalance() {
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
Repository repository = new MutableRepository(new MutableTrieImpl(trieStore, new Trie(trieStore)));
Repository track = repository.startTracking();
Account account = createAccount("acctest1", track, Coin.valueOf(30000));
Account account2 = createAccount("acctest2", track, Coin.valueOf(10L));
Account account3 = createAccount("acctest3", track, Coin.ZERO);
track.commit();
Assert.assertFalse(Arrays.equals(EMPTY_TRIE_HASH, repository.getRoot()));
BlockExecutor executor = buildBlockExecutor(trieStore);
Transaction tx3 = Transaction.builder().nonce(repository.getNonce(account.getAddress())).gasPrice(BigInteger.ONE).gasLimit(BigInteger.valueOf(21000)).destination(account2.getAddress()).chainId(CONFIG.getNetworkConstants().getChainId()).value(BigInteger.TEN).build();
tx3.sign(account.getEcKey().getPrivKeyBytes());
Transaction tx = tx3;
Transaction tx1 = Transaction.builder().nonce(repository.getNonce(account3.getAddress())).gasPrice(BigInteger.ONE).gasLimit(BigInteger.valueOf(21000)).destination(account2.getAddress()).chainId(CONFIG.getNetworkConstants().getChainId()).value(BigInteger.TEN).build();
tx1.sign(account3.getEcKey().getPrivKeyBytes());
Transaction tx2 = tx1;
List<Transaction> txs = new ArrayList<>();
txs.add(tx);
txs.add(tx2);
List<BlockHeader> uncles = new ArrayList<>();
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
genesis.setStateRoot(repository.getRoot());
Block block = blockGenerator.createChildBlock(genesis, txs, uncles, 1, null);
BlockResult result = executor.execute(block, genesis.getHeader(), false);
Assert.assertSame(BlockResult.INTERRUPTED_EXECUTION_BLOCK_RESULT, result);
}
use of co.rsk.trie.TrieStoreImpl in project rskj by rsksmart.
the class NetworkStateExporterTest method setup.
@Before
public void setup() {
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
MutableTrieImpl mutableTrie = new MutableTrieImpl(trieStore, new Trie(trieStore));
repository = new MutableRepository(mutableTrie);
blockchain = mock(Blockchain.class);
block = mock(Block.class);
when(blockchain.getBestBlock()).thenReturn(block);
BlockHeader blockHeader = mock(BlockHeader.class);
when(block.getHeader()).thenReturn(blockHeader);
RepositoryLocator repositoryLocator = mock(RepositoryLocator.class);
when(repositoryLocator.snapshotAt(block.getHeader())).thenReturn(new MutableRepository(mutableTrie));
this.nse = new NetworkStateExporter(repositoryLocator, blockchain);
}
use of co.rsk.trie.TrieStoreImpl in project rskj by rsksmart.
the class TransactionTest method dontLogWhenReverting.
@Test
public void dontLogWhenReverting() throws IOException, InterruptedException {
/*
Original contracts
pragma solidity ^0.4.0;
contract TestEventInvoked {
event internalEvent();
function doIt() {
internalEvent();
throw;
}
}
contract TestEventInvoker {
event externalEvent();
function doIt(address invokedAddress) {
externalEvent();
invokedAddress.call.gas(50000)(0xb29f0835);
}
}
*/
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()));
// First contract code TestEventInvoked
String code1 = "6060604052341561000f57600080fd5b5b60ae8061001e6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063b29f083514603d575b600080fd5b3415604757600080fd5b604d604f565b005b7f95481a538d62f8458d3cecac82408d5ff2630d8335962b1cdbac16f1a9b910e760405160405180910390a1600080fd5b5600a165627a7a723058207d93861daff7f4a0479d7f3eb0ca7ef5cef7e2bbf2c4637ab4f021ecc5afa7ad0029";
// Second contract code TestEventInvoker
String code2 = "6060604052341561000f57600080fd5b5b6101358061001f6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e25fd8a71461003e575b600080fd5b341561004957600080fd5b610075600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610077565b005b7f4cd6f2e769273405c20f3a0c098c9045749deec145502c4838b54206ec5c542860405160405180910390a18073ffffffffffffffffffffffffffffffffffffffff1661c35063b29f0835906040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160006040518083038160008887f19350505050505b505600a165627a7a7230582019096fd773ebc5581ba378acd64cb1acb450b4eb4866d710f3e3f4e33d635a4b0029";
// Second contract ABI
String abi2 = "[{\"constant\":false,\"inputs\":[{\"name\":\"invokedAddress\",\"type\":\"address\"}],\"name\":\"doIt\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"externalEvent\",\"type\":\"event\"}]";
Transaction tx1 = createTx(sender, new byte[0], Hex.decode(code1), repository);
executeTransaction(blockchain, blockStore, tx1, repository, blockTxSignatureCache);
Transaction tx2 = createTx(sender, new byte[0], Hex.decode(code2), repository);
executeTransaction(blockchain, blockStore, tx2, repository, blockTxSignatureCache);
CallTransaction.Contract contract2 = new CallTransaction.Contract(abi2);
byte[] data = contract2.getByName("doIt").encode(ByteUtil.toHexString(tx1.getContractAddress().getBytes()));
Transaction tx3 = createTx(sender, tx2.getContractAddress().getBytes(), data, repository);
TransactionExecutor executor = executeTransaction(blockchain, blockStore, tx3, repository, blockTxSignatureCache);
Assert.assertEquals(1, executor.getResult().getLogInfoList().size());
Assert.assertFalse(executor.getResult().getLogInfoList().get(0).isRejected());
Assert.assertEquals(1, executor.getVMLogs().size());
}
Aggregations