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);
}
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);
}
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());
}
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());
}
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;
}
Aggregations