Search in sources :

Example 41 with RskSystemProperties

use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.

the class AccountBuilder method build.

public static StateWrap build(AccountTck account) {
    ContractDetailsImpl details = new ContractDetailsImpl(new RskSystemProperties());
    details.setCode(parseData(account.getCode()));
    details.setStorage(convertStorage(account.getStorage()));
    AccountState state = new AccountState();
    state.addToBalance(new Coin(unifiedNumericToBigInteger(account.getBalance())));
    state.setNonce(unifiedNumericToBigInteger(account.getNonce()));
    state.setStateRoot(details.getStorageHash());
    state.setCodeHash(HashUtil.keccak256(details.getCode()));
    return new StateWrap(state, details);
}
Also used : Coin(co.rsk.core.Coin) ContractDetailsImpl(co.rsk.db.ContractDetailsImpl) AccountState(org.ethereum.core.AccountState) RskSystemProperties(co.rsk.config.RskSystemProperties)

Example 42 with RskSystemProperties

use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.

the class BlockchainVMTest method testSEND_1.

@Test
public void testSEND_1() {
    NewBlockChainInfo binfo = createNewBlockchain();
    Blockchain blockchain = binfo.blockchain;
    BlockGenerator blockGenerator = new BlockGenerator();
    Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock(), null, binfo.repository.getRoot());
    List<Transaction> txs = new ArrayList<>();
    Coin transferAmount = Coin.valueOf(100L);
    // Add a single transaction paying to a new address
    byte[] dstAddress = randomAddress();
    BigInteger transactionGasLimit = new BigInteger("21000");
    Coin transactionGasPrice = Coin.valueOf(1);
    Transaction t = new Transaction(ZERO_BYTE_ARRAY, transactionGasPrice.getBytes(), transactionGasLimit.toByteArray(), dstAddress, transferAmount.getBytes(), null, new RskSystemProperties().getBlockchainConfig().getCommonConstants().getChainId());
    t.sign(binfo.faucetKey.getPrivKeyBytes());
    txs.add(t);
    Block block2 = blockGenerator.createChildBlock(block1, txs, binfo.repository.getRoot());
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block1));
    MinerHelper mh = new MinerHelper(binfo.repository, binfo.blockchain);
    mh.completeBlock(block2, block1);
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block2));
    Assert.assertEquals(blockchain.getBestBlock(), block2);
    Assert.assertEquals(2, block2.getNumber());
    Coin srcAmount = faucetAmount.subtract(transferAmount);
    srcAmount = srcAmount.subtract(transactionGasPrice.multiply(transactionGasLimit));
    Assert.assertEquals(binfo.repository.getBalance(new RskAddress(binfo.faucetKey.getAddress())), srcAmount);
    Assert.assertEquals(binfo.repository.getBalance(new RskAddress(dstAddress)), transferAmount);
}
Also used : ArrayList(java.util.ArrayList) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Coin(co.rsk.core.Coin) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Example 43 with RskSystemProperties

use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.

the class ConfigTest method ethereumjConfTest.

@Test
public void ethereumjConfTest() {
    RskSystemProperties config = new RskSystemProperties();
    System.out.println("'" + config.databaseDir() + "'");
    System.out.println(config.peerActive());
}
Also used : RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Example 44 with RskSystemProperties

use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.

the class SystemPropertiesTest method punchBindIpTest.

@Test
public void punchBindIpTest() {
    RskSystemProperties config = new RskSystemProperties();
    config.overrideParams("bind.address", "");
    long st = System.currentTimeMillis();
    InetAddress ip = config.getBindAddress();
    long t = System.currentTimeMillis() - st;
    System.out.println(ip + " in " + t + " msec");
    Assert.assertTrue(t < 10 * 1000);
    Assert.assertFalse(ip.toString().isEmpty());
}
Also used : InetAddress(java.net.InetAddress) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Example 45 with RskSystemProperties

use of co.rsk.config.RskSystemProperties 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)

Aggregations

RskSystemProperties (co.rsk.config.RskSystemProperties)112 Test (org.junit.Test)81 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)48 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)45 Blockchain (org.ethereum.core.Blockchain)45 Block (org.ethereum.core.Block)41 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)35 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)20 Ignore (org.junit.Ignore)10 Keccak256 (co.rsk.crypto.Keccak256)8 RegTestConfig (org.ethereum.config.blockchain.RegTestConfig)8 Repository (org.ethereum.core.Repository)8 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)8 Channel (org.ethereum.net.server.Channel)7 ChannelManager (org.ethereum.net.server.ChannelManager)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 BlockDifficulty (co.rsk.core.BlockDifficulty)6 RskAddress (co.rsk.core.RskAddress)6 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)6 BeforeClass (org.junit.BeforeClass)6