-
Notifications
You must be signed in to change notification settings - Fork 891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Priv call #250
Merged
Merged
Priv call #250
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4f0d7e3
Increase timeout to 5s
pinges f20b412
Merge branch 'master' of github.com:hyperledger/besu into request_tim…
pinges f9fa103
add priv_call RPC
pinges 3ba6fed
add priv_call RPC
pinges 3ca0559
merge upstream master
pinges 8de4130
fix spotless
pinges 81619e6
fix ByteValues
pinges 409e517
Merge branch 'master' of github.com:hyperledger/besu into priv_call
pinges 74472ad
add multi tenancy membership check and additional AT
pinges 9f8e600
fix unit test
pinges 48489b4
fix unit test
pinges 741fa89
fix unit test
pinges e4912ca
fix unit test
pinges bf077a5
fix invalid privacy group AT
pinges f269684
Merge branch 'master' into priv_call
pinges 39af6e8
add more ATs
pinges 956950f
Merge branch 'priv_call' of github.com:pinges/besu into priv_call
pinges fe63a54
fix spotless
pinges bad4dad
suppress warning in AT
pinges 97d8f79
Merge branch 'master' of github.com:hyperledger/besu into priv_call
pinges b53b6e3
fix resource version
pinges 90a168c
Merge branch 'master' into priv_call
pinges 20771de
addressed comments
pinges File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
244 changes: 244 additions & 0 deletions
244
.../tests/src/test/java/org/hyperledger/besu/tests/web3j/privacy/PrivCallAcceptanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
/* | ||
* 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.web3j.privacy; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyAcceptanceTestBase; | ||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode; | ||
import org.hyperledger.besu.tests.web3j.generated.EventEmitter; | ||
|
||
import java.io.IOException; | ||
import java.math.BigInteger; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.web3j.abi.FunctionEncoder; | ||
import org.web3j.abi.TypeReference; | ||
import org.web3j.abi.datatypes.Function; | ||
import org.web3j.abi.datatypes.Type; | ||
import org.web3j.abi.datatypes.generated.Uint256; | ||
import org.web3j.protocol.core.Request; | ||
import org.web3j.protocol.core.methods.request.Transaction; | ||
import org.web3j.protocol.core.methods.response.EthCall; | ||
import org.web3j.protocol.core.methods.response.TransactionReceipt; | ||
import org.web3j.protocol.exceptions.ClientConnectionException; | ||
import org.web3j.protocol.http.HttpService; | ||
import org.web3j.tx.Contract; | ||
|
||
public class PrivCallAcceptanceTest extends PrivacyAcceptanceTestBase { | ||
|
||
private static final long POW_CHAIN_ID = 2018; | ||
private static final int VALUE = 1024; | ||
|
||
private PrivacyNode minerNode; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
minerNode = | ||
privacyBesu.createPrivateTransactionEnabledMinerNode( | ||
"miner-node", privacyAccountResolver.resolve(0)); | ||
privacyCluster.start(minerNode); | ||
} | ||
|
||
@Test | ||
public void mustReturnCorrectValue() throws Exception { | ||
|
||
final String privacyGroupId = | ||
minerNode.execute( | ||
privacyTransactions.createPrivacyGroup( | ||
"myGroupName", "my group description", minerNode)); | ||
|
||
final EventEmitter eventEmitter = | ||
minerNode.execute( | ||
privateContractTransactions.createSmartContractWithPrivacyGroupId( | ||
EventEmitter.class, | ||
minerNode.getTransactionSigningKey(), | ||
POW_CHAIN_ID, | ||
minerNode.getEnclaveKey(), | ||
privacyGroupId)); | ||
|
||
privateContractVerifier | ||
.validPrivateContractDeployed( | ||
eventEmitter.getContractAddress(), minerNode.getAddress().toString()) | ||
.verify(eventEmitter); | ||
|
||
final Request<Object, EthCall> priv_call = privCall(privacyGroupId, eventEmitter, false, false); | ||
|
||
EthCall resp = priv_call.send(); | ||
|
||
String value = resp.getValue(); | ||
assertThat(new BigInteger(value.substring(2), 16)).isEqualByComparingTo(BigInteger.ZERO); | ||
|
||
final TransactionReceipt receipt = eventEmitter.store(BigInteger.valueOf(VALUE)).send(); | ||
assertThat(receipt).isNotNull(); | ||
|
||
resp = priv_call.send(); | ||
value = resp.getValue(); | ||
assertThat(new BigInteger(value.substring(2), 16)) | ||
.isEqualByComparingTo(BigInteger.valueOf(VALUE)); | ||
} | ||
|
||
@Test | ||
public void mustNotSucceedWithNonExistingPrivacyGroup() { | ||
|
||
final String privacyGroupId = | ||
minerNode.execute( | ||
privacyTransactions.createPrivacyGroup( | ||
"myGroupName", "my group description", minerNode)); | ||
|
||
final EventEmitter eventEmitter = | ||
minerNode.execute( | ||
privateContractTransactions.createSmartContractWithPrivacyGroupId( | ||
EventEmitter.class, | ||
minerNode.getTransactionSigningKey(), | ||
POW_CHAIN_ID, | ||
minerNode.getEnclaveKey(), | ||
privacyGroupId)); | ||
|
||
System.out.println("Address: " + eventEmitter.getContractAddress()); | ||
|
||
privateContractVerifier | ||
.validPrivateContractDeployed( | ||
eventEmitter.getContractAddress(), minerNode.getAddress().toString()) | ||
.verify(eventEmitter); | ||
|
||
final String invalidPrivacyGroup = constructInvalidString(privacyGroupId); | ||
final Request<Object, EthCall> priv_call = | ||
privCall(invalidPrivacyGroup, eventEmitter, false, false); | ||
|
||
assertThatExceptionOfType(ClientConnectionException.class) | ||
.isThrownBy(() -> priv_call.send()) | ||
.withMessageContaining("Privacy group does not exist."); | ||
} | ||
|
||
@Test | ||
public void mustNotSucceedWithWronglyEncodedFunction() { | ||
|
||
final String privacyGroupId = | ||
minerNode.execute( | ||
privacyTransactions.createPrivacyGroup( | ||
"myGroupName", "my group description", minerNode)); | ||
|
||
final EventEmitter eventEmitter = | ||
minerNode.execute( | ||
privateContractTransactions.createSmartContractWithPrivacyGroupId( | ||
EventEmitter.class, | ||
minerNode.getTransactionSigningKey(), | ||
POW_CHAIN_ID, | ||
minerNode.getEnclaveKey(), | ||
privacyGroupId)); | ||
|
||
privateContractVerifier | ||
.validPrivateContractDeployed( | ||
eventEmitter.getContractAddress(), minerNode.getAddress().toString()) | ||
.verify(eventEmitter); | ||
|
||
final Request<Object, EthCall> priv_call = privCall(privacyGroupId, eventEmitter, true, false); | ||
|
||
assertThatExceptionOfType(ClientConnectionException.class) | ||
.isThrownBy(() -> priv_call.send()) | ||
.withMessageContaining("Invalid params"); | ||
} | ||
|
||
@Test | ||
public void mustReturn0xUsingInvalidContractAddress() throws IOException { | ||
|
||
final String privacyGroupId = | ||
minerNode.execute( | ||
privacyTransactions.createPrivacyGroup( | ||
"myGroupName", "my group description", minerNode)); | ||
|
||
final EventEmitter eventEmitter = | ||
minerNode.execute( | ||
privateContractTransactions.createSmartContractWithPrivacyGroupId( | ||
EventEmitter.class, | ||
minerNode.getTransactionSigningKey(), | ||
POW_CHAIN_ID, | ||
minerNode.getEnclaveKey(), | ||
privacyGroupId)); | ||
|
||
privateContractVerifier | ||
.validPrivateContractDeployed( | ||
eventEmitter.getContractAddress(), minerNode.getAddress().toString()) | ||
.verify(eventEmitter); | ||
|
||
final Request<Object, EthCall> priv_call = privCall(privacyGroupId, eventEmitter, false, true); | ||
|
||
final EthCall result = priv_call.send(); | ||
|
||
assertThat(result).isNotNull(); | ||
assertThat(result.getResult()).isEqualTo("0x"); | ||
} | ||
|
||
@NotNull | ||
private String constructInvalidString(final String privacyGroupId) { | ||
final char[] chars = privacyGroupId.toCharArray(); | ||
if (chars[3] == '0') { | ||
chars[3] = '1'; | ||
} else { | ||
chars[3] = '0'; | ||
} | ||
return String.valueOf(chars); | ||
} | ||
|
||
@NotNull | ||
private Request<Object, EthCall> privCall( | ||
final String privacyGroupId, | ||
final Contract eventEmitter, | ||
final boolean useInvalidParameters, | ||
final boolean useInvalidContractAddress) { | ||
|
||
final Uint256 invalid = new Uint256(BigInteger.TEN); | ||
|
||
@SuppressWarnings("rawtypes") | ||
final List<Type> inputParameters = | ||
useInvalidParameters ? Arrays.asList(invalid) : Collections.emptyList(); | ||
|
||
final Function function = | ||
new Function( | ||
"value", | ||
inputParameters, | ||
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); | ||
|
||
final String encoded = FunctionEncoder.encode(function); | ||
|
||
final HttpService httpService = | ||
new HttpService( | ||
"http://" | ||
+ minerNode.getBesu().getHostName() | ||
+ ":" | ||
+ minerNode.getBesu().getJsonRpcSocketPort().get()); | ||
|
||
final String validContractAddress = eventEmitter.getContractAddress(); | ||
final String invalidContractAddress = constructInvalidString(validContractAddress); | ||
final String contractAddress = | ||
useInvalidContractAddress ? invalidContractAddress : validContractAddress; | ||
|
||
final Transaction transaction = | ||
Transaction.createEthCallTransaction(null, contractAddress, encoded); | ||
|
||
return new Request<>( | ||
"priv_call", | ||
Arrays.asList(privacyGroupId, transaction, "latest"), | ||
httpService, | ||
EthCall.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why widen the scope (encapsulation) instead of using the getter (
getBlockchainQueries
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a short while we need access to this. When we add the mainnet functionality this can be set back to private. I have added a TODO for making this private again.