<commit_before>package org.adridadou.propeller.ethj;

import org.adridadou.ethereum.EthjEthereumFacadeProvider;
import org.adridadou.ethereum.ethj.TestConfig;
import org.adridadou.ethereum.ethj.privatenetwork.PrivateEthereumFacadeProvider;
import org.adridadou.ethereum.propeller.EthereumConfig;
import org.adridadou.ethereum.propeller.EthereumFacade;
import org.adridadou.ethereum.propeller.exception.EthereumApiException;
import org.adridadou.ethereum.propeller.keystore.AccountProvider;
import org.adridadou.ethereum.propeller.solidity.SolidityContractDetails;
import org.adridadou.ethereum.propeller.values.EthAccount;
import org.adridadou.ethereum.propeller.values.EthAddress;
import org.adridadou.ethereum.propeller.values.Payable;
import org.adridadou.ethereum.propeller.values.SoliditySourceFile;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import static org.adridadou.ethereum.ethj.EthereumJConfigs.ropsten;
import static org.adridadou.ethereum.ethj.privatenetwork.PrivateNetworkConfig.config;
import static org.adridadou.ethereum.propeller.values.EthValue.ether;
import static org.junit.Assert.*;

/**
 * Created by davidroon on 20.04.16.
 * This code is released under Apache 2 license
 */
public class TestnetConnectionTest {
    private final PrivateEthereumFacadeProvider privateNetwork = new PrivateEthereumFacadeProvider();
    /**
     * used by multiThreadTest()
     */
    private boolean somethingDied;
    private EthAccount mainAccount = AccountProvider.fromSeed("cow");
    private EthAddress address;

    public TestnetConnectionTest() throws URISyntaxException {
    }

    private EthereumFacade fromRopsten() {
        EthjEthereumFacadeProvider.Builder ethereumProvider = EthjEthereumFacadeProvider.forNetwork(ropsten());
        ethereumProvider.extendConfig().fastSync(true);
        return ethereumProvider.create(EthereumConfig.builder().build());
    }

    private EthereumFacade fromPrivateNetwork() {
        return privateNetwork.create(config()
                .reset(true)
                .initialBalance(mainAccount, ether(10)), EthereumConfig.builder().build());
    }

    private EthereumFacade fromTest() {
        return EthjEthereumFacadeProvider.forTest(TestConfig.builder()
                .balance(mainAccount, ether(10000000))
                .build());
    }

    private MyContract2 publishAndMapContract(EthereumFacade ethereum) throws Exception {
        SolidityContractDetails compiledContract = ethereum.compile(SoliditySourceFile.from(new File("src/test/resources/contract.sol"))).findContract("myContract2").get();
        CompletableFuture<EthAddress> futureAddress = ethereum.publishContract(compiledContract, mainAccount);
        this.address = futureAddress.get();
        return ethereum.createContractProxy(compiledContract, futureAddress.get(), mainAccount, MyContract2.class);
    }

    private void testMethodCalls(MyContract2 myContract, EthAddress address, EthereumFacade ethereum) throws Exception {
        assertEquals("", myContract.getI1());
        Future<Integer> future = myContract.myMethod("this is a test");
        assertEquals(12, future.get().intValue());
        assertEquals("this is a test", myContract.getI1());
        assertTrue(myContract.getT());

        Integer[] expected = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        assertArrayEquals(expected, myContract.getArray().toArray(new Integer[10]));

        assertArrayEquals(expected, myContract.getSet().toArray(new Integer[10]));

        assertEquals(new MyReturnType(true, "hello", 34), myContract.getM());

        assertEquals("", myContract.getI2());
        myContract.myMethod2("async call").get();

        myContract.myMethod3("async call").with(ether(150)).get();

        assertEquals(ether(150), ethereum.getBalance(address));

        assertEquals(mainAccount.getAddress(), myContract.getOwner());

        assertEquals("async call", myContract.getI2());

        assertEquals(EnumTest.VAL2, myContract.getEnumValue());

        assertEquals(new Date(150_000), myContract.getInitTime(new Date(150_000)));
        assertEquals(mainAccount.getAddress(), myContract.getAccountAddress(mainAccount));
        try {
            myContract.throwMe().get();
            fail("the call should fail!");
        } catch (final ExecutionException ex) {
            assertEquals(EthereumApiException.class, ex.getCause().getClass());
        }
    }

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

    @Test<commit_msg>ignore test<commit_after>package org.adridadou.propeller.ethj;

import org.adridadou.ethereum.EthjEthereumFacadeProvider;
import org.adridadou.ethereum.ethj.TestConfig;
import org.adridadou.ethereum.ethj.privatenetwork.PrivateEthereumFacadeProvider;
import org.adridadou.ethereum.propeller.EthereumConfig;
import org.adridadou.ethereum.propeller.EthereumFacade;
import org.adridadou.ethereum.propeller.exception.EthereumApiException;
import org.adridadou.ethereum.propeller.keystore.AccountProvider;
import org.adridadou.ethereum.propeller.solidity.SolidityContractDetails;
import org.adridadou.ethereum.propeller.values.EthAccount;
import org.adridadou.ethereum.propeller.values.EthAddress;
import org.adridadou.ethereum.propeller.values.Payable;
import org.adridadou.ethereum.propeller.values.SoliditySourceFile;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import static org.adridadou.ethereum.ethj.EthereumJConfigs.ropsten;
import static org.adridadou.ethereum.ethj.privatenetwork.PrivateNetworkConfig.config;
import static org.adridadou.ethereum.propeller.values.EthValue.ether;
import static org.junit.Assert.*;

/**
 * Created by davidroon on 20.04.16.
 * This code is released under Apache 2 license
 */
public class TestnetConnectionTest {
    private final PrivateEthereumFacadeProvider privateNetwork = new PrivateEthereumFacadeProvider();
    /**
     * used by multiThreadTest()
     */
    private boolean somethingDied;
    private EthAccount mainAccount = AccountProvider.fromSeed("cow");
    private EthAddress address;

    public TestnetConnectionTest() {
    }

    private EthereumFacade fromRopsten() {
        EthjEthereumFacadeProvider.Builder ethereumProvider = EthjEthereumFacadeProvider.forNetwork(ropsten());
        ethereumProvider.extendConfig().fastSync(true);
        return ethereumProvider.create(EthereumConfig.builder().build());
    }

    private EthereumFacade fromPrivateNetwork() {
        return privateNetwork.create(config()
                .reset(true)
                .initialBalance(mainAccount, ether(10)), EthereumConfig.builder().build());
    }

    private EthereumFacade fromTest() {
        return EthjEthereumFacadeProvider.forTest(TestConfig.builder()
                .balance(mainAccount, ether(10000000))
                .build());
    }

    private MyContract2 publishAndMapContract(EthereumFacade ethereum) throws Exception {
        SolidityContractDetails compiledContract = ethereum.compile(SoliditySourceFile.from(new File("src/test/resources/contract.sol"))).findContract("myContract2").get();
        CompletableFuture<EthAddress> futureAddress = ethereum.publishContract(compiledContract, mainAccount);
        this.address = futureAddress.get();
        return ethereum.createContractProxy(compiledContract, futureAddress.get(), mainAccount, MyContract2.class);
    }

    private void testMethodCalls(MyContract2 myContract, EthAddress address, EthereumFacade ethereum) throws Exception {
        assertEquals("", myContract.getI1());
        Future<Integer> future = myContract.myMethod("this is a test");
        assertEquals(12, future.get().intValue());
        assertEquals("this is a test", myContract.getI1());
        assertTrue(myContract.getT());

        Integer[] expected = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        assertArrayEquals(expected, myContract.getArray().toArray(new Integer[10]));

        assertArrayEquals(expected, myContract.getSet().toArray(new Integer[10]));

        assertEquals(new MyReturnType(true, "hello", 34), myContract.getM());

        assertEquals("", myContract.getI2());
        myContract.myMethod2("async call").get();

        myContract.myMethod3("async call").with(ether(150)).get();

        assertEquals(ether(150), ethereum.getBalance(address));

        assertEquals(mainAccount.getAddress(), myContract.getOwner());

        assertEquals("async call", myContract.getI2());

        assertEquals(EnumTest.VAL2, myContract.getEnumValue());

        assertEquals(new Date(150_000), myContract.getInitTime(new Date(150_000)));
        assertEquals(mainAccount.getAddress(), myContract.getAccountAddress(mainAccount));
        try {
            myContract.throwMe().get();
            fail("the call should fail!");
        } catch (final ExecutionException ex) {
            assertEquals(EthereumApiException.class, ex.getCause().getClass());
        }
    }

    @Test
    @Ignore
    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());
    }

    @Test
{'fraction_non_alphanumeric': 0.10914927768860354, 'fraction_numerical': 0.013041733547351525, 'mean_word_length': 4.27181385510312, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '17396', 'n_tokens_mistral': 3003, 'n_tokens_neox': 2809, 'n_words': 487}