diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java index 02b30759ec4..e11349023c2 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.tests.acceptance.dsl.condition.login.LoginConditions; import org.hyperledger.besu.tests.acceptance.dsl.condition.net.NetConditions; import org.hyperledger.besu.tests.acceptance.dsl.condition.perm.PermissioningConditions; +import org.hyperledger.besu.tests.acceptance.dsl.condition.priv.PrivConditions; import org.hyperledger.besu.tests.acceptance.dsl.condition.web3.Web3Conditions; import org.hyperledger.besu.tests.acceptance.dsl.contract.ContractVerifier; import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.Cluster; @@ -37,6 +38,7 @@ import org.hyperledger.besu.tests.acceptance.dsl.transaction.miner.MinerTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.net.NetTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.perm.PermissioningTransactions; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivacyTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.web3.Web3Transactions; import org.junit.After; @@ -65,6 +67,8 @@ public class AcceptanceTestBase { protected final PermissioningTransactions permissioningTransactions; protected final MinerTransactions minerTransactions; protected final Web3Conditions web3; + protected final PrivConditions priv; + protected final PrivacyTransactions privacyTransactions; protected AcceptanceTestBase() { ethTransactions = new EthTransactions(); @@ -74,6 +78,7 @@ protected AcceptanceTestBase() { ibftTwoTransactions = new Ibft2Transactions(); accountTransactions = new AccountTransactions(accounts); permissioningTransactions = new PermissioningTransactions(); + privacyTransactions = new PrivacyTransactions(); contractTransactions = new ContractTransactions(); minerTransactions = new MinerTransactions(); @@ -85,6 +90,7 @@ protected AcceptanceTestBase() { net = new NetConditions(new NetTransactions()); cluster = new Cluster(net); perm = new PermissioningConditions(permissioningTransactions); + priv = new PrivConditions(privacyTransactions); admin = new AdminConditions(adminTransactions); web3 = new Web3Conditions(new Web3Transactions()); besu = new BesuNodeFactory(); diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/EeaSendRawTransactionSuccess.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/EeaSendRawTransactionSuccess.java new file mode 100644 index 00000000000..a80cbb0007b --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/EeaSendRawTransactionSuccess.java @@ -0,0 +1,38 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.condition.priv; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import org.hyperledger.besu.ethereum.core.Hash; +import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; +import org.hyperledger.besu.tests.acceptance.dsl.node.Node; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.EeaSendRawTransactionTransaction; + +public class EeaSendRawTransactionSuccess implements Condition { + + private final EeaSendRawTransactionTransaction sendRawTransactionTransaction; + + public EeaSendRawTransactionSuccess( + final EeaSendRawTransactionTransaction sendRawTransactionTransaction) { + this.sendRawTransactionTransaction = sendRawTransactionTransaction; + } + + @Override + public void verify(final Node node) { + final Hash transactionHash = node.execute(sendRawTransactionTransaction); + assertThat(transactionHash).isNotNull(); + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivConditions.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivConditions.java new file mode 100644 index 00000000000..a763eab6957 --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivConditions.java @@ -0,0 +1,93 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.condition.priv; + +import org.hyperledger.besu.ethereum.core.Address; +import org.hyperledger.besu.ethereum.core.Hash; +import org.hyperledger.besu.ethereum.privacy.PrivateTransaction; +import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivacyTransactions; + +import java.util.List; + +public class PrivConditions { + + private final PrivacyTransactions transactions; + + public PrivConditions(final PrivacyTransactions transactions) { + this.transactions = transactions; + } + + public Condition getPrivacyPrecompileAddress(final Address precompileAddress) { + return new PrivGetPrivacyPrecompileAddressSuccess( + transactions.getPrivacyPrecompileAddress(), precompileAddress); + } + + public Condition getPrivateTransaction( + final Hash transactionHash, final PrivateTransaction privateTransaction) { + return new PrivGetPrivateTransactionSuccess( + transactions.getPrivateTransaction(transactionHash), privateTransaction); + } + + public Condition createPrivacyGroup( + final List addresses, + final String groupName, + final String groupDescription, + final String groupId) { + return new PrivCreatePrivacyGroupSuccess( + transactions.createPrivacyGroup(addresses, groupName, groupDescription), groupId); + } + + public Condition deletePrivacyGroup(final String groupId) { + return new PrivDeletePrivacyGroupSuccess(transactions.deletePrivacyGroup(groupId), groupId); + } + + public Condition findPrivacyGroup(final int numGroups, final String... groupMembers) { + return new PrivFindPrivacyGroupSuccess(transactions.findPrivacyGroup(groupMembers), numGroups); + } + + public Condition eeaSendRawTransaction(final String transaction) { + return new EeaSendRawTransactionSuccess(transactions.sendRawTransaction(transaction)); + } + + public Condition distributeRawTransaction( + final String transactionRLP, final String enclaveResponseKey) { + return new PrivDistributeRawTransactionSuccess( + transactions.distributeRawTransaction(transactionRLP), enclaveResponseKey); + } + + public Condition getTransactionCount( + final String accountAddress, + final String privacyGroupId, + final int expectedTransactionCount) { + return new PrivGetTransactionCountSuccess( + transactions.getTransactionCount(accountAddress, privacyGroupId), expectedTransactionCount); + } + + public Condition getEeaTransactionCount( + final String accountAddress, + final String privateFrom, + final String[] privateFor, + final int expectedTransactionCount) { + return new PrivGetEeaTransactionCountSuccess( + transactions.getEeaTransactionCount(accountAddress, privateFrom, privateFor), + expectedTransactionCount); + } + + public Condition getTransactionReceipt(final Hash transactionHash) { + return new PrivGetTransactionReceiptSuccess( + transactions.getTransactionReceipt(transactionHash)); + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivCreatePrivacyGroupSuccess.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivCreatePrivacyGroupSuccess.java new file mode 100644 index 00000000000..c507ca4b50f --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivCreatePrivacyGroupSuccess.java @@ -0,0 +1,39 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.condition.priv; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; +import org.hyperledger.besu.tests.acceptance.dsl.node.Node; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivCreatePrivacyGroupTransaction; + +public class PrivCreatePrivacyGroupSuccess implements Condition { + + private final PrivCreatePrivacyGroupTransaction transaction; + private final String groupId; + + public PrivCreatePrivacyGroupSuccess( + final PrivCreatePrivacyGroupTransaction transaction, final String groupId) { + this.transaction = transaction; + this.groupId = groupId; + } + + @Override + public void verify(final Node node) { + final String result = node.execute(transaction); + assertThat(result).isEqualTo(groupId); + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivDeletePrivacyGroupSuccess.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivDeletePrivacyGroupSuccess.java new file mode 100644 index 00000000000..b2cd4a40ce5 --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivDeletePrivacyGroupSuccess.java @@ -0,0 +1,39 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.condition.priv; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; +import org.hyperledger.besu.tests.acceptance.dsl.node.Node; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivDeletePrivacyGroupTransaction; + +public class PrivDeletePrivacyGroupSuccess implements Condition { + + private final PrivDeletePrivacyGroupTransaction transaction; + private final String groupId; + + public PrivDeletePrivacyGroupSuccess( + final PrivDeletePrivacyGroupTransaction transaction, final String groupId) { + this.transaction = transaction; + this.groupId = groupId; + } + + @Override + public void verify(final Node node) { + final String result = node.execute(transaction); + assertThat(result).isEqualTo(groupId); + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivDistributeRawTransactionSuccess.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivDistributeRawTransactionSuccess.java new file mode 100644 index 00000000000..4184102cf5a --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivDistributeRawTransactionSuccess.java @@ -0,0 +1,42 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.condition.priv; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; +import org.hyperledger.besu.tests.acceptance.dsl.node.Node; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivDistributeRawTransactionTransaction; + +public class PrivDistributeRawTransactionSuccess implements Condition { + + private final PrivDistributeRawTransactionTransaction sendRawTransactionTransaction; + private final String enclaveResponseKey; + + public PrivDistributeRawTransactionSuccess( + final PrivDistributeRawTransactionTransaction sendRawTransactionTransaction, + final String enclaveResponseKey) { + this.sendRawTransactionTransaction = sendRawTransactionTransaction; + this.enclaveResponseKey = enclaveResponseKey; + } + + @Override + public void verify(final Node node) { + final String result = node.execute(sendRawTransactionTransaction); + assertThat(result).isNotNull(); + assertThat(result).isInstanceOf(String.class); + assertThat(result).isEqualTo(enclaveResponseKey); + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivFindPrivacyGroupSuccess.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivFindPrivacyGroupSuccess.java new file mode 100644 index 00000000000..f4a069a243f --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivFindPrivacyGroupSuccess.java @@ -0,0 +1,40 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.condition.priv; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import org.hyperledger.besu.enclave.types.PrivacyGroup; +import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; +import org.hyperledger.besu.tests.acceptance.dsl.node.Node; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivFindPrivacyGroupTransaction; + +public class PrivFindPrivacyGroupSuccess implements Condition { + + private final PrivFindPrivacyGroupTransaction transaction; + private final int numGroups; + + public PrivFindPrivacyGroupSuccess( + final PrivFindPrivacyGroupTransaction transaction, final int numGroups) { + this.transaction = transaction; + this.numGroups = numGroups; + } + + @Override + public void verify(final Node node) { + final PrivacyGroup[] privacyGroups = node.execute(transaction); + assertThat(privacyGroups).hasSize(numGroups); + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetEeaTransactionCountSuccess.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetEeaTransactionCountSuccess.java new file mode 100644 index 00000000000..def5502d98c --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetEeaTransactionCountSuccess.java @@ -0,0 +1,42 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.condition.priv; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; +import org.hyperledger.besu.tests.acceptance.dsl.node.Node; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetEeaTransactionCountTransaction; + +public class PrivGetEeaTransactionCountSuccess implements Condition { + + private final PrivGetEeaTransactionCountTransaction privGetEeaTransactionCountTransaction; + private final int expectedTransactionCount; + + public PrivGetEeaTransactionCountSuccess( + final PrivGetEeaTransactionCountTransaction privGetEeaTransactionCountTransaction, + final int expectedTransactionCount) { + this.privGetEeaTransactionCountTransaction = privGetEeaTransactionCountTransaction; + this.expectedTransactionCount = expectedTransactionCount; + } + + @Override + public void verify(final Node node) { + final int result = node.execute(privGetEeaTransactionCountTransaction); + assertThat(result).isNotNull(); + assertThat(result).isInstanceOf(Integer.class); + assertThat(result).isEqualTo(expectedTransactionCount); + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetPrivacyPrecompileAddressSuccess.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetPrivacyPrecompileAddressSuccess.java new file mode 100644 index 00000000000..8b904965810 --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetPrivacyPrecompileAddressSuccess.java @@ -0,0 +1,42 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.condition.priv; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import org.hyperledger.besu.ethereum.core.Address; +import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; +import org.hyperledger.besu.tests.acceptance.dsl.node.Node; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetPrivacyPrecompileAddressTransaction; + +public class PrivGetPrivacyPrecompileAddressSuccess implements Condition { + + private final PrivGetPrivacyPrecompileAddressTransaction transaction; + private final Address precompileAddress; + + public PrivGetPrivacyPrecompileAddressSuccess( + final PrivGetPrivacyPrecompileAddressTransaction transaction, + final Address precompileAddress) { + this.transaction = transaction; + this.precompileAddress = precompileAddress; + } + + @Override + public void verify(final Node node) { + final Address result = node.execute(transaction); + assertThat(result).isInstanceOf(Address.class); + assertThat(result).isEqualTo(precompileAddress); + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetPrivateTransactionSuccess.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetPrivateTransactionSuccess.java new file mode 100644 index 00000000000..33383a054cf --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetPrivateTransactionSuccess.java @@ -0,0 +1,43 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.condition.priv; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionGroupResult; +import org.hyperledger.besu.ethereum.privacy.PrivateTransaction; +import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; +import org.hyperledger.besu.tests.acceptance.dsl.node.Node; +import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivateTransactionGroupResponse; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetPrivateTransactionTransaction; + +public class PrivGetPrivateTransactionSuccess implements Condition { + + private final PrivGetPrivateTransactionTransaction transaction; + private final PrivateTransactionGroupResult privateTransaction; + + public PrivGetPrivateTransactionSuccess( + final PrivGetPrivateTransactionTransaction transaction, + final PrivateTransaction privateTransaction) { + this.transaction = transaction; + this.privateTransaction = new PrivateTransactionGroupResult(privateTransaction); + } + + @Override + public void verify(final Node node) { + final PrivateTransactionGroupResponse result = node.execute(transaction); + assertThat(result).isEqualToComparingFieldByField(privateTransaction); + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetTransactionCountSuccess.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetTransactionCountSuccess.java new file mode 100644 index 00000000000..823548effaf --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetTransactionCountSuccess.java @@ -0,0 +1,42 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.condition.priv; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; +import org.hyperledger.besu.tests.acceptance.dsl.node.Node; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetTransactionCountTransaction; + +public class PrivGetTransactionCountSuccess implements Condition { + + private final PrivGetTransactionCountTransaction privGetTransactionCountTransaction; + private final int expectedTransactionCount; + + public PrivGetTransactionCountSuccess( + final PrivGetTransactionCountTransaction privGetTransactionCountTransaction, + final int expectedTransactionCount) { + this.privGetTransactionCountTransaction = privGetTransactionCountTransaction; + this.expectedTransactionCount = expectedTransactionCount; + } + + @Override + public void verify(final Node node) { + final Integer result = node.execute(privGetTransactionCountTransaction); + assertThat(result).isNotNull(); + assertThat(result).isInstanceOf(Integer.class); + assertThat(result).isEqualTo(expectedTransactionCount); + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetTransactionReceiptSuccess.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetTransactionReceiptSuccess.java new file mode 100644 index 00000000000..aee12a8ab98 --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/PrivGetTransactionReceiptSuccess.java @@ -0,0 +1,38 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.condition.priv; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; +import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; +import org.hyperledger.besu.tests.acceptance.dsl.node.Node; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetTransactionReceiptTransaction; + +public class PrivGetTransactionReceiptSuccess implements Condition { + + private final PrivGetTransactionReceiptTransaction getTransactionReceiptTransaction; + + public PrivGetTransactionReceiptSuccess( + final PrivGetTransactionReceiptTransaction getTransactionReceiptTransaction) { + this.getTransactionReceiptTransaction = getTransactionReceiptTransaction; + } + + @Override + public void verify(final Node node) { + WaitUtils.waitFor(() -> assertThat(node.execute(getTransactionReceiptTransaction)).isNotNull()); + assertThat(node.execute(getTransactionReceiptTransaction).getStatus()).isEqualTo("0x1"); + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java index 2840ba28620..a55e6df9924 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java @@ -123,7 +123,8 @@ public BesuNode( final boolean revertReasonEnabled, final List plugins, final List extraCLIOptions, - final List staticNodes) + final List staticNodes, + final Optional privacyParameters) throws IOException { this.bootnodeEligible = bootnodeEligible; this.revertReasonEnabled = revertReasonEnabled; @@ -161,6 +162,7 @@ public BesuNode( }); this.extraCLIOptions = extraCLIOptions; this.staticNodes = staticNodes; + privacyParameters.ifPresent(this::setPrivacyParameters); LOG.info("Created BesuNode {}", this.toString()); } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java index e46a97c9aa3..ae27c30e130 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java @@ -91,6 +91,9 @@ public void startNode(final BesuNode node) { params.add(Integer.toString(node.getMiningParameters().getStratumPort())); params.add("--miner-stratum-host"); params.add(node.getMiningParameters().getStratumNetworkInterface()); + params.add("--min-gas-price"); + params.add( + Integer.toString(node.getMiningParameters().getMinTransactionGasPrice().intValue())); } if (node.getMiningParameters().isStratumMiningEnabled()) { params.add("--miner-stratum-enabled"); @@ -100,8 +103,12 @@ public void startNode(final BesuNode node) { params.add("--privacy-enabled"); params.add("--privacy-url"); params.add(node.getPrivacyParameters().getEnclaveUri().toString()); - params.add("--privacy-public-key-file"); - params.add(node.getPrivacyParameters().getEnclavePublicKeyFile().getAbsolutePath()); + if (node.getPrivacyParameters().isMultiTenancyEnabled()) { + params.add("--privacy-multi-tenancy-enabled"); + } else { + params.add("--privacy-public-key-file"); + params.add(node.getPrivacyParameters().getEnclavePublicKeyFile().getAbsolutePath()); + } params.add("--privacy-precompiled-address"); params.add(String.valueOf(node.getPrivacyParameters().getPrivacyAddress())); params.add("--privacy-marker-transaction-signing-key-file"); diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java index 3b7e208e1ef..a2c78ca3b21 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java @@ -17,6 +17,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; @@ -44,6 +45,7 @@ public class BesuNodeConfiguration { private final List plugins; private final List extraCLIOptions; private final List staticNodes; + private final Optional privacyParameters; public BesuNodeConfiguration( final String name, @@ -62,7 +64,8 @@ public BesuNodeConfiguration( final boolean revertReasonEnabled, final List plugins, final List extraCLIOptions, - final List staticNodes) { + final List staticNodes, + final Optional privacyParameters) { this.name = name; this.miningParameters = miningParameters; this.jsonRpcConfiguration = jsonRpcConfiguration; @@ -80,6 +83,7 @@ public BesuNodeConfiguration( this.plugins = plugins; this.extraCLIOptions = extraCLIOptions; this.staticNodes = staticNodes; + this.privacyParameters = privacyParameters; } public String getName() { @@ -149,4 +153,8 @@ public boolean isRevertReasonEnabled() { public List getStaticNodes() { return staticNodes; } + + public Optional getPrivacyParameters() { + return privacyParameters; + } } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java index 3608b434762..a5867bd793a 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.MiningParametersTestBuilder; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; @@ -54,6 +55,7 @@ public class BesuNodeConfigurationBuilder { private final List plugins = new ArrayList<>(); private final List extraCLIOptions = new ArrayList<>(); private List staticNodes = new ArrayList<>(); + private Optional privacyParameters = Optional.empty(); public BesuNodeConfigurationBuilder() { // Check connections more frequently during acceptance tests to cut down on @@ -72,6 +74,12 @@ public BesuNodeConfigurationBuilder miningEnabled() { return this; } + public BesuNodeConfigurationBuilder miningConfiguration(final MiningParameters miningParameters) { + this.miningParameters = miningParameters; + this.jsonRpcConfiguration.addRpcApi(RpcApis.MINER); + return this; + } + public BesuNodeConfigurationBuilder jsonRpcConfiguration( final JsonRpcConfiguration jsonRpcConfiguration) { this.jsonRpcConfiguration = jsonRpcConfiguration; @@ -103,11 +111,10 @@ public BesuNodeConfigurationBuilder enablePrivateTransactions() { return this; } - public BesuNodeConfigurationBuilder jsonRpcAuthenticationEnabled() throws URISyntaxException { + public BesuNodeConfigurationBuilder jsonRpcAuthenticationConfiguration(final String authFile) + throws URISyntaxException { final String authTomlPath = - Paths.get(ClassLoader.getSystemResource("authentication/auth.toml").toURI()) - .toAbsolutePath() - .toString(); + Paths.get(ClassLoader.getSystemResource(authFile).toURI()).toAbsolutePath().toString(); this.jsonRpcConfiguration.setAuthenticationEnabled(true); this.jsonRpcConfiguration.setAuthenticationCredentialsFile(authTomlPath); @@ -234,6 +241,11 @@ public BesuNodeConfigurationBuilder staticNodes(final List staticNodes) return this; } + public BesuNodeConfigurationBuilder privacyParameters(final PrivacyParameters privacyParameters) { + this.privacyParameters = Optional.ofNullable(privacyParameters); + return this; + } + public BesuNodeConfiguration build() { return new BesuNodeConfiguration( name, @@ -252,6 +264,7 @@ public BesuNodeConfiguration build() { revertReasonEnabled, plugins, extraCLIOptions, - staticNodes); + staticNodes, + privacyParameters); } } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java index 1707e047a35..820a25aad02 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java @@ -17,9 +17,15 @@ import static java.util.Arrays.asList; import static java.util.stream.Collectors.toList; +import org.hyperledger.besu.enclave.EnclaveFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; +import org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider; +import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningParametersTestBuilder; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; +import org.hyperledger.besu.ethereum.core.Wei; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import org.hyperledger.besu.tests.acceptance.dsl.node.Node; import org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode; @@ -28,9 +34,12 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.nio.file.Paths; import java.util.List; import java.util.Optional; +import io.vertx.core.Vertx; + public class BesuNodeFactory { private final GenesisConfigurationFactory genesis = new GenesisConfigurationFactory(); @@ -54,7 +63,8 @@ public BesuNode create(final BesuNodeConfiguration config) throws IOException { config.isRevertReasonEnabled(), config.getPlugins(), config.getExtraCLIOptions(), - config.getStaticNodes()); + config.getStaticNodes(), + config.getPrivacyParameters()); } public BesuNode createMinerNode(final String name) throws IOException { @@ -128,13 +138,13 @@ public BesuNode createArchiveNodeNetServicesDisabled(final String name) throws I .build()); } - public BesuNode createNodeWithAuthentication(final String name) + public BesuNode createNodeWithAuthentication(final String name, final String authFile) throws IOException, URISyntaxException { return create( new BesuNodeConfigurationBuilder() .name(name) .jsonRpcEnabled() - .jsonRpcAuthenticationEnabled() + .jsonRpcAuthenticationConfiguration(authFile) .webSocketEnabled() .webSocketAuthenticationEnabled() .build()); @@ -161,6 +171,38 @@ public BesuNode createNodeWithP2pDisabled(final String name) throws IOException .build()); } + public BesuNode createNodeWithMultiTenantedPrivacy( + final String name, + final String enclaveUrl, + final String authFile, + final String privTransactionSigningKey) + throws IOException, URISyntaxException { + final PrivacyParameters.Builder privacyParametersBuilder = new PrivacyParameters.Builder(); + final PrivacyParameters privacyParameters = + privacyParametersBuilder + .setMultiTenancyEnabled(true) + .setEnabled(true) + .setStorageProvider(new InMemoryPrivacyStorageProvider()) + .setEnclaveFactory(new EnclaveFactory(Vertx.vertx())) + .setEnclaveUrl(URI.create(enclaveUrl)) + .setPrivateKeyPath( + Paths.get(ClassLoader.getSystemResource(privTransactionSigningKey).toURI())) + .build(); + + final MiningParameters miningParameters = + new MiningParametersTestBuilder().minTransactionGasPrice(Wei.ZERO).enabled(true).build(); + + return create( + new BesuNodeConfigurationBuilder() + .name(name) + .jsonRpcEnabled() + .jsonRpcAuthenticationConfiguration(authFile) + .enablePrivateTransactions() + .privacyParameters(privacyParameters) + .miningConfiguration(miningParameters) + .build()); + } + public BesuNode createArchiveNodeWithRpcDisabled(final String name) throws IOException { return create(new BesuNodeConfigurationBuilder().name(name).build()); } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java index ddd8746607e..3459562b1be 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java @@ -48,8 +48,8 @@ import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -96,7 +96,8 @@ public PrivacyNode(final PrivacyNodeConfiguration privacyConfiguration, final Ve besuConfig.isRevertReasonEnabled(), besuConfig.getPlugins(), besuConfig.getExtraCLIOptions(), - new ArrayList<>()); + Collections.emptyList(), + besuConfig.getPrivacyParameters()); } public void testOrionConnection(final List otherNodes) { diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivateTransactionGroupResponse.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivateTransactionGroupResponse.java new file mode 100644 index 00000000000..f3a139b0ec4 --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivateTransactionGroupResponse.java @@ -0,0 +1,123 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.privacy; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class PrivateTransactionGroupResponse { + private final String from; + private final String gas; + private final String gasPrice; + private final String hash; + private final String input; + private final String nonce; + private final String to; + private final String value; + private final String v; + private final String r; + private final String s; + private final String privateFrom; + private final String restriction; + private final String privacyGroupId; + + @JsonCreator + public PrivateTransactionGroupResponse( + @JsonProperty("from") final String from, + @JsonProperty("gas") final String gas, + @JsonProperty("gasPrice") final String gasPrice, + @JsonProperty("hash") final String hash, + @JsonProperty("input") final String input, + @JsonProperty("nonce") final String nonce, + @JsonProperty("to") final String to, + @JsonProperty("value") final String value, + @JsonProperty("v") final String v, + @JsonProperty("r") final String r, + @JsonProperty("s") final String s, + @JsonProperty("privateFrom") final String privateFrom, + @JsonProperty("restriction") final String restriction, + @JsonProperty("privacyGroupId") final String privacyGroupId) { + this.from = from; + this.gas = gas; + this.gasPrice = gasPrice; + this.hash = hash; + this.input = input; + this.nonce = nonce; + this.to = to; + this.value = value; + this.v = v; + this.r = r; + this.s = s; + this.privateFrom = privateFrom; + this.restriction = restriction; + this.privacyGroupId = privacyGroupId; + } + + public String getFrom() { + return from; + } + + public String getGas() { + return gas; + } + + public String getGasPrice() { + return gasPrice; + } + + public String getHash() { + return hash; + } + + public String getInput() { + return input; + } + + public String getNonce() { + return nonce; + } + + public String getTo() { + return to; + } + + public String getValue() { + return value; + } + + public String getV() { + return v; + } + + public String getR() { + return r; + } + + public String getS() { + return s; + } + + public String getPrivateFrom() { + return privateFrom; + } + + public String getRestriction() { + return restriction; + } + + public String getPrivacyGroupId() { + return privacyGroupId; + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/EeaSendRawTransactionTransaction.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/EeaSendRawTransactionTransaction.java new file mode 100644 index 00000000000..e5e1ef9a2f2 --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/EeaSendRawTransactionTransaction.java @@ -0,0 +1,44 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.ethereum.core.Hash; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; + +public class EeaSendRawTransactionTransaction implements Transaction { + + final String transaction; + + public EeaSendRawTransactionTransaction(final String transaction) { + this.transaction = transaction; + } + + @Override + public Hash execute(final NodeRequests node) { + try { + final PrivacyRequestFactory.SendRawTransactionResponse result = + node.privacy().eeaSendRawTransaction(transaction).send(); + assertThat(result).isNotNull(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivCreatePrivacyGroupTransaction.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivCreatePrivacyGroupTransaction.java new file mode 100644 index 00000000000..eaddb84fc52 --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivCreatePrivacyGroupTransaction.java @@ -0,0 +1,46 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; +import java.util.List; + +public class PrivCreatePrivacyGroupTransaction implements Transaction { + + final CreatePrivacyGroupParameter params; + + public PrivCreatePrivacyGroupTransaction( + final List addresses, final String groupName, final String groupDescription) { + this.params = new CreatePrivacyGroupParameter(addresses, groupName, groupDescription); + } + + @Override + public String execute(final NodeRequests node) { + try { + final PrivacyRequestFactory.CreatePrivacyGroupResponse result = + node.privacy().privCreatePrivacyGroup(params).send(); + assertThat(result).isNotNull(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivDeletePrivacyGroupTransaction.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivDeletePrivacyGroupTransaction.java new file mode 100644 index 00000000000..19adda1472f --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivDeletePrivacyGroupTransaction.java @@ -0,0 +1,43 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; + +public class PrivDeletePrivacyGroupTransaction implements Transaction { + + final String transactionHash; + + public PrivDeletePrivacyGroupTransaction(final String transactionHash) { + this.transactionHash = transactionHash; + } + + @Override + public String execute(final NodeRequests node) { + try { + final PrivacyRequestFactory.DeletePrivacyGroupResponse result = + node.privacy().privDeletePrivacyGroup(transactionHash).send(); + assertThat(result).isNotNull(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivDistributeRawTransactionTransaction.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivDistributeRawTransactionTransaction.java new file mode 100644 index 00000000000..f5245951b9f --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivDistributeRawTransactionTransaction.java @@ -0,0 +1,43 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; + +public class PrivDistributeRawTransactionTransaction implements Transaction { + + final String transaction; + + public PrivDistributeRawTransactionTransaction(final String transaction) { + this.transaction = transaction; + } + + @Override + public String execute(final NodeRequests node) { + try { + final PrivacyRequestFactory.PrivDistributeTransactionResponse result = + node.privacy().privDistributeTransaction(transaction).send(); + assertThat(result).isNotNull(); + return result.getTransactionKey(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivFindPrivacyGroupTransaction.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivFindPrivacyGroupTransaction.java new file mode 100644 index 00000000000..5ee5b5e1fb4 --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivFindPrivacyGroupTransaction.java @@ -0,0 +1,44 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.enclave.types.PrivacyGroup; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; + +public class PrivFindPrivacyGroupTransaction implements Transaction { + + final String[] groupMembers; + + public PrivFindPrivacyGroupTransaction(final String[] groupMembers) { + this.groupMembers = groupMembers; + } + + @Override + public PrivacyGroup[] execute(final NodeRequests node) { + try { + final PrivacyRequestFactory.FindPrivacyGroupResponse result = + node.privacy().privFindPrivacyGroup(groupMembers).send(); + assertThat(result).isNotNull(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetEeaTransactionCountTransaction.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetEeaTransactionCountTransaction.java new file mode 100644 index 00000000000..ba0bd3ba737 --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetEeaTransactionCountTransaction.java @@ -0,0 +1,44 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; + +public class PrivGetEeaTransactionCountTransaction implements Transaction { + + private final Object[] params; + + public PrivGetEeaTransactionCountTransaction( + final String accountAddress, final String privateFrom, final String[] privateFor) { + this.params = new Object[] {accountAddress, privateFrom, privateFor}; + } + + @Override + public Integer execute(final NodeRequests node) { + try { + final PrivacyRequestFactory.GetTransactionCountResponse result = + node.privacy().privGetEeaTransactionCount(params).send(); + assertThat(result).isNotNull(); + return result.getCount(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetPrivacyPrecompileAddressTransaction.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetPrivacyPrecompileAddressTransaction.java new file mode 100644 index 00000000000..abbba72a7c6 --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetPrivacyPrecompileAddressTransaction.java @@ -0,0 +1,38 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.ethereum.core.Address; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; + +public class PrivGetPrivacyPrecompileAddressTransaction implements Transaction
{ + + @Override + public Address execute(final NodeRequests node) { + try { + final PrivacyRequestFactory.GetPrivacyPrecompileAddressResponse result = + node.privacy().privGetPrivacyPrecompileAddress().send(); + assertThat(result).isNotNull(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetPrivateTransactionTransaction.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetPrivateTransactionTransaction.java new file mode 100644 index 00000000000..5c12b6c13eb --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetPrivateTransactionTransaction.java @@ -0,0 +1,46 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.ethereum.core.Hash; +import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivateTransactionGroupResponse; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; + +public class PrivGetPrivateTransactionTransaction + implements Transaction { + + private final Hash transactionHash; + + public PrivGetPrivateTransactionTransaction(final Hash transactionHash) { + this.transactionHash = transactionHash; + } + + @Override + public PrivateTransactionGroupResponse execute(final NodeRequests node) { + try { + final PrivacyRequestFactory.GetPrivateTransactionResponse result = + node.privacy().privGetPrivateTransaction(transactionHash).send(); + assertThat(result).isNotNull(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetTransactionCountTransaction.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetTransactionCountTransaction.java new file mode 100644 index 00000000000..aee4cab49c2 --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetTransactionCountTransaction.java @@ -0,0 +1,44 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; + +public class PrivGetTransactionCountTransaction implements Transaction { + + private final Object[] params; + + public PrivGetTransactionCountTransaction( + final String accountAddress, final String privacyGroupId) { + this.params = new String[] {accountAddress, privacyGroupId}; + } + + @Override + public Integer execute(final NodeRequests node) { + try { + final PrivacyRequestFactory.GetTransactionCountResponse result = + node.privacy().privGetTransactionCount(params).send(); + assertThat(result).isNotNull(); + return result.getCount(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetTransactionReceiptTransaction.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetTransactionReceiptTransaction.java new file mode 100644 index 00000000000..2ea67b7982f --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivGetTransactionReceiptTransaction.java @@ -0,0 +1,47 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.ethereum.core.Hash; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; + +import java.io.IOException; + +import org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt; + +public class PrivGetTransactionReceiptTransaction + implements Transaction { + + private final Hash transaction; + + public PrivGetTransactionReceiptTransaction(final Hash transaction) { + this.transaction = transaction; + } + + @Override + public PrivateTransactionReceipt execute(final NodeRequests node) { + try { + final PrivacyRequestFactory.GetTransactionReceiptResponse result = + node.privacy().privGetTransactionReceipt(transaction).send(); + assertThat(result).isNotNull(); + return result.getResult(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivacyRequestFactory.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivacyRequestFactory.java index 2f71369f9e5..314e921bf56 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivacyRequestFactory.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivacyRequestFactory.java @@ -16,22 +16,51 @@ import static java.util.Collections.singletonList; +import org.hyperledger.besu.enclave.types.PrivacyGroup; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter; +import org.hyperledger.besu.ethereum.core.Address; +import org.hyperledger.besu.ethereum.core.Hash; +import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivateTransactionGroupResponse; + +import java.util.Collections; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import org.web3j.protocol.Web3jService; import org.web3j.protocol.besu.Besu; +import org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt; import org.web3j.protocol.core.Request; import org.web3j.protocol.core.Response; public class PrivacyRequestFactory { - private final Besu besuClient; - private final Web3jService web3jService; - public PrivacyRequestFactory(final Web3jService web3jService) { - this.web3jService = web3jService; - this.besuClient = Besu.build(web3jService); - } + public static class GetPrivacyPrecompileAddressResponse extends Response
{} - public Besu getBesuClient() { - return besuClient; + public static class GetPrivateTransactionResponse + extends Response {} + + public static class CreatePrivacyGroupResponse extends Response {} + + public static class DeletePrivacyGroupResponse extends Response {} + + public static class FindPrivacyGroupResponse extends Response {} + + public static class SendRawTransactionResponse extends Response {} + + public static class GetTransactionReceiptResponse extends Response {} + + public static class GetTransactionCountResponse extends Response { + final Integer count; + + @JsonCreator + public GetTransactionCountResponse(@JsonProperty("result") final String result) { + this.count = Integer.decode(result); + } + + public Integer getCount() { + return count; + } } public Request privDistributeTransaction( @@ -43,6 +72,18 @@ public Request privDistributeTransaction( PrivDistributeTransactionResponse.class); } + private final Besu besuClient; + private final Web3jService web3jService; + + public PrivacyRequestFactory(final Web3jService web3jService) { + this.web3jService = web3jService; + this.besuClient = Besu.build(web3jService); + } + + public Besu getBesuClient() { + return besuClient; + } + public static class PrivDistributeTransactionResponse extends Response { public PrivDistributeTransactionResponse() {} @@ -51,4 +92,79 @@ public String getTransactionKey() { return getResult(); } } + + public Request privGetPrivacyPrecompileAddress() { + return new Request<>( + "priv_getPrivacyPrecompileAddress", + Collections.emptyList(), + web3jService, + GetPrivacyPrecompileAddressResponse.class); + } + + public Request privGetPrivateTransaction( + final Hash transactionHash) { + return new Request<>( + "priv_getPrivateTransaction", + singletonList(transactionHash.toHexString()), + web3jService, + GetPrivateTransactionResponse.class); + } + + public Request privCreatePrivacyGroup( + final CreatePrivacyGroupParameter params) { + return new Request<>( + "priv_createPrivacyGroup", + singletonList(params), + web3jService, + CreatePrivacyGroupResponse.class); + } + + public Request privDeletePrivacyGroup(final String groupId) { + return new Request<>( + "priv_deletePrivacyGroup", + singletonList(groupId), + web3jService, + DeletePrivacyGroupResponse.class); + } + + public Request privFindPrivacyGroup(final String[] groupMembers) { + return new Request<>( + "priv_findPrivacyGroup", + singletonList(groupMembers), + web3jService, + FindPrivacyGroupResponse.class); + } + + public Request eeaSendRawTransaction(final String transaction) { + return new Request<>( + "eea_sendRawTransaction", + singletonList(transaction), + web3jService, + SendRawTransactionResponse.class); + } + + public Request privGetTransactionReceipt( + final Hash transactionHash) { + return new Request<>( + "priv_getTransactionReceipt", + singletonList(transactionHash.toHexString()), + web3jService, + GetTransactionReceiptResponse.class); + } + + public Request privGetTransactionCount(final Object[] params) { + return new Request<>( + "priv_getTransactionCount", + List.of(params), + web3jService, + GetTransactionCountResponse.class); + } + + public Request privGetEeaTransactionCount(final Object[] params) { + return new Request<>( + "priv_getEeaTransactionCount", + List.of(params), + web3jService, + GetTransactionCountResponse.class); + } } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivacyTransactions.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivacyTransactions.java new file mode 100644 index 00000000000..218368a3b7a --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivacyTransactions.java @@ -0,0 +1,65 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy; + +import org.hyperledger.besu.ethereum.core.Hash; + +import java.util.List; + +public class PrivacyTransactions { + public PrivGetPrivacyPrecompileAddressTransaction getPrivacyPrecompileAddress() { + return new PrivGetPrivacyPrecompileAddressTransaction(); + } + + public PrivGetPrivateTransactionTransaction getPrivateTransaction(final Hash transactionHash) { + return new PrivGetPrivateTransactionTransaction(transactionHash); + } + + public PrivCreatePrivacyGroupTransaction createPrivacyGroup( + final List addresses, final String groupName, final String groupDescription) { + return new PrivCreatePrivacyGroupTransaction(addresses, groupName, groupDescription); + } + + public PrivDeletePrivacyGroupTransaction deletePrivacyGroup(final String transactionHash) { + return new PrivDeletePrivacyGroupTransaction(transactionHash); + } + + public PrivFindPrivacyGroupTransaction findPrivacyGroup(final String[] groupMembers) { + return new PrivFindPrivacyGroupTransaction(groupMembers); + } + + public EeaSendRawTransactionTransaction sendRawTransaction(final String transaction) { + return new EeaSendRawTransactionTransaction(transaction); + } + + public PrivDistributeRawTransactionTransaction distributeRawTransaction( + final String transaction) { + return new PrivDistributeRawTransactionTransaction(transaction); + } + + public PrivGetTransactionCountTransaction getTransactionCount( + final String accountAddress, final String privacyGroupId) { + return new PrivGetTransactionCountTransaction(accountAddress, privacyGroupId); + } + + public PrivGetEeaTransactionCountTransaction getEeaTransactionCount( + final String accountAddress, final String privateFrom, final String[] privateFor) { + return new PrivGetEeaTransactionCountTransaction(accountAddress, privateFrom, privateFor); + } + + public PrivGetTransactionReceiptTransaction getTransactionReceipt(final Hash transactionHash) { + return new PrivGetTransactionReceiptTransaction(transactionHash); + } +} diff --git a/acceptance-tests/tests/build.gradle b/acceptance-tests/tests/build.gradle index 1e936e148c1..76aa1646340 100644 --- a/acceptance-tests/tests/build.gradle +++ b/acceptance-tests/tests/build.gradle @@ -15,9 +15,11 @@ dependencies { testImplementation project(':acceptance-tests:dsl') testImplementation project(':besu') testImplementation project(':consensus:clique') + implementation project(':crypto') testImplementation project(':enclave') testImplementation project(':ethereum:api') testImplementation project(':ethereum:core') + testImplementation project(':ethereum:rlp') testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts') testImplementation project(':ethereum:permissioning') testImplementation project(':plugin-api') @@ -33,6 +35,8 @@ dependencies { testImplementation 'org.web3j:besu' testImplementation 'tech.pegasys.ethsigner.internal:core' testImplementation 'tech.pegasys.ethsigner.internal:file-based' + + testCompile "com.github.tomakehurst:wiremock-jre8-standalone:2.25.1" } test.enabled = false diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/HttpServiceLoginAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/HttpServiceLoginAcceptanceTest.java index 5ff7dd6d3ac..605d4d2cf12 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/HttpServiceLoginAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/HttpServiceLoginAcceptanceTest.java @@ -30,6 +30,7 @@ public class HttpServiceLoginAcceptanceTest extends AcceptanceTestBase { private Cluster authenticatedCluster; private BesuNode nodeUsingAuthFile; private BesuNode nodeUsingJwtPublicKey; + private static final String AUTH_FILE = "authentication/auth.toml"; // token with payload{"iat": 1516239022,"exp": 4729363200,"permissions": ["net:peerCount"]} private static final String TOKEN_ALLOWING_NET_PEER_COUNT = @@ -42,11 +43,12 @@ public class HttpServiceLoginAcceptanceTest extends AcceptanceTestBase { @Before public void setUp() throws IOException, URISyntaxException { + final ClusterConfiguration clusterConfiguration = new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build(); authenticatedCluster = new Cluster(clusterConfiguration, net); - nodeUsingAuthFile = besu.createNodeWithAuthentication("node1"); + nodeUsingAuthFile = besu.createNodeWithAuthentication("node1", AUTH_FILE); nodeUsingJwtPublicKey = besu.createNodeWithAuthenticationUsingJwtPublicKey("node2"); authenticatedCluster.start(nodeUsingAuthFile, nodeUsingJwtPublicKey); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/WebsocketServiceLoginAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/WebsocketServiceLoginAcceptanceTest.java index e81cdad8647..588a27390bc 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/WebsocketServiceLoginAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/WebsocketServiceLoginAcceptanceTest.java @@ -30,6 +30,7 @@ public class WebsocketServiceLoginAcceptanceTest extends AcceptanceTestBase { private BesuNode nodeUsingAuthFile; private BesuNode nodeUsingJwtPublicKey; private Cluster authenticatedCluster; + private static final String AUTH_FILE = "authentication/auth.toml"; // token with payload{"iat": 1516239022,"exp": 4729363200,"permissions": ["net:peerCount"]} private static final String TOKEN_ALLOWING_NET_PEER_COUNT = @@ -46,7 +47,7 @@ public void setUp() throws IOException, URISyntaxException { new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build(); authenticatedCluster = new Cluster(clusterConfiguration, net); - nodeUsingAuthFile = besu.createNodeWithAuthentication("node1"); + nodeUsingAuthFile = besu.createNodeWithAuthentication("node1", AUTH_FILE); nodeUsingJwtPublicKey = besu.createNodeWithAuthenticationUsingJwtPublicKey("node2"); authenticatedCluster.start(nodeUsingAuthFile, nodeUsingJwtPublicKey); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/multitenancy/MultiTenancyAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/multitenancy/MultiTenancyAcceptanceTest.java new file mode 100644 index 00000000000..0c873402c2a --- /dev/null +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/multitenancy/MultiTenancyAcceptanceTest.java @@ -0,0 +1,312 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.privacy.multitenancy; + +import static com.github.tomakehurst.wiremock.client.WireMock.ok; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Collections.emptyList; +import static org.hyperledger.besu.ethereum.core.Address.DEFAULT_PRIVACY; + +import org.hyperledger.besu.crypto.SECP256K1; +import org.hyperledger.besu.enclave.types.PrivacyGroup; +import org.hyperledger.besu.enclave.types.ReceiveResponse; +import org.hyperledger.besu.enclave.types.SendResponse; +import org.hyperledger.besu.ethereum.core.Address; +import org.hyperledger.besu.ethereum.core.Hash; +import org.hyperledger.besu.ethereum.core.Wei; +import org.hyperledger.besu.ethereum.privacy.PrivateTransaction; +import org.hyperledger.besu.ethereum.privacy.Restriction; +import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; +import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; +import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.Cluster; +import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfiguration; +import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder; + +import java.math.BigInteger; +import java.util.List; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.io.Base64; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { + private BesuNode node; + private final ObjectMapper mapper = new ObjectMapper(); + private Cluster multiTenancyCluster; + + private static final int ENCLAVE_PORT = 1080; + private static final String PRIVACY_GROUP_ID = "Z3JvdXBJZA=="; + private static final String ENCLAVE_KEY = "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="; + private static final String KEY1 = "sgFkVOyFndZe/5SAZJO5UYbrl7pezHetveriBBWWnE8="; + private static final String KEY2 = "R1kW75NQC9XX3kwNpyPjCBFflM29+XvnKKS9VLrUkzo="; + private static final String KEY3 = "QzHuACXpfhoGAgrQriWJcDJ6MrUwcCvutKMoAn9KplQ="; + private final Address senderAddress = + Address.wrap(Bytes.fromHexString(accounts.getPrimaryBenefactor().getAddress())); + + @Rule public WireMockRule wireMockRule = new WireMockRule(options().port(ENCLAVE_PORT)); + + @Before + public void setUp() throws Exception { + final ClusterConfiguration clusterConfiguration = + new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build(); + multiTenancyCluster = new Cluster(clusterConfiguration, net); + node = + besu.createNodeWithMultiTenantedPrivacy( + "node1", + "http://127.0.0.1:" + ENCLAVE_PORT, + "authentication/auth_priv.toml", + "authentication/auth_priv_key"); + multiTenancyCluster.start(node); + final String token = + node.execute(permissioningTransactions.createSuccessfulLogin("user", "pegasys")); + node.useAuthenticationTokenInHeaderForJsonRpc(token); + } + + @After + public void tearDown() { + multiTenancyCluster.close(); + } + + @Test + public void privGetPrivacyPrecompileAddressShouldReturnExpectedAddress() { + node.verify(priv.getPrivacyPrecompileAddress(DEFAULT_PRIVACY)); + } + + @Test + public void privGetPrivateTransactionSuccessShouldReturnExpectedPrivateTransaction() + throws JsonProcessingException { + final PrivateTransaction validSignedPrivateTransaction = + getValidSignedPrivateTransaction(senderAddress); + + receiveEnclaveStub(getRLPOutput(validSignedPrivateTransaction)); + retrievePrivacyGroupEnclaveStub(); + sendEnclaveStub("testKey"); + + final Hash transactionHash = + node.execute( + privacyTransactions.sendRawTransaction( + getRLPOutput(validSignedPrivateTransaction).encoded().toHexString())); + node.verify(priv.getTransactionReceipt(transactionHash)); + node.verify(priv.getPrivateTransaction(transactionHash, validSignedPrivateTransaction)); + } + + @Test + public void privCreatePrivacyGroupSuccessShouldReturnNewId() throws JsonProcessingException { + createPrivacyGroupEnclaveStub(); + + node.verify( + priv.createPrivacyGroup( + List.of(KEY1, KEY2, KEY3), "GroupName", "Group description.", PRIVACY_GROUP_ID)); + } + + @Test + public void privDeletePrivacyGroupSuccessShouldReturnId() throws JsonProcessingException { + retrievePrivacyGroupEnclaveStub(); + deletePrivacyGroupEnclaveStub(); + + node.verify(priv.deletePrivacyGroup(PRIVACY_GROUP_ID)); + } + + @Test + public void privFindPrivacyGroupSuccessShouldReturnExpectedGroupMembership() + throws JsonProcessingException { + final List groupMembership = + List.of( + testPrivacyGroup(emptyList(), PrivacyGroup.Type.PANTHEON), + testPrivacyGroup(emptyList(), PrivacyGroup.Type.PANTHEON), + testPrivacyGroup(emptyList(), PrivacyGroup.Type.PANTHEON)); + + findPrivacyGroupEnclaveStub(groupMembership); + + node.verify(priv.findPrivacyGroup(groupMembership.size(), ENCLAVE_KEY)); + } + + @Test + public void eeaSendRawTransactionSuccessShouldReturnPrivateTransactionHash() + throws JsonProcessingException { + final PrivateTransaction validSignedPrivateTransaction = + getValidSignedPrivateTransaction(senderAddress); + + retrievePrivacyGroupEnclaveStub(); + sendEnclaveStub("testKey"); + receiveEnclaveStub(getRLPOutput(validSignedPrivateTransaction)); + + node.verify( + priv.eeaSendRawTransaction( + getRLPOutput(validSignedPrivateTransaction).encoded().toHexString())); + } + + @Test + public void privGetTransactionCountSuccessShouldReturnExpectedTransactionCount() + throws JsonProcessingException { + final PrivateTransaction validSignedPrivateTransaction = + getValidSignedPrivateTransaction(senderAddress); + final String accountAddress = validSignedPrivateTransaction.getSender().toHexString(); + final BytesValueRLPOutput rlpOutput = getRLPOutput(validSignedPrivateTransaction); + + retrievePrivacyGroupEnclaveStub(); + sendEnclaveStub("testKey"); + receiveEnclaveStub(rlpOutput); + + node.verify(priv.getTransactionCount(accountAddress, PRIVACY_GROUP_ID, 0)); + final Hash transactionReceipt = + node.execute(privacyTransactions.sendRawTransaction(rlpOutput.encoded().toHexString())); + + node.verify(priv.getTransactionReceipt(transactionReceipt)); + node.verify(priv.getTransactionCount(accountAddress, PRIVACY_GROUP_ID, 1)); + } + + @Test + public void privDistributeRawTransactionSuccessShouldReturnEnclaveKey() + throws JsonProcessingException { + final String enclaveResponseKey = "TestKey"; + final String enclaveResponseKeyBase64 = + Base64.encode(Bytes.wrap(enclaveResponseKey.getBytes(UTF_8))); + final String enclaveResponseKeyBytes = + Bytes.wrap(Bytes.fromBase64String(enclaveResponseKeyBase64)).toString(); + + retrievePrivacyGroupEnclaveStub(); + sendEnclaveStub(enclaveResponseKeyBase64); + + node.verify( + priv.distributeRawTransaction( + getRLPOutput(getValidSignedPrivateTransaction(senderAddress)).encoded().toHexString(), + enclaveResponseKeyBytes)); + } + + @Test + public void privGetTransactionReceiptSuccessShouldReturnTransactionReceiptAfterMined() + throws JsonProcessingException { + final PrivateTransaction validSignedPrivateTransaction = + getValidSignedPrivateTransaction(senderAddress); + final BytesValueRLPOutput rlpOutput = getRLPOutput(validSignedPrivateTransaction); + + retrievePrivacyGroupEnclaveStub(); + sendEnclaveStub("testKey"); + receiveEnclaveStub(rlpOutput); + + final Hash transactionReceipt = + node.execute(privacyTransactions.sendRawTransaction(rlpOutput.encoded().toHexString())); + + node.verify(priv.getTransactionReceipt(transactionReceipt)); + } + + @Test + public void privGetEeaTransactionCountSuccessShouldReturnExpectedTransactionCount() + throws JsonProcessingException { + final PrivateTransaction validSignedPrivateTransaction = + getValidSignedPrivateTransaction(senderAddress); + final String accountAddress = validSignedPrivateTransaction.getSender().toHexString(); + final String senderAddressBase64 = Base64.encode(Bytes.wrap(accountAddress.getBytes(UTF_8))); + final BytesValueRLPOutput rlpOutput = getRLPOutput(validSignedPrivateTransaction); + final List groupMembership = + List.of(testPrivacyGroup(emptyList(), PrivacyGroup.Type.LEGACY)); + + retrievePrivacyGroupEnclaveStub(); + sendEnclaveStub("testKey"); + receiveEnclaveStub(rlpOutput); + findPrivacyGroupEnclaveStub(groupMembership); + + node.verify(priv.getTransactionCount(accountAddress, PRIVACY_GROUP_ID, 0)); + final Hash transactionHash = + node.execute(privacyTransactions.sendRawTransaction(rlpOutput.encoded().toHexString())); + + node.verify(priv.getTransactionReceipt(transactionHash)); + + final String privateFrom = ENCLAVE_KEY; + final String[] privateFor = {senderAddressBase64}; + node.verify(priv.getEeaTransactionCount(accountAddress, privateFrom, privateFor, 1)); + } + + private void findPrivacyGroupEnclaveStub(final List groupMembership) + throws JsonProcessingException { + final String findGroupResponse = mapper.writeValueAsString(groupMembership); + stubFor(post("/findPrivacyGroup").willReturn(ok(findGroupResponse))); + } + + private void createPrivacyGroupEnclaveStub() throws JsonProcessingException { + final String createGroupResponse = + mapper.writeValueAsString(testPrivacyGroup(emptyList(), PrivacyGroup.Type.PANTHEON)); + stubFor(post("/createPrivacyGroup").willReturn(ok(createGroupResponse))); + } + + private void deletePrivacyGroupEnclaveStub() throws JsonProcessingException { + final String deleteGroupResponse = mapper.writeValueAsString(PRIVACY_GROUP_ID); + stubFor(post("/deletePrivacyGroup").willReturn(ok(deleteGroupResponse))); + } + + private void retrievePrivacyGroupEnclaveStub() throws JsonProcessingException { + final String retrieveGroupResponse = + mapper.writeValueAsString( + testPrivacyGroup(List.of(ENCLAVE_KEY), PrivacyGroup.Type.PANTHEON)); + stubFor(post("/retrievePrivacyGroup").willReturn(ok(retrieveGroupResponse))); + } + + private void sendEnclaveStub(final String testKey) throws JsonProcessingException { + final String sendResponse = mapper.writeValueAsString(new SendResponse(testKey)); + stubFor(post("/send").willReturn(ok(sendResponse))); + } + + private void receiveEnclaveStub(final BytesValueRLPOutput rlpOutput) + throws JsonProcessingException { + final String senderKey = "QTFhVnRNeExDVUhtQlZIWG9aenpCZ1BiVy93ajVheERwVzlYOGw5MVNHbz0="; + final String receiveResponse = + mapper.writeValueAsString( + new ReceiveResponse( + rlpOutput.encoded().toBase64String().getBytes(UTF_8), PRIVACY_GROUP_ID, senderKey)); + stubFor(post("/receive").willReturn(ok(receiveResponse))); + } + + private BytesValueRLPOutput getRLPOutput(final PrivateTransaction validSignedPrivateTransaction) { + final BytesValueRLPOutput bvrlpo = new BytesValueRLPOutput(); + validSignedPrivateTransaction.writeTo(bvrlpo); + return bvrlpo; + } + + private PrivacyGroup testPrivacyGroup( + final List groupMembers, final PrivacyGroup.Type groupType) { + return new PrivacyGroup(PRIVACY_GROUP_ID, groupType, "test", "testGroup", groupMembers); + } + + private static PrivateTransaction getValidSignedPrivateTransaction(final Address senderAddress) { + return PrivateTransaction.builder() + .nonce(0) + .gasPrice(Wei.ZERO) + .gasLimit(3000000) + .to(null) + .value(Wei.ZERO) + .payload(Bytes.wrap(new byte[] {})) + .sender(senderAddress) + .chainId(BigInteger.valueOf(2018)) + .privateFrom(Bytes.fromBase64String(ENCLAVE_KEY)) + .restriction(Restriction.RESTRICTED) + .privacyGroupId(Bytes.fromBase64String(PRIVACY_GROUP_ID)) + .signAndBuild( + SECP256K1.KeyPair.create( + SECP256K1.PrivateKey.create( + new BigInteger( + "853d7f0010fd86d0d7811c1f9d968ea89a24484a8127b4a483ddf5d2cfec766d", 16)))); + } +} diff --git a/acceptance-tests/tests/src/test/resources/authentication/auth_priv.toml b/acceptance-tests/tests/src/test/resources/authentication/auth_priv.toml new file mode 100644 index 00000000000..2c86f165bf7 --- /dev/null +++ b/acceptance-tests/tests/src/test/resources/authentication/auth_priv.toml @@ -0,0 +1,4 @@ +[Users.user] +password = "$2a$10$l3GA7K8g6rJ/Yv.YFSygCuI9byngpEzxgWS9qEg5emYDZomQW7fGC" +permissions = ["fakePermission", "*:*"] +privacyPublicKey = "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=" diff --git a/acceptance-tests/tests/src/test/resources/authentication/auth_priv_key b/acceptance-tests/tests/src/test/resources/authentication/auth_priv_key new file mode 100644 index 00000000000..85329a8cbe3 --- /dev/null +++ b/acceptance-tests/tests/src/test/resources/authentication/auth_priv_key @@ -0,0 +1 @@ +8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63 \ No newline at end of file diff --git a/acceptance-tests/tests/src/test/resources/authentication/auth_pub_key b/acceptance-tests/tests/src/test/resources/authentication/auth_pub_key new file mode 100644 index 00000000000..3c8b7f3bfb8 --- /dev/null +++ b/acceptance-tests/tests/src/test/resources/authentication/auth_pub_key @@ -0,0 +1 @@ +A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo= \ No newline at end of file