use of org.adridadou.ethereum.propeller.EthereumFacade in project eth-propeller-ethj by adridadou.
the class TestnetConnectionTest method speedAndReliabilityTest.
@Test
@Ignore
public void speedAndReliabilityTest() throws Exception {
final EthereumFacade ethereum = fromTest();
// myContract.myMethod("1");
for (int i = 0; i < 500; i++) {
MyContract2 myContract = publishAndMapContract(ethereum);
// System.out.println("call no:" + i);
testMethodCalls(myContract, address, ethereum);
assertEquals(mainAccount.getAddress(), myContract.getOwner());
}
}
use of org.adridadou.ethereum.propeller.EthereumFacade in project eth-propeller-ethj by adridadou.
the class PrivateEthereumFacadeProvider method create.
public EthereumFacade create(PrivateNetworkConfig config, EthereumConfig ethereumConfig) {
final boolean dagCached = new File("cachedDag/mine-dag.dat").exists();
if (config.isResetPrivateBlockchain()) {
deleteFolder(new File(config.getDbName()), true);
}
if (dagCached) {
new File(config.getDbName()).mkdirs();
try {
FileUtils.copyFile(new File("cachedDag/mine-dag.dat"), new File(config.getDbName() + "/mine-dag.dat"));
FileUtils.copyFile(new File("cachedDag/mine-dag-light.dat"), new File(config.getDbName() + "/mine-dag-light.dat"));
} catch (IOException e) {
throw new EthereumApiException("error while copying dag files", e);
}
}
MinerConfig.dbName = config.getDbName();
Ethereum ethereum = EthereumFactory.createEthereum(MinerConfig.class);
EthereumBackend ethereumBackend = new EthereumReal(ethereum);
ethereum.initSyncing();
if (!dagCached) {
try {
new File("cachedDag").mkdirs();
FileUtils.copyFile(new File(config.getDbName() + "/mine-dag.dat"), new File("cachedDag/mine-dag.dat"));
FileUtils.copyFile(new File(config.getDbName() + "/mine-dag-light.dat"), new File("cachedDag/mine-dag-light.dat"));
} catch (IOException e) {
log.warn("couldn't copy files: " + e.getMessage());
}
}
EthereumEventHandler ethereumListener = new EthereumEventHandler();
final EthereumFacade facade = CoreEthereumFacadeProvider.create(ethereumBackend, ethereumConfig);
// This event does not trigger when you are the miner
ethereumListener.onReady();
facade.events().ready().thenAccept((b) -> config.getInitialBalances().entrySet().stream().map(entry -> facade.sendEther(mainAccount, entry.getKey().getAddress(), entry.getValue())).forEach(result -> {
try {
result.get();
} catch (InterruptedException | ExecutionException e) {
throw new EthereumApiException("error while setting the initial balances");
}
}));
return facade;
}
use of org.adridadou.ethereum.propeller.EthereumFacade in project eth-propeller-ethj by adridadou.
the class TestnetConnectionTest method main_example_how_the_lib_works.
@Test
public void main_example_how_the_lib_works() throws Exception {
final EthereumFacade ethereum = fromTest();
MyContract2 myContract = publishAndMapContract(ethereum);
testMethodCalls(myContract, address, ethereum);
assertEquals(mainAccount.getAddress(), myContract.getOwner());
}
use of org.adridadou.ethereum.propeller.EthereumFacade in project eth-propeller-ethj by adridadou.
the class TestnetConnectionTest method multiThreadTest.
@Test
@Ignore
public void multiThreadTest() throws Exception {
somethingDied = false;
final EthereumFacade ethereum = fromTest();
final int threadCount = 5;
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(() -> {
try {
for (int i1 = 0; i1 < 10; i1++) {
MyContract2 myContract = publishAndMapContract(ethereum);
testMethodCalls(myContract, address, ethereum);
assertEquals(mainAccount.getAddress(), myContract.getOwner());
}
} catch (Exception e) {
e.printStackTrace();
somethingDied = true;
fail("Something died");
}
});
threads[i].start();
}
// for
for (Thread thread : threads) {
thread.join();
}
// for
assertFalse("Something died, see stack trace", somethingDied);
}
Aggregations