Search in sources :

Example 1 with ReceiptStoreImpl

use of org.ethereum.db.ReceiptStoreImpl in project rskj by rsksmart.

the class Web3ImplLogsTest method getWeb3WithContractInvoke.

private Web3Impl getWeb3WithContractInvoke() {
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
    Block genesis = world.getBlockByName("g00");
    Transaction tx;
    tx = getContractTransaction(acc1);
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    BlockChainImpl blockChain = world.getBlockChain();
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block1));
    byte[] contractAddress = tx.getContractAddress().getBytes();
    Transaction tx2 = getContractTransactionWithInvoke(acc1, contractAddress);
    List<Transaction> tx2s = new ArrayList<>();
    tx2s.add(tx2);
    Block block2 = new BlockBuilder(world).parent(block1).transactions(tx2s).build();
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block2));
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), receiptStore, null, null, 10, 100);
    Web3Impl web3 = createWeb3(world.getBlockChain(), transactionPool, receiptStore);
    web3.personal_newAccountWithSeed("default");
    web3.personal_newAccountWithSeed("notDefault");
    return web3;
}
Also used : ArrayList(java.util.ArrayList) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) AccountBuilder(co.rsk.test.builders.AccountBuilder) ReceiptStore(org.ethereum.db.ReceiptStore) BlockBuilder(co.rsk.test.builders.BlockBuilder)

Example 2 with ReceiptStoreImpl

use of org.ethereum.db.ReceiptStoreImpl in project rskj by rsksmart.

the class ImportLightTest method createBlockchain.

public static BlockChainImpl createBlockchain(Genesis genesis) {
    RskSystemProperties config = new RskSystemProperties();
    config.setBlockchainConfig(new GenesisConfig(new GenesisConfig.GenesisConstants() {

        @Override
        public BlockDifficulty getMinimumDifficulty() {
            return new BlockDifficulty(BigInteger.ONE);
        }
    }));
    IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    Repository repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB()));
    EthereumListenerAdapter listener = new EthereumListenerAdapter();
    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
    BlockChainImpl blockchain = new BlockChainImpl(config, repository, blockStore, receiptStore, null, listener, new AdminInfo(), new DummyBlockValidator());
    blockchain.setNoValidation(true);
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repository, null, receiptStore, null, listener, 10, 100);
    blockchain.setTransactionPool(transactionPool);
    Repository track = repository.startTracking();
    for (RskAddress addr : genesis.getPremine().keySet()) {
        track.createAccount(addr);
        track.addBalance(addr, genesis.getPremine().get(addr).getAccountState().getBalance());
    }
    track.commit();
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    blockchain.setBestBlock(genesis);
    blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty());
    return blockchain;
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) AdminInfo(org.ethereum.manager.AdminInfo) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) EthereumListenerAdapter(org.ethereum.listener.EthereumListenerAdapter) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) BlockDifficulty(co.rsk.core.BlockDifficulty) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) RepositoryImpl(co.rsk.db.RepositoryImpl) RskAddress(co.rsk.core.RskAddress) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) RskSystemProperties(co.rsk.config.RskSystemProperties) ReceiptStore(org.ethereum.db.ReceiptStore) GenesisConfig(org.ethereum.config.blockchain.GenesisConfig)

Example 3 with ReceiptStoreImpl

use of org.ethereum.db.ReceiptStoreImpl in project rskj by rsksmart.

the class Web3ImplTest method eth_sendTransaction.

@Test
public void eth_sendTransaction() {
    BigInteger nonce = BigInteger.ONE;
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    Web3Impl web3 = createWeb3(world, receiptStore);
    // **** Initializes data ******************
    String addr1 = web3.personal_newAccountWithSeed("sampleSeed1");
    String addr2 = web3.personal_newAccountWithSeed("sampleSeed2");
    String toAddress = addr2;
    BigInteger value = BigInteger.valueOf(7);
    BigInteger gasPrice = BigInteger.valueOf(8);
    BigInteger gasLimit = BigInteger.valueOf(9);
    String data = "0xff";
    // ***** Executes the transaction *******************
    Web3.CallArguments args = new Web3.CallArguments();
    args.from = addr1;
    args.to = addr2;
    args.data = data;
    args.gas = TypeConverter.toJsonHex(gasLimit);
    args.gasPrice = TypeConverter.toJsonHex(gasPrice);
    args.value = value.toString();
    args.nonce = nonce.toString();
    String txHash = null;
    try {
        txHash = web3.eth_sendTransaction(args);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // ***** Verifies tx hash
    Transaction tx = Transaction.create(config, toAddress.substring(2), value, nonce, gasPrice, gasLimit, args.data);
    tx.sign(wallet.getAccount(new RskAddress(addr1)).getEcKey().getPrivKeyBytes());
    String expectedHash = tx.getHash().toJsonString();
    Assert.assertTrue("Method is not creating the expected transaction", expectedHash.compareTo(txHash) == 0);
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) JsonRpcInvalidParamException(org.ethereum.rpc.exception.JsonRpcInvalidParamException) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) BigInteger(java.math.BigInteger) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 4 with ReceiptStoreImpl

use of org.ethereum.db.ReceiptStoreImpl in project rskj by rsksmart.

the class Web3ImplTest method getTransactionReceipt.

@Test
public void getTransactionReceipt() throws Exception {
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    Web3Impl web3 = createWeb3(world, receiptStore);
    Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(2000000)).build();
    Account acc2 = new AccountBuilder().name("acc2").build();
    Transaction tx = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    Block genesis = world.getBlockChain().getBestBlock();
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
    String hashString = tx.getHash().toHexString();
    TransactionReceiptDTO tr = web3.eth_getTransactionReceipt(hashString);
    org.junit.Assert.assertNotNull(tr);
    org.junit.Assert.assertEquals("0x" + hashString, tr.transactionHash);
    String trxFrom = TypeConverter.toJsonHex(tx.getSender().getBytes());
    org.junit.Assert.assertEquals(trxFrom, tr.from);
    String trxTo = TypeConverter.toJsonHex(tx.getReceiveAddress().getBytes());
    org.junit.Assert.assertEquals(trxTo, tr.to);
    String blockHashString = "0x" + block1.getHash();
    org.junit.Assert.assertEquals(blockHashString, tr.blockHash);
    String blockNumberAsHex = "0x" + Long.toHexString(block1.getNumber());
    org.junit.Assert.assertEquals(blockNumberAsHex, tr.blockNumber);
}
Also used : TransactionBuilder(co.rsk.test.builders.TransactionBuilder) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) TransactionReceiptDTO(org.ethereum.rpc.dto.TransactionReceiptDTO) AccountBuilder(co.rsk.test.builders.AccountBuilder) ReceiptStore(org.ethereum.db.ReceiptStore) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 5 with ReceiptStoreImpl

use of org.ethereum.db.ReceiptStoreImpl in project rskj by rsksmart.

the class Web3ImplTest method getUnknownTransactionReceipt.

@Test
public void getUnknownTransactionReceipt() throws Exception {
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    Web3Impl web3 = createWeb3(world, receiptStore);
    Account acc1 = new AccountBuilder().name("acc1").build();
    Account acc2 = new AccountBuilder().name("acc2").build();
    Transaction tx = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
    String hashString = tx.getHash().toHexString();
    Assert.assertNull(web3.eth_getTransactionReceipt(hashString));
}
Also used : ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Aggregations

HashMapDB (org.ethereum.datasource.HashMapDB)8 ReceiptStore (org.ethereum.db.ReceiptStore)8 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)8 World (co.rsk.test.World)6 AccountBuilder (co.rsk.test.builders.AccountBuilder)4 Test (org.junit.Test)4 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)3 BlockBuilder (co.rsk.test.builders.BlockBuilder)3 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)3 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)2 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)2 AdminInfo (org.ethereum.manager.AdminInfo)2 TransactionReceiptDTO (org.ethereum.rpc.dto.TransactionReceiptDTO)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 BlockDifficulty (co.rsk.core.BlockDifficulty)1 RskAddress (co.rsk.core.RskAddress)1 RepositoryImpl (co.rsk.db.RepositoryImpl)1 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)1 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)1 BigInteger (java.math.BigInteger)1