use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.
the class BlockchainLoaderTest method testLoadBlockchainEmptyBlockchain.
@Test
public void testLoadBlockchainEmptyBlockchain() throws IOException {
String jsonFile = "blockchain_loader_genesis.json";
RskSystemProperties systemProperties = Mockito.mock(RskSystemProperties.class);
Constants constants = Mockito.mock(Constants.class);
Mockito.when(constants.getInitialNonce()).thenReturn(BigInteger.ZERO);
BlockchainNetConfig blockchainNetConfig = Mockito.mock(BlockchainNetConfig.class);
Mockito.when(blockchainNetConfig.getCommonConstants()).thenReturn(constants);
Mockito.when(systemProperties.databaseDir()).thenReturn(new RskSystemProperties().databaseDir());
Mockito.when(systemProperties.getBlockchainConfig()).thenReturn(blockchainNetConfig);
Mockito.when(systemProperties.genesisInfo()).thenReturn(jsonFile);
BlockStore blockStore = Mockito.mock(BlockStore.class);
Mockito.when(blockStore.getBestBlock()).thenReturn(null);
EthereumListener ethereumListener = Mockito.mock(EthereumListener.class);
Repository repository = new RepositoryImpl(systemProperties, new TrieStoreImpl(new HashMapDB().setClearOnClose(false)));
;
BlockChainLoader blockChainLoader = new BlockChainLoader(systemProperties, repository, blockStore, null, null, ethereumListener, null, null);
blockChainLoader.loadBlockchain();
Assert.assertEquals(5, repository.getAccountsKeys().size());
Assert.assertEquals(Coin.valueOf(2000), repository.getBalance(new RskAddress("dabadabadabadabadabadabadabadabadaba0001")));
Assert.assertEquals(BigInteger.valueOf(24), repository.getNonce(new RskAddress("dabadabadabadabadabadabadabadabadaba0001")));
Assert.assertEquals(Coin.valueOf(1000), repository.getBalance(new RskAddress("dabadabadabadabadabadabadabadabadaba0002")));
Assert.assertEquals(BigInteger.ZERO, repository.getNonce(new RskAddress("dabadabadabadabadabadabadabadabadaba0002")));
Assert.assertEquals(Coin.valueOf(10), repository.getBalance(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")));
Assert.assertEquals(BigInteger.valueOf(25), repository.getNonce(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")));
Assert.assertEquals(DataWord.ONE, repository.getContractDetails(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")).get(DataWord.ZERO));
Assert.assertEquals(new DataWord(3), repository.getContractDetails(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")).get(DataWord.ONE));
Assert.assertEquals(274, repository.getContractDetails(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")).getCode().length);
}
use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.
the class MainNetMinerTest method generateFallbackMinedBlock.
@Test
public void generateFallbackMinedBlock() throws InterruptedException, IOException {
// generate private keys for testing now.
ECKey privateMiningKey0 = ECKey.fromPrivate(BigInteger.TEN);
ECKey privateMiningKey1 = ECKey.fromPrivate(BigInteger.TEN.add(BigInteger.ONE));
byte[] privKey0 = privateMiningKey0.getPrivKeyBytes();
saveToFile(privKey0, new File(folder.getRoot().getCanonicalPath(), "privkey0.bin"));
byte[] privKey1 = privateMiningKey1.getPrivKeyBytes();
saveToFile(privKey1, new File(folder.getRoot().getCanonicalPath(), "privkey1.bin"));
RskSystemProperties tempConfig = new RskSystemProperties() {
BlockchainNetConfig blockchainNetConfig = config.getBlockchainConfig();
@Override
public String fallbackMiningKeysDir() {
try {
return folder.getRoot().getCanonicalPath();
} catch (Exception e) {
}
return null;
}
@Override
public BlockchainNetConfig getBlockchainConfig() {
return new BlockchainNetConfig() {
@Override
public BlockchainConfig getConfigForBlock(long blockNumber) {
return blockchainNetConfig.getConfigForBlock(blockNumber);
}
@Override
public Constants getCommonConstants() {
return new Constants() {
@Override
public byte[] getFallbackMiningPubKey0() {
return privateMiningKey0.getPubKey();
}
@Override
public byte[] getFallbackMiningPubKey1() {
return privateMiningKey1.getPubKey();
}
};
}
};
}
};
EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
Mockito.when(ethereumImpl.addNewMinedBlock(Mockito.any())).thenReturn(ImportResult.IMPORTED_BEST);
MinerServer minerServer = new MinerServerImpl(tempConfig, ethereumImpl, blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(tempConfig).setFallbackMiningEnabled(true), blockToMineBuilder(), ConfigUtils.getDefaultMiningConfig());
try {
minerServer.setFallbackMining(true);
// Accelerate mining
((MinerServerImpl) minerServer).setSecsBetweenFallbackMinedBlocks(1);
minerServer.start();
// Blocks are generated auomatically
// but we can call minerServer.generateFallbackBlock() to generate it manually
// boolean result = minerServer.generateFallbackBlock();
// Assert.assertTrue(result);
long start = System.currentTimeMillis();
while (((MinerServerImpl) minerServer).getFallbackBlocksGenerated() == 0) {
if (System.currentTimeMillis() - start > 20 * 1000) {
Assert.assertTrue(false);
}
//
Thread.sleep(1000);
}
Mockito.verify(ethereumImpl, Mockito.times(1)).addNewMinedBlock(Mockito.any());
// mine another
// NOTE that is NOT using the next block (parity change) because of the blockchain mockito
// to mine a subsequent block, use a real blockchain, not the mockito.
minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
// result = minerServer.generateFallbackBlock();
// Assert.assertTrue(result);
start = System.currentTimeMillis();
while (((MinerServerImpl) minerServer).getFallbackBlocksGenerated() == 1) {
if (System.currentTimeMillis() - start > 20 * 1000) {
Assert.assertTrue(false);
}
//
Thread.sleep(1000);
}
Mockito.verify(ethereumImpl, Mockito.times(2)).addNewMinedBlock(Mockito.any());
} finally {
minerServer.stop();
}
}
use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.
the class BridgePerformanceTestCase method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
config = new RskSystemProperties();
config.setBlockchainConfig(new RegTestConfig());
bridgeConstants = config.getBlockchainConfig().getCommonConstants().getBridgeConstants();
networkParameters = bridgeConstants.getBtcParams();
}
use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.
the class LockWhitelistTest method buildInitializer.
private BridgeStorageProviderInitializer buildInitializer() {
final int minSize = 10;
final int maxSize = 100;
final int minBtcBlocks = 500;
final int maxBtcBlocks = 1000;
return (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
BtcBlockStore btcBlockStore = new RepositoryBlockStore(new RskSystemProperties(), repository, PrecompiledContracts.BRIDGE_ADDR);
Context btcContext = new Context(networkParameters);
BtcBlockChain btcBlockChain;
try {
btcBlockChain = new BtcBlockChain(btcContext, btcBlockStore);
} catch (BlockStoreException e) {
throw new RuntimeException("Error initializing btc blockchain for tests");
}
int blocksToGenerate = Helper.randomInRange(minBtcBlocks, maxBtcBlocks);
Helper.generateAndAddBlocks(btcBlockChain, blocksToGenerate);
lockWhitelist = provider.getLockWhitelist();
int size = Helper.randomInRange(minSize, maxSize);
for (int i = 0; i < size; i++) {
Address address = new BtcECKey().toAddress(networkParameters);
Coin value = Helper.randomCoin(Coin.COIN, 1, 30);
lockWhitelist.put(address, value);
}
};
}
use of co.rsk.config.RskSystemProperties in project rskj by rsksmart.
the class RemascFederationProviderTest method getRemascFederationProvider.
private static RemascFederationProvider getRemascFederationProvider() throws IOException, BlockStoreException {
Genesis genesisBlock = new BlockGenerator().getGenesisBlock();
BlockChainBuilder builder = new BlockChainBuilder().setTesting(true).setGenesis(genesisBlock);
Blockchain blockchain = builder.build();
BridgeSupport bridgeSupport = new BridgeSupport(new RskSystemProperties(), blockchain.getRepository(), null, PrecompiledContracts.BRIDGE_ADDR, null);
RemascFederationProvider provider = null;
try {
provider = new RemascFederationProvider(bridgeSupport);
} catch (BlockStoreException | IOException e) {
e.printStackTrace();
}
return provider;
}
Aggregations