Search in sources :

Example 1 with EthereumFacade

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());
    }
}
Also used : EthereumFacade(org.adridadou.ethereum.propeller.EthereumFacade) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with EthereumFacade

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;
}
Also used : Ethash(org.ethereum.mine.Ethash) LoggerFactory(org.slf4j.LoggerFactory) AccountProvider(org.adridadou.ethereum.propeller.keystore.AccountProvider) EthereumEventHandler(org.adridadou.ethereum.propeller.event.EthereumEventHandler) Block(org.ethereum.core.Block) MinerListener(org.ethereum.mine.MinerListener) SystemProperties(org.ethereum.config.SystemProperties) Ethereum(org.ethereum.facade.Ethereum) ConfigFactory(com.typesafe.config.ConfigFactory) CoreEthereumFacadeProvider(org.adridadou.ethereum.propeller.CoreEthereumFacadeProvider) EthereumReal(org.adridadou.ethereum.ethj.EthereumReal) Logger(org.slf4j.Logger) EthereumBackend(org.adridadou.ethereum.propeller.EthereumBackend) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) EthereumFactory(org.ethereum.facade.EthereumFactory) DatabaseDirectory(org.adridadou.ethereum.values.config.DatabaseDirectory) File(java.io.File) EthAccount(org.adridadou.ethereum.propeller.values.EthAccount) EthereumFacade(org.adridadou.ethereum.propeller.EthereumFacade) ExecutionException(java.util.concurrent.ExecutionException) EthereumApiException(org.adridadou.ethereum.propeller.exception.EthereumApiException) EthereumConfig(org.adridadou.ethereum.propeller.EthereumConfig) BasicSample(org.ethereum.samples.BasicSample) Bean(org.springframework.context.annotation.Bean) EthereumJConfigs(org.adridadou.ethereum.ethj.EthereumJConfigs) EthereumReal(org.adridadou.ethereum.ethj.EthereumReal) EthereumEventHandler(org.adridadou.ethereum.propeller.event.EthereumEventHandler) Ethereum(org.ethereum.facade.Ethereum) EthereumFacade(org.adridadou.ethereum.propeller.EthereumFacade) IOException(java.io.IOException) File(java.io.File) EthereumApiException(org.adridadou.ethereum.propeller.exception.EthereumApiException) EthereumBackend(org.adridadou.ethereum.propeller.EthereumBackend)

Example 3 with EthereumFacade

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());
}
Also used : EthereumFacade(org.adridadou.ethereum.propeller.EthereumFacade) Test(org.junit.Test)

Example 4 with EthereumFacade

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);
}
Also used : EthereumFacade(org.adridadou.ethereum.propeller.EthereumFacade) URISyntaxException(java.net.URISyntaxException) ExecutionException(java.util.concurrent.ExecutionException) EthereumApiException(org.adridadou.ethereum.propeller.exception.EthereumApiException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

EthereumFacade (org.adridadou.ethereum.propeller.EthereumFacade)4 Test (org.junit.Test)3 ExecutionException (java.util.concurrent.ExecutionException)2 EthereumApiException (org.adridadou.ethereum.propeller.exception.EthereumApiException)2 Ignore (org.junit.Ignore)2 ConfigFactory (com.typesafe.config.ConfigFactory)1 File (java.io.File)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 EthereumJConfigs (org.adridadou.ethereum.ethj.EthereumJConfigs)1 EthereumReal (org.adridadou.ethereum.ethj.EthereumReal)1 CoreEthereumFacadeProvider (org.adridadou.ethereum.propeller.CoreEthereumFacadeProvider)1 EthereumBackend (org.adridadou.ethereum.propeller.EthereumBackend)1 EthereumConfig (org.adridadou.ethereum.propeller.EthereumConfig)1 EthereumEventHandler (org.adridadou.ethereum.propeller.event.EthereumEventHandler)1 AccountProvider (org.adridadou.ethereum.propeller.keystore.AccountProvider)1 EthAccount (org.adridadou.ethereum.propeller.values.EthAccount)1 DatabaseDirectory (org.adridadou.ethereum.values.config.DatabaseDirectory)1 FileUtils (org.apache.commons.io.FileUtils)1 SystemProperties (org.ethereum.config.SystemProperties)1