use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class TransactionModuleTest method testGasEstimation.
@Test
public void testGasEstimation() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
TrieStore trieStore = world.getTrieStore();
RepositoryLocator repositoryLocator = world.getRepositoryLocator();
RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
BlockStore blockStore = world.getBlockStore();
BlockTxSignatureCache blockTxSignatureCache = world.getBlockTxSignatureCache();
ReceivedTxSignatureCache receivedTxSignatureCache = world.getReceivedTxSignatureCache();
TransactionExecutorFactory transactionExecutorFactory = buildTransactionExecutionFactoryWithProgramInvokeFactory(blockStore, null, blockTxSignatureCache);
TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, transactionExecutorFactory, receivedTxSignatureCache, 10, 100);
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
Web3Impl web3 = createEnvironmentGasExactimation(blockchain, trieStore, transactionPool, blockStore, transactionGateway, transactionExecutorFactory);
RskAddress srcAddr = new RskAddress(ECKey.fromPrivate(Keccak256Helper.keccak256("cow".getBytes())).getAddress());
// Create the transaction that creates the destination contract
sendContractCreationTransaction(srcAddr, web3, repository);
// Compute contract destination address
BigInteger nonce = repository.getAccountState(srcAddr).getNonce();
RskAddress contractAddress = new RskAddress(HashUtil.calcNewAddr(srcAddr.getBytes(), nonce.toByteArray()));
// start with 5M
int gasLimit = 5000000;
int consumed = checkEstimateGas(callCallWithValue, 33472, gasLimit, srcAddr, contractAddress, web3, repository);
// Now that I know the estimation, call again using the estimated value
// it should not fail. We set the gasLimit to the expected value plus 1 to
// differentiate between OOG and success.
int consumed2 = checkEstimateGas(callCallWithValue, 33472, consumed + 1, srcAddr, contractAddress, web3, repository);
Assert.assertEquals(consumed, consumed2);
consumed = checkEstimateGas(callUnfill, 46942, gasLimit, srcAddr, contractAddress, web3, repository);
consumed2 = checkEstimateGas(callUnfill, 46942, consumed + 1, srcAddr, contractAddress, web3, repository);
Assert.assertEquals(consumed, consumed2);
}
use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class TransactionModuleTest method sendTransactionMustNotBeMined.
@Test
public void sendTransactionMustNotBeMined() {
World world = new World();
BlockChainImpl blockchain = world.getBlockChain();
TrieStore trieStore = world.getTrieStore();
RepositoryLocator repositoryLocator = world.getRepositoryLocator();
RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
BlockStore blockStore = world.getBlockStore();
TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, buildTransactionExecutorFactory(blockStore, null, world.getBlockTxSignatureCache()), world.getReceivedTxSignatureCache(), 10, 100);
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
Web3Impl web3 = createEnvironment(blockchain, null, trieStore, transactionPool, blockStore, false, world.getBlockTxSignatureCache(), transactionGateway);
String tx = sendTransaction(web3, repository);
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
Transaction txInBlock = getTransactionFromBlockWhichWasSend(blockchain, tx);
// Transaction tx must not be in block
Assert.assertNull(txInBlock);
}
use of co.rsk.trie.TrieStore 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());
}
use of co.rsk.trie.TrieStore in project rskj by rsksmart.
the class RepositoryMigrationTest method test.
@Test
public void test() {
final RskAddress COW = new RskAddress("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
final BigInteger accountNonce = BigInteger.valueOf(9);
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
Repository repository = new MutableRepository(trieStore, new Trie(trieStore));
AccountState accountState = repository.createAccount(COW);
accountState.setNonce(accountNonce);
repository.updateAccountState(COW, accountState);
repository.commit();
Assert.assertThat(repository.getAccountState(COW).getNonce(), is(accountNonce));
}
use of co.rsk.trie.TrieStore 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());
}
Aggregations