org.web3j.crypto.SampleKeys Java Examples

The following examples show how to use org.web3j.crypto.SampleKeys. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContractTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
private Contract deployContract(TransactionReceipt transactionReceipt) throws Exception {

        prepareTransaction(transactionReceipt);

        String encodedConstructor =
                FunctionEncoder.encodeConstructor(
                        Collections.<Type>singletonList(new Uint256(BigInteger.TEN)));
        ContractGasProvider contractGasProvider = new DefaultGasProvider();
        return TestContract.deployRemoteCall(
                        TestContract.class,
                        web3j,
                        getVerifiedTransactionManager(SampleKeys.CREDENTIALS),
                        contractGasProvider,
                        "0xcafed00d",
                        encodedConstructor,
                        BigInteger.ZERO)
                .send();
    }
 
Example #2
Source File: ContractTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeployInvalidContractAddress() throws Throwable {
    TransactionReceipt transactionReceipt = new TransactionReceipt();
    transactionReceipt.setTransactionHash(TRANSACTION_HASH);

    prepareTransaction(transactionReceipt);
    ContractGasProvider contractGasProvider = new DefaultGasProvider();
    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Collections.<Type>singletonList(new Uint256(BigInteger.TEN)));
    assertThrows(
            RuntimeException.class,
            () ->
                    TestContract.deployRemoteCall(
                                    TestContract.class,
                                    web3j,
                                    SampleKeys.CREDENTIALS,
                                    contractGasProvider,
                                    "0xcafed00d",
                                    encodedConstructor,
                                    BigInteger.ZERO)
                            .send());
}
 
Example #3
Source File: ManagedTransactionTester.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
void prepareNonceRequest() throws IOException {
    PlatonGetTransactionCount ethGetTransactionCount = new PlatonGetTransactionCount();
    ethGetTransactionCount.setResult("0x1");

    Request<?, PlatonGetTransactionCount> transactionCountRequest = mock(Request.class);
    when(transactionCountRequest.send())
            .thenReturn(ethGetTransactionCount);
    when(web3j.platonGetTransactionCount(SampleKeys.ADDRESS, DefaultBlockParameterName.PENDING))
            .thenReturn((Request) transactionCountRequest);
}
 
Example #4
Source File: ContractTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeout() throws IOException {
    prepareTransaction(null);

    TransactionManager transactionManager =
            getVerifiedTransactionManager(SampleKeys.CREDENTIALS, 1, 1);

    contract = new TestContract(ADDRESS, web3j, transactionManager, new DefaultGasProvider());
    assertThrows(TransactionException.class, this::testErrorScenario);
}
 
Example #5
Source File: ContractTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() throws Exception {
    super.setUp();

    contract =
            new TestContract(
                    ADDRESS,
                    web3j,
                    getVerifiedTransactionManager(SampleKeys.CREDENTIALS),
                    new DefaultGasProvider());
}
 
Example #6
Source File: TransferTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransferInvalidValue() {

    assertThrows(
            UnsupportedOperationException.class,
            () ->
                    sendFunds(
                            SampleKeys.CREDENTIALS,
                            ADDRESS,
                            new BigDecimal(0.1),
                            Convert.Unit.WEI));
}
 
Example #7
Source File: RawTransactionManagerTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testTxHashMismatch() throws IOException {
    TransactionReceipt transactionReceipt = prepareTransfer();
    prepareTransaction(transactionReceipt);

    TransactionManager transactionManager =
            new RawTransactionManager(web3j, SampleKeys.CREDENTIALS);
    Transfer transfer = new Transfer(web3j, transactionManager);
    assertThrows(
            TxHashMismatchException.class,
            () -> transfer.sendFunds(ADDRESS, BigDecimal.ONE, Convert.Unit.ETHER).send());
}
 
Example #8
Source File: ManagedTransactionTester.java    From web3j with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
void prepareNonceRequest() throws IOException {
    EthGetTransactionCount ethGetTransactionCount = new EthGetTransactionCount();
    ethGetTransactionCount.setResult("0x1");

    Request<?, EthGetTransactionCount> transactionCountRequest = mock(Request.class);
    when(transactionCountRequest.send()).thenReturn(ethGetTransactionCount);
    when(web3j.ethGetTransactionCount(SampleKeys.ADDRESS, DefaultBlockParameterName.PENDING))
            .thenReturn((Request) transactionCountRequest);
}
 
Example #9
Source File: ContractTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
private Contract deployContract(TransactionReceipt transactionReceipt)
        throws Exception {

    prepareTransaction(transactionReceipt);

    String encodedConstructor = FunctionEncoder.encodeConstructor(
            Arrays.<Type>asList(new Uint256(BigInteger.TEN)));

    return TestContract.deployRemoteCall(
            TestContract.class, web3j, SampleKeys.CREDENTIALS,
            ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT,
            "0xcafed00d", encodedConstructor, BigInteger.ZERO).send();
}
 
Example #10
Source File: ContractTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected = TransactionException.class)
public void testTimeout() throws Throwable {
    prepareTransaction(null);

    TransactionManager transactionManager = new RawTransactionManager(
            web3j, SampleKeys.CREDENTIALS, 1, 1);

    contract = new TestContract(
            ADDRESS, web3j, transactionManager,
            ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT);

    testErrorScenario();
}
 
Example #11
Source File: ContractTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();

    contract = new TestContract(
            ADDRESS, web3j, SampleKeys.CREDENTIALS,
            ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT);
}
 
Example #12
Source File: ManagedTransactionTester.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
void prepareNonceRequest() throws IOException {
    EthGetTransactionCount ethGetTransactionCount = new EthGetTransactionCount();
    ethGetTransactionCount.setResult("0x1");

    Request<?, EthGetTransactionCount> transactionCountRequest = mock(Request.class);
    when(transactionCountRequest.send())
            .thenReturn(ethGetTransactionCount);
    when(web3j.ethGetTransactionCount(SampleKeys.ADDRESS, DefaultBlockParameterName.PENDING))
            .thenReturn((Request) transactionCountRequest);
}
 
Example #13
Source File: ContractTest.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
private Contract deployContract(TransactionReceipt transactionReceipt)
        throws Exception {

    prepareTransaction(transactionReceipt);

    String encodedConstructor = FunctionEncoder.encodeConstructor(
            Arrays.<Type>asList(new Uint256(BigInteger.TEN)));

    return TestContract.deployRemoteCall(
            TestContract.class, web3j, getVerifiedTransactionManager(SampleKeys.CREDENTIALS),
            ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT,
            "0xcafed00d", encodedConstructor, BigInteger.ZERO).send();
}
 
Example #14
Source File: ContractTest.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test(expected = TransactionException.class)
public void testTimeout() throws Throwable {
    prepareTransaction(null);

    TransactionManager transactionManager =
            getVerifiedTransactionManager(SampleKeys.CREDENTIALS, 1, 1);

    contract = new TestContract(
            ADDRESS, web3j, transactionManager,
            new DefaultGasProvider());

    testErrorScenario();
}
 
Example #15
Source File: ContractTest.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();

    contract = new TestContract(
            ADDRESS, web3j, getVerifiedTransactionManager(SampleKeys.CREDENTIALS),
            new DefaultGasProvider());
}
 
Example #16
Source File: RawTransactionManagerTest.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test(expected = TxHashMismatchException.class)
public void testTxHashMismatch() throws Exception {
    TransactionReceipt transactionReceipt = prepareTransfer();
    prepareTransaction(transactionReceipt);

    TransactionManager transactionManager =
            new RawTransactionManager(web3j, SampleKeys.CREDENTIALS);
    Transfer transfer = new Transfer(web3j, transactionManager);
    transfer.sendFunds(ADDRESS, BigDecimal.ONE, Convert.Unit.LAT).send();
}
 
Example #17
Source File: TransferTest.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testSendFundsAsync() throws  Exception {
    assertThat(Transfer.sendFunds(web3j, SampleKeys.CREDENTIALS, ADDRESS,
            BigDecimal.TEN, Convert.Unit.ETHER).send(),
            is(transactionReceipt));
}
 
Example #18
Source File: TransferTest.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
@Test(expected = UnsupportedOperationException.class)
public void testTransferInvalidValue() throws Exception {
    Transfer.sendFunds(web3j, SampleKeys.CREDENTIALS, ADDRESS,
            new BigDecimal(0.1), Convert.Unit.WEI).send();
}
 
Example #19
Source File: TransferTest.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testSendFunds() throws Exception {
    assertThat(Transfer.sendFunds(web3j, SampleKeys.CREDENTIALS, ADDRESS,
            BigDecimal.TEN, Convert.Unit.ETHER).send(),
            is(transactionReceipt));
}
 
Example #20
Source File: KeyImporterTest.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testSpecifyPrivateKey() {
    prepareWalletCreation(SampleKeys.PRIVATE_KEY_STRING);
}
 
Example #21
Source File: TransferTest.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testSendFunds() throws Exception {
    assertEquals(
            sendFunds(SampleKeys.CREDENTIALS, ADDRESS, BigDecimal.TEN, Convert.Unit.ETHER),
            (transactionReceipt));
}
 
Example #22
Source File: TransferTest.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test(expected = UnsupportedOperationException.class)
public void testTransferInvalidValue() throws Exception {
    sendFunds(SampleKeys.CREDENTIALS, ADDRESS,
            new BigDecimal(0.1), Convert.Unit.VON);
}
 
Example #23
Source File: TransferTest.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testSendFunds() throws Exception {
    assertThat(sendFunds(SampleKeys.CREDENTIALS, ADDRESS,
            BigDecimal.TEN, Convert.Unit.LAT),
            is(transactionReceipt));
}
 
Example #24
Source File: KeyImporterTest.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testSpecifyPrivateKey() {
    prepareWalletCreation(SampleKeys.PRIVATE_KEY_STRING);
}