-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add eth_signTransaction Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com> --------- Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com> Co-authored-by: Simon Dudley <simon.dudley@consensys.net> Co-authored-by: Jason Frame <jasonwframe@gmail.com>
- Loading branch information
1 parent
6b3747e
commit 02e9c55
Showing
76 changed files
with
5,827 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/Contracts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.web3signer.dsl; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static tech.pegasys.web3signer.dsl.utils.ExceptionUtils.failOnIOException; | ||
import static tech.pegasys.web3signer.dsl.utils.WaitUtils.waitFor; | ||
|
||
import tech.pegasys.web3signer.core.service.jsonrpc.response.JsonRpcErrorResponse; | ||
import tech.pegasys.web3signer.dsl.signer.SignerResponse; | ||
|
||
import java.io.IOException; | ||
import java.math.BigInteger; | ||
import java.util.Optional; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.awaitility.core.ConditionTimeoutException; | ||
import org.web3j.protocol.core.methods.response.TransactionReceipt; | ||
|
||
public abstract class Contracts<T> { | ||
|
||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
public static final BigInteger GAS_PRICE = BigInteger.valueOf(1000); | ||
public static final BigInteger GAS_LIMIT = BigInteger.valueOf(3000000); | ||
|
||
public abstract String sendTransaction(T smartContract) throws IOException; | ||
|
||
public abstract SignerResponse<JsonRpcErrorResponse> sendTransactionExpectsError(T smartContract) | ||
throws IOException; | ||
|
||
public abstract Optional<? extends TransactionReceipt> getTransactionReceipt(final String hash) | ||
throws IOException; | ||
|
||
public String submit(final T smartContract) { | ||
return failOnIOException(() -> sendTransaction(smartContract)); | ||
} | ||
|
||
public void awaitBlockContaining(final String hash) { | ||
try { | ||
waitFor(() -> assertThat(getTransactionReceipt(hash).isPresent()).isTrue()); | ||
} catch (final ConditionTimeoutException e) { | ||
LOG.error("Timed out waiting for a block containing the transaction receipt hash: " + hash); | ||
} | ||
} | ||
|
||
public String address(final String hash) { | ||
return failOnIOException( | ||
() -> { | ||
final TransactionReceipt receipt = | ||
getTransactionReceipt(hash) | ||
.orElseThrow(() -> new RuntimeException("No receipt found for hash: " + hash)); | ||
assertThat(receipt.getContractAddress()).isNotEmpty(); | ||
return receipt.getContractAddress(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/PublicContracts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.web3signer.dsl; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static tech.pegasys.web3signer.dsl.utils.ExceptionUtils.failOnIOException; | ||
|
||
import tech.pegasys.web3signer.core.service.jsonrpc.response.JsonRpcErrorResponse; | ||
import tech.pegasys.web3signer.dsl.signer.SignerResponse; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
import org.web3j.protocol.core.methods.request.Transaction; | ||
import org.web3j.protocol.core.methods.response.TransactionReceipt; | ||
|
||
public class PublicContracts extends Contracts<Transaction> { | ||
|
||
private final Eth eth; | ||
|
||
public PublicContracts(final Eth eth) { | ||
this.eth = eth; | ||
} | ||
|
||
@Override | ||
public String sendTransaction(final Transaction smartContract) throws IOException { | ||
return eth.sendTransaction(smartContract); | ||
} | ||
|
||
@Override | ||
public SignerResponse<JsonRpcErrorResponse> sendTransactionExpectsError( | ||
final Transaction smartContract) throws IOException { | ||
return eth.sendTransactionExpectsError(smartContract); | ||
} | ||
|
||
@Override | ||
public Optional<TransactionReceipt> getTransactionReceipt(final String hash) throws IOException { | ||
return eth.getTransactionReceipt(hash); | ||
} | ||
|
||
public String code(final String address) { | ||
return failOnIOException( | ||
() -> { | ||
final String code = eth.getCode(address); | ||
assertThat(code).isNotEmpty(); | ||
return code; | ||
}); | ||
} | ||
|
||
public String call(final Transaction contractViewOperation) { | ||
return failOnIOException(() -> eth.call(contractViewOperation)); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/Transactions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.web3signer.dsl; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static tech.pegasys.web3signer.dsl.utils.ExceptionUtils.failOnIOException; | ||
import static tech.pegasys.web3signer.dsl.utils.WaitUtils.waitFor; | ||
|
||
import tech.pegasys.web3signer.core.service.jsonrpc.response.JsonRpcErrorResponse; | ||
import tech.pegasys.web3signer.dsl.signer.SignerResponse; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.awaitility.core.ConditionTimeoutException; | ||
import org.web3j.protocol.core.methods.request.Transaction; | ||
import org.web3j.protocol.exceptions.ClientConnectionException; | ||
|
||
public class Transactions { | ||
|
||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
private final Eth eth; | ||
|
||
public Transactions(final Eth eth) { | ||
this.eth = eth; | ||
} | ||
|
||
public String submit(final Transaction transaction) { | ||
return failOnIOException(() -> eth.sendTransaction(transaction)); | ||
} | ||
|
||
public SignerResponse<JsonRpcErrorResponse> submitExceptional(final Transaction transaction) { | ||
try { | ||
return failOnIOException(() -> eth.sendTransactionExpectsError(transaction)); | ||
} catch (final ClientConnectionException e) { | ||
LOG.info("ClientConnectionException with message: " + e.getMessage()); | ||
return SignerResponse.fromError(e); | ||
} | ||
} | ||
|
||
public void awaitBlockContaining(final String hash) { | ||
try { | ||
waitFor(() -> assertThat(eth.getTransactionReceipt(hash).isPresent()).isTrue()); | ||
} catch (final ConditionTimeoutException e) { | ||
LOG.error("Timed out waiting for a block containing the transaction receipt hash: " + hash); | ||
throw new RuntimeException("No receipt found for hash: " + hash); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.