Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eth_sendTransaction #835

Merged
merged 46 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
560a21c
add eth_signTransaction
gfukushima Jun 27, 2023
9193fb2
add bouncycastle to test in the core package
gfukushima Jun 27, 2023
a1fcf02
Add eth_sendTransaction
gfukushima Jun 28, 2023
f795d52
Change DefaultTestBase method name to setupWeb3Signer
gfukushima Jun 29, 2023
ddcb571
Change account used by eth_accounts and IT base
gfukushima Jun 29, 2023
439c9fb
Call setupWeb3Signer
gfukushima Jun 30, 2023
0e46208
Extend DefaultTestBase
gfukushima Jun 30, 2023
df52f8c
Integration tests fixes + spotless
gfukushima Jul 5, 2023
6e53e0a
Acceptance tests
gfukushima Jul 5, 2023
e83d585
Remove unused methods
gfukushima Jul 5, 2023
ac65c92
Some extra fixes
gfukushima Jul 6, 2023
bbe7b79
Merge branch 'master' into add_eth_sendTransaction
gfukushima Jul 6, 2023
4d07dcd
spotless
gfukushima Jul 6, 2023
e4d4643
Fix proxy integration tests
gfukushima Jul 6, 2023
cdb5625
Fix proxy integration tests
gfukushima Jul 6, 2023
35c2002
Fix proxy integration tests
gfukushima Jul 6, 2023
4f6dd05
Fix proxy integration tests
gfukushima Jul 6, 2023
0ebf80a
spotless
gfukushima Jul 6, 2023
42fe2f8
Merge remote-tracking branch '_gfukushima/add_eth_sendTransaction' in…
gfukushima Jul 6, 2023
8977e48
spotless
gfukushima Jul 6, 2023
cf81a1c
AT fix
gfukushima Jul 6, 2023
bfe1743
Add eea_sendTransaction
gfukushima Jul 7, 2023
70482fc
spotless
gfukushima Jul 7, 2023
405db63
Add adapter to handle eth1 address identifiers for the eth_sign/eth_s…
gfukushima Jul 11, 2023
36b99a0
delete duplicated test
gfukushima Jul 11, 2023
0b71935
Fix exception ignored on Runner
gfukushima Jul 11, 2023
891a613
Update core/src/main/java/tech/pegasys/web3signer/core/service/http/h…
gfukushima Jul 12, 2023
f87f053
Update core/src/main/java/tech/pegasys/web3signer/core/service/http/h…
gfukushima Jul 12, 2023
a1421f4
Update core/src/main/java/tech/pegasys/web3signer/core/Runner.java
gfukushima Jul 12, 2023
61eb8df
Address PR comments
gfukushima Jul 12, 2023
bbd8e93
Enable test
gfukushima Jul 12, 2023
a3c1d6f
Move implementation back to use list
gfukushima Jul 12, 2023
8abde11
Merge branch 'master' into add_eth_sendTransaction
gfukushima Jul 13, 2023
be185ee
Address comments part 2
gfukushima Jul 13, 2023
8e68e72
Moving packages and fix reference
gfukushima Jul 13, 2023
c7b8054
spotless
gfukushima Jul 13, 2023
7bd851b
Update signing/src/main/java/tech/pegasys/web3signer/signing/config/S…
gfukushima Jul 13, 2023
404039b
spotless
gfukushima Jul 13, 2023
a8e146c
Merge branch 'master' into add_eth_sendTransaction
gfukushima Jul 17, 2023
72c5ff4
Comments part 3
gfukushima Jul 18, 2023
1443e35
Comments part 4
gfukushima Jul 18, 2023
6052c7e
rename params
gfukushima Jul 18, 2023
c960767
use method reference
gfukushima Jul 18, 2023
68f4227
Merge branch 'master' into add_eth_sendTransaction
gfukushima Jul 18, 2023
44bb540
rename var
gfukushima Jul 18, 2023
a5aeaf8
add changelog
gfukushima Jul 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
*/
package tech.pegasys.web3signer.dsl;

import java.math.BigInteger;

public class Account {

private final String address;
private BigInteger nonce = BigInteger.ZERO;

public Account(final String address) {
this.address = address;
Expand All @@ -23,4 +26,16 @@ public Account(final String address) {
public String address() {
return address;
}

public BigInteger nextNonce() {
return nonce;
}

public BigInteger nextNonceAndIncrement() {

final BigInteger next = nonce;
nonce = nonce.add(BigInteger.ONE);

return next;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,26 @@

public class Accounts {

/** Private key: 8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63 */
private static final String GENESIS_ACCOUNT_ONE_PUBLIC_KEY =
"0xfe3b557e8fb62b89f4916b721be55ceb828dbd73";

public static final String GENESIS_ACCOUNT_ONE_PASSWORD = "pass";

private final Account benefactor;
private final Eth eth;

public Accounts(final Eth eth) {
this.eth = eth;
this.benefactor = new Account(GENESIS_ACCOUNT_ONE_PUBLIC_KEY);
}

public Account richBenefactor() {
return benefactor;
}

public BigInteger balance(final Account account) {
return balance(account.address());
}

public BigInteger balance(final String address) {
Expand Down
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();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@
*/
package tech.pegasys.web3signer.dsl;

import static org.assertj.core.api.Assertions.assertThat;

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.List;
import java.util.Optional;

import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.methods.request.Transaction;
import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.protocol.core.methods.response.TransactionReceipt;

public class Eth {

Expand All @@ -27,11 +36,49 @@ public Eth(final Web3j jsonRpc) {
this.jsonRpc = jsonRpc;
}

public String sendTransaction(final Transaction transaction) throws IOException {
final EthSendTransaction response = jsonRpc.ethSendTransaction(transaction).send();

assertThat(response.getTransactionHash()).isNotEmpty();
assertThat(response.getError()).isNull();

return response.getTransactionHash();
}

public SignerResponse<JsonRpcErrorResponse> sendTransactionExpectsError(
final Transaction transaction) throws IOException {
final EthSendTransaction response = jsonRpc.ethSendTransaction(transaction).send();
assertThat(response.hasError()).isTrue();
return SignerResponse.fromWeb3jErrorResponse(response);
}

public BigInteger getTransactionCount(final String address) throws IOException {
return jsonRpc
.ethGetTransactionCount(address, DefaultBlockParameterName.LATEST)
.send()
.getTransactionCount();
}

public Optional<TransactionReceipt> getTransactionReceipt(final String hash) throws IOException {
return jsonRpc.ethGetTransactionReceipt(hash).send().getTransactionReceipt();
}

public List<String> getAccounts() throws IOException {
return jsonRpc.ethAccounts().send().getAccounts();
}

public String getCode(final String address) throws IOException {
return jsonRpc.ethGetCode(address, DefaultBlockParameterName.LATEST).send().getResult();
}

public BigInteger getBalance(final String account) throws IOException {
return jsonRpc.ethGetBalance(account, DefaultBlockParameterName.LATEST).send().getBalance();
}

public String call(final Transaction contractViewOperation) throws IOException {
return jsonRpc
.ethCall(contractViewOperation, DefaultBlockParameterName.LATEST)
.send()
.getValue();
}
}
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));
}
}
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import tech.pegasys.web3signer.dsl.Accounts;
import tech.pegasys.web3signer.dsl.Eth;
import tech.pegasys.web3signer.dsl.PublicContracts;
import tech.pegasys.web3signer.dsl.Transactions;

import java.io.IOException;
import java.io.StringReader;
Expand Down Expand Up @@ -52,12 +54,16 @@ public class BesuNode {
private static final BigInteger SPURIOUS_DRAGON_HARD_FORK_BLOCK = BigInteger.valueOf(1);

private final BesuNodeConfig besuNodeConfig;

private final String[] args;

private final Map<String, String> environment;
private final Properties portsProperties = new Properties();
private Accounts accounts;
private Future<ProcessResult> besuProcess;
private Transactions transactions;
private Web3j jsonRpc;
private PublicContracts publicContracts;
private BesuNodePorts besuNodePorts;

BesuNode(final BesuNodeConfig besuNodeConfig, String[] args, Map<String, String> environment) {
Expand Down Expand Up @@ -130,6 +136,8 @@ public void awaitStartupCompletion() {
final Eth eth = new Eth(jsonRpc);

accounts = new Accounts(eth);
publicContracts = new PublicContracts(eth);
transactions = new Transactions(eth);
}

public BesuNodePorts ports() {
Expand Down Expand Up @@ -159,4 +167,12 @@ private void loadPortsFile() {
throw new RuntimeException("Error reading Besu ports file", e);
}
}

public PublicContracts publicContracts() {
return publicContracts;
}

public Transactions transactions() {
return transactions;
}
}
Loading